2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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/parsers/constants.php' ;
41 class ModuleBuilderController extends SugarController
43 var $action_remap = array ( ) ;
46 * Used by the _getModuleTitleParams() method calls in ModuleBuilder views to get the correct string
47 * for the section you are in
51 public static function getModuleTitle()
55 if(!empty($_REQUEST['type'])){
56 if ( $_REQUEST['type'] == 'studio' ) {
57 return $mod_strings['LBL_STUDIO'];
59 elseif ( $_REQUEST['type'] == 'sugarportal' ) {
60 return $mod_strings['LBL_SUGARPORTAL'];
62 elseif ( $_REQUEST['type'] == 'mb' ) {
63 return $mod_strings['LBL_MODULEBUILDER'];
65 elseif ( $_REQUEST['type'] == 'dropdowns') {
66 return $mod_strings['LBL_DROPDOWNEDITOR'];
68 elseif ( $_REQUEST['type'] == 'home' ) {
69 return $mod_strings['LBL_HOME'];
72 return $mod_strings['LBL_DEVELOPER_TOOLS'];
75 return $mod_strings['LBL_DEVELOPER_TOOLS'];
79 function fromModuleBuilder ()
81 return (isset ( $_REQUEST [ 'MB' ] ) && ($_REQUEST [ 'MB' ] == '1')) ;
85 $GLOBALS [ 'log' ]->info ( get_class($this).":" ) ;
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))))
93 $this->hasAccess = true;
97 $this->hasAccess = false;
103 function action_editLayout ()
105 switch ( strtolower ( $_REQUEST [ 'view' ] ))
109 case MB_QUICKCREATE :
110 $this->view = 'layoutView' ;
113 $this->view = 'listView' ;
115 case MB_BASICSEARCH :
116 case MB_ADVANCEDSEARCH :
117 $this->view = 'searchView' ;
120 case MB_DASHLETSEARCH :
121 $this->view = 'dashlet' ;
124 case MB_POPUPSEARCH :
125 $this->view = 'popupview' ;
128 $GLOBALS [ 'log' ]->fatal ( 'Action = editLayout with unknown view=' . $_REQUEST [ 'view' ] ) ;
133 function action_ViewTree ()
135 require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
136 switch ( $_REQUEST [ 'tree' ])
138 case 'ModuleBuilder' :
139 require_once ('modules/ModuleBuilder/MB/MBPackageTree.php') ;
140 $mbt = new MBPackageTree ( ) ;
143 require_once ('modules/ModuleBuilder/Module/StudioTree.php') ;
144 $mbt = new StudioTree ( ) ;
146 $ajax = new AjaxCompose ( ) ;
147 $ajax->addSection ( 'west', $mbt->getName (), $mbt->fetchNodes () ) ;
148 echo $ajax->getJavascript () ;
150 sugar_cleanup ( true ) ;
154 function action_SavePackage ()
156 $mb = new ModuleBuilder ( ) ;
157 $load = (! empty ( $_REQUEST [ 'original_name' ] )) ? $_REQUEST [ 'original_name' ] : $_REQUEST [ 'name' ] ;
158 if (! empty ( $load ))
160 $mb->getPackage ( $load ) ;
162 if (! empty ( $_REQUEST [ 'duplicate' ] ))
164 $result = $mb->packages [ $load ]->copy ( $_REQUEST [ 'name' ] ) ;
165 $load = $mb->packages [ $load ]->name ;
166 $mb->getPackage ( $load ) ;
168 $mb->packages [ $load ]->populateFromPost () ;
169 $mb->packages [ $load ]->loadModules () ;
171 if (! empty ( $_REQUEST [ 'original_name' ] ) && $_REQUEST [ 'original_name' ] != $_REQUEST [ 'name' ])
173 if (! $mb->packages [ $load ]->rename ( $_REQUEST [ 'name' ] ))
175 $mb->packages [ $load ]->name = $_REQUEST [ 'original_name' ] ;
176 $_REQUEST [ 'name' ] = $_REQUEST [ 'original_name' ] ;
179 $_REQUEST [ 'package' ] = $_REQUEST [ 'name' ] ;
180 $this->view = 'package' ;
184 function action_BuildPackage ()
186 $mb = new ModuleBuilder ( ) ;
187 $load = $_REQUEST [ 'name' ] ;
188 if (! empty ( $load ))
190 $mb->getPackage ( $load ) ;
191 $mb->packages [ $load ]->build () ;
195 function action_DeployPackage ()
197 if(defined('TEMPLATE_URL')){
199 SugarTemplateUtilities::disableCache();
202 $mb = new ModuleBuilder ( ) ;
203 $load = $_REQUEST [ 'package' ] ;
204 $message = $GLOBALS [ 'mod_strings' ] [ 'LBL_MODULE_DEPLOYED' ] ;
205 if (! empty ( $load ))
207 $zip = $mb->getPackage ( $load ) ;
208 require_once ('ModuleInstall/PackageManager/PackageManager.php') ;
209 $pm = new PackageManager ( ) ;
210 $info = $mb->packages [ $load ]->build ( false ) ;
211 $cachedir = sugar_cached('/upload/upgrades/module/');
212 mkdir_recursive ($cachedir) ;
213 rename ( $info [ 'zip' ], $cachedir . $info [ 'name' ] . '.zip' ) ;
214 copy ( $info [ 'manifest' ], $cachedir . $info [ 'name' ] . '-manifest.php' ) ;
215 $_REQUEST [ 'install_file' ] = $cachedir. $info [ 'name' ] . '.zip' ;
216 $GLOBALS [ 'mi_remove_tables' ] = false ;
217 $pm->performUninstall ( $load ) ;
218 //#23177 , js cache clear
219 clearAllJsAndJsLangFilesWithoutOutput();
220 //#30747, clear the cache in memory
221 $cache_key = 'app_list_strings.'.$GLOBALS['current_language'];
222 sugar_cache_clear($cache_key );
225 $pm->performInstall ( $_REQUEST [ 'install_file' ] , true);
227 //clear the unified_search_module.php file
228 require_once('modules/Home/UnifiedSearchAdvanced.php');
229 UnifiedSearchAdvanced::unlinkUnifiedSearchModulesFile();
232 global $current_user;
233 //clear workflow admin modules cache
234 if (isset($_SESSION['get_workflow_admin_modules_for_user'])) unset($_SESSION['get_workflow_admin_modules_for_user']);
236 //clear "is_admin_for_module" cache
237 $sessionVar = 'MLA_'.$current_user->user_name;
238 foreach ($mb->packages as $package) {
239 foreach ($package->modules as $module) {
240 $_SESSION[$sessionVar][$package->name . '_' . $module->name] = true;
245 $actions = ACLAction::getUserActions($current_user->id, true);
252 function action_ExportPackage ()
254 $mb = new ModuleBuilder ( ) ;
255 $load = $_REQUEST [ 'name' ] ;
256 $author = $_REQUEST [ 'author' ] ;
257 $description = $_REQUEST [ 'description' ] ;
258 $readme = $_REQUEST [ 'readme' ] ;
259 if (! empty ( $load ))
261 $mb->getPackage ( $load ) ;
262 $mb->packages [ $load ]->author = $author ;
263 $mb->packages [ $load ]->description = $description ;
264 $mb->packages [ $load ]->exportProject () ;
265 $mb->packages [ $load ]->readme = $readme ;
269 function action_DeletePackage ()
271 $mb = new ModuleBuilder ( ) ;
272 $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
273 $mb->packages [ $_REQUEST [ 'package' ] ]->delete () ;
274 $this->view = 'deletepackage' ;
277 function action_SaveModule ()
279 $mb = new ModuleBuilder ( ) ;
280 $load = (! empty ( $_REQUEST [ 'original_name' ] )) ? $_REQUEST [ 'original_name' ] : $_REQUEST [ 'name' ] ;
281 if (! empty ( $load ))
283 $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
284 $mb->packages [ $_REQUEST [ 'package' ] ]->getModule ( $load ) ;
285 $module = & $mb->packages [ $_REQUEST [ 'package' ] ]->modules [ $load ] ;
286 $module->populateFromPost () ;
288 if (! empty ( $_REQUEST [ 'duplicate' ] ))
290 $module->copy ( $_REQUEST [ 'name' ] ) ;
291 } else if (! empty ( $_REQUEST [ 'original_name' ] ) && $_REQUEST [ 'original_name' ] != $_REQUEST [ 'name' ])
293 if (! $module->rename ( $_REQUEST [ 'name' ] ))
295 $module->name = $_REQUEST [ 'original_name' ] ;
296 $_REQUEST [ 'name' ] = $_REQUEST [ 'original_name' ] ;
300 $_REQUEST [ 'view_package' ] = $_REQUEST [ 'package' ] ;
301 $_REQUEST [ 'view_module' ] = $module->name ;
302 $this->view = 'module' ;
306 function action_DeleteModule ()
308 $mb = new ModuleBuilder ( ) ;
309 $module = & $mb->getPackageModule ( $_REQUEST [ 'package' ], $_REQUEST [ 'view_module' ] ) ;
311 $this->view = 'package' ;
314 function action_saveLabels ()
316 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
317 $parser = new ParserLabel ( $_REQUEST['view_module'] , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
318 $parser->handleSave ( $_REQUEST, $_REQUEST [ 'selected_lang' ] ) ;
319 if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
321 $this->view = 'modulelabels' ;
324 $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)
328 function action_SaveLabel ()
330 if (! empty ( $_REQUEST [ 'view_module' ] ) && !empty($_REQUEST [ 'labelValue' ]))
332 $_REQUEST [ "label_" . $_REQUEST [ 'label' ] ] = $_REQUEST [ 'labelValue' ] ;
333 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
334 $parser = new ParserLabel ( $_REQUEST['view_module'] , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
335 $parser->handleSave ( $_REQUEST, $GLOBALS [ 'current_language' ] ) ;
338 $this->view = 'modulefields' ;
341 function action_ExportCustom ()
343 $modules = $_REQUEST [ 'modules' ] ;
344 $name = $_REQUEST [ 'name' ] ;
345 $author = $_REQUEST [ 'author' ] ;
346 $description = $_REQUEST [ 'description' ] ;
348 if (! empty ( $modules ) && ! empty ( $name ))
350 require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
351 $mb = new MBPackage ( $name ) ;
352 $mb->author = $author ;
353 $mb->description = $description ;
354 $mb->exportCustom ( $modules, true, true ) ;
358 function action_SaveField ()
360 require_once ('modules/DynamicFields/FieldCases.php') ;
361 $field = get_widget ( $_REQUEST [ 'type' ] ) ;
362 $_REQUEST [ 'name' ] = trim ( $_REQUEST [ 'name' ] ) ;
364 $field->populateFromPost () ;
366 if (!isset ( $_REQUEST [ 'view_package' ] ))
368 require_once ('modules/DynamicFields/DynamicField.php') ;
369 if (! empty ( $_REQUEST [ 'view_module' ] ))
371 $module = $_REQUEST [ 'view_module' ] ;
372 if ( $module == 'Employees' ) {
376 $bean = BeanFactory::getBean($module);
379 $field_defs = $bean->field_defs;
380 if(isset($field_defs[$field->name. '_c']))
382 $GLOBALS['log']->error($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS'] . '[' . $field->name . ']');
383 sugar_die($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS']);
387 $df = new DynamicField ( $module ) ;
388 $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
389 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
390 $mod = new $class_name ( ) ;
391 $df->setup ( $mod ) ;
393 $field->save ( $df ) ;
394 $this->action_SaveLabel () ;
395 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
397 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
398 require_once('ModuleInstall/ModuleInstaller.php');
399 $mi = new ModuleInstaller();
401 $mi->rebuild_extensions();
402 $repair = new RepairAndClear();
404 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
405 if ( $module == 'Users' ) {
406 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array('Employee'), true, false);
410 //#28707 ,clear all the js files in cache
411 $repair->module_list = array();
412 $repair->clearJsFiles();
416 $mb = new ModuleBuilder ( ) ;
417 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
418 $field->save ( $module ) ;
419 $module->mbvardefs->save () ;
420 // get the module again to refresh the labels we might have saved with the $field->save (e.g., for address fields)
421 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
422 if (isset ( $_REQUEST [ 'label' ] ) && isset ( $_REQUEST [ 'labelValue' ] ))
423 $module->setLabel ( $GLOBALS [ 'current_language' ], $_REQUEST [ 'label' ], $_REQUEST [ 'labelValue' ] ) ;
426 $this->view = 'modulefields' ;
429 function action_saveSugarField ()
432 require_once ('modules/DynamicFields/FieldCases.php') ;
433 $field = get_widget ( $_REQUEST [ 'type' ] ) ;
434 $_REQUEST [ 'name' ] = trim ( $_POST [ 'name' ] ) ;
436 $field->populateFromPost () ;
437 require_once ('modules/ModuleBuilder/parsers/StandardField.php') ;
438 $module = $_REQUEST [ 'view_module' ] ;
440 // Need to map Employees -> Users
441 if ( $module=='Employees') {
445 $df = new StandardField ( $module ) ;
446 $mod = BeanFactory::getBean($module);
447 $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
448 $df->setup ( $mod ) ;
450 $field->module = $mod;
451 $field->save ( $df ) ;
452 $this->action_SaveLabel () ;
454 $MBmodStrings = $mod_strings;
455 $GLOBALS [ 'mod_strings' ] = return_module_language ( '', 'Administration' ) ;
457 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
458 $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
459 $_REQUEST['execute_sql'] = true;
461 require_once('ModuleInstall/ModuleInstaller.php');
462 $mi = new ModuleInstaller();
464 $mi->rebuild_extensions();
466 $repair = new RepairAndClear();
467 $repair->repairAndClearAll(array('clearVardefs', 'clearTpls'), array($class_name), true, false);
468 //#28707 ,clear all the js files in cache
469 $repair->module_list = array();
470 $repair->clearJsFiles();
472 // now clear the cache so that the results are immediately visible
473 include_once ('include/TemplateHandler/TemplateHandler.php') ;
474 TemplateHandler::clearCache ( $module ) ;
475 if ( $module == 'Users' ) {
476 TemplateHandler::clearCache('Employees');
479 $GLOBALS [ 'mod_strings' ] = $MBmodStrings;
482 function action_RefreshField ()
484 require_once ('modules/DynamicFields/FieldCases.php') ;
485 $field = get_widget ( $_POST [ 'type' ] ) ;
486 $field->populateFromPost () ;
487 $this->view = 'modulefield' ;
490 function action_saveVisibility ()
492 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
493 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
494 $parser = ParserFactory::getParser ( MB_VISIBILITY, $_REQUEST [ 'view_module' ], $packageName ) ;
496 $json = getJSONobj();
497 $visibility_grid = $json->decode(html_entity_decode(rawurldecode($_REQUEST [ 'visibility_grid' ]), ENT_QUOTES) );
498 $parser->saveVisibility ( $_REQUEST [ 'fieldname' ] , $_REQUEST [ 'trigger' ] , $visibility_grid ) ;
500 echo $json->encode(array( "visibility_editor_{$_REQUEST['fieldname']}" => array("action" => "deactivate")));
503 function action_SaveRelationshipLabel (){
504 $selected_lang = (!empty($_REQUEST['relationship_lang'])?$_REQUEST['relationship_lang']:$_SESSION['authenticated_user_language']);
505 if (empty($_REQUEST [ 'view_package' ])){
506 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
507 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
508 if (! empty ( $_REQUEST [ 'relationship_name' ] ))
510 if ($relationship = $relationships->get ( $_REQUEST [ 'relationship_name' ] )){
511 $metadata = $relationship->buildLabels(true);
512 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
513 $parser = new ParserLabel ( $_REQUEST['view_module'] ) ;
514 $parser->handleSaveRelationshipLabels ( $metadata, $selected_lang ) ;
521 $this->view = 'relationships' ;
524 function action_SaveRelationship ()
526 if(!empty($GLOBALS['current_user']) && empty($GLOBALS['modListHeader']))
528 $GLOBALS['modListHeader'] = query_module_access_list($GLOBALS['current_user']);
531 if (empty($_REQUEST [ 'view_package' ]))
533 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
534 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
537 $mb = new ModuleBuilder ( ) ;
538 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
539 require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
540 $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
543 $relationships->addFromPost () ;
544 $relationships->save () ;
545 $GLOBALS['log']->debug("\n\nSTART BUILD");
546 if (empty($_REQUEST [ 'view_package' ])) {
547 $relationships->build () ;
548 LanguageManager::clearLanguageCache($_REQUEST [ 'view_module' ]);
550 $GLOBALS['log']->debug("\n\nEND BUILD");
551 $this->view = 'relationships' ;
554 function action_DeleteRelationship ()
556 if (isset ( $_REQUEST [ 'relationship_name' ] ))
558 if (empty($_REQUEST [ 'view_package' ] ))
560 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
561 if (!empty($_REQUEST['remove_tables']))
562 $GLOBALS['mi_remove_tables'] = $_REQUEST['remove_tables'];
563 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
566 $mb = new ModuleBuilder ( ) ;
567 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
568 require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
569 $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
571 $relationships->delete ( $_REQUEST [ 'relationship_name' ] ) ;
573 $relationships->save () ;
574 require_once("data/Relationships/RelationshipFactory.php");
575 SugarRelationshipFactory::deleteCache();
577 $this->view = 'relationships' ;
580 function action_SaveDropDown ()
582 require_once 'modules/ModuleBuilder/parsers/parser.dropdown.php' ;
583 $parser = new ParserDropDown ( ) ;
584 $parser->saveDropDown ( $_REQUEST ) ;
585 $this->view = 'dropdowns' ;
588 function action_DeleteField ()
590 require_once ('modules/DynamicFields/FieldCases.php') ;
591 $field = get_widget ( $_REQUEST [ 'type' ] ) ;
592 $field->name = $_REQUEST [ 'name' ] ;
593 if (!isset ( $_REQUEST [ 'view_package' ] ))
595 if (! empty ( $_REQUEST [ 'name' ] ) && ! empty ( $_REQUEST [ 'view_module' ] ))
597 require_once ('modules/DynamicFields/DynamicField.php') ;
598 $moduleName = $_REQUEST [ 'view_module' ] ;
599 $class_name = $GLOBALS [ 'beanList' ] [ $moduleName ] ;
600 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
601 $seed = new $class_name ( ) ;
602 $df = new DynamicField ( $moduleName ) ;
603 $df->setup ( $seed ) ;
604 //Need to load the entire field_meta_data for some field types
605 $field = $df->getFieldWidget($moduleName, $field->name);
606 $field->delete ( $df ) ;
608 $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
609 $_REQUEST['execute_sql'] = true;
610 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
611 $repair = new RepairAndClear();
612 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
613 require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php' ;
614 $module = StudioModuleFactory::getStudioModule( $moduleName ) ;
619 $mb = new ModuleBuilder ( ) ;
620 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
621 $field->delete ( $module ) ;
624 $module->removeFieldFromLayouts( $field->name );
625 $this->view = 'modulefields' ;
627 if (isset($GLOBALS['current_language']) && isset($_REQUEST['label']) &&
628 isset($_REQUEST['labelValue']) && isset($_REQUEST['view_module'])) {
629 $this->DeleteLabel($GLOBALS['current_language'], $_REQUEST['label'], $_REQUEST['labelValue'], $_REQUEST['view_module']);
633 function DeleteLabel($language, $label, $labelvalue, $modulename, $basepath = null, $forRelationshipLabel = false)
636 require_once 'modules/ModuleBuilder/parsers/parser.label.php';
637 ParserLabel::removeLabel($language, $label, $labelvalue, $modulename, $basepath, $forRelationshipLabel);
640 function action_CloneField ()
642 $this->view_object_map [ 'field_name' ] = $_REQUEST [ 'name' ] ;
643 $this->view_object_map [ 'is_clone' ] = true ;
644 $this->view = 'modulefield' ;
647 function action_SaveAssistantPref ()
649 global $current_user ;
650 if (isset ( $_REQUEST [ 'pref_value' ] ))
652 if ($_REQUEST [ 'pref_value' ] == 'ignore')
654 $current_user->setPreference ( 'mb_assist', 'DISABLED', 0, 'Assistant' ) ;
657 $current_user->setPreference ( 'mb_assist', 'ENABLED', 0, 'Assistant' ) ;
659 $current_pref = $current_user->getPreference ( 'mb_assist', 'Assistant' ) ;
660 echo "Assistant.processUserPref('$current_pref')" ;
661 sugar_cleanup ( true ) ; //push preferences to DB.
668 function action_EditProperty ()
670 $this->view = 'property' ;
673 function action_saveProperty ()
675 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
676 $modules = $_REQUEST['view_module'];
677 if(!empty($_REQUEST['subpanel'])){
678 $modules = $_REQUEST['subpanel'];
680 $parser = new ParserLabel ( $modules , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
681 // if no language provided, then use the user's current language which is most likely what they intended
682 $language = (isset($_REQUEST [ 'selected_lang' ])) ? $_REQUEST [ 'selected_lang' ] : $GLOBALS['current_language'] ;
683 $parser->handleSave ( $_REQUEST, $language ) ;
684 $json = getJSONobj();
685 echo $json->encode(array("east" => array("action" => "deactivate")));
688 function action_editModule ()
690 $this->view = 'module' ;
693 function action_wizard ()
695 $this->view = 'wizard' ;
699 * Receive a layout through $_REQUEST and save it out to the working files directory
700 * Expects a series of $_REQUEST parameters all in the format $_REQUEST['slot-panel#-slot#-property']=value
703 function action_saveLayout ()
705 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
706 $this->view = 'layoutview' ;
707 $parser->writeWorkingFile () ;
709 if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
710 if(strtolower ($parser->_view) == MB_EDITVIEW){
711 $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
712 $parser2->setUseTabs($parser->getUseTabs());
713 $parser2->writeWorkingFile () ;
718 function action_saveAndPublishLayout ()
720 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
721 $this->view = 'layoutview' ;
722 $parser->handleSave () ;
724 if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
725 if(strtolower ($parser->_view) == MB_EDITVIEW){
726 $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
727 $parser2->setUseTabs($parser->getUseTabs());
728 $parser2->handleSave () ;
733 function action_manageBackups ()
738 function action_listViewSave ()
740 $GLOBALS [ 'log' ]->info ( "action_listViewSave" ) ;
742 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
743 $subpanelName = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : null ;
744 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
745 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName, $subpanelName ) ;
746 $this->view = 'listView' ;
747 $parser->handleSave () ;
751 function action_dashletSave () {
752 $this->view = 'dashlet' ;
753 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
754 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
755 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
756 $parser->handleSave () ;
759 function action_popupSave(){
760 $this->view = 'popupview' ;
761 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
762 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
763 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
764 $parser->handleSave () ;
765 if(empty($packageName)){
766 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
768 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
769 $repair = new RepairAndClear();
770 $repair->show_output = false;
771 $class_name = $GLOBALS [ 'beanList' ] [ $_REQUEST [ 'view_module' ] ] ;
772 $repair->module_list = array($class_name);
773 $repair->clearTpls();
778 function action_searchViewSave ()
780 $packageName = (isset ( $_REQUEST [ 'view_package' ] )) ? $_REQUEST [ 'view_package' ] : null ;
781 require_once 'modules/ModuleBuilder/parsers/views/SearchViewMetaDataParser.php' ;
782 $parser = new SearchViewMetaDataParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
783 $parser->handleSave () ;
786 //Repair or create a custom SearchFields.php file as needed
787 $module_name = $_REQUEST [ 'view_module' ] ;
789 if (isset($beanList[$module_name]) && $beanList[$module_name]!="") {
790 $objectName = BeanFactory::getObjectName($module_name);
792 //Load the vardefs for the module to pass to TemplateRange
793 VardefManager::loadVardef($module_name, $objectName, true);
795 $vardefs = $dictionary[$objectName]['fields'];
796 require_once('modules/DynamicFields/templates/Fields/TemplateRange.php');
797 TemplateRange::repairCustomSearchFields($vardefs, $module_name, $packageName);
799 $this->view = 'searchView' ;
802 function action_editLabels ()
804 if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
806 $this->view = 'modulelabels';
808 $this->view = 'labels';
812 function action_get_app_list_string ()
814 require_once ('include/JSON.php') ;
815 $json = new JSON ( ) ;
816 if (isset ( $_REQUEST [ 'key' ] ) && ! empty ( $_REQUEST [ 'key' ] ))
818 $key = $_REQUEST [ 'key' ] ;
820 if (! empty ( $GLOBALS [ 'app_list_strings' ] [ $key ] ))
822 $value = $GLOBALS [ 'app_list_strings' ] [ $key ] ;
825 $package_strings = array ( ) ;
826 if (! empty ( $_REQUEST [ 'view_package' ] ) && $_REQUEST [ 'view_package' ] != 'studio' && ! empty ( $_REQUEST [ 'view_module' ] ))
828 require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
829 $mb = new ModuleBuilder ( ) ;
830 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
831 $lang = $GLOBALS [ 'current_language' ] ;
832 $module->mblanguage->generateAppStrings ( false ) ;
833 $package_strings = $module->mblanguage->appListStrings [ $lang . '.lang.php' ] ;
834 if (isset ( $package_strings [ $key ] ) && is_array ( $package_strings [ $key ] ))
836 $value = $package_strings [ $key ] ;
840 echo $json->encode ( $value ) ;
844 function action_history ()
846 $this->view = 'history' ;
849 function resetmodule()
851 $this->view = 'resetmodule';
857 * This method handles saving the current user's tabling sorting preferences. It is called when
858 * the user clicks on a column to sort from the fields layout table.
861 function action_savetablesort ()
863 $this->view = 'ajax';
864 global $current_user;
866 if(!empty($current_user) && isset($_REQUEST['column']) && isset($_REQUEST['direction']))
868 $direction = ($_REQUEST['direction'] == 'yui-dt-asc') ? 'ASC' : 'DESC';
869 $valid_columns = array('name', 'label', 'type', 'required', 'unified_search', 'custom');
870 $key = in_array($_REQUEST['column'], $valid_columns) ? $_REQUEST['column'] : 'name';
871 $val = array('key'=>$key, 'direction'=>$direction);
872 $current_user->setPreference('fieldsTableColumn', getJSONobj()->encode($val), 0, 'ModuleBuilder');