/** Function to convert the given string to html * @param $string -- string:: Type string * @returns $string -- string:: Type string */ function to_html($string) { global $doconvert, $default_charset; if ($doconvert == true) { list($cachedresult, $found) = VTCacheUtils::lookupCachedInformation('to_html::' . $string); if ($found) { return $cachedresult; } $key = $string; if ($default_charset == 'UTF-8') { $string = htmlentities($string, ENT_QUOTES, $default_charset); } else { $string = preg_replace(array('/</', '/>/', '/"/'), array('<', '>', '"'), $string); } VTCacheUtils::updateCachedInformation('to_html::' . $key, $string); } return $string; }
public static function getVariable($var, $default, $module = '', $gvuserid = '') { global $adb, $current_user, $gvvalidationinfo, $currentModule; $gvvalidationinfo[] = "search for variable '{$var}' with default value of '{$default}'"; if (empty($module)) { $module = $currentModule; } if (empty($gvuserid)) { $gvuserid = $current_user->id; } $key = md5('gvcache' . $var . $module . $gvuserid); list($value, $found) = VTCacheUtils::lookupCachedInformation($key); if ($found) { $gvvalidationinfo[] = "variable found in cache"; return $value; } $value = ''; $list_of_modules = array(); $focus = CRMEntity::getInstance('GlobalVariable'); $select = 'SELECT * FROM vtiger_globalvariable INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_globalvariable.globalvariableid '; $where = ' where vtiger_crmentity.deleted=0 and gvname=? '; $mandatory = " and mandatory='1'"; $sql = $select . $where . $mandatory; $gvvalidationinfo[] = '---'; $value = $focus->return_global_var_value($sql, $var, $module); $gvvalidationinfo[] = "search as mandatory in module {$module}: {$value}"; if ($value != '') { VTCacheUtils::updateCachedInformation($key, $value); return $value; } if (!is_numeric($gvuserid) and $gvuserid > 0) { return $default; } $user = $adb->convert2Sql(' and vtiger_crmentity.smownerid=?', array($gvuserid)); $sql = $select . $where . $user; $gvvalidationinfo[] = '---'; $value = $focus->return_global_var_value($sql, $var, $module); $gvvalidationinfo[] = "search as set per user {$gvuserid} in module {$module}: {$value}"; if ($value != '') { VTCacheUtils::updateCachedInformation($key, $value); return $value; } $gvvalidationinfo[] = '---'; require_once 'include/utils/GetUserGroups.php'; $UserGroups = new GetUserGroups(); $UserGroups->getAllUserGroups($gvuserid); if (count($UserGroups->user_groups) > 0) { $groups = implode(',', $UserGroups->user_groups); $group = ' and vtiger_crmentity.smownerid in (' . $groups . ') '; $sql = $select . $where . $group; $value = $focus->return_global_var_value($sql, $var, $module); $gvvalidationinfo[] = "search as set per group {$groups} in module {$module}: {$value}"; if ($value != '') { VTCacheUtils::updateCachedInformation($key, $value); return $value; } } else { $gvvalidationinfo[] = 'no groups to search in'; } $sql = $select . $where . " and default_check='1'"; $gvvalidationinfo[] = '---'; $value = $focus->return_global_var_value($sql, $var, $module); $gvvalidationinfo[] = "search as default variable in module {$module}: {$value}"; if ($value != '') { VTCacheUtils::updateCachedInformation($key, $value); return $value; } $gvvalidationinfo[] = '---'; $gvvalidationinfo[] = "return default value give: {$default}"; return $default; }
/** * * @param String $module - module name for which query needs to be generated. * @param Users $user - user for which query needs to be generated. * @return String Access control Query for the user. */ function getNonAdminAccessControlQuery($module, $user, $scope = '') { require 'user_privileges/user_privileges_' . $user->id . '.php'; require 'user_privileges/sharing_privileges_' . $user->id . '.php'; $query = ' '; $tabId = getTabid($module); if ($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $defaultOrgSharingPermission[$tabId] == 3) { $tableName = 'vt_tmp_u' . $user->id; $sharingRuleInfoVariable = $module . '_share_read_permission'; $sharingRuleInfo = ${$sharingRuleInfoVariable}; $sharedTabId = null; if (!empty($sharingRuleInfo) && (count($sharingRuleInfo['ROLE']) > 0 || count($sharingRuleInfo['GROUP']) > 0)) { $tableName = $tableName . '_t' . $tabId; $sharedTabId = $tabId; } elseif ($module == 'Calendar' || !empty($scope)) { $tableName .= '_t' . $tabId; } list($tsSpecialAccessQuery, $typeOfPermissionOverride, $unused1, $unused2) = cbEventHandler::do_filter('corebos.permissions.accessquery', array(' ', 'none', $module, $user)); if ($typeOfPermissionOverride == 'fullOverride') { // create the default temporary table in case it is needed $this->setupTemporaryTable($tableName, $sharedTabId, $user, $current_user_parent_role_seq, $current_user_groups); VTCacheUtils::updateCachedInformation('SpecialPermissionWithDuplicateRows', true); return $tsSpecialAccessQuery; } if ($typeOfPermissionOverride == 'none' or trim($tsSpecialAccessQuery) == '') { $this->setupTemporaryTable($tableName, $sharedTabId, $user, $current_user_parent_role_seq, $current_user_groups); $query = " INNER JOIN {$tableName} {$tableName}{$scope} ON {$tableName}{$scope}.id = vtiger_crmentity{$scope}.smownerid "; } else { global $adb; VTCacheUtils::updateCachedInformation('SpecialPermissionWithDuplicateRows', true); $tsTableName = "tsolucio_tmp_u{$user->id}"; $adb->query("drop table if exists {$tsTableName}"); if ($typeOfPermissionOverride == 'addToUserPermission') { $query = $this->getNonAdminAccessQuery($module, $user, $current_user_parent_role_seq, $current_user_groups); $tsSpecialAccessQuery = "{$query} UNION ({$tsSpecialAccessQuery}) "; } $adb->query("create temporary table {$tsTableName} (id int primary key) as {$tsSpecialAccessQuery}"); if ($typeOfPermissionOverride == 'addToUserPermission') { $query = " INNER JOIN {$tsTableName} on ({$tsTableName}.id=vtiger_crmentity.crmid or {$tsTableName}.id = vtiger_crmentity{$scope}.smownerid) "; } else { // $typeOfPermissionOverride=='showTheseRecords' $query = " INNER JOIN {$tsTableName} on {$tsTableName}.id=vtiger_crmentity.crmid "; } } } return $query; }