]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/controller.php
Release 6.2.4
[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
549             $relationships->save () ;
550         }
551         $this->view = 'relationships' ;
552     }
553
554     function action_SaveDropDown ()
555     {
556         require_once 'modules/ModuleBuilder/parsers/parser.dropdown.php' ;
557         $parser = new ParserDropDown ( ) ;
558         $parser->saveDropDown ( $_REQUEST ) ;
559         $this->view = 'dropdowns' ;
560     }
561
562     function action_DeleteField ()
563     {
564         require_once ('modules/DynamicFields/FieldCases.php') ;
565         $field = get_widget ( $_REQUEST [ 'type' ] ) ;
566         $field->name = $_REQUEST [ 'name' ] ;
567         if (!isset ( $_REQUEST [ 'view_package' ] ))
568         {
569             if (! empty ( $_REQUEST [ 'name' ] ) && ! empty ( $_REQUEST [ 'view_module' ] ))
570             {
571                 require_once ('modules/DynamicFields/DynamicField.php') ;
572                 $moduleName = $_REQUEST [ 'view_module' ] ;
573                 $class_name = $GLOBALS [ 'beanList' ] [ $moduleName ] ;
574                 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
575                 $seed = new $class_name ( ) ;
576                 $df = new DynamicField ( $moduleName ) ;
577                 $df->setup ( $seed ) ;
578                 //Need to load the entire field_meta_data for some field types
579                 $field = $df->getFieldWidget($moduleName, $field->name);
580                 $field->delete ( $df ) ;
581
582                 $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
583                 $_REQUEST['execute_sql'] = true;
584                 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
585                 $repair = new RepairAndClear();
586                 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
587                 require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php' ;
588                 $module = StudioModuleFactory::getStudioModule( $moduleName ) ;
589             }
590         }
591         else
592         {
593             $mb = new ModuleBuilder ( ) ;
594             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
595             $field->delete ( $module ) ;
596             $mb->save () ;
597         }
598         $module->removeFieldFromLayouts( $field->name );
599         $this->view = 'modulefields' ;
600
601         if (isset($GLOBALS['current_language']) && isset($_REQUEST['label']) &&
602                 isset($_REQUEST['labelValue']) && isset($_REQUEST['view_module'])) {
603             $this->DeleteLabel($GLOBALS['current_language'], $_REQUEST['label'], $_REQUEST['labelValue'], $_REQUEST['view_module']);
604         }
605     }
606
607     function DeleteLabel($language, $label, $labelvalue, $modulename, $basepath = null, $forRelationshipLabel = false)
608     {
609         // remove the label
610         require_once 'modules/ModuleBuilder/parsers/parser.label.php';
611         ParserLabel::removeLabel($language, $label, $labelvalue, $modulename, $basepath, $forRelationshipLabel);
612     }
613
614     function action_CloneField ()
615     {
616         $this->view_object_map [ 'field_name' ] = $_REQUEST [ 'name' ] ;
617         $this->view_object_map [ 'is_clone' ] = true ;
618         $this->view = 'modulefield' ;
619     }
620
621     function action_SaveAssistantPref ()
622     {
623         global $current_user ;
624         if (isset ( $_REQUEST [ 'pref_value' ] ))
625         {
626             if ($_REQUEST [ 'pref_value' ] == 'ignore')
627             {
628                 $current_user->setPreference ( 'mb_assist', 'DISABLED', 0, 'Assistant' ) ;
629             } else
630             {
631                 $current_user->setPreference ( 'mb_assist', 'ENABLED', 0, 'Assistant' ) ;
632             }
633             $current_pref = $current_user->getPreference ( 'mb_assist', 'Assistant' ) ;
634             echo "Assistant.processUserPref('$current_pref')" ;
635             sugar_cleanup ( true ) ; //push preferences to DB.
636         }
637     }
638
639     // Studio2 Actions
640
641
642     function action_EditProperty ()
643     {
644         $this->view = 'property' ;
645     }
646
647     function action_saveProperty ()
648     {
649         require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
650         $modules = $_REQUEST['view_module'];
651         if(!empty($_REQUEST['subpanel'])){
652                 $modules = $_REQUEST['subpanel'];
653         }
654         $parser = new ParserLabel ( $modules , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
655         // if no language provided, then use the user's current language which is most likely what they intended
656         $language = (isset($_REQUEST [ 'selected_lang' ])) ? $_REQUEST [ 'selected_lang' ] : $GLOBALS['current_language'] ;
657         $parser->handleSave ( $_REQUEST, $language ) ;
658         $json = getJSONobj();
659         echo $json->encode(array("east" => array("action" => "deactivate")));
660     }
661
662     function action_editModule ()
663     {
664         $this->view = 'module' ;
665     }
666
667     function action_wizard ()
668     {
669         $this->view = 'wizard' ;
670     }
671
672     /**
673      * Receive a layout through $_REQUEST and save it out to the working files directory
674      * Expects a series of $_REQUEST parameters all in the format $_REQUEST['slot-panel#-slot#-property']=value
675      */
676
677     function action_saveLayout ()
678     {
679             $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
680             $this->view = 'layoutview' ;
681         $parser->writeWorkingFile () ;
682
683         if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
684                 if(strtolower ($parser->_view) == MB_EDITVIEW){
685                         $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
686                         $parser2->setUseTabs($parser->getUseTabs());
687                 $parser2->writeWorkingFile () ;
688                 }
689         }
690     }
691
692     function action_saveAndPublishLayout ()
693     {
694             $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
695             $this->view = 'layoutview' ;
696         $parser->handleSave () ;
697
698         if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
699                 if(strtolower ($parser->_view) == MB_EDITVIEW){
700                         $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
701                         $parser2->setUseTabs($parser->getUseTabs());
702                 $parser2->handleSave () ;
703                 }
704         }
705     }
706
707     function action_manageBackups ()
708     {
709
710     }
711
712     function action_listViewSave ()
713     {
714         $GLOBALS [ 'log' ]->info ( "action_listViewSave" ) ;
715
716         $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
717         $subpanelName = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : null ;
718         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
719         $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName, $subpanelName ) ;
720         $this->view = 'listView' ;
721         $parser->handleSave () ;
722
723     }
724
725     function action_dashletSave () {
726         $this->view = 'dashlet' ;
727         $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
728         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
729         $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
730         $parser->handleSave () ;
731     }
732
733         function action_popupSave(){
734                 $this->view = 'popupview' ;
735         $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
736         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
737         $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
738         $parser->handleSave () ;
739         if(empty($packageName)){
740                 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
741                         global $mod_strings;
742                 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
743                 $repair = new RepairAndClear();
744                         $repair->show_output = false;
745                         $class_name = $GLOBALS [ 'beanList' ] [ $_REQUEST [ 'view_module' ] ] ;
746                         $repair->module_list = array($class_name);
747                         $repair->clearTpls();
748         }
749
750         }
751
752     function action_searchViewSave ()
753     {
754         $packageName = (isset ( $_REQUEST [ 'view_package' ] )) ? $_REQUEST [ 'view_package' ] : null ;
755         require_once 'modules/ModuleBuilder/parsers/views/SearchViewMetaDataParser.php' ;
756         $parser = new SearchViewMetaDataParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
757         $parser->handleSave () ;
758
759
760         //Repair or create a custom SearchFields.php file as needed
761         $module_name = $_REQUEST [ 'view_module' ] ;
762         global $beanList;
763         if (isset($beanList[$module_name]) && $beanList[$module_name]!="") {
764             $objectName = $beanList[$module_name];
765             if($objectName == 'aCase') // Bug 17614 - renamed aCase as Case in vardefs for backwards compatibililty with 451 modules
766             {
767                 $objectName = 'Case';
768             }
769
770             //Load the vardefs for the module to pass to TemplateRange
771             VardefManager::loadVardef($module_name, $objectName, true);
772             global $dictionary;
773             $vardefs = $dictionary[$objectName]['fields'];
774             require_once('modules/DynamicFields/templates/Fields/TemplateRange.php');
775             TemplateRange::repairCustomSearchFields($vardefs, $module_name, $packageName);
776         }
777         $this->view = 'searchView' ;
778     }
779
780     function action_editLabels ()
781     {
782         if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
783         {
784             $this->view = 'modulelabels';
785         }else{ //STUDIO
786             $this->view = 'labels';
787         }
788     }
789
790     function action_get_app_list_string ()
791     {
792         require_once ('include/JSON.php') ;
793         $json = new JSON ( ) ;
794         if (isset ( $_REQUEST [ 'key' ] ) && ! empty ( $_REQUEST [ 'key' ] ))
795         {
796             $key = $_REQUEST [ 'key' ] ;
797             $value = array ( ) ;
798             if (! empty ( $GLOBALS [ 'app_list_strings' ] [ $key ] ))
799             {
800                 $value = $GLOBALS [ 'app_list_strings' ] [ $key ] ;
801             } else
802             {
803                 $package_strings = array ( ) ;
804                 if (! empty ( $_REQUEST [ 'view_package' ] ) && $_REQUEST [ 'view_package' ] != 'studio' && ! empty ( $_REQUEST [ 'view_module' ] ))
805                 {
806                     require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
807                     $mb = new ModuleBuilder ( ) ;
808                     $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
809                     $lang = $GLOBALS [ 'current_language' ] ;
810                     $module->mblanguage->generateAppStrings ( false ) ;
811                     $package_strings = $module->mblanguage->appListStrings [ $lang . '.lang.php' ] ;
812                     if (isset ( $package_strings [ $key ] ) && is_array ( $package_strings [ $key ] ))
813                     {
814                         $value = $package_strings [ $key ] ;
815                     }
816                 }
817             }
818             echo $json->encode ( $value ) ;
819         }
820     }
821
822     function action_history ()
823     {
824         $this->view = 'history' ;
825     }
826
827     function resetmodule()
828     {
829         $this->view = 'resetmodule';
830     }
831
832
833
834 }
835 ?>