2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
37 require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
38 require_once ('modules/ModuleBuilder/parsers/ParserFactory.php') ;
39 require_once ('modules/ModuleBuilder/Module/StudioModuleFactory.php');
40 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
42 class ModuleBuilderController extends SugarController
44 var $action_remap = array ( ) ;
47 * Used by the _getModuleTitleParams() method calls in ModuleBuilder views to get the correct string
48 * for the section you are in
52 public static function getModuleTitle()
56 if(!empty($_REQUEST['type'])){
57 if ( $_REQUEST['type'] == 'studio' ) {
58 return $mod_strings['LBL_STUDIO'];
60 elseif ( $_REQUEST['type'] == 'sugarportal' ) {
61 return $mod_strings['LBL_SUGARPORTAL'];
63 elseif ( $_REQUEST['type'] == 'mb' ) {
64 return $mod_strings['LBL_MODULEBUILDER'];
66 elseif ( $_REQUEST['type'] == 'dropdowns') {
67 return $mod_strings['LBL_DROPDOWNEDITOR'];
69 elseif ( $_REQUEST['type'] == 'home' ) {
70 return $mod_strings['LBL_HOME'];
73 return $mod_strings['LBL_DEVELOPER_TOOLS'];
76 return $mod_strings['LBL_DEVELOPER_TOOLS'];
80 function fromModuleBuilder ()
82 return (isset ( $_REQUEST [ 'MB' ] ) && ($_REQUEST [ 'MB' ] == '1')) ;
86 $GLOBALS [ 'log' ]->info ( get_class($this).":" ) ;
88 $access = $current_user->getDeveloperModules();
89 if($current_user->isAdmin() || ($current_user->isDeveloperForAnyModule() && !isset($_REQUEST['view_module']) && (isset($_REQUEST['action']) && $_REQUEST['action'] != 'package'))||
90 (isset($_REQUEST['view_module']) && (in_array($_REQUEST['view_module'], $access)|| empty($_REQUEST['view_module']))) ||
91 (isset($_REQUEST['type']) && (($_REQUEST['type']=='dropdowns' && $current_user->isDeveloperForAnyModule())||
92 ($_REQUEST['type']=='studio' && displayStudioForCurrentUser() == true))))
94 $this->hasAccess = true;
98 $this->hasAccess = false;
104 function action_editLayout ()
106 $view = strtolower ( $_REQUEST [ 'view' ] );
108 //Check the StudioModule first for mapping overrides
109 if(empty($_REQUEST [ 'view_package' ] )|| $_REQUEST [ 'view_package' ] == "studio")
111 $sm = StudioModuleFactory::getStudioModule($_REQUEST [ 'view_module' ]);
112 foreach($sm->sources as $file => $def)
114 if (!empty($def['type']) && !empty($def['view']) && $def['view'] == $view )
116 $view = $def['type'];
126 case MB_QUICKCREATE :
127 $this->view = 'layoutView' ;
130 $this->view = 'listView' ;
132 case MB_BASICSEARCH :
133 case MB_ADVANCEDSEARCH :
134 $this->view = 'searchView' ;
137 case MB_DASHLETSEARCH :
138 $this->view = 'dashlet' ;
141 case MB_POPUPSEARCH :
142 $this->view = 'popupview' ;
145 $GLOBALS [ 'log' ]->fatal ( 'Action = editLayout with unknown view=' . $_REQUEST [ 'view' ] ) ;
152 function action_ViewTree ()
154 require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
155 switch ( $_REQUEST [ 'tree' ])
157 case 'ModuleBuilder' :
158 require_once ('modules/ModuleBuilder/MB/MBPackageTree.php') ;
159 $mbt = new MBPackageTree ( ) ;
162 require_once ('modules/ModuleBuilder/Module/StudioTree.php') ;
163 $mbt = new StudioTree ( ) ;
165 $ajax = new AjaxCompose ( ) ;
166 $ajax->addSection ( 'west', $mbt->getName (), $mbt->fetchNodes () ) ;
167 echo $ajax->getJavascript () ;
169 sugar_cleanup ( true ) ;
173 function action_SavePackage ()
175 $mb = new ModuleBuilder ( ) ;
176 $load = (! empty ( $_REQUEST [ 'original_name' ] )) ? $_REQUEST [ 'original_name' ] : $_REQUEST [ 'name' ] ;
177 if (! empty ( $load ))
179 $mb->getPackage ( $load ) ;
181 if (! empty ( $_REQUEST [ 'duplicate' ] ))
183 $result = $mb->packages [ $load ]->copy ( $_REQUEST [ 'name' ] ) ;
184 $load = $mb->packages [ $load ]->name ;
185 $mb->getPackage ( $load ) ;
187 $mb->packages [ $load ]->populateFromPost () ;
188 $mb->packages [ $load ]->loadModules () ;
190 if (! empty ( $_REQUEST [ 'original_name' ] ) && $_REQUEST [ 'original_name' ] != $_REQUEST [ 'name' ])
192 if (! $mb->packages [ $load ]->rename ( $_REQUEST [ 'name' ] ))
194 $mb->packages [ $load ]->name = $_REQUEST [ 'original_name' ] ;
195 $_REQUEST [ 'name' ] = $_REQUEST [ 'original_name' ] ;
198 $_REQUEST [ 'package' ] = $_REQUEST [ 'name' ] ;
199 $this->view = 'package' ;
203 function action_BuildPackage ()
205 $mb = new ModuleBuilder ( ) ;
206 $load = $_REQUEST [ 'name' ] ;
207 if (! empty ( $load ))
209 $mb->getPackage ( $load ) ;
210 $mb->packages [ $load ]->build () ;
214 function action_DeployPackage ()
216 global $current_user;
218 if(defined('TEMPLATE_URL')){
220 SugarTemplateUtilities::disableCache();
223 //increment etag for menu so the new module shows up when the AJAX UI reloads
224 $current_user->incrementETag("mainMenuETag");
226 $mb = new ModuleBuilder ( ) ;
227 $load = $_REQUEST [ 'package' ] ;
228 $message = $GLOBALS [ 'mod_strings' ] [ 'LBL_MODULE_DEPLOYED' ] ;
229 if (! empty ( $load ))
231 $zip = $mb->getPackage ( $load ) ;
232 require_once ('ModuleInstall/PackageManager/PackageManager.php') ;
233 $pm = new PackageManager ( ) ;
234 $info = $mb->packages [ $load ]->build ( false ) ;
235 $uploadDir = $pm->upload_dir.'/upgrades/module/';
236 mkdir_recursive ($uploadDir) ;
237 rename ( $info [ 'zip' ], $uploadDir . $info [ 'name' ] . '.zip' ) ;
238 copy ( $info [ 'manifest' ], $uploadDir . $info [ 'name' ] . '-manifest.php' ) ;
239 $_REQUEST [ 'install_file' ] = $uploadDir. $info [ 'name' ] . '.zip' ;
240 $GLOBALS [ 'mi_remove_tables' ] = false ;
241 $pm->performUninstall ( $load ) ;
242 //#23177 , js cache clear
243 clearAllJsAndJsLangFilesWithoutOutput();
244 //#30747, clear the cache in memory
245 $cache_key = 'app_list_strings.'.$GLOBALS['current_language'];
246 sugar_cache_clear($cache_key );
249 $pm->performInstall ( $_REQUEST [ 'install_file' ] , true);
251 //clear the unified_search_module.php file
252 require_once('modules/Home/UnifiedSearchAdvanced.php');
253 UnifiedSearchAdvanced::unlinkUnifiedSearchModulesFile();
257 //clear workflow admin modules cache
258 if (isset($_SESSION['get_workflow_admin_modules_for_user'])) unset($_SESSION['get_workflow_admin_modules_for_user']);
260 //clear "is_admin_for_module" cache
261 $sessionVar = 'MLA_'.$current_user->user_name;
262 foreach ($mb->packages as $package) {
263 foreach ($package->modules as $module) {
264 $_SESSION[$sessionVar][$package->name . '_' . $module->name] = true;
269 $actions = ACLAction::getUserActions($current_user->id, true);
276 function action_ExportPackage ()
278 $mb = new ModuleBuilder ( ) ;
279 $load = $_REQUEST [ 'name' ] ;
280 $author = $_REQUEST [ 'author' ] ;
281 $description = $_REQUEST [ 'description' ] ;
282 $readme = $_REQUEST [ 'readme' ] ;
283 if (! empty ( $load ))
285 $mb->getPackage ( $load ) ;
286 $mb->packages [ $load ]->author = $author ;
287 $mb->packages [ $load ]->description = $description ;
288 $mb->packages [ $load ]->exportProject () ;
289 $mb->packages [ $load ]->readme = $readme ;
293 function action_DeletePackage ()
295 $mb = new ModuleBuilder ( ) ;
296 $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
297 $mb->packages [ $_REQUEST [ 'package' ] ]->delete () ;
298 $this->view = 'deletepackage' ;
301 function action_SaveModule ()
303 $mb = new ModuleBuilder ( ) ;
304 $load = (! empty ( $_REQUEST [ 'original_name' ] )) ? $_REQUEST [ 'original_name' ] : $_REQUEST [ 'name' ] ;
305 if (! empty ( $load ))
307 $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
308 $mb->packages [ $_REQUEST [ 'package' ] ]->getModule ( $load ) ;
309 $module = & $mb->packages [ $_REQUEST [ 'package' ] ]->modules [ $load ] ;
310 $module->populateFromPost () ;
312 if (! empty ( $_REQUEST [ 'duplicate' ] ))
314 $module->copy ( $_REQUEST [ 'name' ] ) ;
315 } else if (! empty ( $_REQUEST [ 'original_name' ] ) && $_REQUEST [ 'original_name' ] != $_REQUEST [ 'name' ])
317 if (! $module->rename ( $_REQUEST [ 'name' ] ))
319 $module->name = $_REQUEST [ 'original_name' ] ;
320 $_REQUEST [ 'name' ] = $_REQUEST [ 'original_name' ] ;
324 $_REQUEST [ 'view_package' ] = $_REQUEST [ 'package' ] ;
325 $_REQUEST [ 'view_module' ] = $module->name ;
326 $this->view = 'module' ;
330 function action_DeleteModule ()
332 $mb = new ModuleBuilder ( ) ;
333 $module = & $mb->getPackageModule ( $_REQUEST [ 'package' ], $_REQUEST [ 'view_module' ] ) ;
335 $this->view = 'package' ;
338 function action_saveLabels ()
340 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
341 $parser = new ParserLabel ( $_REQUEST['view_module'] , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
342 $parser->handleSave ( $_REQUEST, $_REQUEST [ 'selected_lang' ] ) ;
343 if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
345 $this->view = 'modulelabels' ;
348 $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)
352 function action_SaveLabel ()
354 if (! empty ( $_REQUEST [ 'view_module' ] ) && !empty($_REQUEST [ 'labelValue' ]))
356 $_REQUEST [ "label_" . $_REQUEST [ 'label' ] ] = $_REQUEST [ 'labelValue' ] ;
357 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
358 $parser = new ParserLabel ( $_REQUEST['view_module'] , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
359 $parser->handleSave ( $_REQUEST, $GLOBALS [ 'current_language' ] ) ;
362 $this->view = 'modulefields' ;
365 function action_ExportCustom ()
367 $modules = $_REQUEST [ 'modules' ] ;
368 $name = $_REQUEST [ 'name' ] ;
369 $author = $_REQUEST [ 'author' ] ;
370 $description = $_REQUEST [ 'description' ] ;
372 if (! empty ( $modules ) && ! empty ( $name ))
374 require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
375 $mb = new MBPackage ( $name ) ;
376 $mb->author = $author ;
377 $mb->description = $description ;
378 $mb->exportCustom ( $modules, true, true ) ;
382 function action_SaveField ()
384 require_once ('modules/DynamicFields/FieldCases.php') ;
385 $field = get_widget ( $_REQUEST [ 'type' ] ) ;
386 $_REQUEST [ 'name' ] = trim ( $_REQUEST [ 'name' ] ) ;
388 $field->populateFromPost () ;
390 if (!isset ( $_REQUEST [ 'view_package' ] ))
392 require_once ('modules/DynamicFields/DynamicField.php') ;
393 if (! empty ( $_REQUEST [ 'view_module' ] ))
395 $module = $_REQUEST [ 'view_module' ] ;
396 if ( $module == 'Employees' ) {
400 $bean = BeanFactory::getBean($module);
403 $field_defs = $bean->field_defs;
404 if(isset($field_defs[$field->name. '_c']))
406 $GLOBALS['log']->error($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS'] . '[' . $field->name . ']');
407 sugar_die($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS']);
411 $df = new DynamicField ( $module ) ;
412 $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
413 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
414 $mod = new $class_name ( ) ;
415 $df->setup ( $mod ) ;
417 $field->save ( $df ) ;
418 $this->action_SaveLabel () ;
419 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
421 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
422 require_once('ModuleInstall/ModuleInstaller.php');
423 $mi = new ModuleInstaller();
425 $mi->rebuild_extensions();
426 $repair = new RepairAndClear();
428 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
429 if ( $module == 'Users' ) {
430 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array('Employee'), true, false);
434 //#28707 ,clear all the js files in cache
435 $repair->module_list = array();
436 $repair->clearJsFiles();
440 $mb = new ModuleBuilder ( ) ;
441 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
442 $field->save ( $module ) ;
443 $module->mbvardefs->save () ;
444 // get the module again to refresh the labels we might have saved with the $field->save (e.g., for address fields)
445 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
446 if (isset ( $_REQUEST [ 'label' ] ) && isset ( $_REQUEST [ 'labelValue' ] ))
447 $module->setLabel ( $GLOBALS [ 'current_language' ], $_REQUEST [ 'label' ], $_REQUEST [ 'labelValue' ] ) ;
450 $this->view = 'modulefields' ;
453 function action_saveSugarField ()
456 require_once ('modules/DynamicFields/FieldCases.php') ;
458 $field = get_widget ( $_REQUEST [ 'type' ] ) ;
459 $_REQUEST [ 'name' ] = trim ( $_POST [ 'name' ] ) ;
461 $field->populateFromPost () ;
462 require_once ('modules/ModuleBuilder/parsers/StandardField.php') ;
463 $module = $_REQUEST [ 'view_module' ] ;
465 // Need to map Employees -> Users
466 if ( $module=='Employees') {
470 $df = new StandardField ( $module ) ;
471 $mod = BeanFactory::getBean($module);
472 $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
473 $df->setup ( $mod ) ;
475 $field->module = $mod;
476 $field->save ( $df ) ;
477 $this->action_SaveLabel () ;
479 $MBmodStrings = $mod_strings;
480 $GLOBALS [ 'mod_strings' ] = return_module_language ( '', 'Administration' ) ;
482 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
483 $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
484 $_REQUEST['execute_sql'] = true;
486 require_once('ModuleInstall/ModuleInstaller.php');
487 $mi = new ModuleInstaller();
489 $mi->rebuild_extensions();
491 $repair = new RepairAndClear();
492 $repair->repairAndClearAll(array('clearVardefs', 'clearTpls'), array($class_name), true, false);
493 //#28707 ,clear all the js files in cache
494 $repair->module_list = array();
495 $repair->clearJsFiles();
497 // now clear the cache so that the results are immediately visible
498 include_once ('include/TemplateHandler/TemplateHandler.php') ;
499 TemplateHandler::clearCache ( $module ) ;
500 if ( $module == 'Users' ) {
501 TemplateHandler::clearCache('Employees');
504 $GLOBALS [ 'mod_strings' ] = $MBmodStrings;
507 function action_RefreshField ()
509 require_once ('modules/DynamicFields/FieldCases.php') ;
510 $field = get_widget ( $_POST [ 'type' ] ) ;
511 $field->populateFromPost () ;
512 $this->view = 'modulefield' ;
515 function action_saveVisibility ()
517 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
518 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
519 $parser = ParserFactory::getParser ( MB_VISIBILITY, $_REQUEST [ 'view_module' ], $packageName ) ;
521 $json = getJSONobj();
522 $visibility_grid = $json->decode(html_entity_decode(rawurldecode($_REQUEST [ 'visibility_grid' ]), ENT_QUOTES) );
523 $parser->saveVisibility ( $_REQUEST [ 'fieldname' ] , $_REQUEST [ 'trigger' ] , $visibility_grid ) ;
525 echo $json->encode(array( "visibility_editor_{$_REQUEST['fieldname']}" => array("action" => "deactivate")));
528 function action_SaveRelationshipLabel (){
529 $selected_lang = (!empty($_REQUEST['relationship_lang'])?$_REQUEST['relationship_lang']:$_SESSION['authenticated_user_language']);
530 if (empty($_REQUEST [ 'view_package' ])){
531 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
532 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
533 if (! empty ( $_REQUEST [ 'relationship_name' ] ))
535 if ($relationship = $relationships->get ( $_REQUEST [ 'relationship_name' ] )){
536 $metadata = $relationship->buildLabels(true);
537 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
538 $parser = new ParserLabel ( $_REQUEST['view_module'] ) ;
539 $parser->handleSaveRelationshipLabels ( $metadata, $selected_lang ) ;
546 $this->view = 'relationships' ;
549 function action_SaveRelationship ()
551 if(!empty($GLOBALS['current_user']) && empty($GLOBALS['modListHeader']))
553 $GLOBALS['modListHeader'] = query_module_access_list($GLOBALS['current_user']);
556 if (empty($_REQUEST [ 'view_package' ]))
558 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
559 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
562 $mb = new ModuleBuilder ( ) ;
563 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
564 require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
565 $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
568 $relationships->addFromPost () ;
569 $relationships->save () ;
570 $GLOBALS['log']->debug("\n\nSTART BUILD");
571 if (empty($_REQUEST [ 'view_package' ])) {
572 $relationships->build () ;
573 LanguageManager::clearLanguageCache($_REQUEST [ 'view_module' ]);
575 $GLOBALS['log']->debug("\n\nEND BUILD");
576 $this->view = 'relationships' ;
579 function action_DeleteRelationship ()
581 if (isset ( $_REQUEST [ 'relationship_name' ] ))
583 if (empty($_REQUEST [ 'view_package' ] ))
585 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
586 if (!empty($_REQUEST['remove_tables']))
587 $GLOBALS['mi_remove_tables'] = $_REQUEST['remove_tables'];
588 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
591 $mb = new ModuleBuilder ( ) ;
592 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
593 require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
594 $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
596 $relationships->delete ( $_REQUEST [ 'relationship_name' ] ) ;
598 $relationships->save () ;
599 require_once("data/Relationships/RelationshipFactory.php");
600 SugarRelationshipFactory::deleteCache();
602 $this->view = 'relationships' ;
605 function action_SaveDropDown ()
607 require_once 'modules/ModuleBuilder/parsers/parser.dropdown.php' ;
608 $parser = new ParserDropDown ( ) ;
609 $parser->saveDropDown ( $_REQUEST ) ;
610 $this->view = 'dropdowns' ;
613 function action_DeleteField ()
615 require_once ('modules/DynamicFields/FieldCases.php') ;
616 $field = get_widget ( $_REQUEST [ 'type' ] ) ;
617 $field->name = $_REQUEST [ 'name' ] ;
618 if (!isset ( $_REQUEST [ 'view_package' ] ))
620 if (! empty ( $_REQUEST [ 'name' ] ) && ! empty ( $_REQUEST [ 'view_module' ] ))
622 require_once ('modules/DynamicFields/DynamicField.php') ;
623 $moduleName = $_REQUEST [ 'view_module' ] ;
625 // bug 51325 make sure we make this switch or delete will not work
626 if( $moduleName == 'Employees' )
627 $moduleName = 'Users';
629 $class_name = $GLOBALS [ 'beanList' ] [ $moduleName ] ;
630 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
631 $seed = new $class_name ( ) ;
632 $df = new DynamicField ( $moduleName ) ;
633 $df->setup ( $seed ) ;
634 //Need to load the entire field_meta_data for some field types
635 $field = $df->getFieldWidget($moduleName, $field->name);
636 $field->delete ( $df ) ;
638 $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
639 $_REQUEST['execute_sql'] = true;
640 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
641 $repair = new RepairAndClear();
642 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
643 require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php' ;
644 $module = StudioModuleFactory::getStudioModule( $moduleName ) ;
649 $mb = new ModuleBuilder ( ) ;
650 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
651 $field->delete ( $module ) ;
654 $module->removeFieldFromLayouts( $field->name );
655 $this->view = 'modulefields' ;
657 if (isset($GLOBALS['current_language']) && isset($_REQUEST['label']) &&
658 isset($_REQUEST['labelValue']) && isset($_REQUEST['view_module'])) {
659 $this->DeleteLabel($GLOBALS['current_language'], $_REQUEST['label'], $_REQUEST['labelValue'], $_REQUEST['view_module']);
663 function DeleteLabel($language, $label, $labelvalue, $modulename, $basepath = null, $forRelationshipLabel = false)
666 require_once 'modules/ModuleBuilder/parsers/parser.label.php';
667 ParserLabel::removeLabel($language, $label, $labelvalue, $modulename, $basepath, $forRelationshipLabel);
670 function action_CloneField ()
672 $this->view_object_map [ 'field_name' ] = $_REQUEST [ 'name' ] ;
673 $this->view_object_map [ 'is_clone' ] = true ;
674 $this->view = 'modulefield' ;
677 function action_SaveAssistantPref ()
679 global $current_user ;
680 if (isset ( $_REQUEST [ 'pref_value' ] ))
682 if ($_REQUEST [ 'pref_value' ] == 'ignore')
684 $current_user->setPreference ( 'mb_assist', 'DISABLED', 0, 'Assistant' ) ;
687 $current_user->setPreference ( 'mb_assist', 'ENABLED', 0, 'Assistant' ) ;
689 $current_pref = $current_user->getPreference ( 'mb_assist', 'Assistant' ) ;
690 echo "Assistant.processUserPref('$current_pref')" ;
691 sugar_cleanup ( true ) ; //push preferences to DB.
698 function action_EditProperty ()
700 $this->view = 'property' ;
703 function action_saveProperty ()
705 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
706 $modules = $_REQUEST['view_module'];
707 if(!empty($_REQUEST['subpanel'])){
708 $modules = $_REQUEST['subpanel'];
710 $parser = new ParserLabel ( $modules , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
711 // if no language provided, then use the user's current language which is most likely what they intended
712 $language = (isset($_REQUEST [ 'selected_lang' ])) ? $_REQUEST [ 'selected_lang' ] : $GLOBALS['current_language'] ;
713 $parser->handleSave ( $_REQUEST, $language ) ;
714 $json = getJSONobj();
715 echo $json->encode(array("east" => array("action" => "deactivate")));
718 function action_editModule ()
720 $this->view = 'module' ;
723 function action_wizard ()
725 $this->view = 'wizard' ;
729 * Receive a layout through $_REQUEST and save it out to the working files directory
730 * Expects a series of $_REQUEST parameters all in the format $_REQUEST['slot-panel#-slot#-property']=value
733 function action_saveLayout ()
735 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
736 $this->view = 'layoutview' ;
737 $parser->writeWorkingFile () ;
739 if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
740 if(strtolower ($parser->_view) == MB_EDITVIEW){
741 $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
742 $parser2->setUseTabs($parser->getUseTabs());
743 $parser2->writeWorkingFile () ;
748 function action_saveAndPublishLayout ()
750 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
751 $this->view = 'layoutview' ;
752 $parser->handleSave () ;
754 if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
755 if(strtolower ($parser->_view) == MB_EDITVIEW){
756 $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
757 $parser2->setUseTabs($parser->getUseTabs());
758 $parser2->handleSave () ;
763 function action_manageBackups ()
768 function action_listViewSave ()
770 $GLOBALS [ 'log' ]->info ( "action_listViewSave" ) ;
772 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
773 $subpanelName = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : null ;
774 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
775 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName, $subpanelName ) ;
776 $this->view = 'listView' ;
777 $parser->handleSave () ;
781 function action_dashletSave () {
782 $this->view = 'dashlet' ;
783 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
784 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
785 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
786 $parser->handleSave () ;
789 function action_popupSave(){
790 $this->view = 'popupview' ;
791 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
792 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
793 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
794 $parser->handleSave () ;
795 if(empty($packageName)){
796 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
798 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
799 $repair = new RepairAndClear();
800 $repair->show_output = false;
801 $class_name = $GLOBALS [ 'beanList' ] [ $_REQUEST [ 'view_module' ] ] ;
802 $repair->module_list = array($class_name);
803 $repair->clearTpls();
808 function action_searchViewSave ()
810 $packageName = (isset ( $_REQUEST [ 'view_package' ] )) ? $_REQUEST [ 'view_package' ] : null ;
811 require_once 'modules/ModuleBuilder/parsers/views/SearchViewMetaDataParser.php' ;
812 $parser = new SearchViewMetaDataParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
813 $parser->handleSave () ;
816 //Repair or create a custom SearchFields.php file as needed
817 $module_name = $_REQUEST [ 'view_module' ] ;
819 if (isset($beanList[$module_name]) && $beanList[$module_name]!="") {
820 $objectName = BeanFactory::getObjectName($module_name);
822 //Load the vardefs for the module to pass to TemplateRange
823 VardefManager::loadVardef($module_name, $objectName, true);
825 $vardefs = $dictionary[$objectName]['fields'];
826 require_once('modules/DynamicFields/templates/Fields/TemplateRange.php');
827 TemplateRange::repairCustomSearchFields($vardefs, $module_name, $packageName);
829 $this->view = 'searchView' ;
832 function action_editLabels ()
834 if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
836 $this->view = 'modulelabels';
838 $this->view = 'labels';
842 function action_get_app_list_string ()
844 require_once ('include/JSON.php') ;
845 $json = new JSON ( ) ;
846 if (isset ( $_REQUEST [ 'key' ] ) && ! empty ( $_REQUEST [ 'key' ] ))
848 $key = $_REQUEST [ 'key' ] ;
850 if (! empty ( $GLOBALS [ 'app_list_strings' ] [ $key ] ))
852 $value = $GLOBALS [ 'app_list_strings' ] [ $key ] ;
855 $package_strings = array ( ) ;
856 if (! empty ( $_REQUEST [ 'view_package' ] ) && $_REQUEST [ 'view_package' ] != 'studio' && ! empty ( $_REQUEST [ 'view_module' ] ))
858 require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
859 $mb = new ModuleBuilder ( ) ;
860 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
861 $lang = $GLOBALS [ 'current_language' ] ;
862 $module->mblanguage->generateAppStrings ( false ) ;
863 $package_strings = $module->mblanguage->appListStrings [ $lang . '.lang.php' ] ;
864 if (isset ( $package_strings [ $key ] ) && is_array ( $package_strings [ $key ] ))
866 $value = $package_strings [ $key ] ;
870 echo $json->encode ( $value ) ;
874 function action_history ()
876 $this->view = 'history' ;
879 function resetmodule()
881 $this->view = 'resetmodule';
887 * This method handles saving the current user's tabling sorting preferences. It is called when
888 * the user clicks on a column to sort from the fields layout table.
891 function action_savetablesort ()
893 $this->view = 'ajax';
894 global $current_user;
896 if(!empty($current_user) && isset($_REQUEST['column']) && isset($_REQUEST['direction']))
898 $direction = ($_REQUEST['direction'] == 'yui-dt-asc') ? 'ASC' : 'DESC';
899 $valid_columns = array('name', 'label', 'type', 'required', 'unified_search', 'custom');
900 $key = in_array($_REQUEST['column'], $valid_columns) ? $_REQUEST['column'] : 'name';
901 $val = array('key'=>$key, 'direction'=>$direction);
902 $current_user->setPreference('fieldsTableColumn', getJSONobj()->encode($val), 0, 'ModuleBuilder');