[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/include/ -> PopulateComboValues.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  include_once ('config.php');
  12  require_once ('include/logging.php');
  13  require_once ('include/database/PearDatabase.php');
  14  require_once ('include/ComboStrings.php');
  15  require_once ('include/ComboUtil.php');
  16  /**
  17   *  Class which handles the population of the combo values
  18   * 
  19   *
  20   */
  21  class PopulateComboValues
  22  {
  23      var $app_list_strings;
  24  
  25  
  26      /** 
  27       * To populate the default combo values for the combo vtiger_tables
  28       * @param $values -- values:: Type string array
  29       * @param $tableName -- tablename:: Type string 
  30       */
  31  	function insertComboValues($values, $tableName,$picklistid)
  32      {
  33          global $log;
  34          $log->debug("Entering insertComboValues(".$values.", ".$tableName.") method ...");
  35          global $adb;
  36          //inserting the value in the vtiger_picklistvalues_seq for the getting uniqueID for each picklist values...
  37          $i=0;
  38          foreach ($values as $val => $cal)
  39          {
  40              $picklist_valueid = getUniquePicklistID();
  41              $id = $adb->getUniqueID('vtiger_'.$tableName);
  42              if($val != '')
  43              {
  44                  $params = array($id, $val, 1, $picklist_valueid, $i);
  45                  $adb->pquery("insert into vtiger_$tableName values(?,?,?,?,?)", $params);
  46              }
  47              else
  48              {
  49                  $params = array($id, '--None--', 1, $picklist_valueid, $i);
  50                  $adb->pquery("insert into vtiger_$tableName values(?,?,?,?,?)", $params);
  51              }
  52  
  53              //Default entries for role2picklist relation has been inserted..
  54  
  55              $sql="select roleid from vtiger_role";
  56              $role_result = $adb->pquery($sql, array());
  57              $numrow = $adb->num_rows($role_result);
  58              for($k=0; $k < $numrow; $k ++)
  59              {
  60                  $roleid = $adb->query_result($role_result,$k,'roleid');
  61                  $params = array($roleid, $picklist_valueid, $picklistid, $i);
  62                  $adb->pquery("insert into vtiger_role2picklist values(?,?,?,?)", $params);
  63              }
  64  
  65              $i++;
  66          }
  67      
  68  
  69          $log->debug("Exiting insertComboValues method ...");
  70      }
  71  
  72  
  73      /** 
  74       * To populate the combo vtiger_tables at startup time
  75       */
  76  
  77  	function create_tables () 
  78      {
  79          global $log;
  80          $log->debug("Entering create_tables () method ...");
  81                  
  82          global $app_list_strings,$adb;
  83          global $combo_strings;
  84          $comboRes = $adb->query("SELECT distinct fieldname FROM vtiger_field WHERE uitype IN ('15') OR fieldname = 'salutationtype' and vtiger_field.presence in (0,2)");
  85          $noOfCombos = $adb->num_rows($comboRes);
  86          for($i=0; $i<$noOfCombos; $i++)
  87          {
  88              $comTab = $adb->query_result($comboRes, $i, 'fieldname');
  89              $picklistid = $adb->getUniqueID("vtiger_picklist");
  90              $params = array($picklistid, $comTab);
  91              $picklist_qry = "insert into vtiger_picklist values(?,?)";
  92              $adb->pquery($picklist_qry, $params);
  93  
  94              $this->insertComboValues($combo_strings[$comTab."_dom"],$comTab,$picklistid);
  95          }
  96          
  97          //we have to decide what are all the picklist and picklist values are non editable
  98          //presence = 0 means you cannot edit the picklist value
  99          //presence = 1 means you can edit the picklist value
 100          $noneditable_tables = Array("ticketstatus","taskstatus","eventstatus","faqstatus","quotestage","postatus","sostatus","invoicestatus","activitytype");
 101          $noneditable_values = Array(
 102                          "Closed Won"=>"sales_stage",
 103                          "Closed Lost"=>"sales_stage",
 104                         );
 105          foreach($noneditable_tables as $picklistname)
 106          {
 107              $adb->pquery("update vtiger_".$picklistname." set PRESENCE=0", array());
 108          }
 109          foreach($noneditable_values as $picklistname => $value)
 110          {
 111              $adb->pquery("update vtiger_$value set PRESENCE=0 where $value=?", array($picklistname));
 112          }
 113  
 114          $log->debug("Exiting create_tables () method ...");
 115  
 116      }
 117  
 118  
 119  	function create_nonpicklist_tables ()
 120      {
 121          global $log;
 122          $log->debug("Entering create_nonpicklist_tables () method ...");
 123                  
 124          global $app_list_strings,$adb;
 125          global $combo_strings;
 126          // uitype -> 16 - Non standard picklist, 115 - User status, 83 - Tax Class
 127          $comboRes = $adb->query("SELECT distinct fieldname FROM vtiger_field WHERE uitype IN ('16','115','83') AND fieldname NOT IN ('hdnTaxType','email_flag') and vtiger_field.presence in (0,2)");
 128          $noOfCombos = $adb->num_rows($comboRes);
 129          for($i=0; $i<$noOfCombos; $i++)
 130          {
 131              $comTab = $adb->query_result($comboRes, $i, 'fieldname');
 132              $this->insertNonPicklistValues($combo_strings[$comTab."_dom"],$comTab);
 133          }
 134          $log->debug("Exiting create_tables () method ...");
 135      }
 136  	function insertNonPicklistValues($values, $tableName)
 137      {
 138          global $log;
 139          $log->debug("Entering insertNonPicklistValues(".$values.", ".$tableName.") method ...");
 140          global $adb;
 141          $i=0;
 142          foreach ($values as $val => $cal)
 143          {
 144                  $id = $adb->getUniqueID('vtiger_'.$tableName);
 145                  if($val != '')
 146                  {
 147                      $params = array($id, $val, $i ,1);
 148                  }
 149                  else
 150                  {
 151                      $params = array($id, '--None--', $i ,1);
 152                  }
 153                  $adb->pquery("insert into vtiger_$tableName values(?,?,?,?)", $params);
 154                  $i++;
 155          }
 156          $log->debug("Exiting insertNonPicklistValues method ...");
 157      }
 158  
 159  }
 160  ?>


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