Updated translations (#1517)
[openemr.git] / modules / sms_email_reminder / cron_sms_notification.php
blob70def0434dbce69e679f1dd1f62761c2df0c7b5a
1 <?php
3 ////////////////////////////////////////////////////////////////////
4 // Package: sms_cron_notification
5 // Purpose: to be run by cron every hour, look for appointments
6 // in the pre-notification period and send an sms reminder
7 //
8 // Created by:
9 // Updated by: Larry Lart on 11/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 // check command line for quite option
23 $bTestRun = 0;
24 if ($argc > 1 && $argv[1] == 'test') {
25 $bTestRun = 1;
28 $TYPE = "SMS";
29 $CRON_TIME = 5;
31 $curr_date = date("Y-m-d");
32 $curr_time = time();
33 $check_date = date("Y-m-d", mktime(date("h")+$SMS_NOTIFICATION_HOUR, 0, 0, date("m"), date("d"), date("Y")));
35 // larry :: move this in the loop to keep it fresh - perhaps try to use it without change
36 // it's content - to do latter
37 $db_email_msg = cron_getNotificationData($TYPE);
39 // object for sms
40 global $mysms;
41 if ($db_email_msg['sms_gateway_type']=='CLICKATELL') {
42 include_once("sms_clickatell.php");
43 } else if ($db_email_msg['sms_gateway_type']=='TMB4') {
44 include_once("sms_tmb4.php");
47 // get notification settings
48 $vectNotificationSettings = cron_GetNotificationSettings();
49 $SMS_GATEWAY_USENAME = $vectNotificationSettings['SMS_gateway_username'];
50 $SMS_GATEWAY_PASSWORD = $vectNotificationSettings['SMS_gateway_password'];
51 $SMS_GATEWAY_APIKEY = $vectNotificationSettings['SMS_gateway_apikey'];
52 // set cron time (time to event ?) - todo extra tests
53 $CRON_TIME = $vectNotificationSettings['Send_SMS_Before_Hours'];
55 //echo "\nDEBUG :: user=".$vectNotificationSettings['SMS_gateway_username']."\n";
57 // create sms object
58 $mysms = new sms($SMS_GATEWAY_USENAME, $SMS_GATEWAY_PASSWORD, $SMS_GATEWAY_APIKEY);
60 $db_patient = cron_getAlertpatientData($TYPE);
61 echo "\n<br>Total ".count($db_patient)." Records Found";
63 // for every event found
64 for ($p=0; $p<count($db_patient); $p++) {
65 $prow =$db_patient[$p];
67 //echo "\n-----\nDEBUG :cron_sms: found patient = ".$prow['fname']." ".$prow['lname']."\n";
69 // my_print_r($prow);
71 if($prow['pc_eventDate'] < $check_date)
73 $app_date = date("Y-m-d")." ".$prow['pc_startTime'];
74 }else{
75 $app_date = $prow['pc_eventDate']." ".$prow['pc_startTime'];
78 $app_date = $prow['pc_eventDate']." ".$prow['pc_startTime'];
79 $app_time = strtotime($app_date);
81 $app_time_hour = round($app_time/3600);
82 $curr_total_hour = round(time()/3600);
84 $remaining_app_hour = round($app_time_hour - $curr_total_hour);
85 $remain_hour = round($remaining_app_hour - $SMS_NOTIFICATION_HOUR);
87 // larry :: debug
88 //echo "\nDEBUG :: checkdate=$check_date, app_date=$app_date, apptime=$app_time remain_hour=$remain_hour -- CRON_TIME=$CRON_TIME\n";
90 // build log message
91 $strMsg = "\n========================".$TYPE." || ".date("Y-m-d H:i:s")."=========================";
92 $strMsg .= "\nSEND NOTIFICATION BEFORE:".$SMS_NOTIFICATION_HOUR." || CRONJOB RUN EVERY:".$CRON_TIME." || APPDATETIME:".$app_date." || REMAINING APP HOUR:".($remaining_app_hour)." || SEND ALERT AFTER:".($remain_hour);
94 // check in the interval
95 if ($remain_hour >= -($CRON_TIME) && $remain_hour <= $CRON_TIME) {
96 // insert entry in notification_log table
97 cron_InsertNotificationLogEntry($TYPE, $prow, $db_email_msg);
99 //set message
100 $db_email_msg['message'] = cron_setmessage($prow, $db_email_msg);
102 // send sms to patinet - if not in test mode
103 if ($bTestRun == 0) {
104 cron_SendSMS(
105 $prow['phone_cell'],
106 $db_email_msg['email_subject'],
107 $db_email_msg['message'],
108 $db_email_msg['email_sender']
112 // larry :: debug
113 echo "\nDEBUG :: sms was sent to= ".$prow['phone_cell'].
114 " \nsender= ".$db_email_msg['email_sender'].
115 " \nsbj= ". $db_email_msg['email_subject'].
116 " \nmsg= ".$db_email_msg['message']."\n";
118 //update entry >> pc_sendalertsms='Yes'
119 cron_updateentry($TYPE, $prow['pid'], $prow['pc_eid']);
121 $strMsg .= " || ALERT SENT SUCCESSFULLY TO ".$prow['phone_cell'];
122 $strMsg .= "\n".$patient_info."\n".$smsgateway_info."\n".$data_info."\n".$db_email_msg['message'];
125 // write logs for every reminder sent
126 WriteLog($strMsg);
128 // larry :: update notification data again - todo :: fix change in cron_updateentry
129 $db_email_msg = cron_getNotificationData($TYPE);
132 unset($mysms);
133 sqlClose();
137 <html>
138 <head>
139 <title>Conrjob - SMS Notification</title>
140 </head>
141 <body>
142 <center>
143 </center>
144 </body>
145 </html>