Beispiel #1
0
 function display()
 {
     global $mod_strings;
     $smarty = new Sugar_Smarty();
     $mb = new ModuleBuilder();
     //if (!empty($_REQUEST['package'])) {
     if (empty($_REQUEST['package']) && empty($_REQUEST['new'])) {
         $this->generatePackageButtons($mb->getPackageList());
         $smarty->assign('buttons', $this->buttons);
         $smarty->assign('title', $GLOBALS['mod_strings']['LBL_MODULEBUILDER']);
         $smarty->assign("question", $GLOBALS['mod_strings']['LBL_QUESTION_PACKAGE']);
         $smarty->assign("defaultHelp", "mbHelp");
         $ajax = new AjaxCompose();
         $ajax->addCrumb($GLOBALS['mod_strings']['LBL_MODULEBUILDER'], 'ModuleBuilder.getContent("module=ModuleBuilder&action=package")');
         $ajax->addCrumb($GLOBALS['mod_strings']['LBL_PACKAGE_LIST'], '');
         $ajax->addSection('center', $GLOBALS['mod_strings']['LBL_PACKAGE_LIST'], $smarty->fetch('modules/ModuleBuilder/tpls/wizard.tpl'));
         echo $ajax->getJavascript();
     } else {
         $name = !empty($_REQUEST['package']) ? $_REQUEST['package'] : '';
         $mb->getPackage($name);
         require_once 'modules/ModuleBuilder/MB/MBPackageTree.php';
         $mbt = new MBPackageTree();
         $nodes = $mbt->fetchNodes();
         $package_labels = array();
         if (!empty($nodes['tree_data']['nodes'])) {
             foreach ($nodes['tree_data']['nodes'] as $entry) {
                 if (!empty($entry['data']['label']) && $name != $entry['data']['label']) {
                     $package_labels[] = strtoupper($entry['data']['label']);
                 }
             }
         }
         $json = getJSONobj();
         $smarty->assign('package_labels', $json->encode($package_labels));
         $this->package =& $mb->packages[$name];
         $this->loadModuleTypes();
         $this->loadPackageHelp($name);
         $this->package->date_modified = $GLOBALS['timedate']->to_display_date_time($this->package->date_modified);
         $smarty->assign('package', $this->package);
         $smarty->assign('mod_strings', $mod_strings);
         $smarty->assign('package_already_deployed', 'false');
         foreach ($this->package->modules as $a_module) {
             if (in_array($a_module->key_name, $GLOBALS['moduleList'])) {
                 $smarty->assign('package_already_deployed', 'true');
                 break;
             }
         }
         $ajax = new AjaxCompose();
         $ajax->addCrumb($GLOBALS['mod_strings']['LBL_MODULEBUILDER'], 'ModuleBuilder.getContent("module=ModuleBuilder&action=package")');
         if (empty($name)) {
             $name = $mod_strings['LBL_NEW_PACKAGE'];
         }
         $ajax->addCrumb($name, '');
         $html = $smarty->fetch('modules/ModuleBuilder/tpls/MBPackage/package.tpl');
         if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'SavePackage') {
             $html .= "<script>ModuleBuilder.treeRefresh('ModuleBuilder')</script>";
         }
         $ajax->addSection('center', translate('LBL_SECTION_PACKAGE', 'ModuleBuilder'), $html);
         echo $ajax->getJavascript();
     }
 }
 public function __construct()
 {
     parent::__construct();
     foreach ($this->vars as $var) {
         if (!isset($_REQUEST[$var])) {
             sugar_die("Required paramter {$var} not set in ViewRelFields");
         }
         $this->{$var} = $_REQUEST[$var];
     }
     $mb = new ModuleBuilder();
     $this->package = empty($_REQUEST['package']) || $_REQUEST['package'] == 'studio' ? "" : $mb->getPackage($_REQUEST['package']);
 }
 function __construct($view, $moduleName, $packageName)
 {
     // BEGIN ASSERTIONS
     if (!isset($this->_fileVariables[$view])) {
         sugar_die(get_class($this) . ": View {$view} is not supported");
     }
     // END ASSERTIONS
     $this->_view = strtolower($view);
     $this->_moduleName = $moduleName;
     $this->_packageName = $packageName;
     //get the bean from ModuleBuilder
     $mb = new ModuleBuilder();
     $module =& $mb->getPackageModule($packageName, $moduleName);
     $pak = $mb->getPackage($packageName);
     $module->mbvardefs->updateVardefs();
     // Set the list of fields associated with this module
     $fielddefs = array_change_key_case($module->mbvardefs->vardefs['fields']);
     // 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'], $module->getModStrings());
     //Load relationshhip based fields and labels
     $moduleRels = $pak->getRelationshipsForModule($moduleName);
     foreach ($moduleRels as $rName => $rel) {
         $varDefsSet = $rel->buildVardefs();
         foreach ($varDefsSet as $arr) {
             foreach ($arr as $def) {
                 $fielddefs[$def['name']] = $def;
             }
         }
         $labels = $rel->buildLabels();
         foreach ($labels as $def) {
             if ($def['module'] == $module->key_name) {
                 $GLOBALS['mod_strings'][$def['system_label']] = $def['display_label'];
             }
         }
     }
     $loaded = null;
     foreach (array(MB_WORKINGMETADATALOCATION, MB_HISTORYMETADATALOCATION) as $type) {
         $this->_sourceFilename = $this->getFileName($view, $moduleName, $packageName, $type);
         if (null !== ($layout = $this->_loadFromFile($this->_sourceFilename))) {
             // merge in the fielddefs from this layout
             $this->_mergeFielddefs($fielddefs, $layout);
             $loaded = $layout;
         }
     }
     if ($loaded === null) {
         throw new Exception(get_class($this) . ": view definitions for View {$this->_view} and Module {$this->_moduleName} are missing");
     }
     $this->_viewdefs = $loaded;
     $this->_originalViewdefs = $this->_loadFromFile(MB_WORKINGMETADATALOCATION);
     $this->_fielddefs = $fielddefs;
     $this->_history = new History($this->getFileName($view, $moduleName, $packageName, MB_HISTORYMETADATALOCATION));
 }
 public function display()
 {
     global $mod_strings, $locale;
     $bak_mod_strings = $mod_strings;
     $smarty = new Sugar_Smarty();
     $smarty->assign('mod_strings', $mod_strings);
     $package_name = $_REQUEST['view_package'];
     $module_name = $_REQUEST['view_module'];
     require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
     $mb = new ModuleBuilder();
     $mb->getPackage($_REQUEST['view_package']);
     $package = $mb->packages[$_REQUEST['view_package']];
     $package->getModule($module_name);
     $mbModule = $package->modules[$module_name];
     if (!empty($_REQUEST['selected_lang'])) {
         $selected_lang = $_REQUEST['selected_lang'];
     } else {
         $selected_lang = $locale->getAuthenticatedUserLanguage();
     }
     //need to change the following to interface with MBlanguage.
     $smarty->assign('MOD', $mbModule->getModStrings($selected_lang));
     $smarty->assign('APP', $GLOBALS['app_strings']);
     $smarty->assign('selected_lang', $selected_lang);
     $smarty->assign('view_package', $package_name);
     $smarty->assign('view_module', $module_name);
     $smarty->assign('mb', '1');
     $smarty->assign('available_languages', get_languages());
     ///////////////////////////////////////////////////////////////////
     ////ASSISTANT
     $smarty->assign('assistant', array('group' => 'module', 'key' => 'labels'));
     /////////////////////////////////////////////////////////////////
     ////ASSISTANT
     $ajax = new AjaxCompose();
     $ajax->addCrumb($bak_mod_strings['LBL_MODULEBUILDER'], 'ModuleBuilder.main("mb")');
     $ajax->addCrumb($package_name, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $package->name . '")');
     $ajax->addCrumb($module_name, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $package->name . '&view_module=' . $module_name . '")');
     $ajax->addCrumb($bak_mod_strings['LBL_LABELS'], '');
     $ajax->addSection('center', $bak_mod_strings['LBL_LABELS'], $smarty->fetch('modules/ModuleBuilder/tpls/labels.tpl'));
     echo $ajax->getJavascript();
 }
