示例#1
0
 /**
  * Function to retrieve name fields of a module
  * @return <array> - array which contains fields which together construct name fields
  */
 public function getNameFields()
 {
     $nameFieldObject = Vtiger_Cache::get('EntityField', $this->getName());
     $moduleName = $this->getName();
     if ($nameFieldObject && $nameFieldObject->fieldname) {
         $this->nameFields = explode(',', $nameFieldObject->fieldname);
     } else {
         $adb = PearDatabase::getInstance();
         $query = "SELECT fieldname, tablename, entityidfield FROM vtiger_entityname WHERE tabid = ?";
         $result = $adb->pquery($query, array(getTabid('Calendar')));
         $this->nameFields = array();
         if ($result) {
             $rowCount = $adb->num_rows($result);
             if ($rowCount > 0) {
                 $fieldNames = $adb->query_result($result, 0, 'fieldname');
                 $this->nameFields = explode(',', $fieldNames);
             }
         }
         $entiyObj = new stdClass();
         $entiyObj->basetable = $adb->query_result($result, 0, 'tablename');
         $entiyObj->basetableid = $adb->query_result($result, 0, 'entityidfield');
         $entiyObj->fieldname = $fieldNames;
         Vtiger_Cache::set('EntityField', $this->getName(), $entiyObj);
     }
     return $this->nameFields;
 }
示例#2
0
 public static function getConfig($type)
 {
     $log = vglobal('log');
     $log->debug('Start ' . __CLASS__ . ':' . __FUNCTION__ . " | Type: {$type}");
     $cache = Vtiger_Cache::get('MarketingProcesses', $type);
     if ($cache) {
         $log->debug('End ' . __CLASS__ . ':' . __FUNCTION__);
         return $cache;
     }
     $db = PearDatabase::getInstance();
     $result = $db->pquery('SELECT * FROM yetiforce_proc_marketing WHERE type = ?;', [$type]);
     if ($db->num_rows($result) == 0) {
         return [];
     }
     $config = [];
     for ($i = 0; $i < $db->num_rows($result); ++$i) {
         $param = $db->query_result_raw($result, $i, 'param');
         $value = $db->query_result_raw($result, $i, 'value');
         if (in_array($param, ['groups', 'status', 'convert_status'])) {
             $config[$param] = $value == '' ? [] : explode(',', $value);
         } else {
             $config[$param] = $value;
         }
     }
     Vtiger_Cache::set('MarketingProcesses', $type, $config);
     $log->debug('End ' . __CLASS__ . ':' . __FUNCTION__);
     return $config;
 }
示例#3
0
 /**
  * Function to get the Display Value, for the current field type with given DB Insert Value
  * @param <Object> $value
  * @return <Object>
  */
 public function getDisplayValue($tree, $record = false, $recordInstance = false, $rawText = false)
 {
     $template = $this->get('field')->getFieldParams();
     $name = Vtiger_Cache::get('TreeData' . $template, $tree);
     if ($name) {
         return $name;
     }
     $adb = PearDatabase::getInstance();
     $result = $adb->pquery('SELECT * FROM vtiger_trees_templates_data WHERE templateid = ? AND tree = ?', [$template, $tree]);
     $parentName = '';
     $module = $this->get('field')->getModuleName();
     $name = false;
     if ($adb->num_rows($result)) {
         if ($adb->query_result_raw($result, 0, 'depth') > 0) {
             $parenttrre = $adb->query_result_raw($result, 0, 'parenttrre');
             $cut = strlen('::' . $tree);
             $parenttrre = substr($parenttrre, 0, -$cut);
             $pieces = explode('::', $parenttrre);
             $parent = end($pieces);
             $result2 = $adb->pquery("SELECT name FROM vtiger_trees_templates_data WHERE templateid = ? AND tree = ?", [$template, $parent]);
             $parentName = $adb->query_result_raw($result2, 0, 'name');
             $parentName = '(' . vtranslate($parentName, $module) . ') ';
         }
         $name = $parentName . vtranslate($adb->query_result($result, 0, 'name'), $module);
     }
     Vtiger_Cache::set('TreeData' . $template, $tree, $name);
     return $name;
 }
