]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/controller.php
Release 6.1.4
[Github/sugarcrm.git] / modules / ModuleBuilder / controller.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM 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     function fromModuleBuilder ()
46     {
47         return (isset ( $_REQUEST [ 'MB' ] ) && ($_REQUEST [ 'MB' ] == '1')) ;
48     }
49
50     function process(){
51         $GLOBALS [ 'log' ]->info ( get_class($this).":" ) ;
52         global $current_user;
53         $access = get_admin_modules_for_user($current_user);
54                 if(is_admin($current_user) || (is_admin_for_any_module($current_user) && !isset($_REQUEST['view_module']) && (isset($_REQUEST['action']) && $_REQUEST['action'] != 'package'))||
55           (isset($_REQUEST['view_module']) && (in_array($_REQUEST['view_module'], $access)|| empty($_REQUEST['view_module']))) ||
56           (isset($_REQUEST['type']) && (($_REQUEST['type']=='dropdowns' && is_admin_for_any_module($current_user))||
57           ($_REQUEST['type']=='studio' && displayStudioForCurrentUser() == true))))
58         {
59             $this->hasAccess = true;
60         }
61         else
62         {
63             $this->hasAccess = false;
64         }
65         parent::process();
66     }
67
68
69     function action_editLayout ()
70     {
71         switch ( strtolower ( $_REQUEST [ 'view' ] ))
72         {
73             case MB_EDITVIEW :
74             case MB_DETAILVIEW :
75             case MB_QUICKCREATE :
76                 $this->view = 'layoutView' ;
77                 break ;
78             case MB_LISTVIEW :
79                 $this->view = 'listView' ;
80                 break ;
81             case MB_BASICSEARCH :
82             case MB_ADVANCEDSEARCH :
83                 $this->view = 'searchView' ;
84                 break ;
85             case MB_DASHLET :
86             case MB_DASHLETSEARCH :
87                 $this->view = 'dashlet' ;
88                 break ;
89             case MB_POPUPLIST :
90             case MB_POPUPSEARCH :
91                 $this->view = 'popupview' ;
92                 break ;
93             default :
94                 $GLOBALS [ 'log' ]->fatal ( 'Action = editLayout with unknown view=' . $_REQUEST [ 'view' ] ) ;
95         }
96     }
97
98
99     function action_ViewTree ()
100     {
101         require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
102         switch ( $_REQUEST [ 'tree' ])
103         {
104             case 'ModuleBuilder' :
105                 require_once ('modules/ModuleBuilder/MB/MBPackageTree.php') ;
106                 $mbt = new MBPackageTree ( ) ;
107                 break ;
108             case 'Studio' :
109                 require_once ('modules/ModuleBuilder/Module/StudioTree.php') ;
110                 $mbt = new StudioTree ( ) ;
111         }
112         $ajax = new AjaxCompose ( ) ;
113         $ajax->addSection ( 'west', $mbt->getName (), $mbt->fetchNodes () ) ;
114         echo $ajax->getJavascript () ;
115
116         sugar_cleanup ( true ) ;
117
118     }
119
120     function action_SavePackage ()
121     {
122         $mb = new ModuleBuilder ( ) ;
123         $load = (! empty ( $_REQUEST [ 'original_name' ] )) ? $_REQUEST [ 'original_name' ] : $_REQUEST [ 'name' ] ;
124         if (! empty ( $load ))
125         {
126             $mb->getPackage ( $load ) ;
127
128             if (! empty ( $_REQUEST [ 'duplicate' ] ))
129             {
130                 $result = $mb->packages [ $load ]->copy ( $_REQUEST [ 'name' ] ) ;
131                 $load = $mb->packages [ $load ]->name ;
132                 $mb->getPackage ( $load ) ;
133             }
134             $mb->packages [ $load ]->populateFromPost () ;
135             $mb->packages [ $load ]->loadModules () ;
136             $mb->save () ;
137             if (! empty ( $_REQUEST [ 'original_name' ] ) && $_REQUEST [ 'original_name' ] != $_REQUEST [ 'name' ])
138             {
139                 if (! $mb->packages [ $load ]->rename ( $_REQUEST [ 'name' ] ))
140                 {
141                     $mb->packages [ $load ]->name = $_REQUEST [ 'original_name' ] ;
142                     $_REQUEST [ 'name' ] = $_REQUEST [ 'original_name' ] ;
143                 }
144             }
145             $_REQUEST [ 'package' ] = $_REQUEST [ 'name' ] ;
146             $this->view = 'package' ;
147         }
148     }
149
150     function action_BuildPackage ()
151     {
152         $mb = new ModuleBuilder ( ) ;
153         $load = $_REQUEST [ 'name' ] ;
154         if (! empty ( $load ))
155         {
156             $mb->getPackage ( $load ) ;
157             $mb->packages [ $load ]->build () ;
158         }
159     }
160
161     function action_DeployPackage ()
162     {
163         if(defined('TEMPLATE_URL')){
164                 sugar_cache_reset();
165                 SugarTemplateUtilities::disableCache();
166         }
167         
168         $mb = new ModuleBuilder ( ) ;
169         $load = $_REQUEST [ 'package' ] ;
170         $message = $GLOBALS [ 'mod_strings' ] [ 'LBL_MODULE_DEPLOYED' ] ;
171         if (! empty ( $load ))
172         {
173             $zip = $mb->getPackage ( $load ) ;
174             require_once ('ModuleInstall/PackageManager/PackageManager.php') ;
175             $pm = new PackageManager ( ) ;
176             $info = $mb->packages [ $load ]->build ( false ) ;
177             mkdir_recursive ( $GLOBALS [ 'sugar_config' ] [ 'cache_dir' ] . '/upload/upgrades/module/') ;
178             rename ( $info [ 'zip' ], $GLOBALS [ 'sugar_config' ] [ 'cache_dir' ] . '/' . 'upload/upgrades/module/' . $info [ 'name' ] . '.zip' ) ;
179             copy ( $info [ 'manifest' ], $GLOBALS [ 'sugar_config' ] [ 'cache_dir' ] . '/' . 'upload/upgrades/module/' . $info [ 'name' ] . '-manifest.php' ) ;
180             $_REQUEST [ 'install_file' ] = $GLOBALS [ 'sugar_config' ] [ 'cache_dir' ] . '/' . 'upload/upgrades/module/' . $info [ 'name' ] . '.zip' ;
181             $GLOBALS [ 'mi_remove_tables' ] = false ;
182             $pm->performUninstall ( $load ) ;           
183                          //#23177 , js cache clear
184                          clearAllJsAndJsLangFilesWithoutOutput();
185                 //#30747, clear the cache in memoy
186                 $cache_key = 'app_list_strings.'.$GLOBALS['current_language'];
187                 sugar_cache_clear($cache_key );
188                 sugar_cache_reset();
189                 //clear end
190             $pm->performInstall ( $_REQUEST [ 'install_file' ] , true) ;
191         }
192         echo 'complete' ;
193
194     }
195
196     function action_ExportPackage ()
197     {
198         $mb = new ModuleBuilder ( ) ;
199         $load = $_REQUEST [ 'name' ] ;
200         $author = $_REQUEST [ 'author' ] ;
201         $description = $_REQUEST [ 'description' ] ;
202         $readme = $_REQUEST [ 'readme' ] ;
203         if (! empty ( $load ))
204         {
205             $mb->getPackage ( $load ) ;
206             $mb->packages [ $load ]->author = $author ;
207             $mb->packages [ $load ]->description = $description ;
208             $mb->packages [ $load ]->exportProject () ;
209             $mb->packages [ $load ]->readme = $readme ;
210         }
211     }
212
213     function action_DeletePackage ()
214     {
215         $mb = new ModuleBuilder ( ) ;
216         $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
217         $mb->packages [ $_REQUEST [ 'package' ] ]->delete () ;
218         $this->view = 'deletepackage' ;
219     }
220
221     function action_SaveModule ()
222     {
223         $mb = new ModuleBuilder ( ) ;
224         $load = (! empty ( $_REQUEST [ 'original_name' ] )) ? $_REQUEST [ 'original_name' ] : $_REQUEST [ 'name' ] ;
225         if (! empty ( $load ))
226         {
227             $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
228             $mb->packages [ $_REQUEST [ 'package' ] ]->getModule ( $load ) ;
229             $module = & $mb->packages [ $_REQUEST [ 'package' ] ]->modules [ $load ] ;
230             $module->populateFromPost () ;
231             $mb->save () ;
232             if (! empty ( $_REQUEST [ 'duplicate' ] ))
233             {
234                 $module->copy ( $_REQUEST [ 'name' ] ) ;
235             } else if (! empty ( $_REQUEST [ 'original_name' ] ) && $_REQUEST [ 'original_name' ] != $_REQUEST [ 'name' ])
236             {
237                 if (! $module->rename ( $_REQUEST [ 'name' ] ))
238                 {
239                     $module->name = $_REQUEST [ 'original_name' ] ;
240                     $_REQUEST [ 'name' ] = $_REQUEST [ 'original_name' ] ;
241                 }
242             }
243
244             $_REQUEST [ 'view_package' ] = $_REQUEST [ 'package' ] ;
245             $_REQUEST [ 'view_module' ] = $module->name ;
246             $this->view = 'module' ;
247         }
248     }
249
250     function action_DeleteModule ()
251     {
252         $mb = new ModuleBuilder ( ) ;
253         $module = & $mb->getPackageModule ( $_REQUEST [ 'package' ], $_REQUEST [ 'view_module' ] ) ;
254         $module->delete () ;
255         $this->view = 'package' ;
256     }
257
258     function action_saveLabels ()
259     {
260         require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
261         $parser = new ParserLabel ( $_REQUEST['view_module'] , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
262         $parser->handleSave ( $_REQUEST, $_REQUEST [ 'selected_lang' ] ) ;
263         if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
264         {
265             $this->view = 'modulelabels' ;
266         } else //STUDIO
267         {
268             $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)
269         }
270     }
271
272     function action_SaveLabel ()
273     {
274         if (! empty ( $_REQUEST [ 'view_module' ] ) && !empty($_REQUEST [ 'labelValue' ]))
275         {
276             $_REQUEST [ "label_" . $_REQUEST [ 'label' ] ] = $_REQUEST [ 'labelValue' ] ;
277             require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
278             $parser = new ParserLabel ( $_REQUEST['view_module'] , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
279             $parser->handleSave ( $_REQUEST, $GLOBALS [ 'current_language' ] ) ;
280
281         }
282         $this->view = 'modulefields' ;
283     }
284
285     function action_ExportCustom ()
286     {
287         $modules = $_REQUEST [ 'modules' ] ;
288         $name = $_REQUEST [ 'name' ] ;
289         $author = $_REQUEST [ 'author' ] ;
290         $description = $_REQUEST [ 'description' ] ;
291         ob_clean () ;
292         if (! empty ( $modules ) && ! empty ( $name ))
293         {
294             require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
295             $mb = new MBPackage ( $name ) ;
296             $mb->author = $author ;
297             $mb->description = $description ;
298             $mb->exportCustom ( $modules, true, true ) ;
299         }
300     }
301
302     function action_SaveField ()
303     {
304         require_once ('modules/DynamicFields/FieldCases.php') ;
305         $field = get_widget ( $_REQUEST [ 'type' ] ) ;
306         $_REQUEST [ 'name' ] = trim ( $_POST [ 'name' ] ) ;
307
308         $field->populateFromPost () ;
309
310         if (!isset ( $_REQUEST [ 'view_package' ] ))
311         {
312             require_once ('modules/DynamicFields/DynamicField.php') ;
313             if (! empty ( $_REQUEST [ 'view_module' ] ))
314             {
315                 $module = $_REQUEST [ 'view_module' ] ;
316                 $df = new DynamicField ( $module ) ;
317                 $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
318                 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
319                 $mod = new $class_name ( ) ;
320                 $df->setup ( $mod ) ;
321
322                 $field->save ( $df ) ;
323                 $this->action_SaveLabel () ;
324                 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
325                         global $mod_strings;
326                 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
327                 $repair = new RepairAndClear();
328                         $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
329                         //#28707 ,clear all the js files in cache
330                         $repair->module_list = array();
331                         $repair->clearJsFiles();
332             }
333         } else
334         {
335             $mb = new ModuleBuilder ( ) ;
336             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
337             $field->save ( $module ) ;
338             $module->mbvardefs->save () ;
339             // get the module again to refresh the labels we might have saved with the $field->save (e.g., for address fields)
340             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
341             if (isset ( $_REQUEST [ 'label' ] ) && isset ( $_REQUEST [ 'labelValue' ] ))
342                 $module->setLabel ( $GLOBALS [ 'current_language' ], $_REQUEST [ 'label' ], $_REQUEST [ 'labelValue' ] ) ;
343             $module->save();
344         }
345         $this->view = 'modulefields' ;
346     }
347
348     function action_saveSugarField ()
349     {
350         global $mod_strings;
351         require_once ('modules/DynamicFields/FieldCases.php') ;
352         $field = get_widget ( $_REQUEST [ 'type' ] ) ;
353         $_REQUEST [ 'name' ] = trim ( $_POST [ 'name' ] ) ;
354
355         $field->populateFromPost () ;
356         require_once ('modules/ModuleBuilder/parsers/StandardField.php') ;
357         $module = $_REQUEST [ 'view_module' ] ;
358         $df = new StandardField ( $module ) ;
359         $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
360         require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
361         $mod = new $class_name ( ) ;
362         $df->setup ( $mod ) ;
363         
364         $field->module = $mod;
365         $field->save ( $df ) ;
366         $this->action_SaveLabel () ;
367         
368         $MBmodStrings = $mod_strings;
369         $GLOBALS [ 'mod_strings' ] = return_module_language ( '', 'Administration' ) ;
370         
371         include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
372         $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
373         $_REQUEST['execute_sql'] = true;
374        
375         $repair = new RepairAndClear();
376         $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
377         //#28707 ,clear all the js files in cache
378         $repair->module_list = array();
379         $repair->clearJsFiles();
380         
381          
382         // now clear the cache so that the results are immediately visible
383         include_once ('include/TemplateHandler/TemplateHandler.php') ;
384         TemplateHandler::clearCache ( $module ) ;
385         
386         $GLOBALS [ 'mod_strings' ] = $MBmodStrings;
387     }
388
389     function action_RefreshField ()
390     {
391         require_once ('modules/DynamicFields/FieldCases.php') ;
392         $field = get_widget ( $_POST [ 'type' ] ) ;
393         $field->populateFromPost () ;
394         $this->view = 'modulefield' ;
395     }
396
397     function action_saveVisibility ()
398     {
399                 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
400         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
401         $parser = ParserFactory::getParser ( MB_VISIBILITY, $_REQUEST [ 'view_module' ], $packageName ) ;
402
403         $json = getJSONobj();
404         $visibility_grid = $json->decode(html_entity_decode(rawurldecode($_REQUEST [ 'visibility_grid' ]), ENT_QUOTES) );
405                 $parser->saveVisibility ( $_REQUEST [ 'fieldname' ] , $_REQUEST [ 'trigger' ] , $visibility_grid ) ;
406
407         echo $json->encode(array( "visibility_editor_{$_REQUEST['fieldname']}" => array("action" => "deactivate")));
408     }
409
410         function action_SaveRelationshipLabel (){
411             $selected_lang = (!empty($_REQUEST['relationship_lang'])?$_REQUEST['relationship_lang']:$_SESSION['authenticated_user_language']);
412                  if (empty($_REQUEST [ 'view_package' ])){
413             require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
414             $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
415             if (! empty ( $_REQUEST [ 'relationship_name' ] ))
416                 {
417                     if ($relationship = $relationships->get ( $_REQUEST [ 'relationship_name' ] )){
418                         $metadata = $relationship->buildLabels(true);
419                          require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
420                                 $parser = new ParserLabel ( $_REQUEST['view_module'] ) ;
421                                 $parser->handleSaveRelationshipLabels ( $metadata, $selected_lang ) ;
422                     }
423             }
424         }
425         else {
426             //TODO FOR MB
427         }
428         $this->view = 'relationships' ;
429         }
430         
431     function action_SaveRelationship ()
432     {
433         if(!empty($GLOBALS['current_user']) && empty($GLOBALS['modListHeader']))
434         {
435             $GLOBALS['modListHeader'] = query_module_access_list($GLOBALS['current_user']);
436         }
437
438         if (empty($_REQUEST [ 'view_package' ]))
439         {
440             require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
441             $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
442         } else
443         {
444             $mb = new ModuleBuilder ( ) ;
445             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
446             require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
447             $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
448         }
449
450         $relationships->addFromPost () ;
451         $relationships->save () ;
452         $GLOBALS['log']->debug("\n\nSTART BUILD");
453         if (empty($_REQUEST [ 'view_package' ])) {
454             $relationships->build () ;
455
456             LanguageManager::clearLanguageCache($_REQUEST [ 'view_module' ]);
457         }
458         $GLOBALS['log']->debug("\n\nEND BUILD");
459
460         $this->view = 'relationships' ;
461     }
462
463     function action_DeleteRelationship ()
464     {
465         if (isset ( $_REQUEST [ 'relationship_name' ] ))
466         {
467             if (empty($_REQUEST [ 'view_package' ] ))
468             {
469                 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
470                 if (!empty($_REQUEST['remove_tables']))
471                                     $GLOBALS['mi_remove_tables'] = $_REQUEST['remove_tables'];
472                 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
473             } else
474             {
475                 $mb = new ModuleBuilder ( ) ;
476                 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
477                 require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
478                 $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
479             }
480             $relationships->delete ( $_REQUEST [ 'relationship_name' ] ) ;
481             $relationships->save () ;
482         }
483         $this->view = 'relationships' ;
484     }
485
486     function action_SaveDropDown ()
487     {
488         require_once 'modules/ModuleBuilder/parsers/parser.dropdown.php' ;
489         $parser = new ParserDropDown ( ) ;
490         $parser->saveDropDown ( $_REQUEST ) ;
491         $this->view = 'dropdowns' ;
492     }
493
494     function action_DeleteField ()
495     {
496         require_once ('modules/DynamicFields/FieldCases.php') ;
497         $field = get_widget ( $_POST [ 'type' ] ) ;
498         $field->name = $_REQUEST [ 'name' ] ;
499         if (!isset ( $_REQUEST [ 'view_package' ] ))
500         {
501             if (! empty ( $_REQUEST [ 'name' ] ) && ! empty ( $_REQUEST [ 'view_module' ] ))
502             {
503                 require_once ('modules/DynamicFields/DynamicField.php') ;
504                 $moduleName = $_REQUEST [ 'view_module' ] ;
505                 $class_name = $GLOBALS [ 'beanList' ] [ $moduleName ] ;
506                 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
507                 $seed = new $class_name ( ) ;
508                 $df = new DynamicField ( $moduleName ) ;
509                 $df->setup ( $seed ) ;
510                 //Need to load the entire field_meta_data for some field types
511                 $field = $df->getFieldWidget($moduleName, $field->name);
512                 $field->delete ( $df ) ;
513                 
514                 $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
515                 $_REQUEST['execute_sql'] = true;
516                 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
517                 $repair = new RepairAndClear();
518                 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
519                 require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php' ;
520                 $module = StudioModuleFactory::getStudioModule( $moduleName ) ;
521             }
522         }
523         else
524         {
525             $mb = new ModuleBuilder ( ) ;
526             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
527             $field->delete ( $module ) ;
528             $mb->save () ;
529         }
530         $module->removeFieldFromLayouts( $field->name );
531         $this->view = 'modulefields' ;
532     }
533
534     function action_CloneField ()
535     {
536         $this->view_object_map [ 'field_name' ] = $_REQUEST [ 'name' ] ;
537         $this->view_object_map [ 'is_clone' ] = true ;
538         $this->view = 'modulefield' ;
539     }
540
541     function action_SaveAssistantPref ()
542     {
543         global $current_user ;
544         if (isset ( $_REQUEST [ 'pref_value' ] ))
545         {
546             if ($_REQUEST [ 'pref_value' ] == 'ignore')
547             {
548                 $current_user->setPreference ( 'mb_assist', 'DISABLED', 0, 'Assistant' ) ;
549             } else
550             {
551                 $current_user->setPreference ( 'mb_assist', 'ENABLED', 0, 'Assistant' ) ;
552             }
553             $current_pref = $current_user->getPreference ( 'mb_assist', 'Assistant' ) ;
554             echo "Assistant.processUserPref('$current_pref')" ;
555             sugar_cleanup ( true ) ; //push preferences to DB.
556         }
557     }
558
559     // Studio2 Actions
560
561
562     function action_EditProperty ()
563     {
564         $this->view = 'property' ;
565     }
566
567     function action_saveProperty ()
568     {
569         require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
570         $modules = $_REQUEST['view_module'];
571         if(!empty($_REQUEST['subpanel'])){
572                 $modules = $_REQUEST['subpanel'];
573         }
574         $parser = new ParserLabel ( $modules , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
575         // if no language provided, then use the user's current language which is most likely what they intended
576         $language = (isset($_REQUEST [ 'selected_lang' ])) ? $_REQUEST [ 'selected_lang' ] : $GLOBALS['current_language'] ;
577         $parser->handleSave ( $_REQUEST, $language ) ;
578         $json = getJSONobj();
579         echo $json->encode(array("east" => array("action" => "deactivate")));
580     }
581
582     function action_editModule ()
583     {
584         $this->view = 'module' ;
585     }
586
587     function action_wizard ()
588     {
589         $this->view = 'wizard' ;
590     }
591
592     /**
593      * Receive a layout through $_REQUEST and save it out to the working files directory
594      * Expects a series of $_REQUEST parameters all in the format $_REQUEST['slot-panel#-slot#-property']=value
595      */
596
597     function action_saveLayout ()
598     {
599             $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
600             $this->view = 'layoutview' ;
601         $parser->writeWorkingFile () ;
602     }
603
604     function action_saveAndPublishLayout ()
605     {
606             $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
607             $this->view = 'layoutview' ;
608         $parser->handleSave () ;
609     }
610
611     function action_manageBackups ()
612     {
613
614     }
615
616     function action_listViewSave ()
617     {
618         $GLOBALS [ 'log' ]->info ( "action_listViewSave" ) ;
619
620         $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
621         $subpanelName = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : null ;
622         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
623         $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName, $subpanelName ) ;
624         $this->view = 'listView' ;
625         $parser->handleSave () ;
626         
627     }
628
629     function action_dashletSave () {
630         $this->view = 'dashlet' ;
631         $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
632         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
633         $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
634         $parser->handleSave () ;
635     }
636
637         function action_popupSave(){
638                 $this->view = 'popupview' ;
639         $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
640         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
641         $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
642         $parser->handleSave () ;
643         if(empty($packageName)){
644                 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
645                         global $mod_strings;
646                 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
647                 $repair = new RepairAndClear();
648                         $repair->show_output = false;
649                         $class_name = $GLOBALS [ 'beanList' ] [ $_REQUEST [ 'view_module' ] ] ;
650                         $repair->module_list = array($class_name);
651                         $repair->clearTpls();   
652         }
653         
654         }
655         
656     function action_searchViewSave ()
657     {
658         $packageName = (isset ( $_REQUEST [ 'view_package' ] )) ? $_REQUEST [ 'view_package' ] : null ;
659         require_once 'modules/ModuleBuilder/parsers/views/SearchViewMetaDataParser.php' ;
660         $parser = new SearchViewMetaDataParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
661         $parser->handleSave () ;
662         $this->view = 'searchView' ;
663     }
664
665     function action_editLabels ()
666     {
667         if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
668         {
669             $this->view = 'modulelabels';
670         }else{ //STUDIO
671             $this->view = 'labels';
672         }
673     }
674
675     function action_get_app_list_string ()
676     {
677         require_once ('include/JSON.php') ;
678         $json = new JSON ( ) ;
679         if (isset ( $_REQUEST [ 'key' ] ) && ! empty ( $_REQUEST [ 'key' ] ))
680         {
681             $key = $_REQUEST [ 'key' ] ;
682             $value = array ( ) ;
683             if (! empty ( $GLOBALS [ 'app_list_strings' ] [ $key ] ))
684             {
685                 $value = $GLOBALS [ 'app_list_strings' ] [ $key ] ;
686             } else
687             {
688                 $package_strings = array ( ) ;
689                 if (! empty ( $_REQUEST [ 'view_package' ] ) && $_REQUEST [ 'view_package' ] != 'studio' && ! empty ( $_REQUEST [ 'view_module' ] ))
690                 {
691                     require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
692                     $mb = new ModuleBuilder ( ) ;
693                     $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
694                     $lang = $GLOBALS [ 'current_language' ] ;
695                     $module->mblanguage->generateAppStrings ( false ) ;
696                     $package_strings = $module->mblanguage->appListStrings [ $lang . '.lang.php' ] ;
697                     if (isset ( $package_strings [ $key ] ) && is_array ( $package_strings [ $key ] ))
698                     {
699                         $value = $package_strings [ $key ] ;
700                     }
701                 }
702             }
703             echo $json->encode ( $value ) ;
704         }
705     }
706
707     function action_history ()
708     {
709         $this->view = 'history' ;
710     }
711
712     function resetmodule()
713     {
714         $this->view = 'resetmodule';
715     }
716
717
718
719 }
720 ?>