function display()
 {
     global $app_strings, $current_user, $mod_strings, $app_list_strings;
     $smarty = new Sugar_Smarty();
     require_once 'include/JSON.php';
     //Load the field list from the target module
     $selected_lang = $_SESSION['authenticated_user_language'];
     $vardef = array();
     //Copy app strings
     $my_list_strings = array_merge($app_list_strings);
     $child = $_REQUEST['field'];
     //if we are using ModuleBuilder then process the following
     if (!empty($_REQUEST['package']) && $_REQUEST['package'] != 'studio') {
         require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
         $mb = new ModuleBuilder();
         $this->module = $mb->getPackageModule($_REQUEST['package'], $_REQUEST['view_module']);
         $vardef = $this->module->getVardefs();
         $this->module->mblanguage->generateAppStrings(false);
         $my_list_strings = array_merge($my_list_strings, $this->module->mblanguage->appListStrings[$selected_lang . '.lang.php']);
     } else {
         $vardef = BeanFactory::getBean($_REQUEST['view_module'])->field_defs;
     }
     foreach ($my_list_strings as $key => $value) {
         if (!is_array($value)) {
             unset($my_list_strings[$key]);
         }
     }
     $parents = $this->getParentDDs($vardef, $child, $my_list_strings);
     $visibility_grid = !empty($vardef[$child]['visibility_grid']) ? $vardef[$child]['visibility_grid'] : array();
     $smarty->assign('app_strings', $app_strings);
     $smarty->assign('mod', $mod_strings);
     $smarty->assign('parents', JSON::encode($parents));
     $smarty->assign('visibility_grid', JSON::encode($visibility_grid));
     $smarty->display('modules/ExpressionEngine/tpls/ddEditor.tpl');
 }
 /**
  * Takes in the request params from a save request and processes
  * them for the save.
  *
  * @param REQUEST params  $params
  */
 function saveDropDown($params)
 {
     require_once 'modules/Administration/Common.php';
     $emptyMarker = translate('LBL_BLANK');
     $selected_lang = !empty($params['dropdown_lang']) ? $params['dropdown_lang'] : $_SESSION['authenticated_user_language'];
     $type = $_REQUEST['view_package'];
     $dir = '';
     $dropdown_name = $params['dropdown_name'];
     $json = getJSONobj();
     $list_value = str_replace('"":""', '"__empty__":""', $params['list_value']);
     //Bug 21362 ENT_QUOTES- convert single quotes to escaped single quotes.
     $dropdown = $json->decode(html_entity_decode(rawurldecode($list_value), ENT_QUOTES));
     if (array_key_exists($emptyMarker, $dropdown)) {
         unset($dropdown[$emptyMarker]);
         $dropdown[''] = '';
     }
     if ($type != 'studio') {
         $mb = new ModuleBuilder();
         $module =& $mb->getPackageModule($params['view_package'], $params['view_module']);
         $this->synchMBDropDown($dropdown_name, $dropdown, $selected_lang, $module);
         //Can't use synch on selected lang as we want to overwrite values, not just keys
         $module->mblanguage->appListStrings[$selected_lang . '.lang.php'][$dropdown_name] = $dropdown;
         $module->mblanguage->save($module->key_name);
         // tyoung - key is required parameter as of
     } else {
         $contents = return_custom_app_list_strings_file_contents($selected_lang);
         $my_list_strings = return_app_list_strings_language($selected_lang);
         if ($selected_lang == $GLOBALS['current_language']) {
             $GLOBALS['app_list_strings'][$dropdown_name] = $dropdown;
         }
         //write to contents
         $contents = str_replace("?>", '', $contents);
         if (empty($contents)) {
             $contents = "<?php";
         }
         //add new drop down to the bottom
         if (!empty($params['use_push'])) {
             //this is for handling moduleList and such where nothing should be deleted or anything but they can be renamed
             foreach ($dropdown as $key => $value) {
                 //only if the value has changed or does not exist do we want to add it this way
                 if (!isset($my_list_strings[$dropdown_name][$key]) || strcmp($my_list_strings[$dropdown_name][$key], $value) != 0) {
                     //clear out the old value
                     $pattern_match = '/\\s*\\$app_list_strings\\s*\\[\\s*\'' . $dropdown_name . '\'\\s*\\]\\[\\s*\'' . $key . '\'\\s*\\]\\s*=\\s*[\'\\"]{1}.*?[\'\\"]{1};\\s*/ism';
                     $contents = preg_replace($pattern_match, "\n", $contents);
                     //add the new ones
                     $contents .= "\n\$GLOBALS['app_list_strings']['{$dropdown_name}']['{$key}']=" . var_export_helper($value) . ";";
                 }
             }
         } else {
             //Now synch up the keys in other langauges to ensure that removed/added Drop down values work properly under all langs.
             $this->synchDropDown($dropdown_name, $dropdown, $selected_lang, $dir);
             $contents = $this->getNewCustomContents($dropdown_name, $dropdown, $selected_lang);
         }
         if (!empty($dir) && !is_dir($dir)) {
             $continue = mkdir_recursive($dir);
         }
         save_custom_app_list_strings_contents($contents, $selected_lang, $dir);
     }
     sugar_cache_reset();
 }
 /**
  * The constructor
  * @param string $subpanelName
  * @param string $moduleName
  * @param string $packageName
  * @param string $client
  */
 public function __construct($subpanelName, $moduleName, $packageName, $client = '')
 {
     $this->mdc = new MetaDataConverter();
     $this->_subpanelName = $subpanelName;
     $this->_moduleName = $moduleName;
     $this->client = empty($client) ? 'base' : $client;
     // TODO: history
     $this->historyPathname = "custom/history/modulebuilder/packages/{$packageName}/modules/{$moduleName}/metadata/" . self::HISTORYFILENAME;
     $this->_history = new History($this->historyPathname);
     //get the bean from ModuleBuilder
     $mb = new ModuleBuilder();
     $this->module = $mb->getPackageModule($packageName, $moduleName);
     $this->module->mbvardefs->updateVardefs();
     $templates = $this->module->config['templates'];
     $template_def = "";
     foreach ($templates as $template => $a) {
         if ($a === 1) {
             $template_def = $template;
         }
     }
     $template_subpanel_def = "include/SugarObjects/templates/{$template_def}/clients/{$this->client}/views/subpanel-list/subpanel-list.php";
     $viewdefs = array();
     if (file_exists($template_subpanel_def)) {
         include $template_subpanel_def;
         if (isset($viewdefs['<module_name>'])) {
             $viewdefs[$this->module->key_name] = $viewdefs['<module_name>'];
             unset($viewdefs['<module_name>']);
         }
     }
     if ($subpanelName != 'default' && !stristr($subpanelName, 'for')) {
         $subpanelName = 'For' . ucfirst($subpanelName);
     }
     $this->sidecarSubpanelName = $this->mdc->fromLegacySubpanelName($subpanelName);
     // Set the original view defs from the loaded file if there are any
     $this->_originalViewdefs = $this->getNewViewDefs($viewdefs);
     $this->sidecarFile = $this->module->getSubpanelFilePath($subpanelName, $this->client);
     if (file_exists($this->sidecarFile)) {
         include $this->sidecarFile;
     }
     $viewdefs = empty($viewdefs) ? array() : $viewdefs;
     $this->_viewdefs = $this->getNewViewDefs($viewdefs);
     $this->_fielddefs = $this->getFieldDefs();
     $this->_paneldefs = isset($this->_viewdefs['panels']) ? $this->_viewdefs['panels'] : array();
     // Set the global mod_strings directly as Sugar does not automatically load the
     // language files for undeployed modules (how could it?)
     $selected_lang = 'en_us';
     if (isset($GLOBALS['current_language']) && !empty($GLOBALS['current_language'])) {
         $selected_lang = $GLOBALS['current_language'];
     }
     $GLOBALS['mod_strings'] = array_merge($GLOBALS['mod_strings'], $this->module->getModStrings($selected_lang));
 }
 function display()
 {
     $moduleName = !empty($_REQUEST['view_module']) ? $_REQUEST['view_module'] : $_REQUEST['edit_module'];
     $smarty = new Sugar_Smarty();
     // set the mod_strings as we can be called after doing a Repair and the mod_strings are set to Administration
     $GLOBALS['mod_strings'] = return_module_language($GLOBALS['current_language'], 'ModuleBuilder');
     $smarty->assign('mod_strings', $GLOBALS['mod_strings']);
     $smarty->assign('view_module', $moduleName);
     $ajax = new AjaxCompose();
     $json = getJSONobj();
     $this->fromModuleBuilder = !empty($_REQUEST['MB']) || !empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio';
     $smarty->assign('fromModuleBuilder', $this->fromModuleBuilder);
     if (!$this->fromModuleBuilder) {
         $smarty->assign('view_package', '');
         $relationships = new DeployedRelationships($moduleName);
         $ajaxRelationships = $this->getAjaxRelationships($relationships);
         $smarty->assign('relationships', $json->encode($ajaxRelationships));
         $smarty->assign('empty', sizeof($ajaxRelationships) == 0);
         $smarty->assign('studio', true);
         //crumb
         global $app_list_strings;
         $moduleNames = array_change_key_case($app_list_strings['moduleList']);
         $translatedModule = $moduleNames[strtolower($moduleName)];
         $ajax->addCrumb(translate('LBL_STUDIO'), 'ModuleBuilder.main("studio")');
         $ajax->addCrumb($translatedModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $moduleName . '")');
         $ajax->addCrumb(translate('LBL_RELATIONSHIPS'), '');
         $ajax->addSection('center', $moduleName . ' ' . translate('LBL_RELATIONSHIPS'), $this->fetchTemplate($smarty, 'modules/ModuleBuilder/tpls/studioRelationships.tpl'));
     } else {
         $smarty->assign('view_package', $_REQUEST['view_package']);
         $mb = new ModuleBuilder();
         $module =& $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
         $package = $mb->packages[$_REQUEST['view_package']];
         $package->loadModuleTitles();
         $relationships = new UndeployedRelationships($module->getModuleDir());
         $ajaxRelationships = $this->getAjaxRelationships($relationships);
         $smarty->assign('relationships', $json->encode($ajaxRelationships));
         $smarty->assign('empty', sizeof($ajaxRelationships) == 0);
         $module->help['default'] = empty($_REQUEST['view_module']) ? 'create' : 'modify';
         $module->help['group'] = 'module';
         $ajax->addCrumb(translate('LBL_MODULEBUILDER'), 'ModuleBuilder.main("mb")');
         $ajax->addCrumb($package->name, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $package->name . '")');
         $ajax->addCrumb($moduleName, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $package->name . '&view_module=' . $moduleName . '")');
         $ajax->addCrumb(translate('LBL_RELATIONSHIPS'), '');
         $ajax->addSection('center', $moduleName . ' ' . translate('LBL_RELATIONSHIPS'), $this->fetchTemplate($smarty, 'modules/ModuleBuilder/tpls/studioRelationships.tpl'));
     }
     echo $ajax->getJavascript();
 }
 function __construct($subpanelName, $moduleName, $packageName)
 {
     // Needed to tap into the abstract for loading and saving
     $this->_view = 'subpanel_layout';
     $this->_fileVariables['subpanel_layout'] = 'subpanel_layout';
     $this->_subpanelName = $subpanelName;
     $this->_moduleName = $moduleName;
     // TODO: history
     $this->historyPathname = 'custom/history/modulebuilder/packages/' . $packageName . '/modules/' . $moduleName . '/metadata/' . self::HISTORYFILENAME;
     $this->_history = new History($this->historyPathname);
     //get the bean from ModuleBuilder
     $mb = new ModuleBuilder();
     $this->module =& $mb->getPackageModule($packageName, $moduleName);
     $this->module->mbvardefs->updateVardefs();
     $this->_fielddefs =& $this->module->mbvardefs->vardefs['fields'];
     $templates =& $this->module->config['templates'];
     $template_def = "";
     foreach ($templates as $template => $a) {
         if ($a === 1) {
             $template_def = $template;
         }
     }
     $templateFile = 'include/SugarObjects/templates/' . $template_def . '/metadata/subpanels/default.php';
     if (file_exists($templateFile)) {
         $subpanel_layout = $this->_loadFromFile($templateFile);
         if (!empty($subpanel_layout['list_fields'])) {
             $originalDef = $subpanel_layout['list_fields'];
             // This has to be done early because once they are in field defs
             // they won't be picked up
             $this->setNonFields($originalDef);
             $this->_mergeFielddefs($this->_fielddefs, $originalDef);
         }
     }
     $filename = $this->module->getSubpanelFilePath($this->_subpanelName, '', true);
     $subpanel_layout = $this->_loadFromFile($filename);
     $this->_originalViewdefs = $subpanel_layout['list_fields'];
     $this->_viewdefs =& $subpanel_layout['list_fields'];
     $this->_mergeFielddefs($this->_fielddefs, $this->_viewdefs);
     // Set the global mod_strings directly as Sugar does not automatically load the language files for undeployed modules (how could it?)
     $selected_lang = 'en_us';
     if (isset($GLOBALS['current_language']) && !empty($GLOBALS['current_language'])) {
         $selected_lang = $GLOBALS['current_language'];
     }
     $GLOBALS['mod_strings'] = array_merge($GLOBALS['mod_strings'], $this->module->getModStrings($selected_lang));
 }
 function display()
 {
     $this->ss = new Sugar_Smarty();
     foreach ($this->vars as $var) {
         if (isset($_REQUEST[$var])) {
             $this->{$var} = $_REQUEST[$var];
             $this->ss->assign($var, $_REQUEST[$var]);
         }
     }
     $mapping = empty($_REQUEST['mapping']) ? array() : json_decode(html_entity_decode($_REQUEST['mapping']), true);
     $this->ss->assign("mapping", $mapping);
     if (empty($_REQUEST['package']) || $_REQUEST['package'] == 'studio') {
         $sm = StudioModuleFactory::getStudioModule($_REQUEST['targetModule']);
         $fields = $sm->getFields();
         if (!empty($fields[$this->parentList]) && !empty($fields[$this->parentList]['options'])) {
             $this->parentList = $fields[$this->parentList]['options'];
         }
         $parentOptions = translate($this->parentList);
         $childOptions = translate($this->childList);
     } else {
         $mb = new ModuleBuilder();
         $moduleName = $_REQUEST['targetModule'];
         $sm = $mb->getPackageModule($_REQUEST['package'], $moduleName);
         $sm->getVardefs();
         $fields = $sm->mbvardefs->vardefs['fields'];
         if (!empty($fields[$this->parentList]) && !empty($fields[$this->parentList]['options'])) {
             $this->parentList = $fields[$this->parentList]['options'];
         }
         $parentOptions = $this->getMBOptions($this->parentList, $sm);
         $childOptions = $this->getMBOptions($this->childList, $sm);
     }
     $this->ss->assign("parent_list_options", $parentOptions);
     $parentOptionsArray = array();
     foreach ($parentOptions as $value => $label) {
         $parentOptionsArray[] = array("value" => $value, "label" => $label);
     }
     $this->ss->assign("parentOptions", json_encode($parentOptions));
     $this->ss->assign("child_list_options", $childOptions);
     $childOptionsArray = array();
     foreach ($childOptions as $value => $label) {
         $childOptionsArray[] = array("value" => $value, "label" => $label);
     }
     $this->ss->assign("childOptions", json_encode($childOptionsArray));
     $this->ss->display("modules/ModuleBuilder/tpls/depdropdown.tpl");
 }
 /** {@inheritDoc} */
 public function getPath()
 {
     $path = $this->file->getPath();
     switch ($this->location) {
         case MB_HISTORYMETADATALOCATION:
             $path = array_merge(explode('/', trim(MetaDataFiles::$paths[MB_WORKINGMETADATALOCATION], '/')), array('modulebuilder', 'packages', $this->package), $path);
             break;
         default:
             // get the module again, all so we can call this method statically without relying
             // on the module stored in the class variables
             require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
             $mb = new ModuleBuilder();
             array_shift($path);
             $module = array_shift($path);
             $path = array_merge(explode('/', trim($mb->getPackageModule($this->package, $module)->getModuleDir(), '/')), $path);
     }
     return $path;
 }
 function __construct($subpanelName, $moduleName, $packageName)
 {
     $this->_subpanelName = $subpanelName;
     $this->_moduleName = $moduleName;
     // TODO: history
     $this->historyPathname = 'custom/history/modulebuilder/packages/' . $packageName . '/modules/' . $moduleName . '/metadata/' . self::HISTORYFILENAME;
     $this->_history = new History($this->historyPathname);
     //get the bean from ModuleBuilder
     $mb = new ModuleBuilder();
     $this->module =& $mb->getPackageModule($packageName, $moduleName);
     $this->module->mbvardefs->updateVardefs();
     $this->_fielddefs =& $this->module->mbvardefs->vardefs['fields'];
     $subpanel_layout = $this->module->getAvailibleSubpanelDef($this->_subpanelName);
     $this->_viewdefs =& $subpanel_layout['list_fields'];
     $this->_mergeFielddefs($this->_fielddefs, $this->_viewdefs);
     // Set the global mod_strings directly as Sugar does not automatically load the language files for undeployed modules (how could it?)
     $GLOBALS['mod_strings'] = array_merge($GLOBALS['mod_strings'], $this->module->getModStrings());
 }
 function display()
 {
     $this->fromModuleBuilder = isset($_REQUEST['MB']) || !empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio';
     if ($this->fromModuleBuilder) {
         return;
         //no support for MB
     }
     global $current_user;
     global $mod_strings;
     $smarty = new Sugar_Smarty();
     $smarty->assign('title', $mod_strings['LBL_DEVELOPER_TOOLS']);
     $smarty->assign('question', $mod_strings['LBL_REMOVE_LAYOUT']);
     $smarty->assign('mod_strings', $mod_strings);
     $module_name = $_REQUEST['view_module'];
     $smarty->assign('view_module', $module_name);
     $groupLayout = $_REQUEST['grpLayout'];
     $smarty->assign('groupLayout', $groupLayout);
     require_once 'modules/SecurityGroups/SecurityGroup.php';
     $groupFocus = new SecurityGroup();
     $groupFocus->retrieve($groupLayout);
     $groupName = $groupFocus->name;
     // set up language files
     //$smarty->assign ( 'language', $parser->getLanguage() ) ; // for sugar_translate in the smarty template
     //$smarty->assign('from_mb',$this->fromModuleBuilder);
     $mb = new ModuleBuilder();
     if (!isset($_REQUEST['view_package'])) {
         $_REQUEST['view_package'] = 'studio';
     }
     $module =& $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
     $package = $mb->packages[$_REQUEST['view_package']];
     $package->loadModuleTitles();
     $ajax = new AjaxCompose();
     $ajax->addCrumb(translate('LBL_STUDIO', 'ModuleBuilder'), 'ModuleBuilder.main("studio")');
     $ajax->addCrumb(translate($module_name), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $module_name . '")');
     $ajax->addCrumb(translate('LBL_LAYOUTS', 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=addlayout&layouts=1&view_module=' . $module_name . '")');
     $ajax->addCrumb(translate($groupName), '');
     $ajax->addCrumb($mod_strings['LBL_REMOVE_LAYOUT'], '');
     //$ajax->addSection ( 'center', $moduleName . ' ' . translate('LBL_ADD_LAYOUT'),
     $ajax->addSection('center', $mod_strings['LBL_ADD_LAYOUT'], $smarty->fetch('modules/ModuleBuilder/tpls/removegrouplayoutprompt.tpl'));
     echo $ajax->getJavascript();
 }
 /**
  * The constructor
  * @param string $moduleName
  * @param string $packageName
  * @param string $client
  */
 public function __construct($moduleName, $packageName, $client = '')
 {
     $this->_moduleName = $moduleName;
     $this->client = empty($client) ? 'base' : $client;
     // TODO: history
     $this->historyPathname = "custom/history/modulebuilder/packages/{$packageName}/modules/{$moduleName}/clients/{$client}/filters/default/" . self::HISTORYFILENAME;
     $this->_history = new History($this->historyPathname);
     //get the bean from ModuleBuilder
     $mb = new ModuleBuilder();
     $this->module = $mb->getPackageModule($packageName, $moduleName);
     $this->module->mbvardefs->updateVardefs();
     $templates = $this->module->config['templates'];
     $template_def = "";
     foreach ($templates as $template => $a) {
         if ($a === 1) {
             $template_def = $template;
         }
     }
     $template_filter_def = "include/SugarObjects/templates/{$template_def}/clients/{$this->client}/filters/default/default.php";
     if (file_exists($template_filter_def)) {
         include $template_filter_def;
     }
     $this->sidecarFile = "{$this->module->getModuleDir()}/clients/{$client}/filters/default/default.php";
     if (file_exists($this->sidecarFile)) {
         include $this->sidecarFile;
     }
     $viewdefs = empty($viewdefs) ? array('fields' => array()) : $viewdefs;
     $this->_viewdefs = $this->getNewViewDefs($viewdefs);
     $this->_fielddefs = $this->getFieldDefs();
     $this->_paneldefs = $this->_viewdefs;
     // Set the global mod_strings directly as Sugar does not automatically load the
     // language files for undeployed modules (how could it?)
     $selected_lang = 'en_us';
     if (isset($GLOBALS['current_language']) && !empty($GLOBALS['current_language'])) {
         $selected_lang = $GLOBALS['current_language'];
     }
     $GLOBALS['mod_strings'] = array_merge($GLOBALS['mod_strings'], $this->module->getModStrings($selected_lang));
 }
 function __construct($subpanelName, $moduleName, $packageName)
 {
     $this->_subpanelName = $subpanelName;
     $this->_moduleName = $moduleName;
     // TODO: history
     $this->historyPathname = 'custom/history/modulebuilder/packages/' . $packageName . '/modules/' . $moduleName . '/metadata/' . self::HISTORYFILENAME;
     $this->_history = new History($this->historyPathname);
     //get the bean from ModuleBuilder
     $mb = new ModuleBuilder();
     $this->module =& $mb->getPackageModule($packageName, $moduleName);
     $this->module->mbvardefs->updateVardefs();
     $this->_fielddefs =& $this->module->mbvardefs->vardefs['fields'];
     $templates =& $this->module->config['templates'];
     $template_def = "";
     foreach ($templates as $template => $a) {
         if ($a === 1) {
             $template_def = $template;
         }
     }
     $template_subpanel_def = 'include/SugarObjects/templates/' . $template_def . '/metadata/subpanels/default.php';
     if (file_exists($template_subpanel_def)) {
         include $template_subpanel_def;
         if (!empty($subpanel_layout['list_fields'])) {
             $this->_mergeFielddefs($this->_fielddefs, $subpanel_layout['list_fields']);
         }
     }
     $subpanel_layout = $this->module->getAvailibleSubpanelDef($this->_subpanelName);
     $this->_viewdefs =& $subpanel_layout['list_fields'];
     $this->_mergeFielddefs($this->_fielddefs, $this->_viewdefs);
     // Set the global mod_strings directly as Sugar does not automatically load the language files for undeployed modules (how could it?)
     $selected_lang = 'en_us';
     if (isset($GLOBALS['current_language']) && !empty($GLOBALS['current_language'])) {
         $selected_lang = $GLOBALS['current_language'];
     }
     $GLOBALS['mod_strings'] = array_merge($GLOBALS['mod_strings'], $this->module->getModStrings($selected_lang));
 }
Beispiel #12
0
 function generateSmarty()
 {
     //get the selected language
     $selected_lang = !empty($_REQUEST['dropdown_lang']) ? $_REQUEST['dropdown_lang'] : $_SESSION['authenticated_user_language'];
     $vardef = array();
     $package_name = 'studio';
     $package_strings = array();
     $new = false;
     $my_list_strings = return_app_list_strings_language($selected_lang);
     //		$my_list_strings = $GLOBALS['app_list_strings'];
     //if we are using ModuleBuilder then process the following
     if (!empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio') {
         require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
         $mb = new ModuleBuilder();
         $this->module =& $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
         $package =& $mb->packages[$_REQUEST['view_package']];
         $package_name = $package->name;
         $this->module->getVardefs();
         if (empty($_REQUEST['dropdown_name']) && !empty($_REQUEST['field'])) {
             $new = true;
             $_REQUEST['dropdown_name'] = $_REQUEST['field'] . '_list';
         }
         $vardef = !empty($this->module->mbvardefs->fields[$_REQUEST['dropdown_name']]) ? $this->module->mbvardefs->fields[$_REQUEST['dropdown_name']] : array();
         $this->module->mblanguage->generateAppStrings(false);
         $my_list_strings = array_merge($my_list_strings, $this->module->mblanguage->appListStrings[$selected_lang . '.lang.php']);
     }
     foreach ($my_list_strings as $key => $value) {
         if (!is_array($value)) {
             unset($my_list_strings[$key]);
         }
     }
     $dropdowns = array_keys($my_list_strings);
     asort($dropdowns);
     $keys = array_keys($dropdowns);
     $first_string = $my_list_strings[$dropdowns[$keys[0]]];
     if (!empty($cf)) {
         $smarty->assign('cf', $cf);
     }
     $name = '';
     $selected_dropdown = array();
     $smarty = new Sugar_Smarty();
     $json = getJSONobj();
     if (!empty($_REQUEST['dropdown_name']) && !$new) {
         $name = $_REQUEST['dropdown_name'];
         // handle the case where we've saved a dropdown in one language, and now attempt to edit it for another language. The $name exists, but $my_list_strings[$name] doesn't
         // for now, we just treat it as if it was new. A better approach might be to use the first language version as a template for future languages
         if (!isset($my_list_strings[$name])) {
             $my_list_strings[$name] = array();
         }
         $selected_dropdown = !empty($vardef['options']) && !empty($my_list_strings[$vardef['options']]) ? $my_list_strings[$vardef['options']] : $my_list_strings[$name];
         $smarty->assign('ul_list', 'list = ' . $json->encode(array_keys($selected_dropdown)));
         $smarty->assign('dropdown_name', !empty($vardef['options']) ? $vardef['options'] : $_REQUEST['dropdown_name']);
         $smarty->assign('name', $_REQUEST['dropdown_name']);
         $smarty->assign('options', $selected_dropdown);
     } else {
         $smarty->assign('ul_list', 'list = {}');
         //we should try to find a name for this dropdown based on the field name.
         $pre_pop_name = '';
         if (!empty($_REQUEST['field'])) {
             $pre_pop_name = $_REQUEST['field'];
         }
         //ensure this dropdown name does not already exist
         $use_name = $pre_pop_name . '_list';
         for ($i = 0; $i < 100; $i++) {
             if (empty($my_list_strings[$use_name])) {
                 break;
             } else {
                 $use_name = $pre_pop_name . '_' . $i;
             }
         }
         $smarty->assign('prepopulated_name', $use_name);
     }
     $smarty->assign('module', $this->module);
     $smarty->assign('APP', $GLOBALS['app_strings']);
     $smarty->assign('MOD', $GLOBALS['mod_strings']);
     $smarty->assign('selected_lang', $selected_lang);
     $smarty->assign('available_languages', get_languages());
     $smarty->assign('package_name', $package_name);
     return $smarty;
 }
Beispiel #13
0
 function display($preview = false)
 {
     global $mod_strings;
     $parser = ParserFactory::getParser($this->editLayout, $this->editModule, $this->package);
     if (isset($this->view_object_map['new_parser'])) {
         $parser = $this->view_object_map['new_parser'];
     }
     $history = $parser->getHistory();
     $smarty = new Sugar_Smarty();
     //Add in the module we are viewing to our current mod strings
     if (!$this->fromModuleBuilder) {
         global $current_language;
         $editModStrings = return_module_language($current_language, $this->editModule);
         $mod_strings = sugarArrayMerge($editModStrings, $mod_strings);
     }
     $smarty->assign('mod', $mod_strings);
     $smarty->assign('MOD', $mod_strings);
     // assign buttons
     $images = array('icon_save' => 'studio_save', 'icon_publish' => 'studio_publish', 'icon_address' => 'icon_Address', 'icon_emailaddress' => 'icon_EmailAddress', 'icon_phone' => 'icon_Phone');
     foreach ($images as $image => $file) {
         $smarty->assign($image, SugarThemeRegistry::current()->getImage($file, '', null, null, '.gif', $file));
     }
     $requiredFields = implode($parser->getRequiredFields(), ',');
     $slashedRequiredFields = addslashes($requiredFields);
     $buttons = array();
     $disableLayout = false;
     if ($preview) {
         $smarty->assign('layouttitle', translate('LBL_LAYOUT_PREVIEW', 'ModuleBuilder'));
     } else {
         $smarty->assign('layouttitle', translate('LBL_CURRENT_LAYOUT', 'ModuleBuilder'));
         //Check if we need to synch edit view to other layouts
         if ($this->editLayout == MB_DETAILVIEW || $this->editLayout == MB_QUICKCREATE) {
             $parser2 = ParserFactory::getParser(MB_EDITVIEW, $this->editModule, $this->package);
             if ($this->editLayout == MB_DETAILVIEW) {
                 $disableLayout = $parser2->getSyncDetailEditViews();
             }
             if (!empty($_REQUEST['copyFromEditView'])) {
                 $editViewPanels = $parser2->convertFromCanonicalForm($parser2->_viewdefs['panels'], $parser2->_fielddefs);
                 $parser->_viewdefs['panels'] = $editViewPanels;
                 $parser->_fielddefs = $parser2->_fielddefs;
                 $parser->setUseTabs($parser2->getUseTabs());
                 $parser->setTabDefs($parser2->getTabDefs());
             }
         }
         if (!$this->fromModuleBuilder) {
             $buttons[] = array('id' => 'saveBtn', 'text' => translate('LBL_BTN_SAVE'), 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handleSave();'", 'disabled' => $disableLayout);
             $buttons[] = array('id' => 'publishBtn', 'text' => translate('LBL_BTN_SAVEPUBLISH'), 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'", 'disabled' => $disableLayout);
             $buttons[] = array('id' => 'spacer', 'width' => '33px');
             $buttons[] = array('id' => 'historyBtn', 'text' => translate('LBL_HISTORY'), 'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'", 'disabled' => $disableLayout);
             $buttons[] = array('id' => 'historyDefault', 'text' => translate('LBL_RESTORE_DEFAULT'), 'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'", 'disabled' => $disableLayout);
         } else {
             $buttons[] = array('id' => 'saveBtn', 'text' => $GLOBALS['mod_strings']['LBL_BTN_SAVE'], 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'", 'disabled' => $disableLayout);
             $buttons[] = array('id' => 'spacer', 'width' => '33px');
             $buttons[] = array('id' => 'historyBtn', 'text' => translate('LBL_HISTORY'), 'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'", 'disabled' => $disableLayout);
             $buttons[] = array('id' => 'historyDefault', 'text' => translate('LBL_RESTORE_DEFAULT'), 'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'", 'disabled' => $disableLayout);
         }
         if ($this->editLayout == MB_DETAILVIEW || $this->editLayout == MB_QUICKCREATE) {
             $buttons[] = array('id' => 'copyFromEditView', 'text' => translate('LBL_COPY_FROM_EDITVIEW'), 'actionScript' => "onclick='ModuleBuilder.copyFromView(\"{$this->editModule}\", \"{$this->editLayout}\")'", 'disabled' => $disableLayout);
         }
     }
     $html = "";
     foreach ($buttons as $button) {
         if ($button['id'] == "spacer") {
             $html .= "<td style='width:{$button['width']}'> </td>";
         } else {
             $html .= "<td><input id='{$button['id']}' type='button' valign='center' class='button' style='cursor:pointer' " . "onmousedown='this.className=\"buttonOn\";return false;' onmouseup='this.className=\"button\"' " . "onmouseout='this.className=\"button\"' {$button['actionScript']} value = '{$button['text']}'";
             if (!empty($button['disabled'])) {
                 $html .= " disabled";
             }
             $html .= "></td>";
         }
     }
     $smarty->assign('buttons', $html);
     // assign fields and layout
     $smarty->assign('available_fields', $parser->getAvailableFields());
     $smarty->assign('disable_layout', $disableLayout);
     $smarty->assign('required_fields', $requiredFields);
     $smarty->assign('layout', $parser->getLayout());
     $smarty->assign('field_defs', $parser->getFieldDefs());
     $smarty->assign('view_module', $this->editModule);
     $smarty->assign('view', $this->editLayout);
     $smarty->assign('maxColumns', $parser->getMaxColumns());
     $smarty->assign('nextPanelId', $parser->getFirstNewPanelId());
     $smarty->assign('displayAsTabs', $parser->getUseTabs());
     $smarty->assign('tabDefs', $parser->getTabDefs());
     $smarty->assign('syncDetailEditViews', $parser->getSyncDetailEditViews());
     $smarty->assign('fieldwidth', 150);
     $smarty->assign('translate', $this->fromModuleBuilder ? false : true);
     if ($this->fromModuleBuilder) {
         $smarty->assign('fromModuleBuilder', $this->fromModuleBuilder);
         $smarty->assign('view_package', $this->package);
     }
     $labels = array(MB_EDITVIEW => 'LBL_EDITVIEW', MB_DETAILVIEW => 'LBL_DETAILVIEW', MB_QUICKCREATE => 'LBL_QUICKCREATE');
     $layoutLabel = 'LBL_LAYOUTS';
     $layoutView = 'layouts';
     $ajax = new AjaxCompose();
     $translatedViewType = '';
     if (isset($labels[strtolower($this->editLayout)])) {
         $translatedViewType = translate($labels[strtolower($this->editLayout)], 'ModuleBuilder');
     } else {
         if (isset($this->sm)) {
             foreach ($this->sm->sources as $file => $def) {
                 if (!empty($def['view']) && $def['view'] == $this->editLayout && !empty($def['name'])) {
                     $translatedViewType = $def['name'];
                 }
             }
             if (empty($translatedViewType)) {
                 $label = "LBL_" . strtoupper($this->editLayout);
                 $translated = translate($label, $this->editModule);
                 if ($translated != $label) {
                     $translatedViewType = $translated;
                 }
             }
         }
     }
     if ($this->fromModuleBuilder) {
         $ajax->addCrumb(translate('LBL_MODULEBUILDER', 'ModuleBuilder'), 'ModuleBuilder.main("mb")');
         $ajax->addCrumb($this->package, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $this->package . '")');
         $ajax->addCrumb($this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $this->package . '&view_module=' . $this->editModule . '")');
         $ajax->addCrumb(translate($layoutLabel, 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view=' . $layoutView . '&view_module=' . $this->editModule . '&view_package=' . $this->package . '")');
         $ajax->addCrumb($translatedViewType, '');
     } else {
         $ajax->addCrumb(translate('LBL_STUDIO', 'ModuleBuilder'), 'ModuleBuilder.main("studio")');
         $ajax->addCrumb($this->translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")');
         $ajax->addCrumb(translate($layoutLabel, 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=' . $layoutView . '&view_module=' . $this->editModule . '")');
         $ajax->addCrumb($translatedViewType, '');
     }
     // set up language files
     $smarty->assign('language', $parser->getLanguage());
     // for sugar_translate in the smarty template
     $smarty->assign('from_mb', $this->fromModuleBuilder);
     $smarty->assign('calc_field_list', json_encode($parser->getCalculatedFields()));
     if ($this->fromModuleBuilder) {
         $mb = new ModuleBuilder();
         $module =& $mb->getPackageModule($this->package, $this->editModule);
         $smarty->assign('current_mod_strings', $module->getModStrings());
     }
     $ajax->addSection('center', $translatedViewType, $smarty->fetch('modules/ModuleBuilder/tpls/layoutView.tpl'));
     if ($preview) {
         echo $smarty->fetch('modules/ModuleBuilder/tpls/Preview/layoutView.tpl');
     } else {
         echo $ajax->getJavascript();
     }
 }
 function fetch($ac = false)
 {
     $fv = new FieldViewer();
     if (empty($_REQUEST['field']) && !empty($_REQUEST['name'])) {
         $_REQUEST['field'] = $_REQUEST['name'];
     }
     $field_name = '';
     if (!empty($this->view_object_map['field_name'])) {
         $field_name = $this->view_object_map['field_name'];
     } elseif (!empty($_REQUEST['field'])) {
         $field_name = $_REQUEST['field'];
     } else {
         $field_name = '';
     }
     $action = 'saveField';
     // tyoung bug 17606: default action is to save as a dynamic field; but for standard OOB
     // fields we override this so don't create a new dynamic field instead of updating the existing field
     $isClone = false;
     if (!empty($this->view_object_map['is_clone']) && $this->view_object_map['is_clone'] && strcmp($field_name, "name") != 0) {
         $isClone = true;
     }
     /*
     $field_types =  array('varchar'=>'YourField', 'int'=>'Integer', 'float'=>'Decimal','bool'=>'Checkbox','enum'=>'DropDown',
     		'date'=>'Date', 'phone' => 'Phone', 'currency' => 'Currency', 'html' => 'HTML', 'radioenum' => 'Radio',
     		'relate' => 'Relate', 'address' => 'Address', 'text' => 'TextArea', 'url' => 'Link');
     */
     $field_types = $GLOBALS['mod_strings']['fieldTypes'];
     if (isset($field_types['encrypt'])) {
         unset($field_types['encrypt']);
     }
     $field_name_exceptions = array('ADD', 'EXCEPT', 'PERCENT', 'ALL', 'EXEC', 'PLAN', 'ALTER', 'EXECUTE', 'PRECISION', 'AND', 'EXISTS', 'PRIMARY', 'ANY', 'EXIT', 'PRINT', 'AS', 'FETCH', 'PROC', 'ASC', 'FILE', 'PROCEDURE', 'AUTHORIZATION', 'FILLFACTOR', 'PUBLIC', 'BACKUP', 'FOR', 'RAISERROR', 'BEGIN', 'FOREIGN', 'READ', 'BETWEEN', 'FREETEXT', 'READTEXT', 'BREAK', 'FREETEXTTABLE', 'RECONFIGURE', 'BROWSE', 'FROM', 'REFERENCES', 'BULK', 'FULL', 'REPLICATION', 'BY', 'FUNCTION', 'RESTORE', 'CASCADE', 'GOTO', 'RESTRICT', 'CASE', 'GRANT', 'RETURN', 'CHECK', 'GROUP', 'REVOKE', 'CHECKPOINT', 'HAVING', 'RIGHT', 'CLOSE', 'HOLDLOCK', 'ROLLBACK', 'CLUSTERED', 'IDENTITY', 'ROWCOUNT', 'COALESCE', 'IDENTITY_INSERT', 'ROWGUIDCOL', 'COLLATE', 'IDENTITYCOL', 'RULE', 'COLUMN', 'IF', 'SAVE', 'COMMIT', 'IN', 'SCHEMA', 'COMPUTE', 'INDEX', 'SELECT', 'CONSTRAINT', 'INNER', 'SESSION_USER', 'CONTAINS', 'INSERT', 'SET', 'CONTAINSTABLE', 'INTERSECT', 'SETUSER', 'CONTINUE', 'INTO', 'SHUTDOWN', 'CONVERT', 'IS', 'SOME', 'CREATE', 'JOIN', 'STATISTICS', 'CROSS', 'KEY', 'SYSTEM_USER', 'CURRENT', 'KILL', 'TABLE', 'CURRENT_DATE', 'LEFT', 'TEXTSIZE', 'CURRENT_TIME', 'LIKE', 'THEN', 'CURRENT_TIMESTAMP', 'LINENO', 'TO', 'CURRENT_USER', 'LOAD', 'TOP', 'CURSOR', 'NATIONAL', 'TRAN', 'DATABASE', 'NOCHECK', 'TRANSACTION', 'DBCC', 'NONCLUSTERED', 'TRIGGER', 'DEALLOCATE', 'NOT', 'TRUNCATE', 'DECLARE', 'NULL', 'TSEQUAL', 'DEFAULT', 'NULLIF', 'UNION', 'DELETE', 'OF', 'UNIQUE', 'DENY', 'OFF', 'UPDATE', 'DESC', 'OFFSETS', 'UPDATETEXT', 'DISK', 'ON', 'USE', 'DISTINCT', 'OPEN', 'USER', 'DISTRIBUTED', 'OPENCONNECTOR', 'VALUES', 'DOUBLE', 'OPENQUERY', 'VARYING', 'DROP', 'OPENROWSET', 'VIEW', 'DUMMY', 'OPENXML', 'WAITFOR', 'DUMP', 'OPTION', 'WHEN', 'ELSE', 'OR', 'WHERE', 'END', 'ORDER', 'WHILE', 'ERRLVL', 'OUTER', 'WITH', 'ESCAPE', 'OVER', 'WRITETEXT', 'ANALYZE', 'ASENSITIVE', 'BEFORE', 'BIGINT', 'BINARY', 'BOTH', 'CALL', 'CHANGE', 'CHARACTER', 'CONDITION', 'DATABASES', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', 'DEC', 'DECIMAL', 'DELAYED', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCTROW', 'DIV', 'DUAL', 'EACH', 'ELSEIF', 'ENCLOSED', 'ESCAPED', 'EXPLAIN', 'FALSE', 'FLOAT', 'FLOAT4', 'FLOAT8', 'FORCE', 'FULLTEXT', 'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', 'IGNORE', 'INFILE', 'INOUT', 'INSENSITIVE', 'INT', 'INT1', 'INT2', 'INT3', 'INT4', 'INT8', 'INTEGER', 'ITERATE', 'KEYS', 'LEADING', 'LEAVE', 'LIMIT', 'LINES', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCK', 'LONGBLOB', 'LONGTEXT', 'LOOP', 'LOW_PRIORITY', 'MATCH', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MOD', 'MODIFIES', 'NATURAL', 'NO_WRITE_TO_BINLOG', 'NUMERIC', 'OPTIMIZE', 'OPTIONALLY', 'OUT', 'OUTFILE', 'PURGE', 'READS', 'REAL', 'REGEXP', 'RELEASE', 'RENAME', 'REPEAT', 'REPLACE', 'REQUIRE', 'RLIKE', 'SCHEMAS', 'SECOND_MICROSECOND', 'SENSITIVE', 'SEPARATOR', 'SHOW', 'SMALLINT', 'SONAME', 'SPATIAL', 'SPECIFIC', 'SQL', 'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', 'SQL_BIG_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT', 'SSL', 'STARTING', 'STRAIGHT_JOIN', 'TERMINATED', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TRAILING', 'TRUE', 'UNDO', 'UNLOCK', 'UNSIGNED', 'USAGE', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'VARBINARY', 'VARCHARACTER', 'WRITE', 'XOR', 'YEAR_MONTH', 'ZEROFILL', 'CONNECTION', 'LABEL', 'UPGRADE', 'DATE', 'VARCHAR', 'VARCHAR2', 'NVARCHAR2', 'CHAR', 'NCHAR', 'NUMBER', 'PLS_INTEGER', 'BINARY_INTEGER', 'LONG', 'TIMESTAMP', 'INTERVAL', 'RAW', 'ROWID', 'UROWID', 'MLSLABEL', 'CLOB', 'NCLOB', 'BLOB', 'BFILE', 'XMLTYPE', 'ID', 'ID_C', 'PARENT_NAME', 'PARENT_ID');
     //C.L. - Add support to mark related module id columns as reserved keywords
     require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php';
     $relatedModules = array_keys(DeployedRelationships::findRelatableModules());
     global $beanList, $current_language;
     foreach ($relatedModules as $relModule) {
         if (isset($beanList[$relModule])) {
             $field_name_exceptions[] = strtoupper($beanList[$relModule]) . '_ID';
         }
     }
     if (empty($_REQUEST['view_package']) || $_REQUEST['view_package'] == 'studio') {
         $moduleName = $_REQUEST['view_module'];
         $objectName = BeanFactory::getObjectName($moduleName);
         $module = BeanFactory::getBean($moduleName);
         VardefManager::loadVardef($moduleName, $objectName, true);
         global $dictionary;
         // Fix for issue #1177 - when trying to add or edit fields in a module an error message is shown:
         // "Warning: Creating default object from empty value"
         if (!isset($module->mbvardefs) || is_null($module->mbvardefs)) {
             $module->mbvardefs = new stdClass();
         }
         $module->mbvardefs->vardefs = $dictionary[$objectName];
         $module->name = $moduleName;
         if (!$ac) {
             $ac = new AjaxCompose();
         }
         $vardef = !empty($module->mbvardefs->vardefs['fields'][$field_name]) ? $module->mbvardefs->vardefs['fields'][$field_name] : array();
         if ($isClone) {
             unset($vardef['name']);
         }
         if (empty($vardef['name'])) {
             if (!empty($_REQUEST['type'])) {
                 $vardef['type'] = $_REQUEST['type'];
             }
             $fv->ss->assign('hideLevel', 0);
         } elseif (isset($vardef['custom_module'])) {
             $fv->ss->assign('hideLevel', 2);
         } else {
             $action = 'saveSugarField';
             // tyoung - for OOB fields we currently only support modifying the label
             $fv->ss->assign('hideLevel', 3);
         }
         if ($isClone && isset($vardef['type']) && $vardef['type'] == 'datetime') {
             $vardef['type'] = 'datetimecombo';
         }
         require_once 'modules/DynamicFields/FieldCases.php';
         $tf = get_widget(empty($vardef['type']) ? "" : $vardef['type']);
         $tf->module = $module;
         $tf->populateFromRow($vardef);
         $vardef = array_merge($vardef, $tf->get_field_def());
         //          $GLOBALS['log']->debug('vardefs after loading = '.print_r($vardef,true));
         //Check if autoincrement fields are allowed
         $allowAutoInc = true;
         $enumFields = array();
         foreach ($module->field_defs as $field => $def) {
             if (!empty($def['type']) && $def['type'] == "int" && !empty($def['auto_increment'])) {
                 $allowAutoInc = false;
                 continue;
             }
             if (!empty($def['type']) && $def['type'] == "enum" && $field != $vardef['name']) {
                 if (!empty($def['studio']) && $def['studio'] == "false") {
                     continue;
                 }
                 //bug51866
                 $enumFields[$field] = translate($def['vname'], $moduleName);
                 if (substr($enumFields[$field], -1) == ":") {
                     $enumFields[$field] = substr($enumFields[$field], 0, strlen($enumFields[$field]) - 1);
                 }
             }
         }
         $fv->ss->assign('allowAutoInc', $allowAutoInc);
         $GLOBALS['log']->warn('view.modulefield: hidelevel ' . $fv->ss->get_template_vars('hideLevel') . " " . print_r($vardef, true));
         if (!empty($vardef['vname'])) {
             $fv->ss->assign('lbl_value', htmlentities(translate($vardef['vname'], $moduleName), ENT_QUOTES, 'UTF-8'));
         }
         $fv->ss->assign('module', $module);
         if (empty($module->mbvardefs->vardefs['fields']['parent_name']) || isset($vardef['type']) && $vardef['type'] == 'parent') {
             $field_types['parent'] = $GLOBALS['mod_strings']['parent'];
         }
         $edit_or_add = 'editField';
     } else {
         require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
         $mb = new ModuleBuilder();
         $moduleName = $_REQUEST['view_module'];
         $module =& $mb->getPackageModule($_REQUEST['view_package'], $moduleName);
         $package =& $mb->packages[$_REQUEST['view_package']];
         $module->getVardefs();
         if (!$ac) {
             $ac = new AjaxCompose();
         }
         $vardef = !empty($module->mbvardefs->vardefs['fields'][$field_name]) ? $module->mbvardefs->vardefs['fields'][$field_name] : array();
         if ($isClone) {
             unset($vardef['name']);
         }
         if (empty($vardef['name'])) {
             if (!empty($_REQUEST['type'])) {
                 $vardef['type'] = $_REQUEST['type'];
             }
             $fv->ss->assign('hideLevel', 0);
         } else {
             if (!empty($module->mbvardefs->vardef['fields'][$vardef['name']])) {
                 $fv->ss->assign('hideLevel', 1);
             } elseif (isset($vardef['custom_module'])) {
                 $fv->ss->assign('hideLevel', 2);
             } else {
                 $fv->ss->assign('hideLevel', 3);
                 // tyoung bug 17350 - effectively mark template derived fields as readonly
             }
         }
         require_once 'modules/DynamicFields/FieldCases.php';
         $tf = get_widget(empty($vardef['type']) ? "" : $vardef['type']);
         $tf->module = $module;
         $tf->populateFromRow($vardef);
         $vardef = array_merge($vardef, $tf->get_field_def());
         $fv->ss->assign('module', $module);
         $fv->ss->assign('package', $package);
         $fv->ss->assign('MB', '1');
         if (isset($vardef['vname'])) {
             $fv->ss->assign('lbl_value', htmlentities($module->getLabel('en_us', $vardef['vname']), ENT_QUOTES, 'UTF-8'));
         }
         if (empty($module->mbvardefs->vardefs['fields']['parent_name']) || isset($vardef['type']) && $vardef['type'] == 'parent') {
             $field_types['parent'] = $GLOBALS['mod_strings']['parent'];
         }
         $enumFields = array();
         if (!empty($module->mbvardefs->vardefs['fields'])) {
             foreach ($module->mbvardefs->vardefs['fields'] as $field => $def) {
                 if (!empty($def['type']) && $def['type'] == "enum" && $field != $vardef['name']) {
                     $enumFields[$field] = isset($module->mblanguage->strings[$current_language][$def['vname']]) ? $this->mbModule->mblanguage->strings[$current_language][$def['vname']] : translate($field);
                     if (substr($enumFields[$field], -1) == ":") {
                         $enumFields[$field] = substr($enumFields[$field], 0, strlen($enumFields[$field]) - 1);
                     }
                 }
             }
         }
         $edit_or_add = 'mbeditField';
     }
     if ($_REQUEST['action'] == 'RefreshField') {
         require_once 'modules/DynamicFields/FieldCases.php';
         $field = get_widget($_POST['type']);
         $field->populateFromPost();
         $vardef = $field->get_field_def();
         $vardef['options'] = $_REQUEST['new_dropdown'];
         $fv->ss->assign('lbl_value', htmlentities($_REQUEST['labelValue'], ENT_QUOTES, 'UTF-8'));
     }
     foreach (array("formula", "default", "comments", "help", "visiblityGrid") as $toEscape) {
         if (!empty($vardef[$toEscape]) && is_string($vardef[$toEscape])) {
             $vardef[$toEscape] = htmlentities($vardef[$toEscape], ENT_QUOTES, 'UTF-8');
         }
     }
     if (!empty($vardef['studio']) && is_array($vardef['studio']) && !empty($vardef['studio']['no_duplicate']) && $vardef['studio']['no_duplicate'] == true || strcmp($field_name, "name") == 0 || isset($vardef['type']) && $vardef['type'] == 'name') {
         $fv->ss->assign('no_duplicate', true);
     }
     $fv->ss->assign('action', $action);
     $fv->ss->assign('isClone', $isClone ? 1 : 0);
     $fv->ss->assign("module_dd_fields", $enumFields);
     $json = getJSONobj();
     $fv->ss->assign('field_name_exceptions', $json->encode($field_name_exceptions));
     ksort($field_types);
     $fv->ss->assign('field_types', $field_types);
     $fv->ss->assign('importable_options', $GLOBALS['app_list_strings']['custom_fields_importable_dom']);
     $fv->ss->assign('duplicate_merge_options', $GLOBALS['app_list_strings']['custom_fields_merge_dup_dom']);
     $triggers = array();
     $existing_field_names = array();
     foreach ($module->mbvardefs->vardefs['fields'] as $field) {
         if ($field['type'] == 'enum' || $field['type'] == 'multienum') {
             $triggers[] = $field['name'];
         }
         if (!isset($field['source']) || $field['source'] != 'non-db') {
             if (preg_match('/^(.*?)(_c)?$/', $field['name'], $matches)) {
                 $existing_field_names[] = strtoupper($matches[1]);
             }
         }
     }
     $fv->ss->assign('triggers', $triggers);
     $fv->ss->assign('existing_field_names', $json->encode($existing_field_names));
     $fv->ss->assign('mod_strings', $GLOBALS['mod_strings']);
     // jchi #24880
     // end
     $layout = $fv->getLayout($vardef);
     $fv->ss->assign('fieldLayout', $layout);
     if (empty($vardef['type'])) {
         $vardef['type'] = 'varchar';
     }
     $fv->ss->assign('vardef', $vardef);
     if (empty($_REQUEST['field'])) {
         $edit_or_add = 'addField';
     }
     $fv->ss->assign('help_group', $edit_or_add);
     $body = $this->fetchTemplate($fv, 'modules/ModuleBuilder/tpls/MBModule/field.tpl');
     $ac->addSection('east', translate('LBL_SECTION_FIELDEDITOR', 'ModuleBuilder'), $body);
     return $ac;
 }
function get_body(&$ss, $vardef)
{
    $multi = false;
    $radio = false;
    if (isset($vardef['type']) && $vardef['type'] == 'multienum') {
        $multi = true;
    }
    $selected_options = "";
    if ($multi && !empty($vardef['default'])) {
        $selected_options = unencodeMultienum($vardef['default']);
    } else {
        if (isset($vardef['default'])) {
            $selected_options = $vardef['default'];
        }
    }
    $edit_mod_strings = return_module_language($GLOBALS['current_language'], 'EditCustomFields');
    if (!empty($_REQUEST['type']) && $_REQUEST['type'] == 'radioenum') {
        $edit_mod_strings['LBL_DROP_DOWN_LIST'] = $edit_mod_strings['LBL_RADIO_FIELDS'];
        $radio = true;
    }
    $package_strings = array();
    if (!empty($_REQUEST['view_package'])) {
        $view_package = $_REQUEST['view_package'];
        if ($view_package != 'studio') {
            require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
            $mb = new ModuleBuilder();
            $module =& $mb->getPackageModule($view_package, $_REQUEST['view_module']);
            $lang = $GLOBALS['current_language'];
            //require_once($package->getPackageDir()."/include/language/$lang.lang.php");
            $module->mblanguage->generateAppStrings(false);
            $package_strings = $module->mblanguage->appListStrings[$lang . '.lang.php'];
        }
    }
    global $app_list_strings;
    $my_list_strings = $app_list_strings;
    $my_list_strings = array_merge($my_list_strings, $package_strings);
    foreach ($my_list_strings as $key => $value) {
        if (!is_array($value)) {
            unset($my_list_strings[$key]);
        }
    }
    $dropdowns = array_keys($my_list_strings);
    sort($dropdowns);
    $default_dropdowns = array();
    if (!empty($vardef['options']) && !empty($my_list_strings[$vardef['options']])) {
        $default_dropdowns = $my_list_strings[$vardef['options']];
    } else {
        //since we do not have a default value then we should assign the first one.
        $key = $dropdowns[0];
        $default_dropdowns = $my_list_strings[$key];
    }
    $selected_dropdown = '';
    if (!empty($vardef['options'])) {
        $selected_dropdown = $vardef['options'];
    }
    $show = true;
    if (!empty($_REQUEST['refresh_dropdown'])) {
        $show = false;
    }
    $ss->assign('dropdowns', $dropdowns);
    $ss->assign('default_dropdowns', $default_dropdowns);
    $ss->assign('selected_dropdown', $selected_dropdown);
    $ss->assign('show', $show);
    $ss->assign('selected_options', $selected_options);
    $ss->assign('multi', isset($multi) ? $multi : false);
    $ss->assign('radio', isset($radio) ? $radio : false);
    $ss->assign('dropdown_name', !empty($vardef['options']) ? $vardef['options'] : '');
    require_once 'include/JSON.php';
    $json = new JSON(JSON_LOOSE_TYPE);
    $ss->assign('app_list_strings', "''");
    return $ss->fetch('custom/modules/DynamicFields/templates/Fields/Forms/dynamicenum.tpl');
}
 protected function getRelateFieldDefinition($sourceModule, $relationshipName, $vnameLabel = '')
 {
     $vardef = array();
     $vardef['name'] = $this->getValidDBName($relationshipName . "_name");
     // must end in _name for the QuickSearch code in TemplateHandler->createQuickSearchCode
     $vardef['type'] = 'relate';
     $vardef['source'] = 'non-db';
     if (!empty($vnameLabel)) {
         $vardef['vname'] = 'LBL_' . strtoupper($relationshipName . '_FROM_' . $vnameLabel) . '_TITLE';
     } else {
         $vardef['vname'] = 'LBL_' . strtoupper($relationshipName . '_FROM_' . $sourceModule) . '_TITLE';
     }
     $vardef['save'] = true;
     // the magic value to tell SugarBean to save this relate field even though it is not listed in the $relationship_fields array
     // id_name matches the join_key_ column in the relationship table for the sourceModule - that is, the column in the relationship table containing the id of the corresponding field in the source module's table (vardef['table'])
     $vardef['id_name'] = $this->getIDName($sourceModule);
     // link cannot match id_name otherwise the $bean->$id_name value set from the POST is overwritten by the Link object created by this 'link' entry
     $vardef['link'] = $this->getValidDBName($relationshipName);
     // the name of the link field that points to the relationship - required for the save to function
     $vardef['table'] = $this->getTablename($sourceModule);
     $vardef['module'] = $sourceModule;
     $module = null;
     switch (strtolower($sourceModule)) {
         case 'prospects':
             $bean = BeanFactory::getBean($this->definition['rhs_module']);
             $fields = array_keys($bean->field_name_map);
             if (in_array('name', $fields)) {
                 $vardef['rname'] = 'name';
             } else {
                 $vardef['rname'] = 'account_name';
             }
             break;
         case 'documents':
             $vardef['rname'] = 'document_name';
             break;
         case 'kbdocuments':
             $vardef['rname'] = 'kbdocument_name';
             break;
         default:
             $module = $sourceModule;
             $vardef['rname'] = 'name';
             break;
     }
     if ($module) {
         $class = BeanFactory::getBean($module);
         $tplconfig = array();
         if (!$class) {
             $parsedModuleName = AbstractRelationships::parseDeployedModuleName($sourceModule);
             if (isset($parsedModuleName['packageName'])) {
                 // added relationship to yet non-deployed module
                 require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
                 $mb = new ModuleBuilder();
                 $module = $mb->getPackageModule($parsedModuleName['packageName'], $parsedModuleName['moduleName']);
                 $tplconfig = array_keys($module->config['templates']);
             } else {
                 throw new \RuntimeException('Module does not exist as a bean and no template found in its config');
             }
         }
         if (is_subclass_of($class, 'File') || in_array('file', $tplconfig)) {
             $vardef['rname'] = 'document_name';
         } elseif (is_subclass_of($class, 'Person') || in_array('person', $tplconfig)) {
             $vardef['rname'] = 'full_name';
             $vardef['db_concat_fields'] = array(0 => 'first_name', 1 => 'last_name');
         } elseif ($class && $class->getFieldDefinition('name')) {
             $vardef['rname'] = 'name';
         }
     }
     return $vardef;
 }
 /**
  * @param AbstractRelationship $relationship
  * @return void
  */
 private function removeAppLangStrings($relationship)
 {
     $def = $relationship->getDefinition();
     if (strtolower($def['rhs_module']) == 'activities' && !empty($_REQUEST['view_package']) && !empty($_REQUEST['view_module'])) {
         $mb = new ModuleBuilder();
         $module = $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
         $appStrings = $module->getAppListStrings();
         foreach (array('parent_type_display', 'record_type_display', 'record_type_display_notes') as $key) {
             if (isset($appStrings[$key][$module->key_name])) {
                 unset($appStrings[$key][$module->key_name]);
             }
         }
         $module->setAppListStrings('en_us', $appStrings);
         $module->save();
     }
 }
Beispiel #18
0
 function display()
 {
     $this->fromModuleBuilder = isset($_REQUEST['MB']) || !empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio';
     if ($this->fromModuleBuilder) {
         return;
         //no support for MB
     }
     global $current_user;
     global $mod_strings;
     $smarty = new Sugar_Smarty();
     $smarty->assign('title', $mod_strings['LBL_DEVELOPER_TOOLS']);
     $smarty->assign('question', $mod_strings['LBL_QUESTION_ADD_LAYOUT']);
     $smarty->assign('mod_strings', $mod_strings);
     $module_name = $_REQUEST['view_module'];
     //$securitygroups = array ( "Support" => "Support" , "Sales" => "Sales" ) ;
     //$copy_layouts = array ( "Default" => "Default", "Support" => "Support" , "Sales" => "Sales" ) ;
     //get security groups that do not have a layout for this module yet
     require_once 'modules/SecurityGroups/SecurityGroup.php';
     $securitygroups = array();
     $copy_layouts = array("Default" => translate('LBL_DEFAULT', 'ModuleBuilder'));
     $groupFocus = new SecurityGroup();
     $groups = $groupFocus->get_list("name", "", 0, 0, 999);
     $custDirectory = "custom/modules/" . $module_name . "/metadata/";
     foreach ($groups['list'] as $group) {
         if (is_dir($custDirectory . $group->id)) {
             $copy_layouts[$group->id] = $group->name;
         } else {
             $securitygroups[$group->id] = $group->name;
         }
     }
     if (empty($securitygroups)) {
         $securitygroups["-1"] = "[Create a Group First]";
     }
     /**
      
              // assign fields and layout
              $smarty->assign ( 'available_fields', $parser->getAvailableFields () ) ;
              $smarty->assign ( 'layout', $parser->getLayout () ) ;
              $smarty->assign ( 'view_module', $this->editModule ) ;
              $smarty->assign ( 'view', $this->editLayout ) ;
              $smarty->assign ( 'maxColumns', $parser->getMaxColumns() ) ;
              $smarty->assign ( 'nextPanelId', $parser->getFirstNewPanelId() ) ;
              $smarty->assign ( 'fieldwidth', '150px' ) ;
             $smarty->assign ( 'translate', true ) ;
     */
     //$this->smarty->assign ( 'view_module', $_REQUEST['view_module'] ) ;
     //$this->smarty->assign ( 'rel', $relationship->getDefinition () ) ;
     //$this->smarty->assign ( 'mod_strings', $GLOBALS [ 'mod_strings' ] ) ;
     //$this->smarty->assign ( 'module_key', $relationship->lhs_module ) ;
     $smarty->assign('securitygroups', array_keys($securitygroups));
     $smarty->assign('translated_securitygroups', $securitygroups);
     $smarty->assign('copy_layouts', array_keys($copy_layouts));
     $smarty->assign('translated_copy_layouts', $copy_layouts);
     $smarty->assign('view_module', $module_name);
     // set up language files
     //$smarty->assign ( 'language', $parser->getLanguage() ) ; // for sugar_translate in the smarty template
     //$smarty->assign('from_mb',$this->fromModuleBuilder);
     $mb = new ModuleBuilder();
     if (!isset($_REQUEST['view_package'])) {
         $_REQUEST['view_package'] = 'studio';
     }
     $module =& $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
     $package = $mb->packages[$_REQUEST['view_package']];
     $package->loadModuleTitles();
     $ajax = new AjaxCompose();
     $ajax->addCrumb(translate('LBL_STUDIO', 'ModuleBuilder'), 'ModuleBuilder.main("studio")');
     $ajax->addCrumb(translate($module_name), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $module_name . '")');
     $ajax->addCrumb(translate('LBL_LAYOUTS', 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=addlayout&layouts=1&view_module=' . $module_name . '")');
     $ajax->addCrumb($mod_strings['LBL_ADD_LAYOUT'], '');
     //$ajax->addSection ( 'center', $moduleName . ' ' . translate('LBL_ADD_LAYOUT'),
     $ajax->addSection('center', $mod_strings['LBL_ADD_LAYOUT'], $smarty->fetch('modules/ModuleBuilder/tpls/addlayout.tpl'));
     echo $ajax->getJavascript();
 }
 function display($preview = false)
 {
     global $mod_strings;
     $params = array();
     if (!empty($_REQUEST['role'])) {
         $role = $params['role'] = $_REQUEST['role'];
     } else {
         $role = null;
     }
     $this->parser = $parser = ParserFactory::getParser($this->editLayout, $this->editModule, $this->package, null, null, $params);
     $history = $parser->getHistory();
     $smarty = $this->getSmarty();
     //Add in the module we are viewing to our current mod strings
     if (!$this->fromModuleBuilder) {
         global $current_language;
         $editModStrings = return_module_language($current_language, $this->editModule);
         $mod_strings = sugarArrayMerge($editModStrings, $mod_strings);
     }
     $smarty->assign('mod', $mod_strings);
     $smarty->assign('MOD', $mod_strings);
     // assign buttons
     $images = array('icon_save' => 'studio_save', 'icon_publish' => 'studio_publish', 'icon_address' => 'icon_Address', 'icon_emailaddress' => 'icon_EmailAddress', 'icon_phone' => 'icon_Phone');
     foreach ($images as $image => $file) {
         $smarty->assign($image, SugarThemeRegistry::current()->getImage($file, '', null, null, '.gif', $file));
     }
     $requiredFields = implode($parser->getRequiredFields(), ',');
     $slashedRequiredFields = addslashes($requiredFields);
     $buttons = array();
     $disableLayout = false;
     if ($preview) {
         $smarty->assign('layouttitle', translate('LBL_LAYOUT_PREVIEW', 'ModuleBuilder'));
     } else {
         $smarty->assign('layouttitle', translate('LBL_CURRENT_LAYOUT', 'ModuleBuilder'));
         //Check if we need to synch edit view to other layouts
         if ($this->editLayout == MB_DETAILVIEW || $this->editLayout == MB_QUICKCREATE) {
             $parser2 = ParserFactory::getParser(MB_EDITVIEW, $this->editModule, $this->package);
             if ($this->editLayout == MB_DETAILVIEW) {
                 $disableLayout = $parser2->getSyncDetailEditViews();
             }
             if (!empty($_REQUEST['copyFromEditView'])) {
                 $editViewPanels = $parser2->convertFromCanonicalForm($parser2->_viewdefs['panels'], $parser2->_fielddefs);
                 $parser->_viewdefs['panels'] = $editViewPanels;
                 $parser->_fielddefs = $parser2->_fielddefs;
                 $parser->setUseTabs($parser2->getUseTabs());
                 $parser->setTabDefs($parser2->getTabDefs());
             }
         }
         $buttons = $this->getButtons($history, $disableLayout, $params);
         $implementation = $parser->getImplementation();
         $roles = $this->getRoleList($implementation);
         $copyFromOptions = $this->getRoleListWithMetadata($roles, $role);
         $smarty->assign('copy_from_options', $copyFromOptions);
     }
     $smarty->assign('buttons', $this->getButtonHTML($buttons));
     // assign fields and layout
     $smarty->assign('available_fields', $parser->getAvailableFields());
     $smarty->assign('disable_layout', $disableLayout);
     $smarty->assign('required_fields', $requiredFields);
     $smarty->assign('layout', $parser->getLayout());
     $smarty->assign('field_defs', $parser->getFieldDefs());
     $smarty->assign('view_module', $this->editModule);
     $smarty->assign('view', $this->editLayout);
     $smarty->assign('selected_role', $role);
     $smarty->assign('maxColumns', $parser->getMaxColumns());
     $smarty->assign('nextPanelId', $parser->getFirstNewPanelId());
     $smarty->assign('displayAsTabs', $parser->getUseTabs());
     $smarty->assign('tabDefs', $parser->getTabDefs());
     $smarty->assign('syncDetailEditViews', $parser->getSyncDetailEditViews());
     $smarty->assign('fieldwidth', 300 / $parser->getMaxColumns());
     // Bug 57260 - LBL_PANEL_DEFAULT not translated for undeployed modules in layout editor
     $smarty->assign('translate', true);
     if ($this->fromModuleBuilder) {
         $smarty->assign('fromModuleBuilder', $this->fromModuleBuilder);
         $smarty->assign('view_package', $this->package);
     }
     // Layout labels for the breadcrumb
     $labels = array(MB_EDITVIEW => 'LBL_EDITVIEW', MB_DETAILVIEW => 'LBL_DETAILVIEW', MB_QUICKCREATE => 'LBL_QUICKCREATE', MB_RECORDVIEW => 'LBL_RECORDVIEW', MB_WIRELESSEDITVIEW => 'LBL_WIRELESSEDITVIEW', MB_WIRELESSDETAILVIEW => 'LBL_WIRELESSDETAILVIEW');
     $layoutLabel = 'LBL_LAYOUTS';
     $layoutView = 'layouts';
     if (in_array($this->editLayout, array(MB_WIRELESSEDITVIEW, MB_WIRELESSDETAILVIEW))) {
         $layoutLabel = 'LBL_WIRELESSLAYOUTS';
         $layoutView = 'wirelesslayouts';
         $smarty->assign('wireless', true);
     }
     $ajax = new AjaxCompose();
     $translatedViewType = '';
     if (isset($labels[strtolower($this->editLayout)])) {
         $translatedViewType = translate($labels[strtolower($this->editLayout)], 'ModuleBuilder');
     } else {
         if (isset($this->sm)) {
             foreach ($this->sm->sources as $file => $def) {
                 if (!empty($def['view']) && $def['view'] == $this->editLayout && !empty($def['name'])) {
                     $translatedViewType = $def['name'];
                 }
             }
             if (empty($translatedViewType)) {
                 $label = "LBL_" . strtoupper($this->editLayout);
                 $translated = translate($label, $this->editModule);
                 if ($translated != $label) {
                     $translatedViewType = $translated;
                 }
             }
         }
     }
     if ($this->fromModuleBuilder) {
         $ajax->addCrumb(translate('LBL_MODULEBUILDER', 'ModuleBuilder'), 'ModuleBuilder.main("mb")');
         $ajax->addCrumb($this->package, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $this->package . '")');
         $ajax->addCrumb($this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $this->package . '&view_module=' . $this->editModule . '")');
         $ajax->addCrumb(translate($layoutLabel, 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view=' . $layoutView . '&view_module=' . $this->editModule . '&view_package=' . $this->package . '")');
         $ajax->addCrumb($translatedViewType, '');
     } else {
         $ajax->addCrumb(translate('LBL_STUDIO', 'ModuleBuilder'), 'ModuleBuilder.main("studio")');
         $ajax->addCrumb($this->translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")');
         $ajax->addCrumb(translate($layoutLabel, 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=' . $layoutView . '&view_module=' . $this->editModule . '")');
         $ajax->addCrumb($translatedViewType, '');
     }
     // set up language files
     $smarty->assign('language', $parser->getLanguage());
     // for sugar_translate in the smarty template
     $smarty->assign('from_mb', $this->fromModuleBuilder);
     $smarty->assign('calc_field_list', json_encode($parser->getCalculatedFields()));
     if ($this->fromModuleBuilder) {
         $mb = new ModuleBuilder();
         $module =& $mb->getPackageModule($this->package, $this->editModule);
         $smarty->assign('current_mod_strings', $module->getModStrings());
     }
     $ajax->addSection('center', $translatedViewType, $smarty->fetch(SugarAutoLoader::existingCustomOne('modules/ModuleBuilder/tpls/layoutView.tpl')));
     if ($preview) {
         echo $smarty->fetch('modules/ModuleBuilder/tpls/Preview/layoutView.tpl');
     } else {
         echo $ajax->getJavascript();
     }
 }
 protected function getRelateFieldDefinition($sourceModule, $relationshipName, $vnameLabel = '')
 {
     $vardef = array();
     $vardef['name'] = $relationshipName . "_name";
     // must end in _name for the QuickSearch code in TemplateHandler->createQuickSearchCode
     $vardef['type'] = 'relate';
     $vardef['source'] = 'non-db';
     if (!empty($vnameLabel)) {
         $vardef['vname'] = 'LBL_' . strtoupper($relationshipName . '_FROM_' . $vnameLabel) . '_TITLE';
     } else {
         $vardef['vname'] = 'LBL_' . strtoupper($relationshipName . '_FROM_' . $sourceModule) . '_TITLE';
     }
     $vardef['save'] = true;
     // the magic value to tell SugarBean to save this relate field even though it is not listed in the $relationship_fields array
     // id_name matches the join_key_ column in the relationship table for the sourceModule - that is, the column in the relationship table containing the id of the corresponding field in the source module's table (vardef['table'])
     $vardef['id_name'] = $this->getIDName($sourceModule);
     // link cannot match id_name otherwise the $bean->$id_name value set from the POST is overwritten by the Link object created by this 'link' entry
     $vardef['link'] = $relationshipName;
     // the name of the link field that points to the relationship - required for the save to function
     $vardef['table'] = $this->getTablename($sourceModule);
     $vardef['module'] = $sourceModule;
     require_once 'modules/ModuleBuilder/parsers/relationships/AbstractRelationships.php';
     $parsedModuleName = AbstractRelationships::parseDeployedModuleName($sourceModule);
     // now determine the appropriate 'rname' field for this relate
     // the 'rname' points to the field in source module that contains the displayable name for the record
     // usually this is 'name' but sometimes it is not...
     $vardef['rname'] = 'name';
     if (isset($parsedModuleName['packageName'])) {
         require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
         $mb = new ModuleBuilder();
         $module = $mb->getPackageModule($parsedModuleName['packageName'], $parsedModuleName['moduleName']);
         if (in_array('file', array_keys($module->config['templates']))) {
             $vardef['rname'] = 'document_name';
         }
     } else {
         switch (strtolower($sourceModule)) {
             case 'prospects':
                 $vardef['rname'] = 'account_name';
                 break;
             case 'documents':
                 $vardef['rname'] = 'document_name';
                 break;
             case 'kbdocuments':
                 $vardef['rname'] = 'kbdocument_name';
                 break;
             case 'leads':
             case 'contacts':
                 // special handling as these modules lack a name column in the database; instead 'name' refers to a non-db field that concatenates first_name and last_name
                 // luckily, the relate field mechanism can handle this with an equivalent additional db_concat_fields entry
                 $vardef['rname'] = 'name';
                 $vardef['db_concat_fields'] = array(0 => 'first_name', 1 => 'last_name');
                 break;
             default:
                 // now see if we have any module inheriting from the 'file' template - records in file-type modules are named by the document_name field, not the usual 'name' field
                 $object = $GLOBALS['beanList'][$sourceModule];
                 require_once $GLOBALS['beanFiles'][$object];
                 $bean = new $object();
                 if (isset($GLOBALS['dictionary'][$object]['templates']) && in_array('file', $GLOBALS['dictionary'][$object]['templates'])) {
                     $vardef['rname'] = 'document_name';
                 }
         }
     }
     return $vardef;
 }
Beispiel #21
0
 public function processMB($ajax)
 {
     if (!isset($_REQUEST['view_package'])) {
         sugar_die("no ModuleBuilder package set");
     }
     $this->editModule = $_REQUEST['view_module'];
     $this->package = $_REQUEST['view_package'];
     $ajax->addCrumb(translate('LBL_MODULEBUILDER', 'ModuleBuilder'), 'ModuleBuilder.main("mb")');
     $ajax->addCrumb($this->package, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&view_package=' . $this->package . '")');
     $ajax->addCrumb($this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_module=' . $this->editModule . '&view_package=' . $this->package . '")');
     switch ($this->view) {
         case 'subpanel':
             //ModuleBuilder Select Subpanel
             $ajax->addCrumb($this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_module=' . $this->editModule . '&view_package=' . $this->package . '")');
             $ajax->addCrumb(translate('LBL_SUBPANELS'), '');
             $this->question = translate('LBL_QUESTION_SUBPANEL');
             $this->help = 'subpanelHelp';
             break;
         case 'wirelesslayouts':
             $ajax->addCrumb(translate('LBL_WIRELESSLAYOUTS'), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view=wirelesslayouts&view_module=' . $this->editModule . '&view_package=' . $this->package . '")');
             $mb = new ModuleBuilder();
             $module = $mb->getPackageModule($this->package, $this->editModule);
             $this->buttons = $module->getWirelessLayouts();
             $this->title = $this->editModule . " " . translate('LBL_WIRELESSLAYOUTS');
             $this->question = translate('LBL_QUESTION_LAYOUT');
             $this->help = "layoutsHelp";
             break;
         case 'wirelesssearch':
             $mb = new ModuleBuilder();
             $module = $mb->getPackageModule($this->package, $this->editModule);
             $this->buttons = $module->getWirelessSearch();
             $this->title = $this->editModule . " " . translate('LBL_WIRELESSSEARCH');
             $this->question = translate('LBL_QUESTION_SEARCH');
             $ajax->addCrumb(translate('LBL_WIRELESSLAYOUTS'), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view_module=' . $this->editModule . '&view_package=' . $this->package . '")');
             $ajax->addCrumb(translate('LBL_WIRELESSSEARCH'), '');
             $this->help = "searchHelp";
             break;
         case 'popup':
             $this->generateMBPopupButtons();
             $this->title = $this->editModule . " " . translate('LBL_POPUP');
             $this->question = translate('LBL_QUESTION_POPUP');
             $this->ajax->addCrumb(translate('LBL_LAYOUTS'), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view=layouts&MB=1&view_package=' . $this->package . '&view_module=' . $this->editModule . '")');
             $this->ajax->addCrumb(translate('LBL_POPUP'), '');
             $this->help = 'popupHelp';
             break;
         default:
             $ajax->addCrumb(translate('LBL_LAYOUTS'), '');
             $this->generateMBViewButtons();
             $this->title = $this->editModule . " " . translate('LBL_LAYOUTS');
             $this->question = translate('LBL_QUESTION_LAYOUT');
             $this->help = "layoutsHelp";
     }
 }
 function build($basepath)
 {
     // first expand out any reference to Activities to its submodules
     // we do this here rather than in the subcomponents of the build as most of those subcomponents make use of elements of the definition, such
     // as the relationship name, that must be unique
     // the only special case is the subpanel for Activities, which is a composite, and is applied only once for all the submodules - this is handled in saveSubpanelDefinitions() for Undeployed modules
     $relationships = array();
     $this->activitiesToAdd = false;
     foreach ($this->relationships as $relationshipName => $relationship) {
         $definition = $relationship->getDefinition();
         // activities will always appear on the rhs only - lhs will be always be this module in MB
         if (strtolower($definition['rhs_module']) == 'activities') {
             $this->activitiesToAdd = true;
             $relationshipName = $definition['relationship_name'];
             foreach (self::$activities as $activitiesSubModuleLower => $activitiesSubModuleName) {
                 $definition['rhs_module'] = $activitiesSubModuleName;
                 $definition['for_activities'] = true;
                 $definition['relationship_name'] = $relationshipName . '_' . $activitiesSubModuleLower;
                 $relationships[$definition['relationship_name']] = RelationshipFactory::newRelationship($definition);
             }
         } else {
             $relationships[$definition['relationship_name']] = $relationship;
         }
     }
     require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
     $mb = new ModuleBuilder();
     $module = $mb->getPackageModule($this->packageName, $this->moduleName);
     if ($this->activitiesToAdd) {
         $appStrings = $module->getAppListStrings();
         $appStrings['parent_type_display'][$module->key_name] = $module->getlabel('en_us', 'LBL_MODULE_TITLE');
         $appStrings['record_type_display'][$module->key_name] = $module->getlabel('en_us', 'LBL_MODULE_TITLE');
         $appStrings['record_type_display_notes'][$module->key_name] = $module->getlabel('en_us', 'LBL_MODULE_TITLE');
         $module->setAppListStrings('en_us', $appStrings);
         $module->save();
     }
     // use an installDefPrefix of <basepath>/SugarModules for compatibility with the rest of ModuleBuilder
     $this->installDefs = parent::build($basepath, "<basepath>/SugarModules", $relationships);
 }
Beispiel #23
0
 function action_get_app_list_string()
 {
     require_once 'include/JSON.php';
     $json = new JSON();
     if (isset($_REQUEST['key']) && !empty($_REQUEST['key'])) {
         $key = $_REQUEST['key'];
         $value = array();
         if (!empty($GLOBALS['app_list_strings'][$key])) {
             $value = $GLOBALS['app_list_strings'][$key];
         } else {
             $package_strings = array();
             if (!empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio' && !empty($_REQUEST['view_module'])) {
                 require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
                 $mb = new ModuleBuilder();
                 $module =& $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
                 $lang = $GLOBALS['current_language'];
                 $module->mblanguage->generateAppStrings(false);
                 $package_strings = $module->mblanguage->appListStrings[$lang . '.lang.php'];
                 if (isset($package_strings[$key]) && is_array($package_strings[$key])) {
                     $value = $package_strings[$key];
                 }
             }
         }
         echo $json->encode($value);
     }
 }
Beispiel #24
0
 function fetch($ac = false)
 {
     $fv = new FieldViewer();
     if (empty($_REQUEST['field']) && !empty($_REQUEST['name'])) {
         $_REQUEST['field'] = $_REQUEST['name'];
     }
     $field_name = '';
     if (!empty($this->view_object_map['field_name'])) {
         $field_name = $this->view_object_map['field_name'];
     } elseif (!empty($_REQUEST['field'])) {
         $field_name = $_REQUEST['field'];
     } else {
         $field_name = '';
     }
     $action = 'saveField';
     // tyoung bug 17606: default action is to save as a dynamic field; but for standard OOB
     // fields we override this so don't create a new dynamic field instead of updating the existing field
     $isClone = false;
     if (!empty($this->view_object_map['is_clone']) && $this->view_object_map['is_clone']) {
         $isClone = true;
     }
     /*
     $field_types =  array('varchar'=>'YourField', 'int'=>'Integer', 'float'=>'Decimal','bool'=>'Checkbox','enum'=>'DropDown',
     		'date'=>'Date', 'phone' => 'Phone', 'currency' => 'Currency', 'html' => 'HTML', 'radioenum' => 'Radio',
     		'relate' => 'Relate', 'address' => 'Address', 'text' => 'TextArea', 'url' => 'Link');
     */
     $field_types = $GLOBALS['mod_strings']['fieldTypes'];
     $field_name_exceptions = array('ADD', 'EXCEPT', 'PERCENT', 'ALL', 'EXEC', 'PLAN', 'ALTER', 'EXECUTE', 'PRECISION', 'AND', 'EXISTS', 'PRIMARY', 'ANY', 'EXIT', 'PRINT', 'AS', 'FETCH', 'PROC', 'ASC', 'FILE', 'PROCEDURE', 'AUTHORIZATION', 'FILLFACTOR', 'PUBLIC', 'BACKUP', 'FOR', 'RAISERROR', 'BEGIN', 'FOREIGN', 'READ', 'BETWEEN', 'FREETEXT', 'READTEXT', 'BREAK', 'FREETEXTTABLE', 'RECONFIGURE', 'BROWSE', 'FROM', 'REFERENCES', 'BULK', 'FULL', 'REPLICATION', 'BY', 'FUNCTION', 'RESTORE', 'CASCADE', 'GOTO', 'RESTRICT', 'CASE', 'GRANT', 'RETURN', 'CHECK', 'GROUP', 'REVOKE', 'CHECKPOINT', 'HAVING', 'RIGHT', 'CLOSE', 'HOLDLOCK', 'ROLLBACK', 'CLUSTERED', 'IDENTITY', 'ROWCOUNT', 'COALESCE', 'IDENTITY_INSERT', 'ROWGUIDCOL', 'COLLATE', 'IDENTITYCOL', 'RULE', 'COLUMN', 'IF', 'SAVE', 'COMMIT', 'IN', 'SCHEMA', 'COMPUTE', 'INDEX', 'SELECT', 'CONSTRAINT', 'INNER', 'SESSION_USER', 'CONTAINS', 'INSERT', 'SET', 'CONTAINSTABLE', 'INTERSECT', 'SETUSER', 'CONTINUE', 'INTO', 'SHUTDOWN', 'CONVERT', 'IS', 'SOME', 'CREATE', 'JOIN', 'STATISTICS', 'CROSS', 'KEY', 'SYSTEM_USER', 'CURRENT', 'KILL', 'TABLE', 'CURRENT_DATE', 'LEFT', 'TEXTSIZE', 'CURRENT_TIME', 'LIKE', 'THEN', 'CURRENT_TIMESTAMP', 'LINENO', 'TO', 'CURRENT_USER', 'LOAD', 'TOP', 'CURSOR', 'NATIONAL', 'TRAN', 'DATABASE', 'NOCHECK', 'TRANSACTION', 'DBCC', 'NONCLUSTERED', 'TRIGGER', 'DEALLOCATE', 'NOT', 'TRUNCATE', 'DECLARE', 'NULL', 'TSEQUAL', 'DEFAULT', 'NULLIF', 'UNION', 'DELETE', 'OF', 'UNIQUE', 'DENY', 'OFF', 'UPDATE', 'DESC', 'OFFSETS', 'UPDATETEXT', 'DISK', 'ON', 'USE', 'DISTINCT', 'OPEN', 'USER', 'DISTRIBUTED', 'OPENCONNECTOR', 'VALUES', 'DOUBLE', 'OPENQUERY', 'VARYING', 'DROP', 'OPENROWSET', 'VIEW', 'DUMMY', 'OPENXML', 'WAITFOR', 'DUMP', 'OPTION', 'WHEN', 'ELSE', 'OR', 'WHERE', 'END', 'ORDER', 'WHILE', 'ERRLVL', 'OUTER', 'WITH', 'ESCAPE', 'OVER', 'WRITETEXT', 'ANALYZE', 'ASENSITIVE', 'BEFORE', 'BIGINT', 'BINARY', 'BOTH', 'CALL', 'CHANGE', 'CHARACTER', 'CONDITION', 'DATABASES', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', 'DEC', 'DECIMAL', 'DELAYED', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCTROW', 'DIV', 'DUAL', 'EACH', 'ELSEIF', 'ENCLOSED', 'ESCAPED', 'EXPLAIN', 'FALSE', 'FLOAT', 'FLOAT4', 'FLOAT8', 'FORCE', 'FULLTEXT', 'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', 'IGNORE', 'INFILE', 'INOUT', 'INSENSITIVE', 'INT', 'INT1', 'INT2', 'INT3', 'INT4', 'INT8', 'INTEGER', 'ITERATE', 'KEYS', 'LEADING', 'LEAVE', 'LIMIT', 'LINES', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCK', 'LONGBLOB', 'LONGTEXT', 'LOOP', 'LOW_PRIORITY', 'MATCH', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MOD', 'MODIFIES', 'NATURAL', 'NO_WRITE_TO_BINLOG', 'NUMERIC', 'OPTIMIZE', 'OPTIONALLY', 'OUT', 'OUTFILE', 'PURGE', 'READS', 'REAL', 'REGEXP', 'RELEASE', 'RENAME', 'REPEAT', 'REPLACE', 'REQUIRE', 'RLIKE', 'SCHEMAS', 'SECOND_MICROSECOND', 'SENSITIVE', 'SEPARATOR', 'SHOW', 'SMALLINT', 'SONAME', 'SPATIAL', 'SPECIFIC', 'SQL', 'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', 'SQL_BIG_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT', 'SSL', 'STARTING', 'STRAIGHT_JOIN', 'TERMINATED', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TRAILING', 'TRUE', 'UNDO', 'UNLOCK', 'UNSIGNED', 'USAGE', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'VARBINARY', 'VARCHARACTER', 'WRITE', 'XOR', 'YEAR_MONTH', 'ZEROFILL', 'CONNECTION', 'LABEL', 'UPGRADE', 'DATE', 'VARCHAR', 'VARCHAR2', 'NVARCHAR2', 'CHAR', 'NCHAR', 'NUMBER', 'PLS_INTEGER', 'BINARY_INTEGER', 'LONG', 'TIMESTAMP', 'INTERVAL', 'RAW', 'ROWID', 'UROWID', 'MLSLABEL', 'CLOB', 'NCLOB', 'BLOB', 'BFILE', 'XMLTYPE');
     if (!isset($_REQUEST['view_package']) || $_REQUEST['view_package'] == 'studio' || empty($_REQUEST['view_package'])) {
         $module = new stdClass();
         $moduleName = $_REQUEST['view_module'];
         global $beanList;
         $objectName = $beanList[$moduleName];
         if ($objectName == 'aCase') {
             // Bug 17614 - renamed aCase as Case in vardefs for backwards compatibililty with 451 modules
             $objectName = 'Case';
         }
         VardefManager::loadVardef($moduleName, $objectName);
         global $dictionary;
         $module->mbvardefs->vardefs = $dictionary[$objectName];
         //          $GLOBALS['log']->debug('vardefs from dictionary = '.print_r($module->mbvardefs->vardefs,true));
         $module->name = $moduleName;
         if (!$ac) {
             $ac = new AjaxCompose();
         }
         $vardef = !empty($module->mbvardefs->vardefs['fields'][$field_name]) ? $module->mbvardefs->vardefs['fields'][$field_name] : array();
         //          $GLOBALS['log']->debug('vardefs after loading = '.print_r($vardef,true));
         if ($isClone) {
             unset($vardef['name']);
         }
         if (empty($vardef['name'])) {
             if (!empty($_REQUEST['type'])) {
                 $vardef['type'] = $_REQUEST['type'];
             }
             $fv->ss->assign('hideLevel', 0);
         } elseif (isset($vardef['custom_module'])) {
             $fv->ss->assign('hideLevel', 2);
         } else {
             $action = 'saveLabel';
             // tyoung - for OOB fields we currently only support modifying the label
             $fv->ss->assign('hideLevel', 10);
         }
         $GLOBALS['log']->warn('view.modulefield: hidelevel ' . $fv->ss->get_template_vars('hideLevel') . " " . print_r($vardef, true));
         if (!empty($vardef['vname'])) {
             $fv->ss->assign('lbl_value', translate($vardef['vname'], $moduleName));
         }
         //$package = new stdClass;
         //$package->name = 'studio';
         //$fv->ss->assign('package', $package);
         $fv->ss->assign('module', $module);
         if (empty($module->mbvardefs->vardefs['fields']['parent_name']) || isset($vardef['type']) && $vardef['type'] == 'parent') {
             $field_types['parent'] = $GLOBALS['mod_strings']['parent'];
         }
         $edit_or_add = 'editField';
     } else {
         require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
         $mb = new ModuleBuilder();
         $module =& $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
         $package =& $mb->packages[$_REQUEST['view_package']];
         $module->getVardefs();
         if (!$ac) {
             $ac = new AjaxCompose();
         }
         $vardef = !empty($module->mbvardefs->vardefs['fields'][$field_name]) ? $module->mbvardefs->vardefs['fields'][$field_name] : array();
         if ($isClone) {
             unset($vardef['name']);
         }
         if (empty($vardef['name'])) {
             if (!empty($_REQUEST['type'])) {
                 $vardef['type'] = $_REQUEST['type'];
             }
             $fv->ss->assign('hideLevel', 0);
         } else {
             if (!empty($module->mbvardefs->vardef['fields'][$vardef['name']])) {
                 $fv->ss->assign('hideLevel', 1);
             } elseif (isset($vardef['custom_module'])) {
                 $fv->ss->assign('hideLevel', 2);
             } else {
                 $action = 'saveLabel';
                 // tyoung - for template fields we currently only support modifying the label
                 $fv->ss->assign('hideLevel', 10);
                 // tyoung bug 17350 - effectively mark template derived fields as readonly
             }
         }
         $fv->ss->assign('module', $module);
         $fv->ss->assign('package', $package);
         $fv->ss->assign('MB', '1');
         if (isset($vardef['vname'])) {
             $fv->ss->assign('lbl_value', $module->getLabel('en_us', $vardef['vname']));
         }
         if (empty($module->mbvardefs->vardefs['fields']['parent_name']) || isset($vardef['type']) && $vardef['type'] == 'parent') {
             $field_types['parent'] = $GLOBALS['mod_strings']['parent'];
         }
         $edit_or_add = 'mbeditField';
     }
     if ($_REQUEST['action'] == 'RefreshField') {
         require_once 'modules/DynamicFields/FieldCases.php';
         $field = get_widget($_POST['type']);
         $field->populateFromPost();
         $vardef = $field->get_field_def();
         $vardef['options'] = $_REQUEST['new_dropdown'];
         $fv->ss->assign('lbl_value', $_REQUEST['labelValue']);
     }
     if (!empty($vardef['formula'])) {
         $vardef['formula'] = htmlspecialchars($vardef['formula']);
     }
     $fv->ss->assign('action', $action);
     $fv->ss->assign('isClone', $isClone ? 1 : 0);
     $json = getJSONobj();
     $fv->ss->assign('field_name_exceptions', $json->encode($field_name_exceptions));
     ksort($field_types);
     $fv->ss->assign('field_types', $field_types);
     $fv->ss->assign('importable_options', $GLOBALS['app_list_strings']['custom_fields_importable_dom']);
     $fv->ss->assign('duplicate_merge_options', $GLOBALS['app_list_strings']['custom_fields_merge_dup_dom']);
     $triggers = array();
     foreach ($module->mbvardefs->vardefs['fields'] as $field) {
         if ($field['type'] == 'enum' || $field['type'] == 'multienum') {
             $triggers[] = $field['name'];
         }
     }
     $fv->ss->assign('triggers', $triggers);
     $fv->ss->assign('mod_strings', $GLOBALS['mod_strings']);
     // jchi #24880
     // end
     $layout = $fv->getLayout($vardef);
     $fv->ss->assign('fieldLayout', $layout);
     if (empty($vardef['type'])) {
         $vardef['type'] = 'varchar';
     }
     $fv->ss->assign('vardef', $vardef);
     if (empty($_REQUEST['field'])) {
         $edit_or_add = 'addField';
     }
     $fv->ss->assign('help_group', $edit_or_add);
     $body = $fv->ss->fetch('modules/ModuleBuilder/tpls/MBModule/field.tpl');
     $ac->addSection('east', translate('LBL_SECTION_FIELDEDITOR', 'ModuleBuilder'), $body);
     return $ac;
 }
 public static function getFileName($view, $moduleName, $packageName, $type = MB_BASEMETADATALOCATION)
 {
     $type = strtolower($type);
     // BEGIN ASSERTIONS
     if ($type != MB_BASEMETADATALOCATION && $type != MB_HISTORYMETADATALOCATION) {
         // just warn rather than die
         $GLOBALS['log']->warning("UndeployedMetaDataImplementation->getFileName(): view type {$type} is not recognized");
     }
     // END ASSERTIONS
     $filenames = array(MB_DASHLETSEARCH => 'dashletviewdefs', MB_DASHLET => 'dashletviewdefs', MB_LISTVIEW => 'listviewdefs', MB_BASICSEARCH => 'searchdefs', MB_ADVANCEDSEARCH => 'searchdefs', MB_EDITVIEW => 'editviewdefs', MB_DETAILVIEW => 'detailviewdefs', MB_QUICKCREATE => 'quickcreatedefs', MB_POPUPSEARCH => 'popupdefs', MB_POPUPLIST => 'popupdefs');
     switch ($type) {
         case MB_HISTORYMETADATALOCATION:
             return 'custom/history/modulebuilder/packages/' . $packageName . '/modules/' . $moduleName . '/metadata/' . $filenames[$view] . '.php';
         default:
             // get the module again, all so we can call this method statically without relying on the module stored in the class variables
             $mb = new ModuleBuilder();
             $module =& $mb->getPackageModule($packageName, $moduleName);
             return $module->getModuleDir() . '/metadata/' . $filenames[$view] . '.php';
     }
 }
 function fetch($ac = false)
 {
     $fv = new FieldViewer();
     if (empty($_REQUEST['field']) && !empty($_REQUEST['name'])) {
         $_REQUEST['field'] = $_REQUEST['name'];
     }
     $field_name = '';
     if (!empty($this->view_object_map['field_name'])) {
         $field_name = $this->view_object_map['field_name'];
     } elseif (!empty($_REQUEST['field'])) {
         $field_name = $_REQUEST['field'];
     }
     // If this is a new field mark it as such
     $isNew = empty($field_name) || !empty($_REQUEST['is_new']);
     $action = 'saveField';
     // tyoung bug 17606: default action is to save as a dynamic field; but for standard OOB
     // fields we override this so don't create a new dynamic field instead of updating the existing field
     $isClone = false;
     if (!empty($this->view_object_map['is_clone']) && $this->view_object_map['is_clone'] && strcmp($field_name, "name") != 0) {
         $isClone = true;
     }
     /*
     $field_types =  array('varchar'=>'YourField', 'int'=>'Integer', 'float'=>'Decimal','bool'=>'Checkbox','enum'=>'DropDown',
     		'date'=>'Date', 'phone' => 'Phone', 'currency' => 'Currency', 'html' => 'HTML', 'radioenum' => 'Radio',
     		'relate' => 'Relate', 'address' => 'Address', 'text' => 'TextArea', 'url' => 'Link');
     */
     $field_types = $GLOBALS['mod_strings']['fieldTypes'];
     //bug 22264: Field name must not be an SQL keyword.
     $field_name_exceptions = array_merge(array_keys($GLOBALS['db']->getReservedWords()), array('ID', 'ID_C', 'PARENT_NAME', 'PARENT_ID'));
     //C.L. - Add support to mark related module id columns as reserved keywords
     require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php';
     $relatedModules = array_keys(DeployedRelationships::findRelatableModules());
     global $beanList, $current_language;
     foreach ($relatedModules as $relModule) {
         if (isset($beanList[$relModule])) {
             $field_name_exceptions[] = strtoupper($beanList[$relModule]) . '_ID';
         }
     }
     if (empty($_REQUEST['view_package']) || $_REQUEST['view_package'] == 'studio') {
         $moduleName = $_REQUEST['view_module'];
         $objectName = BeanFactory::getObjectName($moduleName);
         $module = BeanFactory::getBean($moduleName);
         VardefManager::loadVardef($moduleName, $objectName, true);
         global $dictionary;
         if (empty($module->mbvardefs)) {
             $module->mbvardefs = new stdClass();
         }
         $module->mbvardefs->vardefs = $dictionary[$objectName];
         $module->name = $moduleName;
         if (!$ac) {
             $ac = new AjaxCompose();
         }
         $vardef = !empty($module->mbvardefs->vardefs['fields'][$field_name]) ? $module->mbvardefs->vardefs['fields'][$field_name] : array();
         if ($isClone) {
             unset($vardef['name']);
         }
         // If this is a new field but we are loading this form a second time,
         // like from coming back from a dropdown create on a new field, then
         // keep the 'name' field open to allow the create field process to
         // continue like normal
         if (empty($vardef['name']) || $isNew) {
             if (!empty($_REQUEST['type'])) {
                 $vardef['type'] = $_REQUEST['type'];
             }
             $fv->ss->assign('hideLevel', 0);
         } elseif (isset($vardef['custom_module'])) {
             $fv->ss->assign('hideLevel', 2);
         } else {
             $action = 'saveSugarField';
             // tyoung - for OOB fields we currently only support modifying the label
             $fv->ss->assign('hideLevel', 3);
         }
         if ($isClone && isset($vardef['type']) && $vardef['type'] == 'datetime') {
             $vardef['type'] = 'datetimecombo';
         }
         require_once 'modules/DynamicFields/FieldCases.php';
         $tf = get_widget(empty($vardef['type']) ? "" : $vardef['type']);
         $tf->module = $module;
         $tf->populateFromRow($vardef);
         $vardef = array_merge($vardef, $tf->get_field_def());
         //          $GLOBALS['log']->debug('vardefs after loading = '.print_r($vardef,true));
         //Check if autoincrement fields are allowed
         $allowAutoInc = true;
         $enumFields = array();
         foreach ($module->field_defs as $field => $def) {
             if (!empty($def['type']) && $def['type'] == "int" && !empty($def['auto_increment'])) {
                 $allowAutoInc = false;
                 continue;
             }
             if (!empty($def['type']) && $def['type'] == "enum" && $field != $vardef['name']) {
                 if (!empty($def['studio']) && $def['studio'] == "false") {
                     continue;
                 }
                 //bug51866
                 $enumFields[$field] = translate($def['vname'], $moduleName);
                 if (substr($enumFields[$field], -1) == ":") {
                     $enumFields[$field] = substr($enumFields[$field], 0, strlen($enumFields[$field]) - 1);
                 }
             }
         }
         $fv->ss->assign('allowAutoInc', $allowAutoInc);
         $GLOBALS['log']->warn('view.modulefield: hidelevel ' . $fv->ss->get_template_vars('hideLevel') . " " . print_r($vardef, true));
         if (!empty($vardef['vname'])) {
             $fv->ss->assign('lbl_value', htmlentities(translate($vardef['vname'], $moduleName), ENT_QUOTES, 'UTF-8'));
         }
         $fv->ss->assign('module', $module);
         if (empty($module->mbvardefs->vardefs['fields']['parent_name']) || isset($vardef['type']) && $vardef['type'] == 'parent') {
             $field_types['parent'] = $GLOBALS['mod_strings']['parent'];
         }
         $edit_or_add = 'editField';
     } else {
         require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
         $mb = new ModuleBuilder();
         $moduleName = $_REQUEST['view_module'];
         $module =& $mb->getPackageModule($_REQUEST['view_package'], $moduleName);
         $package =& $mb->packages[$_REQUEST['view_package']];
         $module->getVardefs();
         if (!$ac) {
             $ac = new AjaxCompose();
         }
         $vardef = !empty($module->mbvardefs->vardefs['fields'][$field_name]) ? $module->mbvardefs->vardefs['fields'][$field_name] : array();
         if ($isClone) {
             unset($vardef['name']);
         }
         if (empty($vardef['name'])) {
             if (!empty($_REQUEST['type'])) {
                 $vardef['type'] = $_REQUEST['type'];
             }
             $fv->ss->assign('hideLevel', 0);
         } else {
             if (!empty($module->mbvardefs->vardef['fields'][$vardef['name']])) {
                 $fv->ss->assign('hideLevel', 1);
             } elseif (isset($vardef['custom_module'])) {
                 $fv->ss->assign('hideLevel', 2);
             } else {
                 $fv->ss->assign('hideLevel', 3);
                 // tyoung bug 17350 - effectively mark template derived fields as readonly
             }
         }
         require_once 'modules/DynamicFields/FieldCases.php';
         $tf = get_widget(empty($vardef['type']) ? "" : $vardef['type']);
         $tf->module = $module;
         $tf->populateFromRow($vardef);
         $vardef = array_merge($vardef, $tf->get_field_def());
         $fv->ss->assign('module', $module);
         $fv->ss->assign('package', $package);
         $fv->ss->assign('MB', '1');
         if (isset($vardef['vname'])) {
             $fv->ss->assign('lbl_value', htmlentities($module->getLabel('en_us', $vardef['vname']), ENT_QUOTES, 'UTF-8'));
         }
         if (empty($module->mbvardefs->vardefs['fields']['parent_name']) || isset($vardef['type']) && $vardef['type'] == 'parent') {
             $field_types['parent'] = $GLOBALS['mod_strings']['parent'];
         }
         $enumFields = array();
         if (!empty($module->mbvardefs->vardefs['fields'])) {
             foreach ($module->mbvardefs->vardefs['fields'] as $field => $def) {
                 if (!empty($def['type']) && $def['type'] == "enum" && $field != $vardef['name']) {
                     $enumFields[$field] = isset($module->mblanguage->strings[$current_language][$def['vname']]) ? $this->mbModule->mblanguage->strings[$current_language][$def['vname']] : translate($field);
                     if (substr($enumFields[$field], -1) == ":") {
                         $enumFields[$field] = substr($enumFields[$field], 0, strlen($enumFields[$field]) - 1);
                     }
                 }
             }
         }
         $edit_or_add = 'mbeditField';
     }
     if ($_REQUEST['action'] == 'RefreshField') {
         require_once 'modules/DynamicFields/FieldCases.php';
         $field = get_widget($_POST['type']);
         $field->populateFromPost();
         $vardef = $field->get_field_def();
         $vardef['options'] = $_REQUEST['new_dropdown'];
         $fv->ss->assign('lbl_value', htmlentities($_REQUEST['labelValue'], ENT_QUOTES, 'UTF-8'));
     }
     foreach (array("formula", "default", "comments", "help", "visiblityGrid") as $toEscape) {
         if (!empty($vardef[$toEscape]) && is_string($vardef[$toEscape])) {
             $vardef[$toEscape] = htmlentities($vardef[$toEscape], ENT_QUOTES, 'UTF-8');
         }
     }
     if (!empty($vardef['studio']['no_duplicate']) || $field_name === 'name' || $field_name === 'parent_type' || $field_name === 'parent_id' || $field_name === 'parent_name' || isset($vardef['type']) && $vardef['type'] === 'name') {
         $fv->ss->assign('no_duplicate', true);
     }
     $fv->ss->assign('action', $action);
     $fv->ss->assign('isClone', $isClone ? 1 : 0);
     $fv->ss->assign('isNew', $isNew);
     $fv->ss->assign("module_dd_fields", $enumFields);
     $json = getJSONobj();
     $fv->ss->assign('field_name_exceptions', $json->encode($field_name_exceptions));
     ksort($field_types);
     $fv->ss->assign('field_types', $field_types);
     $ftsEngineType = getFTSEngineType();
     $usa = new UnifiedSearchAdvanced();
     if (SugarSearchEngineFactory::getInstance()->isTypeFtsEnabled($vardef['type']) && (!empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio' || $usa->shouldShowModule($moduleName))) {
         $ftsBoostOptions = getFTSBoostOptions($ftsEngineType . '_boost_options');
         $fv->ss->assign('fts_options', $ftsBoostOptions);
         $fv->ss->assign('show_fts', true);
     } else {
         $fv->ss->assign('show_fts', false);
     }
     //Ensure certain field types always have correct formula return types for validation.
     if (!empty($vardef['type'])) {
         switch ($vardef['type']) {
             case 'date':
             case 'datetime':
                 $fv->ss->assign('calcFieldType', 'date');
                 break;
             case 'bool':
                 $fv->ss->assign('calcFieldType', 'boolean');
                 break;
             default:
                 $fv->ss->assign('calcFieldType', '');
                 break;
         }
     }
     $fv->ss->assign('importable_options', $GLOBALS['app_list_strings']['custom_fields_importable_dom']);
     $fv->ss->assign('duplicate_merge_options', $GLOBALS['app_list_strings']['custom_fields_merge_dup_dom']);
     $triggers = array();
     $existing_field_names = array();
     foreach ($module->mbvardefs->vardefs['fields'] as $field) {
         if ($field['type'] == 'enum' || $field['type'] == 'multienum') {
             $triggers[] = $field['name'];
         }
         if (!isset($field['source']) || $field['source'] != 'non-db') {
             if (preg_match('/^(.*?)(_c)?$/', $field['name'], $matches)) {
                 $existing_field_names[] = strtoupper($matches[1]);
             }
         }
     }
     $fv->ss->assign('triggers', $triggers);
     $fv->ss->assign('existing_field_names', $json->encode($existing_field_names));
     $fv->ss->assign('mod_strings', $GLOBALS['mod_strings']);
     // jchi #24880
     if (!isset($vardef['reportable'])) {
         $vardef['reportable'] = 1;
     }
     // end
     $layout = $fv->getLayout($vardef);
     $fv->ss->assign('fieldLayout', $layout);
     if (empty($vardef['type'])) {
         $vardef['type'] = 'varchar';
     }
     $fv->ss->assign('vardef', $vardef);
     if (empty($_REQUEST['field'])) {
         $edit_or_add = 'addField';
     }
     $fv->ss->assign('help_group', $edit_or_add);
     $body = $this->fetchTemplate($fv, 'modules/ModuleBuilder/tpls/MBModule/field.tpl');
     $ac->addSection('east', translate('LBL_SECTION_FIELDEDITOR', 'ModuleBuilder'), $body);
     return $ac;
 }
 function constructSmarty($parser)
 {
     $smarty = new Sugar_Smarty();
     $smarty->assign('translate', true);
     $smarty->assign('language', $parser->getLanguage());
     $smarty->assign('view', $this->editLayout);
     $smarty->assign('action', 'dashletSave');
     $smarty->assign('module', 'ModuleBuilder');
     $smarty->assign('view_module', $this->editModule);
     $smarty->assign('field_defs', $parser->getFieldDefs());
     $helpName = isset($_REQUEST['view']) && $_REQUEST['view'] == 'dashletsearch' ? 'searchViewEditor' : 'listViewEditor';
     $smarty->assign('helpName', $helpName);
     $smarty->assign('helpDefault', 'modify');
     if ($this->fromModuleBuilder) {
         $mb = new ModuleBuilder();
         $module =& $mb->getPackageModule($this->editPackage, $this->editModule);
         $smarty->assign('current_mod_strings', $module->getModStrings());
     }
     $smarty->assign('title', $this->_constructTitle());
     $groups = array();
     foreach ($parser->columns as $column => $function) {
         // update this so that each field has a properties set
         // properties are name, value, title (optional)
         $groups[$GLOBALS['mod_strings'][$column]] = $parser->{$function}();
         // call the parser functions to populate the list view columns, by default 'default', 'available' and 'hidden'
     }
     foreach ($groups as $groupKey => $group) {
         foreach ($group as $fieldKey => $field) {
             if (isset($field['width'])) {
                 if (substr($field['width'], -1, 1) == '%') {
                     $groups[$groupKey][$fieldKey]['width'] = substr($field['width'], 0, strlen($field['width']) - 1);
                 }
             }
         }
     }
     $smarty->assign('groups', $groups);
     global $image_path;
     $imageSave = SugarThemeRegistry::current()->getImage('studio_save');
     //        $imageHelp = SugarThemeRegistry::current()->getImage('help') ;
     $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")";
     if (isset($this->searchlayout)) {
         $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$this->searchlayout}\")";
     }
     $buttons = array();
     if (!$this->fromModuleBuilder) {
         $buttons[] = array('name' => 'savebtn', 'image' => $imageSave, 'text' => $GLOBALS['mod_strings']['LBL_BTN_SAVEPUBLISH'], 'actionScript' => "onclick='studiotabs.generateGroupForm(\"edittabs\");ModuleBuilder.state.isDirty=false;ModuleBuilder.submitForm(\"edittabs\" )'");
     } else {
         $buttons[] = array('name' => 'mbsavebtn', 'image' => $imageSave, 'text' => $GLOBALS['mod_strings']['LBL_BTN_SAVE'], 'actionScript' => "onclick='studiotabs.generateGroupForm(\"edittabs\");ModuleBuilder.state.isDirty=false;ModuleBuilder.submitForm(\"edittabs\" )'");
     }
     $buttons[] = array('name' => 'historyBtn', 'text' => translate('LBL_HISTORY'), 'actionScript' => "onclick='{$histaction}'");
     $smarty->assign('buttons', $this->_buildImageButtons($buttons));
     $editImage = SugarThemeRegistry::current()->getImage('edit_inline');
     $smarty->assign('editImage', $editImage);
     $deleteImage = SugarThemeRegistry::current()->getImage('delete_inline');
     $smarty->assign('deleteImage', $deleteImage);
     $smarty->assign('MOD', $GLOBALS['mod_strings']);
     if ($this->fromModuleBuilder) {
         $smarty->assign('MB', true);
         $smarty->assign('view_package', $this->editPackage);
         $smarty->assign('description', $GLOBALS['mod_strings']['LBL_LISTVIEW_DESCRIPTION']);
     } else {
         $smarty->assign('description', $GLOBALS['mod_strings']['LBL_LISTVIEW_DESCRIPTION']);
     }
     return $smarty;
 }
Beispiel #28
0
 function constructSmarty($parser)
 {
     global $mod_strings;
     $smarty = new Sugar_Smarty();
     $smarty->assign('translate', true);
     $smarty->assign('language', $parser->getLanguage());
     $smarty->assign('view', $this->editLayout);
     $smarty->assign('module', "ModuleBuilder");
     $smarty->assign('field_defs', $parser->getFieldDefs());
     $smarty->assign('action', 'listViewSave');
     $smarty->assign('view_module', $this->editModule);
     if (!empty($this->subpanel)) {
         $smarty->assign('subpanel', $this->subpanel);
         $smarty->assign('subpanelLabel', $this->subpanelLabel);
         if (!$this->fromModuleBuilder) {
             $subList = SubPanel::getModuleSubpanels($this->editModule);
             $subRef = $subList[strtolower($this->subpanel)];
             $subTitleKey = !empty($subRef) ? $subRef : "LBL_" . strtoupper($this->subpanel) . "_SUBPANEL_TITLE";
             $subTitle = !empty($subRef) ? translate($subTitleKey, $this->editModule) : UCfirst($this->subpanel);
             $smarty->assign('subpanel_label', $subTitleKey);
             $smarty->assign('subpanel_title', $subTitle);
         }
     }
     $helpName = $this->subpanel ? 'subPanelEditor' : 'listViewEditor';
     $smarty->assign('helpName', $helpName);
     $smarty->assign('helpDefault', 'modify');
     $smarty->assign('title', $this->_constructTitle());
     $groups = array();
     foreach ($parser->columns as $column => $function) {
         // update this so that each field has a properties set
         // properties are name, value, title (optional)
         $groups[$GLOBALS['mod_strings'][$column]] = $parser->{$function}();
         // call the parser functions to populate the list view columns, by default 'default', 'available' and 'hidden'
     }
     foreach ($groups as $groupKey => $group) {
         foreach ($group as $fieldKey => $field) {
             if (isset($field['width'])) {
                 if (substr($field['width'], -1, 1) == '%') {
                     $groups[$groupKey][$fieldKey]['width'] = substr($field['width'], 0, strlen($field['width']) - 1);
                 }
             }
         }
     }
     $smarty->assign('groups', $groups);
     $smarty->assign('from_mb', $this->fromModuleBuilder);
     global $image_path;
     $imageSave = SugarThemeRegistry::current()->getImage('studio_save', '', null, null, '.gif', $mod_strings['LBL_BTN_SAVE']);
     //        $imageHelp = SugarThemeRegistry::current()->getImage('help') ;
     $history = $parser->getHistory();
     $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")";
     if ($this->subpanel) {
         $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$this->subpanel}\")";
     }
     $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'";
     if ($this->subpanel) {
         $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"{$this->subpanel}\")'";
     }
     $buttons = array();
     $buttons[] = array('id' => 'savebtn', 'name' => 'savebtn', 'image' => $imageSave, 'text' => !$this->fromModuleBuilder ? $GLOBALS['mod_strings']['LBL_BTN_SAVEPUBLISH'] : $GLOBALS['mod_strings']['LBL_BTN_SAVE'], 'actionScript' => "onclick='studiotabs.generateGroupForm(\"edittabs\");if (countListFields()==0) ModuleBuilder.layoutValidation.popup() ; else ModuleBuilder.handleSave(\"edittabs\" )'");
     $buttons[] = array('id' => 'spacer', 'width' => '50px');
     $buttons[] = array('id' => 'historyBtn', 'name' => 'historyBtn', 'text' => translate('LBL_HISTORY'), 'actionScript' => "onclick='{$histaction}'");
     $buttons[] = array('id' => 'historyDefault', 'name' => 'historyDefault', 'text' => translate('LBL_RESTORE_DEFAULT'), 'actionScript' => $restoreAction);
     $smarty->assign('buttons', $this->_buildImageButtons($buttons));
     $editImage = SugarThemeRegistry::current()->getImage('edit_inline', '', null, null, '.gif', $mod_strings['LBL_EDIT']);
     $smarty->assign('editImage', $editImage);
     $deleteImage = SugarThemeRegistry::current()->getImage('delete_inline', '', null, null, '.gif', $mod_strings['LBL_MB_DELETE']);
     $smarty->assign('deleteImage', $deleteImage);
     $smarty->assign('MOD', $GLOBALS['mod_strings']);
     if ($this->fromModuleBuilder) {
         $smarty->assign('MB', true);
         $smarty->assign('view_package', $_REQUEST['view_package']);
         $mb = new ModuleBuilder();
         $module =& $mb->getPackageModule($_REQUEST['view_package'], $this->editModule);
         $smarty->assign('current_mod_strings', $module->getModStrings());
         if ($this->subpanel) {
             if (isset($_REQUEST['local'])) {
                 $smarty->assign('local', '1');
             }
             $smarty->assign("subpanel", $this->subpanel);
         } else {
             $smarty->assign('description', $GLOBALS['mod_strings']['LBL_LISTVIEW_DESCRIPTION']);
         }
     } else {
         if ($this->subpanel) {
             $smarty->assign("subpanel", "{$this->subpanel}");
         } else {
             $smarty->assign('description', $GLOBALS['mod_strings']['LBL_LISTVIEW_DESCRIPTION']);
         }
     }
     return $smarty;
 }
 function display()
 {
     $selected_lang = !empty($_REQUEST['relationship_lang']) ? $_REQUEST['relationship_lang'] : $_SESSION['authenticated_user_language'];
     $this->smarty = new Sugar_Smarty();
     $ac = new AjaxCompose();
     $this->fromModuleBuilder = isset($_REQUEST['MB']) || !empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio';
     $this->smarty->assign('fromModuleBuilder', $this->fromModuleBuilder);
     if (!$this->fromModuleBuilder) {
         $module = StudioModuleFactory::getStudioModule($_REQUEST['view_module']);
         $moduleName = $_REQUEST['view_module'];
         $fields = $module->fields;
         require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php';
         $relatableModules = DeployedRelationships::findRelatableModules();
         $appStrings = return_app_list_strings_language($selected_lang);
         $modStrings = return_module_language($selected_lang, $_REQUEST['view_module'], true);
         $appStrings = $appStrings['moduleList'];
     } else {
         $mb = new ModuleBuilder();
         $mb->getPackages();
         //display the latest module name rather than what is in or not in the loaded app_list_strings.
         $mb->getPackage($_REQUEST['view_package'])->loadModuleTitles();
         $module = $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
         $moduleName = empty($module->key_name) ? $module->getModuleName() : $module->key_name;
         $this->smarty->assign('view_package', $_REQUEST['view_package']);
         $mbvardefs = $module->getVardefs();
         $fields = $mbvardefs['fields'];
         require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php';
         $relatableModules = UndeployedRelationships::findRelatableModules();
         $appStrings = $module->getModStrings($selected_lang);
     }
     ksort($relatableModules);
     $lhs_subpanels = $module->getProvidedSubpanels();
     // Fix to re-add sorting of the subpanel names so that the 'default' subpanel always appears first in the list.
     // This assumes that subpanels are usually named ForXYZ which is the case currently, and hence 'default' will be sorted first.
     //I f this assumption is incorrect, then a better solution would be to remove 'default' from the subpanel list, then sort, and finally array_unshift it back on.
     natcasesort($lhs_subpanels);
     $cardinality = array(MB_ONETOONE => translate('LBL_ONETOONE'), MB_ONETOMANY => translate('LBL_ONETOMANY'), MB_MANYTOONE => translate('LBL_MANYTOONE'), MB_MANYTOMANY => translate('LBL_MANYTOMANY'));
     if (!$this->fromModuleBuilder) {
         unset($cardinality[MB_MANYTOONE]);
     }
     $relationships = $module->getRelationships();
     // if a description for this relationship already exists, then load it so it can be modified
     if (!empty($_REQUEST['relationship_name'])) {
         $relationship = $relationships->get($_REQUEST['relationship_name']);
         $relationship->setName($_REQUEST['relationship_name']);
         $definition = $relationship->getDefinition();
         if (!$this->fromModuleBuilder) {
             $modStrings = return_module_language($selected_lang, $relationship->rhs_module, true);
             $definition['lhs_label'] = isset($modStrings[$relationship->getTitleKey()]) ? $modStrings[$relationship->getTitleKey()] : $relationship->lhs_module;
             $modStrings = return_module_language($selected_lang, $relationship->lhs_module, true);
             $definition['rhs_label'] = isset($modStrings[$relationship->getTitleKey(true)]) ? $modStrings[$relationship->getTitleKey(true)] : $relationship->rhs_module;
         } else {
             #30624
             if (!empty($_REQUEST['rhs_module'])) {
                 $definition['rhs_label'] = $_REQUEST['rhs_module'];
             }
         }
     } else {
         $definition = array();
         $firstModuleDefinition = each($relatableModules);
         $definition['rhs_module'] = $firstModuleDefinition['key'];
         $definition['lhs_module'] = $moduleName;
         $definition['lhs_label'] = translate($moduleName);
         $definition['relationship_type'] = MB_MANYTOMANY;
     }
     // load the relationship from post - required as we can call view.relationship.php from Ajax when changing the rhs_module for example
     $definition = $this->overrideDefinitionFromPOST($definition);
     if (empty($definition['rhs_label'])) {
         $definition['rhs_label'] = translate($definition['rhs_module']);
     }
     if (empty($definition['lhs_label'])) {
         $definition['lhs_label'] = translate($definition['lhs_module']);
     }
     $relationship = RelationshipFactory::newRelationship($definition);
     $rhs_subpanels = $relatableModules[$relationship->rhs_module];
     // Fix to re-add sorting of the subpanel names so that the 'default' subpanel always appears first in the list. This assumes that subpanels are usually named ForXYZ which is the case currently, and hence 'default' will be sorted first. If this assumption is incorrect, then a better solution would be to remove 'default' from the subpanel list, then sort, and finally array_unshift it back on.
     natcasesort($rhs_subpanels);
     if (empty($_REQUEST['relationship_name'])) {
         // tidy up the options for the view based on the modules participating in the relationship and the cardinality
         // some modules (e.g., Knowledge Base/KBDocuments) lack subpanels. That means they can't be the lhs of a 1-many or many-many, or the rhs of a many-many for example
         // fix up the available cardinality options
         $relationship_type = $relationship->getType();
         if (count($lhs_subpanels) == 0 || count($rhs_subpanels) == 0) {
             unset($cardinality[MB_MANYTOMANY]);
         }
         if (count($rhs_subpanels) == 0) {
             unset($cardinality[MB_ONETOMANY]);
         }
         if (isset($definition['rhs_module']) && $definition['rhs_module'] == 'Activities') {
             $cardinality = array(MB_ONETOMANY => translate('LBL_ONETOMANY'));
         }
         //Bug 23139, Campaigns module current cannot display custom subpanels, so we need to ban it from any
         //relationships that would require a new subpanel to be shown in Campaigns.
         if (isset($definition['lhs_module']) && $definition['lhs_module'] == 'Campaigns') {
             unset($cardinality[MB_MANYTOMANY]);
             unset($cardinality[MB_ONETOMANY]);
         }
         if (isset($definition['rhs_module']) && $definition['rhs_module'] == 'Campaigns' && isset($cardinality[MB_MANYTOMANY])) {
             unset($cardinality[MB_MANYTOMANY]);
             unset($cardinality[MB_MANYTOONE]);
         }
         if (!isset($cardinality[$relationship->getType()])) {
             end($cardinality);
             $definition['relationship_type'] = key($cardinality);
             $relationship = RelationshipFactory::newRelationship($definition);
         }
         $this->smarty->assign('is_new', true);
     } else {
         $this->smarty->assign('is_new', false);
     }
     //Remove Activities if one-to-many is not availible
     if (!isset($cardinality[MB_ONETOMANY]) && isset($relatableModules['Activities'])) {
         unset($relatableModules['Activities']);
     }
     // now enforce the relationship_only requirement - that is, only construct the underlying relationship and link fields, and not the UI, if the subpanel code will have troubles displaying the UI
     $relationships->enforceRelationshipOnly($relationship);
     $this->smarty->assign('view_module', $_REQUEST['view_module']);
     $this->smarty->assign('rel', $relationship->getDefinition());
     $this->smarty->assign('mod_strings', $GLOBALS['mod_strings']);
     $this->smarty->assign('module_key', $relationship->lhs_module);
     $this->smarty->assign('cardinality', array_keys($cardinality));
     $this->smarty->assign('translated_cardinality', $cardinality);
     $this->smarty->assign('selected_cardinality', translate($relationship->getType()));
     $relatable = array();
     foreach ($relatableModules as $name => $dummy) {
         $relatable[$name] = translate($name);
     }
     unset($relatable['KBDocuments']);
     natcasesort($relatable);
     $this->smarty->assign('relatable', array_keys($relatable));
     $this->smarty->assign('translated_relatable', $relatable);
     $this->smarty->assign('rhspanels', $rhs_subpanels);
     $this->smarty->assign('lhspanels', $lhs_subpanels);
     $this->smarty->assign('selected_lang', $selected_lang);
     $this->smarty->assign('available_languages', get_languages());
     switch ($relationship->relationship_type) {
         case MB_ONETOONE:
             break;
         case MB_ONETOMANY:
             if (empty($relationship->relationship_column_name)) {
                 $validRoleColumnFields = array();
                 foreach ($fields as $field) {
                     $validRoleColumnFields[] = $field;
                 }
                 $this->smarty->assign('relationship_role_column_enum', $validRoleColumnFields);
             }
             if (!empty($relationship->relationship_role_column_value)) {
                 $this->smarty->assign('relationship_role_column_value', $relationship->relationship_role_column_value);
             }
             break;
         case MB_MANYTOMANY:
             if (!empty($relationship->relationship_role_column_value)) {
                 $this->smarty->assign('relationship_role_column_value', $relationship->relationship_role_column_value);
             }
             break;
     }
     //see if we use the new system
     if (isset($_REQUEST['json']) && $_REQUEST['json'] == 'false') {
         echo $this->smarty->fetch('modules/ModuleBuilder/tpls/studioRelationship.tpl');
     } else {
         $ac->addSection('east', $module->name . ' ' . $GLOBALS['mod_strings']['LBL_RELATIONSHIPS'], $this->smarty->fetch('modules/ModuleBuilder/tpls/studioRelationship.tpl'));
         echo $ac->getJavascript();
     }
 }
 function display()
 {
     $this->fromModuleBuilder = isset($_REQUEST['MB']) || !empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio';
     if ($this->fromModuleBuilder) {
         return;
         //no support for MB
     }
     global $current_user;
     global $mod_strings;
     $smarty = new Sugar_Smarty();
     $smarty->assign('title', $mod_strings['LBL_DEVELOPER_TOOLS']);
     $smarty->assign('question', $mod_strings['LBL_QUESTION_ADD_LAYOUT']);
     $smarty->assign('mod_strings', $mod_strings);
     $module_name = $_REQUEST['view_module'];
     // set up language files
     //$smarty->assign ( 'language', $parser->getLanguage() ) ; // for sugar_translate in the smarty template
     //$smarty->assign('from_mb',$this->fromModuleBuilder);
     $mb = new ModuleBuilder();
     if (!isset($_REQUEST['view_package'])) {
         $_REQUEST['view_package'] = 'studio';
     }
     $module =& $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
     $package = $mb->packages[$_REQUEST['view_package']];
     $package->loadModuleTitles();
     $ajax = new AjaxCompose();
     $ajax->addCrumb(translate('LBL_STUDIO', 'ModuleBuilder'), 'ModuleBuilder.main("studio")');
     $ajax->addCrumb(translate($module_name), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $module_name . '")');
     $ajax->addCrumb(translate('LBL_LAYOUTS', 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=addlayout&layouts=1&view_module=' . $module_name . '")');
     $ajax->addCrumb($mod_strings['LBL_ADD_LAYOUT'], '');
     //$ajax->addSection ( 'center', $moduleName . ' ' . translate('LBL_ADD_LAYOUT'),
     $html = $smarty->fetch('modules/ModuleBuilder/tpls/addlayoutdone.tpl');
     $html .= "<script>ModuleBuilder.treeRefresh('Studio')</script>";
     $ajax->addSection('center', $mod_strings['LBL_ADD_LAYOUT'], $html);
     echo $ajax->getJavascript();
 }