Dated reminders module.
[openemr.git] / interface / main / dated_reminders / dated_reminders_add.php
blobf78778848862eaf30a60195a80ecb20aa47f80f6
1 <?php
2 // ------------------------------------------------------------------------ //
3 // OpenEMR Electronic Medical Records System //
4 // Copyright (c) 2012 tajemo.co.za //
5 // <http://www.tajemo.co.za/> //
6 // ------------------------------------------------------------------------ //
7 // This program is free software; you can redistribute it and/or modify //
8 // it under the terms of the GNU General Public License as published by //
9 // the Free Software Foundation; either version 2 of the License, or //
10 // (at your option) any later version. //
11 // //
12 // You may not change or alter any portion of this comment or credits //
13 // of supporting developers from this source code or any supporting //
14 // source code which is considered copyrighted (c) material of the //
15 // original comment or credit authors. //
16 // //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details. //
21 // //
22 // You should have received a copy of the GNU General Public License //
23 // along with this program; if not, write to the Free Software //
24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
25 // --------------------------------------------------------------------------//
26 // Original Author of this file: Craig Bezuidenhout (Tajemo Enterprises) //
27 // Purpose of this file: Used for adding dated reminders //
28 // --------------------------------------------------------------------------//
30 $fake_register_globals=false;
31 $sanitize_all_escapes=true;
33 require_once("../../globals.php");
34 require_once("$srcdir/htmlspecialchars.inc.php");
35 require_once("$srcdir/dated_reminders.php");
37 $dateRanges = array();
38 // $dateranges = array ( number_period => text to display ) == period is always in the singular
39 // eg. $dateRanges['4_week'] = '4 Weeks From Now';
40 $dateRanges['1_day'] = xl('1 Day From Now');
41 $dateRanges['2_day'] = xl('2 Days From Now');
42 $dateRanges['3_day'] = xl('3 Days From Now');
43 $dateRanges['4_day'] = xl('4 Days From Now');
44 $dateRanges['5_day'] = xl('5 Days From Now');
45 $dateRanges['6_day'] = xl('6 Days From Now');
46 $dateRanges['1_week'] = xl('1 Week From Now');
47 $dateRanges['2_week'] = xl('2 Weeks From Now');
48 $dateRanges['3_week'] = xl('3 Weeks From Now');
49 $dateRanges['4_week'] = xl('4 Weeks From Now');
50 $dateRanges['5_week'] = xl('5 Weeks From Now');
51 $dateRanges['6_week'] = xl('6 Weeks From Now');
52 $dateRanges['1_month'] = xl('1 Month From Now');
53 $dateRanges['2_month'] = xl('2 Months From Now');
54 $dateRanges['3_month'] = xl('3 Months From Now');
55 $dateRanges['4_month'] = xl('4 Months From Now');
56 $dateRanges['5_month'] = xl('5 Months From Now');
57 $dateRanges['6_month'] = xl('6 Months From Now');
58 $dateRanges['7_month'] = xl('7 Months From Now');
59 $dateRanges['8_month'] = xl('8 Months From Now');
60 $dateRanges['9_month'] = xl('9 Months From Now');
61 $dateRanges['1_year'] = xl('1 Year From Now');
62 $dateRanges['2_year'] = xl('2 Years From Now');
64 // --- need to add a check to ensure the post is being sent from the correct location ???
66 // default values for $this_message
67 $this_message = array('message'=>'','message_priority'=>3,'dueDate'=>'');
68 $forwarding = false;
70 // ---------------- FOR FORWARDING MESSAGES ------------->
71 if(isset($_GET['mID']) and is_numeric($_GET['mID'])){
72 $forwarding = true;
73 $this_message = getReminderById($_GET['mID']);
76 // ---------------END FORWARDING MESSAGES ----------------
79 // --- add reminders
80 if($_POST){
81 // --- initialize $output as blank
82 $output = '';
84 // ------ fills an array with all recipients
85 $sendTo = array();
86 foreach($_POST as $key=>$val){
87 // check for recipients, make sure they are integers
88 if(preg_match('/^sendTo_/',$key) and is_numeric($val)){
89 $sendTo[] = intval($val);
90 unset($_POST[$key]);
94 // for incase of data error, this allows the previously entered data to re-populate the boxes
95 $this_message['message'] = (isset($_POST['message']) ? $_POST['message'] : '');
96 $this_message['priority'] = (isset($_POST['priority']) ? $_POST['priority'] : '');
97 $this_message['dueDate'] = (isset($_POST['dueDate']) ? $_POST['dueDate'] : '');
100 // --------------------------------------------------------------------------------------------------------------------------
101 // --- check for the post, if it is valid, commit to the database, close this window and run opener.Handeler
102 if(
103 // ------- check sendTo is not empty
104 !empty($sendTo) and
105 // ------- check dueDate, only allow valid dates, todo -> enhance date checker
106 isset($_POST['dueDate']) and preg_match('/\d{4}[-]\d{2}[-]\d{2}/',$_POST['dueDate']) and
107 // ------- check priority, only allow 1-3
108 isset($_POST['priority']) and intval($_POST['priority']) <= 3 and
109 // ------- check message, only up to 144 characters
110 isset($_POST['message']) and strlen($_POST['message']) <= 144 and strlen($_POST['message']) > 0 and
111 // ------- check if PatientID is set and in numeric
112 isset($_POST['PatientID']) and is_numeric($_POST['PatientID'])
114 $dueDate = $_POST['dueDate'];
115 $priority = intval($_POST['priority']);
116 $message = $_POST['message'];
117 $fromID = $_SESSION['authId'];
118 $patID = $_POST['PatientID'];
121 // -------- Send the reminder
122 $ReminderSent = sendReminder($sendTo,$fromID,$message,$dueDate,$patID,$priority);
123 // --------------------------------------------------------------------------------------------------------------------------
124 if(!$ReminderSent){
125 $output .= '<div style="text-size:2em; text-align:center; color:red">* '.xlt('Please select a valid recipient').'</div> ';
126 }else{
127 // --------- echo javascript
128 echo '<html><body><script language="JavaScript">';
129 // ------------ 1) refresh parent window this updates if sent to self
130 echo ' if (opener && !opener.closed && opener.updateme) opener.updateme("new");';
131 // ------------ 2) communicate with user
132 echo ' alert("'.addslashes(xl('Message Sent')).'");';
133 // ------------ 3) close this window
134 echo ' window.close();';
135 echo '</script></body></html>';
136 // --------- stop script from executing further
137 exit;
139 // --------------------------------------------------------------------------------------------------------------------------
141 // --------------------------------------------------------------------------------------------------------------------------
143 else{
144 // ------- if POST error
145 $output .= '<div style="text-size:2em; text-align:center; color:red">* '.xlt('Data Error').'</div> ';
147 // ------- if any errors, communicate with the user
148 echo $output;
150 // end add reminders
152 // get current patient, first check if this is a forwarded message, if it is use the original pid
153 if(isset($this_message['pid'])) $patientID = (isset($this_message['pid']) ? $this_message['pid'] : 0);
154 else $patientID = (isset($pid) ? $pid : 0);
156 <html>
157 <head>
158 <title><?php echo xlt('Send a Reminder') ?></title>
159 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
160 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/topdialog.js"></script>
161 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
162 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
163 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-1.4.3.min.js"></script>
164 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-calendar.js"></script>
165 <script language="JavaScript">
166 $(document).ready(function (){
168 $('#timeSpan').change(function(){
169 var value = $(this).val();
170 var arr = value.split('_');
171 var span = arr[1];
172 var period = parseInt(arr[0]);
173 var d=new Date();
174 if(span == 'day'){
175 d.setDate(d.getDate()+period);
177 else if(span == 'week'){
178 var weekInDays = period * 7;
179 d.setDate(d.getDate()+weekInDays);
181 else if(span == 'month'){
182 d.setMonth(d.getMonth()+period);
184 else if(span == 'year'){
185 var yearsInMonths = period * 12;
186 d.setMonth(d.getMonth()+yearsInMonths);
188 var curr_date = d.getDate().toString();
189 if(curr_date.length == 1){
190 curr_date = '0'+curr_date;
192 var curr_month = d.getMonth() + 1; //months are zero based
193 curr_month = curr_month.toString();
194 if(curr_month.length == 1){
195 curr_month = '0'+curr_month;
197 var curr_year = d.getFullYear();
198 $('#dueDate').val(curr_year + "-" + curr_month + "-" + curr_date);
202 $("#sendButton").click(function(){
203 $('#errorMessage').html('');
204 errorMessage = '';
205 var PatientID = $('#PatientID').val();
206 var dueDate = $('#dueDate').val();
207 var priority = $('#priority:checked').val();
208 var message = $("#message").val();
209 // todo : check if PatientID is numeric , no rush as this is checked in the php after the post
211 // check to see if a recipient has been set
212 // todo : check if they are all numeric , no rush as this is checked in the php after the post
213 noRecipient = true;
214 $('.sendTo').each(function(index) {
215 if($(this).is(":checked")){
216 noRecipient = false;
219 if(noRecipient){
220 errorMessage = errorMessage + '* <?php echo xla('Please Select A Recipient') ?><br />';
224 // Check if Date is set
225 // todo : add check to see if dueDate is a valid date , no rush as this is checked in the php after the post
226 if(dueDate == ''){
227 errorMessage = errorMessage + '* <?php echo xla('Please enter a due date') ?><br />';
230 // check if message is set
231 if(message == ''){
232 errorMessage = errorMessage + '* <?php echo xla('Please enter a message') ?><br />';
235 if(errorMessage != ''){
236 // handle invalid queries
237 $('#errorMessage').html(errorMessage);
239 else{
240 // handle valid queries
241 // post the form to self
242 top.restoreSession();
243 $("#addDR").submit();
245 return false;
248 $("#removePatient").click(function(){
249 $("#PatientID").val("0");
250 $("#patientName").val("<?php echo xla('Click to select patient'); ?>");
251 $(this).hide();
252 return false;
256 function sel_patient(){
257 window.open('../../main/calendar/find_patient_popup.php', '_newDRPat', '' + ",width=" + 500 + ",height=" + 400 + ",left=" + 25 + ",top=" + 25 + ",screenX=" + 25 + ",screenY=" + 25);
260 function setpatient(pid, lname, fname, dob){
261 $("#patientName").val(fname +' '+ lname)
262 $("#PatientID").val(pid);
263 $("#removePatient").show();
264 return false;
267 function limitText(limitField, limitCount, limitNum) {
268 if (limitField.value.length > limitNum) {
269 limitField.value = limitField.value.substring(0, limitNum);
270 } else {
271 limitCount.value = limitNum - limitField.value.length;
274 </script>
275 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
276 </head>
277 <body class="body_top">
278 <!-- Required for the popup date selectors -->
279 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
282 <h1><?php echo xlt('Send a Reminder') ?></h1>
283 <form id="addDR" style="margin-left:40px;" id="newMessage" method="post" onsubmit="return top.restoreSession()">
284 <div style="text-size:2em; text-align:center; color:red" id="errorMessage"></div>
286 <?php echo xlt('Link To Patient') ?> :
287 <input type='text' size='10' id='patientName' name='patientName' style='width:200px;cursor:pointer;cursor:hand'
288 value='<?php echo ($patientID > 0 ? attr(getPatName($patientID)) : xla('Click to select patient')); ?>' onclick='sel_patient()'
289 title='<?php xla('Click to select patient'); ?>' readonly />
290 <input name="PatientID" id="PatientID" type="hidden" value="<?php echo (isset($patientID) ? attr($patientID) : 0) ?>" />
291 <button <?php echo ($patientID > 0 ? '' : 'style="display:'.attr('none').'"') ?> id="removePatient"><?php echo xlt('unlink patient') ?></button>
294 <br /><br />
297 <?php echo xlt('Send to') ?> : <p style="line-height:1.8em;">
298 <input class="sendTo" type="checkbox" name="sendTo_me" value="<?php echo attr(intval($_SESSION['authId'])) ?>" id="me"><label for="me"><?php echo xlt('Myself') ?></label>&nbsp;&nbsp;&nbsp;&nbsp;
299 <?php //
300 $uSQL = sqlStatement('SELECT id, fname, mname, lname FROM `users` WHERE `active` = 1 AND id != ?',array(intval($_SESSION['authId'])));
301 for($i=2; $uRow=sqlFetchArray($uSQL); $i++){
302 echo '<input class="sendTo" type="checkbox" name="sendTo_',$i,'" id="sendTo_',$i,'" value="',attr($uRow['id']),'"><label for="sendTo_',$i,'">',text($uRow['fname'].' '.$uRow['mname'].' '.$uRow['lname']),'</label>&nbsp;&nbsp;&nbsp;&nbsp; ';
303 // line break for every 4 users
304 if($i % 4 == 0) echo "<br />";
307 </p>
312 <?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); ?>' />
313 <?php echo xlt('OR') ?>
314 <?php echo xlt('Select a time span') ?> : <select id="timeSpan">
315 <option value="__BLANK__"> -- <?php echo xlt('Select a Time Span') ?> -- </option>
316 <?php
317 $optionTxt = '';
318 foreach($dateRanges as $val=>$txt){
319 $optionTxt .= '<option value="'.attr($val).'">'.text($txt).'</option>';
321 echo $optionTxt;
323 </select>
324 <br />
325 <br />
326 <?php echo xlt('Priority') ?> :
327 <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>
328 <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>
329 <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>
330 <br />
331 <br />
332 <?php echo xlt('Type Your message here') ?> : <br /><br />
333 <font size="1">(<?php echo xlt('Maximum characters') ?>: 144)<br>
334 <textarea onKeyDown="limitText(this.form.message,this.form.countdown,144);"
335 onKeyUp="limitText(this.form.message,this.form.countdown,144);"
336 style="width:98%; height:50px" name="message" id="message"><?php echo text($this_message['message']); ?></textarea>
337 <br>
338 <?php echo xlt('Characters Remaining') ?> : <input readonly type="text" name="countdown" size="3" value="144"> </font>
339 <br />
340 <br />
341 <input type="submit" id="sendButton" value="<?php echo xla('Send This Message') ?>" />
342 </form>
343 </body>
344 <!-- stuff for the popup calendar -->
345 <style type="text/css">@import url(<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css);</style>
346 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
347 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
348 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
349 <script language="Javascript">
350 Calendar.setup({inputField:"dueDate", ifFormat:"%Y-%m-%d", button:"img_begin_date", showsTime:'false'});
351 </script>
352 </html>