[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Users/models/ -> Module.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  class Users_Module_Model extends Vtiger_Module_Model {
  12      /**

  13       * Function to get list view query for popup window

  14       * @param <String> $sourceModule Parent module

  15       * @param <String> $field parent fieldname

  16       * @param <Integer> $record parent id

  17       * @param <String> $listQuery

  18       * @return <String> Listview Query

  19       */
  20  	public function getQueryByModuleField($sourceModule, $field, $record, $listQuery) {
  21          if($sourceModule == 'Users' && $field == 'reports_to_id') {
  22              $overRideQuery = $listQuery;
  23              if(!empty($record)){
  24                  $overRideQuery = $overRideQuery. " AND vtiger_users.id != ". $record;
  25              }
  26              return $overRideQuery;
  27          }
  28      }
  29  
  30      /**

  31       * Function searches the records in the module, if parentId & parentModule

  32       * is given then searches only those records related to them.

  33       * @param <String> $searchValue - Search value

  34       * @param <Integer> $parentId - parent recordId

  35       * @param <String> $parentModule - parent module name

  36       * @return <Array of Users_Record_Model>

  37       */
  38  	public function searchRecord($searchValue, $parentId=false, $parentModule=false, $relatedModule=false) {
  39          if(!empty($searchValue)) {
  40              $db = PearDatabase::getInstance();
  41  
  42              $query = 'SELECT * FROM vtiger_users WHERE (first_name LIKE ? OR last_name LIKE ?) AND status = ?';
  43              $params = array("%$searchValue%", "%$searchValue%", 'Active');
  44  
  45              $result = $db->pquery($query, $params);
  46              $noOfRows = $db->num_rows($result);
  47  
  48              $matchingRecords = array();
  49              for($i=0; $i<$noOfRows; ++$i) {
  50                  $row = $db->query_result_rowdata($result, $i);
  51                  $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Record', 'Users');
  52                  $recordInstance = new $modelClassName();
  53                  $matchingRecords['Users'][$row['id']] = $recordInstance->setData($row)->setModuleFromInstance($this);
  54              }
  55              return $matchingRecords;
  56          }
  57      }
  58  
  59      /**

  60       * Function returns the default column for Alphabetic search

  61       * @return <String> columnname

  62       */
  63  	public function getAlphabetSearchField(){
  64          return 'last_name';
  65      }
  66  
  67      /**

  68       * Function to get the url for the Create Record view of the module

  69       * @return <String> - url

  70       */
  71  	public function getCreateRecordUrl() {
  72          return 'index.php?module=' . $this->get('name') . '&parent=Settings&view=' . $this->getEditViewName();
  73      }
  74  
  75  	public function checkDuplicateUser($userName){
  76          $db = PearDatabase::getInstance();
  77  
  78          $query = 'SELECT user_name FROM vtiger_users WHERE user_name = ?';
  79          $result = $db->pquery($query, array($userName));
  80          if($db->num_rows($result) > 0){
  81              return true;
  82          }
  83          return false;
  84      }
  85  
  86      /**

  87       * Function to delete a given record model of the current module

  88       * @param Vtiger_Record_Model $recordModel

  89       */
  90  	public function deleteRecord($recordModel) {
  91          $db = PearDatabase::getInstance();
  92          $moduleName = $this->get('name');
  93          $date_var = date('Y-m-d H:i:s');
  94          $query = "UPDATE vtiger_users SET status=?, date_modified=?, modified_user_id=? WHERE id=?";
  95          $db->pquery($query, array('Inactive', $adb->formatDate($date_var, true), $recordModel->getId(), $recordModel->getId()), true,"Error marking record deleted: ");
  96      }
  97  
  98      /**

  99       * Function to get the url for list view of the module

 100       * @return <string> - url

 101       */
 102  	public function getListViewUrl() {
 103          return 'index.php?module='.$this->get('name').'&parent=Settings&view='.$this->getListViewName();
 104      }
 105  
 106      /**

 107      * Function to update Base Currency of Product

 108      * @param- $_REQUEST array

 109      */
 110  	public function updateBaseCurrency($currencyName) {
 111          $db = PearDatabase::getInstance();
 112          $result = $db->pquery('SELECT currency_code, currency_symbol FROM vtiger_currencies WHERE currency_name = ?', array($currencyName));
 113          $num_rows = $db->num_rows($result);
 114          if ($num_rows > 0) {
 115              $currency_code = decode_html($db->query_result($result, 0, 'currency_code'));
 116              $currency_symbol = decode_html($db->query_result($result, 0,'currency_symbol'));
 117          }
 118  
 119          //Updating Database

 120          $query = 'UPDATE vtiger_currency_info SET currency_name = ?, currency_code = ?, currency_symbol = ? WHERE id = ?';
 121          $params = array($currencyName, $currency_code, $currency_symbol, '1');
 122          $db->pquery($query, $params);
 123  
 124          $this->updateConfigFile($currencyName);
 125      }
 126  
 127      /**

 128      * Function to update Config file

 129      * @param- $_REQUEST array

 130      */
 131  	public function updateConfigFile($currencyName) {
 132          $currencyName = '$currency_name = \''.$currencyName.'\'';
 133  
 134          //Updating in config inc file

 135          $filename = 'config.inc.php';
 136          if (file_exists($filename)) {
 137              $contents = file_get_contents($filename);
 138              $contents = str_replace('$currency_name = \'USA, Dollars\'', $currencyName, $contents);
 139              file_put_contents($filename, $contents);
 140          }
 141     }
 142  
 143     /**

 144       * Function to get user setup status

 145       * @return-is First User or not

 146       */
 147  	public static function insertEntryIntoCRMSetup($userId) {
 148          $db = PearDatabase::getInstance();
 149  
 150          //updating user setup status into database

 151          $insertQuery = 'INSERT INTO vtiger_crmsetup (userid, setup_status) VALUES (?, ?)';
 152          $db->pquery($insertQuery, array($userId, '1'));
 153      }
 154  
 155      /**

 156       * Function to store the login history

 157       * @param type $username

 158       */
 159  	public function saveLoginHistory($username){
 160          $adb = PearDatabase::getInstance();
 161  
 162          $userIPAddress = $_SERVER['REMOTE_ADDR'];
 163          $loginTime = date("Y-m-d H:i:s");
 164          $query = "INSERT INTO vtiger_loginhistory (user_name, user_ip, logout_time, login_time, status) VALUES (?,?,?,?,?)";
 165          $params = array($username, $userIPAddress, '0000-00-00 00:00:00',  $loginTime, 'Signed in');
 166          $adb->pquery($query, $params);
 167      }
 168  
 169      /**

 170       * Function to store the logout history

 171       * @param type $username

 172       */
 173  	public function saveLogoutHistory(){
 174          $adb = PearDatabase::getInstance();
 175  
 176          $userRecordModel = Users_Record_Model::getCurrentUserModel();
 177          $userIPAddress = $_SERVER['REMOTE_ADDR'];
 178          $outtime = date("Y-m-d H:i:s");
 179  
 180          $loginIdQuery = "SELECT MAX(login_id) AS login_id FROM vtiger_loginhistory WHERE user_name=? AND user_ip=?";
 181          $result = $adb->pquery($loginIdQuery, array($userRecordModel->get('user_name'), $userIPAddress));
 182          $loginid = $adb->query_result($result,0,"login_id");
 183  
 184          if (!empty($loginid)){
 185              $query = "UPDATE vtiger_loginhistory SET logout_time =?, status=? WHERE login_id = ?";
 186              $result = $adb->pquery($query, array($outtime, 'Signed off', $loginid));
 187          }
 188      }
 189  
 190          /**

 191       * Function to save packages info

 192       * @param <type> $packagesList

 193       */
 194  	public static function savePackagesInfo($packagesList) {
 195          $adb = PearDatabase::getInstance();
 196          $packagesListFromDB = Users_CRMSetup::getPackagesList();
 197          $disabledModulesList = array();
 198  
 199          foreach ($packagesListFromDB as $packageName => $packageInfo) {
 200              if (!$packagesList[$packageName]) {
 201                  $disabledModulesList = array_merge($disabledModulesList, array_keys($packageInfo['modules']));
 202              }
 203          }
 204  
 205          if ($disabledModulesList) {
 206              $updateQuery = 'UPDATE vtiger_tab SET presence = CASE WHEN name IN (' . generateQuestionMarks($disabledModulesList) . ') THEN 1 ';
 207              $updateQuery .= 'ELSE 0 END WHERE presence != 2 ';
 208          } else {
 209              $updateQuery = 'UPDATE vtiger_tab SET presence = 0 WHERE presence != 2';
 210          }
 211  
 212          $adb->pquery($updateQuery, $disabledModulesList);
 213      }
 214  
 215      /**

 216      * @return an array with the list of currencies which are available in source

 217      */
 218      public function getCurrenciesList() {
 219        $adb = PearDatabase::getInstance();
 220  
 221         $currency_query = 'SELECT currency_name, currency_code, currency_symbol FROM vtiger_currencies ORDER BY currency_name';
 222         $result = $adb->pquery($currency_query, array());
 223         $num_rows = $adb->num_rows($result);
 224         for($i = 0; $i<$num_rows; $i++) {
 225             $currencyname = decode_html($adb->query_result($result, $i, 'currency_name'));
 226             $currencycode = decode_html($adb->query_result($result, $i, 'currency_code'));
 227             $currencysymbol = decode_html($adb->query_result($result, $i, 'currency_symbol'));
 228             $currencies[$currencyname] = array($currencycode,$currencysymbol);
 229         }
 230         return $currencies;
 231     }
 232  
 233     /**

 234      * @return an array with the list of time zones which are availables in source

 235      */
 236     public function getTimeZonesList() {
 237         $adb = PearDatabase::getInstance();
 238  
 239         $timezone_query = 'SELECT time_zone FROM vtiger_time_zone';
 240         $result = $adb->pquery($timezone_query, array());
 241         $num_rows = $adb->num_rows($result);
 242         for($i = 0; $i<$num_rows; $i++) {
 243             $time_zone = decode_html($adb->query_result($result, $i, 'time_zone'));
 244             $time_zones_list[$time_zone] = $time_zone;
 245         }
 246         return $time_zones_list;
 247     }
 248  
 249     /**

 250      * @return an array with the list of languages which are available in source

 251      */
 252     public function getLanguagesList() {
 253         $adb = PearDatabase::getInstance();
 254  
 255         $language_query = 'SELECT prefix, label FROM vtiger_language';
 256         $result = $adb->pquery($language_query, array());
 257         $num_rows = $adb->num_rows($result);
 258         for($i = 0; $i<$num_rows; $i++) {
 259             $lang_prefix = decode_html($adb->query_result($result, $i, 'prefix'));
 260             $label = decode_html($adb->query_result($result, $i, 'label'));
 261             $languages_list[$lang_prefix] = $label;
 262         }
 263         return $languages_list;
 264     }
 265  
 266  }


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