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