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