| [ 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 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 19 * All Rights Reserved. 20 * Contributor(s): ______________________________________.. 21 ********************************************************************************/ 22 include_once ('config.php'); 23 require_once ('include/logging.php'); 24 require_once ('include/database/PearDatabase.php'); 25 require_once ('data/SugarBean.php'); 26 27 $imported_ids = array(); 28 29 // Contact is used to store customer information. 30 class UsersLastImport extends SugarBean 31 { 32 var $log; 33 var $db; 34 35 // Stored vtiger_fields 36 var $id; 37 var $assigned_user_id; 38 var $bean_type; 39 var $bean_id; 40 41 var $table_name = "vtiger_users_last_import"; 42 var $object_name = "UsersLastImport"; 43 var $column_fields = Array( 44 "id" 45 ,"assigned_user_id" 46 ,"bean_type" 47 ,"bean_id" 48 ,"deleted" 49 ); 50 51 var $new_schema = true; 52 53 var $additional_column_fields = Array(); 54 55 var $list_fields = Array(); 56 var $list_fields_name = Array(); 57 var $list_link_field; 58 59 /** Constructor 60 */ 61 function UsersLastImport() { 62 $this->log = LoggerManager::getLogger('UsersLastImport'); 63 $this->db = new PearDatabase(); 64 } 65 66 /** function used to delete ie., update the deleted as 1 in vtiger_users_last_import table 67 * @param int $user_id - user id to whom's last imported records to delete 68 * @return void 69 */ 70 function mark_deleted_by_user_id($user_id) 71 { 72 $query = "UPDATE $this->table_name set deleted=1 where assigned_user_id='$user_id'"; 73 $this->db->query($query,true,"Error marking last imported vtiger_accounts deleted: "); 74 } 75 76 /** function used to get the list query of the imported records 77 * @param reference &$order_by - reference of the variable order_by to add with the query 78 * @param reference &$where - where condition to add with the query 79 * @return string $query - return the list query to get the imported records list 80 */ 81 function create_list_query(&$order_by, &$where) 82 { 83 global $current_user; 84 $query = ''; 85 86 $this->db->println("create list bean_type = ".$this->bean_type." where = ".$where); 87 88 if ($this->bean_type == 'Contacts') 89 { 90 $query = "SELECT distinct crmid, 91 vtiger_account.accountname as vtiger_account_name, 92 vtiger_contactdetails.contactid, 93 vtiger_contactdetails.accountid, 94 vtiger_contactdetails.yahooid, 95 vtiger_contactdetails.firstname, 96 vtiger_contactdetails.lastname, 97 vtiger_contactdetails.phone, 98 vtiger_contactdetails.title, 99 vtiger_contactdetails.email, 100 vtiger_users.id as assigned_user_id, 101 smownerid, 102 vtiger_users.user_name as user_name 103 FROM vtiger_contactdetails 104 left join vtiger_users_last_import on vtiger_users_last_import.bean_id=vtiger_contactdetails.contactid 105 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid 106 LEFT JOIN vtiger_users ON vtiger_crmentity.smownerid=vtiger_users.id 107 LEFT JOIN vtiger_account ON vtiger_account.accountid=vtiger_contactdetails.accountid 108 WHERE vtiger_users_last_import.assigned_user_id= '{$current_user->id}' 109 AND vtiger_users_last_import.bean_type='Contacts' 110 AND vtiger_users_last_import.deleted=0 AND vtiger_crmentity.deleted=0"; 111 112 } 113 else if ($this->bean_type == 'Accounts') 114 { 115 $query = "SELECT distinct vtiger_account.*, vtiger_accountbillads.city, 116 vtiger_users.user_name user_name, 117 crmid, smownerid 118 FROM vtiger_account 119 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_account.accountid 120 inner join vtiger_accountbillads on vtiger_crmentity.crmid=vtiger_accountbillads.accountaddressid 121 left join vtiger_users_last_import on vtiger_users_last_import.bean_id=vtiger_crmentity.crmid 122 left join vtiger_users ON vtiger_crmentity.smownerid=vtiger_users.id 123 WHERE 124 vtiger_users_last_import.assigned_user_id= 125 '{$current_user->id}' 126 AND vtiger_users_last_import.bean_type='Accounts' 127 AND vtiger_users_last_import.deleted=0 128 AND vtiger_crmentity.deleted=0 129 AND vtiger_users.status='Active'"; 130 } 131 else if ($this->bean_type == 'Potentials') 132 { 133 134 $query = "SELECT distinct 135 vtiger_account.accountid vtiger_account_id, 136 vtiger_account.accountname vtiger_account_name, 137 vtiger_users.user_name user_name, 138 vtiger_crmentity.crmid, smownerid, 139 vtiger_potential.* 140 FROM vtiger_potential 141 inner join vtiger_account on vtiger_account.accountid=vtiger_potential.accountid 142 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_potential.potentialid 143 left join vtiger_users ON vtiger_crmentity.smownerid=vtiger_users.id 144 left join vtiger_users_last_import on vtiger_users_last_import.assigned_user_id=vtiger_users.id 145 where vtiger_users_last_import.assigned_user_id='{$current_user->id}' 146 AND vtiger_users_last_import.bean_type='Potentials' 147 AND vtiger_users_last_import.bean_id=vtiger_crmentity.crmid 148 AND vtiger_users_last_import.deleted=0 149 AND vtiger_crmentity.deleted=0 150 AND vtiger_users.status='Active'"; 151 152 } 153 else if($this->bean_type == 'Leads') 154 { 155 $query = "SELECT distinct vtiger_leaddetails.*, vtiger_crmentity.crmid, vtiger_leadaddress.phone,vtiger_leadsubdetails.website, 156 vtiger_users.user_name user_name, 157 smownerid 158 FROM vtiger_leaddetails 159 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_leaddetails.leadid 160 inner join vtiger_leadaddress on vtiger_crmentity.crmid=vtiger_leadaddress.leadaddressid 161 inner join vtiger_leadsubdetails on vtiger_crmentity.crmid=vtiger_leadsubdetails.leadsubscriptionid 162 left join vtiger_users_last_import on vtiger_users_last_import.bean_id=vtiger_crmentity.crmid 163 left join vtiger_users ON vtiger_crmentity.smownerid=vtiger_users.id 164 WHERE 165 vtiger_users_last_import.assigned_user_id= 166 '{$current_user->id}' 167 AND vtiger_users_last_import.bean_type='Leads' 168 AND vtiger_users_last_import.deleted=0 169 AND vtiger_crmentity.deleted=0 170 AND vtiger_users.status='Active'"; 171 } 172 173 174 return $query; 175 176 } 177 178 /* 179 function list_view_parse_additional_sections(&$list_form) 180 { 181 if ($this->bean_type == "Contacts") 182 { 183 if( isset($this->yahoo_id) && $this->yahoo_id != '') 184 { 185 $list_form->parse("main.row.yahoo_id"); 186 } 187 else 188 { 189 $list_form->parse("main.row.no_yahoo_id"); 190 } 191 } 192 return $list_form; 193 194 } 195 */ 196 197 /** function used to delete (update deleted=1 in crmentity table) the last imported records of the current user 198 * @param int $user_id - user id, whose last imported records want to be deleted 199 * @return int $count - return the number of total deleted records (contacts, accounts, opportunities, leads and products) 200 */ 201 function undo($user_id) 202 { 203 $count = 0; 204 205 $count += $this->undo_contacts($user_id); 206 $count += $this->undo_accounts($user_id); 207 $count += $this->undo_opportunities($user_id); 208 $count += $this->undo_leads($user_id); 209 $count += $this->undo_products($user_id); 210 211 return $count; 212 } 213 214 /** function used to delete (update deleted=1 in crmentity table) the last imported contacts of the current user 215 * @param int $user_id - user id, whose last imported contacts want to be deleted 216 * @return int $count - return the number of deleted contacts 217 */ 218 function undo_contacts($user_id) 219 { 220 $count = 0; 221 $query1 = "select bean_id from vtiger_users_last_import where assigned_user_id='$user_id' AND bean_type='Contacts' AND deleted=0"; 222 223 $this->log->info($query1); 224 225 $result1 = $this->db->query($query1) or die("Error getting last import for undo: ".mysql_error()); 226 227 while ( $row1 = $this->db->fetchByAssoc($result1)) 228 { 229 $query2 = "update vtiger_crmentity set deleted=1 where crmid='{$row1['bean_id']}'"; 230 231 $this->log->info($query2); 232 233 $result2 = $this->db->query($query2) or die("Error undoing last import: ".mysql_error()); 234 235 $count++; 236 237 } 238 return $count; 239 } 240 241 /** function used to delete (update deleted=1 in crmentity table) the last imported leads of the current user 242 * @param int $user_id - user id, whose last imported leads want to be deleted 243 * @return int $count - return the number of deleted leads 244 */ 245 function undo_leads($user_id) 246 { 247 $count = 0; 248 $query1 = "select bean_id from vtiger_users_last_import where assigned_user_id='$user_id' AND bean_type='Leads' AND deleted=0"; 249 250 $this->log->info($query1); 251 252 $result1 = $this->db->query($query1) or die("Error getting last import for undo: ".mysql_error()); 253 254 while ( $row1 = $this->db->fetchByAssoc($result1)) 255 { 256 $query2 = "update vtiger_crmentity set deleted=1 where crmid='{$row1['bean_id']}'"; 257 258 $this->log->info($query2); 259 260 $result2 = $this->db->query($query2) or die("Error undoing last import: ".mysql_error()); 261 262 $count++; 263 264 } 265 return $count; 266 } 267 268 /** function used to delete (update deleted=1 in crmentity table) the last imported accounts of the current user 269 * @param int $user_id - user id, whose last imported accounts want to be deleted 270 * @return int $count - return the number of deleted accounts 271 */ 272 function undo_accounts($user_id) 273 { 274 // this should just be a loop foreach module type 275 $count = 0; 276 $query1 = "select bean_id from vtiger_users_last_import where assigned_user_id='$user_id' AND bean_type='Accounts' AND deleted=0"; 277 278 $this->log->info($query1); 279 280 $result1 = $this->db->query($query1) or die("Error getting last import for undo: ".mysql_error()); 281 282 while ( $row1 = $this->db->fetchByAssoc($result1)) 283 { 284 $query2 = "update vtiger_crmentity set deleted=1 where crmid='{$row1['bean_id']}'"; 285 286 $this->log->info($query2); 287 288 $result2 = $this->db->query($query2) or die("Error undoing last import: ".mysql_error()); 289 290 $count++; 291 292 } 293 return $count; 294 } 295 296 /** function used to delete (update deleted=1 in crmentity table) the last imported potentials of the current user 297 * @param int $user_id - user id, whose last imported potentials want to be deleted 298 * @return int $count - return the number of deleted potentials 299 */ 300 function undo_opportunities($user_id) 301 { 302 // this should just be a loop foreach module type 303 $count = 0; 304 $query1 = "select bean_id from vtiger_users_last_import where assigned_user_id='$user_id' AND bean_type='Potentials' AND deleted=0"; 305 306 $this->log->info($query1); 307 308 $result1 = $this->db->query($query1) or die("Error getting last import for undo: ".mysql_error()); 309 310 while ( $row1 = $this->db->fetchByAssoc($result1)) 311 { 312 $query2 = "update vtiger_crmentity set deleted=1 where crmid='{$row1['bean_id']}'"; 313 314 $this->log->info($query2); 315 316 $result2 = $this->db->query($query2) or die("Error undoing last import: ".mysql_error()); 317 318 $count++; 319 320 } 321 return $count; 322 } 323 324 /** function used to delete (update deleted=1 in crmentity table) the last imported products of the current user 325 * @param int $user_id - user id, whose last imported products want to be deleted 326 * @return int $count - return the number of deleted products 327 */ 328 function undo_products($user_id) 329 { 330 $count = 0; 331 $query1 = "select bean_id from vtiger_users_last_import where assigned_user_id='$user_id' AND bean_type='Products' AND deleted=0"; 332 333 $this->log->info($query1); 334 335 $result1 = $this->db->query($query1) or die("Error getting last import for undo: ".mysql_error()); 336 337 while ( $row1 = $this->db->fetchByAssoc($result1)) 338 { 339 $query2 = "update vtiger_crmentity set deleted=1 where crmid='{$row1['bean_id']}'"; 340 341 $this->log->info($query2); 342 343 $result2 = $this->db->query($query2) or die("Error undoing last import: ".mysql_error()); 344 345 $count++; 346 } 347 return $count; 348 } 349 350 } 351 352 353 ?>
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 |