]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/controller.php
Release 6.2.3
[Github/sugarcrm.git] / modules / ModuleBuilder / controller.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37 require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
38 require_once ('modules/ModuleBuilder/parsers/ParserFactory.php') ;
39 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
40
41 class ModuleBuilderController extends SugarController
42 {
43     var $action_remap = array ( ) ;
44
45     /**
46      * Used by the _getModuleTitleParams() method calls in ModuleBuilder views to get the correct string
47      * for the section you are in
48      *
49      * @return string
50      */
51     public static function getModuleTitle()
52     {
53         global $mod_strings;
54
55         if(!empty($_REQUEST['type'])){
56             if ( $_REQUEST['type'] == 'studio' ) {
57                 return $mod_strings['LBL_STUDIO'];
58             }
59             elseif ( $_REQUEST['type'] == 'sugarportal' ) {
60                 return $mod_strings['LBL_SUGARPORTAL'];
61             }
62             elseif ( $_REQUEST['type'] == 'mb' ) {
63                 return $mod_strings['LBL_MODULEBUILDER'];
64             }
65             elseif ( $_REQUEST['type'] == 'dropdowns') {
66                 return $mod_strings['LBL_DROPDOWNEDITOR'];
67             }
68             elseif ( $_REQUEST['type'] == 'home' ) {
69                 return $mod_strings['LBL_HOME'];
70             }
71             else {
72                 return $mod_strings['LBL_DEVELOPER_TOOLS'];
73             }
74         }else{
75             return $mod_strings['LBL_DEVELOPER_TOOLS'];
76         }
77     }
78
79     function fromModuleBuilder ()
80     {
81         return (isset ( $_REQUEST [ 'MB' ] ) && ($_REQUEST [ 'MB' ] == '1')) ;
82     }
83
84     function process(){
85         $GLOBALS [ 'log' ]->info ( get_class($this).":" ) ;
86         global $current_user;
87         $access = $current_user->getDeveloperModules();
88             if($current_user->isAdmin() || ($current_user->isDeveloperForAnyModule() && !isset($_REQUEST['view_module']) && (isset($_REQUEST['action']) && $_REQUEST['action'] != 'package'))||
89           (isset($_REQUEST['view_module']) && (in_array($_REQUEST['view_module'], $access)|| empty($_REQUEST['view_module']))) ||
90                (isset($_REQUEST['type']) && (($_REQUEST['type']=='dropdowns' && $current_user->isDeveloperForAnyModule())||
91           ($_REQUEST['type']=='studio' && displayStudioForCurrentUser() == true))))
92         {
93             $this->hasAccess = true;
94         }
95         else
96         {
97             $this->hasAccess = false;
98         }
99         parent::process();
100     }
101
102
103     function action_editLayout ()
104     {
105         switch ( strtolower ( $_REQUEST [ 'view' ] ))
106         {
107             case MB_EDITVIEW :
108             case MB_DETAILVIEW :
109             case MB_QUICKCREATE :
110                 $this->view = 'layoutView' ;
111                 break ;
112             case MB_LISTVIEW :
113                 $this->view = 'listView' ;
114                 break ;
115             case MB_BASICSEARCH :
116             case MB_ADVANCEDSEARCH :
117                 $this->view = 'searchView' ;
118                 break ;
119             case MB_DASHLET :
120             case MB_DASHLETSEARCH :
121                 $this->view = 'dashlet' ;
122                 break ;
123             case MB_POPUPLIST :
124             case MB_POPUPSEARCH :
125                 $this->view = 'popupview' ;
126                 break ;
127             default :
128                 $GLOBALS [ 'log' ]->fatal ( 'Action = editLayout with unknown view=' . $_REQUEST [ 'view' ] ) ;
129         }
130     }
131
132
133     function action_ViewTree ()
134     {
135         require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
136         switch ( $_REQUEST [ 'tree' ])
137         {
138             case 'ModuleBuilder' :
139                 require_once ('modules/ModuleBuilder/MB/MBPackageTree.php') ;
140                 $mbt = new MBPackageTree ( ) ;
141                 break ;
142             case 'Studio' :
143                 require_once ('modules/ModuleBuilder/Module/StudioTree.php') ;
144                 $mbt = new StudioTree ( ) ;
145         }
146         $ajax = new AjaxCompose ( ) ;
147         $ajax->addSection ( 'west', $mbt->getName (), $mbt->fetchNodes () ) ;
148         echo $ajax->getJavascript () ;
149
150         sugar_cleanup ( true ) ;
151
152     }
153
154     function action_SavePackage ()
155     {
156         $mb = new ModuleBuilder ( ) ;
157         $load = (! empty ( $_REQUEST [ 'original_name' ] )) ? $_REQUEST [ 'original_name' ] : $_REQUEST [ 'name' ] ;
158         if (! empty ( $load ))
159         {
160             $mb->getPackage ( $load ) ;
161
162             if (! empty ( $_REQUEST [ 'duplicate' ] ))
163             {
164                 $result = $mb->packages [ $load ]->copy ( $_REQUEST [ 'name' ] ) ;
165                 $load = $mb->packages [ $load ]->name ;
166                 $mb->getPackage ( $load ) ;
167             }
168             $mb->packages [ $load ]->populateFromPost () ;
169             $mb->packages [ $load ]->loadModules () ;
170             $mb->save () ;
171             if (! empty ( $_REQUEST [ 'original_name' ] ) && $_REQUEST [ 'original_name' ] != $_REQUEST [ 'name' ])
172             {
173                 if (! $mb->packages [ $load ]->rename ( $_REQUEST [ 'name' ] ))
174                 {
175                     $mb->packages [ $load ]->name = $_REQUEST [ 'original_name' ] ;
176                     $_REQUEST [ 'name' ] = $_REQUEST [ 'original_name' ] ;
177                 }
178             }
179             $_REQUEST [ 'package' ] = $_REQUEST [ 'name' ] ;
180             $this->view = 'package' ;
181         }
182     }
183
184     function action_BuildPackage ()
185     {
186         $mb = new ModuleBuilder ( ) ;
187         $load = $_REQUEST [ 'name' ] ;
188         if (! empty ( $load ))
189         {
190             $mb->getPackage ( $load ) ;
191             $mb->packages [ $load ]->build () ;
192         }
193     }
194
195     function action_DeployPackage ()
196     {
197         if(defined('TEMPLATE_URL')){
198                 sugar_cache_reset();
199                 SugarTemplateUtilities::disableCache();
200         }
201
202         $mb = new ModuleBuilder ( ) ;
203         $load = $_REQUEST [ 'package' ] ;
204         $message = $GLOBALS [ 'mod_strings' ] [ 'LBL_MODULE_DEPLOYED' ] ;
205         if (! empty ( $load ))
206         {
207             $zip = $mb->getPackage ( $load ) ;
208             require_once ('ModuleInstall/PackageManager/PackageManager.php') ;
209             $pm = new PackageManager ( ) ;
210             $info = $mb->packages [ $load ]->build ( false ) ;
211             mkdir_recursive ( $GLOBALS [ 'sugar_config' ] [ 'cache_dir' ] . '/upload/upgrades/module/') ;
212             rename ( $info [ 'zip' ], $GLOBALS [ 'sugar_config' ] [ 'cache_dir' ] . '/' . 'upload/upgrades/module/' . $info [ 'name' ] . '.zip' ) ;
213             copy ( $info [ 'manifest' ], $GLOBALS [ 'sugar_config' ] [ 'cache_dir' ] . '/' . 'upload/upgrades/module/' . $info [ 'name' ] . '-manifest.php' ) ;
214             $_REQUEST [ 'install_file' ] = $GLOBALS [ 'sugar_config' ] [ 'cache_dir' ] . '/' . 'upload/upgrades/module/' . $info [ 'name' ] . '.zip' ;
215             $GLOBALS [ 'mi_remove_tables' ] = false ;
216             $pm->performUninstall ( $load ) ;
217             //#23177 , js cache clear
218             clearAllJsAndJsLangFilesWithoutOutput();
219             //#30747, clear the cache in memory
220             $cache_key = 'app_list_strings.'.$GLOBALS['current_language'];
221             sugar_cache_clear($cache_key );
222             sugar_cache_reset();
223             //clear end
224             $pm->performInstall ( $_REQUEST [ 'install_file' ] , true);
225
226             //clear the unified_search_module.php file
227             require_once('modules/Home/UnifiedSearchAdvanced.php');
228             UnifiedSearchAdvanced::unlinkUnifiedSearchModulesFile();
229
230             //bug 44269 - start
231             global $current_user;
232             //clear workflow admin modules cache
233             if (isset($_SESSION['get_workflow_admin_modules_for_user'])) unset($_SESSION['get_workflow_admin_modules_for_user']);
234
235             //clear "is_admin_for_module" cache
236             $sessionVar = 'MLA_'.$current_user->user_name;
237             foreach ($mb->packages as $package) {
238                 foreach ($package->modules as $module) {
239                     $_SESSION[$sessionVar][$package->name . '_' . $module->name] = true;
240                 }
241             }
242
243             //recreate acl cache
244             $actions = ACLAction::getUserActions($current_user->id, true);
245             //bug 44269 - end
246         }
247
248         echo 'complete' ;
249     }
250
251     function action_ExportPackage ()
252     {
253         $mb = new ModuleBuilder ( ) ;
254         $load = $_REQUEST [ 'name' ] ;
255         $author = $_REQUEST [ 'author' ] ;
256         $description = $_REQUEST [ 'description' ] ;
257         $readme = $_REQUEST [ 'readme' ] ;
258         if (! empty ( $load ))
259         {
260             $mb->getPackage ( $load ) ;
261             $mb->packages [ $load ]->author = $author ;
262             $mb->packages [ $load ]->description = $description ;
263             $mb->packages [ $load ]->exportProject () ;
264             $mb->packages [ $load ]->readme = $readme ;
265         }
266     }
267
268     function action_DeletePackage ()
269     {
270         $mb = new ModuleBuilder ( ) ;
271         $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
272         $mb->packages [ $_REQUEST [ 'package' ] ]->delete () ;
273         $this->view = 'deletepackage' ;
274     }
275
276     function action_SaveModule ()
277     {
278         $mb = new ModuleBuilder ( ) ;
279         $load = (! empty ( $_REQUEST [ 'original_name' ] )) ? $_REQUEST [ 'original_name' ] : $_REQUEST [ 'name' ] ;
280         if (! empty ( $load ))
281         {
282             $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
283             $mb->packages [ $_REQUEST [ 'package' ] ]->getModule ( $load ) ;
284             $module = & $mb->packages [ $_REQUEST [ 'package' ] ]->modules [ $load ] ;
285             $module->populateFromPost () ;
286             $mb->save () ;
287             if (! empty ( $_REQUEST [ 'duplicate' ] ))
288             {
289                 $module->copy ( $_REQUEST [ 'name' ] ) ;
290             } else if (! empty ( $_REQUEST [ 'original_name' ] ) && $_REQUEST [ 'original_name' ] != $_REQUEST [ 'name' ])
291             {
292                 if (! $module->rename ( $_REQUEST [ 'name' ] ))
293                 {
294                     $module->name = $_REQUEST [ 'original_name' ] ;
295                     $_REQUEST [ 'name' ] = $_REQUEST [ 'original_name' ] ;
296                 }
297             }
298
299             $_REQUEST [ 'view_package' ] = $_REQUEST [ 'package' ] ;
300             $_REQUEST [ 'view_module' ] = $module->name ;
301             $this->view = 'module' ;
302         }
303     }
304
305     function action_DeleteModule ()
306     {
307         $mb = new ModuleBuilder ( ) ;
308         $module = & $mb->getPackageModule ( $_REQUEST [ 'package' ], $_REQUEST [ 'view_module' ] ) ;
309         $module->delete () ;
310         $this->view = 'package' ;
311     }
312
313     function action_saveLabels ()
314     {
315         require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
316         $parser = new ParserLabel ( $_REQUEST['view_module'] , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
317         $parser->handleSave ( $_REQUEST, $_REQUEST [ 'selected_lang' ] ) ;
318         if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
319         {
320             $this->view = 'modulelabels' ;
321         } else //STUDIO
322         {
323             $this->view = isset ( $_REQUEST [ 'view' ] ) ? 'edit' : 'labels' ; // detect if we are being called by the LayoutEditor rather than the LabelEditor (set in view.layoutlabel.php)
324         }
325     }
326
327     function action_SaveLabel ()
328     {
329         if (! empty ( $_REQUEST [ 'view_module' ] ) && !empty($_REQUEST [ 'labelValue' ]))
330         {
331             $_REQUEST [ "label_" . $_REQUEST [ 'label' ] ] = $_REQUEST [ 'labelValue' ] ;
332             require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
333             $parser = new ParserLabel ( $_REQUEST['view_module'] , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
334             $parser->handleSave ( $_REQUEST, $GLOBALS [ 'current_language' ] ) ;
335
336         }
337         $this->view = 'modulefields' ;
338     }
339
340     function action_ExportCustom ()
341     {
342         $modules = $_REQUEST [ 'modules' ] ;
343         $name = $_REQUEST [ 'name' ] ;
344         $author = $_REQUEST [ 'author' ] ;
345         $description = $_REQUEST [ 'description' ] ;
346         ob_clean () ;
347         if (! empty ( $modules ) && ! empty ( $name ))
348         {
349             require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
350             $mb = new MBPackage ( $name ) ;
351             $mb->author = $author ;
352             $mb->description = $description ;
353             $mb->exportCustom ( $modules, true, true ) ;
354         }
355     }
356
357     function action_SaveField ()
358     {
359         require_once ('modules/DynamicFields/FieldCases.php') ;
360         $field = get_widget ( $_REQUEST [ 'type' ] ) ;
361         $_REQUEST [ 'name' ] = trim ( $_REQUEST [ 'name' ] ) ;
362
363         $field->populateFromPost () ;
364
365         if (!isset ( $_REQUEST [ 'view_package' ] ))
366         {
367             require_once ('modules/DynamicFields/DynamicField.php') ;
368             if (! empty ( $_REQUEST [ 'view_module' ] ))
369             {
370                 $module = $_REQUEST [ 'view_module' ] ;
371
372                 $bean = loadBean($module);
373                 if(!empty($bean))
374                 {
375                         $field_defs = $bean->field_defs;
376                         if(isset($field_defs[$field->name. '_c']))
377                         {
378                                                 $GLOBALS['log']->error($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS'] . '[' . $field->name . ']');
379                                                 sugar_die($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS']);
380                         }
381                 }
382
383                 $df = new DynamicField ( $module ) ;
384                 $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
385                 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
386                 $mod = new $class_name ( ) ;
387                 $df->setup ( $mod ) ;
388
389                 $field->save ( $df ) ;
390                 $this->action_SaveLabel () ;
391                 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
392                         global $mod_strings;
393                 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
394                 $repair = new RepairAndClear();
395                         $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
396                         //#28707 ,clear all the js files in cache
397                         $repair->module_list = array();
398                         $repair->clearJsFiles();
399             }
400         } else
401         {
402             $mb = new ModuleBuilder ( ) ;
403             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
404             $field->save ( $module ) ;
405             $module->mbvardefs->save () ;
406             // get the module again to refresh the labels we might have saved with the $field->save (e.g., for address fields)
407             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
408             if (isset ( $_REQUEST [ 'label' ] ) && isset ( $_REQUEST [ 'labelValue' ] ))
409                 $module->setLabel ( $GLOBALS [ 'current_language' ], $_REQUEST [ 'label' ], $_REQUEST [ 'labelValue' ] ) ;
410             $module->save();
411         }
412         $this->view = 'modulefields' ;
413     }
414
415     function action_saveSugarField ()
416     {
417         global $mod_strings;
418         require_once ('modules/DynamicFields/FieldCases.php') ;
419         $field = get_widget ( $_REQUEST [ 'type' ] ) ;
420         $_REQUEST [ 'name' ] = trim ( $_POST [ 'name' ] ) ;
421
422         $field->populateFromPost () ;
423         require_once ('modules/ModuleBuilder/parsers/StandardField.php') ;
424         $module = $_REQUEST [ 'view_module' ] ;
425         $df = new StandardField ( $module ) ;
426         $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
427         require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
428         $mod = new $class_name ( ) ;
429         $df->setup ( $mod ) ;
430
431         $field->module = $mod;
432         $field->save ( $df ) ;
433         $this->action_SaveLabel () ;
434
435         $MBmodStrings = $mod_strings;
436         $GLOBALS [ 'mod_strings' ] = return_module_language ( '', 'Administration' ) ;
437
438         include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
439         $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
440         $_REQUEST['execute_sql'] = true;
441
442         $repair = new RepairAndClear();
443         $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
444         //#28707 ,clear all the js files in cache
445         $repair->module_list = array();
446         $repair->clearJsFiles();
447
448
449         // now clear the cache so that the results are immediately visible
450         include_once ('include/TemplateHandler/TemplateHandler.php') ;
451         TemplateHandler::clearCache ( $module ) ;
452
453         $GLOBALS [ 'mod_strings' ] = $MBmodStrings;
454     }
455
456     function action_RefreshField ()
457     {
458         require_once ('modules/DynamicFields/FieldCases.php') ;
459         $field = get_widget ( $_POST [ 'type' ] ) ;
460         $field->populateFromPost () ;
461         $this->view = 'modulefield' ;
462     }
463
464     function action_saveVisibility ()
465     {
466                 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
467         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
468         $parser = ParserFactory::getParser ( MB_VISIBILITY, $_REQUEST [ 'view_module' ], $packageName ) ;
469
470         $json = getJSONobj();
471         $visibility_grid = $json->decode(html_entity_decode(rawurldecode($_REQUEST [ 'visibility_grid' ]), ENT_QUOTES) );
472                 $parser->saveVisibility ( $_REQUEST [ 'fieldname' ] , $_REQUEST [ 'trigger' ] , $visibility_grid ) ;
473
474         echo $json->encode(array( "visibility_editor_{$_REQUEST['fieldname']}" => array("action" => "deactivate")));
475     }
476
477         function action_SaveRelationshipLabel (){
478             $selected_lang = (!empty($_REQUEST['relationship_lang'])?$_REQUEST['relationship_lang']:$_SESSION['authenticated_user_language']);
479                  if (empty($_REQUEST [ 'view_package' ])){
480             require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
481             $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
482             if (! empty ( $_REQUEST [ 'relationship_name' ] ))
483                 {
484                     if ($relationship = $relationships->get ( $_REQUEST [ 'relationship_name' ] )){
485                         $metadata = $relationship->buildLabels(true);
486                          require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
487                                 $parser = new ParserLabel ( $_REQUEST['view_module'] ) ;
488                                 $parser->handleSaveRelationshipLabels ( $metadata, $selected_lang ) ;
489                     }
490             }
491         }
492         else {
493             //TODO FOR MB
494         }
495         $this->view = 'relationships' ;
496         }
497
498     function action_SaveRelationship ()
499     {
500         if(!empty($GLOBALS['current_user']) && empty($GLOBALS['modListHeader']))
501         {
502             $GLOBALS['modListHeader'] = query_module_access_list($GLOBALS['current_user']);
503         }
504
505         if (empty($_REQUEST [ 'view_package' ]))
506         {
507             require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
508             $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
509         } else
510         {
511             $mb = new ModuleBuilder ( ) ;
512             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
513             require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
514             $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
515         }
516
517         $relationships->addFromPost () ;
518         $relationships->save () ;
519         $GLOBALS['log']->debug("\n\nSTART BUILD");
520         if (empty($_REQUEST [ 'view_package' ])) {
521             $relationships->build () ;
522
523             LanguageManager::clearLanguageCache($_REQUEST [ 'view_module' ]);
524         }
525         $GLOBALS['log']->debug("\n\nEND BUILD");
526
527         $this->view = 'relationships' ;
528     }
529
530     function action_DeleteRelationship ()
531     {
532         if (isset ( $_REQUEST [ 'relationship_name' ] ))
533         {
534             if (empty($_REQUEST [ 'view_package' ] ))
535             {
536                 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
537                 if (!empty($_REQUEST['remove_tables']))
538                                     $GLOBALS['mi_remove_tables'] = $_REQUEST['remove_tables'];
539                 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
540             } else
541             {
542                 $mb = new ModuleBuilder ( ) ;
543                 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
544                 require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
545                 $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
546             }
547             $relationships->delete ( $_REQUEST [ 'relationship_name' ] ) ;
548             $relationships->save () ;
549         }
550         $this->view = 'relationships' ;
551     }
552
553     function action_SaveDropDown ()
554     {
555         require_once 'modules/ModuleBuilder/parsers/parser.dropdown.php' ;
556         $parser = new ParserDropDown ( ) ;
557         $parser->saveDropDown ( $_REQUEST ) ;
558         $this->view = 'dropdowns' ;
559     }
560
561     function action_DeleteField ()
562     {
563         require_once ('modules/DynamicFields/FieldCases.php') ;
564         $field = get_widget ( $_REQUEST [ 'type' ] ) ;
565         $field->name = $_REQUEST [ 'name' ] ;
566         if (!isset ( $_REQUEST [ 'view_package' ] ))
567         {
568             if (! empty ( $_REQUEST [ 'name' ] ) && ! empty ( $_REQUEST [ 'view_module' ] ))
569             {
570                 require_once ('modules/DynamicFields/DynamicField.php') ;
571                 $moduleName = $_REQUEST [ 'view_module' ] ;
572                 $class_name = $GLOBALS [ 'beanList' ] [ $moduleName ] ;
573                 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
574                 $seed = new $class_name ( ) ;
575                 $df = new DynamicField ( $moduleName ) ;
576                 $df->setup ( $seed ) ;
577                 //Need to load the entire field_meta_data for some field types
578                 $field = $df->getFieldWidget($moduleName, $field->name);
579                 $field->delete ( $df ) ;
580
581                 $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
582                 $_REQUEST['execute_sql'] = true;
583                 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
584                 $repair = new RepairAndClear();
585                 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
586                 require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php' ;
587                 $module = StudioModuleFactory::getStudioModule( $moduleName ) ;
588             }
589         }
590         else
591         {
592             $mb = new ModuleBuilder ( ) ;
593             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
594             $field->delete ( $module ) ;
595             $mb->save () ;
596         }
597         $module->removeFieldFromLayouts( $field->name );
598         $this->view = 'modulefields' ;
599     }
600
601     function action_CloneField ()
602     {
603         $this->view_object_map [ 'field_name' ] = $_REQUEST [ 'name' ] ;
604         $this->view_object_map [ 'is_clone' ] = true ;
605         $this->view = 'modulefield' ;
606     }
607
608     function action_SaveAssistantPref ()
609     {
610         global $current_user ;
611         if (isset ( $_REQUEST [ 'pref_value' ] ))
612         {
613             if ($_REQUEST [ 'pref_value' ] == 'ignore')
614             {
615                 $current_user->setPreference ( 'mb_assist', 'DISABLED', 0, 'Assistant' ) ;
616             } else
617             {
618                 $current_user->setPreference ( 'mb_assist', 'ENABLED', 0, 'Assistant' ) ;
619             }
620             $current_pref = $current_user->getPreference ( 'mb_assist', 'Assistant' ) ;
621             echo "Assistant.processUserPref('$current_pref')" ;
622             sugar_cleanup ( true ) ; //push preferences to DB.
623         }
624     }
625
626     // Studio2 Actions
627
628
629     function action_EditProperty ()
630     {
631         $this->view = 'property' ;
632     }
633
634     function action_saveProperty ()
635     {
636         require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
637         $modules = $_REQUEST['view_module'];
638         if(!empty($_REQUEST['subpanel'])){
639                 $modules = $_REQUEST['subpanel'];
640         }
641         $parser = new ParserLabel ( $modules , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
642         // if no language provided, then use the user's current language which is most likely what they intended
643         $language = (isset($_REQUEST [ 'selected_lang' ])) ? $_REQUEST [ 'selected_lang' ] : $GLOBALS['current_language'] ;
644         $parser->handleSave ( $_REQUEST, $language ) ;
645         $json = getJSONobj();
646         echo $json->encode(array("east" => array("action" => "deactivate")));
647     }
648
649     function action_editModule ()
650     {
651         $this->view = 'module' ;
652     }
653
654     function action_wizard ()
655     {
656         $this->view = 'wizard' ;
657     }
658
659     /**
660      * Receive a layout through $_REQUEST and save it out to the working files directory
661      * Expects a series of $_REQUEST parameters all in the format $_REQUEST['slot-panel#-slot#-property']=value
662      */
663
664     function action_saveLayout ()
665     {
666             $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
667             $this->view = 'layoutview' ;
668         $parser->writeWorkingFile () ;
669
670         if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
671                 if(strtolower ($parser->_view) == MB_EDITVIEW){
672                         $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
673                         $parser2->setUseTabs($parser->getUseTabs());
674                 $parser2->writeWorkingFile () ;
675                 }
676         }
677     }
678
679     function action_saveAndPublishLayout ()
680     {
681             $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
682             $this->view = 'layoutview' ;
683         $parser->handleSave () ;
684
685         if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
686                 if(strtolower ($parser->_view) == MB_EDITVIEW){
687                         $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
688                         $parser2->setUseTabs($parser->getUseTabs());
689                 $parser2->handleSave () ;
690                 }
691         }
692     }
693
694     function action_manageBackups ()
695     {
696
697     }
698
699     function action_listViewSave ()
700     {
701         $GLOBALS [ 'log' ]->info ( "action_listViewSave" ) ;
702
703         $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
704         $subpanelName = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : null ;
705         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
706         $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName, $subpanelName ) ;
707         $this->view = 'listView' ;
708         $parser->handleSave () ;
709
710     }
711
712     function action_dashletSave () {
713         $this->view = 'dashlet' ;
714         $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
715         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
716         $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
717         $parser->handleSave () ;
718     }
719
720         function action_popupSave(){
721                 $this->view = 'popupview' ;
722         $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
723         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
724         $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
725         $parser->handleSave () ;
726         if(empty($packageName)){
727                 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
728                         global $mod_strings;
729                 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
730                 $repair = new RepairAndClear();
731                         $repair->show_output = false;
732                         $class_name = $GLOBALS [ 'beanList' ] [ $_REQUEST [ 'view_module' ] ] ;
733                         $repair->module_list = array($class_name);
734                         $repair->clearTpls();
735         }
736
737         }
738
739     function action_searchViewSave ()
740     {
741         $packageName = (isset ( $_REQUEST [ 'view_package' ] )) ? $_REQUEST [ 'view_package' ] : null ;
742         require_once 'modules/ModuleBuilder/parsers/views/SearchViewMetaDataParser.php' ;
743         $parser = new SearchViewMetaDataParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
744         $parser->handleSave () ;
745
746
747         //Repair or create a custom SearchFields.php file as needed
748         $module_name = $_REQUEST [ 'view_module' ] ;
749         global $beanList;
750         if (isset($beanList[$module_name]) && $beanList[$module_name]!="") {
751             $objectName = $beanList[$module_name];
752             if($objectName == 'aCase') // Bug 17614 - renamed aCase as Case in vardefs for backwards compatibililty with 451 modules
753             {
754                 $objectName = 'Case';
755             }
756
757             //Load the vardefs for the module to pass to TemplateRange
758             VardefManager::loadVardef($module_name, $objectName, true);
759             global $dictionary;
760             $vardefs = $dictionary[$objectName]['fields'];
761             require_once('modules/DynamicFields/templates/Fields/TemplateRange.php');
762             TemplateRange::repairCustomSearchFields($vardefs, $module_name, $packageName);
763         }
764         $this->view = 'searchView' ;
765     }
766
767     function action_editLabels ()
768     {
769         if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
770         {
771             $this->view = 'modulelabels';
772         }else{ //STUDIO
773             $this->view = 'labels';
774         }
775     }
776
777     function action_get_app_list_string ()
778     {
779         require_once ('include/JSON.php') ;
780         $json = new JSON ( ) ;
781         if (isset ( $_REQUEST [ 'key' ] ) && ! empty ( $_REQUEST [ 'key' ] ))
782         {
783             $key = $_REQUEST [ 'key' ] ;
784             $value = array ( ) ;
785             if (! empty ( $GLOBALS [ 'app_list_strings' ] [ $key ] ))
786             {
787                 $value = $GLOBALS [ 'app_list_strings' ] [ $key ] ;
788             } else
789             {
790                 $package_strings = array ( ) ;
791                 if (! empty ( $_REQUEST [ 'view_package' ] ) && $_REQUEST [ 'view_package' ] != 'studio' && ! empty ( $_REQUEST [ 'view_module' ] ))
792                 {
793                     require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
794                     $mb = new ModuleBuilder ( ) ;
795                     $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
796                     $lang = $GLOBALS [ 'current_language' ] ;
797                     $module->mblanguage->generateAppStrings ( false ) ;
798                     $package_strings = $module->mblanguage->appListStrings [ $lang . '.lang.php' ] ;
799                     if (isset ( $package_strings [ $key ] ) && is_array ( $package_strings [ $key ] ))
800                     {
801                         $value = $package_strings [ $key ] ;
802                     }
803                 }
804             }
805             echo $json->encode ( $value ) ;
806         }
807     }
808
809     function action_history ()
810     {
811         $this->view = 'history' ;
812     }
813
814     function resetmodule()
815     {
816         $this->view = 'resetmodule';
817     }
818
819
820
821 }
822 ?>