[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Settings/Vtiger/models/ -> ConfigModule.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 Settings_Vtiger_ConfigModule_Model extends Settings_Vtiger_Module_Model {
  12  
  13      var $fileName = 'config.inc.php';
  14      var $completeData;
  15      var $data;
  16  
  17      /**

  18       * Function to read config file

  19       * @return <Array> The data of config file

  20       */
  21  	public function readFile() {
  22          if (!$this->completeData) {
  23              $this->completeData = file_get_contents($this->fileName);
  24          }
  25          return $this->completeData;
  26      }
  27      
  28      /**

  29       * Function to get CompanyDetails Menu item

  30       * @return menu item Model

  31       */
  32  	public function getMenuItem() {
  33          $menuItem = Settings_Vtiger_MenuItem_Model::getInstance('LBL_CONFIG_EDITOR');
  34          return $menuItem;
  35      }
  36      
  37      /**

  38       * Function to get Edit view Url

  39       * @return <String> Url

  40       */
  41  	public function getEditViewUrl() {
  42          $menuItem = $this->getMenuItem();
  43          return '?module=Vtiger&parent=Settings&view=ConfigEditorEdit&block='.$menuItem->get('blockid').'&fieldid='.$menuItem->get('fieldid');
  44      }
  45  
  46      /**

  47       * Function to get Detail view Url

  48       * @return <String> Url

  49       */
  50  	public function getDetailViewUrl() {
  51          $menuItem = $this->getMenuItem();
  52          return '?module=Vtiger&parent=Settings&view=ConfigEditorDetail&block='.$menuItem->get('blockid').'&fieldid='.$menuItem->get('fieldid');
  53      }
  54  
  55      /**

  56       * Function to get Viewable data of config details

  57       * @return <Array>

  58       */
  59  	public function getViewableData() {
  60          if (!$this->getData()) {
  61              $fileContent = $this->readFile();
  62              $pattern = '/\$([^=]+)=([^;]+);/';
  63              $matches = null;
  64              $matchesFound = preg_match_all($pattern, $fileContent, $matches);
  65              $configContents = array();
  66              if ($matchesFound) {
  67                  $configContents = $matches[0];
  68              }
  69  
  70              $data = array();
  71              $editableFileds = $this->getEditableFields();
  72              foreach ($editableFileds as $fieldName => $fieldDetails) {
  73                  foreach ($configContents as $configContent) {
  74                      if (strpos($configContent, $fieldName)) {
  75                          $fieldValue = explode(' = ', $configContent);
  76                          $fieldValue = $fieldValue[1];
  77                          if ($fieldName === 'upload_maxsize') {
  78                              $fieldValue = round(number_format($fieldValue / 1048576, 2));
  79                          }
  80  
  81                          $data[$fieldName] = str_replace(";", '', str_replace("'", '', $fieldValue));
  82                          break;
  83                      }
  84                  }
  85              }
  86              $this->setData($data);
  87          }
  88          return $this->getData();
  89      }
  90  
  91      /**

  92       * Function to get picklist values

  93       * @param <String> $fieldName

  94       * @return <Array> list of module names

  95       */
  96  	public function getPicklistValues($fieldName) {
  97          if ($fieldName === 'default_module') {
  98              $db = PearDatabase::getInstance();
  99  
 100              $presence = array(0);
 101              $restrictedModules = array('Webmails', 'Emails', 'Integration', 'Dashboard');
 102              $query = 'SELECT name, tablabel FROM vtiger_tab WHERE presence IN (' . generateQuestionMarks($presence) . ') AND isentitytype = ? AND name NOT IN (' . generateQuestionMarks($restrictedModules) . ')';
 103  
 104              $result = $db->pquery($query, array($presence, '1', $restrictedModules));
 105              $numOfRows = $db->num_rows($result);
 106  
 107              $moduleData = array('Home' => 'Home');
 108              for ($i = 0; $i < $numOfRows; $i++) {
 109                  $row = $db->query_result_rowdata($result, $i);
 110                  $moduleData[$db->query_result($result, $i, 'name')] = $db->query_result($result, $i, 'tablabel');
 111              }
 112              return $moduleData;
 113          }
 114          return array('true', 'false');
 115      }
 116  
 117      /**

 118       * Function to get editable fields

 119       * @return <Array> list of field names

 120       */
 121  	public function getEditableFields() {
 122          return array(
 123  //            'CALENDAR_DISPLAY'                => array('label' => 'LBL_MINI_CALENDAR_DISPLAY',            'fieldType' => 'checkbox'),

 124  //            'WORLD_CLOCK_DISPLAY'            => array('label' => 'LBL_WORLD_CLOCK_DISPLAY',                'fieldType' => 'checkbox'),

 125  //            'CALCULATOR_DISPLAY'            => array('label' => 'LBL_CALCULATOR_DISPLAY',                'fieldType' => 'checkbox'),

 126  //            'USE_RTE'                        => array('label' => 'LBL_USE_RTE',                            'fieldType' => 'checkbox'),

 127              'HELPDESK_SUPPORT_EMAIL_ID'        => array('label' => 'LBL_HELPDESK_SUPPORT_EMAILID',            'fieldType' => 'input'),
 128              'HELPDESK_SUPPORT_NAME'            => array('label' => 'LBL_HELPDESK_SUPPORT_NAME',            'fieldType' => 'input'),
 129              'upload_maxsize'                => array('label' => 'LBL_MAX_UPLOAD_SIZE',                    'fieldType' => 'input'),
 130  //            'history_max_viewed'            => array('label' => 'LBL_MAX_HISTORY_VIEWED',                'fieldType' => 'input'),

 131              'default_module'                => array('label' => 'LBL_DEFAULT_MODULE',                    'fieldType' => 'picklist'),
 132              'listview_max_textlength'        => array('label' => 'LBL_MAX_TEXT_LENGTH_IN_LISTVIEW',        'fieldType' => 'input'),
 133              'list_max_entries_per_page'        => array('label' => 'LBL_MAX_ENTRIES_PER_PAGE_IN_LISTVIEW',    'fieldType' => 'input')
 134          );
 135      }
 136  
 137      /**

 138       * Function to save the data

 139       */
 140  	public function save() {
 141          $fileContent = $this->completeData;
 142          $updatedFields = $this->get('updatedFields');
 143          $validationInfo = $this->validateFieldValues($updatedFields);
 144          if ($validationInfo === true) {
 145              foreach ($updatedFields as $fieldName => $fieldValue) {
 146                  $patternString = "\$%s = '%s';";
 147                  if ($fieldName === 'upload_maxsize') {
 148                      $fieldValue = $fieldValue * 1048576; //(1024 * 1024)

 149                      $patternString = "\$%s = %s;";
 150                  }
 151                  $pattern = '/\$' . $fieldName . '[\s]+=([^;]+);/';
 152                  $replacement = sprintf($patternString, $fieldName, ltrim($fieldValue, '0'));
 153                  $fileContent = preg_replace($pattern, $replacement, $fileContent);
 154              }
 155              $filePointer = fopen($this->fileName, 'w');
 156              fwrite($filePointer, $fileContent);
 157              fclose($filePointer);
 158          }
 159          return $validationInfo;
 160      }
 161  
 162      /**

 163       * Function to validate the field values

 164       * @param <Array> $updatedFields

 165       * @return <String> True/Error message

 166       */
 167  	public function validateFieldValues($updatedFields){
 168          if (!filter_var($updatedFields['HELPDESK_SUPPORT_EMAIL_ID'], FILTER_VALIDATE_EMAIL)) {
 169              return "LBL_INVALID_EMAILID";
 170          } else if(preg_match ('/[\'";?><]/', $updatedFields['HELPDESK_SUPPORT_NAME'])) {
 171              return "LBL_INVALID_SUPPORT_NAME";
 172          } else if(!preg_match ('/[a-zA-z0-9]/', $updatedFields['default_module'])) {
 173              return "LBL_INVALID_MODULE";
 174          } else if(!filter_var(ltrim($updatedFields['upload_maxsize'],'0'), FILTER_VALIDATE_INT)
 175                  || !filter_var(ltrim($updatedFields['list_max_entries_per_page'], '0'), FILTER_VALIDATE_INT)
 176                  || !filter_var(ltrim($updatedFields['listview_max_textlength'], '0'), FILTER_VALIDATE_INT)) {
 177              return "LBL_INVALID_NUMBER";
 178          }
 179          return true;
 180      }
 181  
 182      /**

 183       * Function to get the instance of Config module model

 184       * @return <Settings_Vtiger_ConfigModule_Model> $moduleModel

 185       */
 186  	public static function getInstance() {
 187          $moduleModel = new self();
 188          $moduleModel->getViewableData();
 189          return $moduleModel;
 190      }
 191  }


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