示例#1
0
    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;
    }
示例#2
0
/** 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('&lt;', '&gt;', '&quot;'), $string);
        }
        VTCacheUtils::updateCachedInformation('to_html::' . $key, $string);
    }
    return $string;
}
示例#3
0
 // Sorting
 if (!empty($order_by)) {
     if ($order_by == 'smownerid') {
         $list_query .= ' ORDER BY user_name ' . $sorder;
     } else {
         $tablename = getTableNameForField($currentModule, $order_by);
         $tablename = $tablename != '' ? $tablename . '.' : '';
         $list_query .= ' ORDER BY ' . $tablename . $order_by . ' ' . $sorder;
     }
 }
 if (GlobalVariable::getVariable('Debug_ListView_Query', '0') == '1') {
     echo '<br>' . $list_query . '<br>';
 }
 try {
     if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true) {
         list($specialPermissionWithDuplicateRows, $cached) = VTCacheUtils::lookupCachedInformation('SpecialPermissionWithDuplicateRows');
         if ($specialPermissionWithDuplicateRows) {
             $count_result = $adb->query(mkCountWithFullQuery($list_query));
         } else {
             $count_result = $adb->query(mkCountQuery($list_query));
         }
         $noofrows = $adb->query_result($count_result, 0, "count");
     } else {
         $noofrows = null;
     }
     $queryMode = isset($_REQUEST['query']) && $_REQUEST['query'] == 'true';
     $start = ListViewSession::getRequestCurrentPage($currentModule, $list_query, $viewid, $queryMode);
     $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows);
     $limit_start_rec = ($start - 1) * $list_max_entries_per_page;
     $list_result = $adb->pquery($list_query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array());
 } catch (Exception $e) {
示例#4
0
/** Function to get related list entries in detailed array format
 * @param $module -- modulename:: Type string
 * @param $relatedmodule -- relatedmodule:: Type string
 * @param $focus -- focus:: Type object
 * @param $query -- query:: Type string
 * @param $button -- buttons:: Type string
 * @param $returnset -- returnset:: Type string
 * @param $id -- id:: Type string
 * @param $edit_val -- edit value:: Type string
 * @param $del_val -- delete value:: Type string
 * @returns $related_entries -- related entires:: Type string array
 */
