Fix the dated reminders script headers.
[openemr.git] / interface / main / dated_reminders / dated_reminders_add.php
blob6f7515d3a8e1843ce1260a5edfb8378bf327ae3a
1 <?php
2 /**
3 * Used for adding dated reminders.
5 * Copyright (C) 2012 tajemo.co.za <http://www.tajemo.co.za/>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author Craig Bezuidenhout <http://www.tajemo.co.za/>
20 * @link http://www.open-emr.org
23 $fake_register_globals=false;
24 $sanitize_all_escapes=true;
26 require_once("../../globals.php");
27 require_once("$srcdir/htmlspecialchars.inc.php");
28 require_once("$srcdir/dated_reminder_functions.php");
30 $dateRanges = array();
31 // $dateranges = array ( number_period => text to display ) == period is always in the singular
32 // eg. $dateRanges['4_week'] = '4 Weeks From Now';
33 $dateRanges['1_day'] = xl('1 Day From Now');
34 $dateRanges['2_day'] = xl('2 Days From Now');
35 $dateRanges['3_day'] = xl('3 Days From Now');
36 $dateRanges['4_day'] = xl('4 Days From Now');
37 $dateRanges['5_day'] = xl('5 Days From Now');
38 $dateRanges['6_day'] = xl('6 Days From Now');
39 $dateRanges['1_week'] = xl('1 Week From Now');
40 $dateRanges['2_week'] = xl('2 Weeks From Now');
41 $dateRanges['3_week'] = xl('3 Weeks From Now');
42 $dateRanges['4_week'] = xl('4 Weeks From Now');
43 $dateRanges['5_week'] = xl('5 Weeks From Now');
44 $dateRanges['6_week'] = xl('6 Weeks From Now');
45 $dateRanges['1_month'] = xl('1 Month From Now');
46 $dateRanges['2_month'] = xl('2 Months From Now');
47 $dateRanges['3_month'] = xl('3 Months From Now');
48 $dateRanges['4_month'] = xl('4 Months From Now');
49 $dateRanges['5_month'] = xl('5 Months From Now');
50 $dateRanges['6_month'] = xl('6 Months From Now');
51 $dateRanges['7_month'] = xl('7 Months From Now');
52 $dateRanges['8_month'] = xl('8 Months From Now');
53 $dateRanges['9_month'] = xl('9 Months From Now');
54 $dateRanges['1_year'] = xl('1 Year From Now');
55 $dateRanges['2_year'] = xl('2 Years From Now');
57 // --- need to add a check to ensure the post is being sent from the correct location ???
59 // default values for $this_message
60 $this_message = array('message'=>'','message_priority'=>3,'dueDate'=>'');
61 $forwarding = false;
63 // ---------------- FOR FORWARDING MESSAGES ------------->
64 if(isset($_GET['mID']) and is_numeric($_GET['mID'])){
65 $forwarding = true;
66 $this_message = getReminderById($_GET['mID']);
69 // ---------------END FORWARDING MESSAGES ----------------
73 // --- add reminders
74 if($_POST){
75 // --- initialize $output as blank
76 $output = '';
77 // ------ fills an array with all recipients
78 $sendTo = $_POST['sendTo'];
80 // for incase of data error, this allows the previously entered data to re-populate the boxes
81 $this_message['message'] = (isset($_POST['message']) ? $_POST['message'] : '');
82 $this_message['priority'] = (isset($_POST['priority']) ? $_POST['priority'] : '');
83 $this_message['dueDate'] = (isset($_POST['dueDate']) ? $_POST['dueDate'] : '');
86 // --------------------------------------------------------------------------------------------------------------------------
87 // --- check for the post, if it is valid, commit to the database, close this window and run opener.Handeler
88 if(
89 // ------- check sendTo is not empty
90 !empty($sendTo) and
91 // ------- check dueDate, only allow valid dates, todo -> enhance date checker
92 isset($_POST['dueDate']) and preg_match('/\d{4}[-]\d{2}[-]\d{2}/',$_POST['dueDate']) and
93 // ------- check priority, only allow 1-3
94 isset($_POST['priority']) and intval($_POST['priority']) <= 3 and
95 // ------- check message, only up to 255 characters
96 isset($_POST['message']) and strlen($_POST['message']) <= 255 and strlen($_POST['message']) > 0 and
97 // ------- check if PatientID is set and in numeric
98 isset($_POST['PatientID']) and is_numeric($_POST['PatientID'])
99 ){
100 $dueDate = $_POST['dueDate'];
101 $priority = intval($_POST['priority']);
102 $message = $_POST['message'];
103 $fromID = $_SESSION['authId'];
104 $patID = $_POST['PatientID'];
105 if(isset($_POST['sendSeperately']) and $_POST['sendSeperately']){
106 foreach($sendTo as $st){
107 $ReminderSent = sendReminder(array($st),$fromID,$message,$dueDate,$patID,$priority);
110 else{
111 // -------- Send the reminder
112 $ReminderSent = sendReminder($sendTo,$fromID,$message,$dueDate,$patID,$priority);
114 // --------------------------------------------------------------------------------------------------------------------------
115 if(!$ReminderSent){
116 $output .= '<div style="text-size:2em; text-align:center; color:red">* '.xlt('Please select a valid recipient').'</div> ';
117 }else{
118 // --------- echo javascript
119 echo '<html><body><script language="JavaScript">';
120 // ------------ 1) refresh parent window this updates if sent to self
121 echo ' if (opener && !opener.closed && opener.updateme) opener.updateme("new");';
122 // ------------ 2) communicate with user
123 echo ' alert("'.addslashes(xl('Message Sent')).'");';
124 // ------------ 3) close this window
125 echo ' window.close();';
126 echo '</script></body></html>';
127 // --------- stop script from executing further
128 exit;
130 // --------------------------------------------------------------------------------------------------------------------------
132 // --------------------------------------------------------------------------------------------------------------------------
134 else{
135 // ------- if POST error
136 $output .= '<div style="text-size:2em; text-align:center; color:red">* '.xlt('Data Error').'</div> ';
138 // ------- if any errors, communicate with the user
139 echo $output;
141 // end add reminders
143 // get current patient, first check if this is a forwarded message, if it is use the original pid
144 if(isset($this_message['pid'])) $patientID = (isset($this_message['pid']) ? $this_message['pid'] : 0);
145 else $patientID = (isset($pid) ? $pid : 0);
147 <html>
148 <head>
149 <title><?php echo xlt('Send a Reminder') ?></title>
150 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
151 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/topdialog.js"></script>
152 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
153 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
154 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-1.4.3.min.js"></script>
155 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-calendar.js"></script>
156 <script language="JavaScript">
157 $(document).ready(function (){
159 $('#timeSpan').change(function(){
160 var value = $(this).val();
161 var arr = value.split('_');
162 var span = arr[1];
163 var period = parseInt(arr[0]);
164 var d=new Date();
165 if(span == 'day'){
166 d.setDate(d.getDate()+period);
168 else if(span == 'week'){
169 var weekInDays = period * 7;
170 d.setDate(d.getDate()+weekInDays);
172 else if(span == 'month'){
173 d.setMonth(d.getMonth()+period);
175 else if(span == 'year'){
176 var yearsInMonths = period * 12;
177 d.setMonth(d.getMonth()+yearsInMonths);
179 var curr_date = d.getDate().toString();
180 if(curr_date.length == 1){
181 curr_date = '0'+curr_date;
183 var curr_month = d.getMonth() + 1; //months are zero based
184 curr_month = curr_month.toString();
185 if(curr_month.length == 1){
186 curr_month = '0'+curr_month;
188 var curr_year = d.getFullYear();
189 $('#dueDate').val(curr_year + "-" + curr_month + "-" + curr_date);
193 $("#sendButton").click(function(){
194 $('#errorMessage').html('');
195 errorMessage = '';
196 var PatientID = $('#PatientID').val();
197 var dueDate = $('#dueDate').val();
198 var priority = $('#priority:checked').val();
199 var message = $("#message").val();
200 // todo : check if PatientID is numeric , no rush as this is checked in the php after the post
202 // check to see if a recipient has been set
203 // todo : check if they are all numeric , no rush as this is checked in the php after the post
205 if (!$("#sendTo option:selected").length){
206 errorMessage = errorMessage + '* <?php echo xla('Please Select A Recipient') ?><br />';
210 // Check if Date is set
211 // todo : add check to see if dueDate is a valid date , no rush as this is checked in the php after the post
212 if(dueDate == ''){
213 errorMessage = errorMessage + '* <?php echo xla('Please enter a due date') ?><br />';
216 // check if message is set
217 if(message == ''){
218 errorMessage = errorMessage + '* <?php echo xla('Please enter a message') ?><br />';
221 if(errorMessage != ''){
222 // handle invalid queries
223 $('#errorMessage').html(errorMessage);
225 else{
226 // handle valid queries
227 // post the form to self
228 top.restoreSession();
229 $("#addDR").submit();
231 return false;
234 $("#removePatient").click(function(){
235 $("#PatientID").val("0");
236 $("#patientName").val("<?php echo xla('Click to select patient'); ?>");
237 $(this).hide();
238 return false;
242 function sel_patient(){
243 window.open('../../main/calendar/find_patient_popup.php', '_newDRPat', '' + ",width=" + 500 + ",height=" + 400 + ",left=" + 25 + ",top=" + 25 + ",screenX=" + 25 + ",screenY=" + 25);
246 function setpatient(pid, lname, fname, dob){
247 $("#patientName").val(fname +' '+ lname)
248 $("#PatientID").val(pid);
249 $("#removePatient").show();
250 return false;
253 function limitText(limitField, limitCount, limitNum) {
254 if (limitField.value.length > limitNum) {
255 limitField.value = limitField.value.substring(0, limitNum);
256 } else {
257 limitCount.value = limitNum - limitField.value.length;
261 function selectAll(){
262 $("#sendTo").each(function(){$("#sendTo option").attr("selected","selected"); });
264 </script>
265 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
266 </head>
267 <body class="body_top">
268 <!-- Required for the popup date selectors -->
269 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
272 <h1><?php echo xlt('Send a Reminder') ?></h1>
273 <form id="addDR" style="margin:0 0 10px 0;" id="newMessage" method="post" onsubmit="return top.restoreSession()">
274 <div style="text-align:center; color:red" id="errorMessage"></div>
276 <fieldset>
277 <?php echo xlt('Link To Patient') ?> :
278 <input type='text' size='10' id='patientName' name='patientName' style='width:200px;cursor:pointer;cursor:hand'
279 value='<?php echo ($patientID > 0 ? attr(getPatName($patientID)) : xla('Click to select patient')); ?>' onclick='sel_patient()'
280 title='<?php xla('Click to select patient'); ?>' readonly />
281 <input type="hidden" name="PatientID" id="PatientID" value="<?php echo (isset($patientID) ? attr($patientID) : 0) ?>" />
282 <button <?php echo ($patientID > 0 ? '' : 'style="display:none"') ?> id="removePatient"><?php echo xlt('unlink patient') ?></button>
283 </fieldset>
286 <br />
289 <fieldset>
290 <table style="width:100%;" cellpadding="5px">
291 <tr>
292 <td style="width:20%; text-align:right" valign="top">
293 <?php echo xlt('Send to') ?> : <br /><?php echo xlt('([ctrl] + click to select multiple recipients)'); ?>
294 </td>
295 <td style="width:60%;">
296 <select style="width:100%" id="sendTo" name="sendTo[]" multiple="multiple">
297 <option value="<?php echo attr(intval($_SESSION['authId'])); ?>"><?php echo xlt('Myself') ?></option>
298 <?php //
299 $uSQL = sqlStatement('SELECT id, fname, mname, lname FROM `users` WHERE `active` = 1 AND `facility_id` > 0 AND id != ?',array(intval($_SESSION['authId'])));
300 for($i=2; $uRow=sqlFetchArray($uSQL); $i++){
301 echo '<option value="',attr($uRow['id']),'">',text($uRow['fname'].' '.$uRow['mname'].' '.$uRow['lname']),'</option>';
304 </select> <br />
305 <input title="<?php echo xlt('Selecting this will create a message that needs to be processed by each recipient individually (this is not a group task).') ?>" type="checkbox" name="sendSeperately" id="sendSeperately" /> <label title="<?php echo xlt('Selecting this will create a message that needs to be processed by each recipient individually (this is not a group task).') ?>" for="sendSeperately">(<?php echo xlt('Each recipient must set their own messages as completed.') ?>)</label>
306 </td>
307 <td style="text-align:right">
308 <a class="css_button_small" style="cursor:pointer" onclick="selectAll();" ><span><?php echo xlt('Send to all') ?></span></a>
309 </td>
310 </table>
311 </fieldset>
313 <br />
315 <fieldset>
316 <?php echo xlt('Due Date') ?> : <input type='text' name='dueDate' id="dueDate" size='20' value="<?php echo ($this_message['dueDate'] == '' ? date('Y-m-d') : attr($this_message['dueDate'])); ?>" onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='<?php echo htmlspecialchars( xl('yyyy-mm-dd'), ENT_QUOTES); ?>' />
317 <?php echo xlt('OR') ?>
318 <?php echo xlt('Select a Time Span') ?> : <select id="timeSpan">
319 <option value="__BLANK__"> -- <?php echo xlt('Select a Time Span') ?> -- </option>
320 <?php
321 $optionTxt = '';
322 foreach($dateRanges as $val=>$txt){
323 $optionTxt .= '<option value="'.attr($val).'">'.text($txt).'</option>';
325 echo $optionTxt;
327 </select>
328 </td>
329 </fieldset>
332 <br />
336 <fieldset>
337 <?php echo xlt('Priority') ?> :
338 <input <?php echo ($this_message['message_priority'] == 3 ? 'checked="checked"' : '') ?> type="radio" name="priority" id="priority_3" value='3'> <label for="priority_3"><?php echo xlt('Low') ?></label>
339 <input <?php echo ($this_message['message_priority'] == 2 ? 'checked="checked"' : '') ?> type="radio" name="priority" id="priority_2" value='2'> <label for="priority_2"><?php echo xlt('Medium') ?></label>
340 <input <?php echo ($this_message['message_priority'] == 1 ? 'checked="checked"' : '') ?> type="radio" name="priority" id="priority_1" value='1'> <label for="priority_1"><?php echo xlt('High') ?></label>
341 </fieldset>
344 <br />
347 <fieldset>
348 <table style="width:100%;">
349 <tr>
350 <td valign="top" style="width:25%">
351 <?php echo xlt('Type Your message here') ?> :<br /><br />
352 <font size="1">(<?php echo xlt('Maximum characters') ?>: 255)<br />
353 </td>
354 <td valign="top" style="width:75%">
355 <textarea onKeyDown="limitText(this.form.message,this.form.countdown,255);"
356 onKeyUp="limitText(this.form.message,this.form.countdown,255);"
357 style="width:100%; height:50px" name="message" id="message"><?php echo text($this_message['message']); ?></textarea>
358 <br />
359 <?php echo xlt('Characters Remaining') ?> : <input style="border:0; background:none;" readonly type="text" name="countdown" size="3" value="255"> </font>
360 </td>
361 </tr>
362 </table>
363 </fieldset>
366 <p align="center">
367 <input type="submit" id="sendButton" value="<?php echo xla('Send This Message') ?>" />
368 </p>
369 </form>
370 <?php
371 $_GET['sentBy'] = array($_SESSION['authId']);
372 $_GET['sd'] = date('Y/m/d');
373 $TempRemindersArray = logRemindersArray();
374 $remindersArray = array();
375 foreach($TempRemindersArray as $RA){
376 $remindersArray[$RA['messageID']]['messageID'] = $RA['messageID'];
377 $remindersArray[$RA['messageID']]['ToName'] = ($remindersArray[$RA['messageID']]['ToName'] ? $remindersArray[$RA['messageID']]['ToName'].', '.$RA['ToName'] : $RA['ToName']);
378 $remindersArray[$RA['messageID']]['PatientName'] = $RA['PatientName'];
379 $remindersArray[$RA['messageID']]['message'] = $RA['message'];
380 $remindersArray[$RA['messageID']]['dDate'] = $RA['dDate'];
383 echo '<h2>',xlt('Messages You have sent Today'),'</h2>';
384 echo '<table border="1" width="100%" cellpadding="5px" id="logTable">
385 <thead>
386 <tr>
387 <th>'.xlt('ID').'</th>
388 <th>'.xlt('To').'</th>
389 <th>'.xlt('Patient').'</th>
390 <th>'.xlt('Message').'</th>
391 <th>'.xlt('Due Date').'</th>
392 </tr>
393 </thead>
394 <tbody>';
396 foreach($remindersArray as $RA){
397 echo '<tr class="heading">
398 <td>',text($RA['messageID']),'</td>
399 <td>',text($RA['ToName']),'</td>
400 <td>',text($RA['PatientName']),'</td>
401 <td>',text($RA['message']),'</td>
402 <td>',text($RA['dDate']),'</td>
403 </tr>';
405 echo '</tbody></table>';
407 </body>
408 <!-- stuff for the popup calendar -->
409 <style type="text/css">@import url(<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css);</style>
410 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
411 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
412 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
413 <script language="Javascript">
414 Calendar.setup({inputField:"dueDate", ifFormat:"%Y-%m-%d", button:"img_begin_date", showsTime:'false'});
415 </script>
416 </html>