[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
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 // Contact is used to store customer information. 23 class Contacts extends CRMEntity { 24 var $log; 25 var $db; 26 27 var $table_name = "vtiger_contactdetails"; 28 var $table_index= 'contactid'; 29 var $tab_name = Array('vtiger_crmentity','vtiger_contactdetails','vtiger_contactaddress','vtiger_contactsubdetails','vtiger_contactscf','vtiger_customerdetails'); 30 var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_contactdetails'=>'contactid','vtiger_contactaddress'=>'contactaddressid','vtiger_contactsubdetails'=>'contactsubscriptionid','vtiger_contactscf'=>'contactid','vtiger_customerdetails'=>'customerid'); 31 /** 32 * Mandatory table for supporting custom fields. 33 */ 34 var $customFieldTable = Array('vtiger_contactscf', 'contactid'); 35 36 var $column_fields = Array(); 37 38 var $sortby_fields = Array('lastname','firstname','title','email','phone','smownerid','accountname'); 39 40 var $list_link_field= 'lastname'; 41 42 // This is the list of vtiger_fields that are in the lists. 43 var $list_fields = Array( 44 'First Name' => Array('contactdetails'=>'firstname'), 45 'Last Name' => Array('contactdetails'=>'lastname'), 46 'Title' => Array('contactdetails'=>'title'), 47 'Account Name' => Array('account'=>'accountid'), 48 'Email' => Array('contactdetails'=>'email'), 49 'Office Phone' => Array('contactdetails'=>'phone'), 50 'Assigned To' => Array('crmentity'=>'smownerid') 51 ); 52 53 var $range_fields = Array( 54 'first_name', 55 'last_name', 56 'primary_address_city', 57 'account_name', 58 'account_id', 59 'id', 60 'email1', 61 'salutation', 62 'title', 63 'phone_mobile', 64 'reports_to_name', 65 'primary_address_street', 66 'primary_address_city', 67 'primary_address_state', 68 'primary_address_postalcode', 69 'primary_address_country', 70 'alt_address_city', 71 'alt_address_street', 72 'alt_address_city', 73 'alt_address_state', 74 'alt_address_postalcode', 75 'alt_address_country', 76 'office_phone', 77 'home_phone', 78 'other_phone', 79 'fax', 80 'department', 81 'birthdate', 82 'assistant_name', 83 'assistant_phone'); 84 85 86 var $list_fields_name = Array( 87 'First Name' => 'firstname', 88 'Last Name' => 'lastname', 89 'Title' => 'title', 90 'Account Name' => 'account_id', 91 'Email' => 'email', 92 'Office Phone' => 'phone', 93 'Assigned To' => 'assigned_user_id' 94 ); 95 96 var $search_fields = Array( 97 'First Name' => Array('contactdetails'=>'firstname'), 98 'Last Name' => Array('contactdetails'=>'lastname'), 99 'Title' => Array('contactdetails'=>'title'), 100 'Account Name'=>Array('contactdetails'=>'account_id'), 101 'Assigned To'=>Array('crmentity'=>'smownerid'), 102 ); 103 104 var $search_fields_name = Array( 105 'First Name' => 'firstname', 106 'Last Name' => 'lastname', 107 'Title' => 'title', 108 'Account Name'=>'account_id', 109 'Assigned To'=>'assigned_user_id' 110 ); 111 112 // This is the list of vtiger_fields that are required 113 var $required_fields = array("lastname"=>1); 114 115 // Used when enabling/disabling the mandatory fields for the module. 116 // Refers to vtiger_field.fieldname values. 117 var $mandatory_fields = Array('assigned_user_id','lastname','createdtime' ,'modifiedtime'); 118 119 //Default Fields for Email Templates -- Pavani 120 var $emailTemplate_defaultFields = array('firstname','lastname','salutation','title','email','department','phone','mobile','support_start_date','support_end_date'); 121 122 //Added these variables which are used as default order by and sortorder in ListView 123 var $default_order_by = 'lastname'; 124 var $default_sort_order = 'ASC'; 125 126 // For Alphabetical search 127 var $def_basicsearch_col = 'lastname'; 128 129 var $related_module_table_index = array( 130 'Potentials' => array('table_name' => 'vtiger_potential', 'table_index' => 'potentialid', 'rel_index' => 'contact_id'), 131 'Quotes' => array('table_name' => 'vtiger_quotes', 'table_index' => 'quoteid', 'rel_index' => 'contactid'), 132 'SalesOrder' => array('table_name' => 'vtiger_salesorder', 'table_index' => 'salesorderid', 'rel_index' => 'contactid'), 133 'PurchaseOrder' => array('table_name' => 'vtiger_purchaseorder', 'table_index' => 'purchaseorderid', 'rel_index' => 'contactid'), 134 'Invoice' => array('table_name' => 'vtiger_invoice', 'table_index' => 'invoiceid', 'rel_index' => 'contactid'), 135 'HelpDesk' => array('table_name' => 'vtiger_troubletickets', 'table_index' => 'ticketid', 'rel_index' => 'contact_id'), 136 'Products' => array('table_name' => 'vtiger_seproductsrel', 'table_index' => 'productid', 'rel_index' => 'crmid'), 137 'Calendar' => array('table_name' => 'vtiger_cntactivityrel', 'table_index' => 'activityid', 'rel_index' => 'contactid'), 138 'Documents' => array('table_name' => 'vtiger_senotesrel', 'table_index' => 'notesid', 'rel_index' => 'crmid'), 139 'ServiceContracts' => array('table_name' => 'vtiger_servicecontracts', 'table_index' => 'servicecontractsid', 'rel_index' => 'sc_related_to'), 140 'Services' => array('table_name' => 'vtiger_crmentityrel', 'table_index' => 'crmid', 'rel_index' => 'crmid'), 141 'Campaigns' => array('table_name' => 'vtiger_campaigncontrel', 'table_index' => 'campaignid', 'rel_index' => 'contactid'), 142 'Assets' => array('table_name' => 'vtiger_assets', 'table_index' => 'assetsid', 'rel_index' => 'contact'), 143 'Project' => array('table_name' => 'vtiger_project', 'table_index' => 'projectid', 'rel_index' => 'linktoaccountscontacts'), 144 'Emails' => array('table_name' => 'vtiger_seactivityrel', 'table_index' => 'crmid', 'rel_index' => 'activityid'), 145 ); 146 147 function Contacts() { 148 $this->log = LoggerManager::getLogger('contact'); 149 $this->db = PearDatabase::getInstance(); 150 $this->column_fields = getColumnFields('Contacts'); 151 } 152 153 // Mike Crowe Mod --------------------------------------------------------Default ordering for us 154 /** Function to get the number of Contacts assigned to a particular User. 155 * @param varchar $user name - Assigned to User 156 * Returns the count of contacts assigned to user. 157 */ 158 function getCount($user_name) 159 { 160 global $log; 161 $log->debug("Entering getCount(".$user_name.") method ..."); 162 $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=? and vtiger_crmentity.deleted=0"; 163 $result = $this->db->pquery($query,array($user_name),true,"Error retrieving contacts count"); 164 $rows_found = $this->db->getRowCount($result); 165 $row = $this->db->fetchByAssoc($result, 0); 166 167 168 $log->debug("Exiting getCount method ..."); 169 return $row["count(*)"]; 170 } 171 172 // This function doesn't seem to be used anywhere. Need to check and remove it. 173 /** Function to get the Contact Details assigned to a particular User based on the starting count and the number of subsequent records. 174 * @param varchar $user_name - Assigned User 175 * @param integer $from_index - Initial record number to be displayed 176 * @param integer $offset - Count of the subsequent records to be displayed. 177 * Returns Query. 178 */ 179 function get_contacts($user_name,$from_index,$offset) 180 { 181 global $log; 182 $log->debug("Entering get_contacts(".$user_name.",".$from_index.",".$offset.") method ..."); 183 $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_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid 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; 184 185 $log->debug("Exiting get_contacts method ..."); 186 return $this->process_list_query1($query); 187 } 188 189 190 /** Function to process list query for a given query 191 * @param $query 192 * Returns the results of query in array format 193 */ 194 function process_list_query1($query) 195 { 196 global $log; 197 $log->debug("Entering process_list_query1(".$query.") method ..."); 198 199 $result =& $this->db->query($query,true,"Error retrieving $this->object_name list: "); 200 $list = Array(); 201 $rows_found = $this->db->getRowCount($result); 202 if($rows_found != 0) 203 { 204 $contact = Array(); 205 for($index = 0 , $row = $this->db->fetchByAssoc($result, $index); $row && $index <$rows_found;$index++, $row = $this->db->fetchByAssoc($result, $index)) 206 207 { 208 foreach($this->range_fields as $columnName) 209 { 210 if (isset($row[$columnName])) { 211 212 $contact[$columnName] = $row[$columnName]; 213 } 214 else 215 { 216 $contact[$columnName] = ""; 217 } 218 } 219 // TODO OPTIMIZE THE QUERY ACCOUNT NAME AND ID are set separetly for every vtiger_contactdetails and hence 220 // vtiger_account query goes for ecery single vtiger_account row 221 222 $list[] = $contact; 223 } 224 } 225 226 $response = Array(); 227 $response['list'] = $list; 228 $response['row_count'] = $rows_found; 229 $response['next_offset'] = $next_offset; 230 $response['previous_offset'] = $previous_offset; 231 232 233 $log->debug("Exiting process_list_query1 method ..."); 234 return $response; 235 } 236 237 238 /** Function to process list query for Plugin with Security Parameters for a given query 239 * @param $query 240 * Returns the results of query in array format 241 */ 242 function plugin_process_list_query($query) 243 { 244 global $log,$adb,$current_user; 245 $log->debug("Entering process_list_query1(".$query.") method ..."); 246 $permitted_field_lists = Array(); 247 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 248 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) 249 { 250 $sql1 = "select columnname from vtiger_field where tabid=4 and block <> 75 and vtiger_field.presence in (0,2)"; 251 $params1 = array(); 252 }else 253 { 254 $profileList = getCurrentUserProfileList(); 255 $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,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)"; 256 $params1 = array(); 257 if (count($profileList) > 0) { 258 $sql1 .= " and vtiger_profile2field.profileid in (". generateQuestionMarks($profileList) .")"; 259 array_push($params1, $profileList); 260 } 261 } 262 $result1 = $this->db->pquery($sql1, $params1); 263 for($i=0;$i < $adb->num_rows($result1);$i++) 264 { 265 $permitted_field_lists[] = $adb->query_result($result1,$i,'columnname'); 266 } 267 268 $result =& $this->db->query($query,true,"Error retrieving $this->object_name list: "); 269 $list = Array(); 270 $rows_found = $this->db->getRowCount($result); 271 if($rows_found != 0) 272 { 273 for($index = 0 , $row = $this->db->fetchByAssoc($result, $index); $row && $index <$rows_found;$index++, $row = $this->db->fetchByAssoc($result, $index)) 274 { 275 $contact = Array(); 276 277 $contact[lastname] = in_array("lastname",$permitted_field_lists) ? $row[lastname] : ""; 278 $contact[firstname] = in_array("firstname",$permitted_field_lists)? $row[firstname] : ""; 279 $contact[email] = in_array("email",$permitted_field_lists) ? $row[email] : ""; 280 281 282 if(in_array("accountid",$permitted_field_lists)) 283 { 284 $contact[accountname] = $row[accountname]; 285 $contact[account_id] = $row[accountid]; 286 }else 287 { 288 $contact[accountname] = ""; 289 $contact[account_id] = ""; 290 } 291 $contact[contactid] = $row[contactid]; 292 $list[] = $contact; 293 } 294 } 295 296 $response = Array(); 297 $response['list'] = $list; 298 $response['row_count'] = $rows_found; 299 $response['next_offset'] = $next_offset; 300 $response['previous_offset'] = $previous_offset; 301 $log->debug("Exiting process_list_query1 method ..."); 302 return $response; 303 } 304 305 306 /** Returns a list of the associated opportunities 307 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. 308 * All Rights Reserved.. 309 * Contributor(s): ______________________________________.. 310 */ 311 function get_opportunities($id, $cur_tab_id, $rel_tab_id, $actions=false) { 312 global $log, $singlepane_view,$currentModule,$current_user; 313 $log->debug("Entering get_opportunities(".$id.") method ..."); 314 $this_module = $currentModule; 315 316 $related_module = vtlib_getModuleNameById($rel_tab_id); 317 require_once("modules/$related_module/$related_module.php"); 318 $other = new $related_module(); 319 vtlib_setup_modulevars($related_module, $other); 320 $singular_modname = vtlib_toSingular($related_module); 321 322 $parenttab = getParentTab(); 323 324 if($singlepane_view == 'true') 325 $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; 326 else 327 $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; 328 329 $button = ''; 330 331 if($actions) { 332 if(is_string($actions)) $actions = explode(',', strtoupper($actions)); 333 if(in_array('SELECT', $actions) && isPermitted($related_module,4, '') == 'yes') { 334 $button .= "<input title='".getTranslatedString('LBL_SELECT')." ". getTranslatedString($related_module). "' class='crmbutton small edit' type='button' onclick=\"return window.open('index.php?module=$related_module&return_module=$currentModule&action=Popup&popuptype=detailview&select=enable&form=EditView&form_submit=false&recordid=$id&parenttab=$parenttab','test','width=640,height=602,resizable=0,scrollbars=0');\" value='". getTranslatedString('LBL_SELECT'). " " . getTranslatedString($related_module) ."'> "; 335 } 336 if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { 337 $button .= "<input title='".getTranslatedString('LBL_NEW'). " ". getTranslatedString($singular_modname) ."' class='crmbutton small create'" . 338 " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\";this.form.return_action.value=\"updateRelations\"' type='submit' name='button'" . 339 " value='". getTranslatedString('LBL_ADD_NEW'). " " . getTranslatedString($singular_modname) ."'> "; 340 } 341 } 342 343 // Should Opportunities be listed on Secondary Contacts ignoring the boundaries of Organization. 344 // Useful when the Reseller are working to gain Potential for other Organization. 345 $ignoreOrganizationCheck = true; 346 347 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 348 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 349 $query ='select case when (vtiger_users.user_name not like "") then '.$userNameSql.' else vtiger_groups.groupname end as user_name, 350 vtiger_contactdetails.accountid, vtiger_contactdetails.contactid , vtiger_potential.potentialid, vtiger_potential.potentialname, 351 vtiger_potential.potentialtype, vtiger_potential.sales_stage, vtiger_potential.amount, vtiger_potential.closingdate, 352 vtiger_potential.related_to, vtiger_potential.contact_id, vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_account.accountname 353 from vtiger_contactdetails 354 left join vtiger_contpotentialrel on vtiger_contpotentialrel.contactid=vtiger_contactdetails.contactid 355 left join vtiger_potential on (vtiger_potential.potentialid = vtiger_contpotentialrel.potentialid or vtiger_potential.contact_id=vtiger_contactdetails.contactid) 356 inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_potential.potentialid 357 left join vtiger_account on vtiger_account.accountid=vtiger_contactdetails.accountid 358 LEFT JOIN vtiger_potentialscf ON vtiger_potential.potentialid = vtiger_potentialscf.potentialid 359 left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid 360 left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid 361 where vtiger_crmentity.deleted=0 and vtiger_contactdetails.contactid ='.$id; 362 363 if (!$ignoreOrganizationCheck) { 364 // Restrict the scope of listing to only related contacts of the organization linked to potential via related_to of Potential 365 $query .= ' and (vtiger_contactdetails.accountid = vtiger_potential.related_to or vtiger_contactdetails.contactid=vtiger_potential.contact_id)'; 366 } 367 368 $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); 369 370 if($return_value == null) $return_value = Array(); 371 $return_value['CUSTOM_BUTTON'] = $button; 372 373 $log->debug("Exiting get_opportunities method ..."); 374 return $return_value; 375 } 376 377 378 /** Returns a list of the associated tasks 379 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. 380 * All Rights Reserved.. 381 * Contributor(s): ______________________________________.. 382 */ 383 function get_activities($id, $cur_tab_id, $rel_tab_id, $actions=false) { 384 global $log, $singlepane_view,$currentModule,$current_user; 385 $log->debug("Entering get_activities(".$id.") method ..."); 386 $this_module = $currentModule; 387 388 $related_module = vtlib_getModuleNameById($rel_tab_id); 389 require_once("modules/$related_module/Activity.php"); 390 $other = new Activity(); 391 vtlib_setup_modulevars($related_module, $other); 392 $singular_modname = vtlib_toSingular($related_module); 393 394 $parenttab = getParentTab(); 395 396 if($singlepane_view == 'true') 397 $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; 398 else 399 $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; 400 401 $button = ''; 402 403 $button .= '<input type="hidden" name="activity_mode">'; 404 405 if($actions) { 406 if(is_string($actions)) $actions = explode(',', strtoupper($actions)); 407 if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { 408 if(getFieldVisibilityPermission('Calendar',$current_user->id,'contact_id', 'readwrite') == '0') { 409 $button .= "<input title='".getTranslatedString('LBL_NEW'). " ". getTranslatedString('LBL_TODO', $related_module) ."' class='crmbutton small create'" . 410 " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\";this.form.return_module.value=\"$this_module\";this.form.activity_mode.value=\"Task\";' type='submit' name='button'" . 411 " value='". getTranslatedString('LBL_ADD_NEW'). " " . getTranslatedString('LBL_TODO', $related_module) ."'> "; 412 } 413 if(getFieldVisibilityPermission('Events',$current_user->id,'contact_id', 'readwrite') == '0') { 414 $button .= "<input title='".getTranslatedString('LBL_NEW'). " ". getTranslatedString('LBL_TODO', $related_module) ."' class='crmbutton small create'" . 415 " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\";this.form.return_module.value=\"$this_module\";this.form.activity_mode.value=\"Events\";' type='submit' name='button'" . 416 " value='". getTranslatedString('LBL_ADD_NEW'). " " . getTranslatedString('LBL_EVENT', $related_module) ."'>"; 417 } 418 } 419 } 420 421 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 422 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 423 $query = "SELECT case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name," . 424 " vtiger_contactdetails.lastname, vtiger_contactdetails.firstname, vtiger_activity.activityid ," . 425 " vtiger_activity.subject, vtiger_activity.activitytype, vtiger_activity.date_start, vtiger_activity.due_date," . 426 " vtiger_activity.time_start,vtiger_activity.time_end, vtiger_cntactivityrel.contactid, vtiger_crmentity.crmid," . 427 " vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime, vtiger_recurringevents.recurringtype," . 428 " case when (vtiger_activity.activitytype = 'Task') then vtiger_activity.status else vtiger_activity.eventstatus end as status, " . 429 " vtiger_seactivityrel.crmid as parent_id " . 430 " from vtiger_contactdetails " . 431 " inner join vtiger_cntactivityrel on vtiger_cntactivityrel.contactid = vtiger_contactdetails.contactid" . 432 " inner join vtiger_activity on vtiger_cntactivityrel.activityid=vtiger_activity.activityid" . 433 " inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_cntactivityrel.activityid " . 434 " left join vtiger_seactivityrel on vtiger_seactivityrel.activityid = vtiger_cntactivityrel.activityid " . 435 " left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid" . 436 " left outer join vtiger_recurringevents on vtiger_recurringevents.activityid=vtiger_activity.activityid" . 437 " left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid" . 438 " where vtiger_contactdetails.contactid=".$id." and vtiger_crmentity.deleted = 0" . 439 " and ((vtiger_activity.activitytype='Task' and vtiger_activity.status not in ('Completed','Deferred'))" . 440 " or (vtiger_activity.activitytype Not in ('Emails','Task') and vtiger_activity.eventstatus not in ('','Held')))"; 441 442 $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); 443 444 if($return_value == null) $return_value = Array(); 445 $return_value['CUSTOM_BUTTON'] = $button; 446 447 $log->debug("Exiting get_activities method ..."); 448 return $return_value; 449 } 450 /** 451 * Function to get Contact related Task & Event which have activity type Held, Completed or Deferred. 452 * @param integer $id - contactid 453 * returns related Task or Event record in array format 454 */ 455 function get_history($id) 456 { 457 global $log; 458 $log->debug("Entering get_history(".$id.") method ..."); 459 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 460 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 461 $query = "SELECT vtiger_activity.activityid, vtiger_activity.subject, vtiger_activity.status 462 , vtiger_activity.eventstatus,vtiger_activity.activitytype, vtiger_activity.date_start, 463 vtiger_activity.due_date,vtiger_activity.time_start,vtiger_activity.time_end, 464 vtiger_contactdetails.contactid, vtiger_contactdetails.firstname, 465 vtiger_contactdetails.lastname, vtiger_crmentity.modifiedtime, 466 vtiger_crmentity.createdtime, vtiger_crmentity.description,vtiger_crmentity.crmid, 467 case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name 468 from vtiger_activity 469 inner join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid= vtiger_activity.activityid 470 inner join vtiger_contactdetails on vtiger_contactdetails.contactid= vtiger_cntactivityrel.contactid 471 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid 472 left join vtiger_seactivityrel on vtiger_seactivityrel.activityid=vtiger_activity.activityid 473 left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid 474 left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid 475 where (vtiger_activity.activitytype != 'Emails') 476 and (vtiger_activity.status = 'Completed' or vtiger_activity.status = 'Deferred' or (vtiger_activity.eventstatus = 'Held' and vtiger_activity.eventstatus != '')) 477 and vtiger_cntactivityrel.contactid=".$id." 478 and vtiger_crmentity.deleted = 0"; 479 //Don't add order by, because, for security, one more condition will be added with this query in include/RelatedListView.php 480 $log->debug("Entering get_history method ..."); 481 return getHistory('Contacts',$query,$id); 482 } 483 /** 484 * Function to get Contact related Tickets. 485 * @param integer $id - contactid 486 * returns related Ticket records in array format 487 */ 488 function get_tickets($id, $cur_tab_id, $rel_tab_id, $actions=false) { 489 global $log, $singlepane_view,$currentModule,$current_user; 490 $log->debug("Entering get_tickets(".$id.") method ..."); 491 $this_module = $currentModule; 492 493 $related_module = vtlib_getModuleNameById($rel_tab_id); 494 require_once("modules/$related_module/$related_module.php"); 495 $other = new $related_module(); 496 vtlib_setup_modulevars($related_module, $other); 497 $singular_modname = vtlib_toSingular($related_module); 498 499 $parenttab = getParentTab(); 500 501 if($singlepane_view == 'true') 502 $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; 503 else 504 $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; 505 506 $button = ''; 507 508 if($actions && getFieldVisibilityPermission($related_module, $current_user->id, 'parent_id', 'readwrite') == '0') { 509 if(is_string($actions)) $actions = explode(',', strtoupper($actions)); 510 if(in_array('SELECT', $actions) && isPermitted($related_module,4, '') == 'yes') { 511 $button .= "<input title='".getTranslatedString('LBL_SELECT')." ". getTranslatedString($related_module). "' class='crmbutton small edit' type='button' onclick=\"return window.open('index.php?module=$related_module&return_module=$currentModule&action=Popup&popuptype=detailview&select=enable&form=EditView&form_submit=false&recordid=$id&parenttab=$parenttab','test','width=640,height=602,resizable=0,scrollbars=0');\" value='". getTranslatedString('LBL_SELECT'). " " . getTranslatedString($related_module) ."'> "; 512 } 513 if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { 514 $button .= "<input title='".getTranslatedString('LBL_ADD_NEW'). " ". getTranslatedString($singular_modname) ."' class='crmbutton small create'" . 515 " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\"' type='submit' name='button'" . 516 " value='". getTranslatedString('LBL_ADD_NEW'). " " . getTranslatedString($singular_modname) ."'> "; 517 } 518 } 519 520 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 521 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 522 $query = "select case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name, 523 vtiger_crmentity.crmid, vtiger_troubletickets.title, vtiger_contactdetails.contactid, vtiger_troubletickets.parent_id, 524 vtiger_contactdetails.firstname, vtiger_contactdetails.lastname, vtiger_troubletickets.status, vtiger_troubletickets.priority, 525 vtiger_crmentity.smownerid, vtiger_troubletickets.ticket_no, vtiger_troubletickets.contact_id 526 from vtiger_troubletickets inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_troubletickets.ticketid 527 left join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_troubletickets.contact_id 528 LEFT JOIN vtiger_ticketcf ON vtiger_troubletickets.ticketid = vtiger_ticketcf.ticketid 529 left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid 530 left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid 531 where vtiger_crmentity.deleted=0 and vtiger_contactdetails.contactid=".$id; 532 533 $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); 534 535 if($return_value == null) $return_value = Array(); 536 $return_value['CUSTOM_BUTTON'] = $button; 537 538 $log->debug("Exiting get_tickets method ..."); 539 return $return_value; 540 } 541 542 /** 543 * Function to get Contact related Quotes 544 * @param integer $id - contactid 545 * returns related Quotes record in array format 546 */ 547 function get_quotes($id, $cur_tab_id, $rel_tab_id, $actions=false) { 548 global $log, $singlepane_view,$currentModule,$current_user; 549 $log->debug("Entering get_quotes(".$id.") method ..."); 550 $this_module = $currentModule; 551 552 $related_module = vtlib_getModuleNameById($rel_tab_id); 553 require_once("modules/$related_module/$related_module.php"); 554 $other = new $related_module(); 555 vtlib_setup_modulevars($related_module, $other); 556 $singular_modname = vtlib_toSingular($related_module); 557 558 $parenttab = getParentTab(); 559 560 if($singlepane_view == 'true') 561 $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; 562 else 563 $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; 564 565 $button = ''; 566 567 if($actions && getFieldVisibilityPermission($related_module, $current_user->id, 'contact_id', 'readwrite') == '0') { 568 if(is_string($actions)) $actions = explode(',', strtoupper($actions)); 569 if(in_array('SELECT', $actions) && isPermitted($related_module,4, '') == 'yes') { 570 $button .= "<input title='".getTranslatedString('LBL_SELECT')." ". getTranslatedString($related_module). "' class='crmbutton small edit' type='button' onclick=\"return window.open('index.php?module=$related_module&return_module=$currentModule&action=Popup&popuptype=detailview&select=enable&form=EditView&form_submit=false&recordid=$id&parenttab=$parenttab','test','width=640,height=602,resizable=0,scrollbars=0');\" value='". getTranslatedString('LBL_SELECT'). " " . getTranslatedString($related_module) ."'> "; 571 } 572 if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { 573 $button .= "<input title='".getTranslatedString('LBL_ADD_NEW'). " ". getTranslatedString($singular_modname) ."' class='crmbutton small create'" . 574 " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\"' type='submit' name='button'" . 575 " value='". getTranslatedString('LBL_ADD_NEW'). " " . getTranslatedString($singular_modname) ."'> "; 576 } 577 } 578 579 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 580 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 581 $query = "select case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name,vtiger_crmentity.*, vtiger_quotes.*,vtiger_potential.potentialname,vtiger_contactdetails.lastname,vtiger_account.accountname 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_account on vtiger_account.accountid = vtiger_quotes.accountid LEFT JOIN vtiger_quotescf ON vtiger_quotescf.quoteid = vtiger_quotes.quoteid LEFT JOIN vtiger_quotesbillads ON vtiger_quotesbillads.quotebilladdressid = vtiger_quotes.quoteid LEFT JOIN vtiger_quotesshipads ON vtiger_quotesshipads.quoteshipaddressid = vtiger_quotes.quoteid left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid where vtiger_crmentity.deleted=0 and vtiger_contactdetails.contactid=".$id; 582 583 $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); 584 585 if($return_value == null) $return_value = Array(); 586 $return_value['CUSTOM_BUTTON'] = $button; 587 588 $log->debug("Exiting get_quotes method ..."); 589 return $return_value; 590 } 591 /** 592 * Function to get Contact related SalesOrder 593 * @param integer $id - contactid 594 * returns related SalesOrder record in array format 595 */ 596 function get_salesorder($id, $cur_tab_id, $rel_tab_id, $actions=false) { 597 global $log, $singlepane_view,$currentModule,$current_user; 598 $log->debug("Entering get_salesorder(".$id.") method ..."); 599 $this_module = $currentModule; 600 601 $related_module = vtlib_getModuleNameById($rel_tab_id); 602 require_once("modules/$related_module/$related_module.php"); 603 $other = new $related_module(); 604 vtlib_setup_modulevars($related_module, $other); 605 $singular_modname = vtlib_toSingular($related_module); 606 607 $parenttab = getParentTab(); 608 609 if($singlepane_view == 'true') 610 $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; 611 else 612 $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; 613 614 $button = ''; 615 616 if($actions && getFieldVisibilityPermission($related_module, $current_user->id, 'contact_id', 'readwrite') == '0') { 617 if(is_string($actions)) $actions = explode(',', strtoupper($actions)); 618 if(in_array('SELECT', $actions) && isPermitted($related_module,4, '') == 'yes') { 619 $button .= "<input title='".getTranslatedString('LBL_SELECT')." ". getTranslatedString($related_module). "' class='crmbutton small edit' type='button' onclick=\"return window.open('index.php?module=$related_module&return_module=$currentModule&action=Popup&popuptype=detailview&select=enable&form=EditView&form_submit=false&recordid=$id&parenttab=$parenttab','test','width=640,height=602,resizable=0,scrollbars=0');\" value='". getTranslatedString('LBL_SELECT'). " " . getTranslatedString($related_module) ."'> "; 620 } 621 if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { 622 $button .= "<input title='".getTranslatedString('LBL_ADD_NEW'). " ". getTranslatedString($singular_modname) ."' class='crmbutton small create'" . 623 " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\"' type='submit' name='button'" . 624 " value='". getTranslatedString('LBL_ADD_NEW'). " " . getTranslatedString($singular_modname) ."'> "; 625 } 626 } 627 628 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 629 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 630 $query = "select case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as 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_salesordercf ON vtiger_salesordercf.salesorderid = vtiger_salesorder.salesorderid LEFT JOIN vtiger_sobillads ON vtiger_sobillads.sobilladdressid = vtiger_salesorder.salesorderid LEFT JOIN vtiger_soshipads ON vtiger_soshipads.soshipaddressid = 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 JOIN vtiger_invoice_recurring_info ON vtiger_invoice_recurring_info.start_period = vtiger_salesorder.salesorderid left outer join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_salesorder.contactid left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid where vtiger_crmentity.deleted=0 and vtiger_salesorder.contactid = ".$id; 631 632 $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); 633 634 if($return_value == null) $return_value = Array(); 635 $return_value['CUSTOM_BUTTON'] = $button; 636 637 $log->debug("Exiting get_salesorder method ..."); 638 return $return_value; 639 } 640 /** 641 * Function to get Contact related Products 642 * @param integer $id - contactid 643 * returns related Products record in array format 644 */ 645 function get_products($id, $cur_tab_id, $rel_tab_id, $actions=false) { 646 global $log, $singlepane_view,$currentModule,$current_user; 647 $log->debug("Entering get_products(".$id.") method ..."); 648 $this_module = $currentModule; 649 650 $related_module = vtlib_getModuleNameById($rel_tab_id); 651 require_once("modules/$related_module/$related_module.php"); 652 $other = new $related_module(); 653 vtlib_setup_modulevars($related_module, $other); 654 $singular_modname = vtlib_toSingular($related_module); 655 656 $parenttab = getParentTab(); 657 658 if($singlepane_view == 'true') 659 $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; 660 else 661 $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; 662 663 $button = ''; 664 665 if($actions) { 666 if(is_string($actions)) $actions = explode(',', strtoupper($actions)); 667 if(in_array('SELECT', $actions) && isPermitted($related_module,4, '') == 'yes') { 668 $button .= "<input title='".getTranslatedString('LBL_SELECT')." ". getTranslatedString($related_module). "' class='crmbutton small edit' type='button' onclick=\"return window.open('index.php?module=$related_module&return_module=$currentModule&action=Popup&popuptype=detailview&select=enable&form=EditView&form_submit=false&recordid=$id&parenttab=$parenttab','test','width=640,height=602,resizable=0,scrollbars=0');\" value='". getTranslatedString('LBL_SELECT'). " " . getTranslatedString($related_module) ."'> "; 669 } 670 if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { 671 $button .= "<input title='".getTranslatedString('LBL_ADD_NEW'). " ". getTranslatedString($singular_modname) ."' class='crmbutton small create'" . 672 " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\"' type='submit' name='button'" . 673 " value='". getTranslatedString('LBL_ADD_NEW'). " " . getTranslatedString($singular_modname) ."'> "; 674 } 675 } 676 677 $query = 'SELECT vtiger_products.productid, vtiger_products.productname, vtiger_products.productcode, 678 vtiger_products.commissionrate, vtiger_products.qty_per_unit, vtiger_products.unit_price, 679 vtiger_crmentity.crmid, vtiger_crmentity.smownerid,vtiger_contactdetails.lastname 680 FROM vtiger_products 681 INNER JOIN vtiger_seproductsrel 682 ON vtiger_seproductsrel.productid=vtiger_products.productid and vtiger_seproductsrel.setype="Contacts" 683 INNER JOIN vtiger_productcf 684 ON vtiger_products.productid = vtiger_productcf.productid 685 INNER JOIN vtiger_crmentity 686 ON vtiger_crmentity.crmid = vtiger_products.productid 687 INNER JOIN vtiger_contactdetails 688 ON vtiger_contactdetails.contactid = vtiger_seproductsrel.crmid 689 LEFT JOIN vtiger_users 690 ON vtiger_users.id=vtiger_crmentity.smownerid 691 LEFT JOIN vtiger_groups 692 ON vtiger_groups.groupid = vtiger_crmentity.smownerid 693 WHERE vtiger_contactdetails.contactid = '.$id.' and vtiger_crmentity.deleted = 0'; 694 695 $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); 696 697 if($return_value == null) $return_value = Array(); 698 $return_value['CUSTOM_BUTTON'] = $button; 699 700 $log->debug("Exiting get_products method ..."); 701 return $return_value; 702 } 703 704 /** 705 * Function to get Contact related PurchaseOrder 706 * @param integer $id - contactid 707 * returns related PurchaseOrder record in array format 708 */ 709 function get_purchase_orders($id, $cur_tab_id, $rel_tab_id, $actions=false) { 710 global $log, $singlepane_view,$currentModule,$current_user; 711 $log->debug("Entering get_purchase_orders(".$id.") method ..."); 712 $this_module = $currentModule; 713 714 $related_module = vtlib_getModuleNameById($rel_tab_id); 715 require_once("modules/$related_module/$related_module.php"); 716 $other = new $related_module(); 717 vtlib_setup_modulevars($related_module, $other); 718 $singular_modname = vtlib_toSingular($related_module); 719 720 $parenttab = getParentTab(); 721 722 if($singlepane_view == 'true') 723 $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; 724 else 725 $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; 726 727 $button = ''; 728 729 if($actions && getFieldVisibilityPermission($related_module, $current_user->id, 'contact_id', 'readwrite') == '0') { 730 if(is_string($actions)) $actions = explode(',', strtoupper($actions)); 731 if(in_array('SELECT', $actions) && isPermitted($related_module,4, '') == 'yes') { 732 $button .= "<input title='".getTranslatedString('LBL_SELECT')." ". getTranslatedString($related_module). "' class='crmbutton small edit' type='button' onclick=\"return window.open('index.php?module=$related_module&return_module=$currentModule&action=Popup&popuptype=detailview&select=enable&form=EditView&form_submit=false&recordid=$id&parenttab=$parenttab','test','width=640,height=602,resizable=0,scrollbars=0');\" value='". getTranslatedString('LBL_SELECT'). " " . getTranslatedString($related_module) ."'> "; 733 } 734 if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { 735 $button .= "<input title='".getTranslatedString('LBL_ADD_NEW'). " ". getTranslatedString($singular_modname) ."' class='crmbutton small create'" . 736 " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\"' type='submit' name='button'" . 737 " value='". getTranslatedString('LBL_ADD_NEW'). " " . getTranslatedString($singular_modname) ."'> "; 738 } 739 } 740 741 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 742 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 743 $query = "select case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as 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_purchaseordercf ON vtiger_purchaseordercf.purchaseorderid = vtiger_purchaseorder.purchaseorderid LEFT JOIN vtiger_pobillads ON vtiger_pobillads.pobilladdressid = vtiger_purchaseorder.purchaseorderid LEFT JOIN vtiger_poshipads ON vtiger_poshipads.poshipaddressid = vtiger_purchaseorder.purchaseorderid left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid where vtiger_crmentity.deleted=0 and vtiger_purchaseorder.contactid=".$id; 744 745 $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); 746 747 if($return_value == null) $return_value = Array(); 748 $return_value['CUSTOM_BUTTON'] = $button; 749 750 $log->debug("Exiting get_purchase_orders method ..."); 751 return $return_value; 752 } 753 754 /** Returns a list of the associated emails 755 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. 756 * All Rights Reserved.. 757 * Contributor(s): ______________________________________.. 758 */ 759 function get_emails($id, $cur_tab_id, $rel_tab_id, $actions=false) { 760 global $log, $singlepane_view,$currentModule,$current_user; 761 $log->debug("Entering get_emails(".$id.") method ..."); 762 $this_module = $currentModule; 763 764 $related_module = vtlib_getModuleNameById($rel_tab_id); 765 require_once("modules/$related_module/$related_module.php"); 766 $other = new $related_module(); 767 vtlib_setup_modulevars($related_module, $other); 768 $singular_modname = vtlib_toSingular($related_module); 769 770 $parenttab = getParentTab(); 771 772 if($singlepane_view == 'true') 773 $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; 774 else 775 $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; 776 777 $button = ''; 778 779 $button .= '<input type="hidden" name="email_directing_module"><input type="hidden" name="record">'; 780 781 if($actions) { 782 if(is_string($actions)) $actions = explode(',', strtoupper($actions)); 783 if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { 784 $button .= "<input title='". getTranslatedString('LBL_ADD_NEW')." ". getTranslatedString($singular_modname)."' accessyKey='F' class='crmbutton small create' onclick='fnvshobj(this,\"sendmail_cont\");sendmail(\"$this_module\",$id);' type='button' name='button' value='". getTranslatedString('LBL_ADD_NEW')." ". getTranslatedString($singular_modname)."'></td>"; 785 } 786 } 787 788 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 789 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 790 $query = "select case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name," . 791 " vtiger_activity.activityid, vtiger_activity.subject, vtiger_activity.activitytype, vtiger_crmentity.modifiedtime," . 792 " vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_activity.date_start, vtiger_activity.time_start, vtiger_seactivityrel.crmid as parent_id " . 793 " from vtiger_activity, vtiger_seactivityrel, vtiger_contactdetails, vtiger_users, vtiger_crmentity" . 794 " left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid" . 795 " where vtiger_seactivityrel.activityid = vtiger_activity.activityid" . 796 " and vtiger_contactdetails.contactid = vtiger_seactivityrel.crmid and vtiger_users.id=vtiger_crmentity.smownerid" . 797 " and vtiger_crmentity.crmid = vtiger_activity.activityid and vtiger_contactdetails.contactid = ".$id." and" . 798 " vtiger_activity.activitytype='Emails' and vtiger_crmentity.deleted = 0"; 799 800 $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); 801 802 if($return_value == null) $return_value = Array(); 803 $return_value['CUSTOM_BUTTON'] = $button; 804 805 $log->debug("Exiting get_emails method ..."); 806 return $return_value; 807 } 808 809 /** Returns a list of the associated Campaigns 810 * @param $id -- campaign id :: Type Integer 811 * @returns list of campaigns in array format 812 */ 813 814 function get_campaigns($id, $cur_tab_id, $rel_tab_id, $actions=false) { 815 global $log, $singlepane_view,$currentModule,$current_user; 816 $log->debug("Entering get_campaigns(".$id.") method ..."); 817 $this_module = $currentModule; 818 819 $related_module = vtlib_getModuleNameById($rel_tab_id); 820 require_once("modules/$related_module/$related_module.php"); 821 $other = new $related_module(); 822 vtlib_setup_modulevars($related_module, $other); 823 $singular_modname = vtlib_toSingular($related_module); 824 825 $parenttab = getParentTab(); 826 827 if($singlepane_view == 'true') 828 $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; 829 else 830 $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; 831 832 $button = ''; 833 834 $button .= '<input type="hidden" name="email_directing_module"><input type="hidden" name="record">'; 835 836 if($actions) { 837 if(is_string($actions)) $actions = explode(',', strtoupper($actions)); 838 if(in_array('SELECT', $actions) && isPermitted($related_module,4, '') == 'yes') { 839 $button .= "<input title='".getTranslatedString('LBL_SELECT')." ". getTranslatedString($related_module). "' class='crmbutton small edit' type='button' onclick=\"return window.open('index.php?module=$related_module&return_module=$currentModule&action=Popup&popuptype=detailview&select=enable&form=EditView&form_submit=false&recordid=$id&parenttab=$parenttab','test','width=640,height=602,resizable=0,scrollbars=0');\" value='". getTranslatedString('LBL_SELECT'). " " . getTranslatedString($related_module) ."'> "; 840 } 841 if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { 842 $button .= "<input title='". getTranslatedString('LBL_ADD_NEW')." ". getTranslatedString($singular_modname)."' accessyKey='F' class='crmbutton small create' onclick='fnvshobj(this,\"sendmail_cont\");sendmail(\"$this_module\",$id);' type='button' name='button' value='". getTranslatedString('LBL_ADD_NEW')." ". getTranslatedString($singular_modname)."'></td>"; 843 } 844 } 845 846 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 847 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 848 $query = "SELECT case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name, 849 vtiger_campaign.campaignid, vtiger_campaign.campaignname, vtiger_campaign.campaigntype, vtiger_campaign.campaignstatus, 850 vtiger_campaign.expectedrevenue, vtiger_campaign.closingdate, vtiger_crmentity.crmid, vtiger_crmentity.smownerid, 851 vtiger_crmentity.modifiedtime from vtiger_campaign 852 inner join vtiger_campaigncontrel on vtiger_campaigncontrel.campaignid=vtiger_campaign.campaignid 853 inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_campaign.campaignid 854 inner join vtiger_campaignscf ON vtiger_campaignscf.campaignid = vtiger_campaign.campaignid 855 left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid 856 left join vtiger_users on vtiger_users.id = vtiger_crmentity.smownerid 857 where vtiger_campaigncontrel.contactid=".$id." and vtiger_crmentity.deleted=0"; 858 859 $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); 860 861 if($return_value == null) $return_value = Array(); 862 $return_value['CUSTOM_BUTTON'] = $button; 863 864 $log->debug("Exiting get_campaigns method ..."); 865 return $return_value; 866 } 867 868 /** 869 * Function to get Contact related Invoices 870 * @param integer $id - contactid 871 * returns related Invoices record in array format 872 */ 873 function get_invoices($id, $cur_tab_id, $rel_tab_id, $actions=false) { 874 global $log, $singlepane_view,$currentModule,$current_user; 875 $log->debug("Entering get_invoices(".$id.") method ..."); 876 $this_module = $currentModule; 877 878 $related_module = vtlib_getModuleNameById($rel_tab_id); 879 require_once("modules/$related_module/$related_module.php"); 880 $other = new $related_module(); 881 vtlib_setup_modulevars($related_module, $other); 882 $singular_modname = vtlib_toSingular($related_module); 883 884 $parenttab = getParentTab(); 885 886 if($singlepane_view == 'true') 887 $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; 888 else 889 $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; 890 891 $button = ''; 892 893 if($actions && getFieldVisibilityPermission($related_module, $current_user->id, 'contact_id', 'readwrite') == '0') { 894 if(is_string($actions)) $actions = explode(',', strtoupper($actions)); 895 if(in_array('SELECT', $actions) && isPermitted($related_module,4, '') == 'yes') { 896 $button .= "<input title='".getTranslatedString('LBL_SELECT')." ". getTranslatedString($related_module). "' class='crmbutton small edit' type='button' onclick=\"return window.open('index.php?module=$related_module&return_module=$currentModule&action=Popup&popuptype=detailview&select=enable&form=EditView&form_submit=false&recordid=$id&parenttab=$parenttab','test','width=640,height=602,resizable=0,scrollbars=0');\" value='". getTranslatedString('LBL_SELECT'). " " . getTranslatedString($related_module) ."'> "; 897 } 898 if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { 899 $button .= "<input title='".getTranslatedString('LBL_ADD_NEW'). " ". getTranslatedString($singular_modname) ."' class='crmbutton small create'" . 900 " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\"' type='submit' name='button'" . 901 " value='". getTranslatedString('LBL_ADD_NEW'). " " . getTranslatedString($singular_modname) ."'> "; 902 } 903 } 904 905 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 906 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 907 $query = "SELECT case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name, 908 vtiger_crmentity.*, 909 vtiger_invoice.*, 910 vtiger_contactdetails.lastname,vtiger_contactdetails.firstname, 911 vtiger_salesorder.subject AS salessubject 912 FROM vtiger_invoice 913 INNER JOIN vtiger_crmentity 914 ON vtiger_crmentity.crmid = vtiger_invoice.invoiceid 915 LEFT OUTER JOIN vtiger_contactdetails 916 ON vtiger_contactdetails.contactid = vtiger_invoice.contactid 917 LEFT OUTER JOIN vtiger_salesorder 918 ON vtiger_salesorder.salesorderid = vtiger_invoice.salesorderid 919 LEFT JOIN vtiger_groups 920 ON vtiger_groups.groupid = vtiger_crmentity.smownerid 921 LEFT JOIN vtiger_invoicecf 922 ON vtiger_invoicecf.invoiceid = vtiger_invoice.invoiceid 923 LEFT JOIN vtiger_invoicebillads 924 ON vtiger_invoicebillads.invoicebilladdressid = vtiger_invoice.invoiceid 925 LEFT JOIN vtiger_invoiceshipads 926 ON vtiger_invoiceshipads.invoiceshipaddressid = vtiger_invoice.invoiceid 927 LEFT JOIN vtiger_users 928 ON vtiger_crmentity.smownerid = vtiger_users.id 929 WHERE vtiger_crmentity.deleted = 0 930 AND vtiger_contactdetails.contactid = ".$id; 931 932 $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); 933 934 if($return_value == null) $return_value = Array(); 935 $return_value['CUSTOM_BUTTON'] = $button; 936 937 $log->debug("Exiting get_invoices method ..."); 938 return $return_value; 939 } 940 941 /** 942 * Function to get Contact related vendors. 943 * @param integer $id - contactid 944 * returns related vendor records in array format 945 */ 946 function get_vendors($id, $cur_tab_id, $rel_tab_id, $actions=false) { 947 global $log, $singlepane_view,$currentModule,$current_user; 948 $log->debug("Entering get_vendors(".$id.") method ..."); 949 $this_module = $currentModule; 950 951 $related_module = vtlib_getModuleNameById($rel_tab_id); 952 require_once("modules/$related_module/$related_module.php"); 953 $other = new $related_module(); 954 vtlib_setup_modulevars($related_module, $other); 955 $singular_modname = vtlib_toSingular($related_module); 956 957 $parenttab = getParentTab(); 958 959 if($singlepane_view == 'true') 960 $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; 961 else 962 $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; 963 964 $button = ''; 965 966 if($actions && getFieldVisibilityPermission($related_module, $current_user->id, 'parent_id', 'readwrite') == '0') { 967 if(is_string($actions)) $actions = explode(',', strtoupper($actions)); 968 if(in_array('SELECT', $actions) && isPermitted($related_module,4, '') == 'yes') { 969 $button .= "<input title='".getTranslatedString('LBL_SELECT')." ". getTranslatedString($related_module). "' class='crmbutton small edit' type='button' onclick=\"return window.open('index.php?module=$related_module&return_module=$currentModule&action=Popup&popuptype=detailview&select=enable&form=EditView&form_submit=false&recordid=$id&parenttab=$parenttab','test','width=640,height=602,resizable=0,scrollbars=0');\" value='". getTranslatedString('LBL_SELECT'). " " . getTranslatedString($related_module) ."'> "; 970 } 971 if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { 972 $button .= "<input title='".getTranslatedString('LBL_ADD_NEW'). " ". getTranslatedString($singular_modname) ."' class='crmbutton small create'" . 973 " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\"' type='submit' name='button'" . 974 " value='". getTranslatedString('LBL_ADD_NEW'). " " . getTranslatedString($singular_modname) ."'> "; 975 } 976 } 977 978 $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=> 979 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 980 $query = "SELECT case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name, 981 vtiger_crmentity.crmid, vtiger_vendor.*, vtiger_vendorcf.* 982 from vtiger_vendor inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_vendor.vendorid 983 INNER JOIN vtiger_vendorcontactrel on vtiger_vendorcontactrel.vendorid=vtiger_vendor.vendorid 984 LEFT JOIN vtiger_vendorcf on vtiger_vendorcf.vendorid=vtiger_vendor.vendorid 985 LEFT JOIN vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid 986 LEFT JOIN vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid 987 WHERE vtiger_crmentity.deleted=0 and vtiger_vendorcontactrel.contactid=".$id; 988 989 $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); 990 991 if($return_value == null) $return_value = Array(); 992 $return_value['CUSTOM_BUTTON'] = $button; 993 994 $log->debug("Exiting get_vendors method ..."); 995 return $return_value; 996 } 997 998 /** Function to export the contact records in CSV Format 999 * @param reference variable - where condition is passed when the query is executed 1000 * Returns Export Contacts Query. 1001 */ 1002 function create_export_query($where) 1003 { 1004 global $log; 1005 global $current_user; 1006 $log->debug("Entering create_export_query(".$where.") method ..."); 1007 1008 include ("include/utils/ExportUtils.php"); 1009 1010 //To get the Permitted fields query and the permitted fields list 1011 $sql = getPermittedFieldsQuery("Contacts", "detail_view"); 1012 $fields_list = getFieldsListFromQuery($sql); 1013 1014 $query = "SELECT vtiger_contactdetails.salutation as 'Salutation',$fields_list,case when (vtiger_users.user_name not like '') then vtiger_users.user_name else vtiger_groups.groupname end as user_name 1015 FROM vtiger_contactdetails 1016 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid 1017 LEFT JOIN vtiger_users ON vtiger_crmentity.smownerid=vtiger_users.id and vtiger_users.status='Active' 1018 LEFT JOIN vtiger_account on vtiger_contactdetails.accountid=vtiger_account.accountid 1019 left join vtiger_contactaddress on vtiger_contactaddress.contactaddressid=vtiger_contactdetails.contactid 1020 left join vtiger_contactsubdetails on vtiger_contactsubdetails.contactsubscriptionid=vtiger_contactdetails.contactid 1021 left join vtiger_contactscf on vtiger_contactscf.contactid=vtiger_contactdetails.contactid 1022 left join vtiger_customerdetails on vtiger_customerdetails.customerid=vtiger_contactdetails.contactid 1023 LEFT JOIN vtiger_groups 1024 ON vtiger_groups.groupid = vtiger_crmentity.smownerid 1025 LEFT JOIN vtiger_contactdetails vtiger_contactdetails2 1026 ON vtiger_contactdetails2.contactid = vtiger_contactdetails.reportsto"; 1027 $query .= getNonAdminAccessControlQuery('Contacts',$current_user); 1028 $where_auto = " vtiger_crmentity.deleted = 0 "; 1029 1030 if($where != "") 1031 $query .= " WHERE ($where) AND ".$where_auto; 1032 else 1033 $query .= " WHERE ".$where_auto; 1034 1035 $log->info("Export Query Constructed Successfully"); 1036 $log->debug("Exiting create_export_query method ..."); 1037 return $query; 1038 } 1039 1040 1041 /** Function to get the Columnnames of the Contacts 1042 * Used By vtigerCRM Word Plugin 1043 * Returns the Merge Fields for Word Plugin 1044 */ 1045 function getColumnNames() 1046 { 1047 global $log, $current_user; 1048 $log->debug("Entering getColumnNames() method ..."); 1049 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 1050 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) 1051 { 1052 $sql1 = "select fieldlabel from vtiger_field where tabid=4 and block <> 75 and vtiger_field.presence in (0,2)"; 1053 $params1 = array(); 1054 }else 1055 { 1056 $profileList = getCurrentUserProfileList(); 1057 $sql1 = "select vtiger_field.fieldid,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 <> 75 and vtiger_field.displaytype in (1,2,4,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)"; 1058 $params1 = array(); 1059 if (count($profileList) > 0) { 1060 $sql1 .= " and vtiger_profile2field.profileid in (". generateQuestionMarks($profileList) .") group by fieldid"; 1061 array_push($params1, $profileList); 1062 } 1063 } 1064 $result = $this->db->pquery($sql1, $params1); 1065 $numRows = $this->db->num_rows($result); 1066 for($i=0; $i < $numRows;$i++) 1067 { 1068 $custom_fields[$i] = $this->db->query_result($result,$i,"fieldlabel"); 1069 $custom_fields[$i] = preg_replace("/\s+/","",$custom_fields[$i]); 1070 $custom_fields[$i] = strtoupper($custom_fields[$i]); 1071 } 1072 $mergeflds = $custom_fields; 1073 $log->debug("Exiting getColumnNames method ..."); 1074 return $mergeflds; 1075 } 1076 //End 1077 /** Function to get the Contacts assigned to a user with a valid email address. 1078 * @param varchar $username - User Name 1079 * @param varchar $emailaddress - Email Addr for each contact. 1080 * Used By vtigerCRM Outlook Plugin 1081 * Returns the Query 1082 */ 1083 function get_searchbyemailid($username,$emailaddress) 1084 { 1085 global $log; 1086 global $current_user; 1087 require_once ("modules/Users/Users.php"); 1088 $seed_user=new Users(); 1089 $user_id=$seed_user->retrieve_user_id($username); 1090 $current_user=$seed_user; 1091 $current_user->retrieve_entity_info($user_id, 'Users'); 1092 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 1093 require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); 1094 $log->debug("Entering get_searchbyemailid(".$username.",".$emailaddress.") method ..."); 1095 $query = "select vtiger_contactdetails.lastname,vtiger_contactdetails.firstname, 1096 vtiger_contactdetails.contactid, vtiger_contactdetails.salutation, 1097 vtiger_contactdetails.email,vtiger_contactdetails.title, 1098 vtiger_contactdetails.mobile,vtiger_account.accountname, 1099 vtiger_account.accountid as accountid from vtiger_contactdetails 1100 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid 1101 inner join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid 1102 left join vtiger_account on vtiger_account.accountid=vtiger_contactdetails.accountid 1103 left join vtiger_contactaddress on vtiger_contactaddress.contactaddressid=vtiger_contactdetails.contactid 1104 LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid"; 1105 $query .= getNonAdminAccessControlQuery('Contacts',$current_user); 1106 $query .= "where vtiger_crmentity.deleted=0"; 1107 if(trim($emailaddress) != '') { 1108 $query .= " and ((vtiger_contactdetails.email like '". formatForSqlLike($emailaddress) . 1109 "') or vtiger_contactdetails.lastname REGEXP REPLACE('".$emailaddress. 1110 "',' ','|') or vtiger_contactdetails.firstname REGEXP REPLACE('".$emailaddress. 1111 "',' ','|')) and vtiger_contactdetails.email != ''"; 1112 } else { 1113 $query .= " and (vtiger_contactdetails.email like '". formatForSqlLike($emailaddress) . 1114 "' and vtiger_contactdetails.email != '')"; 1115 } 1116 1117 $log->debug("Exiting get_searchbyemailid method ..."); 1118 return $this->plugin_process_list_query($query); 1119 } 1120 1121 /** Function to get the Contacts associated with the particular User Name. 1122 * @param varchar $user_name - User Name 1123 * Returns query 1124 */ 1125 1126 function get_contactsforol($user_name) 1127 { 1128 global $log,$adb; 1129 global $current_user; 1130 require_once ("modules/Users/Users.php"); 1131 $seed_user=new Users(); 1132 $user_id=$seed_user->retrieve_user_id($user_name); 1133 $current_user=$seed_user; 1134 $current_user->retrieve_entity_info($user_id, 'Users'); 1135 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 1136 require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); 1137 1138 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) 1139 { 1140 $sql1 = "select tablename,columnname from vtiger_field where tabid=4 and vtiger_field.presence in (0,2)"; 1141 $params1 = array(); 1142 }else 1143 { 1144 $profileList = getCurrentUserProfileList(); 1145 $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.displaytype in (1,2,4,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)"; 1146 $params1 = array(); 1147 if (count($profileList) > 0) { 1148 $sql1 .= " and vtiger_profile2field.profileid in (". generateQuestionMarks($profileList) .")"; 1149 array_push($params1, $profileList); 1150 } 1151 } 1152 $result1 = $adb->pquery($sql1, $params1); 1153 for($i=0;$i < $adb->num_rows($result1);$i++) 1154 { 1155 $permitted_lists[] = $adb->query_result($result1,$i,'tablename'); 1156 $permitted_lists[] = $adb->query_result($result1,$i,'columnname'); 1157 if($adb->query_result($result1,$i,'columnname') == "accountid") 1158 { 1159 $permitted_lists[] = 'vtiger_account'; 1160 $permitted_lists[] = 'accountname'; 1161 } 1162 } 1163 $permitted_lists = array_chunk($permitted_lists,2); 1164 $column_table_lists = array(); 1165 for($i=0;$i < count($permitted_lists);$i++) 1166 { 1167 $column_table_lists[] = implode(".",$permitted_lists[$i]); 1168 } 1169 1170 $log->debug("Entering get_contactsforol(".$user_name.") method ..."); 1171 $query = "select vtiger_contactdetails.contactid as id, ".implode(',',$column_table_lists)." from vtiger_contactdetails 1172 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid 1173 inner join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid 1174 left join vtiger_customerdetails on vtiger_customerdetails.customerid=vtiger_contactdetails.contactid 1175 left join vtiger_account on vtiger_account.accountid=vtiger_contactdetails.accountid 1176 left join vtiger_contactaddress on vtiger_contactaddress.contactaddressid=vtiger_contactdetails.contactid 1177 left join vtiger_contactsubdetails on vtiger_contactsubdetails.contactsubscriptionid = vtiger_contactdetails.contactid 1178 left join vtiger_campaigncontrel on vtiger_contactdetails.contactid = vtiger_campaigncontrel.contactid 1179 left join vtiger_campaignrelstatus on vtiger_campaignrelstatus.campaignrelstatusid = vtiger_campaigncontrel.campaignrelstatusid 1180 LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid 1181 where vtiger_crmentity.deleted=0 and vtiger_users.user_name='".$user_name."'"; 1182 $log->debug("Exiting get_contactsforol method ..."); 1183 return $query; 1184 } 1185 1186 1187 /** Function to handle module specific operations when saving a entity 1188 */ 1189 function save_module($module) 1190 { 1191 $this->insertIntoAttachment($this->id,$module); 1192 } 1193 1194 /** 1195 * 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. 1196 * @param int $id - entity id to which the vtiger_files to be uploaded 1197 * @param string $module - the current module name 1198 */ 1199 function insertIntoAttachment($id,$module) 1200 { 1201 global $log, $adb,$upload_badext; 1202 $log->debug("Entering into insertIntoAttachment($id,$module) method."); 1203 1204 $file_saved = false; 1205 //This is to added to store the existing attachment id of the contact where we should delete this when we give new image 1206 $old_attachmentid = $adb->query_result($adb->pquery("select vtiger_crmentity.crmid from vtiger_seattachmentsrel inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_seattachmentsrel.attachmentsid where vtiger_seattachmentsrel.crmid=?", array($id)),0,'crmid'); 1207 foreach($_FILES as $fileindex => $files) 1208 { 1209 if($files['name'] != '' && $files['size'] > 0) 1210 { 1211 $files['original_name'] = vtlib_purify($_REQUEST[$fileindex.'_hidden']); 1212 $file_saved = $this->uploadAndSaveFile($id,$module,$files); 1213 } 1214 } 1215 1216 $imageNameSql = 'SELECT name FROM vtiger_seattachmentsrel INNER JOIN vtiger_attachments ON 1217 vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid LEFT JOIN vtiger_contactdetails ON 1218 vtiger_contactdetails.contactid = vtiger_seattachmentsrel.crmid WHERE vtiger_seattachmentsrel.crmid = ?'; 1219 $imageNameResult = $adb->pquery($imageNameSql,array($id)); 1220 $imageName = decode_html($adb->query_result($imageNameResult, 0, "name")); 1221 1222 //Inserting image information of record into base table 1223 $adb->pquery('UPDATE vtiger_contactdetails SET imagename = ? WHERE contactid = ?',array($imageName,$id)); 1224 1225 //This is to handle the delete image for contacts 1226 if($module == 'Contacts' && $file_saved) 1227 { 1228 if($old_attachmentid != '') 1229 { 1230 $setype = $adb->query_result($adb->pquery("select setype from vtiger_crmentity where crmid=?", array($old_attachmentid)),0,'setype'); 1231 if($setype == 'Contacts Image') 1232 { 1233 $del_res1 = $adb->pquery("delete from vtiger_attachments where attachmentsid=?", array($old_attachmentid)); 1234 $del_res2 = $adb->pquery("delete from vtiger_seattachmentsrel where attachmentsid=?", array($old_attachmentid)); 1235 } 1236 } 1237 } 1238 1239 $log->debug("Exiting from insertIntoAttachment($id,$module) method."); 1240 } 1241 1242 /** 1243 * Move the related records of the specified list of id's to the given record. 1244 * @param String This module name 1245 * @param Array List of Entity Id's from which related records need to be transfered 1246 * @param Integer Id of the the Record to which the related records are to be moved 1247 */ 1248 function transferRelatedRecords($module, $transferEntityIds, $entityId) { 1249 global $adb,$log; 1250 $log->debug("Entering function transferRelatedRecords ($module, $transferEntityIds, $entityId)"); 1251 1252 $rel_table_arr = Array("Potentials"=>"vtiger_contpotentialrel","Potentials"=>"vtiger_potential","Activities"=>"vtiger_cntactivityrel", 1253 "Emails"=>"vtiger_seactivityrel","HelpDesk"=>"vtiger_troubletickets","Quotes"=>"vtiger_quotes","PurchaseOrder"=>"vtiger_purchaseorder", 1254 "SalesOrder"=>"vtiger_salesorder","Products"=>"vtiger_seproductsrel","Documents"=>"vtiger_senotesrel", 1255 "Attachments"=>"vtiger_seattachmentsrel","Campaigns"=>"vtiger_campaigncontrel",'Invoice'=>'vtiger_invoice', 1256 'ServiceContracts'=>'vtiger_servicecontracts','Project'=>'vtiger_project','Assets'=>'vtiger_assets'); 1257 1258 $tbl_field_arr = Array("vtiger_contpotentialrel"=>"potentialid","vtiger_potential"=>"potentialid","vtiger_cntactivityrel"=>"activityid", 1259 "vtiger_seactivityrel"=>"activityid","vtiger_troubletickets"=>"ticketid","vtiger_quotes"=>"quoteid","vtiger_purchaseorder"=>"purchaseorderid", 1260 "vtiger_salesorder"=>"salesorderid","vtiger_seproductsrel"=>"productid","vtiger_senotesrel"=>"notesid", 1261 "vtiger_seattachmentsrel"=>"attachmentsid","vtiger_campaigncontrel"=>"campaignid",'vtiger_invoice'=>'invoiceid', 1262 'vtiger_servicecontracts'=>'servicecontractsid','vtiger_project'=>'projectid','vtiger_assets'=>'assetsid', 1263 'vtiger_payments'=>'paymentsid'); 1264 1265 $entity_tbl_field_arr = Array("vtiger_contpotentialrel"=>"contactid","vtiger_potential"=>"contact_id","vtiger_cntactivityrel"=>"contactid", 1266 "vtiger_seactivityrel"=>"crmid","vtiger_troubletickets"=>"contact_id","vtiger_quotes"=>"contactid","vtiger_purchaseorder"=>"contactid", 1267 "vtiger_salesorder"=>"contactid","vtiger_seproductsrel"=>"crmid","vtiger_senotesrel"=>"crmid", 1268 "vtiger_seattachmentsrel"=>"crmid","vtiger_campaigncontrel"=>"contactid",'vtiger_invoice'=>'contactid', 1269 'vtiger_servicecontracts'=>'sc_related_to','vtiger_project'=>'linktoaccountscontacts','vtiger_assets'=>'contact', 1270 'vtiger_payments'=>'relatedcontact'); 1271 1272 foreach($transferEntityIds as $transferId) { 1273 foreach($rel_table_arr as $rel_module=>$rel_table) { 1274 $id_field = $tbl_field_arr[$rel_table]; 1275 $entity_id_field = $entity_tbl_field_arr[$rel_table]; 1276 // IN clause to avoid duplicate entries 1277 $sel_result = $adb->pquery("select $id_field from $rel_table where $entity_id_field=? " . 1278 " and $id_field not in (select $id_field from $rel_table where $entity_id_field=?)", 1279 array($transferId,$entityId)); 1280 $res_cnt = $adb->num_rows($sel_result); 1281 if($res_cnt > 0) { 1282 for($i=0;$i<$res_cnt;$i++) { 1283 $id_field_value = $adb->query_result($sel_result,$i,$id_field); 1284 $adb->pquery("update $rel_table set $entity_id_field=? where $entity_id_field=? and $id_field=?", 1285 array($entityId,$transferId,$id_field_value)); 1286 } 1287 } 1288 } 1289 $adb->pquery("UPDATE vtiger_potential SET related_to = ? WHERE related_to = ?", array($entityId, $transferId)); 1290 } 1291 parent::transferRelatedRecords($module, $transferEntityIds, $entityId); 1292 $log->debug("Exiting transferRelatedRecords..."); 1293 } 1294 1295 /* 1296 * Function to get the secondary query part of a report 1297 * @param - $module primary module name 1298 * @param - $secmodule secondary module name 1299 * returns the query string formed on fetching the related data for report for secondary module 1300 */ 1301 function generateReportsSecQuery($module,$secmodule,$queryplanner){ 1302 $matrix = $queryplanner->newDependencyMatrix(); 1303 $matrix->setDependency('vtiger_crmentityContacts',array('vtiger_groupsContacts','vtiger_usersContacts','vtiger_lastModifiedByContacts')); 1304 $matrix->setDependency('vtiger_contactdetails', array('vtiger_crmentityContacts','vtiger_contactaddress', 1305 'vtiger_customerdetails','vtiger_contactsubdetails','vtiger_contactscf')); 1306 1307 if (!$queryplanner->requireTable('vtiger_contactdetails', $matrix)) { 1308 return ''; 1309 } 1310 1311 1312 $query = $this->getRelationQuery($module,$secmodule,"vtiger_contactdetails","contactid", $queryplanner); 1313 1314 if ($queryplanner->requireTable("vtiger_crmentityContacts",$matrix)){ 1315 $query .= " left join vtiger_crmentity as vtiger_crmentityContacts on vtiger_crmentityContacts.crmid = vtiger_contactdetails.contactid and vtiger_crmentityContacts.deleted=0"; 1316 } 1317 if ($queryplanner->requireTable("vtiger_contactdetailsContacts")){ 1318 $query .= " left join vtiger_contactdetails as vtiger_contactdetailsContacts on vtiger_contactdetailsContacts.contactid = vtiger_contactdetails.reportsto"; 1319 } 1320 if ($queryplanner->requireTable("vtiger_contactaddress")){ 1321 $query .= " left join vtiger_contactaddress on vtiger_contactdetails.contactid = vtiger_contactaddress.contactaddressid"; 1322 } 1323 if ($queryplanner->requireTable("vtiger_customerdetails")){ 1324 $query .= " left join vtiger_customerdetails on vtiger_customerdetails.customerid = vtiger_contactdetails.contactid"; 1325 } 1326 if ($queryplanner->requireTable("vtiger_contactsubdetails")){ 1327 $query .= " left join vtiger_contactsubdetails on vtiger_contactdetails.contactid = vtiger_contactsubdetails.contactsubscriptionid"; 1328 } 1329 if ($queryplanner->requireTable("vtiger_accountContacts")){ 1330 $query .= " left join vtiger_account as vtiger_accountContacts on vtiger_accountContacts.accountid = vtiger_contactdetails.accountid"; 1331 } 1332 if ($queryplanner->requireTable("vtiger_contactscf")){ 1333 $query .= " left join vtiger_contactscf on vtiger_contactdetails.contactid = vtiger_contactscf.contactid"; 1334 } 1335 if ($queryplanner->requireTable("vtiger_email_trackContacts")){ 1336 $query .= " LEFT JOIN vtiger_email_track AS vtiger_email_trackContacts ON vtiger_email_trackContacts.crmid = vtiger_contactdetails.contactid"; 1337 } 1338 if ($queryplanner->requireTable("vtiger_groupsContacts")){ 1339 $query .= " left join vtiger_groups as vtiger_groupsContacts on vtiger_groupsContacts.groupid = vtiger_crmentityContacts.smownerid"; 1340 } 1341 if ($queryplanner->requireTable("vtiger_usersContacts")){ 1342 $query .= " left join vtiger_users as vtiger_usersContacts on vtiger_usersContacts.id = vtiger_crmentityContacts.smownerid"; 1343 } 1344 if ($queryplanner->requireTable("vtiger_lastModifiedByContacts")){ 1345 $query .= " left join vtiger_users as vtiger_lastModifiedByContacts on vtiger_lastModifiedByContacts.id = vtiger_crmentityContacts.modifiedby "; 1346 } 1347 if ($queryplanner->requireTable("vtiger_createdbyContacts")){ 1348 $query .= " left join vtiger_users as vtiger_createdbyContacts on vtiger_createdbyContacts.id = vtiger_crmentityContacts.smcreatorid "; 1349 } 1350 return $query; 1351 } 1352 1353 /* 1354 * Function to get the relation tables for related modules 1355 * @param - $secmodule secondary module name 1356 * returns the array with table names and fieldnames storing relations between module and this module 1357 */ 1358 function setRelationTables($secmodule){ 1359 $rel_tables = array ( 1360 "Calendar" => array("vtiger_cntactivityrel"=>array("contactid","activityid"),"vtiger_contactdetails"=>"contactid"), 1361 "HelpDesk" => array("vtiger_troubletickets"=>array("contact_id","ticketid"),"vtiger_contactdetails"=>"contactid"), 1362 "Quotes" => array("vtiger_quotes"=>array("contactid","quoteid"),"vtiger_contactdetails"=>"contactid"), 1363 "PurchaseOrder" => array("vtiger_purchaseorder"=>array("contactid","purchaseorderid"),"vtiger_contactdetails"=>"contactid"), 1364 "SalesOrder" => array("vtiger_salesorder"=>array("contactid","salesorderid"),"vtiger_contactdetails"=>"contactid"), 1365 "Products" => array("vtiger_seproductsrel"=>array("crmid","productid"),"vtiger_contactdetails"=>"contactid"), 1366 "Campaigns" => array("vtiger_campaigncontrel"=>array("contactid","campaignid"),"vtiger_contactdetails"=>"contactid"), 1367 "Documents" => array("vtiger_senotesrel"=>array("crmid","notesid"),"vtiger_contactdetails"=>"contactid"), 1368 "Accounts" => array("vtiger_contactdetails"=>array("contactid","accountid")), 1369 "Invoice" => array("vtiger_invoice"=>array("contactid","invoiceid"),"vtiger_contactdetails"=>"contactid"), 1370 "Emails" => array("vtiger_seactivityrel"=>array("crmid","activityid"),"vtiger_contactdetails"=>"contactid"), 1371 ); 1372 return $rel_tables[$secmodule]; 1373 } 1374 1375 // Function to unlink all the dependent entities of the given Entity by Id 1376 function unlinkDependencies($module, $id) { 1377 global $log; 1378 1379 //Deleting Contact related Potentials. 1380 $pot_q = 'SELECT vtiger_crmentity.crmid FROM vtiger_crmentity 1381 INNER JOIN vtiger_potential ON vtiger_crmentity.crmid=vtiger_potential.potentialid 1382 LEFT JOIN vtiger_account ON vtiger_account.accountid=vtiger_potential.related_to 1383 WHERE vtiger_crmentity.deleted=0 AND vtiger_potential.related_to=?'; 1384 $pot_res = $this->db->pquery($pot_q, array($id)); 1385 $pot_ids_list = array(); 1386 for($k=0;$k < $this->db->num_rows($pot_res);$k++) 1387 { 1388 $pot_id = $this->db->query_result($pot_res,$k,"crmid"); 1389 $pot_ids_list[] = $pot_id; 1390 $sql = 'UPDATE vtiger_crmentity SET deleted = 1 WHERE crmid = ?'; 1391 $this->db->pquery($sql, array($pot_id)); 1392 } 1393 //Backup deleted Contact related Potentials. 1394 $params = array($id, RB_RECORD_UPDATED, 'vtiger_crmentity', 'deleted', 'crmid', implode(",", $pot_ids_list)); 1395 $this->db->pquery('INSERT INTO vtiger_relatedlists_rb VALUES(?,?,?,?,?,?)', $params); 1396 1397 //Backup Contact-Trouble Tickets Relation 1398 $tkt_q = 'SELECT ticketid FROM vtiger_troubletickets WHERE contact_id=?'; 1399 $tkt_res = $this->db->pquery($tkt_q, array($id)); 1400 if ($this->db->num_rows($tkt_res) > 0) { 1401 $tkt_ids_list = array(); 1402 for($k=0;$k < $this->db->num_rows($tkt_res);$k++) 1403 { 1404 $tkt_ids_list[] = $this->db->query_result($tkt_res,$k,"ticketid"); 1405 } 1406 $params = array($id, RB_RECORD_UPDATED, 'vtiger_troubletickets', 'contact_id', 'ticketid', implode(",", $tkt_ids_list)); 1407 $this->db->pquery('INSERT INTO vtiger_relatedlists_rb VALUES (?,?,?,?,?,?)', $params); 1408 } 1409 //removing the relationship of contacts with Trouble Tickets 1410 $this->db->pquery('UPDATE vtiger_troubletickets SET contact_id=0 WHERE contact_id=?', array($id)); 1411 1412 //Backup Contact-PurchaseOrder Relation 1413 $po_q = 'SELECT purchaseorderid FROM vtiger_purchaseorder WHERE contactid=?'; 1414 $po_res = $this->db->pquery($po_q, array($id)); 1415 if ($this->db->num_rows($po_res) > 0) { 1416 $po_ids_list = array(); 1417 for($k=0;$k < $this->db->num_rows($po_res);$k++) 1418 { 1419 $po_ids_list[] = $this->db->query_result($po_res,$k,"purchaseorderid"); 1420 } 1421 $params = array($id, RB_RECORD_UPDATED, 'vtiger_purchaseorder', 'contactid', 'purchaseorderid', implode(",", $po_ids_list)); 1422 $this->db->pquery('INSERT INTO vtiger_relatedlists_rb VALUES (?,?,?,?,?,?)', $params); 1423 } 1424 //removing the relationship of contacts with PurchaseOrder 1425 $this->db->pquery('UPDATE vtiger_purchaseorder SET contactid=0 WHERE contactid=?', array($id)); 1426 1427 //Backup Contact-SalesOrder Relation 1428 $so_q = 'SELECT salesorderid FROM vtiger_salesorder WHERE contactid=?'; 1429 $so_res = $this->db->pquery($so_q, array($id)); 1430 if ($this->db->num_rows($so_res) > 0) { 1431 $so_ids_list = array(); 1432 for($k=0;$k < $this->db->num_rows($so_res);$k++) 1433 { 1434 $so_ids_list[] = $this->db->query_result($so_res,$k,"salesorderid"); 1435 } 1436 $params = array($id, RB_RECORD_UPDATED, 'vtiger_salesorder', 'contactid', 'salesorderid', implode(",", $so_ids_list)); 1437 $this->db->pquery('INSERT INTO vtiger_relatedlists_rb VALUES (?,?,?,?,?,?)', $params); 1438 } 1439 //removing the relationship of contacts with SalesOrder 1440 $this->db->pquery('UPDATE vtiger_salesorder SET contactid=0 WHERE contactid=?', array($id)); 1441 1442 //Backup Contact-Quotes Relation 1443 $quo_q = 'SELECT quoteid FROM vtiger_quotes WHERE contactid=?'; 1444 $quo_res = $this->db->pquery($quo_q, array($id)); 1445 if ($this->db->num_rows($quo_res) > 0) { 1446 $quo_ids_list = array(); 1447 for($k=0;$k < $this->db->num_rows($quo_res);$k++) 1448 { 1449 $quo_ids_list[] = $this->db->query_result($quo_res,$k,"quoteid"); 1450 } 1451 $params = array($id, RB_RECORD_UPDATED, 'vtiger_quotes', 'contactid', 'quoteid', implode(",", $quo_ids_list)); 1452 $this->db->pquery('INSERT INTO vtiger_relatedlists_rb VALUES (?,?,?,?,?,?)', $params); 1453 } 1454 //removing the relationship of contacts with Quotes 1455 $this->db->pquery('UPDATE vtiger_quotes SET contactid=0 WHERE contactid=?', array($id)); 1456 //remove the portal info the contact 1457 $this->db->pquery('DELETE FROM vtiger_portalinfo WHERE id = ?', array($id)); 1458 $this->db->pquery('UPDATE vtiger_customerdetails SET portal=0,support_start_date=NULL,support_end_date=NULl WHERE customerid=?', array($id)); 1459 parent::unlinkDependencies($module, $id); 1460 } 1461 1462 // Function to unlink an entity with given Id from another entity 1463 function unlinkRelationship($id, $return_module, $return_id) { 1464 global $log; 1465 if(empty($return_module) || empty($return_id)) return; 1466 1467 if($return_module == 'Accounts') { 1468 $sql = 'UPDATE vtiger_contactdetails SET accountid = ? WHERE contactid = ?'; 1469 $this->db->pquery($sql, array(null, $id)); 1470 } elseif($return_module == 'Potentials') { 1471 $sql = 'DELETE FROM vtiger_contpotentialrel WHERE contactid=? AND potentialid=?'; 1472 $this->db->pquery($sql, array($id, $return_id)); 1473 1474 //If contact related to potential through edit of record,that entry will be present in 1475 //vtiger_potential contact_id column,which should be set to zero 1476 $sql = 'UPDATE vtiger_potential SET contact_id = ? WHERE contact_id=? AND potentialid=?'; 1477 $this->db->pquery($sql, array(0,$id, $return_id)); 1478 } elseif($return_module == 'Campaigns') { 1479 $sql = 'DELETE FROM vtiger_campaigncontrel WHERE contactid=? AND campaignid=?'; 1480 $this->db->pquery($sql, array($id, $return_id)); 1481 } elseif($return_module == 'Products') { 1482 $sql = 'DELETE FROM vtiger_seproductsrel WHERE crmid=? AND productid=?'; 1483 $this->db->pquery($sql, array($id, $return_id)); 1484 } elseif($return_module == 'Vendors') { 1485 $sql = 'DELETE FROM vtiger_vendorcontactrel WHERE vendorid=? AND contactid=?'; 1486 $this->db->pquery($sql, array($return_id, $id)); 1487 } else { 1488 $sql = 'DELETE FROM vtiger_crmentityrel WHERE (crmid=? AND relmodule=? AND relcrmid=?) OR (relcrmid=? AND module=? AND crmid=?)'; 1489 $params = array($id, $return_module, $return_id, $id, $return_module, $return_id); 1490 $this->db->pquery($sql, $params); 1491 } 1492 } 1493 1494 //added to get mail info for portal user 1495 //type argument included when when addin customizable tempalte for sending portal login details 1496 public static function getPortalEmailContents($entityData, $password, $type='') { 1497 require_once 'config.inc.php'; 1498 global $PORTAL_URL, $HELPDESK_SUPPORT_EMAIL_ID; 1499 1500 $adb = PearDatabase::getInstance(); 1501 $moduleName = $entityData->getModuleName(); 1502 1503 $companyDetails = getCompanyDetails(); 1504 1505 $portalURL = '<a href="'.$PORTAL_URL.'" style="font-family:Arial, Helvetica, sans-serif;font-size:12px; font-weight:bolder;text-decoration:none;color: #4242FD;">'.getTranslatedString('Please Login Here', $moduleName).'</a>'; 1506 1507 //here id is hardcoded with 5. it is for support start notification in vtiger_notificationscheduler 1508 $query='SELECT vtiger_emailtemplates.subject,vtiger_emailtemplates.body 1509 FROM vtiger_notificationscheduler 1510 INNER JOIN vtiger_emailtemplates ON vtiger_emailtemplates.templateid=vtiger_notificationscheduler.notificationbody 1511 WHERE schedulednotificationid=5'; 1512 1513 $result = $adb->pquery($query, array()); 1514 $body=decode_html($adb->query_result($result,0,'body')); 1515 $contents=$body; 1516 $contents = str_replace('$contact_name$',$entityData->get('firstname')." ".$entityData->get('lastname'),$contents); 1517 $contents = str_replace('$login_name$',$entityData->get('email'),$contents); 1518 $contents = str_replace('$password$',$password,$contents); 1519 $contents = str_replace('$URL$',$portalURL,$contents); 1520 $contents = str_replace('$support_team$',getTranslatedString('Support Team', $moduleName),$contents); 1521 $contents = str_replace('$logo$','<img src="cid:logo" />',$contents); 1522 1523 //Company Details 1524 $contents = str_replace('$address$',$companyDetails['address'],$contents); 1525 $contents = str_replace('$companyname$',$companyDetails['companyname'],$contents); 1526 $contents = str_replace('$phone$',$companyDetails['phone'],$contents); 1527 $contents = str_replace('$companywebsite$',$companyDetails['website'],$contents); 1528 $contents = str_replace('$supportemail$',$HELPDESK_SUPPORT_EMAIL_ID,$contents); 1529 1530 if($type == "LoginDetails") { 1531 $temp=$contents; 1532 $value["subject"]=decode_html($adb->query_result($result,0,'subject')); 1533 $value["body"]=$temp; 1534 return $value; 1535 } 1536 return $contents; 1537 } 1538 1539 function save_related_module($module, $crmid, $with_module, $with_crmids) { 1540 $adb = PearDatabase::getInstance(); 1541 1542 if(!is_array($with_crmids)) $with_crmids = Array($with_crmids); 1543 foreach($with_crmids as $with_crmid) { 1544 if($with_module == 'Products') { 1545 $adb->pquery("insert into vtiger_seproductsrel values (?,?,?)", array($crmid, $with_crmid, 'Contacts')); 1546 1547 } elseif($with_module == 'Campaigns') { 1548 $adb->pquery("insert into vtiger_campaigncontrel values(?,?,1)", array($with_crmid, $crmid)); 1549 1550 } elseif($with_module == 'Potentials') { 1551 $adb->pquery("insert into vtiger_contpotentialrel values(?,?)", array($crmid, $with_crmid)); 1552 1553 } 1554 else if($with_module == 'Vendors'){ 1555 $adb->pquery("insert into vtiger_vendorcontactrel values (?,?)", array($with_crmid,$crmid)); 1556 }else { 1557 parent::save_related_module($module, $crmid, $with_module, $with_crmid); 1558 } 1559 } 1560 } 1561 1562 function getListButtons($app_strings,$mod_strings = false) { 1563 $list_buttons = Array(); 1564 1565 if(isPermitted('Contacts','Delete','') == 'yes') { 1566 $list_buttons['del'] = $app_strings[LBL_MASS_DELETE]; 1567 } 1568 if(isPermitted('Contacts','EditView','') == 'yes') { 1569 $list_buttons['mass_edit'] = $app_strings[LBL_MASS_EDIT]; 1570 $list_buttons['c_owner'] = $app_strings[LBL_CHANGE_OWNER]; 1571 } 1572 if(isPermitted('Emails','EditView','') == 'yes'){ 1573 $list_buttons['s_mail'] = $app_strings[LBL_SEND_MAIL_BUTTON]; 1574 } 1575 return $list_buttons; 1576 } 1577 } 1578 1579 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |