[ 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 * $Header$ 17 * Description: TODO: To be written. 18 ********************************************************************************/ 19 include_once ('config.php'); 20 require_once ('include/logging.php'); 21 require_once ('modules/Contacts/Contacts.php'); 22 require_once ('modules/Import/UsersLastImport.php'); 23 require_once ('include/database/PearDatabase.php'); 24 require_once ('include/ComboUtil.php'); 25 26 // Get _dom arrays from Database 27 $comboFieldNames = Array('salutationtype'=>'salutation_dom'); 28 $comboFieldArray = getComboArray($comboFieldNames); 29 30 // Contact is used to store customer information. 31 class ImportContact extends Contacts { 32 // these are vtiger_fields that may be set on import 33 // but are to be processed and incorporated 34 // into vtiger_fields of the parent class 35 var $db; 36 var $full_name; 37 var $primary_address_street_2; 38 var $primary_address_street_3; 39 var $alt_address_street_2; 40 var $alt_address_street_3; 41 42 // This is the list of the functions to run when importing 43 var $special_functions = array( 44 //"get_names_from_full_name" 45 "add_create_account" 46 //,"add_salutation" 47 //,"add_lead_source" 48 //,"add_birthdate" 49 //,"add_do_not_call" 50 //,"add_email_opt_out" 51 //,"add_primary_address_streets" 52 //,"add_alt_address_streets" 53 ); 54 /* 55 function add_salutation() 56 { 57 if ( isset($this->salutation) && 58 ! isset( $comboFieldArray['salutation_dom'][ $this->salutation ]) ) 59 { 60 $this->salutation = ''; 61 } 62 } 63 64 function add_lead_source() 65 { 66 if ( isset($this->lead_source) && 67 ! isset( $comboFieldArray['lead_source_dom'][ $this->lead_source ]) ) 68 { 69 $this->lead_source = ''; 70 } 71 72 } 73 74 function add_birthdate() 75 { 76 if ( isset($this->birthdate)) 77 { 78 if (! preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/',$this->birthdate)) 79 { 80 $this->birthdate = ''; 81 } 82 } 83 84 } 85 86 function add_do_not_call() 87 { 88 if ( isset($this->do_not_call) && $this->do_not_call != 'on') 89 { 90 $this->do_not_call = ''; 91 } 92 93 } 94 95 function add_email_opt_out() 96 { 97 if ( isset($this->email_opt_out) && $this->email_opt_out != 'on') 98 { 99 $this->email_opt_out = ''; 100 } 101 } 102 103 function add_primary_address_streets() 104 { 105 if ( isset($this->primary_address_street_2)) 106 { 107 $this->primary_address_street .= " ". $this->primary_address_street_2; 108 } 109 110 if ( isset($this->primary_address_street_3)) 111 { 112 $this->primary_address_street .= " ". $this->primary_address_street_3; 113 } 114 } 115 116 function add_alt_address_streets() 117 { 118 if ( isset($this->alt_address_street_2)) 119 { 120 $this->alt_address_street .= " ". $this->alt_address_street_2; 121 } 122 123 if ( isset($this->alt_address_street_3)) 124 { 125 $this->alt_address_street .= " ". $this->alt_address_street_3; 126 } 127 128 } 129 130 function get_names_from_full_name() 131 { 132 if ( ! isset($this->full_name)) 133 { 134 return; 135 } 136 $arr = array(); 137 138 $name_arr = preg_split('/\s+/',$this->full_name); 139 140 if ( count($name_arr) == 1) 141 { 142 $this->last_name = $this->full_name; 143 } 144 145 $this->first_name = array_shift($name_arr); 146 147 $this->last_name = join(' ',$name_arr); 148 149 } 150 */ 151 152 /** function used to create or map with existing account if the contact has mapped with an account during import 153 */ 154 function add_create_account() 155 { 156 global $adb; 157 // global is defined in UsersLastImport.php 158 global $imported_ids; 159 global $current_user; 160 161 $acc_name = $this->column_fields['account_id']; 162 $adb->println("contact add_create acc=".$acc_name); 163 164 if ((! isset($acc_name) || $acc_name == '') ) 165 { 166 return; 167 } 168 169 $arr = array(); 170 171 // check if it already exists 172 $focus = new Accounts(); 173 174 $query = ''; 175 176 // if user is defining the vtiger_account id to be associated with this contact.. 177 178 //Modified to remove the spaces at first and last in vtiger_account name -- after 4.2 patch 2 179 $acc_name = trim(addslashes($acc_name)); 180 181 //Modified the query to get the available account only ie., which is not deleted 182 $query = "select vtiger_crmentity.deleted, vtiger_account.* from vtiger_account, vtiger_crmentity WHERE accountname='{$acc_name}' and vtiger_crmentity.crmid =vtiger_account.accountid and vtiger_crmentity.deleted=0"; 183 184 $result = $adb->query($query); 185 186 $row = $this->db->fetchByAssoc($result, -1, false); 187 188 $adb->println("fetched account"); 189 $adb->println($row); 190 191 // we found a row with that id 192 if (isset($row['accountid']) && $row['accountid'] != -1) 193 { 194 $focus->id = $row['accountid']; 195 $adb->println("Account row exists - using same id=".$focus->id); 196 } 197 198 // if we didnt find the vtiger_account, so create it 199 if (! isset($focus->id) || $focus->id == '') 200 { 201 $adb->println("Createing new vtiger_account"); 202 $focus->column_fields['accountname'] = $acc_name; 203 $focus->column_fields['assigned_user_id'] = $current_user->id; 204 $focus->column_fields['modified_user_id'] = $current_user->id; 205 206 //$focus->saveentity("Accounts"); 207 $focus->save("Accounts"); 208 $acc_id = $focus->id; 209 210 $adb->println("New Account created id=".$focus->id); 211 212 // avoid duplicate mappings: 213 if (! isset( $imported_ids[$acc_id]) ) 214 { 215 $adb->println("inserting vtiger_users last import for vtiger_accounts"); 216 // save the new vtiger_account as a vtiger_users_last_import 217 $last_import = new UsersLastImport(); 218 $last_import->assigned_user_id = $current_user->id; 219 $last_import->bean_type = "Accounts"; 220 $last_import->bean_id = $focus->id; 221 $last_import->save(); 222 $imported_ids[$acc_id] = 1; 223 } 224 } 225 226 $adb->println("prev contact accid=".$this->column_fields["account_id"]); 227 // now just link the vtiger_account 228 $this->column_fields["account_id"] = $focus->id; 229 $adb->println("curr contact accid=".$this->column_fields["account_id"]); 230 231 } 232 233 234 235 // This is the list of vtiger_fields that can be imported 236 // some of these don't map directly to columns in the db 237 238 //we need to add two or more arrays as the columns are distributed across the vtiger_tables now 239 /*var $importable_fields = array( 240 "contactid"=>1, 241 "firstname"=>1, 242 "lastname"=>1, 243 "salutation"=>1, 244 "donotcall"=>1, 245 "emailoptout"=>1, 246 "accountid"=>1, 247 "title"=>1, 248 "department"=>1, 249 "phone"=>1, 250 "mobile"=>1, 251 "fax"=>1, 252 "email"=>1, 253 "otheremail"=>1, 254 "yahooid"=>1, 255 );*/ 256 257 var $importable_fields = Array(); 258 259 /** Constructor which will set the importable_fields as $this->importable_fields[$key]=1 in this object where key is the fieldname in the field table 260 */ 261 function ImportContact() { 262 $this->log = LoggerManager::getLogger('import_contact'); 263 $this->db = new PearDatabase(); 264 $this->db->println("IMP ImportContact"); 265 $colf = getColumnFields("Contacts"); 266 foreach($colf as $key=>$value) 267 $this->importable_fields[$key]=1; 268 //unset($this->importable_fields['account_id']); 269 //$this->importable_fields['account_name']=1; 270 271 $this->db->println($this->importable_fields); 272 } 273 274 } 275 276 277 278 ?>
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 |