示例#4
0
 public static function getConfig($process, $type, $procesParam = false)
 {
     $log = vglobal('log');
     $log->debug('Start ' . __CLASS__ . ':' . __FUNCTION__ . " | Process: {$process}, Type: {$type}");
     $db = PearDatabase::getInstance();
     $processList = ['marketing' => 'yetiforce_proc_marketing', 'sales' => 'yetiforce_proc_sales'];
     $cache = Vtiger_Cache::get('ProcessesModel', $process . $type);
     if ($cache) {
         $log->debug('End ' . __CLASS__ . ':' . __FUNCTION__);
         return $cache;
     }
     $result = $db->pquery('SELECT * FROM ' . $processList[$process] . ' WHERE type = ?;', [$type]);
     if ($db->num_rows($result) == 0) {
         return [];
     }
     $config = [];
     for ($i = 0; $i < $db->num_rows($result); ++$i) {
         $param = $db->query_result_raw($result, $i, 'param');
         $value = $db->query_result_raw($result, $i, 'value');
         if ($param == 'users') {
             $config[$param] = $value == '' ? [] : explode(',', $value);
         } else {
             $config[$param] = $value;
         }
         if ($procesParam != false && $param == $procesParam) {
             Vtiger_Cache::set('ProcessesModel', $process . $type . $procesParam, $value);
             $log->debug('End ' . __CLASS__ . ':' . __FUNCTION__);
             return $value;
         }
     }
     Vtiger_Cache::set('ProcessesModel', $process . $type, $config);
     $log->debug('End ' . __CLASS__ . ':' . __FUNCTION__);
     return $config;
 }
示例#5
0
 /**
  * Static Function to get the instance of Vtiger Module Model for the given id or name
  * @param mixed id or name of the module
  */
 public static function getInstance()
 {
     $instance = Vtiger_Cache::get('calendar', $value);
     if (!$instance) {
         $instance = new self();
     }
     return $instance;
 }
示例#6
0
	/**
	 * Get invnetory instance
	 * @param string $moduleName Module name
	 * @return Vtiger_Inventory_Model instance
	 */
	public static function getInstance($moduleName)
	{
		$instance = Vtiger_Cache::get('Inventory', $moduleName);
		if (!$instance) {
			$modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Inventory', $moduleName);
			$instance = new $modelClassName();
			$instance->initialize($moduleName);
			Vtiger_Cache::set('Inventory', $moduleName, $instance);
		}
		return $instance;
	}
 public static function getInstance($module)
 {
     $instance = Vtiger_Cache::get('transferOwnership', $module);
     if (!$instance) {
         $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'TransferOwnership', $module);
         $instance = new $modelClassName();
         $instance->set('module', $module);
         Vtiger_Cache::set('transferOwnership', $module, $instance);
     }
     return $instance;
 }
示例#8
0
 /**
  * Function to get all the available picklist values for the current field
  * @return <Array> List of picklist values if the field is of type picklist or multipicklist, null otherwise.
  */
 public function getTaxes()
 {
     $taxs = Vtiger_Cache::get('taxes', 'global');
     if (!$taxs) {
         $db = PearDatabase::getInstance();
         $taxs = [];
         $result = $db->pquery('SELECT * FROM a_yf_taxes_global WHERE status = ?', [0]);
         while ($row = $db->fetch_array($result)) {
             $taxs[$row['id']] = $row;
         }
         Vtiger_Cache::set('taxes', 'global', $taxs);
     }
     return $taxs;
 }
示例#9
0
 /**
  * Function to get all the available picklist values for the current field
  * @return <Array> List of picklist values if the field is of type picklist or multipicklist, null otherwise.
  */
 public function getLimits()
 {
     $limits = Vtiger_Cache::get('Inventory', 'limits');
     if (!$limits) {
         $db = PearDatabase::getInstance();
         $limits = [];
         $result = $db->pquery('SELECT * FROM a_yf_inventory_limits WHERE status = ?', [0]);
         while ($row = $db->fetch_array($result)) {
             $limits[$row['id']] = $row;
         }
         Vtiger_Cache::set('Inventory', 'limits', $limits);
     }
     return $limits;
 }
 /**
  * Loading the list of multireference fields
  * @param string $sourceModule Source module name
  * @param string $destinationModule Destination module name
  * @return array
  */
 public function getMultiReferenceValueFields($sourceModule, $destinationModule)
 {
     $return = Vtiger_Cache::get('mrvf-' . $sourceModule, $destinationModule);
     if (!$return) {
         $db = PearDatabase::getInstance();
         $query = 'SELECT * FROM vtiger_field WHERE tabid = ? AND presence <> ? AND fieldparams LIKE \'{"module":"' . $destinationModule . '"%\';';
         $result = $db->pquery($query, [Vtiger_Functions::getModuleId($sourceModule), 1]);
         $return = [];
         while ($field = $db->fetch_array($result)) {
             $return[] = $field;
         }
         Vtiger_Cache::set('mrvf-' . $sourceModule, $destinationModule, $return);
     }
     return $return;
 }
