]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/controller.php
Release 6.2.1
[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         echo 'complete' ;
231
232     }
233
234     function action_ExportPackage ()
235     {
236         $mb = new ModuleBuilder ( ) ;
237         $load = $_REQUEST [ 'name' ] ;
238         $author = $_REQUEST [ 'author' ] ;
239         $description = $_REQUEST [ 'description' ] ;
240         $readme = $_REQUEST [ 'readme' ] ;
241         if (! empty ( $load ))
242         {
243             $mb->getPackage ( $load ) ;
244             $mb->packages [ $load ]->author = $author ;
245             $mb->packages [ $load ]->description = $description ;
246             $mb->packages [ $load ]->exportProject () ;
247             $mb->packages [ $load ]->readme = $readme ;
248         }       
249     }
250
251     function action_DeletePackage ()
252     {
253         $mb = new ModuleBuilder ( ) ;
254         $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
255         $mb->packages [ $_REQUEST [ 'package' ] ]->delete () ;
256         $this->view = 'deletepackage' ;
257     }
258
259     function action_SaveModule ()
260     {
261         $mb = new ModuleBuilder ( ) ;
262         $load = (! empty ( $_REQUEST [ 'original_name' ] )) ? $_REQUEST [ 'original_name' ] : $_REQUEST [ 'name' ] ;
263         if (! empty ( $load ))
264         {
265             $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
266             $mb->packages [ $_REQUEST [ 'package' ] ]->getModule ( $load ) ;
267             $module = & $mb->packages [ $_REQUEST [ 'package' ] ]->modules [ $load ] ;
268             $module->populateFromPost () ;
269             $mb->save () ;
270             if (! empty ( $_REQUEST [ 'duplicate' ] ))
271             {
272                 $module->copy ( $_REQUEST [ 'name' ] ) ;
273             } else if (! empty ( $_REQUEST [ 'original_name' ] ) && $_REQUEST [ 'original_name' ] != $_REQUEST [ 'name' ])
274             {
275                 if (! $module->rename ( $_REQUEST [ 'name' ] ))
276                 {
277                     $module->name = $_REQUEST [ 'original_name' ] ;
278                     $_REQUEST [ 'name' ] = $_REQUEST [ 'original_name' ] ;
279                 }
280             }
281
282             $_REQUEST [ 'view_package' ] = $_REQUEST [ 'package' ] ;
283             $_REQUEST [ 'view_module' ] = $module->name ;
284             $this->view = 'module' ;
285         }
286     }
287
288     function action_DeleteModule ()
289     {
290         $mb = new ModuleBuilder ( ) ;
291         $module = & $mb->getPackageModule ( $_REQUEST [ 'package' ], $_REQUEST [ 'view_module' ] ) ;
292         $module->delete () ;
293         $this->view = 'package' ;
294     }
295
296     function action_saveLabels ()
297     {
298         require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
299         $parser = new ParserLabel ( $_REQUEST['view_module'] , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
300         $parser->handleSave ( $_REQUEST, $_REQUEST [ 'selected_lang' ] ) ;
301         if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
302         {
303             $this->view = 'modulelabels' ;
304         } else //STUDIO
305         {
306             $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)
307         }
308     }
309
310     function action_SaveLabel ()
311     {
312         if (! empty ( $_REQUEST [ 'view_module' ] ) && !empty($_REQUEST [ 'labelValue' ]))
313         {
314             $_REQUEST [ "label_" . $_REQUEST [ 'label' ] ] = $_REQUEST [ 'labelValue' ] ;
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, $GLOBALS [ 'current_language' ] ) ;
318
319         }
320         $this->view = 'modulefields' ;
321     }
322
323     function action_ExportCustom ()
324     {
325         $modules = $_REQUEST [ 'modules' ] ;
326         $name = $_REQUEST [ 'name' ] ;
327         $author = $_REQUEST [ 'author' ] ;
328         $description = $_REQUEST [ 'description' ] ;
329         ob_clean () ;
330         if (! empty ( $modules ) && ! empty ( $name ))
331         {
332             require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
333             $mb = new MBPackage ( $name ) ;
334             $mb->author = $author ;
335             $mb->description = $description ;
336             $mb->exportCustom ( $modules, true, true ) ;
337         }
338     }
339
340     function action_SaveField ()
341     {
342         require_once ('modules/DynamicFields/FieldCases.php') ;
343         $field = get_widget ( $_REQUEST [ 'type' ] ) ;
344         $_REQUEST [ 'name' ] = trim ( $_REQUEST [ 'name' ] ) ;
345
346         $field->populateFromPost () ;
347
348         if (!isset ( $_REQUEST [ 'view_package' ] ))
349         {
350             require_once ('modules/DynamicFields/DynamicField.php') ;
351             if (! empty ( $_REQUEST [ 'view_module' ] ))
352             {
353                 $module = $_REQUEST [ 'view_module' ] ;
354                 
355                 $bean = loadBean($module);
356                 if(!empty($bean))
357                 {
358                         $field_defs = $bean->field_defs;          
359                         if(isset($field_defs[$field->name. '_c']))
360                         {
361                                                 $GLOBALS['log']->error($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS'] . '[' . $field->name . ']');
362                                                 sugar_die($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS']);
363                         }
364                 }                
365                 
366                 $df = new DynamicField ( $module ) ;
367                 $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
368                 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
369                 $mod = new $class_name ( ) ;
370                 $df->setup ( $mod ) ;
371
372                 $field->save ( $df ) ;
373                 $this->action_SaveLabel () ;
374                 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
375                         global $mod_strings;
376                 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
377                 $repair = new RepairAndClear();
378                         $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
379                         //#28707 ,clear all the js files in cache
380                         $repair->module_list = array();
381                         $repair->clearJsFiles();
382             }
383         } else
384         {
385             $mb = new ModuleBuilder ( ) ;
386             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
387             $field->save ( $module ) ;
388             $module->mbvardefs->save () ;
389             // get the module again to refresh the labels we might have saved with the $field->save (e.g., for address fields)
390             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
391             if (isset ( $_REQUEST [ 'label' ] ) && isset ( $_REQUEST [ 'labelValue' ] ))
392                 $module->setLabel ( $GLOBALS [ 'current_language' ], $_REQUEST [ 'label' ], $_REQUEST [ 'labelValue' ] ) ;
393             $module->save();
394         }
395         $this->view = 'modulefields' ;
396     }
397
398     function action_saveSugarField ()
399     {
400         global $mod_strings;
401         require_once ('modules/DynamicFields/FieldCases.php') ;
402         $field = get_widget ( $_REQUEST [ 'type' ] ) ;
403         $_REQUEST [ 'name' ] = trim ( $_POST [ 'name' ] ) ;
404
405         $field->populateFromPost () ;
406         require_once ('modules/ModuleBuilder/parsers/StandardField.php') ;
407         $module = $_REQUEST [ 'view_module' ] ;
408         $df = new StandardField ( $module ) ;
409         $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
410         require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
411         $mod = new $class_name ( ) ;
412         $df->setup ( $mod ) ;
413         
414         $field->module = $mod;
415         $field->save ( $df ) ;
416         $this->action_SaveLabel () ;
417         
418         $MBmodStrings = $mod_strings;
419         $GLOBALS [ 'mod_strings' ] = return_module_language ( '', 'Administration' ) ;
420         
421         include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
422         $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
423         $_REQUEST['execute_sql'] = true;
424        
425         $repair = new RepairAndClear();
426         $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
427         //#28707 ,clear all the js files in cache
428         $repair->module_list = array();
429         $repair->clearJsFiles();
430         
431          
432         // now clear the cache so that the results are immediately visible
433         include_once ('include/TemplateHandler/TemplateHandler.php') ;
434         TemplateHandler::clearCache ( $module ) ;
435         
436         $GLOBALS [ 'mod_strings' ] = $MBmodStrings;
437     }
438
439     function action_RefreshField ()
440     {
441         require_once ('modules/DynamicFields/FieldCases.php') ;
442         $field = get_widget ( $_POST [ 'type' ] ) ;
443         $field->populateFromPost () ;
444         $this->view = 'modulefield' ;
445     }
446
447     function action_saveVisibility ()
448     {
449                 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
450         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
451         $parser = ParserFactory::getParser ( MB_VISIBILITY, $_REQUEST [ 'view_module' ], $packageName ) ;
452
453         $json = getJSONobj();
454         $visibility_grid = $json->decode(html_entity_decode(rawurldecode($_REQUEST [ 'visibility_grid' ]), ENT_QUOTES) );
455                 $parser->saveVisibility ( $_REQUEST [ 'fieldname' ] , $_REQUEST [ 'trigger' ] , $visibility_grid ) ;
456
457         echo $json->encode(array( "visibility_editor_{$_REQUEST['fieldname']}" => array("action" => "deactivate")));
458     }
459
460         function action_SaveRelationshipLabel (){
461             $selected_lang = (!empty($_REQUEST['relationship_lang'])?$_REQUEST['relationship_lang']:$_SESSION['authenticated_user_language']);
462                  if (empty($_REQUEST [ 'view_package' ])){
463             require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
464             $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
465             if (! empty ( $_REQUEST [ 'relationship_name' ] ))
466                 {
467                     if ($relationship = $relationships->get ( $_REQUEST [ 'relationship_name' ] )){
468                         $metadata = $relationship->buildLabels(true);
469                          require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
470                                 $parser = new ParserLabel ( $_REQUEST['view_module'] ) ;
471                                 $parser->handleSaveRelationshipLabels ( $metadata, $selected_lang ) ;
472                     }
473             }
474         }
475         else {
476             //TODO FOR MB
477         }
478         $this->view = 'relationships' ;
479         }
480         
481     function action_SaveRelationship ()
482     {
483         if(!empty($GLOBALS['current_user']) && empty($GLOBALS['modListHeader']))
484         {
485             $GLOBALS['modListHeader'] = query_module_access_list($GLOBALS['current_user']);
486         }
487
488         if (empty($_REQUEST [ 'view_package' ]))
489         {
490             require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
491             $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
492         } else
493         {
494             $mb = new ModuleBuilder ( ) ;
495             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
496             require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
497             $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
498         }
499
500         $relationships->addFromPost () ;
501         $relationships->save () ;
502         $GLOBALS['log']->debug("\n\nSTART BUILD");
503         if (empty($_REQUEST [ 'view_package' ])) {
504             $relationships->build () ;
505
506             LanguageManager::clearLanguageCache($_REQUEST [ 'view_module' ]);
507         }
508         $GLOBALS['log']->debug("\n\nEND BUILD");
509
510         $this->view = 'relationships' ;
511     }
512
513     function action_DeleteRelationship ()
514     {
515         if (isset ( $_REQUEST [ 'relationship_name' ] ))
516         {
517             if (empty($_REQUEST [ 'view_package' ] ))
518             {
519                 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
520                 if (!empty($_REQUEST['remove_tables']))
521                                     $GLOBALS['mi_remove_tables'] = $_REQUEST['remove_tables'];
522                 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
523             } else
524             {
525                 $mb = new ModuleBuilder ( ) ;
526                 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
527                 require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
528                 $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
529             }
530             $relationships->delete ( $_REQUEST [ 'relationship_name' ] ) ;
531             $relationships->save () ;
532         }
533         $this->view = 'relationships' ;
534     }
535
536     function action_SaveDropDown ()
537     {
538         require_once 'modules/ModuleBuilder/parsers/parser.dropdown.php' ;
539         $parser = new ParserDropDown ( ) ;
540         $parser->saveDropDown ( $_REQUEST ) ;
541         $this->view = 'dropdowns' ;
542     }
543
544     function action_DeleteField ()
545     {
546         require_once ('modules/DynamicFields/FieldCases.php') ;
547         $field = get_widget ( $_REQUEST [ 'type' ] ) ;
548         $field->name = $_REQUEST [ 'name' ] ;
549         if (!isset ( $_REQUEST [ 'view_package' ] ))
550         {
551             if (! empty ( $_REQUEST [ 'name' ] ) && ! empty ( $_REQUEST [ 'view_module' ] ))
552             {
553                 require_once ('modules/DynamicFields/DynamicField.php') ;
554                 $moduleName = $_REQUEST [ 'view_module' ] ;
555                 $class_name = $GLOBALS [ 'beanList' ] [ $moduleName ] ;
556                 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
557                 $seed = new $class_name ( ) ;
558                 $df = new DynamicField ( $moduleName ) ;
559                 $df->setup ( $seed ) ;
560                 //Need to load the entire field_meta_data for some field types
561                 $field = $df->getFieldWidget($moduleName, $field->name);
562                 $field->delete ( $df ) ;
563                 
564                 $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
565                 $_REQUEST['execute_sql'] = true;
566                 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
567                 $repair = new RepairAndClear();
568                 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
569                 require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php' ;
570                 $module = StudioModuleFactory::getStudioModule( $moduleName ) ;
571             }
572         }
573         else
574         {
575             $mb = new ModuleBuilder ( ) ;
576             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
577             $field->delete ( $module ) ;
578             $mb->save () ;
579         }
580         $module->removeFieldFromLayouts( $field->name );
581         $this->view = 'modulefields' ;
582     }
583
584     function action_CloneField ()
585     {
586         $this->view_object_map [ 'field_name' ] = $_REQUEST [ 'name' ] ;
587         $this->view_object_map [ 'is_clone' ] = true ;
588         $this->view = 'modulefield' ;
589     }
590
591     function action_SaveAssistantPref ()
592     {
593         global $current_user ;
594         if (isset ( $_REQUEST [ 'pref_value' ] ))
595         {
596             if ($_REQUEST [ 'pref_value' ] == 'ignore')
597             {
598                 $current_user->setPreference ( 'mb_assist', 'DISABLED', 0, 'Assistant' ) ;
599             } else
600             {
601                 $current_user->setPreference ( 'mb_assist', 'ENABLED', 0, 'Assistant' ) ;
602             }
603             $current_pref = $current_user->getPreference ( 'mb_assist', 'Assistant' ) ;
604             echo "Assistant.processUserPref('$current_pref')" ;
605             sugar_cleanup ( true ) ; //push preferences to DB.
606         }
607     }
608
609     // Studio2 Actions
610
611
612     function action_EditProperty ()
613     {
614         $this->view = 'property' ;
615     }
616
617     function action_saveProperty ()
618     {
619         require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
620         $modules = $_REQUEST['view_module'];
621         if(!empty($_REQUEST['subpanel'])){
622                 $modules = $_REQUEST['subpanel'];
623         }
624         $parser = new ParserLabel ( $modules , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
625         // if no language provided, then use the user's current language which is most likely what they intended
626         $language = (isset($_REQUEST [ 'selected_lang' ])) ? $_REQUEST [ 'selected_lang' ] : $GLOBALS['current_language'] ;
627         $parser->handleSave ( $_REQUEST, $language ) ;
628         $json = getJSONobj();
629         echo $json->encode(array("east" => array("action" => "deactivate")));
630     }
631
632     function action_editModule ()
633     {
634         $this->view = 'module' ;
635     }
636
637     function action_wizard ()
638     {
639         $this->view = 'wizard' ;
640     }
641
642     /**
643      * Receive a layout through $_REQUEST and save it out to the working files directory
644      * Expects a series of $_REQUEST parameters all in the format $_REQUEST['slot-panel#-slot#-property']=value
645      */
646
647     function action_saveLayout ()
648     {
649             $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
650             $this->view = 'layoutview' ;
651         $parser->writeWorkingFile () ;
652         
653         if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
654                 if(strtolower ($parser->_view) == MB_EDITVIEW){
655                         $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
656                         $parser2->setUseTabs($parser->getUseTabs());
657                 $parser2->writeWorkingFile () ;
658                 }
659         }
660     }
661
662     function action_saveAndPublishLayout ()
663     {
664             $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
665             $this->view = 'layoutview' ;
666         $parser->handleSave () ;
667         
668         if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
669                 if(strtolower ($parser->_view) == MB_EDITVIEW){
670                         $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
671                         $parser2->setUseTabs($parser->getUseTabs());
672                 $parser2->handleSave () ;
673                 }
674         }
675     }
676
677     function action_manageBackups ()
678     {
679
680     }
681
682     function action_listViewSave ()
683     {
684         $GLOBALS [ 'log' ]->info ( "action_listViewSave" ) ;
685
686         $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
687         $subpanelName = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : null ;
688         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
689         $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName, $subpanelName ) ;
690         $this->view = 'listView' ;
691         $parser->handleSave () ;
692         
693     }
694
695     function action_dashletSave () {
696         $this->view = 'dashlet' ;
697         $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
698         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
699         $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
700         $parser->handleSave () ;
701     }
702
703         function action_popupSave(){
704                 $this->view = 'popupview' ;
705         $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
706         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
707         $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
708         $parser->handleSave () ;
709         if(empty($packageName)){
710                 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
711                         global $mod_strings;
712                 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
713                 $repair = new RepairAndClear();
714                         $repair->show_output = false;
715                         $class_name = $GLOBALS [ 'beanList' ] [ $_REQUEST [ 'view_module' ] ] ;
716                         $repair->module_list = array($class_name);
717                         $repair->clearTpls();   
718         }
719         
720         }
721         
722     function action_searchViewSave ()
723     {
724         $packageName = (isset ( $_REQUEST [ 'view_package' ] )) ? $_REQUEST [ 'view_package' ] : null ;
725         require_once 'modules/ModuleBuilder/parsers/views/SearchViewMetaDataParser.php' ;
726         $parser = new SearchViewMetaDataParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
727         $parser->handleSave () ;
728         $this->view = 'searchView' ;
729     }
730
731     function action_editLabels ()
732     {
733         if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
734         {
735             $this->view = 'modulelabels';
736         }else{ //STUDIO
737             $this->view = 'labels';
738         }
739     }
740
741     function action_get_app_list_string ()
742     {
743         require_once ('include/JSON.php') ;
744         $json = new JSON ( ) ;
745         if (isset ( $_REQUEST [ 'key' ] ) && ! empty ( $_REQUEST [ 'key' ] ))
746         {
747             $key = $_REQUEST [ 'key' ] ;
748             $value = array ( ) ;
749             if (! empty ( $GLOBALS [ 'app_list_strings' ] [ $key ] ))
750             {
751                 $value = $GLOBALS [ 'app_list_strings' ] [ $key ] ;
752             } else
753             {
754                 $package_strings = array ( ) ;
755                 if (! empty ( $_REQUEST [ 'view_package' ] ) && $_REQUEST [ 'view_package' ] != 'studio' && ! empty ( $_REQUEST [ 'view_module' ] ))
756                 {
757                     require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
758                     $mb = new ModuleBuilder ( ) ;
759                     $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
760                     $lang = $GLOBALS [ 'current_language' ] ;
761                     $module->mblanguage->generateAppStrings ( false ) ;
762                     $package_strings = $module->mblanguage->appListStrings [ $lang . '.lang.php' ] ;
763                     if (isset ( $package_strings [ $key ] ) && is_array ( $package_strings [ $key ] ))
764                     {
765                         $value = $package_strings [ $key ] ;
766                     }
767                 }
768             }
769             echo $json->encode ( $value ) ;
770         }
771     }
772
773     function action_history ()
774     {
775         $this->view = 'history' ;
776     }
777     
778     function resetmodule()
779     {
780         $this->view = 'resetmodule';
781     }
782
783
784
785 }
786 ?>