[ 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/Emails/Email.php,v 1.41 2005/04/28 08:11:21 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 23 include_once ('config.php'); 24 require_once ('include/logging.php'); 25 require_once ('include/database/PearDatabase.php'); 26 require_once ('data/SugarBean.php'); 27 require_once ('data/CRMEntity.php'); 28 require_once ('modules/Contacts/Contact.php'); 29 require_once ('modules/Accounts/Account.php'); 30 require_once ('modules/Potentials/Opportunity.php'); 31 require_once ('modules/Users/User.php'); 32 33 // Email is used to store customer information. 34 class Email extends CRMEntity { 35 var $log; 36 var $db; 37 38 // Stored vtiger_fields 39 var $module_id="emailid"; 40 // added to check email save from plugin or not 41 var $plugin_save = false; 42 43 var $rel_users_table = "vtiger_salesmanactivityrel"; 44 var $rel_contacts_table = "vtiger_cntactivityrel"; 45 var $rel_serel_table = "vtiger_seactivityrel"; 46 47 var $table_name = "activity"; 48 var $tab_name = Array('vtiger_crmentity','vtiger_activity','vtiger_seactivityrel','vtiger_cntactivityrel','vtiger_attachments'); 49 var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_activity'=>'activityid','vtiger_seactivityrel'=>'activityid','vtiger_cntactivityrel'=>'activityid','vtiger_attachments'=>'attachmentsid'); 50 51 // This is the list of vtiger_fields that are in the lists. 52 var $list_fields = Array( 53 'Subject'=>Array('activity'=>'subject'), 54 'Related to'=>Array('seactivityrel'=>'activityid'), 55 'Date Sent'=>Array('activity'=>'date_start'), 56 'Assigned To'=>Array('crmentity','smownerid') 57 ); 58 59 var $list_fields_name = Array( 60 'Subject'=>'subject', 61 'Related to'=>'activityid', 62 'Date Sent'=>'date_start', 63 'Assigned To'=>'assigned_user_id' 64 ); 65 66 var $list_link_field= 'subject'; 67 68 var $object_name = "Email"; 69 70 var $column_fields = Array(); 71 72 var $sortby_fields = Array('subject','date_start','smownerid'); 73 74 //Added these variables which are used as default order by and sortorder in ListView 75 var $default_order_by = 'date_start'; 76 var $default_sort_order = 'ASC'; 77 78 /** This function will set the columnfields for Email module 79 */ 80 81 function Email() { 82 $this->log = LoggerManager::getLogger('email'); 83 $this->log->debug("Entering Email() method ..."); 84 $this->log = LoggerManager::getLogger('email'); 85 $this->db = new PearDatabase(); 86 $this->column_fields = getColumnFields('Emails'); 87 $this->log->debug("Exiting Email method ..."); 88 } 89 90 var $new_schema = true; 91 92 /** Returns a list of the associated contacts 93 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. 94 * All Rights Reserved.. 95 * Contributor(s): ______________________________________.. 96 */ 97 function get_contacts($id) 98 { 99 global $log,$adb; 100 $log->debug("Entering get_contacts(".$id.") method ..."); 101 global $mod_strings; 102 global $app_strings; 103 104 $focus = new Contact(); 105 106 $button = ''; 107 $returnset = '&return_module=Emails&return_action=CallRelatedList&return_id='.$id; 108 109 $query = 'select vtiger_contactdetails.accountid, vtiger_contactdetails.contactid, vtiger_contactdetails.firstname,vtiger_contactdetails.lastname, vtiger_contactdetails.department, vtiger_contactdetails.title, vtiger_contactdetails.email, vtiger_contactdetails.phone, vtiger_contactdetails.emailoptout, vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime from vtiger_contactdetails inner join vtiger_cntactivityrel on vtiger_cntactivityrel.contactid=vtiger_contactdetails.contactid inner join vtiger_crmentity on vtiger_crmentity.crmid = 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 where vtiger_cntactivityrel.activityid='.$adb->quote($id).' and vtiger_crmentity.deleted=0'; 110 $log->info("Contact Related List for Email is Displayed"); 111 $log->debug("Exiting get_contacts method ..."); 112 return GetRelatedList('Emails','Contacts',$focus,$query,$button,$returnset); 113 } 114 115 /** Returns the column name that needs to be sorted 116 * Portions created by vtigerCRM are Copyright (C) vtigerCRM. 117 * All Rights Reserved.. 118 * Contributor(s): Mike Crowe 119 */ 120 121 function getSortOrder() 122 { 123 global $log; 124 $log->debug("Entering getSortOrder() method ..."); 125 if(isset($_REQUEST['sorder'])) 126 $sorder = $_REQUEST['sorder']; 127 else 128 $sorder = (($_SESSION['EMAILS_SORT_ORDER'] != '')?($_SESSION['EMAILS_SORT_ORDER']):($this->default_sort_order)); 129 130 $log->debug("Exiting getSortOrder method ..."); 131 return $sorder; 132 } 133 134 /** Returns the order in which the records need to be sorted 135 * Portions created by vtigerCRM are Copyright (C) vtigerCRM. 136 * All Rights Reserved.. 137 * Contributor(s): Mike Crowe 138 */ 139 140 function getOrderBy() 141 { 142 global $log; 143 $log->debug("Entering getOrderBy() method ..."); 144 if (isset($_REQUEST['order_by'])) 145 $order_by = $_REQUEST['order_by']; 146 else 147 $order_by = (($_SESSION['EMAILS_ORDER_BY'] != '')?($_SESSION['EMAILS_ORDER_BY']):($this->default_order_by)); 148 149 $log->debug("Exiting getOrderBy method ..."); 150 return $order_by; 151 } 152 // Mike Crowe Mod -------------------------------------------------------- 153 154 /** Returns a list of the associated vtiger_users 155 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. 156 * All Rights Reserved.. 157 * Contributor(s): ______________________________________.. 158 */ 159 function get_users($id) 160 { 161 global $log; 162 $log->debug("Entering get_users(".$id.") method ..."); 163 global $adb; 164 global $mod_strings; 165 global $app_strings; 166 167 $id = $_REQUEST['record']; 168 169 $query = 'SELECT vtiger_users.id, vtiger_users.first_name,vtiger_users.last_name, vtiger_users.user_name, vtiger_users.email1, vtiger_users.email2, vtiger_users.yahoo_id, vtiger_users.phone_home, vtiger_users.phone_work, vtiger_users.phone_mobile, vtiger_users.phone_other, vtiger_users.phone_fax from vtiger_users inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.smid=vtiger_users.id and vtiger_salesmanactivityrel.activityid='.$adb->quote($id); 170 $result=$adb->query($query); 171 172 $noofrows = $adb->num_rows($result); 173 $header [] = $app_strings['LBL_LIST_NAME']; 174 175 $header []= $app_strings['LBL_LIST_USER_NAME']; 176 177 $header []= $app_strings['LBL_EMAIL']; 178 179 $header []= $app_strings['LBL_PHONE']; 180 while($row = $adb->fetch_array($result)) 181 { 182 183 global $current_user; 184 185 $entries = Array(); 186 187 if(is_admin($current_user)) 188 { 189 $entries[] = $row['last_name'].' '.$row['first_name']; 190 } 191 else 192 { 193 $entries[] = $row['last_name'].' '.$row['first_name']; 194 } 195 196 $entries[] = $row['user_name']; 197 $entries[] = $row['email1']; 198 if($email == '') $email = $row['email2']; 199 if($email == '') $email = $row['yahoo_id']; 200 201 $entries[] = $row['phone_home']; 202 if($phone == '') $phone = $row['phone_work']; 203 if($phone == '') $phone = $row['phone_mobile']; 204 if($phone == '') $phone = $row['phone_other']; 205 if($phone == '') $phone = $row['phone_fax']; 206 207 //Adding Security Check for User 208 209 $entries_list[] = $entries; 210 } 211 212 if($entries_list != '') 213 $return_data = array("header"=>$header, "entries"=>$entries); 214 $log->debug("Exiting get_users method ..."); 215 return $return_data; 216 } 217 218 /** 219 * Returns a list of the associated vtiger_attachments and vtiger_notes of the Email 220 */ 221 function get_attachments($id) 222 { 223 global $log,$adb; 224 $log->debug("Entering get_attachments(".$id.") method ..."); 225 $query = "select vtiger_notes.title,'Notes ' ActivityType, vtiger_notes.filename, 226 vtiger_attachments.type FileType,crm2.modifiedtime lastmodified, 227 vtiger_seattachmentsrel.attachmentsid attachmentsid, vtiger_notes.notesid crmid, 228 crm2.createdtime, vtiger_notes.notecontent description, vtiger_users.user_name 229 from vtiger_notes 230 inner join vtiger_senotesrel on vtiger_senotesrel.notesid= vtiger_notes.notesid 231 inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_senotesrel.crmid 232 inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_notes.notesid and crm2.deleted=0 233 left join vtiger_seattachmentsrel on vtiger_seattachmentsrel.crmid =vtiger_notes.notesid 234 left join vtiger_attachments on vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid 235 inner join vtiger_users on crm2.smcreatorid= vtiger_users.id 236 where vtiger_crmentity.crmid=".$adb->quote($id); 237 $query .= ' union all '; 238 $query .= "select vtiger_attachments.description title ,'Attachments' ActivityType, 239 vtiger_attachments.name filename, vtiger_attachments.type FileType,crm2.modifiedtime lastmodified, 240 vtiger_attachments.attachmentsid attachmentsid,vtiger_seattachmentsrel.attachmentsid crmid, 241 crm2.createdtime, vtiger_attachments.description, vtiger_users.user_name 242 from vtiger_attachments 243 inner join vtiger_seattachmentsrel on vtiger_seattachmentsrel.attachmentsid= vtiger_attachments.attachmentsid 244 inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_seattachmentsrel.crmid 245 inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_attachments.attachmentsid 246 inner join vtiger_users on crm2.smcreatorid= vtiger_users.id 247 where vtiger_crmentity.crmid=".$adb->quote($id); 248 249 $log->info("Notes&Attachments Related List for Email is Displayed"); 250 $log->debug("Exiting get_attachments method ..."); 251 return getAttachmentsAndNotes('Emails',$query,$id); 252 } 253 254 /** 255 * Returns a list of the Emails to be exported 256 */ 257 function create_export_query(&$order_by, &$where) 258 { 259 global $log; 260 global $current_user; 261 $log->debug("Entering create_export_query(".$order_by.",".$where.") method ..."); 262 263 include ("include/utils/ExportUtils.php"); 264 265 //To get the Permitted fields query and the permitted fields list 266 $sql = getPermittedFieldsQuery("Emails", "detail_view"); 267 $fields_list = getFieldsListFromQuery($sql); 268 269 $query = "SELECT $fields_list FROM vtiger_activity 270 INNER JOIN vtiger_crmentity 271 ON vtiger_crmentity.crmid=vtiger_activity.activityid 272 LEFT JOIN vtiger_users 273 ON vtiger_users.id = vtiger_crmentity.smownerid 274 LEFT JOIN vtiger_seactivityrel 275 ON vtiger_seactivityrel.activityid = vtiger_activity.activityid 276 LEFT JOIN vtiger_contactdetails 277 ON vtiger_contactdetails.contactid = vtiger_seactivityrel.crmid 278 LEFT JOIN vtiger_cntactivityrel 279 ON vtiger_cntactivityrel.activityid = vtiger_activity.activityid 280 AND vtiger_cntactivityrel.contactid = vtiger_cntactivityrel.contactid 281 LEFT JOIN vtiger_activitygrouprelation 282 ON vtiger_activitygrouprelation.activityid = vtiger_crmentity.crmid 283 LEFT JOIN vtiger_groups 284 ON vtiger_groups.groupname = vtiger_activitygrouprelation.groupname 285 LEFT JOIN vtiger_salesmanactivityrel 286 ON vtiger_salesmanactivityrel.activityid = vtiger_activity.activityid 287 LEFT JOIN vtiger_emaildetails 288 ON vtiger_emaildetails.emailid = vtiger_activity.activityid 289 LEFT JOIN vtiger_seattachmentsrel 290 ON vtiger_activity.activityid=vtiger_seattachmentsrel.crmid 291 LEFT JOIN vtiger_attachments 292 ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid 293 WHERE vtiger_activity.activitytype='Emails' AND vtiger_crmentity.deleted=0 "; 294 295 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 296 require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); 297 //we should add security check when the user has Private Access 298 299 if($is_admin==false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1) 300 { 301 $sec_parameter=getListViewSecurityParameter("Emails"); 302 $query .= $sec_parameter; 303 } 304 305 $log->debug("Exiting create_export_query method ..."); 306 return $query; 307 } 308 309 /** 310 * Used to releate email and contacts -- Outlook Plugin 311 */ 312 function set_emails_contact_invitee_relationship($email_id, $contact_id) 313 { 314 global $log; 315 $log->debug("Entering set_emails_contact_invitee_relationship(".$email_id.",". $contact_id.") method ..."); 316 $query = "insert into $this->rel_contacts_table (contactid,activityid) values('$contact_id','$email_id')"; 317 $this->db->query($query,true,"Error setting email to contact relationship: "."<BR>$query"); 318 $log->debug("Exiting set_emails_contact_invitee_relationship method ..."); 319 } 320 321 /** 322 * Used to releate email and salesentity -- Outlook Plugin 323 */ 324 function set_emails_se_invitee_relationship($email_id, $contact_id) 325 { 326 global $log; 327 $log->debug("Entering set_emails_se_invitee_relationship(".$email_id.",". $contact_id.") method ..."); 328 $query = "insert into $this->rel_serel_table (crmid,activityid) values('$contact_id','$email_id')"; 329 $this->db->query($query,true,"Error setting email to contact relationship: "."<BR>$query"); 330 $log->debug("Exiting set_emails_se_invitee_relationship method ..."); 331 } 332 333 /** 334 * Used to releate email and Users -- Outlook Plugin 335 */ 336 function set_emails_user_invitee_relationship($email_id, $user_id) 337 { 338 global $log; 339 $log->debug("Entering set_emails_user_invitee_relationship(".$email_id.",". $user_id.") method ..."); 340 $query = "insert into $this->rel_users_table (smid,activityid) values ('$user_id', '$email_id')"; 341 $this->db->query($query,true,"Error setting email to user relationship: "."<BR>$query"); 342 $log->debug("Exiting set_emails_user_invitee_relationship method ..."); 343 } 344 345 346 } 347 /** Function to get the emailids for the given ids form the request parameters 348 * It returns an array which contains the mailids and the parentidlists 349 */ 350 351 function get_to_emailids($module) 352 { 353 global $adb; 354 $query = 'select columnname,fieldid from vtiger_field where fieldid in('.ereg_replace(':',',',$_REQUEST["field_lists"]).')'; 355 $result = $adb->query($query); 356 $columns = Array(); 357 $idlists = ''; 358 $mailids = ''; 359 while($row = $adb->fetch_array($result)) 360 { 361 $columns[]=$row['columnname']; 362 $fieldid[]=$row['fieldid']; 363 } 364 $columnlists = implode(',',$columns); 365 $crmids = ereg_replace(':',',',$_REQUEST["idlist"]); 366 switch($module) 367 { 368 case 'Leads': 369 $query = 'select crmid,concat(lastname," ",firstname) as entityname,'.$columnlists.' from vtiger_leaddetails inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_leaddetails.leadid left join vtiger_leadscf on vtiger_leadscf.leadid = vtiger_leaddetails.leadid where vtiger_crmentity.deleted=0 and vtiger_crmentity.crmid in ('.$crmids.')'; 370 break; 371 case 'Contacts': 372 $query = 'select crmid,concat(lastname," ",firstname) as entityname,'.$columnlists.' from vtiger_contactdetails inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid left join vtiger_contactscf on vtiger_contactscf.contactid = vtiger_contactdetails.contactid where vtiger_crmentity.deleted=0 and vtiger_crmentity.crmid in ('.$crmids.')'; 373 break; 374 case 'Accounts': 375 $query = 'select crmid,accountname as entityname,'.$columnlists.' from vtiger_account inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_account.accountid left join vtiger_accountscf on vtiger_accountscf.accountid = vtiger_account.accountid where vtiger_crmentity.deleted=0 and vtiger_crmentity.crmid in ('.$crmids.')'; 376 break; 377 } 378 $result = $adb->query($query); 379 while($row = $adb->fetch_array($result)) 380 { 381 $name = $row['entityname']; 382 for($i=0;$i<count($columns);$i++) 383 { 384 if($row[$columns[$i]] != NULL && $row[$columns[$i]] !='') 385 { 386 $idlists .= $row['crmid'].'@'.$fieldid[$i].'|'; 387 $mailids .= $name.'<'.$row[$columns[$i]].'>,'; 388 } 389 } 390 } 391 392 $return_data = Array('idlists'=>$idlists,'mailds'=>$mailids); 393 return $return_data; 394 395 } 396 ?>
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 |