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 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 );
224 $pm->performInstall ( $_REQUEST [ 'install_file' ] , true);
226 //clear the unified_search_module.php file
227 require_once('modules/Home/UnifiedSearchAdvanced.php');
228 UnifiedSearchAdvanced::unlinkUnifiedSearchModulesFile();
231 global $current_user;
232 //clear workflow admin modules cache
233 if (isset($_SESSION['get_workflow_admin_modules_for_user'])) unset($_SESSION['get_workflow_admin_modules_for_user']);
235 //clear "is_admin_for_module" cache
236 $sessionVar = 'MLA_'.$current_user->user_name;
237 foreach ($mb->packages as $package) {
238 foreach ($package->modules as $module) {
239 $_SESSION[$sessionVar][$package->name . '_' . $module->name] = true;
244 $actions = ACLAction::getUserActions($current_user->id, true);
251 function action_ExportPackage ()
253 $mb = new ModuleBuilder ( ) ;
254 $load = $_REQUEST [ 'name' ] ;
255 $author = $_REQUEST [ 'author' ] ;
256 $description = $_REQUEST [ 'description' ] ;
257 $readme = $_REQUEST [ 'readme' ] ;
258 if (! empty ( $load ))
260 $mb->getPackage ( $load ) ;
261 $mb->packages [ $load ]->author = $author ;
262 $mb->packages [ $load ]->description = $description ;
263 $mb->packages [ $load ]->exportProject () ;
264 $mb->packages [ $load ]->readme = $readme ;
268 function action_DeletePackage ()
270 $mb = new ModuleBuilder ( ) ;
271 $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
272 $mb->packages [ $_REQUEST [ 'package' ] ]->delete () ;
273 $this->view = 'deletepackage' ;
276 function action_SaveModule ()
278 $mb = new ModuleBuilder ( ) ;
279 $load = (! empty ( $_REQUEST [ 'original_name' ] )) ? $_REQUEST [ 'original_name' ] : $_REQUEST [ 'name' ] ;
280 if (! empty ( $load ))
282 $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
283 $mb->packages [ $_REQUEST [ 'package' ] ]->getModule ( $load ) ;
284 $module = & $mb->packages [ $_REQUEST [ 'package' ] ]->modules [ $load ] ;
285 $module->populateFromPost () ;
287 if (! empty ( $_REQUEST [ 'duplicate' ] ))
289 $module->copy ( $_REQUEST [ 'name' ] ) ;
290 } else if (! empty ( $_REQUEST [ 'original_name' ] ) && $_REQUEST [ 'original_name' ] != $_REQUEST [ 'name' ])
292 if (! $module->rename ( $_REQUEST [ 'name' ] ))
294 $module->name = $_REQUEST [ 'original_name' ] ;
295 $_REQUEST [ 'name' ] = $_REQUEST [ 'original_name' ] ;
299 $_REQUEST [ 'view_package' ] = $_REQUEST [ 'package' ] ;
300 $_REQUEST [ 'view_module' ] = $module->name ;
301 $this->view = 'module' ;
305 function action_DeleteModule ()
307 $mb = new ModuleBuilder ( ) ;
308 $module = & $mb->getPackageModule ( $_REQUEST [ 'package' ], $_REQUEST [ 'view_module' ] ) ;
310 $this->view = 'package' ;
313 function action_saveLabels ()
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, $_REQUEST [ 'selected_lang' ] ) ;
318 if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
320 $this->view = 'modulelabels' ;
323 $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)
327 function action_SaveLabel ()
329 if (! empty ( $_REQUEST [ 'view_module' ] ) && !empty($_REQUEST [ 'labelValue' ]))
331 $_REQUEST [ "label_" . $_REQUEST [ 'label' ] ] = $_REQUEST [ 'labelValue' ] ;
332 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
333 $parser = new ParserLabel ( $_REQUEST['view_module'] , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
334 $parser->handleSave ( $_REQUEST, $GLOBALS [ 'current_language' ] ) ;
337 $this->view = 'modulefields' ;
340 function action_ExportCustom ()
342 $modules = $_REQUEST [ 'modules' ] ;
343 $name = $_REQUEST [ 'name' ] ;
344 $author = $_REQUEST [ 'author' ] ;
345 $description = $_REQUEST [ 'description' ] ;
347 if (! empty ( $modules ) && ! empty ( $name ))
349 require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
350 $mb = new MBPackage ( $name ) ;
351 $mb->author = $author ;
352 $mb->description = $description ;
353 $mb->exportCustom ( $modules, true, true ) ;
357 function action_SaveField ()
359 require_once ('modules/DynamicFields/FieldCases.php') ;
360 $field = get_widget ( $_REQUEST [ 'type' ] ) ;
361 $_REQUEST [ 'name' ] = trim ( $_REQUEST [ 'name' ] ) ;
363 $field->populateFromPost () ;
365 if (!isset ( $_REQUEST [ 'view_package' ] ))
367 require_once ('modules/DynamicFields/DynamicField.php') ;
368 if (! empty ( $_REQUEST [ 'view_module' ] ))
370 $module = $_REQUEST [ 'view_module' ] ;
372 $bean = BeanFactory::getBean($module);
375 $field_defs = $bean->field_defs;
376 if(isset($field_defs[$field->name. '_c']))
378 $GLOBALS['log']->error($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS'] . '[' . $field->name . ']');
379 sugar_die($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS']);
383 $df = new DynamicField ( $module ) ;
384 $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
385 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
386 $mod = new $class_name ( ) ;
387 $df->setup ( $mod ) ;
389 $field->save ( $df ) ;
390 $this->action_SaveLabel () ;
391 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
393 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
394 require_once('ModuleInstall/ModuleInstaller.php');
395 $mi = new ModuleInstaller();
397 $mi->rebuild_extensions();
398 $repair = new RepairAndClear();
399 $repair->repairAndClearAll(array('clearVardefs', 'clearTpls'), array($class_name), true, false);
400 //#28707 ,clear all the js files in cache
401 $repair->module_list = array();
402 $repair->clearJsFiles();
406 $mb = new ModuleBuilder ( ) ;
407 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
408 $field->save ( $module ) ;
409 $module->mbvardefs->save () ;
410 // get the module again to refresh the labels we might have saved with the $field->save (e.g., for address fields)
411 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
412 if (isset ( $_REQUEST [ 'label' ] ) && isset ( $_REQUEST [ 'labelValue' ] ))
413 $module->setLabel ( $GLOBALS [ 'current_language' ], $_REQUEST [ 'label' ], $_REQUEST [ 'labelValue' ] ) ;
416 $this->view = 'modulefields' ;
419 function action_saveSugarField ()
422 require_once ('modules/DynamicFields/FieldCases.php') ;
423 $field = get_widget ( $_REQUEST [ 'type' ] ) ;
424 $_REQUEST [ 'name' ] = trim ( $_POST [ 'name' ] ) ;
426 $field->populateFromPost () ;
427 require_once ('modules/ModuleBuilder/parsers/StandardField.php') ;
428 $module = $_REQUEST [ 'view_module' ] ;
429 $df = new StandardField ( $module ) ;
430 $mod = BeanFactory::getBean($module);
431 $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
432 $df->setup ( $mod ) ;
434 $field->module = $mod;
435 $field->save ( $df ) ;
436 $this->action_SaveLabel () ;
438 $MBmodStrings = $mod_strings;
439 $GLOBALS [ 'mod_strings' ] = return_module_language ( '', 'Administration' ) ;
441 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
442 $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
443 $_REQUEST['execute_sql'] = true;
445 require_once('ModuleInstall/ModuleInstaller.php');
446 $mi = new ModuleInstaller();
448 $mi->rebuild_extensions();
450 $repair = new RepairAndClear();
451 $repair->repairAndClearAll(array('clearVardefs', 'clearTpls'), array($class_name), true, false);
452 //#28707 ,clear all the js files in cache
453 $repair->module_list = array();
454 $repair->clearJsFiles();
456 // now clear the cache so that the results are immediately visible
457 include_once ('include/TemplateHandler/TemplateHandler.php') ;
458 TemplateHandler::clearCache ( $module ) ;
460 $GLOBALS [ 'mod_strings' ] = $MBmodStrings;
463 function action_RefreshField ()
465 require_once ('modules/DynamicFields/FieldCases.php') ;
466 $field = get_widget ( $_POST [ 'type' ] ) ;
467 $field->populateFromPost () ;
468 $this->view = 'modulefield' ;
471 function action_saveVisibility ()
473 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
474 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
475 $parser = ParserFactory::getParser ( MB_VISIBILITY, $_REQUEST [ 'view_module' ], $packageName ) ;
477 $json = getJSONobj();
478 $visibility_grid = $json->decode(html_entity_decode(rawurldecode($_REQUEST [ 'visibility_grid' ]), ENT_QUOTES) );
479 $parser->saveVisibility ( $_REQUEST [ 'fieldname' ] , $_REQUEST [ 'trigger' ] , $visibility_grid ) ;
481 echo $json->encode(array( "visibility_editor_{$_REQUEST['fieldname']}" => array("action" => "deactivate")));
484 function action_SaveRelationshipLabel (){
485 $selected_lang = (!empty($_REQUEST['relationship_lang'])?$_REQUEST['relationship_lang']:$_SESSION['authenticated_user_language']);
486 if (empty($_REQUEST [ 'view_package' ])){
487 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
488 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
489 if (! empty ( $_REQUEST [ 'relationship_name' ] ))
491 if ($relationship = $relationships->get ( $_REQUEST [ 'relationship_name' ] )){
492 $metadata = $relationship->buildLabels(true);
493 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
494 $parser = new ParserLabel ( $_REQUEST['view_module'] ) ;
495 $parser->handleSaveRelationshipLabels ( $metadata, $selected_lang ) ;
502 $this->view = 'relationships' ;
505 function action_SaveRelationship ()
507 if(!empty($GLOBALS['current_user']) && empty($GLOBALS['modListHeader']))
509 $GLOBALS['modListHeader'] = query_module_access_list($GLOBALS['current_user']);
512 if (empty($_REQUEST [ 'view_package' ]))
514 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
515 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
518 $mb = new ModuleBuilder ( ) ;
519 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
520 require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
521 $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
524 $relationships->addFromPost () ;
525 $relationships->save () ;
526 $GLOBALS['log']->debug("\n\nSTART BUILD");
527 if (empty($_REQUEST [ 'view_package' ])) {
528 $relationships->build () ;
529 LanguageManager::clearLanguageCache($_REQUEST [ 'view_module' ]);
531 $GLOBALS['log']->debug("\n\nEND BUILD");
532 $this->view = 'relationships' ;
535 function action_DeleteRelationship ()
537 if (isset ( $_REQUEST [ 'relationship_name' ] ))
539 if (empty($_REQUEST [ 'view_package' ] ))
541 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
542 if (!empty($_REQUEST['remove_tables']))
543 $GLOBALS['mi_remove_tables'] = $_REQUEST['remove_tables'];
544 $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
547 $mb = new ModuleBuilder ( ) ;
548 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
549 require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
550 $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
552 $relationships->delete ( $_REQUEST [ 'relationship_name' ] ) ;
554 $relationships->save () ;
555 require_once("data/Relationships/RelationshipFactory.php");
556 SugarRelationshipFactory::deleteCache();
558 $this->view = 'relationships' ;
561 function action_SaveDropDown ()
563 require_once 'modules/ModuleBuilder/parsers/parser.dropdown.php' ;
564 $parser = new ParserDropDown ( ) ;
565 $parser->saveDropDown ( $_REQUEST ) ;
566 $this->view = 'dropdowns' ;
569 function action_DeleteField ()
571 require_once ('modules/DynamicFields/FieldCases.php') ;
572 $field = get_widget ( $_REQUEST [ 'type' ] ) ;
573 $field->name = $_REQUEST [ 'name' ] ;
574 if (!isset ( $_REQUEST [ 'view_package' ] ))
576 if (! empty ( $_REQUEST [ 'name' ] ) && ! empty ( $_REQUEST [ 'view_module' ] ))
578 require_once ('modules/DynamicFields/DynamicField.php') ;
579 $moduleName = $_REQUEST [ 'view_module' ] ;
580 $class_name = $GLOBALS [ 'beanList' ] [ $moduleName ] ;
581 require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
582 $seed = new $class_name ( ) ;
583 $df = new DynamicField ( $moduleName ) ;
584 $df->setup ( $seed ) ;
585 //Need to load the entire field_meta_data for some field types
586 $field = $df->getFieldWidget($moduleName, $field->name);
587 $field->delete ( $df ) ;
589 $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
590 $_REQUEST['execute_sql'] = true;
591 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
592 $repair = new RepairAndClear();
593 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
594 require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php' ;
595 $module = StudioModuleFactory::getStudioModule( $moduleName ) ;
600 $mb = new ModuleBuilder ( ) ;
601 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
602 $field->delete ( $module ) ;
605 $module->removeFieldFromLayouts( $field->name );
606 $this->view = 'modulefields' ;
608 if (isset($GLOBALS['current_language']) && isset($_REQUEST['label']) &&
609 isset($_REQUEST['labelValue']) && isset($_REQUEST['view_module'])) {
610 $this->DeleteLabel($GLOBALS['current_language'], $_REQUEST['label'], $_REQUEST['labelValue'], $_REQUEST['view_module']);
614 function DeleteLabel($language, $label, $labelvalue, $modulename, $basepath = null, $forRelationshipLabel = false)
617 require_once 'modules/ModuleBuilder/parsers/parser.label.php';
618 ParserLabel::removeLabel($language, $label, $labelvalue, $modulename, $basepath, $forRelationshipLabel);
621 function action_CloneField ()
623 $this->view_object_map [ 'field_name' ] = $_REQUEST [ 'name' ] ;
624 $this->view_object_map [ 'is_clone' ] = true ;
625 $this->view = 'modulefield' ;
628 function action_SaveAssistantPref ()
630 global $current_user ;
631 if (isset ( $_REQUEST [ 'pref_value' ] ))
633 if ($_REQUEST [ 'pref_value' ] == 'ignore')
635 $current_user->setPreference ( 'mb_assist', 'DISABLED', 0, 'Assistant' ) ;
638 $current_user->setPreference ( 'mb_assist', 'ENABLED', 0, 'Assistant' ) ;
640 $current_pref = $current_user->getPreference ( 'mb_assist', 'Assistant' ) ;
641 echo "Assistant.processUserPref('$current_pref')" ;
642 sugar_cleanup ( true ) ; //push preferences to DB.
649 function action_EditProperty ()
651 $this->view = 'property' ;
654 function action_saveProperty ()
656 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
657 $modules = $_REQUEST['view_module'];
658 if(!empty($_REQUEST['subpanel'])){
659 $modules = $_REQUEST['subpanel'];
661 $parser = new ParserLabel ( $modules , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
662 // if no language provided, then use the user's current language which is most likely what they intended
663 $language = (isset($_REQUEST [ 'selected_lang' ])) ? $_REQUEST [ 'selected_lang' ] : $GLOBALS['current_language'] ;
664 $parser->handleSave ( $_REQUEST, $language ) ;
665 $json = getJSONobj();
666 echo $json->encode(array("east" => array("action" => "deactivate")));
669 function action_editModule ()
671 $this->view = 'module' ;
674 function action_wizard ()
676 $this->view = 'wizard' ;
680 * Receive a layout through $_REQUEST and save it out to the working files directory
681 * Expects a series of $_REQUEST parameters all in the format $_REQUEST['slot-panel#-slot#-property']=value
684 function action_saveLayout ()
686 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
687 $this->view = 'layoutview' ;
688 $parser->writeWorkingFile () ;
690 if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
691 if(strtolower ($parser->_view) == MB_EDITVIEW){
692 $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
693 $parser2->setUseTabs($parser->getUseTabs());
694 $parser2->writeWorkingFile () ;
699 function action_saveAndPublishLayout ()
701 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
702 $this->view = 'layoutview' ;
703 $parser->handleSave () ;
705 if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
706 if(strtolower ($parser->_view) == MB_EDITVIEW){
707 $parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
708 $parser2->setUseTabs($parser->getUseTabs());
709 $parser2->handleSave () ;
714 function action_manageBackups ()
719 function action_listViewSave ()
721 $GLOBALS [ 'log' ]->info ( "action_listViewSave" ) ;
723 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
724 $subpanelName = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : null ;
725 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
726 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName, $subpanelName ) ;
727 $this->view = 'listView' ;
728 $parser->handleSave () ;
732 function action_dashletSave () {
733 $this->view = 'dashlet' ;
734 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
735 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
736 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
737 $parser->handleSave () ;
740 function action_popupSave(){
741 $this->view = 'popupview' ;
742 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
743 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
744 $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
745 $parser->handleSave () ;
746 if(empty($packageName)){
747 include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
749 $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
750 $repair = new RepairAndClear();
751 $repair->show_output = false;
752 $class_name = $GLOBALS [ 'beanList' ] [ $_REQUEST [ 'view_module' ] ] ;
753 $repair->module_list = array($class_name);
754 $repair->clearTpls();
759 function action_searchViewSave ()
761 $packageName = (isset ( $_REQUEST [ 'view_package' ] )) ? $_REQUEST [ 'view_package' ] : null ;
762 require_once 'modules/ModuleBuilder/parsers/views/SearchViewMetaDataParser.php' ;
763 $parser = new SearchViewMetaDataParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
764 $parser->handleSave () ;
767 //Repair or create a custom SearchFields.php file as needed
768 $module_name = $_REQUEST [ 'view_module' ] ;
770 if (isset($beanList[$module_name]) && $beanList[$module_name]!="") {
771 $objectName = BeanFactory::getObjectName($module_name);
773 //Load the vardefs for the module to pass to TemplateRange
774 VardefManager::loadVardef($module_name, $objectName, true);
776 $vardefs = $dictionary[$objectName]['fields'];
777 require_once('modules/DynamicFields/templates/Fields/TemplateRange.php');
778 TemplateRange::repairCustomSearchFields($vardefs, $module_name, $packageName);
780 $this->view = 'searchView' ;
783 function action_editLabels ()
785 if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
787 $this->view = 'modulelabels';
789 $this->view = 'labels';
793 function action_get_app_list_string ()
795 require_once ('include/JSON.php') ;
796 $json = new JSON ( ) ;
797 if (isset ( $_REQUEST [ 'key' ] ) && ! empty ( $_REQUEST [ 'key' ] ))
799 $key = $_REQUEST [ 'key' ] ;
801 if (! empty ( $GLOBALS [ 'app_list_strings' ] [ $key ] ))
803 $value = $GLOBALS [ 'app_list_strings' ] [ $key ] ;
806 $package_strings = array ( ) ;
807 if (! empty ( $_REQUEST [ 'view_package' ] ) && $_REQUEST [ 'view_package' ] != 'studio' && ! empty ( $_REQUEST [ 'view_module' ] ))
809 require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
810 $mb = new ModuleBuilder ( ) ;
811 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
812 $lang = $GLOBALS [ 'current_language' ] ;
813 $module->mblanguage->generateAppStrings ( false ) ;
814 $package_strings = $module->mblanguage->appListStrings [ $lang . '.lang.php' ] ;
815 if (isset ( $package_strings [ $key ] ) && is_array ( $package_strings [ $key ] ))
817 $value = $package_strings [ $key ] ;
821 echo $json->encode ( $value ) ;
825 function action_history ()
827 $this->view = 'history' ;
830 function resetmodule()
832 $this->view = 'resetmodule';