| [ 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: /advent/projects/wesat/vtiger_crm/sugarcrm/modules/Accounts/Accounts.php,v 1.53 2005/04/28 08:06:45 rank Exp $ 17 * Description: Defines the Account SugarBean Account entity with the necessary 18 * methods and variables. 19 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 20 * All Rights Reserved. 21 * Contributor(s): ______________________________________.. 22 ********************************************************************************/ 23 24 include_once ('config.php'); 25 require_once ('include/logging.php'); 26 require_once ('include/database/PearDatabase.php'); 27 require_once ('data/SugarBean.php'); 28 require_once ('data/CRMEntity.php'); 29 require_once ('modules/Contacts/Contacts.php'); 30 require_once ('modules/Potentials/Potentials.php'); 31 require_once ('modules/Calendar/Activity.php'); 32 require_once ('modules/Notes/Notes.php'); 33 require_once ('modules/Emails/Emails.php'); 34 require_once ('include/utils/utils.php'); 35 require_once ('user_privileges/default_module_view.php'); 36 37 // Account is used to store vtiger_account information. 38 class Accounts extends CRMEntity { 39 var $log; 40 var $db; 41 42 var $tab_name = Array('vtiger_crmentity','vtiger_account','vtiger_accountbillads','vtiger_accountshipads','vtiger_accountscf'); 43 var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_account'=>'accountid','vtiger_accountbillads'=>'accountaddressid','vtiger_accountshipads'=>'accountaddressid','vtiger_accountscf'=>'accountid'); 44 45 46 var $column_fields = Array(); 47 48 var $sortby_fields = Array('accountname','city','website','phone','smownerid'); 49 50 51 // This is the list of vtiger_fields that are in the lists. 52 var $list_fields = Array( 53 'Account Name'=>Array('vtiger_account'=>'accountname'), 54 'City'=>Array('vtiger_accountbillads'=>'city'), 55 'Website'=>Array('vtiger_account'=>'website'), 56 'Phone'=>Array('vtiger_account'=> 'phone'), 57 'Assigned To'=>Array('vtiger_crmentity'=>'smownerid') 58 ); 59 60 var $list_fields_name = Array( 61 'Account Name'=>'accountname', 62 'City'=>'bill_city', 63 'Website'=>'website', 64 'Phone'=>'phone', 65 'Assigned To'=>'assigned_user_id' 66 ); 67 var $list_link_field= 'accountname'; 68 69 var $search_fields = Array( 70 'Account Name'=>Array('vtiger_account'=>'accountname'), 71 'City'=>Array('vtiger_accountbillads'=>'city'), 72 ); 73 74 var $search_fields_name = Array( 75 'Account Name'=>'accountname', 76 'City'=>'bill_city', 77 ); 78 79 80 //Added these variables which are used as default order by and sortorder in ListView 81 var $default_order_by = 'accountname'; 82 var $default_sort_order = 'ASC'; 83 84 function Accounts() { 85 $this->log =LoggerManager::getLogger('account'); 86 $this->db = new PearDatabase(); 87 $this->column_fields = getColumnFields('Accounts'); 88 } 89 90 /** Function to handle module specific operations when saving a entity 91 */ 92 function save_module($module) 93 { 94 } 95 96 97 // Mike Crowe Mod --------------------------------------------------------Default ordering for us 98 /** 99 * Function to get sort order 100 * return string $sorder - sortorder string either 'ASC' or 'DESC' 101 */ 102 function getSortOrder() 103 { 104 global $log; 105 $log->debug("Entering getSortOrder() method ..."); 106 if(isset($_REQUEST['sorder'])) 107 $sorder = $_REQUEST['sorder']; 108 else 109 $sorder = (($_SESSION['ACCOUNTS_SORT_ORDER'] != '')?($_SESSION['ACCOUNTS_SORT_ORDER']):($this->default_sort_order)); 110 $log->debug("Exiting getSortOrder() method ..."); 111 return $sorder; 112 } 113 /** 114 * Function to get order by 115 * return string $order_by - fieldname(eg: 'accountname') 116 */ 117 function getOrderBy() 118 { 119 global $log; 120 $log->debug("Entering getOrderBy() method ..."); 121 if (isset($_REQUEST['order_by'])) 122 $order_by = $_REQUEST['order_by']; 123 else 124 $order_by = (($_SESSION['ACCOUNTS_ORDER_BY'] != '')?($_SESSION['ACCOUNTS_ORDER_BY']):($this->default_order_by)); 125 $log->debug("Exiting getOrderBy method ..."); 126 return $order_by; 127 } 128 // Mike Crowe Mod -------------------------------------------------------- 129 130 131 /** Returns a list of the associated contacts 132 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. 133 * All Rights Reserved.. 134 * Contributor(s): ______________________________________.. 135 */ 136 function get_contacts($id) 137 { 138 global $log, $singlepane_view; 139 $log->debug("Entering get_contacts(".$id.") method ..."); 140 global $mod_strings; 141 142 $focus = new Contacts(); 143 144 $button = ''; 145 if(isPermitted("Contacts",1,"") == 'yes') 146 { 147 $button .= '<input title="New Contact" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Contacts\'" type="submit" name="button" value="'.$mod_strings['LBL_NEW_CONTACT'].'"> </td>'; 148 } 149 150 if($singlepane_view == 'true') 151 $returnset = '&return_module=Accounts&return_action=DetailView&return_id='.$id; 152 else 153 $returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id; 154 155 //SQL 156 $query = "SELECT vtiger_contactdetails.*, 157 vtiger_crmentity.crmid, 158 vtiger_crmentity.smownerid, 159 vtiger_users.user_name 160 FROM vtiger_contactdetails 161 INNER JOIN vtiger_crmentity 162 ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid 163 LEFT JOIN vtiger_contactgrouprelation 164 ON vtiger_contactdetails.contactid = vtiger_contactgrouprelation.contactid 165 LEFT JOIN vtiger_groups 166 ON vtiger_groups.groupname = vtiger_contactgrouprelation.groupname 167 LEFT JOIN vtiger_users 168 ON vtiger_crmentity.smownerid = vtiger_users.id 169 WHERE vtiger_crmentity.deleted = 0 170 AND vtiger_contactdetails.accountid = ".$id; 171 $log->debug("Exiting get_contacts method ..."); 172 return GetRelatedList('Accounts','Contacts',$focus,$query,$button,$returnset); 173 } 174 175 /** Returns a list of the associated opportunities 176 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. 177 * All Rights Reserved.. 178 * Contributor(s): ______________________________________.. 179 */ 180 function get_opportunities($id) 181 { 182 global $log, $singlepane_view; 183 $log->debug("Entering get_opportunities(".$id.") method ..."); 184 global $mod_strings; 185 186 $focus = new Potentials(); 187 $button = ''; 188 189 if(isPermitted("Potentials",1,"") == 'yes') 190 { 191 $button .= '<input title="New Potential" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Potentials\'" type="submit" name="button" value="'.$mod_strings['LBL_NEW_POTENTIAL'].'">'; 192 } 193 if($singlepane_view == 'true') 194 $returnset = '&return_module=Accounts&return_action=DetailView&return_id='.$id; 195 else 196 $returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id; 197 198 $query = "SELECT vtiger_potential.potentialid, vtiger_potential.accountid, 199 vtiger_potential.potentialname, vtiger_potential.sales_stage, 200 vtiger_potential.potentialtype, vtiger_potential.amount, 201 vtiger_potential.closingdate, vtiger_potential.potentialtype, 202 vtiger_users.user_name, 203 vtiger_crmentity.crmid, vtiger_crmentity.smownerid 204 FROM vtiger_potential 205 INNER JOIN vtiger_crmentity 206 ON vtiger_crmentity.crmid = vtiger_potential.potentialid 207 LEFT JOIN vtiger_users 208 ON vtiger_crmentity.smownerid = vtiger_users.id 209 LEFT JOIN vtiger_potentialgrouprelation 210 ON vtiger_potential.potentialid = vtiger_potentialgrouprelation.potentialid 211 LEFT JOIN vtiger_groups 212 ON vtiger_groups.groupname = vtiger_potentialgrouprelation.groupname 213 WHERE vtiger_crmentity.deleted = 0 214 AND vtiger_potential.accountid = ".$id; 215 $log->debug("Exiting get_opportunities method ..."); 216 217 return GetRelatedList('Accounts','Potentials',$focus,$query,$button,$returnset); 218 } 219 220 /** Returns a list of the associated tasks 221 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. 222 * All Rights Reserved.. 223 * Contributor(s): ______________________________________.. 224 */ 225 function get_activities($id) 226 { 227 global $log, $singlepane_view; 228 $log->debug("Entering get_activities(".$id.") method ..."); 229 global $mod_strings; 230 231 $focus = new Activity(); 232 $button = ''; 233 if(isPermitted("Calendar",1,"") == 'yes') 234 { 235 236 $button .= '<input title="New Task" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.return_action.value=\'DetailView\';this.form.module.value=\'Calendar\';this.form.return_module.value=\'Accounts\';this.form.activity_mode.value=\'Task\'" type="submit" name="button" value="'.$mod_strings['LBL_NEW_TASK'].'"> '; 237 $button .= '<input title="New Event" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.return_action.value=\'DetailView\';this.form.module.value=\'Calendar\';this.form.return_module.value=\'Accounts\';this.form.activity_mode.value=\'Events\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_EVENT'].'"> </td>'; 238 } 239 if($singlepane_view == 'true') 240 $returnset = '&return_module=Accounts&return_action=DetailView&return_id='.$id; 241 else 242 $returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id; 243 244 $query = "SELECT vtiger_activity.*, 245 vtiger_seactivityrel.*, 246 vtiger_crmentity.crmid, vtiger_crmentity.smownerid, 247 vtiger_crmentity.modifiedtime, 248 vtiger_users.user_name, 249 vtiger_recurringevents.recurringtype 250 FROM vtiger_activity 251 INNER JOIN vtiger_seactivityrel 252 ON vtiger_seactivityrel.activityid = vtiger_activity.activityid 253 INNER JOIN vtiger_crmentity 254 ON vtiger_crmentity.crmid = vtiger_activity.activityid 255 LEFT JOIN vtiger_users 256 ON vtiger_users.id = vtiger_crmentity.smownerid 257 LEFT OUTER JOIN vtiger_recurringevents 258 ON vtiger_recurringevents.activityid = vtiger_activity.activityid 259 LEFT JOIN vtiger_activitygrouprelation 260 ON vtiger_activitygrouprelation.activityid = vtiger_crmentity.crmid 261 LEFT JOIN vtiger_groups 262 ON vtiger_groups.groupname = vtiger_activitygrouprelation.groupname 263 WHERE vtiger_seactivityrel.crmid = ".$id." 264 AND (activitytype='Task' 265 OR activitytype='Call' 266 OR activitytype='Meeting') 267 AND vtiger_crmentity.deleted = 0 268 AND ((vtiger_activity.status IS NOT NULL 269 AND vtiger_activity.status != 'Completed') 270 AND (vtiger_activity.status IS NOT NULL 271 AND vtiger_activity.status != 'Deferred') 272 OR (vtiger_activity.eventstatus !='' 273 AND vtiger_activity.eventstatus != 'Held'))"; 274 $log->debug("Exiting get_activities method ..."); 275 return GetRelatedList('Accounts','Calendar',$focus,$query,$button,$returnset); 276 277 } 278 /** 279 * Function to get Account related Task & Event which have activity type Held, Completed or Deferred. 280 * @param integer $id - accountid 281 * returns related Task or Event record in array format 282 */ 283 function get_history($id) 284 { 285 global $log; 286 $log->debug("Entering get_history(".$id.") method ..."); 287 $query = "SELECT vtiger_activity.activityid, vtiger_activity.subject, 288 vtiger_activity.status, vtiger_activity.eventstatus, 289 vtiger_activity.activitytype, vtiger_activity.date_start, vtiger_activity.due_date, 290 vtiger_crmentity.modifiedtime, vtiger_crmentity.createdtime, 291 vtiger_crmentity.description, 292 vtiger_users.user_name 293 FROM vtiger_activity 294 INNER JOIN vtiger_seactivityrel 295 ON vtiger_seactivityrel.activityid = vtiger_activity.activityid 296 INNER JOIN vtiger_crmentity 297 ON vtiger_crmentity.crmid = vtiger_activity.activityid 298 LEFT JOIN vtiger_activitygrouprelation 299 ON vtiger_activitygrouprelation.activityid = vtiger_activity.activityid 300 LEFT JOIN vtiger_groups 301 ON vtiger_groups.groupname = vtiger_activitygrouprelation.groupname 302 INNER JOIN vtiger_users 303 ON vtiger_crmentity.smcreatorid = vtiger_users.id 304 WHERE (vtiger_activity.activitytype = 'Meeting' 305 OR vtiger_activity.activitytype = 'Call' 306 OR vtiger_activity.activitytype = 'Task') 307 AND (vtiger_activity.status = 'Completed' 308 OR vtiger_activity.status = 'Deferred' 309 OR (vtiger_activity.eventstatus = 'Held' 310 AND vtiger_activity.eventstatus != '')) 311 AND vtiger_seactivityrel.crmid = ".$id; 312 //Don't add order by, because, for security, one more condition will be added with this query in include/RelatedListView.php 313 $log->debug("Exiting get_history method ..."); 314 return getHistory('Accounts',$query,$id); 315 } 316 /** 317 * Function to get Account related Attachments 318 * @param integer $id - accountid 319 * returns related Attachment record in array format 320 */ 321 function get_attachments($id) 322 { 323 global $log; 324 $log->debug("Entering get_attachments(".$id.") method ..."); 325 // Armando Lüscher 18.10.2005 -> §visibleDescription 326 // Desc: Inserted crm2.createdtime, vtiger_notes.notecontent description, vtiger_users.user_name 327 // Inserted inner join vtiger_users on crm2.smcreatorid= vtiger_users.id 328 $query = "SELECT vtiger_notes.title, vtiger_notes.notecontent AS description, 329 vtiger_notes.filename, vtiger_notes.notesid AS crmid, 330 'Notes ' AS ActivityType, 331 vtiger_attachments.type AS FileType, 332 crm2.modifiedtime AS lastmodified, crm2.createdtime, 333 vtiger_seattachmentsrel.attachmentsid, 334 vtiger_users.user_name 335 FROM vtiger_notes 336 INNER JOIN vtiger_senotesrel 337 ON vtiger_senotesrel.notesid = vtiger_notes.notesid 338 INNER JOIN vtiger_crmentity 339 ON vtiger_crmentity.crmid = vtiger_senotesrel.crmid 340 INNER JOIN vtiger_crmentity crm2 341 ON crm2.crmid = vtiger_notes.notesid 342 AND crm2.deleted = 0 343 LEFT JOIN vtiger_seattachmentsrel 344 ON vtiger_seattachmentsrel.crmid = vtiger_notes.notesid 345 LEFT JOIN vtiger_attachments 346 ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid 347 INNER JOIN vtiger_users 348 ON crm2.smcreatorid = vtiger_users.id 349 WHERE vtiger_crmentity.crmid = ".$id." 350 UNION ALL 351 SELECT vtiger_attachments.description AS title, vtiger_attachments.description, 352 vtiger_attachments.name AS filename, 353 vtiger_seattachmentsrel.attachmentsid AS crmid, 354 'Attachments' AS ActivityType, 355 vtiger_attachments.type AS FileType, 356 crm2.modifiedtime AS lastmodified, crm2.createdtime, 357 vtiger_attachments.attachmentsid, 358 vtiger_users.user_name 359 FROM vtiger_attachments 360 INNER JOIN vtiger_seattachmentsrel 361 ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid 362 INNER JOIN vtiger_crmentity 363 ON vtiger_crmentity.crmid = vtiger_seattachmentsrel.crmid 364 INNER JOIN vtiger_crmentity crm2 365 ON crm2.crmid = vtiger_attachments.attachmentsid 366 INNER JOIN vtiger_users 367 ON crm2.smcreatorid = vtiger_users.id 368 WHERE vtiger_crmentity.crmid = ".$id." 369 ORDER BY createdtime DESC"; 370 $log->debug("Exiting get_attachments method ..."); 371 return getAttachmentsAndNotes('Accounts',$query,$id); 372 } 373 /** 374 * Function to get Account related Quotes 375 * @param integer $id - accountid 376 * returns related Quotes record in array format 377 */ 378 function get_quotes($id) 379 { 380 global $log, $singlepane_view; 381 $log->debug("Entering get_quotes(".$id.") method ..."); 382 global $app_strings; 383 require_once ('modules/Quotes/Quotes.php'); 384 385 $focus = new Quotes(); 386 387 $button = ''; 388 if(isPermitted("Quotes",1,"") == 'yes') 389 { 390 $button .= '<input title="'.$app_strings['LBL_NEW_QUOTE_BUTTON_TITLE'].'" accessyKey="'.$app_strings['LBL_NEW_QUOTE_BUTTON_KEY'].'" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Quotes\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_QUOTE_BUTTON'].'"> </td>'; 391 } 392 393 if($singlepane_view == 'true') 394 $returnset = '&return_module=Accounts&return_action=DetailView&return_id='.$id; 395 else 396 $returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id; 397 398 $query = "SELECT vtiger_users.user_name, 399 vtiger_groups.groupname, 400 vtiger_crmentity.*, 401 vtiger_quotes.*, 402 vtiger_potential.potentialname, 403 vtiger_account.accountname 404 FROM vtiger_quotes 405 INNER JOIN vtiger_crmentity 406 ON vtiger_crmentity.crmid = vtiger_quotes.quoteid 407 LEFT OUTER JOIN vtiger_account 408 ON vtiger_account.accountid = vtiger_quotes.accountid 409 LEFT OUTER JOIN vtiger_potential 410 ON vtiger_potential.potentialid = vtiger_quotes.potentialid 411 LEFT JOIN vtiger_quotegrouprelation 412 ON vtiger_quotes.quoteid = vtiger_quotegrouprelation.quoteid 413 LEFT JOIN vtiger_groups 414 ON vtiger_groups.groupname = vtiger_quotegrouprelation.groupname 415 LEFT JOIN vtiger_users 416 ON vtiger_crmentity.smownerid = vtiger_users.id 417 WHERE vtiger_crmentity.deleted = 0 418 AND vtiger_account.accountid = ".$id; 419 $log->debug("Exiting get_quotes method ..."); 420 return GetRelatedList('Accounts','Quotes',$focus,$query,$button,$returnset); 421 } 422 /** 423 * Function to get Account related Invoices 424 * @param integer $id - accountid 425 * returns related Invoices record in array format 426 */ 427 function get_invoices($id) 428 { 429 global $log, $singlepane_view; 430 $log->debug("Entering get_invoices(".$id.") method ..."); 431 global $app_strings; 432 require_once ('modules/Invoice/Invoice.php'); 433 434 $focus = new Invoice(); 435 436 $button = ''; 437 if(isPermitted("Invoice",1,"") == 'yes') 438 { 439 $button .= '<input title="'.$app_strings['LBL_NEW_INVOICE_BUTTON_TITLE'].'" accessyKey="'.$app_strings['LBL_NEW_INVOICE_BUTTON_KEY'].'" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Invoice\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_INVOICE_BUTTON'].'"> </td>'; 440 } 441 if($singlepane_view == 'true') 442 $returnset = '&return_module=Accounts&return_action=DetailView&return_id='.$id; 443 else 444 $returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id; 445 446 $query = "SELECT vtiger_users.user_name, 447 vtiger_groups.groupname, 448 vtiger_crmentity.*, 449 vtiger_invoice.*, 450 vtiger_account.accountname, 451 vtiger_salesorder.subject AS salessubject 452 FROM vtiger_invoice 453 INNER JOIN vtiger_crmentity 454 ON vtiger_crmentity.crmid = vtiger_invoice.invoiceid 455 LEFT OUTER JOIN vtiger_account 456 ON vtiger_account.accountid = vtiger_invoice.accountid 457 LEFT OUTER JOIN vtiger_salesorder 458 ON vtiger_salesorder.salesorderid = vtiger_invoice.salesorderid 459 LEFT JOIN vtiger_invoicegrouprelation 460 ON vtiger_invoice.invoiceid = vtiger_invoicegrouprelation.invoiceid 461 LEFT JOIN vtiger_groups 462 ON vtiger_groups.groupname = vtiger_invoicegrouprelation.groupname 463 LEFT JOIN vtiger_users 464 ON vtiger_crmentity.smownerid = vtiger_users.id 465 WHERE vtiger_crmentity.deleted = 0 466 AND vtiger_account.accountid = ".$id; 467 $log->debug("Exiting get_invoices method ..."); 468 return GetRelatedList('Accounts','Invoice',$focus,$query,$button,$returnset); 469 } 470 471 /** 472 * Function to get Account related SalesOrder 473 * @param integer $id - accountid 474 * returns related SalesOrder record in array format 475 */ 476 function get_salesorder($id) 477 { 478 global $log, $singlepane_view; 479 $log->debug("Entering get_salesorder(".$id.") method ..."); 480 require_once ('modules/SalesOrder/SalesOrder.php'); 481 global $app_strings; 482 483 $focus = new SalesOrder(); 484 485 $button = ''; 486 if(isPermitted("SalesOrder",1,"") == 'yes') 487 { 488 $button .= '<input title="'.$app_strings['LBL_NEW_SORDER_BUTTON_TITLE'].'" accessyKey="'.$app_strings['LBL_NEW_SORDER_BUTTON_KEY'].'" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'SalesOrder\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_SORDER_BUTTON'].'"> </td>'; 489 } 490 491 if($singlepane_view == 'true') 492 $returnset = '&return_module=Accounts&return_action=DetailView&return_id='.$id; 493 else 494 $returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id; 495 496 $query = "SELECT vtiger_crmentity.*, 497 vtiger_salesorder.*, 498 vtiger_quotes.subject AS quotename, 499 vtiger_account.accountname, 500 vtiger_users.user_name, 501 vtiger_groups.groupname 502 FROM vtiger_salesorder 503 INNER JOIN vtiger_crmentity 504 ON vtiger_crmentity.crmid = vtiger_salesorder.salesorderid 505 LEFT OUTER JOIN vtiger_quotes 506 ON vtiger_quotes.quoteid = vtiger_salesorder.quoteid 507 LEFT OUTER JOIN vtiger_account 508 ON vtiger_account.accountid = vtiger_salesorder.accountid 509 LEFT JOIN vtiger_sogrouprelation 510 ON vtiger_salesorder.salesorderid = vtiger_sogrouprelation.salesorderid 511 LEFT JOIN vtiger_groups 512 ON vtiger_groups.groupname = vtiger_sogrouprelation.groupname 513 LEFT JOIN vtiger_users 514 ON vtiger_crmentity.smownerid = vtiger_users.id 515 WHERE vtiger_crmentity.deleted = 0 516 AND vtiger_salesorder.accountid = ".$id; 517 $log->debug("Exiting get_salesorder method ..."); 518 return GetRelatedList('Accounts','SalesOrder',$focus,$query,$button,$returnset); 519 } 520 /** 521 * Function to get Account related Tickets 522 * @param integer $id - accountid 523 * returns related Ticket record in array format 524 */ 525 function get_tickets($id) 526 { 527 global $log, $singlepane_view; 528 $log->debug("Entering get_tickets(".$id.") method ..."); 529 global $app_strings; 530 531 $focus = new HelpDesk(); 532 $button = ''; 533 534 $button .= '<td valign="bottom" align="right"><input title="New TICKET" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'HelpDesk\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_TICKET'].'"> </td>'; 535 if($singlepane_view == 'true') 536 $returnset = '&return_module=Accounts&return_action=DetailView&return_id='.$id; 537 else 538 $returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id; 539 540 $query = "SELECT vtiger_users.user_name, vtiger_users.id, 541 vtiger_troubletickets.title, vtiger_troubletickets.ticketid AS crmid, 542 vtiger_troubletickets.status, vtiger_troubletickets.priority, 543 vtiger_troubletickets.parent_id, 544 vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime 545 FROM vtiger_troubletickets 546 INNER JOIN vtiger_crmentity 547 ON vtiger_crmentity.crmid = vtiger_troubletickets.ticketid 548 LEFT JOIN vtiger_account 549 ON vtiger_account.accountid = vtiger_troubletickets.parent_id 550 LEFT JOIN vtiger_contactdetails 551 ON vtiger_contactdetails.contactid=vtiger_troubletickets.parent_id 552 LEFT JOIN vtiger_users 553 ON vtiger_users.id=vtiger_crmentity.smownerid 554 LEFT JOIN vtiger_ticketgrouprelation 555 ON vtiger_troubletickets.ticketid = vtiger_ticketgrouprelation.ticketid 556 LEFT JOIN vtiger_groups 557 ON vtiger_groups.groupname = vtiger_ticketgrouprelation.groupname 558 WHERE vtiger_troubletickets.parent_id=".$id." or " ; 559 560 $query .= "vtiger_troubletickets.parent_id in(SELECT vtiger_contactdetails.contactid 561 FROM vtiger_contactdetails 562 INNER JOIN vtiger_crmentity 563 ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid 564 LEFT JOIN vtiger_contactgrouprelation 565 ON vtiger_contactdetails.contactid = vtiger_contactgrouprelation.contactid 566 LEFT JOIN vtiger_groups 567 ON vtiger_groups.groupname = vtiger_contactgrouprelation.groupname 568 LEFT JOIN vtiger_users 569 ON vtiger_crmentity.smownerid = vtiger_users.id 570 WHERE vtiger_crmentity.deleted = 0 571 AND vtiger_contactdetails.accountid = ".$id; 572 573 574 //Appending the security parameter 575 global $current_user; 576 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 577 require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); 578 $tab_id=getTabid('Contacts'); 579 if($is_admin==false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $defaultOrgSharingPermission[$tab_id] == 3) 580 { 581 $sec_parameter=getListViewSecurityParameter('Contacts'); 582 $query .= ' '.$sec_parameter; 583 584 } 585 586 $query .= ") "; 587 588 /* 589 $query .= " UNION ALL 590 SELECT vtiger_users.user_name, vtiger_users.id, 591 vtiger_troubletickets.title, vtiger_troubletickets.ticketid AS crmid, 592 vtiger_troubletickets.status, vtiger_troubletickets.priority, 593 vtiger_troubletickets.parent_id, 594 vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime 595 FROM vtiger_troubletickets 596 INNER JOIN vtiger_crmentity 597 ON vtiger_crmentity.crmid = vtiger_troubletickets.ticketid 598 LEFT JOIN vtiger_contactdetails 599 ON vtiger_contactdetails.contactid = vtiger_troubletickets.parent_id 600 LEFT JOIN vtiger_account 601 ON vtiger_account.accountid = vtiger_contactdetails.accountid 602 LEFT JOIN vtiger_users 603 ON vtiger_users.id = vtiger_crmentity.smownerid 604 LEFT JOIN vtiger_ticketgrouprelation 605 ON vtiger_troubletickets.ticketid = vtiger_ticketgrouprelation.ticketid 606 LEFT JOIN vtiger_groups 607 ON vtiger_groups.groupname = vtiger_ticketgrouprelation.groupname 608 WHERE vtiger_account.accountid = ".$id; 609 */ 610 $log->debug("Exiting get_tickets method ..."); 611 return GetRelatedList('Accounts','HelpDesk',$focus,$query,$button,$returnset); 612 } 613 /** 614 * Function to get Account related Products 615 * @param integer $id - accountid 616 * returns related Products record in array format 617 */ 618 function get_products($id) 619 { 620 global $log, $singlepane_view; 621 $log->debug("Entering get_products(".$id.") method ..."); 622 require_once ('modules/Products/Products.php'); 623 global $app_strings; 624 625 $focus = new Products(); 626 627 $button = ''; 628 629 if(isPermitted("Products",1,"") == 'yes') 630 { 631 632 633 $button .= '<input title="New Product" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Products\';this.form.return_module.value=\'Accounts\';this.form.return_action.value=\'DetailView\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_PRODUCT'].'"> '; 634 } 635 if($singlepane_view == 'true') 636 $returnset = '&return_module=Accounts&return_action=DetailView&return_id='.$id; 637 else 638 $returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id; 639 640 $query = "SELECT vtiger_products.productid, vtiger_products.productname, 641 vtiger_products.productcode, vtiger_products.commissionrate, 642 vtiger_products.qty_per_unit, vtiger_products.unit_price, 643 vtiger_crmentity.crmid, vtiger_crmentity.smownerid 644 FROM vtiger_products 645 INNER JOIN vtiger_seproductsrel 646 ON vtiger_products.productid = vtiger_seproductsrel.productid 647 INNER JOIN vtiger_crmentity 648 ON vtiger_crmentity.crmid = vtiger_products.productid 649 INNER JOIN vtiger_account 650 ON vtiger_account.accountid = vtiger_seproductsrel.crmid 651 WHERE vtiger_account.accountid = ".$id." 652 AND vtiger_crmentity.deleted = 0"; 653 $log->debug("Exiting get_products method ..."); 654 return GetRelatedList('Accounts','Products',$focus,$query,$button,$returnset); 655 } 656 657 /** Function to export the account records in CSV Format 658 * @param reference variable - order by is passed when the query is executed 659 * @param reference variable - where condition is passed when the query is executed 660 * Returns Export Accounts Query. 661 */ 662 function create_export_query(&$order_by, &$where) 663 { 664 global $log; 665 global $current_user; 666 $log->debug("Entering create_export_query(".$order_by.",".$where.") method ..."); 667 668 include ("include/utils/ExportUtils.php"); 669 670 //To get the Permitted fields query and the permitted fields list 671 $sql = getPermittedFieldsQuery("Accounts", "detail_view"); 672 $fields_list = getFieldsListFromQuery($sql); 673 674 $query = "SELECT $fields_list FROM ".$this->entity_table." 675 INNER JOIN vtiger_account 676 ON vtiger_crmentity.crmid = vtiger_account.accountid 677 LEFT JOIN vtiger_accountbillads 678 ON vtiger_account.accountid = vtiger_accountbillads.accountaddressid 679 LEFT JOIN vtiger_accountshipads 680 ON vtiger_account.accountid = vtiger_accountshipads.accountaddressid 681 LEFT JOIN vtiger_accountscf 682 ON vtiger_accountscf.accountid = vtiger_account.accountid 683 LEFT JOIN vtiger_accountgrouprelation 684 ON vtiger_accountscf.accountid = vtiger_accountgrouprelation.accountid 685 LEFT JOIN vtiger_groups 686 ON vtiger_groups.groupname = vtiger_accountgrouprelation.groupname 687 LEFT JOIN vtiger_users 688 ON vtiger_crmentity.smownerid = vtiger_users.id 689 LEFT JOIN vtiger_account vtiger_account2 690 ON vtiger_account2.accountid = vtiger_account.parentid 691 ";//vtiger_account2 is added to get the Member of account 692 693 694 $where_auto = " vtiger_users.status = 'Active' 695 AND vtiger_crmentity.deleted = 0 "; 696 697 if($where != "") 698 $query .= "WHERE ($where) AND ".$where_auto; 699 else 700 $query .= "WHERE ".$where_auto; 701 702 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 703 require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); 704 //we should add security check when the user has Private Access 705 if($is_admin==false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $defaultOrgSharingPermission[6] == 3) 706 { 707 //Added security check to get the permitted records only 708 $query = $query." ".getListViewSecurityParameter("Accounts"); 709 } 710 711 if(!empty($order_by)) 712 $query .= " ORDER BY $order_by"; 713 714 $log->debug("Exiting create_export_query method ..."); 715 return $query; 716 } 717 718 /** Function to get the Columnnames of the Account Record 719 * Used By vtigerCRM Word Plugin 720 * Returns the Merge Fields for Word Plugin 721 */ 722 function getColumnNames_Acnt() 723 { 724 global $log,$current_user; 725 $log->debug("Entering getColumnNames_Acnt() method ..."); 726 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 727 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) 728 { 729 $sql1 = "SELECT fieldlabel FROM vtiger_field WHERE tabid = 6"; 730 }else 731 { 732 $profileList = getCurrentUserProfileList(); 733 $sql1 = "select fieldlabel from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=6 and vtiger_field.displaytype in (1,2,4) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_profile2field.profileid in ".$profileList; 734 } 735 $result = $this->db->query($sql1); 736 $numRows = $this->db->num_rows($result); 737 for($i=0; $i < $numRows;$i++) 738 { 739 $custom_fields[$i] = $this->db->query_result($result,$i,"fieldlabel"); 740 $custom_fields[$i] = ereg_replace(" ","",$custom_fields[$i]); 741 $custom_fields[$i] = strtoupper($custom_fields[$i]); 742 } 743 $mergeflds = $custom_fields; 744 $log->debug("Exiting getColumnNames_Acnt method ..."); 745 return $mergeflds; 746 } 747 748 } 749 750 ?>
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 |