Esempio n. 1
0
 /**
  * Load ACLs for module
  * @param string $module
  * @param array $context
  * @return array ACLs list
  */
 public static function loadACLs($module, $context = array())
 {
     if (!isset(self::$acls[$module])) {
         self::$acls[$module] = array();
         $name = BeanFactory::getObjectName($module);
         if (!isset($GLOBALS['dictionary'][$name])) {
             if (empty($name) || empty($GLOBALS['beanList'][$module]) || empty($GLOBALS['beanFiles'][$GLOBALS['beanList'][$module]]) || in_array($module, array('Empty'))) {
                 // try to weed out non-bean modules - these can't have ACLs as they don't have vardefs to keep them
                 $GLOBALS['log']->debug("Non-bean {$module} - no ACL for you!");
                 return array();
             }
             VardefManager::loadVardef($module, $name);
         }
         $acl_list = isset($GLOBALS['dictionary'][$name]['acls']) ? $GLOBALS['dictionary'][$name]['acls'] : array();
         $acl_list = array_merge($acl_list, SugarBean::getDefaultACL());
         $GLOBALS['log']->debug("ACLS for {$module}: " . var_export($acl_list, true));
         foreach ($acl_list as $klass => $args) {
             if ($args === false) {
                 continue;
             }
             self::$acls[$module][] = new $klass($args);
         }
     }
     return self::$acls[$module];
 }
Esempio n. 2
0
 private function createRelationship($lhs_module, $rhs_module = null, $relationship_type = 'one-to-many')
 {
     $rhs_module = $rhs_module == null ? $lhs_module : $rhs_module;
     // Adding relation between products and users
     $this->relationships = new DeployedRelationships($lhs_module);
     $definition = array('lhs_module' => $lhs_module, 'relationship_type' => $relationship_type, 'rhs_module' => $rhs_module, 'lhs_label' => $lhs_module, 'rhs_label' => $rhs_module, 'rhs_subpanel' => 'default');
     $this->relationship = RelationshipFactory::newRelationship($definition);
     $this->relationships->add($this->relationship);
     $this->relationships->save();
     $this->relationships->build();
     LanguageManager::clearLanguageCache($lhs_module);
     // Updating $dictionary by created relation
     global $dictionary;
     $moduleInstaller = new ModuleInstaller();
     $moduleInstaller->silent = true;
     $moduleInstaller->rebuild_tabledictionary();
     require 'modules/TableDictionary.php';
     // Updating vardefs
     VardefManager::$linkFields = array();
     VardefManager::clearVardef();
     VardefManager::refreshVardefs($lhs_module, BeanFactory::getObjectName($lhs_module));
     if ($lhs_module != $rhs_module) {
         VardefManager::refreshVardefs($rhs_module, BeanFactory::getObjectName($rhs_module));
     }
     SugarRelationshipFactory::rebuildCache();
 }
Esempio n. 3
0
 /**
  * Find the link entry for a particular relationship and module.
  *
  * @param $module
  * @return array|bool
  */
 public function getLinkedDefForModuleByRelationship($module)
 {
     $results = VardefManager::getLinkFieldForRelationship($module, BeanFactory::getObjectName($module), $this->name);
     //Only a single link was found
     if (isset($results['name'])) {
         return $results;
     } else {
         if (is_array($results)) {
             $GLOBALS['log']->error("Warning: Multiple links found for relationship {$this->name} within module {$module}");
             return $this->getMostAppropriateLinkedDefinition($results);
         } else {
             return FALSE;
         }
     }
 }
Esempio n. 4
0
 public function __construct($def)
 {
     global $dictionary;
     $this->def = $def;
     $this->name = $def['name'];
     $this->selfReferencing = $def['lhs_module'] == $def['rhs_module'];
     $lhsModule = $def['lhs_module'];
     $rhsModule = $def['rhs_module'];
     if ($this->selfReferencing) {
         $links = VardefManager::getLinkFieldForRelationship($lhsModule, BeanFactory::getObjectName($lhsModule), $this->name);
         if (empty($links)) {
             $GLOBALS['log']->fatal("No Links found for relationship {$this->name}");
         } else {
             if (!isset($links[0]) && !isset($links['name'])) {
                 $GLOBALS['log']->fatal("Bad link found for relationship {$this->name}");
             } else {
                 if (!isset($links[1]) && isset($links['name'])) {
                     $this->lhsLinkDef = $this->rhsLinkDef = $links;
                 } else {
                     if (!empty($links[0]) && !empty($links[1])) {
                         if (!empty($links[0]['side']) && $links[0]['side'] == "right" || !empty($links[0]['link_type']) && $links[0]['link_type'] == "one") {
                             //$links[0] is the RHS
                             $this->lhsLinkDef = $links[1];
                             $this->rhsLinkDef = $links[0];
                         } else {
                             //$links[0] is the LHS
                             $this->lhsLinkDef = $links[0];
                             $this->rhsLinkDef = $links[1];
                         }
                     }
                 }
             }
         }
     } else {
         $this->lhsLinkDef = VardefManager::getLinkFieldForRelationship($lhsModule, BeanFactory::getObjectName($lhsModule), $this->name);
         $this->rhsLinkDef = VardefManager::getLinkFieldForRelationship($rhsModule, BeanFactory::getObjectName($rhsModule), $this->name);
         if (!isset($this->lhsLinkDef['name']) && isset($this->lhsLinkDef[0])) {
             $this->lhsLinkDef = $this->lhsLinkDef[0];
         }
         if (!isset($this->rhsLinkDef['name']) && isset($this->rhsLinkDef[0])) {
             $this->rhsLinkDef = $this->rhsLinkDef[0];
         }
     }
     $this->lhsLink = $this->lhsLinkDef['name'];
     $this->rhsLink = $this->rhsLinkDef['name'];
 }
Esempio n. 5
0
 /**
  * Generates field equality comparison PHP code
  *
  * @param WorkFlowTriggerShell $shell_object
  * @param bool $is_equal
  * @return string
  */
 private function getCompareText($shell_object, $is_equal)
 {
     global $dictionary;
     $parentWorkflow = $shell_object->get_workflow_type();
     if (empty($parentWorkflow->base_module)) {
         $GLOBALS['log']->error("WorkFlowTriggerShell ({$shell_object->id}) " . "parent WorkFlow ({$parentWorkflow->id}) has no base module set.");
     }
     $useStrict = true;
     $moduleName = $parentWorkflow->base_module;
     $objectName = BeanFactory::getObjectName($moduleName);
     $field = $shell_object->field;
     VardefManager::loadVardef($moduleName, $objectName);
     if (!empty($dictionary[$objectName]) && !empty($dictionary[$objectName]['fields'][$field])) {
         $vardef = $dictionary[$objectName]['fields'][$field];
         // Don't use strict for numerical types
         if (!empty($vardef['type']) && in_array($vardef['type'], array('currency', 'double', 'int'))) {
             $useStrict = false;
         }
         // Use to_display_date for Date fields
         if (!empty($vardef['type']) && in_array($vardef['type'], array('date'))) {
             $dateTimeFunction = 'to_display_date';
         }
         // Use to_display_date_time for DateTime fields
         if (!empty($vardef['type']) && in_array($vardef['type'], array('datetime', 'datetimecombo'))) {
             $dateTimeFunction = 'to_display_date_time';
         }
     }
     $sep = $is_equal ? '==' : '!=';
     if ($useStrict) {
         $sep .= '=';
     }
     $equalityCheck = "\$focus->fetched_row['" . $field . "'] " . $sep . " \$focus->" . $field;
     if (!empty($dateTimeFunction)) {
         $equalityCheck = "\$GLOBALS['timedate']->{$dateTimeFunction}(\$focus->fetched_row['" . $field . "'])" . " {$sep} " . "\$GLOBALS['timedate']->{$dateTimeFunction}(\$focus->" . $field . ")";
     }
     // Due to sidecar pushing unchanged fields, we need a check when that happens
     if (!$is_equal) {
         $equalityCheck .= " && !(\$focus->fetched_row['" . $field . "'] === null && strlen(\$focus->" . $field . ") === 0)";
     }
     return " (isset(\$focus->" . $field . ") && " . "(empty(\$focus->fetched_row) || array_key_exists('" . $field . "', \$focus->fetched_row)) " . "&& {$equalityCheck}) ";
 }
