[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
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_CompanyDetails_Model extends Settings_Vtiger_Module_Model { 12 13 STATIC $logoSupportedFormats = array('jpeg', 'jpg', 'png', 'gif', 'pjpeg', 'x-png'); 14 15 var $baseTable = 'vtiger_organizationdetails'; 16 var $baseIndex = 'organization_id'; 17 var $listFields = array('organizationname'); 18 var $nameFields = array('organizationname'); 19 var $logoPath = 'test/logo/'; 20 21 var $fields = array( 22 'organizationname' => 'text', 23 'logoname' => 'text', 24 'logo' => 'file', 25 'address' => 'textarea', 26 'city' => 'text', 27 'state' => 'text', 28 'code' => 'text', 29 'country' => 'text', 30 'phone' => 'text', 31 'fax' => 'text', 32 'website' => 'text', 33 'vatid' => 'text' 34 ); 35 36 /** 37 * Function to get Edit view Url 38 * @return <String> Url 39 */ 40 public function getEditViewUrl() { 41 return 'index.php?module=Vtiger&parent=Settings&view=CompanyDetailsEdit'; 42 } 43 44 /** 45 * Function to get CompanyDetails Menu item 46 * @return menu item Model 47 */ 48 public function getMenuItem() { 49 $menuItem = Settings_Vtiger_MenuItem_Model::getInstance('LBL_COMPANY_DETAILS'); 50 return $menuItem; 51 } 52 53 /** 54 * Function to get Index view Url 55 * @return <String> URL 56 */ 57 public function getIndexViewUrl() { 58 $menuItem = $this->getMenuItem(); 59 return 'index.php?module=Vtiger&parent=Settings&view=CompanyDetails&block='.$menuItem->get('blockid').'&fieldid='.$menuItem->get('fieldid'); 60 } 61 62 /** 63 * Function to get fields 64 * @return <Array> 65 */ 66 public function getFields() { 67 return $this->fields; 68 } 69 70 /** 71 * Function to get Logo path to display 72 * @return <String> path 73 */ 74 public function getLogoPath() { 75 $logoPath = $this->logoPath; 76 $handler = @opendir($logoPath); 77 $logoName = $this->get('logoname'); 78 if ($logoName && $handler) { 79 while ($file = readdir($handler)) { 80 if($logoName === $file && in_array(str_replace('.', '', strtolower(substr($file, -4))), self::$logoSupportedFormats) && $file != "." && $file!= "..") { 81 closedir($handler); 82 return $logoPath.$logoName; 83 } 84 } 85 } 86 return ''; 87 } 88 89 /** 90 * Function to save the logoinfo 91 */ 92 public function saveLogo() { 93 $uploadDir = vglobal('root_directory'). '/' .$this->logoPath; 94 $logoName = $uploadDir.$_FILES["logo"]["name"]; 95 move_uploaded_file($_FILES["logo"]["tmp_name"], $logoName); 96 copy($logoName, $uploadDir.'application.ico'); 97 } 98 99 /** 100 * Function to save the Company details 101 */ 102 public function save() { 103 $db = PearDatabase::getInstance(); 104 $id = $this->get('id'); 105 $fieldsList = $this->getFields(); 106 unset($fieldsList['logo']); 107 $tableName = $this->baseTable; 108 109 if ($id) { 110 $params = array(); 111 112 $query = "UPDATE $tableName SET "; 113 foreach ($fieldsList as $fieldName => $fieldType) { 114 $query .= " $fieldName = ?, "; 115 array_push($params, $this->get($fieldName)); 116 } 117 $query .= " logo = NULL WHERE organization_id = ?"; 118 119 array_push($params, $id); 120 } else { 121 $params = $this->getData(); 122 123 $query = "INSERT INTO $tableName ("; 124 foreach ($fieldsList as $fieldName => $fieldType) { 125 $query .= " $fieldName,"; 126 } 127 $query .= " organization_id) VALUES (". generateQuestionMarks($params). ", ?)"; 128 129 array_push($params, $db->getUniqueID($this->baseTable)); 130 } 131 $db->pquery($query, $params); 132 } 133 134 /** 135 * Function to get the instance of Company details module model 136 * @return <Settings_Vtiger_CompanyDetais_Model> $moduleModel 137 */ 138 public static function getInstance() { 139 $moduleModel = new self(); 140 $db = PearDatabase::getInstance(); 141 142 $result = $db->pquery("SELECT * FROM vtiger_organizationdetails", array()); 143 if ($db->num_rows($result) == 1) { 144 $moduleModel->setData($db->query_result_rowdata($result)); 145 $moduleModel->set('id', $moduleModel->get('organization_id')); 146 } 147 148 $moduleModel->getFields(); 149 return $moduleModel; 150 } 151 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |