[ 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/Contacts/Contact.php,v 1.70 2005/04/27 11:21:49 rank Exp $ 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 require_once ('data/CRMEntity.php'); 27 require_once ('include/utils/utils.php'); 28 require_once ('modules/Potentials/Opportunity.php'); 29 require_once ('modules/Calendar/Activity.php'); 30 require_once ('modules/Campaigns/Campaign.php'); 31 require_once ('modules/Notes/Note.php'); 32 require_once ('modules/Emails/Email.php'); 33 require_once ('modules/HelpDesk/HelpDesk.php'); 34 require_once ('user_privileges/default_module_view.php'); 35 36 37 // Contact is used to store customer information. 38 class Contact extends CRMEntity { 39 var $log; 40 var $db; 41 42 var $table_name = "contactdetails"; 43 var $tab_name = Array('vtiger_crmentity','vtiger_contactdetails','vtiger_contactaddress','vtiger_contactsubdetails','vtiger_contactscf','vtiger_customerdetails','vtiger_attachments'); 44 var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_contactdetails'=>'contactid','vtiger_contactaddress'=>'contactaddressid','vtiger_contactsubdetails'=>'contactsubscriptionid','vtiger_contactscf'=>'contactid','vtiger_customerdetails'=>'customerid','vtiger_attachments'=>'attachmentsid'); 45 46 var $module_id = "contactid"; 47 var $object_name = "Contact"; 48 49 var $new_schema = true; 50 51 var $column_fields = Array(); 52 53 var $sortby_fields = Array('lastname','firstname','title','email','phone','smownerid','accountid'); 54 55 var $list_link_field= 'lastname'; 56 57 // This is the list of vtiger_fields that are in the lists. 58 var $list_fields = Array( 59 'Last Name' => Array('contactdetails'=>'lastname'), 60 'First Name' => Array('contactdetails'=>'firstname'), 61 'Title' => Array('contactdetails'=>'title'), 62 'Account Name' => Array('account'=>'accountname'), 63 'Email' => Array('contactdetails'=>'email'), 64 'Phone' => Array('contactdetails'=>'phone'), 65 'Assigned To' => Array('crmentity'=>'smownerid') 66 ); 67 68 var $range_fields = Array( 69 'first_name', 70 'last_name', 71 'primary_address_city', 72 'account_name', 73 'account_id', 74 'id', 75 'email1', 76 'salutation', 77 'title', 78 'phone_mobile', 79 'reports_to_name', 80 'primary_address_street', 81 'primary_address_city', 82 'primary_address_state', 83 'primary_address_postalcode', 84 'primary_address_country', 85 'alt_address_city', 86 'alt_address_street', 87 'alt_address_city', 88 'alt_address_state', 89 'alt_address_postalcode', 90 'alt_address_country', 91 'office_phone', 92 'home_phone', 93 'other_phone', 94 'fax', 95 'department', 96 'birthdate', 97 'assistant_name', 98 'assistant_phone'); 99 100 101 var $list_fields_name = Array( 102 'Last Name' => 'lastname', 103 'First Name' => 'firstname', 104 'Title' => 'title', 105 'Account Name' => 'accountid', 106 'Email' => 'email', 107 'Phone' => 'phone', 108 'Assigned To' => 'assigned_user_id' 109 ); 110 111 var $search_fields = Array( 112 'Name' => Array('contactdetails'=>'lastname'), 113 'Title' => Array('contactdetails'=>'title') 114 ); 115 116 var $search_fields_name = Array( 117 'Name' => 'lastname', 118 'Title' => 'title' 119 ); 120 121 // This is the list of vtiger_fields that are required 122 var $required_fields = array("lastname"=>1); 123 124 //Added these variables which are used as default order by and sortorder in ListView 125 var $default_order_by = 'lastname'; 126 var $default_sort_order = 'ASC'; 127 128 function Contact() { 129 $this->log = LoggerManager::getLogger('contact'); 130 $this->db = new PearDatabase(); 131 $this->column_fields = getColumnFields('Contacts'); 132 } 133 134 // Mike Crowe Mod --------------------------------------------------------Default ordering for us 135 /** 136 * Function to get sort order 137 * return string $sorder - sortorder string either 'ASC' or 'DESC' 138 */ 139 function getSortOrder() 140 { 141 global $log; 142 $log->debug("Entering getSortOrder() method ..."); 143 if(isset($_REQUEST['sorder'])) 144 $sorder = $_REQUEST['sorder']; 145 else 146 $sorder = (($_SESSION['CONTACTS_SORT_ORDER'] != '')?($_SESSION['CONTACTS_SORT_ORDER']):($this->default_sort_order)); 147 $log->debug("Exiting getSortOrder method ..."); 148 return $sorder; 149 } 150 /** 151 * Function to get order by 152 * return string $order_by - fieldname(eg: 'Contactname') 153 */ 154 function getOrderBy() 155 { 156 global $log; 157 $log->debug("Entering getOrderBy() method ..."); 158 if (isset($_REQUEST['order_by'])) 159 $order_by = $_REQUEST['order_by']; 160 else 161 $order_by = (($_SESSION['CONTACTS_ORDER_BY'] != '')?($_SESSION['CONTACTS_ORDER_BY']):($this->default_order_by)); 162 $log->debug("Exiting getOrderBy method ..."); 163 return $order_by; 164 } 165 // Mike Crowe Mod -------------------------------------------------------- 166 /** Function to get the number of Contacts assigned to a particular User. 167 * @param varchar $user name - Assigned to User 168 * Returns the count of contacts assigned to user. 169 */ 170 function getCount($user_name) 171 { 172 global $log; 173 $log->debug("Entering getCount(".$user_name.") method ..."); 174 $query = "select count(*) from vtiger_contactdetails inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid inner join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid where user_name='" .$user_name ."' and vtiger_crmentity.deleted=0"; 175 176 $result = $this->db->query($query,true,"Error retrieving contacts count"); 177 $rows_found = $this->db->getRowCount($result); 178 $row = $this->db->fetchByAssoc($result, 0); 179 180 181 $log->debug("Exiting getCount method ..."); 182 return $row["count(*)"]; 183 } 184 /** Function to get the Contact Details assigned to a given User ID which has a valid Email Address. 185 * @param varchar $user_name - User Name (eg. Admin) 186 * @param varchar $email_address - Email Addr of each contact record. 187 * Returns the query. 188 */ 189 function get_contacts1($user_name,$email_address) 190 { 191 global $log; 192 $log->debug("Entering get_contacts1(".$user_name.",".$email_address.") method ..."); 193 $query = "select vtiger_users.user_name, vtiger_contactdetails.lastname last_name,vtiger_contactdetails.firstname first_name,vtiger_contactdetails.contactid as id, vtiger_contactdetails.salutation as salutation, vtiger_contactdetails.email as email1,vtiger_contactdetails.title as title,vtiger_contactdetails.mobile as phone_mobile,vtiger_account.accountname as account_name,vtiger_account.accountid as account_id from vtiger_contactdetails inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid inner join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid left join vtiger_account on vtiger_account.accountid=vtiger_contactdetails.accountid left join vtiger_contactaddress on vtiger_contactaddress.contactaddressid=vtiger_contactdetails.contactid left join vtiger_contactgrouprelation on vtiger_contactdetails.contactid=vtiger_contactgrouprelation.contactid where user_name='" .$user_name ."' and vtiger_crmentity.deleted=0 and vtiger_contactdetails.email like '%" .$email_address ."%' limit 50"; 194 195 $log->debug("Exiting get_contacts1 method ..."); 196 return $this->process_list_query1($query); 197 } 198 /** Function to get the Contact Details assigned to a particular User based on the starting count and the number of subsequent records. 199 * @param varchar $user_name - Assigned User 200 * @param integer $from_index - Initial record number to be displayed 201 * @param integer $offset - Count of the subsequent records to be displayed. 202 * Returns Query. 203 */ 204 function get_contacts($user_name,$from_index,$offset) 205 { 206 global $log; 207 $log->debug("Entering get_contacts(".$user_name.",".$from_index.",".$offset.") method ..."); 208 $query = "select vtiger_users.user_name,vtiger_groups.groupname,vtiger_contactdetails.department department, vtiger_contactdetails.phone office_phone, vtiger_contactdetails.fax fax, vtiger_contactsubdetails.assistant assistant_name, vtiger_contactsubdetails.otherphone other_phone, vtiger_contactsubdetails.homephone home_phone,vtiger_contactsubdetails.birthday birthdate, vtiger_contactdetails.lastname last_name,vtiger_contactdetails.firstname first_name,vtiger_contactdetails.contactid as id, vtiger_contactdetails.salutation as salutation, vtiger_contactdetails.email as email1,vtiger_contactdetails.title as title,vtiger_contactdetails.mobile as phone_mobile,vtiger_account.accountname as account_name,vtiger_account.accountid as account_id, vtiger_contactaddress.mailingcity as primary_address_city,vtiger_contactaddress.mailingstreet as primary_address_street, vtiger_contactaddress.mailingcountry as primary_address_country,vtiger_contactaddress.mailingstate as primary_address_state, vtiger_contactaddress.mailingzip as primary_address_postalcode, vtiger_contactaddress.othercity as alt_address_city,vtiger_contactaddress.otherstreet as alt_address_street, vtiger_contactaddress.othercountry as alt_address_country,vtiger_contactaddress.otherstate as alt_address_state, vtiger_contactaddress.otherzip as alt_address_postalcode from vtiger_contactdetails inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid inner join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid left join vtiger_account on vtiger_account.accountid=vtiger_contactdetails.accountid left join vtiger_contactaddress on vtiger_contactaddress.contactaddressid=vtiger_contactdetails.contactid left join vtiger_contactsubdetails on vtiger_contactsubdetails.contactsubscriptionid = vtiger_contactdetails.contactid left join vtiger_contactgrouprelation on vtiger_contactdetails.contactid=vtiger_contactgrouprelation.contactid left join vtiger_groups on vtiger_groups.groupname=vtiger_contactgrouprelation.groupname left join vtiger_users on vtiger_crmentity.smownerid=vtiger_users.id where user_name='" .$user_name ."' and vtiger_crmentity.deleted=0 limit " .$from_index ."," .$offset; 209 210 $log->debug("Exiting get_contacts method ..."); 211 return $this->process_list_query1($query); 212 } 213 214 215 /** Function to process list query for a given query 216 * @param $query 217 * Returns the results of query in array format 218 */ 219 function process_list_query1($query) 220 { 221 global $log; 222 $log->debug("Entering process_list_query1(".$query.") method ..."); 223 224 $result =& $this->db->query($query,true,"Error retrieving $this->object_name list: "); 225 $list = Array(); 226 $rows_found = $this->db->getRowCount($result); 227 if($rows_found != 0) 228 { 229 $contact = Array(); 230 for($index = 0 , $row = $this->db->fetchByAssoc($result, $index); $row && $index <$rows_found;$index++, $row = $this->db->fetchByAssoc($result, $index)) 231 232 { 233 foreach($this->range_fields as $columnName) 234 { 235 if (isset($row[$columnName])) { 236 237 $contact[$columnName] = $row[$columnName]; 238 } 239 else 240 { 241 $contact[$columnName] = ""; 242 } 243 } 244 // TODO OPTIMIZE THE QUERY ACCOUNT NAME AND ID are set separetly for every vtiger_contactdetails and hence 245 // vtiger_account query goes for ecery single vtiger_account row 246 247 $list[] = $contact; 248 } 249 } 250 251 $response = Array(); 252 $response['list'] = $list; 253 $response['row_count'] = $rows_found; 254 $response['next_offset'] = $next_offset; 255 $response['previous_offset'] = $previous_offset; 256 257 258 $log->debug("Exiting process_list_query1 method ..."); 259 return $response; 260 } 261 262 263 /** Function to process list query for Plugin with Security Parameters for a given query 264 * @param $query 265 * Returns the results of query in array format 266 */ 267 function plugin_process_list_query($query) 268 { 269 global $log,$adb,$current_user; 270 $log->debug("Entering process_list_query1(".$query.") method ..."); 271 $permitted_field_lists = Array(); 272 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 273 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) 274 { 275 $sql1 = "select columnname from vtiger_field where tabid=4 and block <> 75"; 276 }else 277 { 278 $profileList = getCurrentUserProfileList(); 279 $sql1 = "select columnname 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=4 and vtiger_field.block <> 6 and vtiger_field.block <> 75 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; 280 } 281 $result1 = $this->db->query($sql1); 282 for($i=0;$i < $adb->num_rows($result1);$i++) 283 { 284 $permitted_field_lists[] = $adb->query_result($result1,$i,'columnname'); 285 } 286 287 $result =& $this->db->query($query,true,"Error retrieving $this->object_name list: "); 288 $list = Array(); 289 $rows_found = $this->db->getRowCount($result); 290 if($rows_found != 0) 291 { 292 for($index = 0 , $row = $this->db->fetchByAssoc($result, $index); $row && $index <$rows_found;$index++, $row = $this->db->fetchByAssoc($result, $index)) 293 { 294 $contact = Array(); 295 foreach($permitted_field_lists as $columnName) 296 { 297 if ($columnName == "lastname" || $columnName == "firstname" || $columnName == "email") 298 { 299 $contact[$columnName] = $row[$columnName]; 300 } 301 else 302 { 303 $contact[$columnName] = ""; 304 } 305 } 306 if(in_array("accountid",$permitted_field_lists)) 307 { 308 $contact[accountname] = $row[accountname]; 309 $contact[account_id] = $row[accountid]; 310 } 311 $contact[contactid] = $row[contactid]; 312 $list[] = $contact; 313 } 314 } 315 316 $response = Array(); 317 $response['list'] = $list; 318 $response['row_count'] = $rows_found; 319 $response['next_offset'] = $next_offset; 320 $response['previous_offset'] = $previous_offset; 321 $log->debug("Exiting process_list_query1 method ..."); 322 return $response; 323 } 324 325 326 /** Returns a list of the associated opportunities 327 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. 328 * All Rights Reserved.. 329 * Contributor(s): ______________________________________.. 330 */ 331 function get_opportunities($id) 332 { 333 global $log, $singlepane_view; 334 $log->debug("Entering get_opportunities(".$id.") method ..."); 335 global $mod_strings; 336 337 $focus = new Potential(); 338 $button = ''; 339 340 if(isPermitted("Potentials",1,"") == 'yes') 341 { 342 343 $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'].'"> '; 344 } 345 if($singlepane_view == 'true') 346 $returnset = '&return_module=Contacts&return_action=DetailView&return_id='.$id; 347 else 348 $returnset = '&return_module=Contacts&return_action=CallRelatedList&return_id='.$id; 349 350 $log->info("Potential Related List for Contact Displayed"); 351 352 // First, get the list of IDs. 353 $query = 'select vtiger_users.user_name,vtiger_groups.groupname,vtiger_contactdetails.accountid, vtiger_contactdetails.contactid , vtiger_potential.potentialid, vtiger_potential.potentialname, vtiger_potential.potentialtype, vtiger_potential.sales_stage, vtiger_potential.amount, vtiger_potential.closingdate, vtiger_crmentity.crmid, vtiger_crmentity.smownerid from vtiger_contactdetails inner join vtiger_potential on vtiger_contactdetails.accountid = vtiger_potential.accountid inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_potential.potentialid left join vtiger_potentialgrouprelation on vtiger_potential.potentialid=vtiger_potentialgrouprelation.potentialid left join vtiger_groups on vtiger_groups.groupname=vtiger_potentialgrouprelation.groupname left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid where vtiger_contactdetails.contactid = '.$id.' and vtiger_crmentity.deleted=0'; 354 if($this->column_fields['account_id'] != 0) 355 $log->debug("Exiting get_opportunities method ..."); 356 return GetRelatedList('Contacts','Potentials',$focus,$query,$button,$returnset); 357 } 358 359 360 /** Returns a list of the associated tasks 361 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. 362 * All Rights Reserved.. 363 * Contributor(s): ______________________________________.. 364 */ 365 function get_activities($id) 366 { 367 global $log, $singlepane_view; 368 $log->debug("Entering get_activities(".$id.") method ..."); 369 global $mod_strings; 370 371 $focus = new Activity(); 372 373 $button = ''; 374 375 if(isPermitted("Calendar",1,"") == 'yes') 376 { 377 $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.activity_mode.value=\'Task\';this.form.return_module.value=\'Contacts\'" type="submit" name="button" value="'.$mod_strings['LBL_NEW_TASK'].'"> '; 378 $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=\'Contacts\';this.form.activity_mode.value=\'Events\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_EVENT'].'"> '; 379 } 380 if($singlepane_view == 'true') 381 $returnset = '&return_module=Contacts&return_action=DetailView&return_id='.$id; 382 else 383 $returnset = '&return_module=Contacts&return_action=CallRelatedList&return_id='.$id; 384 385 $log->info("Activity Related List for Contact Displayed"); 386 387 $query = "SELECT vtiger_users.user_name,vtiger_contactdetails.lastname, vtiger_contactdetails.firstname, vtiger_activity.activityid , vtiger_activity.subject, vtiger_activity.activitytype, vtiger_activity.date_start, vtiger_activity.due_date, vtiger_cntactivityrel.contactid, vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime, vtiger_recurringevents.recurringtype from vtiger_contactdetails inner join vtiger_cntactivityrel on vtiger_cntactivityrel.contactid = vtiger_contactdetails.contactid inner join vtiger_activity on vtiger_cntactivityrel.activityid=vtiger_activity.activityid inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_cntactivityrel.activityid left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid left outer join vtiger_recurringevents on vtiger_recurringevents.activityid=vtiger_activity.activityid left join vtiger_activitygrouprelation on vtiger_activitygrouprelation.activityid=vtiger_crmentity.crmid left join vtiger_groups on vtiger_groups.groupname=vtiger_activitygrouprelation.groupname where vtiger_contactdetails.contactid=".$id." and vtiger_crmentity.deleted = 0 and (vtiger_activity.activitytype = 'Meeting' or vtiger_activity.activitytype='Call' or vtiger_activity.activitytype='Task') AND ( vtiger_activity.status is NULL OR vtiger_activity.status != 'Completed' ) and ( vtiger_activity.eventstatus is NULL OR vtiger_activity.eventstatus != 'Held') "; //recurring type is added in Query -Jaguar 388 $log->debug("Exiting get_activities method ..."); 389 return GetRelatedList('Contacts','Calendar',$focus,$query,$button,$returnset); 390 391 } 392 /** 393 * Function to get Contact related Task & Event which have activity type Held, Completed or Deferred. 394 * @param integer $id - contactid 395 * returns related Task or Event record in array format 396 */ 397 function get_history($id) 398 { 399 global $log; 400 $log->debug("Entering get_history(".$id.") method ..."); 401 $query = "SELECT vtiger_activity.activityid, vtiger_activity.subject, vtiger_activity.status, vtiger_activity.eventstatus, 402 vtiger_activity.activitytype, vtiger_contactdetails.contactid, vtiger_contactdetails.firstname, 403 vtiger_contactdetails.lastname, vtiger_crmentity.modifiedtime, 404 vtiger_crmentity.createdtime, vtiger_crmentity.description, vtiger_users.user_name 405 from vtiger_activity 406 inner join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid= vtiger_activity.activityid 407 inner join vtiger_contactdetails on vtiger_contactdetails.contactid= vtiger_cntactivityrel.contactid 408 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid 409 left join vtiger_seactivityrel on vtiger_seactivityrel.activityid=vtiger_activity.activityid 410 left join vtiger_activitygrouprelation on vtiger_activitygrouprelation.activityid=vtiger_activity.activityid 411 left join vtiger_groups on vtiger_groups.groupname=vtiger_activitygrouprelation.groupname 412 inner join vtiger_users on vtiger_crmentity.smcreatorid= vtiger_users.id 413 where (vtiger_activity.activitytype = 'Meeting' or vtiger_activity.activitytype='Call' or vtiger_activity.activitytype='Task') 414 and (vtiger_activity.status = 'Completed' or vtiger_activity.status = 'Deferred' or (vtiger_activity.eventstatus = 'Held' and vtiger_activity.eventstatus != '')) 415 and vtiger_cntactivityrel.contactid=".$id; 416 //Don't add order by, because, for security, one more condition will be added with this query in include/RelatedListView.php 417 $log->debug("Entering get_history method ..."); 418 return getHistory('Contacts',$query,$id); 419 } 420 /** 421 * Function to get Contact related Tickets. 422 * @param integer $id - contactid 423 * returns related Ticket records in array format 424 */ 425 function get_tickets($id) 426 { 427 global $log, $singlepane_view; 428 global $app_strings; 429 $log->debug("Entering get_tickets(".$id.") method ..."); 430 $focus = new HelpDesk(); 431 432 $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>'; 433 if($singlepane_view == 'true') 434 $returnset = '&return_module=Contacts&return_action=DetailView&return_id='.$id; 435 else 436 $returnset = '&return_module=Contacts&return_action=CallRelatedList&return_id='.$id; 437 438 $query = "select vtiger_users.user_name,vtiger_crmentity.crmid, vtiger_troubletickets.title, vtiger_contactdetails.contactid, vtiger_troubletickets.parent_id, vtiger_contactdetails.firstname, vtiger_contactdetails.lastname, vtiger_troubletickets.status, vtiger_troubletickets.priority, vtiger_crmentity.smownerid from vtiger_troubletickets inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_troubletickets.ticketid left join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_troubletickets.parent_id left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid left join vtiger_ticketgrouprelation on vtiger_troubletickets.ticketid=vtiger_ticketgrouprelation.ticketid left join vtiger_groups on vtiger_groups.groupname=vtiger_ticketgrouprelation.groupname where vtiger_crmentity.deleted=0 and vtiger_contactdetails.contactid=".$id; 439 $log->info("Ticket Related List for Contact Displayed"); 440 $log->debug("Exiting get_tickets method ..."); 441 return GetRelatedList('Contacts','HelpDesk',$focus,$query,$button,$returnset); 442 } 443 /** 444 * Function to get Contact related Attachments 445 * @param integer $id - contactid 446 * returns related Attachment record in array format 447 */ 448 function get_attachments($id) 449 { 450 global $log; 451 $log->debug("Entering get_attachments(".$id.") method ..."); 452 $query = "select vtiger_notes.title,'Notes ' AS ActivityType, 453 vtiger_notes.filename, vtiger_attachments.type AS FileType,crm2.modifiedtime AS lastmodified, 454 vtiger_seattachmentsrel.attachmentsid AS attachmentsid, vtiger_notes.notesid AS crmid, 455 crm2.createdtime, vtiger_notes.notecontent AS description, vtiger_users.user_name 456 from vtiger_notes 457 inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_notes.contact_id 458 inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_notes.notesid and crm2.deleted=0 459 left join vtiger_seattachmentsrel on vtiger_seattachmentsrel.crmid =vtiger_notes.notesid 460 left join vtiger_attachments on vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid 461 inner join vtiger_users on crm2.smcreatorid= vtiger_users.id 462 where vtiger_crmentity.crmid=".$id; 463 $query .= " union all "; 464 $query .= "select vtiger_attachments.description AS title,'Attachments' AS ActivityType, 465 vtiger_attachments.name AS filename, vtiger_attachments.type AS FileType,crm2.modifiedtime AS lastmodified, 466 vtiger_attachments.attachmentsid AS attachmentsid, vtiger_seattachmentsrel.attachmentsid AS crmid, 467 crm2.createdtime, vtiger_attachments.description, vtiger_users.user_name 468 from vtiger_attachments 469 inner join vtiger_seattachmentsrel on vtiger_seattachmentsrel.attachmentsid= vtiger_attachments.attachmentsid 470 inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_seattachmentsrel.crmid 471 inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_attachments.attachmentsid 472 inner join vtiger_users on crm2.smcreatorid= vtiger_users.id 473 where vtiger_crmentity.crmid=".$id." 474 order by createdtime desc"; 475 $log->info("Notes&Attachmenmts for Contact Displayed"); 476 $log->debug("Exiting get_attachments method ..."); 477 return getAttachmentsAndNotes('Contacts',$query,$id); 478 } 479 /** 480 * Function to get Contact related Quotes 481 * @param integer $id - contactid 482 * returns related Quotes record in array format 483 */ 484 function get_quotes($id) 485 { 486 global $log, $singlepane_view; 487 $log->debug("Entering get_quotes(".$id.") method ..."); 488 global $app_strings; 489 require_once ('modules/Quotes/Quote.php'); 490 $focus = new Quote(); 491 492 $button = ''; 493 if(isPermitted("Quotes",1,"") == 'yes') 494 { 495 $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>'; 496 } 497 if($singlepane_view == 'true') 498 $returnset = '&return_module=Contacts&return_action=DetailView&return_id='.$id; 499 else 500 $returnset = '&return_module=Contacts&return_action=CallRelatedList&return_id='.$id; 501 $query = "select vtiger_users.user_name,vtiger_crmentity.*, vtiger_quotes.*,vtiger_potential.potentialname,vtiger_contactdetails.lastname from vtiger_quotes inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_quotes.quoteid left outer join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_quotes.contactid left outer join vtiger_potential on vtiger_potential.potentialid=vtiger_quotes.potentialid left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid left join vtiger_quotegrouprelation on vtiger_quotes.quoteid=vtiger_quotegrouprelation.quoteid left join vtiger_groups on vtiger_groups.groupname=vtiger_quotegrouprelation.groupname where vtiger_crmentity.deleted=0 and vtiger_contactdetails.contactid=".$id; 502 $log->debug("Exiting get_quotes method ..."); 503 return GetRelatedList('Contacts','Quotes',$focus,$query,$button,$returnset); 504 } 505 /** 506 * Function to get Contact related SalesOrder 507 * @param integer $id - contactid 508 * returns related SalesOrder record in array format 509 */ 510 function get_salesorder($id) 511 { 512 global $log, $singlepane_view; 513 $log->debug("Entering get_salesorder(".$id.") method ..."); 514 require_once ('modules/SalesOrder/SalesOrder.php'); 515 global $app_strings; 516 $focus = new SalesOrder(); 517 $button = ''; 518 519 if(isPermitted("SalesOrder",1,"") == 'yes') 520 { 521 522 $button .= '<input title="'.$app_strings['LBL_NEW_SORDER_BUTTON_TITLE'].'" accessyKey="O" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'SalesOrder\';this.form.return_module.value=\'Contacts\';this.form.return_action.value=\'DetailView\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_SORDER_BUTTON'].'"> '; 523 } 524 if($singlepane_view == 'true') 525 $returnset = '&return_module=Contacts&return_action=DetailView&return_id='.$id; 526 else 527 $returnset = '&return_module=Contacts&return_action=CallRelatedList&return_id='.$id; 528 529 $query = "select vtiger_users.user_name,vtiger_crmentity.*, vtiger_salesorder.*, vtiger_quotes.subject as quotename, vtiger_account.accountname, vtiger_contactdetails.lastname from vtiger_salesorder inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_salesorder.salesorderid left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid left outer join vtiger_quotes on vtiger_quotes.quoteid=vtiger_salesorder.quoteid left outer join vtiger_account on vtiger_account.accountid=vtiger_salesorder.accountid left outer join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_salesorder.contactid left join vtiger_sogrouprelation on vtiger_salesorder.salesorderid=vtiger_sogrouprelation.salesorderid left join vtiger_groups on vtiger_groups.groupname=vtiger_sogrouprelation.groupname where vtiger_crmentity.deleted=0 and vtiger_salesorder.contactid = ".$id; 530 $log->debug("Exiting get_salesorder method ..."); 531 return GetRelatedList('Contacts','SalesOrder',$focus,$query,$button,$returnset); 532 } 533 /** 534 * Function to get Contact related Products 535 * @param integer $id - contactid 536 * returns related Products record in array format 537 */ 538 function get_products($id) 539 { 540 global $log, $singlepane_view; 541 $log->debug("Entering get_products(".$id.") method ..."); 542 global $app_strings; 543 require_once ('modules/Products/Product.php'); 544 $focus = new Product(); 545 $button = ''; 546 547 if(isPermitted("Products",1,"") == 'yes') 548 { 549 550 $button .= '<input title="'.$app_strings['LBL_NEW_PRODUCT'].'" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Products\';this.form.return_module.value=\'Contacts\';this.form.return_action.value=\'DetailView\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_PRODUCT'].'"> '; 551 } 552 if($singlepane_view == 'true') 553 $returnset = '&return_module=Contacts&return_action=DetailView&return_id='.$id; 554 else 555 $returnset = '&return_module=Contacts&return_action=CallRelatedList&return_id='.$id; 556 557 $query = 'select vtiger_products.productid, vtiger_products.productname, vtiger_products.productcode, vtiger_products.commissionrate, vtiger_products.qty_per_unit, vtiger_products.unit_price, vtiger_crmentity.crmid, vtiger_crmentity.smownerid,vtiger_contactdetails.lastname from vtiger_products inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_products.productid left outer join vtiger_contactdetails on vtiger_contactdetails.contactid = vtiger_products.contactid where vtiger_contactdetails.contactid = '.$id.' and vtiger_crmentity.deleted = 0'; 558 $log->debug("Exiting get_products method ..."); 559 return GetRelatedList('Contacts','Products',$focus,$query,$button,$returnset); 560 } 561 562 /** 563 * Function to get Contact related PurchaseOrder 564 * @param integer $id - contactid 565 * returns related PurchaseOrder record in array format 566 */ 567 function get_purchase_orders($id) 568 { 569 global $log, $singlepane_view; 570 $log->debug("Entering get_purchase_orders(".$id.") method ..."); 571 global $app_strings; 572 require_once ('modules/PurchaseOrder/PurchaseOrder.php'); 573 $focus = new Order(); 574 575 $button = ''; 576 577 if(isPermitted("PurchaseOrder",1,"") == 'yes') 578 { 579 580 $button .= '<input title="'.$app_strings['LBL_PORDER_BUTTON_TITLE'].'" accessyKey="O" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'PurchaseOrder\';this.form.return_module.value=\'Contacts\';this.form.return_action.value=\'DetailView\'" type="submit" name="button" value="'.$app_strings['LBL_PORDER_BUTTON'].'"> '; 581 } 582 if($singlepane_view == 'true') 583 $returnset = '&return_module=Contacts&return_action=DetailView&return_id='.$id; 584 else 585 $returnset = '&return_module=Contacts&return_action=CallRelatedList&return_id='.$id; 586 587 $query = "select vtiger_users.user_name,vtiger_crmentity.*, vtiger_purchaseorder.*,vtiger_vendor.vendorname,vtiger_contactdetails.lastname from vtiger_purchaseorder inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_purchaseorder.purchaseorderid left outer join vtiger_vendor on vtiger_purchaseorder.vendorid=vtiger_vendor.vendorid left outer join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_purchaseorder.contactid left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid left join vtiger_pogrouprelation on vtiger_purchaseorder.purchaseorderid=vtiger_pogrouprelation.purchaseorderid left join vtiger_groups on vtiger_groups.groupname=vtiger_pogrouprelation.groupname where vtiger_crmentity.deleted=0 and vtiger_purchaseorder.contactid=".$id; 588 $log->debug("Exiting get_purchase_orders method ..."); 589 return GetRelatedList('Contacts','PurchaseOrder',$focus,$query,$button,$returnset); 590 } 591 592 /** Returns a list of the associated emails 593 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. 594 * All Rights Reserved.. 595 * Contributor(s): ______________________________________.. 596 */ 597 function get_emails($id) 598 { 599 global $log, $singlepane_view; 600 $log->debug("Entering get_emails(".$id.") method ..."); 601 global $mod_strings; 602 603 $focus = new Email(); 604 605 $button = ''; 606 607 if(isPermitted("Emails",1,"") == 'yes') 608 { 609 $button .= '<input title="New Email" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Emails\';this.form.email_directing_module.value=\'contacts\';this.form.record.value='.$id.';this.form.return_action.value=\'DetailView\'" type="submit" name="button" value="'.$mod_strings['LBL_NEW_EMAIL'].'">'; 610 } 611 if($singlepane_view == 'true') 612 $returnset = '&return_module=Contacts&return_action=DetailView&return_id='.$id; 613 else 614 $returnset = '&return_module=Contacts&return_action=CallRelatedList&return_id='.$id; 615 616 $log->info("Email Related List for Contact Displayed"); 617 618 $query = "select vtiger_activity.activityid, vtiger_activity.subject, vtiger_activity.activitytype, vtiger_users.user_name, vtiger_crmentity.modifiedtime, vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_activity.date_start from vtiger_activity, vtiger_seactivityrel, vtiger_contactdetails, vtiger_users, vtiger_crmentity left join vtiger_activitygrouprelation on vtiger_activitygrouprelation.activityid=vtiger_crmentity.crmid left join vtiger_groups on vtiger_groups.groupname=vtiger_activitygrouprelation.groupname where vtiger_seactivityrel.activityid = vtiger_activity.activityid and vtiger_contactdetails.contactid = vtiger_seactivityrel.crmid and vtiger_users.id=vtiger_crmentity.smownerid and vtiger_crmentity.crmid = vtiger_activity.activityid and vtiger_contactdetails.contactid = ".$id." and vtiger_activity.activitytype='Emails' and vtiger_crmentity.deleted = 0"; 619 $log->debug("Exiting get_emails method ..."); 620 return GetRelatedList('Contacts','Emails',$focus,$query,$button,$returnset); 621 } 622 623 /** Returns a list of the associated Campaigns 624 * @param $id -- campaign id :: Type Integer 625 * @returns list of campaigns in array format 626 */ 627 628 function get_campaigns($id) 629 { 630 global $log, $singlepane_view; 631 $log->debug("Entering get_campaigns(".$id.") method ..."); 632 global $mod_strings; 633 634 $focus = new Campaign(); 635 if($singlepane_view == 'true') 636 $returnset = '&return_module=Contacts&return_action=DetailView&return_id='.$id; 637 else 638 $returnset = '&return_module=Contacts&return_action=CallRelatedList&return_id='.$id; 639 $button = ''; 640 641 $log->info("Campaign Related List for Contact Displayed"); 642 $query = "SELECT vtiger_users.user_name, vtiger_campaign.campaignid, vtiger_campaign.campaignname, vtiger_campaign.campaigntype, vtiger_campaign.campaignstatus, vtiger_campaign.expectedrevenue, vtiger_campaign.closingdate, vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime from vtiger_campaign inner join vtiger_campaigncontrel on vtiger_campaigncontrel.campaignid=vtiger_campaign.campaignid inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_campaign.campaignid left join vtiger_campaigngrouprelation on vtiger_campaign.campaignid=vtiger_campaigngrouprelation.campaignid left join vtiger_groups on vtiger_groups.groupname=vtiger_campaigngrouprelation.groupname left join vtiger_users on vtiger_users.id = vtiger_crmentity.smownerid where vtiger_campaigncontrel.contactid=".$id." and vtiger_crmentity.deleted=0"; 643 644 $log->debug("Exiting get_campaigns method ..."); 645 return GetRelatedList('Contacts','Campaigns',$focus,$query,$button,$returnset); 646 647 } 648 /** Function to export the contact records in CSV Format 649 * @param reference variable - order by is passed when the query is executed 650 * @param reference variable - where condition is passed when the query is executed 651 * Returns Export Contacts Query. 652 */ 653 function create_export_query(&$order_by, &$where) 654 { 655 global $log; 656 global $current_user; 657 $log->debug("Entering create_export_query(".$order_by.",".$where.") method ..."); 658 659 include ("include/utils/ExportUtils.php"); 660 661 //To get the Permitted fields query and the permitted fields list 662 $sql = getPermittedFieldsQuery("Contacts", "detail_view"); 663 $fields_list = getFieldsListFromQuery($sql); 664 665 $query = "SELECT $fields_list 666 FROM vtiger_contactdetails 667 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid 668 LEFT JOIN vtiger_users ON vtiger_crmentity.smownerid=vtiger_users.id 669 LEFT JOIN vtiger_account on vtiger_contactdetails.accountid=vtiger_account.accountid 670 left join vtiger_contactaddress on vtiger_contactaddress.contactaddressid=vtiger_contactdetails.contactid 671 left join vtiger_contactsubdetails on vtiger_contactsubdetails.contactsubscriptionid=vtiger_contactdetails.contactid 672 left join vtiger_contactscf on vtiger_contactscf.contactid=vtiger_contactdetails.contactid 673 left join vtiger_customerdetails on vtiger_customerdetails.customerid=vtiger_contactdetails.contactid 674 LEFT JOIN vtiger_contactgrouprelation 675 ON vtiger_contactscf.contactid = vtiger_contactgrouprelation.contactid 676 LEFT JOIN vtiger_groups 677 ON vtiger_groups.groupname = vtiger_contactgrouprelation.groupname 678 LEFT JOIN vtiger_contactdetails vtiger_contactdetails2 679 ON vtiger_contactdetails2.contactid = vtiger_contactdetails.reportsto 680 where vtiger_crmentity.deleted=0 and vtiger_users.status='Active' "; 681 //vtiger_contactdetails2 is added to get the Reports To of Contact 682 683 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 684 require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); 685 //we should add security check when the user has Private Access 686 if($is_admin==false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $defaultOrgSharingPermission[4] == 3) 687 { 688 //Added security check to get the permitted records only 689 $query = $query." ".getListViewSecurityParameter("Contacts"); 690 } 691 692 $log->info("Export Query Constructed Successfully"); 693 $log->debug("Exiting create_export_query method ..."); 694 return $query; 695 } 696 697 698 /** Function to get the Columnnames of the Contacts 699 * Used By vtigerCRM Word Plugin 700 * Returns the Merge Fields for Word Plugin 701 */ 702 function getColumnNames() 703 { 704 global $log, $current_user; 705 $log->debug("Entering getColumnNames() method ..."); 706 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 707 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) 708 { 709 $sql1 = "select fieldlabel from vtiger_field where tabid=4 and block <> 75"; 710 }else 711 { 712 $profileList = getCurrentUserProfileList(); 713 $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=4 and vtiger_field.block <> 6 and vtiger_field.block <> 75 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; 714 } 715 $result = $this->db->query($sql1); 716 $numRows = $this->db->num_rows($result); 717 for($i=0; $i < $numRows;$i++) 718 { 719 $custom_fields[$i] = $this->db->query_result($result,$i,"fieldlabel"); 720 $custom_fields[$i] = ereg_replace(" ","",$custom_fields[$i]); 721 $custom_fields[$i] = strtoupper($custom_fields[$i]); 722 } 723 $mergeflds = $custom_fields; 724 $log->debug("Exiting getColumnNames method ..."); 725 return $mergeflds; 726 } 727 //End 728 /** Function to get the Contacts assigned to a user with a valid email address. 729 * @param varchar $username - User Name 730 * @param varchar $emailaddress - Email Addr for each contact. 731 * Used By vtigerCRM Outlook Plugin 732 * Returns the Query 733 */ 734 function get_searchbyemailid($username,$emailaddress) 735 { 736 global $log; 737 global $current_user; 738 require_once ("modules/Users/User.php"); 739 $seed_user=new User(); 740 $user_id=$seed_user->retrieve_user_id($username); 741 $current_user=$seed_user; 742 $current_user->retrieve_entity_info($user_id, 'Users'); 743 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 744 require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); 745 $log->debug("Entering get_searchbyemailid(".$username.",".$emailaddress.") method ..."); 746 $query = "select vtiger_contactdetails.lastname,vtiger_contactdetails.firstname, 747 vtiger_contactdetails.contactid, vtiger_contactdetails.salutation, 748 vtiger_contactdetails.email,vtiger_contactdetails.title, 749 vtiger_contactdetails.mobile,vtiger_account.accountname, 750 vtiger_account.accountid as accountid from vtiger_contactdetails 751 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid 752 inner join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid 753 left join vtiger_account on vtiger_account.accountid=vtiger_contactdetails.accountid 754 left join vtiger_contactaddress on vtiger_contactaddress.contactaddressid=vtiger_contactdetails.contactid 755 LEFT JOIN vtiger_contactgrouprelation ON vtiger_contactdetails.contactid = vtiger_contactgrouprelation.contactid 756 LEFT JOIN vtiger_groups ON vtiger_groups.groupname = vtiger_contactgrouprelation.groupname 757 where vtiger_crmentity.deleted=0 and vtiger_contactdetails.email like '%".$emailaddress."%'"; 758 $tab_id = getTabid("Contacts"); 759 if($is_admin==false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $defaultOrgSharingPermission[$tab_id] == 3) 760 { 761 $sec_parameter=getListViewSecurityParameter("Contacts"); 762 $query .= $sec_parameter; 763 764 } 765 $log->debug("Exiting get_searchbyemailid method ..."); 766 return $this->plugin_process_list_query($query); 767 } 768 769 /** Function to get the Contacts associated with the particular User Name. 770 * @param varchar $user_name - User Name 771 * Returns query 772 */ 773 774 function get_contactsforol($user_name) 775 { 776 global $log,$adb; 777 global $current_user; 778 require_once ("modules/Users/User.php"); 779 $seed_user=new User(); 780 $user_id=$seed_user->retrieve_user_id($user_name); 781 $current_user=$seed_user; 782 $current_user->retrieve_entity_info($user_id, 'Users'); 783 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 784 require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); 785 786 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) 787 { 788 $sql1 = "select tablename,columnname from vtiger_field where tabid=4 and block <> 75 and block <> 6 and vtiger_field.block <> 5"; 789 }else 790 { 791 $profileList = getCurrentUserProfileList(); 792 $sql1 = "select tablename,columnname 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=4 and vtiger_field.block <> 75 and vtiger_field.block <> 6 and vtiger_field.block <> 5 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; 793 } 794 $result1 = $adb->query($sql1); 795 for($i=0;$i < $adb->num_rows($result1);$i++) 796 { 797 $permitted_lists[] = $adb->query_result($result1,$i,'tablename'); 798 $permitted_lists[] = $adb->query_result($result1,$i,'columnname'); 799 if($adb->query_result($result1,$i,'columnname') == "accountid") 800 { 801 $permitted_lists[] = 'vtiger_account'; 802 $permitted_lists[] = 'accountname'; 803 } 804 } 805 $permitted_lists = array_chunk($permitted_lists,2); 806 $column_table_lists = array(); 807 for($i=0;$i < count($permitted_lists);$i++) 808 { 809 $column_table_lists[] = implode(".",$permitted_lists[$i]); 810 } 811 812 $log->debug("Entering get_contactsforol(".$user_name.") method ..."); 813 $query = "select vtiger_contactdetails.contactid as id, ".implode(',',$column_table_lists)." from vtiger_contactdetails 814 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid 815 inner join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid 816 left join vtiger_account on vtiger_account.accountid=vtiger_contactdetails.accountid 817 left join vtiger_contactaddress on vtiger_contactaddress.contactaddressid=vtiger_contactdetails.contactid 818 left join vtiger_contactsubdetails on vtiger_contactsubdetails.contactsubscriptionid = vtiger_contactdetails.contactid 819 LEFT JOIN vtiger_contactgrouprelation ON vtiger_contactdetails.contactid = vtiger_contactgrouprelation.contactid 820 LEFT JOIN vtiger_groups ON vtiger_groups.groupname = vtiger_contactgrouprelation.groupname 821 where vtiger_crmentity.deleted=0 and vtiger_users.user_name='".$user_name."'"; 822 $log->debug("Exiting get_contactsforol method ..."); 823 return $query; 824 } 825 826 827 //End 828 829 } 830 831 ?>
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 |