示例#11
0
 /**
  * Function to get the instance of the CompanyDetails model for a given organization id
  * @param <Number> $id
  * @return Vtiger_CompanyDetails_Model instance
  */
 public static function getInstanceById($id = 1) {
     $companyDetails = Vtiger_Cache::get('vtiger', 'organization');
     if (!$companyDetails) {
         $db = PearDatabase::getInstance();
         $sql = 'SELECT * FROM vtiger_organizationdetails WHERE organization_id=?';
         $params = array($id);
         $result = $db->pquery($sql, $params);
         $companyDetails = new self();
         if ($result && $db->num_rows($result) > 0) {
             $resultRow = $db->query_result_rowdata($result, 0);
             $companyDetails->setData($resultRow);
         }
         Vtiger_Cache::set('vtiger','organization',$companyDetails);
     }
     return $companyDetails;
 }
示例#12
0
 public static function getConfig($type = false)
 {
     $log = vglobal('log');
     $log->debug('Start ' . __CLASS__ . ':' . __FUNCTION__ . " | Type: {$type}");
     $cache = Vtiger_Cache::get('SalesProcesses', $type == false ? 'all' : $type);
     if ($cache) {
         $log->debug('End ' . __CLASS__ . ':' . __FUNCTION__);
         return $cache;
     }
     $db = PearDatabase::getInstance();
     $params = [];
     $returnArrayForFields = ['groups', 'status', 'calculationsstatus', 'salesstage', 'salesstage', 'assetstatus'];
     $sql = 'SELECT * FROM yetiforce_proc_sales';
     if ($type) {
         $sql .= ' WHERE type = ?';
         $params[] = $type;
     }
     $result = $db->pquery($sql, $params);
     if ($db->num_rows($result) == 0) {
         return [];
     }
     $config = [];
     for ($i = 0; $i < $db->num_rows($result); ++$i) {
         $param = $db->query_result_raw($result, $i, 'param');
         $value = $db->query_result_raw($result, $i, 'value');
         if (in_array($param, $returnArrayForFields)) {
             $value = $value == '' ? [] : explode(',', $value);
         }
         if ($type) {
             $config[$param] = $value;
         } else {
             $config[$db->query_result_raw($result, $i, 'type')][$param] = $value;
         }
     }
     Vtiger_Cache::set('SalesProcesses', $type == false ? 'all' : $type, $config);
     $log->debug('End ' . __CLASS__ . ':' . __FUNCTION__);
     return $config;
 }
示例#13
0
 function getPicklistDetails()
 {
     $cache = Vtiger_Cache::getInstance();
     if ($cache->getPicklistDetails($this->getTabId(), $this->getFieldName())) {
         return $cache->getPicklistDetails($this->getTabId(), $this->getFieldName());
     } else {
         $hardCodedPickListNames = array("hdntaxtype", "email_flag");
         $hardCodedPickListValues = array("hdntaxtype" => array(array("label" => "Individual", "value" => "individual"), array("label" => "Group", "value" => "group")), "email_flag" => array(array('label' => 'SAVED', 'value' => 'SAVED'), array('label' => 'SENT', 'value' => 'SENT'), array('label' => 'MAILSCANNER', 'value' => 'MAILSCANNER')));
         if (in_array(strtolower($this->getFieldName()), $hardCodedPickListNames)) {
             return $hardCodedPickListValues[strtolower($this->getFieldName())];
         }
         $picklistDetails = $this->getPickListOptions($this->getFieldName());
         $cache->setPicklistDetails($this->getTabId(), $this->getFieldName(), $picklistDetails);
         return $picklistDetails;
     }
 }
 /**
  * Get instance of block
  * @param mixed block id or block label
  * @param Vtiger_Module Instance of the module if block label is passed
  */
 static function getInstance($value, $moduleInstance = false)
 {
     global $adb;
     $cache = Vtiger_Cache::getInstance();
     if ($moduleInstance && $cache->getBlockInstance($value, $moduleInstance->id)) {
         return $cache->getBlockInstance($value, $moduleInstance->id);
     } else {
         $instance = false;
         $query = false;
         $queryParams = false;
         if (Vtiger_Utils::isNumber($value)) {
             $query = "SELECT * FROM vtiger_blocks WHERE blockid=?";
             $queryParams = array($value);
         } else {
             $query = "SELECT * FROM vtiger_blocks WHERE blocklabel=? AND tabid=?";
             $queryParams = array($value, $moduleInstance->id);
         }
         $result = $adb->pquery($query, $queryParams);
         if ($adb->num_rows($result)) {
             $instance = new self();
             $instance->initialize($adb->fetch_array($result), $moduleInstance);
         }
         $cache->setBlockInstance($value, $instance->module->id, $instance);
         return $instance;
     }
 }