Esempio n. 6
0
 protected function buildRelationshipCache()
 {
     global $beanList, $dictionary, $buildingRelCache;
     if ($buildingRelCache) {
         return;
     }
     $buildingRelCache = true;
     include_once "modules/TableDictionary.php";
     if (empty($beanList)) {
         include "include/modules.php";
     }
     //Reload ALL the module vardefs....
     foreach ($beanList as $moduleName => $beanName) {
         VardefManager::loadVardef($moduleName, BeanFactory::getObjectName($moduleName));
     }
     $relationships = array();
     //Grab all the relationships from the dictionary.
     foreach ($dictionary as $key => $def) {
         if (!empty($def['relationships'])) {
             foreach ($def['relationships'] as $relKey => $relDef) {
                 if ($key == $relKey) {
                     //Relationship only entry, we need to capture everything
                     $relationships[$key] = array_merge(array('name' => $key), $def, $relDef);
                 } else {
                     $relationships[$relKey] = array_merge(array('name' => $relKey), $relDef);
                     if (!empty($relationships[$relKey]['join_table']) && empty($relationships[$relKey]['fields']) && isset($dictionary[$relationships[$relKey]['join_table']]['fields'])) {
                         $relationships[$relKey]['fields'] = $dictionary[$relationships[$relKey]['join_table']]['fields'];
                     }
                 }
             }
         }
     }
     //Save it out
     sugar_mkdir(dirname($this->getCacheFile()), null, true);
     $out = "<?php \n \$relationships=" . var_export($relationships, true) . ";";
     sugar_file_put_contents($this->getCacheFile(), $out);
     $this->relationships = $relationships;
     $buildingRelCache = false;
 }
Esempio n. 7
0
 /**
  * Gets vardef info for a given module.
  *
  * @param string $moduleName The name of the module to collect vardef information about.
  * @return array The vardef's $dictonary array.
  */
 public function getVarDef($moduleName)
 {
     require_once 'data/BeanFactory.php';
     $obj = BeanFactory::getObjectName($moduleName);
     if ($obj) {
         require_once 'include/SugarObjects/VardefManager.php';
         global $dictionary;
         VardefManager::loadVardef($moduleName, $obj);
         if (isset($dictionary[$obj])) {
             $data = $dictionary[$obj];
         }
         // vardefs are missing something, for consistency let's populate some arrays
         if (!isset($data['fields'])) {
             $data['fields'] = array();
         }
         if (!isset($data['relationships'])) {
             $data['relationships'] = array();
         }
         if (!isset($data['fields'])) {
             $data['fields'] = array();
         }
     }
     // Bug 56505 - multiselect fields default value wrapped in '^' character
     if (!empty($data['fields'])) {
         $data['fields'] = $this->getMetaDataHacks()->normalizeFieldDefs($data);
     }
     if (!isset($data['relationships'])) {
         $data['relationships'] = array();
     }
     return $data;
 }
Esempio n. 8
0
 /**
  * Returns array of linked bean's calculated fields which use relation to
  * the current bean in their formulas
  *
  * @param string $linkName Name of current bean's link
  * @return array
  */
 protected function get_fields_influencing_linked_bean_calc_fields($linkName)
 {
     global $dictionary;
     $result = array();
     if (!$this->load_relationship($linkName)) {
         return $result;
     }
     /** @var Link2 $link */
     $link = $this->{$linkName};
     $relatedModuleName = $link->getRelatedModuleName();
     $relatedBeanName = BeanFactory::getObjectName($relatedModuleName);
     $relatedLinkName = $link->getRelatedModuleLinkName();
     if (empty($relatedBeanName) || empty($dictionary[$relatedBeanName])) {
         $GLOBALS['log']->fatal("Cannot load field defs for {$relatedBeanName}");
         return $result;
     }
     // iterate over related bean fields
     foreach ($dictionary[$relatedBeanName]['fields'] as $def) {
         if (!empty($def['formula'])) {
             $expr = Parser::evaluate($def['formula'], $this);
             $fields = $this->get_formula_related_fields($expr, $relatedLinkName);
             $result = array_merge($result, $fields);
         }
     }
     return array_unique($result);
 }
 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;
 }
