Bug fix to show correct name of encounter author on custom report.
[openemr.git] / modules / sms_email_reminder / cron_email_notification.php
blobad793921fd8fe26b9c7fd1af10e0901fc2a995b5
1 <?php
3 ////////////////////////////////////////////////////////////////////
4 // Package: cron_email_notification
5 // Purpose: to be run by cron every hour, look for appointments
6 // in the pre-notification period and send an email reminder
7 //
8 // Created by:
9 // Updated by: Larry Lart on 10/03/2008
10 ////////////////////////////////////////////////////////////////////
12 // larry :: hack add for command line version
13 $_SERVER['REQUEST_URI']=$_SERVER['PHP_SELF'];
14 $_SERVER['SERVER_NAME']='localhost';
15 $backpic = "";
17 // email notification
18 $ignoreAuth=1;
19 include_once("../../interface/globals.php");
20 include_once("cron_functions.php");
22 $TYPE = "Email";
23 $CRON_TIME = 5;
25 // set cron time (time to event ?) - todo extra tests
26 $vectNotificationSettings = cron_GetNotificationSettings( );
27 $CRON_TIME = $vectNotificationSettings['Send_Email_Before_Hours'];
29 $check_date = date("Y-m-d", mktime(date("h")+$EMAIL_NOTIFICATION_HOUR, 0, 0, date("m"), date("d"), date("Y")));
32 // get data from automatic_notification table
33 $db_email_msg = cron_getNotificationData($TYPE);
34 //my_print_r($db_email_msg);
36 // get patient data for send alert
37 $db_patient = cron_getAlertpatientData($TYPE);
38 echo "<br>Total ".count($db_patient)." Records Found\n";
39 for($p=0;$p<count($db_patient);$p++)
41 $prow =$db_patient[$p];
42 //my_print_r($prow);
44 if($prow['pc_eventDate'] < $check_date)
46 $app_date = date("Y-m-d")." ".$prow['pc_startTime'];
47 }else{
48 $app_date = $prow['pc_eventDate']." ".$prow['pc_startTime'];
51 $app_date = $prow['pc_eventDate']." ".$prow['pc_startTime'];
52 $app_time = strtotime($app_date);
54 $app_time_hour = round($app_time/3600);
55 $curr_total_hour = round(time()/3600);
57 $remaining_app_hour = round($app_time_hour - $curr_total_hour);
58 $remain_hour = round($remaining_app_hour - $EMAIL_NOTIFICATION_HOUR);
60 $strMsg = "\n========================".$TYPE." || ".date("Y-m-d H:i:s")."=========================";
61 $strMsg .= "\nSEND NOTIFICATION BEFORE:".$EMAIL_NOTIFICATION_HOUR." || CRONJOB RUN EVERY:".$CRON_TIME." || APPDATETIME:".$app_date." || REMAINING APP HOUR:".($remaining_app_hour)." || SEND ALERT AFTER:".($remain_hour);
63 if($remain_hour >= -($CRON_TIME) && $remain_hour <= $CRON_TIME)
65 // insert entry in notification_log table
66 cron_InsertNotificationLogEntry($TYPE,$prow,$db_email_msg);
68 //set message
69 $db_email_msg['message'] = cron_setmessage( $prow, $db_email_msg );
71 // send mail to patinet
72 cron_SendMail( $prow['email'], $db_email_msg['email_subject'],
73 $db_email_msg['message'], $db_email_msg['email_sender'] );
75 //update entry >> pc_sendalertemail='Yes'
76 cron_updateentry($TYPE,$prow['pid'],$prow['pc_eid']);
78 $strMsg .= " || ALERT SENT SUCCESSFULLY TO ".$prow['email'];
79 $strMsg .= "\n".$patient_info."\n".$smsgateway_info."\n".$data_info."\n".$db_email_msg['message'];
82 WriteLog( $strMsg );
84 // larry :: get notification data again - since was updated by cron_updateentry
85 // todo :: instead fix not to modify the template aka $db_email_msg
86 $db_email_msg = cron_getNotificationData($TYPE);
89 sqlClose();
92 <html>
93 <head>
94 <title>Conrjob - Email Notification</title>
95 </head>
96 <body>
97 <center>
98 </center>
99 </body>
100 </html>