示例#15
0
 /**
  * Function to get all the accessible groups
  * @return <Array>
  */
 public function getAccessibleGroups($private = "", $module = false)
 {
     //TODO:Remove dependence on $_REQUEST for the module name in the below API
     $accessibleGroups = Vtiger_Cache::get('vtiger-' . $private, 'accessiblegroups');
     if (!$accessibleGroups) {
         $accessibleGroups = get_group_array(false, "ACTIVE", "", $private, $module);
         Vtiger_Cache::set('vtiger-' . $private, 'accessiblegroups', $accessibleGroups);
     }
     return get_group_array(false, "ACTIVE", "", $private);
 }
示例#16
0
文件: utils.php 项目: yunter/crm
function getUserId_Ol($username)
{
    global $log;
    $log->debug("Entering getUserId_Ol(" . $username . ") method ...");
    $log->info("in getUserId_Ol " . $username);
    $cache = Vtiger_Cache::getInstance();
    if ($cache->getUserId($username) || $cache->getUserId($username) === 0) {
        return $cache->getUserId($username);
    } else {
        global $adb;
        $sql = "select id from vtiger_users where user_name=?";
        $result = $adb->pquery($sql, array($username));
        $num_rows = $adb->num_rows($result);
        if ($num_rows > 0) {
            $user_id = $adb->query_result($result, 0, "id");
        } else {
            $user_id = 0;
        }
        $log->debug("Exiting getUserId_Ol method ...");
        $cache->setUserId($username, $user_id);
        return $user_id;
    }
}
示例#17
0
 protected static function preModuleInitialize2()
 {
     if (!Vtiger_Cache::get('EntityField', 'all')) {
         $db = PearDatabase::getInstance();
         // Initialize meta information - to speed up instance creation (Vtiger_ModuleBasic::initialize2)
         $result = $db->pquery('SELECT modulename,tablename,entityidfield,fieldname FROM vtiger_entityname', array());
         for ($index = 0, $len = $db->num_rows($result); $index < $len; ++$index) {
             $fieldNames = $db->query_result($result, $index, 'fieldname');
             $modulename = $db->query_result($result, $index, 'modulename');
             //added to handle entity names for these two modules
             //@Note: need to move these to database
             switch ($modulename) {
                 case 'HelpDesk':
                     $fieldNames = 'ticket_title';
                     break;
                 case 'Documents':
                     $fieldNames = 'notes_title';
                     break;
             }
             $entiyObj = new stdClass();
             $entiyObj->basetable = $db->query_result($result, $index, 'tablename');
             $entiyObj->basetableid = $db->query_result($result, $index, 'entityidfield');
             $entiyObj->fieldname = $fieldNames;
             Vtiger_Cache::set('EntityField', $modulename, $entiyObj);
             Vtiger_Cache::set('EntityField', 'all', true);
         }
     }
 }
示例#18
0
 /**
  * Get Vtiger_Field instances related to block
  * @param Vtiger_Block Instnace of block to use
  * @param Vtiger_Module Instance of module to which block is associated
  */
 static function getAllForBlock($blockInstance, $moduleInstance = false)
 {
     $cache = Vtiger_Cache::getInstance();
     if ($cache->getBlockFields($blockInstance->id, $moduleInstance->id)) {
         return $cache->getBlockFields($blockInstance->id, $moduleInstance->id);
     } else {
         global $adb;
         $instances = false;
         $query = false;
         $queryParams = false;
         if ($moduleInstance) {
             $query = "SELECT * FROM vtiger_field WHERE block=? AND tabid=? ORDER BY sequence";
             $queryParams = array($blockInstance->id, $moduleInstance->id);
         } else {
             $query = "SELECT * FROM vtiger_field WHERE block=? ORDER BY sequence";
             $queryParams = array($blockInstance->id);
         }
         $result = $adb->pquery($query, $queryParams);
         for ($index = 0; $index < $adb->num_rows($result); ++$index) {
             $instance = new self();
             $instance->initialize($adb->fetch_array($result), $moduleInstance, $blockInstance);
             $instances[] = $instance;
         }
         $cache->setBlockFields($blockInstance->id, $moduleInstance->id, $instances);
         return $instances;
     }
 }
