2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 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' ;
360 $relate_arr = array('Users' => 'Employees',
361 'Employees' => 'Users');
362 $module = $_REQUEST['view_module'];
363 array_push($modules, $module);
364 if ( array_key_exists($module, $relate_arr))
366 array_push($modules, $relate_arr[$module]);
369 foreach ($modules as $key)
371 $req['view_module'] = $key;
372 $parser = new ParserLabel($req['view_module'], isset($req['view_package']) ? $req['view_package'] : null);
373 $parser->handleSave($req, $GLOBALS['current_language']);
376 $this->view = 'modulefields' ;
379 function action_ExportCustom ()
381 $modules = $_REQUEST [ 'modules' ] ;
382 $name = $_REQUEST [ 'name' ] ;
383 $author = $_REQUEST [ 'author' ] ;
384 $description = $_REQUEST [ 'description' ] ;
386 if (! empty ( $modules ) && ! empty ( $name ))
388 require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
389 $mb = new MBPackage ( $name ) ;
390 $mb->author = $author ;
391 $mb->description = $description ;
392 $mb->exportCustom ( $modules, true, true ) ;
396 function action_SaveField ()
398 require_once ('modules/DynamicFields/FieldCases.php') ;
399 $field = get_widget ( $_REQUEST [ 'type' ] ) ;
400 $_REQUEST [ 'name' ] = trim ( $_REQUEST [ 'name' ] ) ;
402 $field->populateFromPost () ;
404 if (!isset ( $_REQUEST [ 'view_package' ] ))
406 require_once ('modules/DynamicFields/DynamicField.php') ;
407 if (! empty ( $_REQUEST [ 'view_module' ] ))
409 $module = $_REQUEST [ 'view_module' ] ;
410 if ( $module == 'Employees' ) {
414 $bean = BeanFactory::getBean($module);
417 $field_defs = $bean->field_defs;
418 if(isset($field_defs[$field->name. '_c']))
420 $GLOBALS['log']->error($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS'] . '[' . $field->name . ']');
421 sugar_die($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS']);
425 $df = new DynamicField ( $module ) ;
426 $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
427 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
428 $mod = new $class_name ( ) ;
429 $df->setup ( $mod ) ;
431 $field->save ( $df ) ;
432 $this->action_SaveLabel () ;
433 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
435 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
436 require_once('ModuleInstall/ModuleInstaller.php');
437 $mi = new ModuleInstaller();
439 $mi->rebuild_extensions();
440 $repair = new RepairAndClear();
442 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
443 if ( $module == 'Users' ) {
444 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array('Employee'), true, false);
448 //#28707 ,clear all the js files in cache
449 $repair->module_list = array();
450 $repair->clearJsFiles();
454 $mb = new ModuleBuilder ( ) ;
455 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
456 $field->save ( $module ) ;
457 $module->mbvardefs->save () ;
458 // get the module again to refresh the labels we might have saved with the $field->save (e.g., for address fields)
459 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
460 if (isset ( $_REQUEST [ 'label' ] ) && isset ( $_REQUEST [ 'labelValue' ] ))
461 $module->setLabel ( $GLOBALS [ 'current_language' ], $_REQUEST [ 'label' ], $_REQUEST [ 'labelValue' ] ) ;
464 $this->view = 'modulefields' ;
467 function action_saveSugarField ()
470 require_once ('modules/DynamicFields/FieldCases.php') ;
472 $field = get_widget ( $_REQUEST [ 'type' ] ) ;
473 $_REQUEST [ 'name' ] = trim ( $_POST [ 'name' ] ) ;
475 $field->populateFromPost () ;
476 require_once ('modules/ModuleBuilder/parsers/StandardField.php') ;
477 $module = $_REQUEST [ 'view_module' ] ;
479 // Need to map Employees -> Users
480 if ( $module=='Employees') {
484 $df = new StandardField ( $module ) ;
485 $mod = BeanFactory::getBean($module);
486 $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
487 $df->setup ( $mod ) ;
489 $field->module = $mod;
490 $field->save ( $df ) ;
491 $this->action_SaveLabel () ;
493 $MBmodStrings = $mod_strings;
494 $GLOBALS [ 'mod_strings' ] = return_module_language ( '', 'Administration' ) ;
496 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
497 $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
498 $_REQUEST['execute_sql'] = true;
500 require_once('ModuleInstall/ModuleInstaller.php');
501 $mi = new ModuleInstaller();
503 $mi->rebuild_extensions();
505 $repair = new RepairAndClear();
506 $repair->repairAndClearAll(array('clearVardefs', 'clearTpls'), array($class_name), true, false);
507 //#28707 ,clear all the js files in cache
508 $repair->module_list = array();
509 $repair->clearJsFiles();
511 // now clear the cache so that the results are immediately visible
512 include_once ('include/TemplateHandler/TemplateHandler.php') ;
513 TemplateHandler::clearCache ( $module ) ;
514 if ( $module == 'Users' ) {
515 TemplateHandler::clearCache('Employees');
518 $GLOBALS [ 'mod_strings' ] = $MBmodStrings;
521 function action_RefreshField ()
523 require_once ('modules/DynamicFields/FieldCases.php') ;
524 $field = get_widget ( $_POST [ 'type' ] ) ;
525 $field->populateFromPost () ;
526 $this->view = 'modulefield' ;
529 function action_saveVisibility ()
531 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
532 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
533 $parser = ParserFactory::getParser ( MB_VISIBILITY, $_REQUEST [ 'view_module' ], $packageName ) ;
535 $json = getJSONobj();
536 $visibility_grid = $json->decode(html_entity_decode(rawurldecode($_REQUEST [ 'visibility_grid' ]), ENT_QUOTES) );
537 $parser->saveVisibility ( $_REQUEST [ 'fieldname' ] , $_REQUEST [ 'trigger' ] , $visibility_grid ) ;
539 echo $json->encode(array( "visibility_editor_{$_REQUEST['fieldname']}" => array("action" => "deactivate")));
542 function action_SaveRelationshipLabel (){
543 $selected_lang = (!empty($_REQUEST['relationship_lang'])?$_REQUEST['relationship_lang']:$_SESSION['authenticated_user_language']);
544 if (empty($_REQUEST [ 'view_package' ])){
545 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
546 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
547 if (! empty ( $_REQUEST [ 'relationship_name' ] ))
549 if ($relationship = $relationships->get ( $_REQUEST [ 'relationship_name' ] )){
550 $metadata = $relationship->buildLabels(true);
551 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
552 $parser = new ParserLabel ( $_REQUEST['view_module'] ) ;
553 $parser->handleSaveRelationshipLabels ( $metadata, $selected_lang ) ;
560 $this->view = 'relationships' ;
563 function action_SaveRelationship ()
565 if(!empty($GLOBALS['current_user']) && empty($GLOBALS['modListHeader']))
567 $GLOBALS['modListHeader'] = query_module_access_list($GLOBALS['current_user']);
570 if (empty($_REQUEST [ 'view_package' ]))
572 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
573 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
576 $mb = new ModuleBuilder ( ) ;
577 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
578 require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
579 $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
582 $relationships->addFromPost () ;
583 $relationships->save () ;
584 $GLOBALS['log']->debug("\n\nSTART BUILD");
585 if (empty($_REQUEST [ 'view_package' ])) {
586 $relationships->build () ;
587 LanguageManager::clearLanguageCache($_REQUEST [ 'view_module' ]);
589 $GLOBALS['log']->debug("\n\nEND BUILD");
590 $this->view = 'relationships' ;
593 function action_DeleteRelationship ()
595 if (isset ( $_REQUEST [ 'relationship_name' ] ))
597 if (empty($_REQUEST [ 'view_package' ] ))
599 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
600 if (!empty($_REQUEST['remove_tables']))
601 $GLOBALS['mi_remove_tables'] = $_REQUEST['remove_tables'];
602 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
605 $mb = new ModuleBuilder ( ) ;
606 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
607 require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
608 $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
610 $relationships->delete ( $_REQUEST [ 'relationship_name' ] ) ;
612 $relationships->save () ;
613 require_once("data/Relationships/RelationshipFactory.php");
614 SugarRelationshipFactory::deleteCache();
616 $this->view = 'relationships' ;
619 function action_SaveDropDown ()
621 require_once 'modules/ModuleBuilder/parsers/parser.dropdown.php' ;
622 $parser = new ParserDropDown ( ) ;
623 $parser->saveDropDown ( $_REQUEST ) ;
624 $this->view = 'dropdowns' ;
627 function action_DeleteField ()
629 require_once ('modules/DynamicFields/FieldCases.php') ;
630 $field = get_widget ( $_REQUEST [ 'type' ] ) ;
631 $field->name = $_REQUEST [ 'name' ] ;
632 if (!isset ( $_REQUEST [ 'view_package' ] ))
634 if (! empty ( $_REQUEST [ 'name' ] ) && ! empty ( $_REQUEST [ 'view_module' ] ))
636 require_once ('modules/DynamicFields/DynamicField.php') ;
637 $moduleName = $_REQUEST [ 'view_module' ] ;
639 // bug 51325 make sure we make this switch or delete will not work
640 if( $moduleName == 'Employees' )
641 $moduleName = 'Users';
643 $class_name = $GLOBALS [ 'beanList' ] [ $moduleName ] ;
644 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
645 $seed = new $class_name ( ) ;
646 $df = new DynamicField ( $moduleName ) ;
647 $df->setup ( $seed ) ;
648 //Need to load the entire field_meta_data for some field types
649 $field = $df->getFieldWidget($moduleName, $field->name);
650 $field->delete ( $df ) ;
652 $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
653 $_REQUEST['execute_sql'] = true;
654 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
655 $repair = new RepairAndClear();
656 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
657 require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php' ;
658 $module = StudioModuleFactory::getStudioModule( $moduleName ) ;
663 $mb = new ModuleBuilder ( ) ;
664 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
665 $field->delete ( $module ) ;
668 $module->removeFieldFromLayouts( $field->name );
669 $this->view = 'modulefields' ;
671 if (isset($GLOBALS['current_language']) && isset($_REQUEST['label']) &&
672 isset($_REQUEST['labelValue']) && isset($_REQUEST['view_module'])) {
673 $this->DeleteLabel($GLOBALS['current_language'], $_REQUEST['label'], $_REQUEST['labelValue'], $_REQUEST['view_module']);
677 function DeleteLabel($language, $label, $labelvalue, $modulename, $basepath = null, $forRelationshipLabel = false)
680 require_once 'modules/ModuleBuilder/parsers/parser.label.php';
681 ParserLabel::removeLabel($language, $label, $labelvalue, $modulename, $basepath, $forRelationshipLabel);
684 function action_CloneField ()
686 $this->view_object_map [ 'field_name' ] = $_REQUEST [ 'name' ] ;
687 $this->view_object_map [ 'is_clone' ] = true ;
688 $this->view = 'modulefield' ;
691 function action_SaveAssistantPref ()
693 global $current_user ;
694 if (isset ( $_REQUEST [ 'pref_value' ] ))
696 if ($_REQUEST [ 'pref_value' ] == 'ignore')
698 $current_user->setPreference ( 'mb_assist', 'DISABLED', 0, 'Assistant' ) ;
701 $current_user->setPreference ( 'mb_assist', 'ENABLED', 0, 'Assistant' ) ;
703 $current_pref = $current_user->getPreference ( 'mb_assist', 'Assistant' ) ;
704 echo "Assistant.processUserPref('$current_pref')" ;
705 sugar_cleanup ( true ) ; //push preferences to DB.
712 function action_EditProperty ()
714 $this->view = 'property' ;
717 function action_saveProperty ()
719 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
720 $modules = $_REQUEST['view_module'];
721 if(!empty($_REQUEST['subpanel'])){
722 $modules = $_REQUEST['subpanel'];
724 $parser = new ParserLabel ( $modules , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
725 // if no language provided, then use the user's current language which is most likely what they intended
726 $language = (isset($_REQUEST [ 'selected_lang' ])) ? $_REQUEST [ 'selected_lang' ] : $GLOBALS['current_language'] ;
727 $parser->handleSave ( $_REQUEST, $language ) ;
728 $json = getJSONobj();
729 echo $json->encode(array("east" => array("action" => "deactivate")));
732 function action_editModule ()
734 $this->view = 'module' ;
737 function action_wizard ()
739 $this->view = 'wizard' ;
743 * Receive a layout through $_REQUEST and save it out to the working files directory
744 * Expects a series of $_REQUEST parameters all in the format $_REQUEST['slot-panel#-slot#-property']=value
747 function action_saveLayout ()
749 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
750 $this->view = 'layoutview' ;
751 $parser->writeWorkingFile () ;
753 if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
754 if(strtolower ($parser->_view) == MB_EDITVIEW){
755 $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
756 $parser2->setUseTabs($parser->getUseTabs());
757 $parser2->writeWorkingFile () ;
762 function action_saveAndPublishLayout ()
764 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
765 $this->view = 'layoutview' ;
766 $parser->handleSave () ;
768 if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
769 if(strtolower ($parser->_view) == MB_EDITVIEW){
770 $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
771 $parser2->setUseTabs($parser->getUseTabs());
772 $parser2->handleSave () ;
777 function action_manageBackups ()
782 function action_listViewSave ()
784 $GLOBALS [ 'log' ]->info ( "action_listViewSave" ) ;
786 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
787 $subpanelName = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : null ;
788 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
789 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName, $subpanelName ) ;
790 $this->view = 'listView' ;
791 $parser->handleSave () ;
795 function action_dashletSave () {
796 $this->view = 'dashlet' ;
797 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
798 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
799 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
800 $parser->handleSave () ;
803 function action_popupSave(){
804 $this->view = 'popupview' ;
805 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
806 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
807 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
808 $parser->handleSave () ;
809 if(empty($packageName)){
810 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
812 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
813 $repair = new RepairAndClear();
814 $repair->show_output = false;
815 $class_name = $GLOBALS [ 'beanList' ] [ $_REQUEST [ 'view_module' ] ] ;
816 $repair->module_list = array($class_name);
817 $repair->clearTpls();
822 function action_searchViewSave ()
824 $packageName = (isset ( $_REQUEST [ 'view_package' ] )) ? $_REQUEST [ 'view_package' ] : null ;
825 require_once 'modules/ModuleBuilder/parsers/views/SearchViewMetaDataParser.php' ;
826 $parser = new SearchViewMetaDataParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
827 $parser->handleSave () ;
830 //Repair or create a custom SearchFields.php file as needed
831 $module_name = $_REQUEST [ 'view_module' ] ;
833 if (isset($beanList[$module_name]) && $beanList[$module_name]!="") {
834 $objectName = BeanFactory::getObjectName($module_name);
836 //Load the vardefs for the module to pass to TemplateRange
837 VardefManager::loadVardef($module_name, $objectName, true);
839 $vardefs = $dictionary[$objectName]['fields'];
840 require_once('modules/DynamicFields/templates/Fields/TemplateRange.php');
841 TemplateRange::repairCustomSearchFields($vardefs, $module_name, $packageName);
843 $this->view = 'searchView' ;
846 function action_editLabels ()
848 if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
850 $this->view = 'modulelabels';
852 $this->view = 'labels';
856 function action_get_app_list_string ()
858 require_once ('include/JSON.php') ;
859 $json = new JSON ( ) ;
860 if (isset ( $_REQUEST [ 'key' ] ) && ! empty ( $_REQUEST [ 'key' ] ))
862 $key = $_REQUEST [ 'key' ] ;
864 if (! empty ( $GLOBALS [ 'app_list_strings' ] [ $key ] ))
866 $value = $GLOBALS [ 'app_list_strings' ] [ $key ] ;
869 $package_strings = array ( ) ;
870 if (! empty ( $_REQUEST [ 'view_package' ] ) && $_REQUEST [ 'view_package' ] != 'studio' && ! empty ( $_REQUEST [ 'view_module' ] ))
872 require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
873 $mb = new ModuleBuilder ( ) ;
874 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
875 $lang = $GLOBALS [ 'current_language' ] ;
876 $module->mblanguage->generateAppStrings ( false ) ;
877 $package_strings = $module->mblanguage->appListStrings [ $lang . '.lang.php' ] ;
878 if (isset ( $package_strings [ $key ] ) && is_array ( $package_strings [ $key ] ))
880 $value = $package_strings [ $key ] ;
884 echo $json->encode ( $value ) ;
888 function action_history ()
890 $this->view = 'history' ;
893 function resetmodule()
895 $this->view = 'resetmodule';
901 * This method handles saving the current user's tabling sorting preferences. It is called when
902 * the user clicks on a column to sort from the fields layout table.
905 function action_savetablesort ()
907 $this->view = 'ajax';
908 global $current_user;
910 if(!empty($current_user) && isset($_REQUEST['column']) && isset($_REQUEST['direction']))
912 $direction = ($_REQUEST['direction'] == 'yui-dt-asc') ? 'ASC' : 'DESC';
913 $valid_columns = array('name', 'label', 'type', 'required', 'unified_search', 'custom');
914 $key = in_array($_REQUEST['column'], $valid_columns) ? $_REQUEST['column'] : 'name';
915 $val = array('key'=>$key, 'direction'=>$direction);
916 $current_user->setPreference('fieldsTableColumn', getJSONobj()->encode($val), 0, 'ModuleBuilder');