Beispiel #5
0
 function display()
 {
     global $mod_strings;
     $smarty = new Sugar_Smarty();
     $mb = new ModuleBuilder();
     //if (!empty($_REQUEST['package'])) {
     if (empty($_REQUEST['package']) && empty($_REQUEST['new'])) {
         $this->generatePackageButtons($mb->getPackageList());
         $smarty->assign('buttons', $this->buttons);
         $smarty->assign('title', $GLOBALS['mod_strings']['LBL_MODULEBUILDER']);
         $smarty->assign("question", $GLOBALS['mod_strings']['LBL_QUESTION_PACKAGE']);
         $smarty->assign("defaultHelp", "mbHelp");
         $ajax = new AjaxCompose();
         $ajax->addCrumb($GLOBALS['mod_strings']['LBL_MODULEBUILDER'], 'ModuleBuilder.getContent("module=ModuleBuilder&action=package")');
         $ajax->addCrumb($GLOBALS['mod_strings']['LBL_PACKAGE_LIST'], '');
         $ajax->addSection('center', $GLOBALS['mod_strings']['LBL_PACKAGE_LIST'], $smarty->fetch('modules/ModuleBuilder/tpls/wizard.tpl'));
         echo $ajax->getJavascript();
     } else {
         $name = !empty($_REQUEST['package']) ? $_REQUEST['package'] : '';
         $mb->getPackage($name);
         $this->package =& $mb->packages[$name];
         $this->loadModuleTypes();
         $this->loadPackageHelp($name);
         $this->package->date_modified = $GLOBALS['timedate']->to_display_date_time($this->package->date_modified);
         $smarty->assign('package', $this->package);
         $smarty->assign('mod_strings', $mod_strings);
         $ajax = new AjaxCompose();
         $ajax->addCrumb($GLOBALS['mod_strings']['LBL_MODULEBUILDER'], 'ModuleBuilder.getContent("module=ModuleBuilder&action=package")');
         if (empty($name)) {
             $name = $mod_strings['LBL_NEW_PACKAGE'];
         }
         $ajax->addCrumb($name, '');
         $html = $smarty->fetch('modules/ModuleBuilder/tpls/MBPackage/package.tpl');
         if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'SavePackage') {
             $html .= "<script>ModuleBuilder.treeRefresh('ModuleBuilder')</script>";
         }
         $ajax->addSection('center', translate('LBL_SECTION_PACKAGE', 'ModuleBuilder'), $html);
         echo $ajax->getJavascript();
     }
 }
 function display()
 {
     global $mod_strings;
     $smarty = new Sugar_Smarty();
     require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
     $mb = new ModuleBuilder();
     $mb->getPackage($_REQUEST['view_package']);
     $package = $mb->packages[$_REQUEST['view_package']];
     $module_name = !empty($_REQUEST['view_module']) ? $_REQUEST['view_module'] : '';
     $package->getModule($module_name);
     $this->mbModule = $package->modules[$module_name];
     $this->loadPackageHelp($module_name);
     // set up the list of either available types for a new module, or implemented types for an existing one
     $types = empty($module_name) ? MBModule::getTypes() : $this->mbModule->mbvardefs->templates;
     foreach ($types as $type => $definition) {
         $translated_type[$type] = translate('LBL_TYPE_' . strtoupper($type), 'ModuleBuilder');
     }
     natcasesort($translated_type);
     $smarty->assign('types', $translated_type);
     $smarty->assign('package', $package);
     $smarty->assign('module', $this->mbModule);
     $smarty->assign('mod_strings', $mod_strings);
     $ajax = new AjaxCompose();
     $ajax->addCrumb($GLOBALS['mod_strings']['LBL_MODULEBUILDER'], 'ModuleBuilder.main("mb")');
     $ajax->addCrumb(' ' . $package->name, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $package->name . '")');
     if (empty($module_name)) {
         $module_name = translate('LBL_NEW_MODULE', 'ModuleBuilder');
     }
     $ajax->addCrumb($module_name, '');
     $html = $smarty->fetch('modules/ModuleBuilder/tpls/MBModule/module.tpl');
     if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'SaveModule') {
         $html .= "<script>ModuleBuilder.treeRefresh('ModuleBuilder')</script>";
     }
     $ajax->addSection('center', translate('LBL_SECTION_MODULE', 'ModuleBuilder'), $html);
     echo $ajax->getJavascript();
 }
 static function parseDeployedModuleName($deployedName)
 {
     require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
     $mb = new ModuleBuilder();
     $packageName = '';
     $moduleName = $deployedName;
     foreach ($mb->getPackageList() as $name) {
         // convert the keyName into a packageName, needed for checking to see if this is really an undeployed module, or just a module with a _ in the name...
         $package = $mb->getPackage($name);
         // seem to need to call getPackage twice to get the key correctly... TODO: figure out why...
         $key = $mb->getPackage($name)->key;
         if (strlen($key) < strlen($deployedName)) {
             $position = stripos($deployedName, $key);
             $moduleName = trim(substr($deployedName, strlen($key)), '_');
             //use trim rather than just assuming that _ is between packageName and moduleName in the deployedName
             if ($position !== false && $position == 0 && isset($mb->packages[$name]->modules[$moduleName])) {
                 $packageName = $name;
                 break;
             }
         }
     }
     if (!empty($packageName)) {
         return array('moduleName' => $moduleName, 'packageName' => $packageName);
     } else {
         return array('moduleName' => $deployedName);
     }
 }
 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()
 {
     $smarty = new Sugar_Smarty();
     global $mod_strings;
     $bak_mod_strings = $mod_strings;
     $smarty->assign('mod_strings', $mod_strings);
     $module_name = $_REQUEST['view_module'];
     if (!isset($_REQUEST['view_package']) || $_REQUEST['view_package'] == 'studio') {
         //$this->loadPackageHelp($module_name);
         $studioClass = new stdClass();
         $studioClass->name = $module_name;
         global $beanList;
         $objectName = $beanList[$module_name];
         if ($objectName == 'aCase') {
             // Bug 17614 - renamed aCase as Case in vardefs for backwards compatibililty with 451 modules
             $objectName = 'Case';
         }
         VardefManager::loadVardef($module_name, $objectName, true);
         global $dictionary;
         $f = array($mod_strings['LBL_HCUSTOM'] => array(), $mod_strings['LBL_HDEFAULT'] => array());
         // TODO: replace this section to select fields to list with the algorithm in AbstractMetaDataImplmentation::validField()
         $def = $this->cullFields($dictionary[$objectName]['fields']);
         foreach ($dictionary[$objectName]['fields'] as $def) {
             if ($this->isValidStudioField($def)) {
                 //Custom relate fields will have a non-db source, but custom_module set
                 if (isset($def['source']) && $def['source'] == 'custom_fields' || isset($def['custom_module'])) {
                     $f[$mod_strings['LBL_HCUSTOM']][$def['name']] = $def;
                 } else {
                     $f[$mod_strings['LBL_HDEFAULT']][$def['name']] = $def;
                 }
             }
         }
         $studioClass->mbvardefs->vardefs['fields'] = $f;
         $smarty->assign('module', $studioClass);
         $package = new stdClass();
         $package->name = '';
         $smarty->assign('package', $package);
         $ajax = new AjaxCompose();
         $ajax->addCrumb($mod_strings['LBL_STUDIO'], 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard")');
         $ajax->addCrumb(translate($module_name), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $module_name . '")');
         $ajax->addCrumb($mod_strings['LBL_FIELDS'], '');
         $ajax->addSection('center', $mod_strings['LBL_EDIT_FIELDS'], $smarty->fetch('modules/ModuleBuilder/tpls/MBModule/fields.tpl'));
         $_REQUEST['field'] = '';
         echo $ajax->getJavascript();
     } else {
         require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
         $mb = new ModuleBuilder();
         $mb->getPackage($_REQUEST['view_package']);
         $package = $mb->packages[$_REQUEST['view_package']];
         $package->getModule($module_name);
         $this->module = $package->modules[$module_name];
         $this->loadPackageHelp($module_name);
         $this->module->getVardefs(true);
         $this->module->mbvardefs->vardefs['fields'] = array_reverse($this->module->mbvardefs->vardefs['fields'], true);
         $loadedFields = array();
         foreach ($this->module->mbvardefs->vardefs['fields'] as $k => $v) {
             if ($k != $module_name) {
                 $titleLBL[$k] = translate("LBL_" . strtoupper($k), 'ModuleBuilder');
             } else {
                 $titleLBL[$k] = $k;
             }
             foreach ($v as $field => $def) {
                 if (isset($loadedFields[$field])) {
                     unset($this->module->mbvardefs->vardefs['fields'][$k][$field]);
                 } else {
                     $loadedFields[$field] = true;
                 }
             }
         }
         $this->module->mbvardefs->vardefs['fields'][$module_name] = $this->cullFields($this->module->mbvardefs->vardefs['fields'][$module_name]);
         if (file_exists($this->module->path . '/language/' . $GLOBALS['current_language'] . '.lang.php')) {
             include $this->module->path . '/language/' . $GLOBALS['current_language'] . '.lang.php';
             $this->module->setModStrings($GLOBALS['current_language'], $mod_strings);
         } elseif (file_exists($this->module->path . '/language/en_us.lang.php')) {
             include $this->module->path . '/language/en_us.lang.php';
             $this->module->setModStrings('en_us', $mod_strings);
         }
         $smarty->assign('title', $titleLBL);
         $smarty->assign('package', $package);
         $smarty->assign('module', $this->module);
         $smarty->assign('editLabelsMb', '1');
         //need to merge MB labels and studio labels. quick fix for now.
         $ajax = new AjaxCompose();
         $ajax->addCrumb($bak_mod_strings['LBL_MODULEBUILDER'], 'ModuleBuilder.main("mb")');
         $ajax->addCrumb($package->name, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $package->name . '")');
         $ajax->addCrumb($module_name, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $package->name . '&view_module=' . $module_name . '")');
         $ajax->addCrumb($bak_mod_strings['LBL_FIELDS'], '');
         $ajax->addSection('center', $bak_mod_strings["LBL_FIELDS"], $smarty->fetch('modules/ModuleBuilder/tpls/MBModule/fields.tpl'));
         $_REQUEST['field'] = '';
         echo $ajax->getJavascript();
     }
 }
Beispiel #10
0
 function action_SaveModule()
 {
     $mb = new ModuleBuilder();
     $load = !empty($_REQUEST['original_name']) ? $_REQUEST['original_name'] : $_REQUEST['name'];
     if (!empty($load)) {
         $mb->getPackage($_REQUEST['package']);
         $mb->packages[$_REQUEST['package']]->getModule($load);
         $module =& $mb->packages[$_REQUEST['package']]->modules[$load];
         $module->populateFromPost();
         $mb->save();
         if (!empty($_REQUEST['duplicate'])) {
             $module->copy($_REQUEST['name']);
         } else {
             if (!empty($_REQUEST['original_name']) && $_REQUEST['original_name'] != $_REQUEST['name']) {
                 if (!$module->rename($_REQUEST['name'])) {
                     $module->name = $_REQUEST['original_name'];
                     $_REQUEST['name'] = $_REQUEST['original_name'];
                 }
             }
         }
         $_REQUEST['view_package'] = $_REQUEST['package'];
         $_REQUEST['view_module'] = $module->name;
         $this->view = 'module';
     }
 }
 function display()
 {
     $smarty = new Sugar_Smarty();
     global $mod_strings;
     $bak_mod_strings = $mod_strings;
     $smarty->assign('mod_strings', $mod_strings);
     $module_name = $_REQUEST['view_module'];
     global $current_language;
     $module_strings = return_module_language($current_language, $module_name);
     $fieldsData = array();
     $customFieldsData = array();
     //use fieldTypes variable to map field type to displayed field type
     $fieldTypes = $mod_strings['fieldTypes'];
     //add datetimecombo type field from the vardef overrides to point to Datetime type
     $fieldTypes['datetime'] = $fieldTypes['datetimecombo'];
     if (!isset($_REQUEST['view_package']) || $_REQUEST['view_package'] == 'studio') {
         //$this->loadPackageHelp($module_name);
         $studioClass = new stdClass();
         $studioClass->name = $module_name;
         $objectName = BeanFactory::getObjectName($module_name);
         VardefManager::loadVardef($module_name, $objectName, true);
         global $dictionary;
         $f = array($mod_strings['LBL_HCUSTOM'] => array(), $mod_strings['LBL_HDEFAULT'] => array());
         foreach ($dictionary[$objectName]['fields'] as $def) {
             if (!$this->isValidStudioField($def)) {
                 continue;
             }
             if (!empty($def['vname'])) {
                 $def['label'] = translate($def['vname'], $module_name);
             } elseif (!empty($def['label'])) {
                 $def['label'] = translate($def['label'], $module_name);
             } else {
                 $def['label'] = $def['name'];
             }
             //Custom relate fields will have a non-db source, but custom_module set
             if (isset($def['source']) && $def['source'] == 'custom_fields' || isset($def['custom_module'])) {
                 $f[$mod_strings['LBL_HCUSTOM']][$def['name']] = $def;
                 $def['custom'] = true;
             } else {
                 $f[$mod_strings['LBL_HDEFAULT']][$def['name']] = $def;
                 $def['custom'] = false;
             }
             $def['type'] = isset($fieldTypes[$def['type']]) ? $fieldTypes[$def['type']] : ucfirst($def['type']);
             $fieldsData[] = $def;
             $customFieldsData[$def['name']] = $def['custom'];
         }
         $studioClass->mbvardefs->vardefs['fields'] = $f;
         $smarty->assign('module', $studioClass);
         $package = new stdClass();
         $package->name = '';
         $smarty->assign('package', $package);
         global $current_user;
         $sortPreferences = $current_user->getPreference('fieldsTableColumn', 'ModuleBuilder');
         $smarty->assign('sortPreferences', $sortPreferences);
         $smarty->assign('fieldsData', getJSONobj()->encode($fieldsData));
         $smarty->assign('customFieldsData', getJSONobj()->encode($customFieldsData));
         $smarty->assign('studio', true);
         $ajax = new AjaxCompose();
         $ajax->addCrumb($mod_strings['LBL_STUDIO'], 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard")');
         $ajax->addCrumb(translate($module_name), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $module_name . '")');
         $ajax->addCrumb($mod_strings['LBL_FIELDS'], '');
         $ajax->addSection('center', $mod_strings['LBL_EDIT_FIELDS'], $smarty->fetch('modules/ModuleBuilder/tpls/MBModule/fields.tpl'));
         $_REQUEST['field'] = '';
         echo $ajax->getJavascript();
     } else {
         require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
         $mb = new ModuleBuilder();
         $mb->getPackage($_REQUEST['view_package']);
         $package = $mb->packages[$_REQUEST['view_package']];
         $package->getModule($module_name);
         $this->mbModule = $package->modules[$module_name];
         // We need the type to determine true custom fields
         $moduleType = $this->mbModule->getModuleType();
         $this->loadPackageHelp($module_name);
         $this->mbModule->getVardefs(true);
         $this->mbModule->mbvardefs->vardefs['fields'] = array_reverse($this->mbModule->mbvardefs->vardefs['fields'], true);
         $loadedFields = array();
         if (file_exists($this->mbModule->path . '/language/' . $current_language . '.lang.php')) {
             include $this->mbModule->path . '/language/' . $current_language . '.lang.php';
             $this->mbModule->setModStrings($current_language, $mod_strings);
         } elseif (file_exists($this->mbModule->path . '/language/en_us.lang.php')) {
             include $this->mbModule->path . '/language/en_us.lang.php';
             $this->mbModule->setModStrings('en_us', $mod_strings);
         }
         foreach ($this->mbModule->mbvardefs->vardefs['fields'] as $k => $v) {
             if ($k != $this->mbModule->name) {
                 foreach ($v as $field => $def) {
                     if (in_array($field, array_keys($this->mbModule->mbvardefs->vardefs['fields'][$this->mbModule->name]))) {
                         $this->mbModule->mbvardefs->vardefs['fields'][$k][$field] = $this->mbModule->mbvardefs->vardefs['fields'][$this->mbModule->name][$field];
                         unset($this->mbModule->mbvardefs->vardefs['fields'][$this->mbModule->name][$field]);
                     }
                 }
             }
         }
         foreach ($this->mbModule->mbvardefs->vardefs['fields'] as $k => $v) {
             if ($k != $module_name) {
                 $titleLBL[$k] = translate("LBL_" . strtoupper($k), 'ModuleBuilder');
             } else {
                 $titleLBL[$k] = $k;
             }
             foreach ($v as $field => $def) {
                 if (isset($loadedFields[$field])) {
                     unset($this->mbModule->mbvardefs->vardefs['fields'][$k][$field]);
                 } else {
                     $this->mbModule->mbvardefs->vardefs['fields'][$k][$field]['label'] = isset($def['vname']) && isset($this->mbModule->mblanguage->strings[$current_language . '.lang.php'][$def['vname']]) ? $this->mbModule->mblanguage->strings[$current_language . '.lang.php'][$def['vname']] : $field;
                     // It's only custom if the module name is the same as the key AND not the same as the module type
                     $custom = $k == $this->mbModule->name && $this->mbModule->name != $moduleType;
                     $customFieldsData[$field] = $custom ? true : false;
                     $loadedFields[$field] = true;
                     $type = $this->mbModule->mbvardefs->vardefs['fields'][$k][$field]['type'];
                     $this->mbModule->mbvardefs->vardefs['fields'][$k][$field]['type'] = isset($fieldTypes[$type]) ? $fieldTypes[$type] : ucfirst($type);
                     if ($this->isValidStudioField($this->mbModule->mbvardefs->vardefs['fields'][$k][$field])) {
                         $fieldsData[] = $this->mbModule->mbvardefs->vardefs['fields'][$k][$field];
                     }
                 }
             }
         }
         $this->mbModule->mbvardefs->vardefs['fields'][$module_name] = $this->cullFields($this->mbModule->mbvardefs->vardefs['fields'][$module_name]);
         $smarty->assign('fieldsData', getJSONobj()->encode($fieldsData));
         $smarty->assign('customFieldsData', getJSONobj()->encode($customFieldsData));
         global $current_user;
         $sortPreferences = $current_user->getPreference('fieldsTableColumn', 'ModuleBuilder');
         $smarty->assign('sortPreferences', $sortPreferences);
         $smarty->assign('title', $titleLBL);
         $smarty->assign('package', $package);
         $smarty->assign('module', $this->mbModule);
         $smarty->assign('editLabelsMb', '1');
         $smarty->assign('studio', false);
         $ajax = new AjaxCompose();
         $ajax->addCrumb($bak_mod_strings['LBL_MODULEBUILDER'], 'ModuleBuilder.main("mb")');
         $ajax->addCrumb($package->name, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $package->name . '")');
         $ajax->addCrumb($module_name, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $package->name . '&view_module=' . $module_name . '")');
         $ajax->addCrumb($bak_mod_strings['LBL_FIELDS'], '');
         $ajax->addSection('center', $bak_mod_strings["LBL_FIELDS"], $smarty->fetch('modules/ModuleBuilder/tpls/MBModule/fields.tpl'));
         $_REQUEST['field'] = '';
         echo $ajax->getJavascript();
     }
 }
 /**
  * Gets a translated module name for both deployed and undeployed modules
  * 
  * @param string $module The module to get a translated name for
  * @return string
  */
 protected function getModuleName($module)
 {
     // If there is an object name for this (or bean name) assume this is a
     // deployed module and return the translated string
     if (BeanFactory::getObjectName($module)) {
         return translate($module);
     }
     // If we get here, then see if there is an undeployed module based on
     // all installed packages
     $mb = new ModuleBuilder();
     $packages = $mb->getPackageList();
     foreach ($packages as $package) {
         $mod = $mb->getPackage($package)->getModuleByFullName($module);
         if ($mod && !empty($mod->config['label'])) {
             // Since this is undeployed, there is no module "name" so rely on
             // the label in the module config
             return $mod->config['label'];
         }
     }
     // Hmmm, what really is this? Don't know, send it back as is
     return $module;
 }
    /**
     * Load current Sugar metadata for this module
     * 
     * @return array
     */
    protected function loadDefaultMetadata()
    {
        $client = $this->client == 'wireless' ? 'mobile' : $this->client;
        // The new defs array - this should contain OOTB defs for the module
        $newdefs = $viewdefs = array();
        $viewname = MetaDataFiles::getName($this->viewtype);
        if (!$viewname) {
            $viewname = $this->viewtype;
        }
        // Bug 55568 - new metadata was not included for custom metadata
        // conversion from pre-6.6 installations.
        // Grab the new metadata for this module. For undeployed modules we
        // need to get the metadata from the SugarObject type.
        // If there are defs for this module, grab them
        $this->defsfile = 'modules/' . $this->module . '/clients/' . $client . '/views/' . $viewname . '/' . $viewname . '.php';
        if (file_exists($this->defsfile)) {
            require $this->defsfile;
            if (isset($viewdefs[$this->module][$client]['view'][$viewname])) {
                $newdefs = $viewdefs[$this->module][$client]['view'][$viewname];
            }
        }
        // Fallback to the object type if there were no defs found
        // Bug 57216 - Upgrade wizard was dying on undeployed modules getType
        if (empty($newdefs)) {
            if ($this->deployed) {
                require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php';
                $sm = StudioModuleFactory::getStudioModule($this->module);
                $moduleType = $sm->getType();
            } elseif ($this->package) {
                require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
                $mb = new ModuleBuilder();
                $package = $mb->getPackage($this->package);
                $module = $package->getModule($this->module);
                $moduleType = $module->getModuleType();
            }
            if (!empty($moduleType)) {
                $this->base_defsfile = 'include/SugarObjects/templates/' . $moduleType . '/clients/' . $client . '/views/' . $viewname . '/' . $viewname . '.php';
                if (file_exists($this->base_defsfile)) {
                    require $this->base_defsfile;
                } else {
                    $this->base_defsfile = 'include/SugarObjects/templates/basic/clients/' . $client . '/views/' . $viewname . '/' . $viewname . '.php';
                    if (file_exists($this->base_defsfile)) {
                        require $this->base_defsfile;
                    } else {
                        $this->logUpgradeStatus("Could not find basic {$viewname} template for module {$this->module} type {$moduleType}");
                    }
                }
                // See if there are viewdefs defined that we can use
                if (isset($viewdefs['<module_name>'][$client]['view'][$viewname])) {
                    //Need to perform variable replacement for some field defs
                    $module = $this->getNormalizedModuleName();
                    $convertedDefs = MetaDataFiles::getModuleMetaDataDefsWithReplacements($module, $viewdefs);
                    if (isset($convertedDefs[$module][$client]['view'][$viewname])) {
                        $newdefs = $convertedDefs[$module][$client]['view'][$viewname];
                    } else {
                        $newdefs = $viewdefs['<module_name>'][$client]['view'][$viewname];
                    }
                }
                // Only write a defs file for deployed modules
                if ($newdefs && $this->deployed) {
                    // If we used the template, create the basic one
                    $this->logUpgradeStatus(get_class($this) . ": Copying template defs {$this->base_defsfile} to {$this->defsfile}");
                    mkdir_recursive(dirname($this->defsfile));
                    $viewname = pathinfo($this->defsfile, PATHINFO_FILENAME);
                    $export = var_export($newdefs, true);
                    $data = <<<END
<?php
/* Generated by SugarCRM Upgrader */
\$viewdefs['{$this->module}']['{$client}']['view']['{$viewname}'] = {$export};
END;
                    sugar_file_put_contents($this->defsfile, $data);
                }
            }
        }
        return $newdefs;
    }
 /**
  * Constructor
  * @param string $view
  * @param string $moduleName
  * @param string $packageName
  * @param string $client The client making the request for this implementation
  * @throws Exception Thrown if the provided view doesn't exist for this module
  */
 function __construct($view, $moduleName, $packageName, $client = '')
 {
     // BEGIN ASSERTIONS
     if (!isset($this->_fileVariables[$view])) {
         sugar_die(get_class($this) . ": View {$view} is not supported");
     }
     // END ASSERTIONS
     $this->_view = strtolower($view);
     $this->setViewClient($client);
     $this->_moduleName = $moduleName;
     $this->_packageName = $packageName;
     //get the bean from ModuleBuilder
     $mb = new ModuleBuilder();
     $this->module = $module =& $mb->getPackageModule($packageName, $moduleName);
     $pak = $mb->getPackage($packageName);
     $module->mbvardefs->updateVardefs();
     // Set the list of fields associated with this module
     $fielddefs = array_change_key_case($module->mbvardefs->vardefs['fields']);
     // 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'];
     }
     // Set up global mod strings so that if they are not set up yet - like in
     // upgrades - calling on the global var will not throw warnings
     $globalModStrings = empty($GLOBALS['mod_strings']) ? array() : $GLOBALS['mod_strings'];
     $GLOBALS['mod_strings'] = array_merge($globalModStrings, $module->getModStrings($selected_lang));
     //Load relationshhip based fields and labels
     $moduleRels = $pak->getRelationshipsForModule($moduleName);
     foreach ($moduleRels as $rName => $rel) {
         $varDefsSet = $rel->buildVardefs();
         if (!empty($varDefsSet[$module->key_name])) {
             foreach ($varDefsSet[$module->key_name] as $def) {
                 $fielddefs[$def['name']] = $def;
             }
         }
         $labels = $rel->buildLabels();
         foreach ($labels as $def) {
             if ($def['module'] == $module->key_name) {
                 $GLOBALS['mod_strings'][$def['system_label']] = $def['display_label'];
             }
         }
     }
     $loaded = null;
     foreach (array(MB_WORKINGMETADATALOCATION, MB_HISTORYMETADATALOCATION) as $type) {
         $this->_sourceFilename = $this->getFileName($view, $moduleName, $packageName, $type);
         if ($view == MB_POPUPSEARCH || $view == MB_POPUPLIST) {
             $layout = $this->_loadFromPopupFile($this->_sourceFilename, null, $view);
         } else {
             $layout = $this->_loadFromFile($this->_sourceFilename);
         }
         if (null !== $layout) {
             if (MB_WORKINGMETADATALOCATION == $type) {
                 $this->_useWorkingFile = true;
             } elseif (MB_HISTORYMETADATALOCATION == $type && $this->_useWorkingFile) {
                 $this->_useWorkingFile = false;
             }
             // merge in the fielddefs from this layout
             $this->_mergeFielddefs($fielddefs, $layout);
             $loaded = $layout;
         }
     }
     if ($loaded === null) {
         throw new Exception(get_class($this) . ": view definitions for View {$this->_view} and Module {$this->_moduleName} are missing");
     }
     $this->_viewdefs = $loaded;
     $sourceFilename = $this->getFileName($view, $moduleName, $packageName, MB_WORKINGMETADATALOCATION);
     if ($view == MB_POPUPSEARCH || $view == MB_POPUPLIST) {
         $layout = $this->_loadFromPopupFile($sourceFilename, null, $view);
     } else {
         $layout = $this->_loadFromFile($sourceFilename);
     }
     $this->_originalViewdefs = $layout;
     $this->_fielddefs = $fielddefs;
     // Bug 56675 - Panel defs needed for undeployed modules as well
     // Set the panel defs (the old field defs)
     $this->setPanelDefsFromViewDefs();
     // Make sure the paneldefs are proper if there are any
     if (is_array($this->_paneldefs) && !is_numeric(key($this->_paneldefs))) {
         $this->_paneldefs = array($this->_paneldefs);
     }
     $this->_history = new History($this->getFileName($view, $moduleName, $packageName, MB_HISTORYMETADATALOCATION));
 }