示例#19
0
 /**
  * Function to Preinitialize the module Field Permissions
  * @param <Integer> $tabid
  * @param <String> $accessmode
  * @return <Array>
  */
 public static function preFetchModuleFieldPermission($tabid, $accessmode = 'readonly')
 {
     $adb = PearDatabase::getInstance();
     $user = Users_Record_Model::getCurrentUserModel();
     $privileges = $user->getPrivileges();
     $profilelist = $privileges->get('profiles');
     if (count($profilelist) > 0) {
         if ($accessmode == 'readonly') {
             $query = "SELECT vtiger_profile2field.visible,vtiger_field.fieldid FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=? AND vtiger_profile2field.visible=0 AND vtiger_def_org_field.visible=0  AND vtiger_profile2field.profileid in (" . generateQuestionMarks($profilelist) . ") AND vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid";
         } else {
             $query = "SELECT vtiger_profile2field.visible,vtiger_field.fieldid FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=? AND vtiger_profile2field.visible=0 AND vtiger_profile2field.readonly=0 AND vtiger_def_org_field.visible=0  AND vtiger_profile2field.profileid in (" . generateQuestionMarks($profilelist) . ") AND vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid";
         }
         $params = array($tabid, $profilelist);
     } else {
         if ($accessmode == 'readonly') {
             $query = "SELECT vtiger_profile2field.visible,vtiger_field.fieldid FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=? AND vtiger_profile2field.visible=0 AND vtiger_def_org_field.visible=0  AND vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid";
         } else {
             $query = "SELECT vtiger_profile2field.visible,vtiger_field.fieldid FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=? AND vtiger_profile2field.visible=0 AND vtiger_profile2field.readonly=0 AND vtiger_def_org_field.visible=0  AND vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid";
         }
         $params = array($tabid);
     }
     $result = $adb->pquery($query, $params);
     $modulePermission = array();
     $noOfFields = $adb->num_rows($result);
     for ($i = 0; $i < $noOfFields; ++$i) {
         $row = $adb->query_result_rowdata($result, $i);
         $modulePermission[$row['fieldid']] = $row['visible'];
     }
     Vtiger_Cache::set('modulePermission-' . $accessmode, $tabid, $modulePermission);
     return $modulePermission;
 }
示例#20
0
 static function lookupEntityNameInfo($module)
 {
     $entityNames = Vtiger_Cache::get('EntityInfo', $module);
     if ($entityNames) {
         return $entityNames;
     } else {
         if (isset(self::$_module_entityname_cache[$module])) {
             return self::$_module_entityname_cache[$module];
         }
     }
     return false;
 }
示例#21
0
 /**
  * Function to get the user if of the active admin user.
  * @return Integer - Active Admin User ID
  */
 public static function getActiveAdminId()
 {
     $adb = PearDatabase::getInstance();
     $cache = Vtiger_Cache::getInstance();
     if ($cache->getAdminUserId()) {
         return $cache->getAdminUserId();
     } else {
         $sql = "SELECT id FROM vtiger_users WHERE is_admin = 'on' AND status = 'Active' limit 1";
         $result = $adb->pquery($sql, array());
         $adminId = 1;
         $it = new SqlResultIterator($adb, $result);
         foreach ($it as $row) {
             $adminId = $row->id;
         }
         $cache->setAdminUserId($adminId);
         return $adminId;
     }
 }
示例#22
0
 public static function getAssignedToGroupList($module)
 {
     $cache = Vtiger_Cache::getInstance();
     if ($cache->getGroupList($module, $current_user->id)) {
         return $cache->getGroupList($module, $current_user->id);
     } else {
         $groupList = get_group_array(FALSE, "Active", $current_user->id);
         $cache->setGroupList($module, $groupList, $current_user->id);
         return $groupList;
     }
 }
示例#23
0
/**
	 * Function to get Creator of this record
	 * @param <Integer> $recordId
	 * @return <Integer>
	 */
	public static function getCreator($recordId) {
		$cache = Vtiger_Cache::getInstance();
		if ($cache->hasCreator($recordId)) {
			return $cache->getCreator($recordId);
		}

		$db = PearDatabase::getInstance();
		$result = $db->pquery('SELECT smcreatorid FROM vtiger_crmentity WHERE crmid = ?', array($recordId));
		$creatorId = $db->query_result($result, 0, 'smcreatorid');

		if ($creatorId) {
			$cache->setCreator($recordId, $creatorId);
		}
		return $creatorId;
	}
示例#24
0
 public function setAdminUserId($userId)
 {
     if (self::$cacheEnable) {
         self::$_admin_user_id = $userId;
     }
 }
/**
 * this function returns all the assigned picklist values for the given tablename for the given roleid
 * @param string $tableName - the picklist tablename
 * @param integer $roleid - the roleid of the role for which you want data
 * @param object $adb - the peardatabase object
 * @return array $val - the assigned picklist values in array format
 */
