/** * 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; } }
/** * 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; } }
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; } }
/** * 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; } }
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; } }
/** * 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; }
/** * 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; } }
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; } }
/** * Function which will give the non editable picklist values for a field * @param type $fieldName -- string * @return type -- array of values */ public static function getNonEditablePicklistValues($fieldName) { $cache = Vtiger_Cache::getInstance(); $NonEditablePicklistValues = $cache->get('NonEditablePicklistValues', $fieldName); if ($NonEditablePicklistValues) { return $NonEditablePicklistValues; } $db = PearDatabase::getInstance(); $query = "select {$fieldName} from vtiger_{$fieldName} where presence=0"; $values = array(); $result = $db->pquery($query, array()); $num_rows = $db->num_rows($result); for ($i = 0; $i < $num_rows; $i++) { //Need to decode the picklist values twice which are saved from old ui $values[] = decode_html(decode_html($db->query_result($result, $i, $fieldName))); } $cache->set('NonEditablePicklistValues', $fieldName, $values); return $values; }
/** * Function to get Creator of this record * @param <Integer> $recordId * @return <Integer> */ public static function getCreator($recordId) { global $log; $log->debug("Entering ./helpers/Util.php::staticgetCreator"); $cache = Vtiger_Cache::getInstance(); if ($cache->hasCreator($recordId)) { $log->debug("Exiting ./helpers/Util.php::staticgetCreator"); 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); } $log->debug("Exiting ./helpers/Util.php::staticgetCreator"); return $creatorId; }
/** * 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, true) . ' FROM ' . $adb->sql_escape_string("vtiger_{$tableName}", true) . ' inner join vtiger_role2picklist on ' . $adb->sql_escape_string("vtiger_{$tableName}", true) . '.picklist_valueid=vtiger_role2picklist.picklistvalueid' . ' and roleid in (' . $adb->generateQuestionMarks($roleids) . ') order by sortid'; $result = $adb->pquery($sql, $roleids); $count = $adb->num_rows($result); if ($count) { while ($resultrow = $adb->fetch_array($result)) { /** Earlier we used to save picklist values by encoding it. Now, we are directly saving those(getRaw()). * If value in DB is like "test1 & test2" then $abd->fetch_array() is giving it as * "test1 &$amp; test2" which we should decode two time to get result */ $pick_val = decode_html(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; } }
/** * Function which will give the non editable picklist values for a field * @param type $fieldName -- string * @return type -- array of values */ public static function getNonEditablePicklistValues($fieldName) { $cache = Vtiger_Cache::getInstance(); $NonEditablePicklistValues = $cache->get('NonEditablePicklistValues', $fieldName); if ($NonEditablePicklistValues) { return $NonEditablePicklistValues; } $db = PearDatabase::getInstance(); //SalesPlatform.ru begin fix picklist value unique id cretation $primaryKey = Vtiger_Util_Helper::getPickListId($fieldName); $query = "select {$primaryKey} ,{$fieldName} from vtiger_{$fieldName} where presence=0"; //$query = "select $fieldName from vtiger_$fieldName where presence=0"; //SalesPlatform.ru end $values = array(); $result = $db->pquery($query, array()); $num_rows = $db->num_rows($result); for ($i = 0; $i < $num_rows; $i++) { //Need to decode the picklist values twice which are saved from old ui //SalesPlatform.ru begin fix picklist value unique id cretation $values[$db->query_result($result, $i, $primaryKey)] = decode_html(decode_html($db->query_result($result, $i, $fieldName))); //$values[] = decode_html(decode_html($db->query_result($result,$i,$fieldName))); //SalesPlatform.ru end } $cache->set('NonEditablePicklistValues', $fieldName, $values); return $values; }