function GetRelatedListBase($module, $relatedmodule, $focus, $query, $button, $returnset, $id = '', $edit_val = '', $del_val = '', $skipActions = false)
{
    $log = LoggerManager::getLogger('account_list');
    $log->debug("Entering GetRelatedList(" . $module . "," . $relatedmodule . "," . get_class($focus) . "," . $query . "," . $button . "," . $returnset . "," . $edit_val . "," . $del_val . ") method ...");
    global $GetRelatedList_ReturnOnlyQuery;
    if (isset($GetRelatedList_ReturnOnlyQuery) and $GetRelatedList_ReturnOnlyQuery) {
        return array('query' => $query);
    }
    require_once 'Smarty_setup.php';
    require_once "data/Tracker.php";
    require_once 'include/database/PearDatabase.php';
    global $adb, $app_strings, $current_language;
    $current_module_strings = return_module_language($current_language, $module);
    global $list_max_entries_per_page, $urlPrefix, $currentModule, $theme, $theme_path, $theme_path, $mod_strings;
    $smarty = new vtigerCRM_Smarty();
    if (!isset($where)) {
        $where = "";
    }
    $button = '<table cellspacing=0 cellpadding=2><tr><td>' . $button . '</td></tr></table>';
    // Added to have Purchase Order as form Title
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    $smarty->assign("MOD", $mod_strings);
    $smarty->assign("APP", $app_strings);
    $smarty->assign("THEME", $theme);
    $smarty->assign("IMAGE_PATH", $image_path);
    $smarty->assign("MODULE", $relatedmodule);
    // We do not have RelatedListView in Detail View mode of Calendar module. So need to skip it.
    if ($module != 'Calendar') {
        $focus->initSortByField($relatedmodule);
    }
    // Append security parameter
    if ($relatedmodule != 'Users') {
        global $current_user;
        $secQuery = getNonAdminAccessControlQuery($relatedmodule, $current_user);
        if (strlen($secQuery) > 1) {
            $query = appendFromClauseToQuery($query, $secQuery);
        }
    }
    if ($relatedmodule == 'Leads') {
        $query .= " AND vtiger_leaddetails.converted = 0";
    }
    if (isset($where) && $where != '') {
        $query .= ' and ' . $where;
    }
    if (!$_SESSION['rlvs'][$module][$relatedmodule]) {
        $modObj = new ListViewSession();
        $modObj->sortby = $focus->default_order_by;
        $modObj->sorder = $focus->default_sort_order;
        $_SESSION['rlvs'][$module][$relatedmodule] = get_object_vars($modObj);
    }
    if (!empty($_REQUEST['order_by'])) {
        if (method_exists($focus, getSortOrder)) {
            $sorder = $focus->getSortOrder();
        }
        if (method_exists($focus, getOrderBy)) {
            $order_by = $focus->getOrderBy();
        }
        if (isset($order_by) && $order_by != '') {
            $_SESSION['rlvs'][$module][$relatedmodule]['sorder'] = $sorder;
            $_SESSION['rlvs'][$module][$relatedmodule]['sortby'] = $order_by;
        }
    } elseif ($_SESSION['rlvs'][$module][$relatedmodule]) {
        $sorder = $_SESSION['rlvs'][$module][$relatedmodule]['sorder'];
        $order_by = $_SESSION['rlvs'][$module][$relatedmodule]['sortby'];
    } else {
        $order_by = $focus->default_order_by;
        $sorder = $focus->default_sort_order;
    }
    // AssignedTo ordering issue in Related Lists
    $query_order_by = $order_by;
    if ($order_by == 'smownerid') {
        $userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users');
        $query_order_by = "case when (vtiger_users.user_name not like '') then {$userNameSql} else vtiger_groups.groupname end ";
    } elseif ($order_by != 'crmid' && !empty($order_by)) {
        $tabname = getTableNameForField($relatedmodule, $order_by);
        if ($tabname !== '' and $tabname != NULL) {
            $query_order_by = $tabname . "." . $query_order_by;
        }
    }
    if (!empty($query_order_by)) {
        $query .= ' ORDER BY ' . $query_order_by . ' ' . $sorder;
    }
    if ($relatedmodule == 'Calendar') {
        $mod_listquery = "activity_listquery";
    } else {
        $mod_listquery = strtolower($relatedmodule) . "_listquery";
    }
    $_SESSION[$mod_listquery] = $query;
    $url_qry = "&order_by=" . $order_by . "&sorder=" . $sorder;
    $computeCount = isset($_REQUEST['withCount']) ? $_REQUEST['withCount'] : '';
    if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true || (bool) $computeCount == true) {
        // Retreiving the no of rows
        list($specialPermissionWithDuplicateRows, $cached) = VTCacheUtils::lookupCachedInformation('SpecialPermissionWithDuplicateRows');
        if (FALSE and ($specialPermissionWithDuplicateRows or $relatedmodule == 'Calendar')) {
            // FIXME FIXME FIXME FIXME
            // the FALSE above MUST be eliminated, we need to execute mkCountWithFullQuery for modified queries
            // the problem is that related list queries are hardcoded and can (mostly do) repeat columns which is not supported as a
            // subquery which is what mkCountWithFullQuery does
            // This works on ListView because we use query generator that eliminates those repeated columns
            // It is currently incorrect and will produce wrong count on related lists when special permissions are active
            // FIXME FIXME FIXME FIXME
            // for calendar (with multiple contacts for single activity) and special permissions, count will change
            $count_result = $adb->query(mkCountWithFullQuery($query));
        } else {
            $count_result = $adb->query(mkCountQuery($query));
        }
        $noofrows = $adb->query_result($count_result, 0, 'count');
    } else {
        $noofrows = null;
    }
    //Setting Listview session object while sorting/pagination
    if (isset($_REQUEST['relmodule']) && $_REQUEST['relmodule'] != '' && $_REQUEST['relmodule'] == $relatedmodule) {
        $relmodule = vtlib_purify($_REQUEST['relmodule']);
        if ($_SESSION['rlvs'][$module][$relmodule]) {
            setSessionVar($_SESSION['rlvs'][$module][$relmodule], $noofrows, $list_max_entries_per_page, $module, $relmodule);
        }
    }
    global $relationId;
    $start = RelatedListViewSession::getRequestCurrentPage($relationId, $query);
    $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows);
    $limit_start_rec = ($start - 1) * $list_max_entries_per_page;
    $list_result = $adb->pquery($query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array());
    /* Save the related list in session for when we click in a register
     * from this list we will can navigate with the arrows left and right, to move only in this related list
     */
    $relcv = new CustomView();
    $relviewId = $relcv->getViewId($relatedmodule);
    ListViewSession::setSessionQuery($relatedmodule, $query, $relviewId);
    $_SESSION['lvs'][$relatedmodule][$relviewId]['start'] = $start;
    //Retreive the List View Table Header
    $id = vtlib_purify($_REQUEST['record']);
    $listview_header = getListViewHeader($focus, $relatedmodule, '', $sorder, $order_by, $id, '', $module, $skipActions);
    //"Accounts");
    if ($noofrows > 15) {
        $smarty->assign('SCROLLSTART', '<div style="overflow:auto;height:315px;width:100%;">');
        $smarty->assign('SCROLLSTOP', '</div>');
    }
    $smarty->assign("LISTHEADER", $listview_header);
    if ($module == 'PriceBook' && $relatedmodule == 'Products') {
        $listview_entries = getListViewEntries($focus, $relatedmodule, $list_result, $navigation_array, 'relatedlist', $returnset, $edit_val, $del_val, '', '', '', '', $skipActions);
    }
    if ($module == 'Products' && $relatedmodule == 'PriceBooks') {
        $listview_entries = getListViewEntries($focus, $relatedmodule, $list_result, $navigation_array, 'relatedlist', $returnset, 'EditListPrice', 'DeletePriceBookProductRel', '', '', '', '', $skipActions);
    } elseif ($relatedmodule == 'SalesOrder') {
        $listview_entries = getListViewEntries($focus, $relatedmodule, $list_result, $navigation_array, 'relatedlist', $returnset, 'SalesOrderEditView', 'DeleteSalesOrder', '', '', '', '', $skipActions);
    } else {
        $listview_entries = getListViewEntries($focus, $relatedmodule, $list_result, $navigation_array, 'relatedlist', $returnset, $edit_val, $del_val, '', '', '', '', $skipActions);
    }
    $navigationOutput = array();
    $navigationOutput[] = getRecordRangeMessage($list_result, $limit_start_rec, $noofrows);
    if (empty($id) && !empty($_REQUEST['record'])) {
        $id = vtlib_purify($_REQUEST['record']);
    }
    $navigationOutput[] = getRelatedTableHeaderNavigation($navigation_array, $url_qry, $module, $relatedmodule, $id);
    $related_entries = array('header' => $listview_header, 'entries' => $listview_entries, 'navigation' => $navigationOutput);
    $log->debug("Exiting GetRelatedList method ...");
    return $related_entries;
}
示例#5
0
 public function getQuery($distinct = false)
 {
     if (empty($this->query)) {
         $conditionedReferenceFields = array();
         $allFields = array_merge($this->whereFields, $this->fields);
         foreach ($allFields as $fieldName) {
             if (in_array($fieldName, $this->referenceFieldList)) {
                 $moduleList = $this->referenceFieldInfoList[$fieldName];
                 foreach ($moduleList as $module) {
                     if (empty($this->moduleNameFields[$module])) {
                         $meta = $this->getMeta($module);
                     }
                 }
             } elseif (in_array($fieldName, $this->ownerFields)) {
                 $meta = $this->getMeta('Users');
                 $meta = $this->getMeta('Groups');
             }
         }
         $query = $this->getSelectClauseColumnSQL();
         $query .= $this->getFromClause();
         $query .= $this->getWhereClause();
         list($specialPermissionWithDuplicateRows, $cached) = VTCacheUtils::lookupCachedInformation('SpecialPermissionWithDuplicateRows');
         $query = 'SELECT ' . (($distinct or $specialPermissionWithDuplicateRows) ? 'DISTINCT ' : '') . $query;
         $this->query = $query;
         return $query;
     } else {
         return $this->query;
     }
 }