function getAssignedPicklistValues($tableName, $roleid, $adb, $lang = array())
{
    $cache = Vtiger_Cache::getInstance();
    if ($cache->hasAssignedPicklistValues($tableName, $roleid)) {
        return $cache->getAssignedPicklistValues($tableName, $roleid);
    } else {
        $arr = array();
        $sql = "select picklistid from vtiger_picklist where name = ?";
        $result = $adb->pquery($sql, array($tableName));
        if ($adb->num_rows($result)) {
            $picklistid = $adb->query_result($result, 0, "picklistid");
            $sub = getSubordinateRoleAndUsers($roleid);
            $subRoles = array($roleid);
            $subRoles = array_merge($subRoles, array_keys($sub));
            $roleids = array();
            foreach ($subRoles as $role) {
                $roleids[] = $role;
            }
            $sql = "SELECT distinct " . $adb->sql_escape_string($tableName) . " FROM " . $adb->sql_escape_string("vtiger_{$tableName}") . " inner join vtiger_role2picklist on " . $adb->sql_escape_string("vtiger_{$tableName}") . ".picklist_valueid=vtiger_role2picklist.picklistvalueid" . " and roleid in (" . generateQuestionMarks($roleids) . ") order by sortid";
            $result = $adb->pquery($sql, $roleids);
            $count = $adb->num_rows($result);
            if ($count) {
                while ($resultrow = $adb->fetch_array($result)) {
                    $pick_val = decode_html($resultrow[$tableName]);
                    if ($lang[$pick_val] != '') {
                        $arr[$pick_val] = $lang[$pick_val];
                    } else {
                        $arr[$pick_val] = $pick_val;
                    }
                }
            }
        }
        // END
        $cache->setAssignedPicklistValues($tableName, $roleid, $arr);
        return $arr;
    }
}
示例#26
0
 /**
  * Function to get visibilty permissions of a Field
  * @param <String> $accessmode
  * @return <Boolean>
  */
 public function getPermissions($accessmode = 'readonly')
 {
     $user = Users_Record_Model::getCurrentUserModel();
     $privileges = $user->getPrivileges();
     if ($privileges->hasGlobalReadPermission()) {
         return true;
     } else {
         $modulePermission = Vtiger_Cache::get('modulePermission-' . $accessmode, $this->getModuleId());
         if (!$modulePermission) {
             $modulePermissionCalendar = self::preFetchModuleFieldPermission(Vtiger_Functions::getModuleId('Calendar'), $accessmode);
             $modulePermissionEvents = self::preFetchModuleFieldPermission(Vtiger_Functions::getModuleId('Events'), $accessmode);
             $modulePermission = $modulePermissionCalendar + $modulePermissionEvents;
             Vtiger_Cache::set('modulePermission-' . $accessmode, $this->getModuleId(), $modulePermission);
         }
         if (array_key_exists($this->getId(), $modulePermission)) {
             return true;
         } else {
             return false;
         }
     }
 }
示例#27
0
 /**
  * Function returns the instance of Folder model
  * @return <Reports_Folder_Model>
  */
 public static function getAll()
 {
     $db = PearDatabase::getInstance();
     $folders = Vtiger_Cache::get('reports', 'folders');
     if (!$folders) {
         $folders = array();
         $result = $db->pquery("SELECT * FROM vtiger_reportfolder ORDER BY foldername ASC", array());
         $noOfFolders = $db->num_rows($result);
         if ($noOfFolders > 0) {
             for ($i = 0; $i < $noOfFolders; $i++) {
                 $folderModel = Reports_Folder_Model::getInstance();
                 $values = $db->query_result_rowdata($result, $i);
                 $folders[$values['folderid']] = $folderModel->setData($values);
                 Vtiger_Cache::set('reportsFolder', $values['folderid'], $folderModel);
             }
         }
         Vtiger_Cache::set('reports', 'folders', $folders);
     }
     return $folders;
 }
示例#28
0
/** Function to get the Group Id for a given group groupname
 *  @param $groupname -- Groupname
 *  @returns Group Id -- Type Integer
 */
function getGrpId($groupname)
{
    $log = vglobal('log');
    $log->debug("Entering getGrpId(" . $groupname . ") method ...");
    $adb = PearDatabase::getInstance();
    $groupid = Vtiger_Cache::get('group', $groupname);
    if (!$groupid && $groupid !== 0) {
        $result = $adb->pquery("select groupid from vtiger_groups where groupname=?", array($groupname));
        $groupid = $adb->num_rows($result) > 0 ? $adb->query_result($result, 0, 'groupid') : 0;
        Vtiger_Cache::set('group', $groupname, $groupid);
    }
    $log->debug("Exiting getGrpId method ...");
    return $groupid;
}
示例#29
0
 /**
  * Get field name for the module taxes
  * @param string $moduleName Module name
  * @return string Tax field name
  */
 public function getTaxField($moduleName)
 {
     $cache = Vtiger_Cache::get('InventoryIsGetTaxField', $moduleName);
     if ($cache) {
         return $cache;
     }
     $return = false;
     if ($moduleName == '') {
         return $return;
     }
     $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
     foreach ($moduleModel->getFields() as $fieldName => $fieldModel) {
         if ($fieldModel->get('uitype') == 303) {
             $return = $fieldName;
             continue;
         }
     }
     Vtiger_Cache::set('InventoryIsGetTaxField', $moduleName, $return);
     return $return;
 }
示例#30
0
 public function transformForImport($fieldData, $moduleMeta, $fillDefault = true, $checkMandatoryFieldValues = true)
 {
     $moduleFields = $moduleMeta->getModuleFields();
     $defaultFieldValues = $this->getDefaultFieldValues($moduleMeta);
     foreach ($fieldData as $fieldName => $fieldValue) {
         $fieldInstance = $moduleFields[$fieldName];
         if ($fieldInstance->getFieldDataType() == 'owner') {
             $ownerId = getUserId_Ol(trim($fieldValue));
             if (empty($ownerId)) {
                 $ownerId = getGrpId($fieldValue);
             }
             if (empty($ownerId) && isset($defaultFieldValues[$fieldName])) {
                 $ownerId = $defaultFieldValues[$fieldName];
             }
             if (empty($ownerId) || !Import_Utils_Helper::hasAssignPrivilege($moduleMeta->getEntityName(), $ownerId)) {
                 $ownerId = $this->user->id;
             }
             $fieldData[$fieldName] = $ownerId;
         } elseif ($fieldInstance->getFieldDataType() == 'multipicklist') {
             $trimmedValue = trim($fieldValue);
             if (!$trimmedValue && isset($defaultFieldValues[$fieldName])) {
                 $explodedValue = explode(',', $defaultFieldValues[$fieldName]);
             } else {
                 $explodedValue = explode(' |##| ', $trimmedValue);
             }
             foreach ($explodedValue as $key => $value) {
                 $explodedValue[$key] = trim($value);
             }
             $implodeValue = implode(' |##| ', $explodedValue);
             $fieldData[$fieldName] = $implodeValue;
         } elseif ($fieldInstance->getFieldDataType() == 'reference') {
             $entityId = false;
             if (!empty($fieldValue)) {
                 if (strpos($fieldValue, '::::') > 0) {
                     $fieldValueDetails = explode('::::', $fieldValue);
                 } else {
                     if (strpos($fieldValue, ':::') > 0) {
                         $fieldValueDetails = explode(':::', $fieldValue);
                     } else {
                         $fieldValueDetails = $fieldValue;
                     }
                 }
                 if (count($fieldValueDetails) > 1) {
                     $referenceModuleName = trim($fieldValueDetails[0]);
                     $entityLabel = trim($fieldValueDetails[1]);
                     $entityId = getEntityId($referenceModuleName, $entityLabel);
                 } else {
                     $referencedModules = $fieldInstance->getReferenceList();
                     $entityLabel = $fieldValue;
                     foreach ($referencedModules as $referenceModule) {
                         $referenceModuleName = $referenceModule;
                         if ($referenceModule == 'Users') {
                             $referenceEntityId = getUserId_Ol($entityLabel);
                             if (empty($referenceEntityId) || !Import_Utils_Helper::hasAssignPrivilege($moduleMeta->getEntityName(), $referenceEntityId)) {
                                 $referenceEntityId = $this->user->id;
                             }
                         } elseif ($referenceModule == 'Currency') {
                             $referenceEntityId = getCurrencyId($entityLabel);
                         } else {
                             $referenceEntityId = getEntityId($referenceModule, $entityLabel);
                         }
                         if ($referenceEntityId != 0) {
                             $entityId = $referenceEntityId;
                             break;
                         }
                     }
                 }
                 if ((empty($entityId) || $entityId == 0) && !empty($referenceModuleName)) {
                     if (isPermitted($referenceModuleName, 'EditView') == 'yes') {
                         try {
                             $wsEntityIdInfo = $this->createEntityRecord($referenceModuleName, $entityLabel);
                             $wsEntityId = $wsEntityIdInfo['id'];
                             $entityIdComponents = vtws_getIdComponents($wsEntityId);
                             $entityId = $entityIdComponents[1];
                         } catch (Exception $e) {
                             $entityId = false;
                         }
                     }
                 }
                 $fieldData[$fieldName] = $entityId;
             } else {
                 $referencedModules = $fieldInstance->getReferenceList();
                 if ($referencedModules[0] == 'Users') {
                     if (isset($defaultFieldValues[$fieldName])) {
                         $fieldData[$fieldName] = $defaultFieldValues[$fieldName];
                     }
                     if (empty($fieldData[$fieldName]) || !Import_Utils_Helper::hasAssignPrivilege($moduleMeta->getEntityName(), $fieldData[$fieldName])) {
                         $fieldData[$fieldName] = $this->user->id;
                     }
                 } else {
                     $fieldData[$fieldName] = '';
                 }
             }
         } elseif ($fieldInstance->getFieldDataType() == 'picklist') {
             $fieldValue = trim($fieldValue);
             global $default_charset;
             if (empty($fieldValue) && isset($defaultFieldValues[$fieldName])) {
                 $fieldData[$fieldName] = $fieldValue = $defaultFieldValues[$fieldName];
             }
             $olderCacheEnable = Vtiger_Cache::$cacheEnable;
             Vtiger_Cache::$cacheEnable = false;
             if (!isset($this->allPicklistValues[$fieldName])) {
                 $this->allPicklistValues[$fieldName] = $fieldInstance->getPicklistDetails();
             }
             $allPicklistDetails = $this->allPicklistValues[$fieldName];
             $allPicklistValues = array();
             foreach ($allPicklistDetails as $picklistDetails) {
                 $allPicklistValues[] = $picklistDetails['value'];
             }
             $picklistValueInLowerCase = strtolower(htmlentities($fieldValue, ENT_QUOTES, $default_charset));
             $allPicklistValuesInLowerCase = array_map('strtolower', $allPicklistValues);
             $picklistDetails = array_combine($allPicklistValuesInLowerCase, $allPicklistValues);
             if (!in_array($picklistValueInLowerCase, $allPicklistValuesInLowerCase)) {
                 $moduleObject = Vtiger_Module::getInstance($moduleMeta->getEntityName());
                 $fieldObject = Vtiger_Field::getInstance($fieldName, $moduleObject);
                 $fieldObject->setPicklistValues(array($fieldValue));
                 unset($this->allPicklistValues[$fieldName]);
             } else {
                 $fieldData[$fieldName] = $picklistDetails[$picklistValueInLowerCase];
             }
             Vtiger_Cache::$cacheEnable = $olderCacheEnable;
         } else {
             if ($fieldInstance->getFieldDataType() == 'currency') {
                 // While exporting we are exporting as user format, we should import as db format while importing
                 $fieldData[$fieldName] = CurrencyField::convertToDBFormat($fieldValue, $current_user, false);
             } else {
                 if ($fieldInstance->getFieldDataType() == 'datetime' && !empty($fieldValue)) {
                     if ($fieldValue == null || $fieldValue == '0000-00-00 00:00:00') {
                         $fieldValue = '';
                     }
                     $valuesList = explode(' ', $fieldValue);
                     if (count($valuesList) == 1) {
                         $fieldValue = '';
                     }
                     $fieldValue = getValidDBInsertDateTimeValue($fieldValue);
                     if (preg_match("/^[0-9]{2,4}[-][0-1]{1,2}?[0-9]{1,2}[-][0-3]{1,2}?[0-9]{1,2} ([0-1][0-9]|[2][0-3])([:][0-5][0-9]){1,2}\$/", $fieldValue) == 0) {
                         $fieldValue = '';
                     }
                     $fieldData[$fieldName] = $fieldValue;
                 }
                 if ($fieldInstance->getFieldDataType() == 'date' && !empty($fieldValue)) {
                     if ($fieldValue == null || $fieldValue == '0000-00-00') {
                         $fieldValue = '';
                     }
                     $fieldValue = getValidDBInsertDateValue($fieldValue);
                     if (preg_match("/^[0-9]{2,4}[-][0-1]{1,2}?[0-9]{1,2}[-][0-3]{1,2}?[0-9]{1,2}\$/", $fieldValue) == 0) {
                         $fieldValue = '';
                     }
                     $fieldData[$fieldName] = $fieldValue;
                 }
                 if (empty($fieldValue) && isset($defaultFieldValues[$fieldName])) {
                     $fieldData[$fieldName] = $fieldValue = $defaultFieldValues[$fieldName];
                 }
             }
         }
     }
     if ($fillDefault) {
         foreach ($defaultFieldValues as $fieldName => $fieldValue) {
             if (!isset($fieldData[$fieldName])) {
                 $fieldData[$fieldName] = $defaultFieldValues[$fieldName];
             }
         }
     }
     // We should sanitizeData before doing final mandatory check below.
     $fieldData = DataTransform::sanitizeData($fieldData, $moduleMeta);
     if ($fieldData != null && $checkMandatoryFieldValues) {
         foreach ($moduleFields as $fieldName => $fieldInstance) {
             if (empty($fieldData[$fieldName]) && $fieldInstance->isMandatory()) {
                 return null;
             }
         }
     }
     return $fieldData;
 }