[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/include/utils/ -> ExportUtils.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  /**    function used to get the permitted blocks
  14   *    @param string $module - module name
  15   *    @param string $disp_view - view name, this may be create_view, edit_view or detail_view
  16   *    @return string $blockid_list - list of block ids within the paranthesis with comma seperated
  17   */
  18  function getPermittedBlocks($module, $disp_view)
  19  {
  20      global $adb, $log;
  21      $log->debug("Entering into the function getPermittedBlocks($module, $disp_view)");
  22  
  23          $tabid = getTabid($module);
  24          $block_detail = Array();
  25          $query="select blockid,blocklabel,show_title from vtiger_blocks where tabid=? and $disp_view=0 and visible = 0 order by sequence";
  26          $result = $adb->pquery($query, array($tabid));
  27          $noofrows = $adb->num_rows($result);
  28      $blockid_list ='(';
  29      for($i=0; $i<$noofrows; $i++)
  30      {
  31          $blockid = $adb->query_result($result,$i,"blockid");
  32          if($i != 0)
  33              $blockid_list .= ', ';
  34          $blockid_list .= $blockid;
  35          $block_label[$blockid] = $adb->query_result($result,$i,"blocklabel");
  36      }
  37      $blockid_list .= ')';
  38  
  39      $log->debug("Exit from the function getPermittedBlocks($module, $disp_view). Return value = $blockid_list");
  40      return $blockid_list;
  41  }
  42  
  43  /**    function used to get the query which will list the permitted fields
  44   *    @param string $module - module name
  45   *    @param string $disp_view - view name, this may be create_view, edit_view or detail_view
  46   *    @return string $sql - query to get the list of fields which are permitted to the current user
  47   */
  48  function getPermittedFieldsQuery($module, $disp_view)
  49  {
  50      global $adb, $log;
  51      $log->debug("Entering into the function getPermittedFieldsQuery($module, $disp_view)");
  52  
  53      global $current_user;
  54      require('user_privileges/user_privileges_'.$current_user->id.'.php');
  55  
  56      //To get the permitted blocks
  57      $blockid_list = getPermittedBlocks($module, $disp_view);
  58  
  59          $tabid = getTabid($module);
  60      if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || $module == "Users")
  61      {
  62           $sql = "SELECT vtiger_field.columnname, vtiger_field.fieldlabel, vtiger_field.tablename FROM vtiger_field WHERE vtiger_field.tabid=".$tabid." AND vtiger_field.block IN $blockid_list AND vtiger_field.displaytype IN (1,2,4,5) and vtiger_field.presence in (0,2) ORDER BY block,sequence";
  63        }
  64        else
  65        {
  66          $profileList = getCurrentUserProfileList();
  67          $sql = "SELECT vtiger_field.columnname, vtiger_field.fieldlabel, vtiger_field.tablename FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=".$tabid." AND vtiger_field.block IN ".$blockid_list." AND vtiger_field.displaytype IN (1,2,4,5) AND vtiger_profile2field.visible=0 AND vtiger_def_org_field.visible=0 AND vtiger_profile2field.profileid IN (". implode(",", $profileList) .") and vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid ORDER BY block,sequence";
  68      }
  69  
  70      $log->debug("Exit from the function getPermittedFieldsQuery($module, $disp_view). Return value = $sql");
  71      return $sql;
  72  }
  73  
  74  /**    function used to get the list of fields from the input query as a comma seperated string
  75   *    @param string $query - field table query which contains the list of fields
  76   *    @return string $fields - list of fields as a comma seperated string
  77   */
  78  function getFieldsListFromQuery($query)
  79  {
  80      global $adb, $log;
  81      $log->debug("Entering into the function getFieldsListFromQuery($query)");
  82  
  83      $result = $adb->query($query);
  84      $num_rows = $adb->num_rows($result);
  85  
  86      for($i=0; $i < $num_rows;$i++)
  87      {
  88          $columnName = $adb->query_result($result,$i,"columnname");
  89          $fieldlabel = $adb->query_result($result,$i,"fieldlabel");
  90          $tablename = $adb->query_result($result,$i,"tablename");
  91  
  92          //HANDLE HERE - Mismatch fieldname-tablename in field table, in future we have to avoid these if elses
  93          if($columnName == 'smownerid')//for all assigned to user name
  94          {
  95              $fields .= "case when (vtiger_users.user_name not like '') then vtiger_users.user_name else vtiger_groups.groupname end as '".$fieldlabel."',";
  96          }
  97          elseif($tablename == 'vtiger_account' && $columnName == 'parentid')//Account - Member Of
  98          {
  99               $fields .= "vtiger_account2.accountname as '".$fieldlabel."',";
 100          }
 101          elseif($tablename == 'vtiger_contactdetails' && $columnName == 'accountid')//Contact - Account Name
 102          {
 103              $fields .= "vtiger_account.accountname as '".$fieldlabel."',";
 104          }
 105          elseif($tablename == 'vtiger_contactdetails' && $columnName == 'reportsto')//Contact - Reports To
 106          {
 107              $fields .= " concat(vtiger_contactdetails2.lastname,' ',vtiger_contactdetails2.firstname) as 'Reports To Contact',";
 108          }
 109          elseif($tablename == 'vtiger_potential' && $columnName == 'related_to')//Potential - Related to (changed for B2C model support)
 110          {
 111              $fields .= "vtiger_potential.related_to as '".$fieldlabel."',";
 112          }
 113          elseif($tablename == 'vtiger_potential' && $columnName == 'campaignid')//Potential - Campaign Source
 114          {
 115              $fields .= "vtiger_campaign.campaignname as '".$fieldlabel."',";
 116          }
 117          elseif($tablename == 'vtiger_seproductsrel' && $columnName == 'crmid')//Product - Related To
 118          {
 119              $fields .= "case vtiger_crmentityRelatedTo.setype
 120                      when 'Leads' then concat('Leads :::: ',vtiger_ProductRelatedToLead.lastname,' ',vtiger_ProductRelatedToLead.firstname)
 121                      when 'Accounts' then concat('Accounts :::: ',vtiger_ProductRelatedToAccount.accountname)
 122                      when 'Potentials' then concat('Potentials :::: ',vtiger_ProductRelatedToPotential.potentialname)
 123                      End as 'Related To',";
 124          }
 125          elseif($tablename == 'vtiger_products' && $columnName == 'contactid')//Product - Contact
 126          {
 127              $fields .= " concat(vtiger_contactdetails.lastname,' ',vtiger_contactdetails.firstname) as 'Contact Name',";
 128          }
 129          elseif($tablename == 'vtiger_products' && $columnName == 'vendor_id')//Product - Vendor Name
 130          {
 131              $fields .= "vtiger_vendor.vendorname as '".$fieldlabel."',";
 132          }
 133          elseif($tablename == 'vtiger_producttaxrel' && $columnName == 'taxclass')//avoid product - taxclass
 134          {
 135              $fields .= "";
 136          }
 137          elseif($tablename == 'vtiger_attachments' && $columnName == 'name')//Emails filename
 138          {
 139              $fields .= $tablename.".name as '".$fieldlabel."',";
 140          }
 141          //By Pavani...Handling mismatch field and table name for trouble tickets
 142            elseif($tablename == 'vtiger_troubletickets' && $columnName == 'product_id')//Ticket - Product
 143          {
 144              $fields .= "vtiger_products.productname as '".$fieldlabel."',";
 145          }
 146          elseif($tablename == 'vtiger_notes' && ($columnName == 'filename' || $columnName == 'filetype' || $columnName == 'filesize' || $columnName == 'filelocationtype' || $columnName == 'filestatus' || $columnName == 'filedownloadcount' ||$columnName == 'folderid')){
 147              continue;
 148          }
 149          elseif(($tablename == 'vtiger_invoice' || $tablename == 'vtiger_quotes' || $tablename == 'vtiger_salesorder')&& $columnName == 'accountid') {
 150              $fields .= 'concat("Accounts::::",vtiger_account.accountname) as "'.$fieldlabel.'",';
 151          }
 152          elseif(($tablename == 'vtiger_invoice' || $tablename == 'vtiger_quotes' || $tablename == 'vtiger_salesorder' || $tablename == 'vtiger_purchaseorder') && $columnName == 'contactid') {
 153              $fields .= 'concat("Contacts::::",vtiger_contactdetails.lastname," ",vtiger_contactdetails.firstname) as "'.$fieldlabel.'",';
 154          }
 155          elseif($tablename == 'vtiger_invoice' && $columnName == 'salesorderid') {
 156              $fields .= 'concat("SalesOrder::::",vtiger_salesorder.subject) as "'.$fieldlabel.'",';
 157          }
 158          elseif(($tablename == 'vtiger_quotes' || $tablename == 'vtiger_salesorder') && $columnName == 'potentialid') {
 159              $fields .= 'concat("Potentials::::",vtiger_potential.potentialname) as "'.$fieldlabel.'",';
 160          }
 161          elseif($tablename == 'vtiger_quotes' && $columnName == 'inventorymanager') {
 162              $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=>'vtiger_inventoryManager.first_name', 'last_name' => 'vtiger_inventoryManager.last_name'), 'Users');
 163              $fields .= $userNameSql. ' as "'.$fieldlabel.'",';
 164          }
 165          elseif($tablename == 'vtiger_salesorder' && $columnName == 'quoteid') {
 166              $fields .= 'concat("Quotes::::",vtiger_quotes.subject) as "'.$fieldlabel.'",';
 167          }
 168          elseif($tablename == 'vtiger_purchaseorder' && $columnName == 'vendorid') {
 169              $fields .= 'concat("Vendors::::",vtiger_vendor.vendorname) as "'.$fieldlabel.'",';
 170          }
 171          else
 172          {
 173              $fields .= $tablename.".".$columnName. " as '" .$fieldlabel."',";
 174          }
 175      }
 176      $fields = trim($fields,",");
 177  
 178      $log->debug("Exit from the function getFieldsListFromQuery($query). Return value = $fields");
 179      return $fields;
 180  }
 181  
 182  
 183  
 184  ?>


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