示例#1
0
 protected function getKeyMetricsWithCount()
 {
     global $current_user, $adb;
     $current_user = Users_Record_Model::getCurrentUserModel();
     require_once 'modules/CustomView/ListViewTop.php';
     $metriclists = getMetricList();
     foreach ($metriclists as $key => $metriclist) {
         $metricresult = NULL;
         if ($metriclist['module'] == "Calendar") {
             $listquery = getListQuery($metriclist['module']);
             $oCustomView = new CustomView($metriclist['module']);
             $metricsql = $oCustomView->getModifiedCvListQuery($metriclist['id'], $listquery, $metriclist['module']);
             $metricresult = $adb->query(Vtiger_Functions::mkCountQuery($metricsql));
         } else {
             $queryGenerator = new QueryGenerator($metriclist['module'], $current_user);
             $queryGenerator->initForCustomViewById($metriclist['id']);
             $metricsql = $queryGenerator->getQuery();
             $metricresult = $adb->query(Vtiger_Functions::mkCountQuery($metricsql));
         }
         if ($metricresult) {
             $rowcount = $adb->fetch_array($metricresult);
             $metriclists[$key]['count'] = $rowcount['count'];
         }
     }
     return $metriclists;
 }
示例#2
0
 protected function getKeyMetricsWithCount()
 {
     global $log;
     $log->debug("Entering ./dashboards/KeyMetrics.php::getKeyMetricsWithCount");
     global $current_user, $adb;
     $current_user = Users_Record_Model::getCurrentUserModel();
     require_once 'modules/CustomView/ListViewTop.php';
     $metriclists = getMetricList();
     foreach ($metriclists as $key => $metriclist) {
         $metricresult = NULL;
         $queryGenerator = new QueryGenerator($metriclist['module'], $current_user);
         $queryGenerator->initForCustomViewById($metriclist['id']);
         if ($metriclist['module'] == "Calendar") {
             // For calendar we need to eliminate emails or else it will break in status empty condition
             $queryGenerator->addCondition('activitytype', "Emails", 'n', QueryGenerator::$AND);
         }
         $metricsql = $queryGenerator->getQuery();
         $metricresult = $adb->query(Vtiger_Functions::mkCountQuery($metricsql));
         if ($metricresult) {
             $rowcount = $adb->fetch_array($metricresult);
             $metriclists[$key]['count'] = $rowcount['count'];
         }
     }
     return $metriclists;
 }
 protected function getModuleFilterDetails($filterid)
 {
     global $adb;
     $result = $adb->pquery("SELECT * FROM vtiger_customview WHERE cvid=?", array($filterid));
     if ($result && $adb->num_rows($result)) {
         $resultrow = $adb->fetch_array($result);
         $module = $resultrow['entitytype'];
         $view = new CustomView($module);
         $viewid = $resultrow['cvid'];
         $view->getCustomViewByCvid($viewid);
         $viewQuery = $view->getModifiedCvListQuery($viewid, getListQuery($module), $module);
         $countResult = $adb->pquery(Vtiger_Functions::mkCountQuery($viewQuery), array());
         $count = 0;
         if ($countResult && $adb->num_rows($countResult)) {
             $count = $adb->query_result($countResult, 0, 'count');
         }
         $filter = $this->prepareFilterDetailUsingResultRow($resultrow);
         $filter['userName'] = getUserName($resultrow['userid']);
         $filter['count'] = $count;
         return $filter;
     }
 }
/**	Function to display the Products which are related to the PriceBook
 *	@param string $query - query to get the list of products which are related to the current PriceBook
 *	@param object $focus - PriceBook object which contains all the information of the current PriceBook
 *	@param string $returnset - return_module, return_action and return_id which are sequenced with & to pass to the URL which is optional
 *	return array $return_data which will be formed like array('header'=>$header,'entries'=>$entries_list) where as $header contains all the header columns and $entries_list will contain all the Product entries
 */
function getPriceBookRelatedProducts($query, $focus, $returnset = '')
{
    global $log;
    $log->debug("Entering getPriceBookRelatedProducts(" . $query . "," . get_class($focus) . "," . $returnset . ") method ...");
    global $adb;
    global $app_strings;
    global $mod_strings;
    global $current_language, $current_user;
    $current_module_strings = return_module_language($current_language, 'PriceBook');
    $no_of_decimal_places = getCurrencyDecimalPlaces();
    global $list_max_entries_per_page;
    global $urlPrefix;
    global $theme;
    $pricebook_id = vtlib_purify($_REQUEST['record']);
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    $computeCount = $_REQUEST['withCount'];
    if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true || (bool) $computeCount == true) {
        $noofrows = $adb->query_result($adb->query(Vtiger_Functions::mkCountQuery($query)), 0, 'count');
    } else {
        $noofrows = null;
    }
    $module = 'PriceBooks';
    $relatedmodule = 'Products';
    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 (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;
    if ($adb->dbType == "pgsql") {
        $list_result = $adb->pquery($query . " OFFSET {$limit_start_rec} LIMIT {$list_max_entries_per_page}", array());
    } else {
        $list_result = $adb->pquery($query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array());
    }
    $header = array();
    $header[] = $mod_strings['LBL_LIST_PRODUCT_NAME'];
    if (getFieldVisibilityPermission('Products', $current_user->id, 'productcode') == '0') {
        $header[] = $mod_strings['LBL_PRODUCT_CODE'];
    }
    if (getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0') {
        $header[] = $mod_strings['LBL_PRODUCT_UNIT_PRICE'];
    }
    $header[] = $mod_strings['LBL_PB_LIST_PRICE'];
    if (isPermitted("PriceBooks", "EditView", "") == 'yes' || isPermitted("PriceBooks", "Delete", "") == 'yes') {
        $header[] = $mod_strings['LBL_ACTION'];
    }
    $currency_id = $focus->column_fields['currency_id'];
    $numRows = $adb->num_rows($list_result);
    for ($i = 0; $i < $numRows; $i++) {
        $entity_id = $adb->query_result($list_result, $i, "crmid");
        $unit_price = $adb->query_result($list_result, $i, "unit_price");
        if ($currency_id != null) {
            $prod_prices = getPricesForProducts($currency_id, array($entity_id));
            $unit_price = $prod_prices[$entity_id];
        }
        $listprice = $adb->query_result($list_result, $i, "listprice");
        $field_name = $entity_id . "_listprice";
        $entries = array();
        $entries[] = textlength_check($adb->query_result($list_result, $i, "productname"));
        if (getFieldVisibilityPermission('Products', $current_user->id, 'productcode') == '0') {
            $entries[] = $adb->query_result($list_result, $i, "productcode");
        }
        if (getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0') {
            $entries[] = CurrencyField::convertToUserFormat($unit_price, null, true);
        }
        $entries[] = CurrencyField::convertToUserFormat($listprice, null, true);
        $action = "";
        if (isPermitted("PriceBooks", "EditView", "") == 'yes' && isPermitted('Products', 'EditView', $entity_id) == 'yes') {
            $action .= '<img style="cursor:pointer;" src="' . vtiger_imageurl('editfield.gif', $theme) . '" border="0" onClick="fnvshobj(this,\'editlistprice\'),editProductListPrice(\'' . $entity_id . '\',\'' . $pricebook_id . '\',\'' . number_format($listprice, $no_of_decimal_places, '.', '') . '\')" alt="' . $app_strings["LBL_EDIT_BUTTON"] . '" title="' . $app_strings["LBL_EDIT_BUTTON"] . '"/>';
        } else {
            $action .= '<img src="' . vtiger_imageurl('blank.gif', $theme) . '" border="0" />';
        }
        if (isPermitted("PriceBooks", "Delete", "") == 'yes' && isPermitted('Products', 'Delete', $entity_id) == 'yes') {
            if ($action != "") {
                $action .= '&nbsp;|&nbsp;';
            }
            $action .= '<img src="' . vtiger_imageurl('delete.gif', $theme) . '" onclick="if(confirm(\'' . $app_strings['ARE_YOU_SURE'] . '\')) deletePriceBookProductRel(' . $entity_id . ',' . $pricebook_id . ');" alt="' . $app_strings["LBL_DELETE"] . '" title="' . $app_strings["LBL_DELETE"] . '" style="cursor:pointer;" border="0">';
        }
        if ($action != "") {
            $entries[] = $action;
        }
        $entries_list[] = $entries;
    }
    $navigationOutput[] = getRecordRangeMessage($list_result, $limit_start_rec, $noofrows);
    $navigationOutput[] = getRelatedTableHeaderNavigation($navigation_array, '', $module, $relatedmodule, $focus->id);
    $return_data = array('header' => $header, 'entries' => $entries_list, 'navigation' => $navigationOutput);
    $log->debug("Exiting getPriceBookRelatedProducts method ...");
    return $return_data;
}
 function getRequestCurrentPage($currentModule, $query, $viewid, $queryMode = false)
 {
     global $list_max_entries_per_page, $adb;
     $start = 1;
     if (isset($_REQUEST['query']) && $_REQUEST['query'] == 'true' && $_REQUEST['start'] != "last") {
         return ListViewSession::getRequestStartPage();
     }
     if (!empty($_REQUEST['start'])) {
         $start = $_REQUEST['start'];
         if ($start == 'last') {
             $count_result = $adb->query(Vtiger_Functions::mkCountQuery($query));
             $noofrows = $adb->query_result($count_result, 0, "count");
             if ($noofrows > 0) {
                 $start = ceil($noofrows / $list_max_entries_per_page);
             }
         }
         if (!is_numeric($start)) {
             $start = 1;
         } elseif ($start < 1) {
             $start = 1;
         }
         $start = ceil($start);
     } else {
         if (!empty($_SESSION['lvs'][$currentModule][$viewid]['start'])) {
             $start = $_SESSION['lvs'][$currentModule][$viewid]['start'];
         }
     }
     if (!$queryMode) {
         $_SESSION['lvs'][$currentModule][$viewid]['start'] = intval($start);
     }
     return $start;
 }
