[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
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 12 /** 13 * This function returns no value but handles the delete functionality of each entity. 14 * Input Parameter are $module - module name, $return_module - return module name, $focus - module object, $record - entity id, $return_id - return entity id. 15 */ 16 17 function DeleteEntity($module,$return_module,$focus,$record,$return_id) 18 { 19 global $log; 20 $log->debug("Entering DeleteEntity(".$module.",".$return_module.",".$focus.",".$record.",".$return_id.") method ..."); 21 global $adb; 22 global $current_user; 23 24 //if we delete the entity from relatedlist then this if will be used ie., the relationship will be deleted otherwise if we delete the entiry from listview then the relationship will not be deleted where as total entity will be deleted 25 if($module != $related_module) 26 { 27 28 switch($module): 29 case Leads: 30 if($return_module == "Campaigns") { 31 $sql = 'delete from vtiger_campaignleadrel where leadid='.$record.' and campaignid='.$return_id; 32 $adb->query($sql); 33 } else { 34 $sql = 'delete from vtiger_seactivityrel where crmid = '.$record.' and activityid = '.$return_id; 35 $adb->query($sql); 36 } 37 break; 38 case Accounts: 39 if($return_id!='') 40 { 41 $sql ='delete from vtiger_seactivityrel where crmid = '.$record.' and activityid = '.$return_id; 42 $adb->query($sql); 43 } 44 break; 45 case Campaigns: 46 if($return_module == "Leads") { 47 $sql = 'delete from vtiger_campaignleadrel where campaignid='.$record.' and leadid='.$return_id; 48 $adb->query($sql); 49 } elseif($return_module == "Contacts") { 50 $sql = 'delete from vtiger_campaigncontrel where campaignid='.$record.' and contactid='.$return_id; 51 $adb->query($sql); 52 } 53 break; 54 case Contacts: 55 if($return_module == 'Accounts') 56 { 57 $sql = 'update vtiger_contactdetails set accountid = "" where contactid = '.$record; 58 $adb->query($sql); 59 } 60 if($return_module == 'Potentials' && $record != '' && $return_id != '') 61 { 62 $sql = 'delete from vtiger_contpotentialrel where contactid='.$record.' and potentialid='.$return_id; 63 $adb->query($sql); 64 } 65 if($return_module == "Campaigns") { 66 $sql = 'delete from vtiger_campaigncontrel where contactid='.$record.' and campaignid='.$return_id; 67 $adb->query($sql); 68 } 69 if($record != '' && $return_id != '') 70 { 71 $sql = 'delete from vtiger_seactivityrel where crmid = '.$record.' and activityid = '.$return_id; 72 $adb->query($sql); 73 $sql_recentviewed ='delete from vtiger_tracker where user_id = '.$current_user->id.' and item_id = '.$record; 74 $adb->query($sql_recentviewed); 75 } 76 if($return_module == 'Products') 77 { 78 $sql = 'delete from vtiger_vendorcontactrel where contactid='.$record.' and vendorid='.$return_id; 79 $adb->query($sql); 80 } 81 if($return_module == 'Vendors') 82 { 83 $sql = "delete from vtiger_vendorcontactrel where vendorid=$return_id and contactid=$record"; 84 $adb->query($sql); 85 } 86 if($return_module == 'Calendar') 87 { 88 $sql = "delete from vtiger_cntactivityrel where activityid=$return_id and contactid=$record"; 89 $adb->query($sql); 90 } 91 break; 92 case Potentials: 93 if($return_module == 'Accounts' || $return_module == 'Campaigns') 94 { 95 //we can call $focus->mark_deleted($record) 96 $sql = 'update vtiger_crmentity set deleted = 1 where crmid = '.$record; 97 $adb->query($sql); 98 } 99 $sql ='delete from vtiger_seactivityrel where crmid = '.$record.' and activityid = '.$return_id; 100 $adb->query($sql); 101 break; 102 case Calendar: 103 if($return_module == 'Contacts') 104 { 105 $sql = 'delete from vtiger_cntactivityrel where contactid = '.$return_id.' and activityid = '.$record; 106 $adb->query($sql); 107 } 108 else 109 { 110 $sql= 'delete from vtiger_seactivityrel where activityid='.$record; 111 $adb->query($sql); 112 } 113 114 if($return_module == 'HelpDesk') 115 { 116 $sql = 'delete from vtiger_seticketsrel where ticketid = '.$return_id.' and crmid = '.$record; 117 $adb->query($sql); 118 } 119 $sql = 'delete from vtiger_activity_reminder where activity_id='.$record; 120 $adb->query($sql); 121 122 $sql = 'delete from vtiger_recurringevents where activityid='.$record; 123 $adb->query($sql); 124 break; 125 case Emails: 126 $sql='delete from vtiger_seactivityrel where activityid='.$adb->quote($record); 127 $adb->query($sql); 128 break; 129 case HelpDesk: 130 if($return_module == 'Contacts' || $return_module == 'Accounts') 131 { 132 $sql = "update vtiger_troubletickets set parent_id='' where ticketid=".$record; 133 $adb->query($sql); 134 $se_sql= 'delete from vtiger_seticketsrel where ticketid='.$record; 135 $adb->query($se_sql); 136 137 } 138 if($return_module == 'Products') 139 { 140 $sql = "update vtiger_troubletickets set product_id='' where ticketid=".$record; 141 $adb->query($sql); 142 } 143 break; 144 case Notes: 145 if($return_module== 'Contacts') 146 { 147 $sql = 'update vtiger_notes set contact_id = 0 where notesid = '.$record; 148 $adb->query($sql); 149 } 150 $sql = 'delete from vtiger_senotesrel where notesid = '.$record. ' and crmid = '.$return_id; 151 $adb->query($sql); 152 break; 153 case Products: 154 if($record != '' && $return_id != '') 155 { 156 if($return_module == 'Calendar') 157 $sql = 'delete from vtiger_seactivityrel where crmid = '.$record.' and activityid = '.$return_id; 158 159 if($return_module == 'Potentials' || $return_module == 'Accounts' || $return_module == 'Leads') 160 $sql = 'delete from vtiger_seproductsrel where crmid = '.$return_id.' and productid = '.$record; 161 162 $adb->query($sql); 163 } 164 if($return_module == "Contacts") 165 { 166 $sql = "UPDATE vtiger_products set contactid = '' where productid = ".$record; 167 $adb->query($sql); 168 } 169 if($return_module == "Vendors") 170 { 171 $sql = "update vtiger_products set vendor_id = '' where productid = $record"; 172 $adb->query($sql); 173 } 174 break; 175 case PurchaseOrder: 176 177 if($return_module == "Vendors") 178 { 179 $sql_req ='update vtiger_crmentity set deleted = 1 where crmid= '.$record; 180 $adb->query($sql_req); 181 } 182 elseif($return_module == "Contacts") 183 { 184 $sql_req ='UPDATE vtiger_purchaseorder set contactid="" where purchaseorderid = '.$record; 185 $adb->query($sql_req); 186 } 187 188 //Following condition is commented because in Product Relatedlist we have PO which should not be deleted. 189 /* 190 elseif($return_module == "Products") 191 { 192 //Removing the relation from the po product rel 193 $po_query = "select * from vtiger_poproductrel where productid=".$return_id; 194 $result = $adb->query($po_query); 195 $num_rows = $adb->num_rows($result); 196 for($i=0; $i< $num_rows; $i++) 197 { 198 $po_id = $adb->query_result($result,$i,"purchaseorderid"); 199 $qty = $adb->query_result($result,$i,"quantity"); 200 $listprice = $adb->query_result($result,$i,"listprice"); 201 $prod_total = $qty * $listprice; 202 //Handle here -- Tax calculations 203 204 //Get the current sub total from Quotes and update it with the new subtotal 205 updateSubTotal("PurchaseOrder","vtiger_purchaseorder","subtotal","total","purchaseorderid",$po_id,$prod_total); 206 } 207 //delete the relation from po product rel 208 $del_query = "delete from vtiger_poproductrel where productid=".$return_id." and purchaseorderid=".$record; 209 $adb->query($del_query); 210 211 } 212 */ 213 break; 214 case SalesOrder: 215 if($return_module == "Accounts") 216 { 217 $focus->mark_deleted($record); 218 } 219 elseif($return_module == "Quotes") 220 { 221 $relation_query = "UPDATE vtiger_salesorder set quoteid='' where salesorderid=".$record; 222 $adb->query($relation_query); 223 } 224 elseif($return_module == "Potentials") 225 { 226 $relation_query = "UPDATE vtiger_salesorder set potentialid='' where salesorderid=".$record; 227 $adb->query($relation_query); 228 } 229 elseif($return_module == "Contacts") 230 { 231 $relation_query = "UPDATE vtiger_salesorder set contactid='' where salesorderid=".$record; 232 $adb->query($relation_query); 233 } 234 //Following condition is commented because in Product Relatedlist we have SO which should not be deleted. 235 /* 236 elseif($return_module == "Products") 237 { 238 //Removing the relation from the so product rel 239 $so_query = "select * from vtiger_soproductrel where productid=".$return_id; 240 $result = $adb->query($so_query); 241 $num_rows = $adb->num_rows($result); 242 for($i=0; $i< $num_rows; $i++) 243 { 244 $so_id = $adb->query_result($result,$i,"salesorderid"); 245 $qty = $adb->query_result($result,$i,"quantity"); 246 $listprice = $adb->query_result($result,$i,"listprice"); 247 $prod_total = $qty * $listprice; 248 //Handle here -- Tax calculations 249 250 //Get the current sub total from Quotes and update it with the new subtotal 251 updateSubTotal("SalesOrder","vtiger_salesorder","subtotal","total","salesorderid",$so_id,$prod_total); 252 } 253 //delete the relation from so product rel 254 $del_query = "delete from vtiger_soproductrel where productid=".$return_id." and salesorderid=".$record; 255 $adb->query($del_query); 256 257 } 258 */ 259 break; 260 case Quotes: 261 if($return_module == "Accounts" ) 262 { 263 $focus->mark_deleted($record); 264 } 265 elseif($return_module == "Potentials") 266 { 267 $relation_query = "UPDATE vtiger_quotes set potentialid='' where quoteid=".$record; 268 $adb->query($relation_query); 269 } 270 elseif($return_module == "Contacts") 271 { 272 $relation_query = "UPDATE vtiger_quotes set contactid='' where quoteid=".$record; 273 $adb->query($relation_query); 274 } 275 //Following condition is commented because in Product Relatedlist we have Quotes which should not be deleted. 276 /* 277 elseif($return_module == "Products") 278 { 279 //Removing the relation from the vtiger_quotes product rel 280 $qt_query = "select * from vtiger_quotesproductrel where productid=".$return_id; 281 $result = $adb->query($qt_query); 282 $num_rows = $adb->num_rows($result); 283 for($i=0; $i< $num_rows; $i++) 284 { 285 $quote_id = $adb->query_result($result,$i,"quoteid"); 286 $qty = $adb->query_result($result,$i,"quantity"); 287 $listprice = $adb->query_result($result,$i,"listprice"); 288 $prod_total = $qty * $listprice; 289 //Handle here -- Tax calculation 290 291 //Get the current sub total from Quotes and update it with the new subtotal 292 updateSubTotal("Quotes","vtiger_quotes","subtotal","total","quoteid",$quote_id,$prod_total); 293 } 294 //delete the relation from vtiger_quotes product rel 295 $del_query = "delete from vtiger_quotesproductrel where productid=".$return_id." and quoteid=".$record; 296 $adb->query($del_query); 297 298 } 299 */ 300 break; 301 case Invoice: 302 if($return_module == "Accounts") 303 { 304 $focus->mark_deleted($record); 305 } 306 elseif($return_module=="SalesOrder") 307 { 308 $relation_query = "UPDATE vtiger_invoice set salesorderid='' where invoiceid=".$record; 309 $adb->query($relation_query); 310 } 311 //Following condition is commented because in Product Relatedlist we have Invoice which should not be deleted. 312 /* 313 elseif($return_module=="Products") 314 { 315 //Removing the relation from the vtiger_quotes product rel 316 $inv_query = "select * from vtiger_invoiceproductrel where productid=".$return_id; 317 $result = $adb->query($inv_query); 318 $num_rows = $adb->num_rows($result); 319 for($i=0; $i< $num_rows; $i++) 320 { 321 $invoice_id = $adb->query_result($result,$i,"invoiceid"); 322 $qty = $adb->query_result($result,$i,"quantity"); 323 $listprice = $adb->query_result($result,$i,"listprice"); 324 $prod_total = $qty * $listprice; 325 //Handle here -- tax calculations should be handle here 326 327 //Get the current sub total from Quotes and update it with the new subtotal 328 updateSubTotal("Invoices","vtiger_invoice","subtotal","total","invoiceid",$invoice_id,$prod_total); 329 } 330 //delete the relation from vtiger_quotes product rel 331 $del_query = "delete from vtiger_invoiceproductrel where productid=".$return_id." and invoiceid=".$record; 332 $adb->query($del_query); 333 } 334 */ 335 break; 336 case Rss: 337 $del_query = "delete from vtiger_rss where rssid=".$record; 338 $adb->query($del_query); 339 break; 340 case Portal: 341 $del_query = "delete from vtiger_portal where portalid=".$record; 342 $adb->query($del_query); 343 break; 344 endswitch; 345 } 346 347 //this is added to update the crmentity.deleted=1 when we delete from listview and not from relatedlist 348 if($return_module == $module && $return_module !='Rss' && $return_module !='Portal') 349 { 350 require_once ('include/freetag/freetag.class.php'); 351 $freetag=new freetag(); 352 $freetag->delete_all_object_tags_for_user($current_user->id,$record); 353 $focus->mark_deleted($record); 354 } 355 356 //This is to delete the entity information from tracker ie., lastviewed 357 if($module != 'Faq') 358 { 359 $sql_recentviewed ='delete from vtiger_tracker where user_id = '.$current_user->id.' and item_id = '.$record; 360 $adb->query($sql_recentviewed); 361 } 362 $log->debug("Entering DeleteEntity method ..."); 363 } 364 ?>
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 |