Esempio n. 10
0
 /**
  * Process all after create operations:
  * copy_rel_from - Copies relationships from a specified record. The relationship that should be copied is specified
  *                 in the vardef.
  *
  * @param $args
  * @param SugarBean $bean
  */
 protected function processAfterCreateOperations($args, SugarBean $bean)
 {
     $this->requireArgs($args, array('module'));
     global $dictionary;
     $afterCreateKey = 'after_create';
     $copyRelationshipsFromKey = 'copy_rel_from';
     $module = $args['module'];
     $objectName = BeanFactory::getObjectName($module);
     if (array_key_exists($afterCreateKey, $args) && array_key_exists($copyRelationshipsFromKey, $args[$afterCreateKey]) && array_key_exists($afterCreateKey, $dictionary[$objectName]) && array_key_exists($copyRelationshipsFromKey, $dictionary[$objectName][$afterCreateKey])) {
         $relationshipsToCopy = $dictionary[$objectName][$afterCreateKey][$copyRelationshipsFromKey];
         $beanCopiedFrom = BeanFactory::getBean($module, $args[$afterCreateKey][$copyRelationshipsFromKey]);
         foreach ($relationshipsToCopy as $linkName) {
             $bean->load_relationship($linkName);
             $beanCopiedFrom->load_relationship($linkName);
             $beanCopiedFrom->{$linkName}->getBeans();
             $bean->{$linkName}->add($beanCopiedFrom->{$linkName}->beans);
         }
     }
 }
    function process_editview()
    {
        if (isset($this->bean->{$this->value_name}['secondaries'])) {
            $this->numFields = count($this->bean->{$this->value_name}['secondaries']) + 1;
        }
        if (!isset($this->displayParams['readOnly'])) {
            $this->displayParams['readOnly'] = '';
        } else {
            $this->displayParams['readOnly'] = $this->displayParams['readOnly'] == false ? '' : 'READONLY';
        }
        // If there is extra field to show.
        if (isset($this->displayParams['collection_field_list'])) {
            $relatedObject = BeanFactory::getObjectName($this->related_module);
            vardefmanager::loadVardef($this->related_module, $relatedObject);
            foreach ($this->displayParams['collection_field_list'] as $k => $v) {
                $javascript = '';
                $collection_field_vardef = $GLOBALS['dictionary'][$relatedObject]['fields'][$v['name']];
                // For each extra field the params which are not displayParams will be consider as params to override the vardefs values.
                foreach ($v as $k_override => $v_override) {
                    if ($k_override != 'displayParams') {
                        $collection_field_vardef[$k_override] = $v_override;
                    }
                }
                // If relate field : enable quick search by creating the sqs_object array.
                if ($collection_field_vardef['type'] == 'relate') {
                    require_once 'include/TemplateHandler/TemplateHandler.php';
                    $tph = new TemplateHandler();
                    $javascript = $tph->createQuickSearchCode(array($collection_field_vardef['name'] => $collection_field_vardef), array($v), $this->form_name);
                    $javascript = str_replace('<script language="javascript">' . "if(typeof sqs_objects == 'undefined'){var sqs_objects = new Array;}sqs_objects['{$collection_field_vardef['name']}']=", "", $javascript);
                    $javascript = substr($javascript, 0, -10);
                    //remove ";</script>"
                    $javascriptPHP = $this->json->decode($javascript);
                    foreach ($javascriptPHP['populate_list'] as $kk => $vv) {
                        $javascriptPHP['populate_list'][$kk] .= "_" . $this->vardef['name'] . "_collection_extra_0";
                    }
                    foreach ($javascriptPHP['required_list'] as $kk => $vv) {
                        $javascriptPHP['required_list'][$kk] .= "_" . $this->vardef['name'] . "_collection_extra_0";
                    }
                    foreach ($javascriptPHP['field_list'] as $kk => $vv) {
                        if ($vv == 'id') {
                            $javascriptPHP['populate_list'][$kk];
                        }
                    }
                    $javascript = $this->json->encode($javascriptPHP);
                    $javascript = "<script language='javascript'>if(typeof sqs_objects == 'undefined'){var sqs_objects = new Array;}sqs_objects['{$collection_field_vardef['name']}_" . $this->vardef['name'] . "_collection_extra_0']=" . $javascript . ';</script>';
                }
                $collection_field_vardef['name'] .= "_" . $this->vardef['name'] . "_collection_extra_0";
                if (isset($collection_field_vardef['id_name'])) {
                    $collection_field_vardef['id_name'] .= "_" . $this->vardef['name'] . "_collection_extra_0";
                }
                if (isset($this->displayParams['allow_update']) && ($this->displayParams['allow_update'] === false || $this->displayParams['allow_update'] === 'false')) {
                    $this->displayParams['allow_update'] = 'false';
                    $v['displayParams']['field']['disabled'] = '';
                } else {
                    $this->displayParams['allow_update'] = 'true';
                    if (!isset($v['displayParams'])) {
                        $v['displayParams'] = array();
                    }
                }
                // Wireless view for Enum type because the wireless view retrieve and translate the list on real time.
                if ($collection_field_vardef['type'] == 'enum') {
                    //TODO Change to an other view
                    $viewtype = 'WirelessEditView';
                } else {
                    $viewtype = 'EditView';
                }
                $name = $collection_field_vardef['name'];
                // Rearranging the array with name as key instaead of number. This is required for displaySmarty() to assign the good variable.
                $this->displayParams['collection_field_list'][$name]['vardefName'] = $this->displayParams['collection_field_list'][$k]['name'];
                $this->displayParams['collection_field_list'][$name]['name'] = $name;
                if ($collection_field_vardef['type'] == 'relate') {
                    $this->displayParams['collection_field_list'][$name]['id_name'] = $collection_field_vardef['id_name'];
                    $this->displayParams['collection_field_list'][$name]['module'] = $collection_field_vardef['module'];
                }
                $this->displayParams['collection_field_list'][$name]['label'] = "{sugar_translate label='{$collection_field_vardef['vname']}' module='{$this->related_module}'}";
                //translate($collection_field_vardef['vname'], $this->related_module);
                $this->displayParams['collection_field_list'][$name]['field'] = $sfh->displaySmarty('displayParams.collection_field_list', $collection_field_vardef, $viewtype, $v['displayParams'], 1);
                $this->displayParams['collection_field_list'][$name]['field'] .= '{literal}' . $javascript;
                // Handle update_field array ONCHANGE
                $this->displayParams['collection_field_list'][$name]['field'] .= <<<FRA
                <script language='javascript'>
                    var oldonchange = '';
                    if(typeof(document.getElementById('{$collection_field_vardef['name']}').attributes.onchange) != 'undefined')
                    {
                        oldonchange=document.getElementById('{$collection_field_vardef['name']}').attributes.onchange.value;
                    }
FRA;
                $this->displayParams['collection_field_list'][$name]['field'] .= "eval(\"document.getElementById('{$collection_field_vardef['name']}').onchange = function onchange(event){collection['{$this->vardef['name']}'].update_fields.{$collection_field_vardef['name']}=true;";
                if ($collection_field_vardef['type'] == 'relate') {
                    // If relate add the ID field to the array
                    $this->displayParams['collection_field_list'][$name]['field'] .= "collection['{$this->vardef['name']}'].update_fields.{$collection_field_vardef['id_name']}=true;";
                }
                $this->displayParams['collection_field_list'][$name]['field'] .= "document.getElementById('update_fields_{$this->vardef['name']}_collection').value = YAHOO.lang.JSON.stringify(collection['{$this->vardef['name']}'].update_fields);\" + oldonchange + \"};\");</script>{/literal}";
                //we need to get rid of the old value;
                unset($this->displayParams['collection_field_list'][$k]);
            }
        }
        if (!isset($this->displayParams['class'])) {
            $this->displayParams['class'] = '';
        }
        if (isset($this->displayParams['allow_new']) && ($this->displayParams['allow_new'] === false || $this->displayParams['allow_new'] === 'false')) {
            $this->displayParams['allow_new'] = 'false';
            $this->displayParams['class'] = str_replace('sqsNoAutofill', '', $this->displayParams['class']);
        } else {
            $this->displayParams['allow_new'] = 'true';
            $this->displayParams['class'] .= ' sqsNoAutofill';
        }
        if (isset($this->displayParams['new_on_update']) && ($this->displayParams['new_on_update'] !== false || $this->displayParams['new_on_update'] !== 'false' || $this->displayParams['new_on_update'] !== 'FALSE' || $this->displayParams['new_on_update'] !== '0')) {
            $this->displayParams['new_on_update'] = 'true';
        } else {
            $this->displayParams['new_on_update'] = 'false';
        }
    }
Esempio n. 12
0
 static function getModules()
 {
     $modules = array();
     foreach ($GLOBALS['beanList'] as $module => $object) {
         $object = BeanFactory::getObjectName($module);
         VardefManager::loadVardef($module, $object);
         if (empty($GLOBALS['dictionary'][$object]['fields'])) {
             continue;
         }
         $modules[] = $module;
     }
     sort($modules);
     return $modules;
 }
Esempio n. 13
0
 /**
  * @static
  * @param  $module
  * @param  $object
  * @return array|bool  returns a list of all fields in the module of type 'link'.
  */
 protected static function getLinkFieldsForModule($module, $object)
 {
     global $dictionary;
     //Some modules like cases have a bean name that doesn't match the object name
     if (empty($dictionary[$object])) {
         $newName = BeanFactory::getObjectName($module);
         $object = $newName != false ? $newName : $object;
     }
     if (empty($dictionary[$object])) {
         self::loadVardef($module, $object, false, array('ignore_rel_calc_fields' => true));
     }
     if (empty($dictionary[$object])) {
         $GLOBALS['log']->debug("Failed to load vardefs for {$module}:{$object} in linkFieldsForModule<br/>");
         return false;
     }
     //Cache link fields for this call in a static variable
     if (!isset(self::$linkFields)) {
         self::$linkFields = array();
     }
     if (isset(self::$linkFields[$object])) {
         return self::$linkFields[$object];
     }
     $vardef = $dictionary[$object];
     $links = array();
     foreach ($vardef['fields'] as $name => $def) {
         //Look through all link fields for related modules that have calculated fields that use that relationship
         if (!empty($def['type']) && $def['type'] == 'link' && !empty($def['relationship'])) {
             $links[$name] = $def;
         }
     }
     self::$linkFields[$object] = $links;
     return $links;
 }
Esempio n. 14
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'];
     }
     // 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;
 }
Esempio n. 15
0
 /**
  * Cleaning caches and refreshing vardefs
  *
  * @static
  * @param string $lhs_module left module from relation
  * @param string $rhs_module right module from relation
  * @return bool are caches refreshed or not
  */
 protected static function setUp_relation(array $params)
 {
     if (empty($params[0]) || empty($params[1])) {
         throw new SugarTestHelperException('setUp("relation") requires two parameters');
     }
     list($lhs_module, $rhs_module) = $params;
     self::$registeredVars['relation'] = true;
     self::$cleanModules[] = $lhs_module;
     LanguageManager::clearLanguageCache($lhs_module);
     if ($lhs_module != $rhs_module) {
         self::$cleanModules[] = $rhs_module;
         LanguageManager::clearLanguageCache($rhs_module);
     }
     self::setUp('dictionary');
     VardefManager::$linkFields = array();
     VardefManager::clearVardef();
     VardefManager::refreshVardefs($lhs_module, BeanFactory::getObjectName($lhs_module));
     if ($lhs_module != $rhs_module) {
         VardefManager::refreshVardefs($rhs_module, BeanFactory::getObjectName($rhs_module));
     }
     SugarRelationshipFactory::rebuildCache();
     return true;
 }
Esempio n. 16
0
 /**
  * Refreshes vardefs for modules that are affected by a change during installation.
  *
  * @param array $modules List of modules to refresh vardefs for
  */
 protected function clearAffectedVardefsCache($modules = array())
 {
     foreach ($modules as $module) {
         $obj = BeanFactory::getObjectName($module);
         VardefManager::refreshVardefs($module, $obj);
     }
 }
 public static function manageExternalDatabaseQueries($alternativeDb, $reportModule, $simpleName = false)
 {
     require_once "modules/asol_Reports/include_basic/generateQuery.php";
     if ($alternativeDb !== false) {
         $domainField = null;
         $useAlternativeDbConnection = true;
         if ($simpleName) {
             $report_module = $reportModule;
         } else {
             $alternativeModuleAux = explode(" ", $reportModule);
             $alternativeModule = explode(".", $alternativeModuleAux[0]);
             $report_module = $alternativeModule[1];
         }
         $report_table = $report_module;
         $report_table_primary_key = asol_ReportsGenerateQuery::getExternalTablePrimaryKey($alternativeDb, $report_table);
         //***********************//
         //***AlineaSol Premium***//
         //***********************//
         $extraParams = array('alternativeDb' => $alternativeDb, 'report_table' => $report_table);
         $domainField = asol_ReportsUtils::managePremiumFeature("externalDatabasesReports", "reportFunctions.php", "getExternalDatabaseDomainField", $extraParams);
         $extraParams = array('alternativeDb' => $alternativeDb);
         $gmtDates = asol_ReportsUtils::managePremiumFeature("externalDatabasesReports", "reportFunctions.php", "getExternalDatabaseGmtDates", $extraParams);
         //***********************//
         //***AlineaSol Premium***//
         //***********************//
     } else {
         $useAlternativeDbConnection = false;
         $gmtDates = true;
         $report_module = $reportModule;
         $report_table = BeanFactory::newBean(BeanFactory::getObjectName($reportModule))->table_name;
         $report_table = $report_table == '' ? strtolower($report_module) : $report_table;
         $report_table_primary_key = "id";
     }
     return array("useAlternativeDbConnection" => $useAlternativeDbConnection, "domainField" => $domainField, "gmtDates" => $gmtDates, "report_module" => $report_module, "report_table" => $report_table, "report_table_primary_key" => $report_table_primary_key);
 }
Esempio n. 18
0
 public function action_searchViewSave()
 {
     $packageName = isset($_REQUEST['view_package']) ? $_REQUEST['view_package'] : null;
     // Bug 56789 - Set the client from the view to ensure the proper viewdef file
     $client = MetaDataFiles::getClientByView($_REQUEST['view']);
     if (isModuleBWC($_REQUEST['view_module'])) {
         $parser = new SearchViewMetaDataParser($_REQUEST['view'], $_REQUEST['view_module'], $packageName, $client);
     } else {
         $client = empty($client) ? 'base' : $client;
         $parser = new SidecarFilterLayoutMetaDataParser($_REQUEST['view_module'], $packageName, $client);
     }
     $parser->handleSave();
     //Repair or create a custom SearchFields.php file as needed
     $module_name = $_REQUEST['view_module'];
     global $beanList;
     if (isset($beanList[$module_name]) && $beanList[$module_name] != "") {
         $objectName = BeanFactory::getObjectName($module_name);
         //Load the vardefs for the module to pass to TemplateRange
         VardefManager::loadVardef($module_name, $objectName, true);
         global $dictionary;
         $vardefs = $dictionary[$objectName]['fields'];
         TemplateRange::repairCustomSearchFields($vardefs, $module_name, $packageName);
     }
     $this->view = 'searchView';
 }
Esempio n. 19
0
 /**
  * Deletes the field from fields_meta_data and drops the database column then it rebuilds the cache
  * Use the widgets get_db_modify_alter_table() method to get the table sql - some widgets do not need any custom table modifications
  * @param STRING $name - field name
  */
 function deleteField($widget)
 {
     require_once 'modules/DynamicFields/templates/Fields/TemplateField.php';
     global $beanList;
     if (!$widget instanceof TemplateField) {
         $field_name = $widget;
         $widget = new TemplateField();
         $widget->name = $field_name;
     }
     $object_name = $beanList[$this->module];
     //Some modules like cases have a bean name that doesn't match the object name
     if (empty($GLOBALS['dictionary'][$object_name])) {
         $newName = BeanFactory::getObjectName($this->module);
         $object_name = $newName != false ? $newName : $object_name;
     }
     $GLOBALS['db']->query("DELETE FROM fields_meta_data WHERE id='" . $this->module . $widget->name . "'");
     $sql = $widget->get_db_delete_alter_table($this->bean->table_name . "_cstm");
     if (!empty($sql)) {
         $GLOBALS['db']->query($sql);
     }
     $this->removeVardefExtension($widget);
     VardefManager::clearVardef();
     VardefManager::refreshVardefs($this->module, $object_name);
 }
