| [ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /********************************************************************************* 3 * The contents of this file are subject to the SugarCRM Public License Version 1.1.2 4 * ("License"); You may not use this file except in compliance with the 5 * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL 6 * Software distributed under the License is distributed on an "AS IS" basis, 7 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for 8 * the specific language governing rights and limitations under the License. 9 * The Original Code is: SugarCRM Open Source 10 * The Initial Developer of the Original Code is SugarCRM, Inc. 11 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.; 12 * All Rights Reserved. 13 * Contributor(s): ______________________________________. 14 ********************************************************************************/ 15 /********************************************************************************* 16 * Description: TODO: To be written. 17 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 18 * All Rights Reserved. 19 * Contributor(s): ______________________________________.. 20 ********************************************************************************/ 21 include_once ('config.php'); 22 require_once ('include/logging.php'); 23 require_once ('include/database/PearDatabase.php'); 24 require_once ('data/SugarBean.php'); 25 26 // Contact is used to store customer information. 27 class ImportMap extends SugarBean 28 { 29 var $log; 30 var $db; 31 32 // Stored vtiger_fields 33 var $id; 34 var $name; 35 var $module; 36 var $content; 37 var $has_header; 38 var $deleted; 39 var $date_entered; 40 var $date_modified; 41 var $assigned_user_id; 42 var $is_published; 43 44 var $table_name = "vtiger_import_maps"; 45 var $object_name = "ImportMap"; 46 var $module_id="id"; 47 48 var $tab_name_index = Array("import_maps"=>"id"); 49 var $new_schema = true; 50 51 var $column_fields = Array("id" 52 ,"name" 53 ,"module" 54 ,"content" 55 ,"has_header" 56 ,"deleted" 57 ,"date_entered" 58 ,"date_modified" 59 ,"assigned_user_id" 60 ,"is_published" 61 ); 62 63 /** Constructor 64 */ 65 function ImportMap() 66 { 67 $this->log = LoggerManager::getLogger('file'); 68 $this->db = new PearDatabase(); 69 } 70 71 /** function used to get the id, name, module and content as string 72 * @return string Object:ImportMap id=$this->id name=$this->name module=$this->module content=$this->content 73 */ 74 function toString() 75 { 76 return "Object:ImportMap id=$this->id name=$this->name module=$this->module content=$this->content"; 77 } 78 79 /** function used to save the mapping 80 * @param int $owner_id - user id who is the owner for this mapping 81 * @param string $name - name of the mapping 82 * @param string $module - module name in which we have saved the mapping 83 * @param string $has_header - has_header value 84 * @param string $content - all fields which are concatenated with & symbol 85 * @return int $result - return 1 if the mapping contents updated 86 */ 87 function save_map( $owner_id, $name, $module, $has_header,$content ) 88 { 89 $query_arr = array('assigned_user_id'=>$owner_id,'name'=>$name); 90 91 //$this->retrieve_by_string_fields($query_arr, false); 92 93 $result = 1; 94 $this->assigned_user_id = $owner_id; 95 96 $this->name = $name; 97 $this->module = $module; 98 99 $this->content = "".$this->db->getEmptyBlob().""; 100 $this->has_header = $has_header; 101 $this->deleted = 0; 102 103 //check whether this map name is already exist, if yes then overwrite the existing one, else create new 104 $res = $this->db->query("select id from vtiger_import_maps where name='".trim($name)."'"); 105 if($this->db->num_rows($res) > 0) 106 { 107 $this->id = $this->db->query_result($res,0,'id'); 108 } 109 110 $returnid = $this->save(); 111 112 $this->db->updateBlob($this->table_name,"content","name='".$name."' and module='".$module."'",$content); 113 114 return $result; 115 } 116 117 /** function used to publish or unpublish the mapping 118 * @param int $user_id - user id who is publishing the map 119 * @param string $flag - yes or no 120 * @return value - if flag is yes then update the db and return 1 otherwise return -1 121 */ 122 function mark_published($user_id,$flag) 123 { 124 $other_map = new ImportMap(); 125 126 if ($flag == 'yes') 127 { 128 // if you are trying to publish your map 129 // but there's another published map 130 // by the same name 131 132 $query_arr = array('name'=>$this->name, 133 'is_published'=>'yes'); 134 } 135 else 136 { 137 // if you are trying to unpublish a map 138 // but you own an unpublished map by the same name 139 $query_arr = array('name'=>$this->name, 140 'assigned_user_id'=>$user_id, 141 'is_published'=>'no'); 142 } 143 $other_map->retrieve_by_string_fields($query_arr, false); 144 145 if ( isset($other_map->id) ) 146 { 147 //.. don't do it! 148 return -1; 149 } 150 151 $query = "UPDATE $this->table_name set is_published='$flag', assigned_user_id='$user_id' where id='".$this->id."'"; 152 $this->db->query($query,true,"Error marking import map published: "); 153 return 1; 154 } 155 156 157 /** function to retrieve all the column fields and set as properties 158 * @param array $fields_array - fields array of the corresponding module 159 * @return array $obj_arr - return an array which contains the retrieved column_field values as properties 160 */ 161 function retrieve_all_by_string_fields($fields_array) 162 { 163 $where_clause = $this->get_where($fields_array); 164 $query = "SELECT * FROM $this->table_name $where_clause"; 165 $this->log->debug("Retrieve $this->object_name: ".$query); 166 $result = & $this->db->query($query,true," Error: "); 167 $obj_arr = array(); 168 169 while ($row = $this->db->fetchByAssoc($result,-1,FALSE) ) 170 { 171 $focus = new ImportMap(); 172 173 foreach($this->column_fields as $field) 174 { 175 if(isset($row[$field])) 176 { 177 $focus->$field = $row[$field]; 178 } 179 } 180 array_push($obj_arr,$focus); 181 } 182 return $obj_arr; 183 } 184 185 /** function used to get the list of saved mappings 186 * @param string $module - module name which we currently importing 187 * @return array $map_lists - return the list of mappings in the format of [id]=>name 188 */ 189 function getSavedMappingsList($module) 190 { 191 $query = "SELECT * FROM $this->table_name where module='".$module."' and deleted=0"; 192 $result = $this->db->query($query,true," Error: "); 193 $map_lists = array(); 194 195 while ($row = $this->db->fetchByAssoc($result,-1,FALSE) ) 196 { 197 $map_lists[$row['id']] = $row['name']; 198 } 199 return $map_lists; 200 } 201 202 /** function used to retrieve the mapping content for the passed mapid 203 * @param int $mapid - mapid for the selected map 204 * @return array $mapping_arr - return the array which contains the mapping_arr[name]=value from the content of the map 205 */ 206 function getSavedMappingContent($mapid) 207 { 208 $query = "SELECT * FROM $this->table_name where id='".$mapid."' and deleted=0"; 209 $result = $this->db->query($query,true," Error: "); 210 $mapping_arr = array(); 211 212 $pairs = split("&",$this->db->query_result($result,0,'content')); 213 foreach ($pairs as $pair) 214 { 215 list($name,$value) = split("=",$pair); 216 $mapping_arr["$name"] = $value; 217 } 218 219 return $mapping_arr; 220 } 221 222 } 223 224 225 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |