[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/include/ -> RelatedListView.php (source)

   1  <?php
   2  /*********************************************************************************
   3  ** The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   *
  10   ********************************************************************************/
  11  
  12  
  13  require_once ('include/utils/UserInfoUtil.php');
  14  require_once ("include/utils/utils.php");
  15  require_once ("include/ListView/ListViewSession.php");
  16  require_once ("include/ListView/RelatedListViewSession.php");
  17  
  18  if(!function_exists('GetRelatedList')) {
  19  	function GetRelatedList($module,$relatedmodule,$focus,$query,$button,$returnset,$id='',
  20              $edit_val='',$del_val='',$skipActions=false) {
  21          return GetRelatedListBase($module, $relatedmodule, $focus, $query, $button, $returnset, $id, $edit_val, $del_val, $skipActions);
  22      }
  23  }
  24  
  25  if(!function_exists('GetHistory')) {
  26  	function GetHistory($parentmodule,$query,$id) {
  27          return GetHistoryBase($parentmodule,$query,$id);
  28      }
  29  }
  30  
  31  /** Function to get related list entries in detailed array format
  32    * @param $module -- modulename:: Type string
  33    * @param $relatedmodule -- relatedmodule:: Type string
  34    * @param $focus -- focus:: Type object
  35    * @param $query -- query:: Type string
  36    * @param $button -- buttons:: Type string
  37    * @param $returnset -- returnset:: Type string
  38    * @param $id -- id:: Type string
  39    * @param $edit_val -- edit value:: Type string
  40    * @param $del_val -- delete value:: Type string
  41    * @returns $related_entries -- related entires:: Type string array
  42    *
  43    */
  44  
  45  function GetRelatedListBase($module,$relatedmodule,$focus,$query,$button,$returnset,$id='',$edit_val='',$del_val='',$skipActions=false)
  46  {
  47  
  48  }
  49  
  50  /** Function to get related list entries in detailed array format
  51    * @param $parentmodule -- parentmodulename:: Type string
  52    * @param $query -- query:: Type string
  53    * @param $id -- id:: Type string
  54    * @returns $return_data -- return data:: Type string array
  55    *
  56    */
  57  
  58  function GetHistoryBase($parentmodule,$query,$id)
  59  {
  60  
  61  
  62  }
  63  
  64  /**    Function to display the Products which are related to the PriceBook
  65   *    @param string $query - query to get the list of products which are related to the current PriceBook
  66   *    @param object $focus - PriceBook object which contains all the information of the current PriceBook
  67   *    @param string $returnset - return_module, return_action and return_id which are sequenced with & to pass to the URL which is optional
  68   *    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
  69   */
  70  function getPriceBookRelatedProducts($query,$focus,$returnset='')
  71  {
  72      global $log;
  73      $log->debug("Entering getPriceBookRelatedProducts(".$query.",".get_class($focus).",".$returnset.") method ...");
  74  
  75      global $adb;
  76      global $app_strings;
  77      global $mod_strings;
  78      global $current_language,$current_user;
  79      $current_module_strings = return_module_language($current_language, 'PriceBook');
  80      $no_of_decimal_places = getCurrencyDecimalPlaces();
  81      global $list_max_entries_per_page;
  82      global $urlPrefix;
  83  
  84      global $theme;
  85      $pricebook_id = vtlib_purify($_REQUEST['record']);
  86      $theme_path="themes/".$theme."/";
  87      $image_path=$theme_path."images/";
  88  
  89      $computeCount = $_REQUEST['withCount'];
  90      if(PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true ||
  91              ((boolean) $computeCount) == true){
  92          $noofrows = $adb->query_result($adb->query(Vtiger_Functions::mkCountQuery($query)),0,'count');
  93      }else{
  94          $noofrows = null;
  95      }
  96  
  97      $module = 'PriceBooks';
  98      $relatedmodule = 'Products';
  99      if(!$_SESSION['rlvs'][$module][$relatedmodule])
 100      {
 101          $modObj = new ListViewSession();
 102          $modObj->sortby = $focus->default_order_by;
 103          $modObj->sorder = $focus->default_sort_order;
 104          $_SESSION['rlvs'][$module][$relatedmodule] = get_object_vars($modObj);
 105      }
 106  
 107  
 108      if(isset($_REQUEST['relmodule']) && $_REQUEST['relmodule']!='' && $_REQUEST['relmodule'] == $relatedmodule) {
 109          $relmodule = vtlib_purify($_REQUEST['relmodule']);
 110          if($_SESSION['rlvs'][$module][$relmodule]) {
 111              setSessionVar($_SESSION['rlvs'][$module][$relmodule],$noofrows,$list_max_entries_per_page,$module,$relmodule);
 112          }
 113      }
 114      global $relationId;
 115      $start = RelatedListViewSession::getRequestCurrentPage($relationId, $query);
 116      $navigation_array =  VT_getSimpleNavigationValues($start, $list_max_entries_per_page,
 117              $noofrows);
 118  
 119      $limit_start_rec = ($start-1) * $list_max_entries_per_page;
 120  
 121      if( $adb->dbType == "pgsql")
 122          $list_result = $adb->pquery($query.
 123                  " OFFSET $limit_start_rec LIMIT $list_max_entries_per_page", array());
 124      else
 125          $list_result = $adb->pquery($query.
 126                  " LIMIT $limit_start_rec, $list_max_entries_per_page", array());
 127  
 128      $header=array();
 129      $header[]=$mod_strings['LBL_LIST_PRODUCT_NAME'];
 130      if(getFieldVisibilityPermission('Products', $current_user->id, 'productcode') == '0')
 131          $header[]=$mod_strings['LBL_PRODUCT_CODE'];
 132      if(getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0')
 133          $header[]=$mod_strings['LBL_PRODUCT_UNIT_PRICE'];
 134      $header[]=$mod_strings['LBL_PB_LIST_PRICE'];
 135      if(isPermitted("PriceBooks","EditView","") == 'yes' || isPermitted("PriceBooks","Delete","") == 'yes')
 136          $header[]=$mod_strings['LBL_ACTION'];
 137  
 138      $currency_id = $focus->column_fields['currency_id'];
 139      $numRows = $adb->num_rows($list_result);
 140      for($i=0; $i<$numRows; $i++) {
 141          $entity_id = $adb->query_result($list_result,$i,"crmid");
 142          $unit_price =     $adb->query_result($list_result,$i,"unit_price");
 143          if($currency_id != null) {
 144              $prod_prices = getPricesForProducts($currency_id, array($entity_id));
 145              $unit_price = $prod_prices[$entity_id];
 146          }
 147          $listprice = $adb->query_result($list_result,$i,"listprice");
 148          $field_name=$entity_id."_listprice";
 149  
 150          $entries = Array();
 151          $entries[] = textlength_check($adb->query_result($list_result,$i,"productname"));
 152          if(getFieldVisibilityPermission('Products', $current_user->id, 'productcode') == '0')
 153              $entries[] = $adb->query_result($list_result,$i,"productcode");
 154          if(getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0')
 155              $entries[] = CurrencyField::convertToUserFormat($unit_price, null, true);
 156  
 157          $entries[] = CurrencyField::convertToUserFormat($listprice, null, true);
 158          $action = "";
 159          if(isPermitted("PriceBooks","EditView","") == 'yes' && isPermitted('Products', 'EditView', $entity_id) == 'yes') {
 160              $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"].'"/>';
 161          } else {
 162              $action .= '<img src="'. vtiger_imageurl('blank.gif', $theme).'" border="0" />';
 163          }
 164          if(isPermitted("PriceBooks","Delete","") == 'yes' && isPermitted('Products', 'Delete', $entity_id) == 'yes') {
 165              if($action != "")
 166                  $action .= '&nbsp;|&nbsp;';
 167              $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">';
 168          }
 169          if($action != "")
 170              $entries[] = $action;
 171          $entries_list[] = $entries;
 172      }
 173      $navigationOutput[] =  getRecordRangeMessage($list_result, $limit_start_rec,$noofrows);
 174      $navigationOutput[] = getRelatedTableHeaderNavigation($navigation_array, '',$module,
 175              $relatedmodule,$focus->id);
 176      $return_data = array('header'=>$header,'entries'=>$entries_list,'navigation'=>$navigationOutput);
 177  
 178      $log->debug("Exiting getPriceBookRelatedProducts method ...");
 179      return $return_data;
 180  }
 181  
 182  function CheckFieldPermission($fieldname,$module) {
 183      global $current_user,$adb;
 184      require('user_privileges/user_privileges_'.$current_user->id.'.php');
 185      if($fieldname == '' || $module == '') {
 186          return "false";
 187      }
 188  
 189      if(getFieldVisibilityPermission($module, $current_user->id, $fieldname) == '0') {
 190          return "true";
 191      }
 192      return "false";
 193  }
 194  
 195  function CheckColumnPermission($tablename, $columnname, $module)
 196  {
 197      global $adb;
 198      
 199      static $cache = array();
 200      
 201      $cachekey = $module . ":" . $tablename . ":" . $columnname;
 202      if (!array_key_exists($cachekey, $cache)) {
 203          $res = $adb->pquery("select fieldname from vtiger_field where tablename=? and columnname=? and vtiger_field.presence in (0,2)", array($tablename, $columnname));
 204          $fieldname = $adb->query_result($res, 0, 'fieldname');
 205          $cache[$cachekey] = CheckFieldPermission($fieldname, $module);
 206      }
 207  
 208      return $cache[$cachekey];
 209  }
 210  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1