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