示例#6
0
/** to get the details of a KeyMetrics on Home page 
* @returns  $customviewlist Array in the following format
* $values = Array('Title'=>Array(0=>'image name',
*				 1=>'Key Metrics',
*			 	 2=>'home_metrics'
*			 	),
*		  'Header'=>Array(0=>'Metrics',
*	  			  1=>'Count'
*			  	),
*		  'Entries'=>Array($cvid=>Array(
*			  			0=>$customview name,
*						1=>$no of records for the view
*					       ),
*				   $cvid=>Array(
*                                               0=>$customview name,
*                                               1=>$no of records for the view
*                                              ),
*					|
*					|
*				   $cvid=>Array(
*                                               0=>$customview name,
*                                               1=>$no of records for the view
*                                              )	
*				  )
*
*/
function getKeyMetrics($maxval, $calCnt)
{
    require_once "include/Tracker.php";
    require_once 'modules/CustomView/CustomView.php';
    require_once 'include/logging.php';
    require_once 'include/ListView/ListView.php';
    global $app_strings;
    $adb = PearDatabase::getInstance();
    $log = vglobal('log');
    $metricviewnames = "'Hot Leads'";
    $current_language = vglobal('current_language');
    $current_module_strings = return_module_language($current_language, "CustomView");
    $log = LoggerManager::getLogger('metrics');
    $metriclists = getMetricList();
    // Determine if the KeyMetrics widget should appear or not?
    if ($calCnt == 'calculateCnt') {
        return count($metriclists);
    }
    $log->info("Metrics :: Successfully got MetricList to be displayed");
    if (isset($metriclists)) {
        $current_user = vglobal('current_user');
        foreach ($metriclists as $key => $metriclist) {
            if ($metriclist['module'] == "Calendar") {
                $listquery = getListQuery($metriclist['module']);
                $oCustomView = new CustomView($metriclist['module']);
                $metricsql = $oCustomView->getModifiedCvListQuery($metriclist['id'], $listquery, $metriclist['module']);
                $metricsql = Vtiger_Functions::mkCountQuery($metricsql);
                $metricresult = $adb->query($metricsql);
                if ($metricresult) {
                    $rowcount = $adb->fetch_array($metricresult);
                    $metriclists[$key]['count'] = $rowcount['count'];
                }
            } else {
                $queryGenerator = new QueryGenerator($metriclist['module'], $current_user);
                $queryGenerator->initForCustomViewById($metriclist['id']);
                $metricsql = $queryGenerator->getQuery();
                $metricsql = Vtiger_Functions::mkCountQuery($metricsql);
                $metricresult = $adb->query($metricsql);
                if ($metricresult) {
                    $rowcount = $adb->fetch_array($metricresult);
                    $metriclists[$key]['count'] = $rowcount['count'];
                }
            }
        }
        $log->info("Metrics :: Successfully build the Metrics");
    }
    $title = array();
    $title[] = 'keyMetrics.gif';
    $title[] = $app_strings['LBL_HOME_KEY_METRICS'];
    $title[] = 'home_metrics';
    $header = array();
    $header[] = $app_strings['LBL_HOME_METRICS'];
    $header[] = $app_strings['LBL_MODULE'];
    $header[] = $app_strings['LBL_HOME_COUNT'];
    $entries = array();
    if (isset($metriclists)) {
        $oddRow = true;
        foreach ($metriclists as $metriclist) {
            $value = array();
            $CVname = strlen($metriclist['name']) > 20 ? substr($metriclist['name'], 0, 20) . '...' : $metriclist['name'];
            $value[] = '<a href="index.php?action=ListView&module=' . $metriclist['module'] . '&viewname=' . $metriclist['id'] . '">' . $CVname . '</a> <font style="color:#6E6E6E;">(' . $metriclist['user'] . ')</font>';
            $value[] = '<a href="index.php?action=ListView&module=' . $metriclist['module'] . '&viewname=' . $metriclist['id'] . '">' . getTranslatedString($metriclist['module']) . '</a>';
            $value[] = '<a href="index.php?action=ListView&module=' . $metriclist['module'] . '&viewname=' . $metriclist['id'] . '">' . $metriclist['count'] . '</a>';
            $entries[$metriclist['id']] = $value;
        }
    }
    $values = array('Title' => $title, 'Header' => $header, 'Entries' => $entries);
    if ($display_empty_home_blocks || count($value) != 0) {
        return $values;
    }
}
 public static function getRequestCurrentPage($relationId, $query)
 {
     global $list_max_entries_per_page, $adb;
     $start = 1;
     if (!empty($_REQUEST['start'])) {
         $start = $_REQUEST['start'];
         if ($start == 'last') {
             $count_result = $adb->query(Vtiger_Functions::mkCountQuery($query));
             $noofrows = $adb->query_result($count_result, 0, "count");
             if ($noofrows > 0) {
                 $start = ceil($noofrows / $list_max_entries_per_page);
             }
         }
         if (!is_numeric($start)) {
             $start = 1;
         } elseif ($start < 1) {
             $start = 1;
         }
         $start = ceil($start);
     } else {
         $start = RelatedListViewSession::getCurrentPage($relationId);
     }
     return $start;
 }
 function query()
 {
     $sql = Mobile_WS_Utils::getModuleListQuery('Potentials', "vtiger_potential.sales_stage not like 'Closed%' AND\n\t\t\t\t\tDATEDIFF(vtiger_potential.closingdate, CURDATE()) <= 5");
     return preg_replace("/^SELECT count\\(\\*\\) as count(.*)/i", "SELECT crmid \$1", Vtiger_Functions::mkCountQuery($sql));
 }
示例#9
0
 protected function countQuery()
 {
     return Vtiger_Functions::mkCountQuery($this->query());
 }
示例#10
0
 $queryGenerator->initForCustomViewById($viewid);
 // Enabling Module Search
 $url_string = '';
 if ($_REQUEST['query'] == 'true') {
     $queryGenerator->addUserSearchConditions($_REQUEST);
     $ustring = getSearchURL($_REQUEST);
     $url_string .= "&query=true{$ustring}";
     $smarty->assign('SEARCH_URL', $url_string);
 }
 $list_query = $queryGenerator->getQuery();
 $list_query = preg_replace("/vtiger_crmentity.deleted\\s*=\\s*0/i", 'vtiger_crmentity.deleted = 1', $list_query);
 //Search criteria added to the list Query
 if (isset($where) && $where != '') {
     $list_query .= ' AND ' . $where;
 }
 $count_result = $adb->query(Vtiger_Functions::mkCountQuery($list_query));
 $noofrows = $adb->query_result($count_result, 0, "count");
 $smarty->assign("NUMOFROWS", $noofrows);
 $controller = new ListViewController($adb, $current_user, $queryGenerator);
 $rb_listview_header = $controller->getListViewHeader($focus, $select_module, $url_string, $sorder, $order_by, true);
 $listview_header_search = $controller->getBasicSearchFieldInfoList();
 $smarty->assign("SEARCHLISTHEADER", $listview_header_search);
 if (isset($_REQUEST['start']) && $_REQUEST['start'] != '') {
     $start = vtlib_purify($_REQUEST['start']);
 } else {
     $start = 1;
 }
 $navigation_array = getNavigationValues($start, $noofrows, $list_max_entries_per_page);
 // Setting the record count string
 //modified by rdhital
 $start_rec = $navigation_array['start'];