Acknowledgements page update
[openemr.git] / modules / sms_email_reminder / cron_sms_notification.php
blob1594f65d7d0713d2dad861021edacc9506c33b5e
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' ) $bTestRun = 1;
26 $TYPE = "SMS";
27 $CRON_TIME = 5;
29 $curr_date = date("Y-m-d");
30 $curr_time = time();
31 $check_date = date("Y-m-d", mktime(date("h")+$SMS_NOTIFICATION_HOUR, 0, 0, date("m"), date("d"), date("Y")));
33 // larry :: move this in the loop to keep it fresh - perhaps try to use it without change
34 // it's content - to do latter
35 $db_email_msg = cron_getNotificationData($TYPE);
37 // object for sms
38 global $mysms;
39 if( $db_email_msg['sms_gateway_type']=='CLICKATELL' )
41 include_once("sms_clickatell.php");
43 }else if($db_email_msg['sms_gateway_type']=='TMB4')
45 include_once("sms_tmb4.php");
48 // get notification settings
49 $vectNotificationSettings = cron_GetNotificationSettings( );
50 $SMS_GATEWAY_USENAME = $vectNotificationSettings['SMS_gateway_username'];
51 $SMS_GATEWAY_PASSWORD = $vectNotificationSettings['SMS_gateway_password'];
52 $SMS_GATEWAY_APIKEY = $vectNotificationSettings['SMS_gateway_apikey'];
53 // set cron time (time to event ?) - todo extra tests
54 $CRON_TIME = $vectNotificationSettings['Send_SMS_Before_Hours'];
56 //echo "\nDEBUG :: user=".$vectNotificationSettings['SMS_gateway_username']."\n";
58 // create sms object
59 $mysms = new sms( $SMS_GATEWAY_USENAME, $SMS_GATEWAY_PASSWORD, $SMS_GATEWAY_APIKEY );
61 $db_patient = cron_getAlertpatientData($TYPE);
62 echo "\n<br>Total ".count($db_patient)." Records Found";
64 // for every event found
65 for( $p=0; $p<count($db_patient); $p++ )
67 $prow =$db_patient[$p];
69 //echo "\n-----\nDEBUG :cron_sms: found patient = ".$prow['fname']." ".$prow['lname']."\n";
71 // my_print_r($prow);
73 if($prow['pc_eventDate'] < $check_date)
75 $app_date = date("Y-m-d")." ".$prow['pc_startTime'];
76 }else{
77 $app_date = $prow['pc_eventDate']." ".$prow['pc_startTime'];
80 $app_date = $prow['pc_eventDate']." ".$prow['pc_startTime'];
81 $app_time = strtotime($app_date);
83 $app_time_hour = round($app_time/3600);
84 $curr_total_hour = round(time()/3600);
86 $remaining_app_hour = round($app_time_hour - $curr_total_hour);
87 $remain_hour = round($remaining_app_hour - $SMS_NOTIFICATION_HOUR);
89 // larry :: debug
90 //echo "\nDEBUG :: checkdate=$check_date, app_date=$app_date, apptime=$app_time remain_hour=$remain_hour -- CRON_TIME=$CRON_TIME\n";
92 // build log message
93 $strMsg = "\n========================".$TYPE." || ".date("Y-m-d H:i:s")."=========================";
94 $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);
96 // check in the interval
97 if( $remain_hour >= -($CRON_TIME) && $remain_hour <= $CRON_TIME )
99 // insert entry in notification_log table
100 cron_InsertNotificationLogEntry($TYPE,$prow,$db_email_msg);
102 //set message
103 $db_email_msg['message'] = cron_setmessage($prow,$db_email_msg);
105 // send sms to patinet - if not in test mode
106 if( $bTestRun == 0 )
108 cron_SendSMS( $prow['phone_cell'], $db_email_msg['email_subject'],
109 $db_email_msg['message'], $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'];
124 // write logs for every reminder sent
125 WriteLog($strMsg);
127 // larry :: update notification data again - todo :: fix change in cron_updateentry
128 $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>