Esempio n. 20
0
 function display()
 {
     global $locale;
     $editModule = $_REQUEST['view_module'];
     $allLabels = !empty($_REQUEST['labels']) && $_REQUEST['labels'] == 'all';
     if (!isset($_REQUEST['MB'])) {
         global $app_list_strings;
         $moduleNames = array_change_key_case($app_list_strings['moduleList']);
         $translatedEditModule = $moduleNames[strtolower($editModule)];
     }
     $selected_lang = null;
     if (!empty($_REQUEST['selected_lang'])) {
         $selected_lang = $_REQUEST['selected_lang'];
     } else {
         $selected_lang = $locale->getAuthenticatedUserLanguage();
     }
     $smarty = new Sugar_Smarty();
     global $mod_strings;
     $smarty->assign('mod_strings', $mod_strings);
     $smarty->assign('available_languages', get_languages());
     $objectName = BeanFactory::getObjectName($editModule);
     VardefManager::loadVardef($editModule, $objectName);
     global $dictionary;
     $vnames = array();
     //jchi 24557 . We should list all the lables in viewdefs(list,detail,edit,quickcreate) that the user can edit them.
     $parser = ParserFactory::getParser(MB_LISTVIEW, $editModule);
     foreach ($parser->getLayout() as $key => $def) {
         if (isset($def['label'])) {
             $vnames[$def['label']] = $def['label'];
         }
     }
     require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php';
     $variableMap = $this->getVariableMap($editModule);
     foreach ($variableMap as $key => $value) {
         $gridLayoutMetaDataParserTemp = ParserFactory::getParser($key, $editModule);
         foreach ($gridLayoutMetaDataParserTemp->getLayout() as $panel) {
             foreach ($panel as $row) {
                 foreach ($row as $fieldArray) {
                     // fieldArray is an array('name'=>name,'label'=>label)
                     if (isset($fieldArray['label'])) {
                         $vnames[$fieldArray['label']] = $fieldArray['label'];
                     }
                 }
             }
         }
     }
     //end
     //Get Subpanel Labels:
     require_once 'include/SubPanel/SubPanel.php';
     $subList = SubPanel::getModuleSubpanels($editModule);
     foreach ($subList as $subpanel => $titleLabel) {
         $vnames[$titleLabel] = $titleLabel;
     }
     foreach ($dictionary[$objectName]['fields'] as $name => $def) {
         if (isset($def['vname'])) {
             $vnames[$def['vname']] = $def['vname'];
         }
     }
     $formatted_mod_strings = array();
     // we shouldn't set the $refresh=true here, or will lost template language
     // mod_strings.
     // return_module_language($selected_lang, $editModule,false) :
     // the mod_strings will be included from cache files here.
     foreach (return_module_language($selected_lang, $editModule, false) as $name => $label) {
         //#25294
         if ($allLabels || isset($vnames[$name]) || preg_match('/lbl_city|lbl_country|lbl_billing_address|lbl_alt_address|lbl_shipping_address|lbl_postal_code|lbl_state$/si', $name)) {
             // Bug 58174 - Escaped labels are sent to the client escaped
             // even in the label editor in studio
             $formatted_mod_strings[$name] = html_entity_decode($label, null, 'UTF-8');
         }
     }
     //Grab everything from the custom files
     $mod_bak = $mod_strings;
     $files = array("custom/modules/{$editModule}/language/{$selected_lang}.lang.php", "custom/modules/{$editModule}/Ext/Language/{$selected_lang}.lang.ext.php");
     foreach ($files as $langfile) {
         $mod_strings = array();
         if (is_file($langfile)) {
             include $langfile;
             foreach ($mod_strings as $key => $label) {
                 // Bug 58174 - Escaped labels are sent to the client escaped
                 // even in the label editor in studio
                 $formatted_mod_strings[$key] = html_entity_decode($label, null, 'UTF-8');
             }
         }
     }
     $mod_strings = $mod_bak;
     ksort($formatted_mod_strings);
     $smarty->assign('MOD', $formatted_mod_strings);
     $smarty->assign('view_module', $editModule);
     $smarty->assign('APP', $GLOBALS['app_strings']);
     $smarty->assign('selected_lang', $selected_lang);
     $smarty->assign('defaultHelp', 'labelsBtn');
     $smarty->assign('assistant', array('key' => 'labels', 'group' => 'module'));
     $smarty->assign('labels_choice', $mod_strings['labelTypes']);
     $smarty->assign('labels_current', $allLabels ? "all" : "");
     $ajax = new AjaxCompose();
     $ajax->addCrumb($mod_strings['LBL_STUDIO'], 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard")');
     $ajax->addCrumb($translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $editModule . '")');
     $ajax->addCrumb($mod_strings['LBL_LABELS'], '');
     $html = $smarty->fetch('modules/ModuleBuilder/tpls/labels.tpl');
     $ajax->addSection('center', $GLOBALS['mod_strings']['LBL_SECTION_EDLABELS'], $html);
     echo $ajax->getJavascript();
 }
Esempio n. 21
0
 function getRelatedFields($module, $id, $fields, $return_array = false)
 {
     if (empty($GLOBALS['beanList'][$module])) {
         return '';
     }
     $object = BeanFactory::getObjectName($module);
     VardefManager::loadVardef($module, $object);
     if (empty($GLOBALS['dictionary'][$object]['table'])) {
         return '';
     }
     $table = $GLOBALS['dictionary'][$object]['table'];
     $query = 'SELECT id';
     foreach ($fields as $field => $alias) {
         if (!empty($GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields'])) {
             $query .= ' ,' . $this->db->concat($table, $GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields']) . ' as ' . $alias;
         } else {
             if (!empty($GLOBALS['dictionary'][$object]['fields'][$field]) && (empty($GLOBALS['dictionary'][$object]['fields'][$field]['source']) || $GLOBALS['dictionary'][$object]['fields'][$field]['source'] != "non-db")) {
                 $query .= ' ,' . $table . '.' . $field . ' as ' . $alias;
             }
         }
         if (!$return_array) {
             $this->{$alias} = '';
         }
     }
     if ($query == 'SELECT id' || empty($id)) {
         return '';
     }
     if (isset($GLOBALS['dictionary'][$object]['fields']['assigned_user_id'])) {
         $query .= " , " . $table . ".assigned_user_id owner";
     } else {
         if (isset($GLOBALS['dictionary'][$object]['fields']['created_by'])) {
             $query .= " , " . $table . ".created_by owner";
         }
     }
     $query .= ' FROM ' . $table . ' WHERE deleted=0 AND id=';
     $result = $GLOBALS['db']->query($query . "'{$id}'");
     $row = $GLOBALS['db']->fetchByAssoc($result);
     if ($return_array) {
         return $row;
     }
     $owner = empty($row['owner']) ? '' : $row['owner'];
     foreach ($fields as $alias) {
         $this->{$alias} = !empty($row[$alias]) ? $row[$alias] : '';
         $alias = $alias . '_owner';
         $this->{$alias} = $owner;
         $a_mod = $alias . '_mod';
         $this->{$a_mod} = $module;
     }
 }
Esempio n. 22
0
 function buildCache()
 {
     global $beanList, $beanFiles, $dictionary;
     $supported_modules = array();
     foreach ($beanList as $moduleName => $beanName) {
         if (!isset($beanFiles[$beanName])) {
             continue;
         }
         $beanName = BeanFactory::getObjectName($moduleName);
         $manager = new VardefManager();
         $manager->loadVardef($moduleName, $beanName);
         // obtain the field definitions used by generateSearchWhere (duplicate code in view.list.php)
         if (file_exists('custom/modules/' . $moduleName . '/metadata/metafiles.php')) {
             require 'custom/modules/' . $moduleName . '/metadata/metafiles.php';
         } elseif (file_exists('modules/' . $moduleName . '/metadata/metafiles.php')) {
             require 'modules/' . $moduleName . '/metadata/metafiles.php';
         }
         if (!empty($metafiles[$moduleName]['searchfields'])) {
             require $metafiles[$moduleName]['searchfields'];
         } else {
             if (file_exists("modules/{$moduleName}/metadata/SearchFields.php")) {
                 require "modules/{$moduleName}/metadata/SearchFields.php";
             }
         }
         //Load custom SearchFields.php if it exists
         if (file_exists("custom/modules/{$moduleName}/metadata/SearchFields.php")) {
             require "custom/modules/{$moduleName}/metadata/SearchFields.php";
         }
         //If there are $searchFields are empty, just continue, there are no search fields defined for the module
         if (empty($searchFields[$moduleName])) {
             continue;
         }
         $isCustomModule = preg_match('/^([a-z0-9]{1,5})_([a-z0-9_]+)$/i', $moduleName);
         //If the bean supports unified search or if it's a custom module bean and unified search is not defined
         if (!empty($dictionary[$beanName]['unified_search']) || $isCustomModule) {
             $fields = array();
             foreach ($dictionary[$beanName]['fields'] as $field => $def) {
                 // We cannot enable or disable unified_search for email in the vardefs as we don't actually have a vardef entry for 'email'
                 // the searchFields entry for 'email' doesn't correspond to any vardef entry. Instead it contains SQL to directly perform the search.
                 // So as a proxy we allow any field in the vardefs that has a name starting with 'email...' to be tagged with the 'unified_search' parameter
                 if (strpos($field, 'email') !== false) {
                     $field = 'email';
                 }
                 //bug: 38139 - allow phone to be searched through Global Search
                 if (strpos($field, 'phone') !== false) {
                     $field = 'phone';
                 }
                 if (!empty($def['unified_search']) && isset($searchFields[$moduleName][$field])) {
                     $fields[$field] = $searchFields[$moduleName][$field];
                 }
             }
             foreach ($searchFields[$moduleName] as $field => $def) {
                 if (isset($def['force_unifiedsearch']) and $def['force_unifiedsearch']) {
                     $fields[$field] = $def;
                 }
             }
             if (count($fields) > 0) {
                 $supported_modules[$moduleName]['fields'] = $fields;
                 if (isset($dictionary[$beanName]['unified_search_default_enabled']) && $dictionary[$beanName]['unified_search_default_enabled'] === TRUE) {
                     $supported_modules[$moduleName]['default'] = true;
                 } else {
                     $supported_modules[$moduleName]['default'] = false;
                 }
             }
         }
     }
     ksort($supported_modules);
     write_array_to_file('unified_search_modules', $supported_modules, $this->cache_search);
 }
Esempio n. 23
0
 function action_searchViewSave()
 {
     $packageName = isset($_REQUEST['view_package']) ? $_REQUEST['view_package'] : null;
     require_once 'modules/ModuleBuilder/parsers/views/SearchViewMetaDataParser.php';
     $parser = new SearchViewMetaDataParser($_REQUEST['view'], $_REQUEST['view_module'], $packageName);
     $parser->handleSave();
     //Repair or create a custom SearchFields.php file as needed
     $module_name = $_REQUEST['view_module'];
     global $beanList;
     if (isset($beanList[$module_name]) && $beanList[$module_name] != "") {
         $objectName = BeanFactory::getObjectName($module_name);
         //Load the vardefs for the module to pass to TemplateRange
         VardefManager::loadVardef($module_name, $objectName, true);
         global $dictionary;
         $vardefs = $dictionary[$objectName]['fields'];
         require_once 'modules/DynamicFields/templates/Fields/TemplateRange.php';
         TemplateRange::repairCustomSearchFields($vardefs, $module_name, $packageName);
     }
     $this->view = 'searchView';
 }
Esempio n. 24
0
 /**
  * Builds a template
  * This is a private function that should be called only from checkTemplate method
  *
  * @param module string module name
  * @param view string view need (eg DetailView, EditView, etc)
  * @param tpl string generic tpl to use
  * @param ajaxSave boolean parameter indicating whether or not this is coming from an Ajax call
  * @param metaDataDefs metadata definition as Array
  **/
 function buildTemplate($module, $view, $tpl, $ajaxSave, $metaDataDefs)
 {
     $this->loadSmarty();
     $cacheDir = create_cache_directory($this->templateDir . $module . '/');
     $file = $cacheDir . $view . '.tpl';
     $this->ss->left_delimiter = '{{';
     $this->ss->right_delimiter = '}}';
     $this->ss->assign('module', $module);
     $this->ss->assign('built_in_buttons', array('CANCEL', 'DELETE', 'DUPLICATE', 'EDIT', 'SHARE', 'FIND_DUPLICATES', 'SAVE', 'CONNECTOR'));
     $contents = $this->ss->fetch($tpl);
     //Insert validation and quicksearch stuff here
     if ($view == 'EditView' || strpos($view, 'QuickCreate') || $ajaxSave || $view == "ConvertLead") {
         global $dictionary, $app_strings, $mod_strings;
         $mod = BeanFactory::getObjectName($module);
         $defs = $dictionary[$mod]['fields'];
         $defs2 = array();
         //Retrieve all panel field definitions with displayParams Array field set
         $panelFields = array();
         foreach ($metaDataDefs['panels'] as $panel) {
             foreach ($panel as $row) {
                 foreach ($row as $entry) {
                     if (empty($entry)) {
                         continue;
                     }
                     if (is_array($entry) && isset($entry['name']) && isset($entry['displayParams']) && isset($entry['displayParams']['required']) && $entry['displayParams']['required']) {
                         $panelFields[$entry['name']] = $entry;
                     }
                     if (is_array($entry)) {
                         $defs2[$entry['name']] = $entry;
                     } else {
                         $defs2[$entry] = array('name' => $entry);
                     }
                 }
                 //foreach
             }
             //foreach
         }
         //foreach
         foreach ($panelFields as $field => $value) {
             $nameList = array();
             if (!is_array($value['displayParams']['required'])) {
                 $nameList[] = $field;
             } else {
                 foreach ($value['displayParams']['required'] as $groupedField) {
                     $nameList[] = $groupedField;
                 }
             }
             foreach ($nameList as $x) {
                 if (isset($defs[$x]) && isset($defs[$x]['type']) && !isset($defs[$x]['required'])) {
                     $defs[$x]['required'] = true;
                 }
             }
         }
         //foreach
         //Create a base class with field_name_map property
         $sugarbean = new stdClass();
         $sugarbean->field_name_map = $defs;
         $sugarbean->module_dir = $module;
         $javascript = new javascript();
         $view = $view == 'QuickCreate' ? "QuickCreate_{$module}" : $view;
         $javascript->setFormName($view);
         $javascript->setSugarBean($sugarbean);
         if ($view != "ConvertLead") {
             $javascript->addAllFields('', null, true);
         }
         $validatedFields = array();
         $validatedFields[] = 'team_name';
         $javascript->addToValidateBinaryDependency('assigned_user_name', 'alpha', $javascript->buildStringToTranslateInSmarty('ERR_SQS_NO_MATCH_FIELD') . ': ' . $javascript->buildStringToTranslateInSmarty('LBL_ASSIGNED_TO'), 'false', '', 'assigned_user_id');
         $validatedFields[] = 'assigned_user_name';
         //Add remaining validation dependency for related fields
         //1) a relate type as defined in vardefs
         //2) set in metadata layout
         //3) not have validateDepedency set to false in metadata
         //4) have id_name in vardef entry
         //5) not already been added to Array
         foreach ($sugarbean->field_name_map as $name => $def) {
             if ($def['type'] == 'relate' && isset($defs2[$name]) && (!isset($defs2[$name]['validateDependency']) || $defs2[$name]['validateDependency'] === true) && isset($def['id_name']) && !in_array($name, $validatedFields)) {
                 if (isset($mod_strings[$def['vname']]) || isset($app_strings[$def['vname']]) || translate($def['vname'], $sugarbean->module_dir) != $def['vname']) {
                     $vname = $def['vname'];
                 } else {
                     $vname = "undefined";
                 }
                 $javascript->addToValidateBinaryDependency($name, 'alpha', $javascript->buildStringToTranslateInSmarty('ERR_SQS_NO_MATCH_FIELD') . ': ' . $javascript->buildStringToTranslateInSmarty($vname), !empty($def['required']) ? 'true' : 'false', '', $def['id_name']);
                 $validatedFields[] = $name;
             }
         }
         //foreach
         $contents .= "{literal}\n";
         $contents .= $javascript->getScript();
         $contents .= $this->createQuickSearchCode($defs, $defs2, $view, $module);
         $contents .= $this->createDependencyJavascript($defs, $metaDataDefs, $view, $module);
         $contents .= "{/literal}\n";
     } else {
         if (preg_match('/^SearchForm_.+/', $view)) {
             global $dictionary, $app_strings, $mod_strings;
             $mod = BeanFactory::getObjectName($module);
             $defs = $dictionary[$mod]['fields'];
             $contents .= '{literal}';
             $contents .= $this->createQuickSearchCode($defs, array(), $view);
             $contents .= '{/literal}';
         } else {
             if ($view == 'DetailView') {
                 global $dictionary, $app_strings, $mod_strings;
                 $mod = BeanFactory::getObjectName($module);
                 $defs = $dictionary[$mod]['fields'];
                 $contents .= "{literal}\n";
                 $contents .= $this->createDependencyJavascript($defs, $metaDataDefs, $view, $module);
                 $contents .= "{/literal}\n";
             }
         }
     }
     //if
     //Remove all the copyright comments
     $contents = preg_replace('/\\{\\*[^\\}]*?\\*\\}/', '', $contents);
     if ($fh = @sugar_fopen($file, 'w')) {
         fputs($fh, $contents);
         fclose($fh);
     }
     $this->ss->left_delimiter = '{';
     $this->ss->right_delimiter = '}';
 }
Esempio n. 25
0
/**
 * This function retrieves a module's language file and returns the array of strings included.
 *
 * @param string $language specific language to load
 * @param string $module module name to load strings for
 * @param bool $refresh optional, true if you want to rebuild the language strings
 * @return array lang strings
 */
function return_module_language($language, $module, $refresh = false)
{
    global $mod_strings;
    global $sugar_config;
    global $currentModule;
    // Jenny - Bug 8119: Need to check if $module is not empty
    if (empty($module)) {
        $stack = debug_backtrace();
        $GLOBALS['log']->warn("Variable module is not in return_module_language " . var_export($stack, true));
        return array();
    }
    if (!$refresh) {
        $cache_key = LanguageManager::getLanguageCacheKey($module, $language);
        // Check for cached value
        $cache_entry = sugar_cache_retrieve($cache_key);
        if (!empty($cache_entry) && is_array($cache_entry)) {
            return $cache_entry;
        }
    }
    // Store the current mod strings for later
    $temp_mod_strings = $mod_strings;
    $loaded_mod_strings = array();
    $language_used = $language;
    $default_language = $sugar_config['default_language'];
    if (empty($language)) {
        $language = $default_language;
    }
    // Bug 21559 - So we can get all the strings defined in the template, refresh
    // the vardefs file if the cached language file doesn't exist.
    if (!file_exists(sugar_cached('modules/') . $module . '/language/' . $language . '.lang.php') && !empty($GLOBALS['beanList'][$module])) {
        $object = BeanFactory::getObjectName($module);
        VardefManager::refreshVardefs($module, $object);
    }
    $loaded_mod_strings = LanguageManager::loadModuleLanguage($module, $language, $refresh);
    // cn: bug 6048 - merge en_us with requested language
    if ($language != $sugar_config['default_language']) {
        $loaded_mod_strings = sugarLangArrayMerge(LanguageManager::loadModuleLanguage($module, $sugar_config['default_language'], $refresh), $loaded_mod_strings);
    }
    // Load in en_us strings by default
    if ($language != 'en_us' && $sugar_config['default_language'] != 'en_us') {
        $loaded_mod_strings = sugarLangArrayMerge(LanguageManager::loadModuleLanguage($module, 'en_us', $refresh), $loaded_mod_strings);
    }
    // If we are in debug mode for translating, turn on the prefix now!
    if ($sugar_config['translation_string_prefix']) {
        foreach ($loaded_mod_strings as $entry_key => $entry_value) {
            $loaded_mod_strings[$entry_key] = $language_used . ' ' . $entry_value;
        }
    }
    $return_value = $loaded_mod_strings;
    if (!isset($mod_strings)) {
        $mod_strings = $return_value;
    } else {
        $mod_strings = $temp_mod_strings;
    }
    $cache_key = LanguageManager::getLanguageCacheKey($module, $language);
    sugar_cache_put($cache_key, $return_value);
    return $return_value;
}
Esempio n. 26
0
 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();
     }
 }
Esempio n. 27
0
 function uninstall_relationships($include_studio_relationships = false)
 {
     $relationships = array();
     //Find and remove studio created relationships.
     global $beanList, $beanFiles, $dictionary;
     //Load up the custom relationship definitions.
     if (file_exists('custom/application/Ext/TableDictionary/tabledictionary.ext.php')) {
         include 'custom/application/Ext/TableDictionary/tabledictionary.ext.php';
     }
     //Find all the relatioships/relate fields involving this module.
     $rels_to_remove = array();
     foreach ($beanList as $mod => $bean) {
         //Some modules like cases have a bean name that doesn't match the object name
         $bean = BeanFactory::getObjectName($mod);
         VardefManager::loadVardef($mod, $bean);
         //We can skip modules that are in this package as they will be removed anyhow
         if (!in_array($mod, $this->modulesInPackage) && !empty($dictionary[$bean]) && !empty($dictionary[$bean]['fields'])) {
             $field_defs = $dictionary[$bean]['fields'];
             foreach ($field_defs as $field => $def) {
                 //Weed out most fields first
                 if (isset($def['type'])) {
                     //Custom relationships created in the relationship editor
                     if ($def['type'] == "link" && !empty($def['relationship']) && !empty($dictionary[$def['relationship']])) {
                         $rel_name = $def['relationship'];
                         $rel_def = $dictionary[$rel_name]['relationships'][$rel_name];
                         //Check against mods to be removed.
                         foreach ($this->modulesInPackage as $removed_mod) {
                             if ($rel_def['lhs_module'] == $removed_mod || $rel_def['rhs_module'] == $removed_mod) {
                                 $dictionary[$rel_name]['from_studio'] = true;
                                 $relationships[$rel_name] = $dictionary[$rel_name];
                             }
                         }
                     }
                     //Custom "relate" fields created in studio also need to be removed
                     if ($def['type'] == 'relate' && isset($def['module'])) {
                         foreach ($this->modulesInPackage as $removed_mod) {
                             if ($def['module'] == $removed_mod) {
                                 require_once 'modules/ModuleBuilder/Module/StudioModule.php';
                                 $studioMod = new StudioModule($mod);
                                 $studioMod->removeFieldFromLayouts($field);
                                 if (isset($def['custom_module'])) {
                                     require_once 'modules/DynamicFields/DynamicField.php';
                                     require_once $beanFiles[$bean];
                                     $seed = new $bean();
                                     $df = new DynamicField($mod);
                                     $df->setup($seed);
                                     //Need to load the entire field_meta_data for some field types
                                     $field_obj = $df->getFieldWidget($mod, $field);
                                     $field_obj->delete($df);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->uninstall_relationship(null, $relationships);
     if (isset($this->installdefs['relationships'])) {
         $relationships = $this->installdefs['relationships'];
         $this->log(translate('LBL_MI_UN_RELATIONSHIPS'));
         foreach ($relationships as $relationship) {
             // remove the metadata entry
             $filename = basename($relationship['meta_data']);
             $pathname = file_exists("custom/metadata/{$filename}") ? "custom/metadata/{$filename}" : "metadata/{$filename}";
             if (isset($GLOBALS['mi_remove_tables']) && $GLOBALS['mi_remove_tables']) {
                 $this->uninstall_relationship($pathname);
             }
             if (file_exists($pathname)) {
                 unlink($pathname);
             }
         }
     }
     if (file_exists("custom/Extension/application/Ext/TableDictionary/{$this->id_name}.php")) {
         unlink("custom/Extension/application/Ext/TableDictionary/{$this->id_name}.php");
     }
     Relationship::delete_cache();
     $this->rebuild_tabledictionary();
 }
Esempio n. 28
0
 public function index($module, $beanId)
 {
     try {
         if (!$this->isEnabled()) {
             return;
         }
         if (empty($GLOBALS['beanList'][$module])) {
             return false;
         }
         $bean_name = $GLOBALS['beanList'][$module];
         $bean = new $bean_name();
         if (!$bean || !$bean instanceof SugarBean) {
             return false;
         }
         if (!self::isModuleSearchable($module, BeanFactory::getObjectName($module))) {
             return false;
         }
         $bean->retrieve($beanId);
         if (!$bean) {
             return false;
         }
         $indexEvent = $this->getIndexEvent($module, $beanId);
         $indexEvent->name = $bean->get_summary_text();
         $document = $this->getDocumentForBean($bean);
         //Index name, id, date, filename
         if (!$document['error']) {
             $this->remove($module, $beanId);
             $this->getLuceneIndex()->addDocument($document['document']);
             $indexEvent->success = true;
         } else {
             $indexEvent->success = false;
             $indexEvent->error = $document['error'];
         }
         $indexEvent->save();
     } catch (Exception $ex) {
         $GLOBALS['log']->error($ex->getMessage());
         return false;
     }
 }
 /**
  * Generate unifed search fields for a particular module even if the module does not participate in the unified search.
  *
  * @param string $moduleName
  * @return array An array of fields to be searched against.
  */
 function generateUnifiedSearchFields($moduleName)
 {
     global $beanList, $beanFiles, $dictionary;
     if (!isset($beanList[$moduleName])) {
         return array();
     }
     $beanName = $beanList[$moduleName];
     if (!isset($beanFiles[$beanName])) {
         return array();
     }
     $beanName = BeanFactory::getObjectName($moduleName);
     $manager = new VardefManager();
     $manager->loadVardef($moduleName, $beanName);
     // obtain the field definitions used by generateSearchWhere (duplicate code in view.list.php)
     if (file_exists('custom/modules/' . $moduleName . '/metadata/metafiles.php')) {
         require 'custom/modules/' . $moduleName . '/metadata/metafiles.php';
     } elseif (file_exists('modules/' . $moduleName . '/metadata/metafiles.php')) {
         require 'modules/' . $moduleName . '/metadata/metafiles.php';
     }
     if (!empty($metafiles[$moduleName]['searchfields'])) {
         require $metafiles[$moduleName]['searchfields'];
     } elseif (file_exists("modules/{$moduleName}/metadata/SearchFields.php")) {
         require "modules/{$moduleName}/metadata/SearchFields.php";
     }
     $fields = array();
     foreach ($dictionary[$beanName]['fields'] as $field => $def) {
         if (strpos($field, 'email') !== false) {
             $field = 'email';
         }
         //bug: 38139 - allow phone to be searched through Global Search
         if (strpos($field, 'phone') !== false) {
             $field = 'phone';
         }
         if (isset($def['unified_search']) && $def['unified_search'] && isset($searchFields[$moduleName][$field])) {
             $fields[$field] = $searchFields[$moduleName][$field];
         }
     }
     //If no fields with the unified flag have been set then lets add a default field.
     if (empty($fields)) {
         if (isset($dictionary[$beanName]['fields']['name']) && isset($searchFields[$moduleName]['name'])) {
             $fields['name'] = $searchFields[$moduleName]['name'];
         } else {
             if (isset($dictionary[$beanName]['fields']['first_name']) && isset($searchFields[$moduleName]['first_name'])) {
                 $fields['first_name'] = $searchFields[$moduleName]['first_name'];
             }
             if (isset($dictionary[$beanName]['fields']['last_name']) && isset($searchFields[$moduleName]['last_name'])) {
                 $fields['last_name'] = $searchFields[$moduleName]['last_name'];
             }
         }
     }
     return $fields;
 }
 protected function getLinkFieldDefinition($sourceModule, $relationshipName, $right_side = false, $vname = "", $id_name = false)
 {
     $vardef = array();
     $vardef['name'] = $this->getValidDBName($relationshipName);
     $vardef['type'] = 'link';
     $vardef['relationship'] = $relationshipName;
     $vardef['source'] = 'non-db';
     $vardef['module'] = $sourceModule;
     $vardef['bean_name'] = BeanFactory::getObjectName($sourceModule);
     if ($right_side) {
         $vardef['side'] = 'right';
     }
     if (!empty($vname)) {
         $vardef['vname'] = $vname;
     }
     if (!empty($id_name)) {
         $vardef['id_name'] = $id_name;
     } else {
         $vardef['id_name'] = $this->getIDName($sourceModule);
     }
     return $vardef;
 }