[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 //////////////////////////////////////////////////// 3 // PHPMailer - PHP email class 4 // 5 // Class for sending email using either 6 // sendmail, PHP mail(), or SMTP. Methods are 7 // based upon the standard AspEmail(tm) classes. 8 // 9 // Copyright (C) 2001 - 2003 Brent R. Matzelle 10 // 11 // License: LGPL, see LICENSE 12 //////////////////////////////////////////////////// 13 14 /** 15 * PHPMailer - PHP email transport class 16 * @package PHPMailer 17 * @author Brent R. Matzelle 18 * @copyright 2001 - 2003 Brent R. Matzelle 19 */ 20 21 22 //file modified by richie 23 24 require_once ('include/utils/utils.php'); 25 require_once ("modules/Emails/class.phpmailer.php"); 26 require_once ("modules/Emails/mail.php"); 27 require_once ('include/logging.php'); 28 require_once ("config.php"); 29 30 $current_user = Users::getActiveAdminUser(); 31 // Set the default sender email id 32 global $HELPDESK_SUPPORT_EMAIL_ID; 33 $from = $HELPDESK_SUPPORT_EMAIL_ID; 34 if(empty($from)) { 35 // default configuration is empty? 36 $from = "[email protected]"; 37 } 38 39 // Get the list of activity for which reminder needs to be sent 40 41 global $adb; 42 global $log; 43 $log =& LoggerManager::getLogger('SendReminder'); 44 $log->debug(" invoked SendReminder "); 45 46 // retrieve the translated strings. 47 if(empty($current_language)) 48 $current_language = 'en_us'; 49 $app_strings = return_application_language($current_language); 50 51 //modified query for recurring events -Jag 52 $query="select vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_seactivityrel.crmid as setype,vtiger_activity.*,vtiger_activity_reminder.reminder_time,vtiger_activity_reminder.reminder_sent,vtiger_activity_reminder.recurringid,vtiger_recurringevents.recurringdate from vtiger_activity inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid inner join vtiger_activity_reminder on vtiger_activity.activityid=vtiger_activity_reminder.activity_id left outer join vtiger_recurringevents on vtiger_activity.activityid=vtiger_recurringevents.activityid left outer join vtiger_seactivityrel on vtiger_seactivityrel.activityid = vtiger_activity.activityid where DATE_FORMAT(vtiger_activity.date_start,'%Y-%m-%d, %H:%i:%s') >= '".date('Y-m-d')."' and vtiger_crmentity.crmid != 0 and vtiger_activity.eventstatus = 'Planned' and vtiger_activity_reminder.reminder_sent = 0 group by vtiger_activity.activityid,vtiger_recurringevents.recurringid"; 53 $result = $adb->pquery($query, array()); 54 55 if($adb->num_rows($result) >= 1) 56 { 57 //To fetch reminder frequency from cron tasks 58 $reminderFrequencyQuery = 'SELECT frequency FROM vtiger_cron_task WHERE name = "SendReminder" AND handler_file = "cron/SendReminder.service"'; 59 $reminderResult = $adb->pquery($reminderFrequencyQuery, array()); 60 $reminderFrequency = $adb->query_result($reminderResult,0,'frequency'); 61 62 while($result_set = $adb->fetch_array($result)) 63 { 64 $date_start = $result_set['date_start']; 65 $time_start = $result_set['time_start']; 66 $reminder_time = $result_set['reminder_time']*60; 67 $date = new DateTimeField( null ); 68 $userFormatedString = $date->getDisplayDate(); 69 $timeFormatedString = $date->getDisplayTime(); 70 $dBFomatedDate = DateTimeField::convertToDBFormat($userFormatedString); 71 $curr_time = strtotime($dBFomatedDate." ". $timeFormatedString); 72 $activity_id = $result_set['activityid']; 73 $activitymode = ($result_set['activitytype'] == "Task")?"Task":"Events"; 74 $parent_type = $result_set['setype']; 75 $activity_sub = $result_set['subject']; 76 $to_addr=''; 77 78 if($parent_type!='') 79 $parent_content = getParentInfo($parent_type)."\n"; 80 else 81 $parent_content = ""; 82 //code included for recurring events by jaguar starts 83 $recur_id = $result_set['recurringid']; 84 $current_date=date('Y-m-d'); 85 if($recur_id == 0) 86 { 87 $date_start = $result_set['date_start']; 88 } 89 else 90 { 91 $date_start = $result_set['recurringdate']; 92 } 93 //code included for recurring events by jaguar ends 94 $date = new DateTimeField("$date_start $time_start"); 95 $userFormatedString = $date->getDisplayDate(); 96 $timeFormatedString = $date->getDisplayTime(); 97 $dBFomatedDate = DateTimeField::convertToDBFormat($userFormatedString); 98 $activity_time = strtotime($dBFomatedDate.' '.$timeFormatedString); 99 $differenceOfActivityTimeAndCurrentTime = ($activity_time - $curr_time); 100 if (($differenceOfActivityTimeAndCurrentTime > 0) && (($differenceOfActivityTimeAndCurrentTime <= $reminder_time) || ($differenceOfActivityTimeAndCurrentTime <= $reminderFrequency))) 101 { 102 $log->debug(" InSide REMINDER"); 103 $query_user="SELECT vtiger_users.email1,vtiger_salesmanactivityrel.smid FROM vtiger_salesmanactivityrel inner join vtiger_users on vtiger_users.id=vtiger_salesmanactivityrel.smid where vtiger_salesmanactivityrel.activityid =? and vtiger_users.deleted=0"; 104 $user_result = $adb->pquery($query_user, array($activity_id)); 105 $invitedUsersList = array(); 106 if($adb->num_rows($user_result)>=1) 107 { 108 while($user_result_row = $adb->fetch_array($user_result)) 109 { 110 if($user_result_row['email1']!='' || $user_result_row['email1'] !=NULL) 111 { 112 $to_addr[] = $user_result_row['email1']; 113 } 114 $invitedUsersList[] = $user_result_row['smid']; 115 } 116 } 117 118 $ownerId = $result_set['smownerid']; 119 if (!in_array($ownerId, $invitedUsersList)) { 120 $ownerId = $invitedUsersList[0]; 121 } 122 $ownerFocus = CRMEntity::getInstance('Users'); 123 $ownerFocus->retrieve_entity_info($ownerId, 'Users'); 124 $ownerTimeZone = getTranslatedString($ownerFocus->column_fields['time_zone'], 'Users'); 125 126 $dateTime = new DateTimeField($result_set['date_start'] .' '. $result_set['time_start']); 127 $dateTimeInOwnerFormat = $dateTime->getDisplayDateTimeValue($ownerFocus); 128 129 // Retriving the Subject and message from reminder table 130 $sql = "select active,notificationsubject,notificationbody from vtiger_notificationscheduler where schedulednotificationid=8"; 131 $result_main = $adb->pquery($sql, array()); 132 133 $subject = $app_strings['Reminder']. $result_set['activitytype'] . " @ $dateTimeInOwnerFormat ] ($ownerTimeZone)". 134 $adb->query_result($result_main,0,'notificationsubject'); 135 136 //Set the mail body/contents here 137 $contents = nl2br($adb->query_result($result_main,0,'notificationbody')) ."\n\n ". 138 $app_strings['Subject']." : ".$activity_sub."\n ". $parent_content ." ". 139 $app_strings['Date & Time']." : $dateTimeInOwnerFormat ($ownerTimeZone)\n\n ". 140 $app_strings['Visit_Link']." <a href='".$site_URL."/index.php?view=Detail&module=Calendar&record=".$activity_id."'>".$app_strings['Click here']."</a>"; 141 if(count($to_addr) >=1) 142 { 143 send_email($to_addr,$from,$subject,$contents,$mail_server,$mail_server_username,$mail_server_password); 144 $upd_query = "UPDATE vtiger_activity_reminder SET reminder_sent=1 where activity_id=?"; 145 $upd_params = array($activity_id); 146 147 if($recur_id!=0) 148 { 149 $upd_query.=" and recurringid =?"; 150 array_push($upd_params, $recur_id); 151 } 152 153 $adb->pquery($upd_query, $upd_params); 154 155 } 156 } 157 } 158 } 159 160 /** 161 This function is used to assign parameters to the mail object and send it. 162 It takes the following as parameters. 163 $to as string - to address 164 $from as string - from address 165 $subject as string - subject if the mail 166 $contents as text - content of the mail 167 $mail_server as string - sendmail server name 168 $mail_server_username as string - sendmail server username 169 $mail_server_password as string - sendmail server password 170 171 */ 172 function send_email($to,$from,$subject,$contents,$mail_server,$mail_server_username,$mail_server_password) 173 { 174 global $adb; 175 global $log; 176 $log->info("This is send_mail function in SendReminder.php(vtiger home)."); 177 global $root_directory; 178 179 $mail = new PHPMailer(); 180 181 182 $mail->Subject = $subject; 183 $mail->Body = nl2br($contents);//"This is the HTML message body <b>in bold!</b>"; 184 185 186 $mail->IsSMTP(); // set mailer to use SMTP 187 188 $mailserverresult=$adb->pquery("select * from vtiger_systems where server_type='email'", array()); 189 $mail_server = $adb->query_result($mailserverresult,0,'server'); 190 $mail_server_username = $adb->query_result($mailserverresult,0,'server_username'); 191 $mail_server_password = $adb->query_result($mailserverresult,0,'server_password'); 192 $smtp_auth = $adb->query_result($mailserverresult,0,'smtp_auth'); 193 194 $_REQUEST['server']=$mail_server; 195 $log->info("Mail Server Details => '".$mail_server."','".$mail_server_username."','".$mail_server_password."'"); 196 197 198 $mail->Host = $mail_server; // specify main and backup server 199 if($smtp_auth == 'true' || $smtp_auth == '1') 200 $mail->SMTPAuth = true; 201 else 202 $mail->SMTPAuth = false; 203 $mail->Username = $mail_server_username ; // SMTP username 204 $mail->Password = $mail_server_password ; // SMTP password 205 $mail->From = $from; 206 $mail->FromName = $initialfrom; 207 $log->info("Mail sending process : From Name & email id => '".$initialfrom."','".$from."'"); 208 foreach($to as $pos=>$addr) 209 { 210 $mail->AddAddress($addr); // name is optional 211 $log->info("Mail sending process : To Email id = '".$addr."' (set in the mail object)"); 212 213 } 214 $mail->WordWrap = 50; // set word wrap to 50 characters 215 216 $mail->IsHTML(true); // set email format to HTML 217 218 $mail->AltBody = "This is the body in plain text for non-HTML mail clients"; 219 220 $flag = MailSend($mail); 221 $log->info("After executing the mail->Send() function."); 222 } 223 224 /** 225 This function is used to get the Parent type and its Name 226 It takes the input integer - crmid and returns the parent type and its name as string. 227 */ 228 function getParentInfo($value) 229 { 230 global $adb; 231 $parent_module = getSalesEntityType($value); 232 if($parent_module == "Leads") 233 { 234 $sql = "select * from vtiger_leaddetails where leadid=?"; 235 $result = $adb->pquery($sql, array($value)); 236 $first_name = $adb->query_result($result,0,"firstname"); 237 $last_name = $adb->query_result($result,0,"lastname"); 238 239 $parent_name = $last_name.' '.$first_name; 240 } 241 elseif($parent_module == "Accounts") 242 { 243 $sql = "select * from vtiger_account where accountid=?"; 244 $result = $adb->pquery($sql, array($value)); 245 $account_name = $adb->query_result($result,0,"accountname"); 246 247 $parent_name =$account_name; 248 } 249 elseif($parent_module == "Potentials") 250 { 251 $sql = "select * from vtiger_potential where potentialid=?"; 252 $result = $adb->pquery($sql, array($value)); 253 $potentialname = $adb->query_result($result,0,"potentialname"); 254 255 $parent_name =$potentialname; 256 } 257 return $parent_module ." : ".$parent_name; 258 } 259 ?>
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 |