fix add_edit_amendments.php
[openemr.git] / interface / patient_file / summary / add_edit_amendments.php
blob1aa20dc7bb85b4496ec82fdbfebb235c3be2a1c3
1 <?php
2 /**
3 * Add/Edit Amendments
5 * Copyright (C) 2014 Ensoftek
6 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
8 * LICENSE: This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 3
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @package OpenEMR
20 * @author Hema Bandaru <hemab@drcloudemr.com>
21 * @author Brady Miller <brady.g.miller@gmail.com>
22 * @link http://www.open-emr.org
25 //SANITIZE ALL ESCAPES
26 $sanitize_all_escapes=true;
29 //STOP FAKE REGISTER GLOBALS
30 $fake_register_globals=false;
33 include_once("../../globals.php");
34 include_once("$srcdir/options.inc.php");
36 if ( isset($_POST['mode'] )) {
37 $currentUser = $_SESSION['authUserID'];
38 $created_time = date('Y-m-d H:i');
39 if ( $_POST["amendment_id"] == "" ) {
40 // New. Insert
41 $query = "INSERT INTO amendments SET
42 amendment_date = ?,
43 amendment_by = ?,
44 amendment_status = ?,
45 pid = ?,
46 amendment_desc = ?,
47 created_by = ?,
48 created_time = ?";
49 $sqlBindArray = array(
50 DateToYYYYMMDD( $_POST['amendment_date']),
51 $_POST['form_amendment_by'],
52 $_POST['form_amendment_status'],
53 $pid,
54 $_POST['desc'],
55 $currentUser,
56 $created_time
59 $amendment_id = sqlInsert($query,$sqlBindArray);
60 } else {
61 $amendment_id = $_POST['amendment_id'];
62 // Existing. Update
63 $query = "UPDATE amendments SET
64 amendment_date = ?,
65 amendment_by = ?,
66 amendment_status = ?,
67 amendment_desc = ?,
68 modified_by = ?,
69 modified_time = ?
70 WHERE amendment_id = ?";
71 $sqlBindArray = array(
72 DateToYYYYMMDD($_POST['amendment_date']),
73 $_POST['form_amendment_by'],
74 $_POST['form_amendment_status'],
75 $_POST['desc'],
76 $currentUser,
77 $created_time,
78 $_POST['amendment_id']
80 sqlStatement($query,$sqlBindArray);
83 // Insert into amendments_history
84 $query = "INSERT INTO amendments_history SET
85 amendment_id = ? ,
86 amendment_note = ?,
87 amendment_status = ?,
88 created_by = ?,
89 created_time = ?";
90 $sqlBindArray = array(
91 $amendment_id,
92 $_POST['note'],
93 $_POST["form_amendment_status"],
94 $currentUser,
95 $created_time
97 sqlStatement($query,$sqlBindArray);
98 header("Location:add_edit_amendments.php?id=$amendment_id");
99 exit;
102 $amendment_id = ( $amendment_id ) ? $amendment_id : $_REQUEST['id'];
103 if ( $amendment_id ) {
104 $query = "SELECT * FROM amendments WHERE amendment_id = ? ";
105 $resultSet = sqlQuery($query,array($amendment_id));
106 $amendment_date = $resultSet['amendment_date'];
107 $amendment_status = $resultSet['amendment_status'];
108 $amendment_by = $resultSet['amendment_by'];
109 $amendment_desc = $resultSet['amendment_desc'];
111 $query = "SELECT * FROM amendments_history ah INNER JOIN users u ON ah.created_by = u.id WHERE amendment_id = ? ";
112 $resultSet = sqlStatement($query,array($amendment_id));
114 // Check the ACL
115 $haveAccess = acl_check('patients', 'trans');
116 $onlyRead = ( $haveAccess ) ? 0 : 1;
117 $onlyRead = ( $onlyRead || $amendment_status ) ? 1 : 0;
118 $customAttributes = ( $onlyRead ) ? array("disabled" => "true") : null;
122 <html>
123 <head>
124 <?php html_header_show();?>
126 <!-- supporting javascript code -->
127 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
128 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
129 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
130 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
132 <!-- page styles -->
133 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
134 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
136 <style>
137 .highlight {
138 color: green;
140 tr.selected {
141 background-color: white;
143 .historytbl {
144 border-collapse: collapse;
146 .historytbl td th{
147 border: 1px solid #000;
149 </style>
151 <script type="text/javascript">
153 function formValidation() {
154 if ( $("#amendment_date").val() == "" ) {
155 alert("<?php echo xls('Select Amendment Date'); ?>");
156 return;
157 } else if ( $("#form_amendment_by").val() == "" ) {
158 alert("<?php echo xls('Select Requested By'); ?>");
159 return;
162 var statusText = $("#form_amendment_status option:selected").text();
163 $("#note").val($("#note").val() + ' ' + statusText);
165 $("#add_edit_amendments").submit();
168 $(document).ready(function() {
169 $('.datepicker').datetimepicker({
170 <?php $datetimepicker_timepicker = false; ?>
171 <?php $datetimepicker_formatInput = true; ?>
172 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
173 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
177 </script>
179 </head>
181 <body class="body_top">
183 <form action="add_edit_amendments.php" name="add_edit_amendments" id="add_edit_amendments" method="post" onsubmit='return top.restoreSession()'>
185 <table>
186 <tr>
187 <td>
188 <span class="title"><?php echo xlt('Amendments'); ?></span>&nbsp;
189 </td>
190 <?php if ( ! $onlyRead ) { ?>
191 <td>
192 <a href=# onclick="formValidation()" class="css_button_small"><span><?php echo xlt('Save');?></span></a>
193 </td>
194 <?php } ?>
195 <td>
196 <a href="list_amendments.php" class="css_button_small"><span><?php echo xlt('Back');?></span></a>
197 </td>
198 </tr>
199 </table>
201 <br>
202 <table border=0 cellpadding=1 cellspacing=1>
203 <tr>
204 <td><span class=text ><?php echo xlt('Requested Date'); ?></span></td>
205 <td>
206 <?php if ( ! $onlyRead ) { ?>
207 <input type='text' size='10' class='datepicker' name="amendment_date" id="amendment_date"
208 value='<?php echo $amendment_date ? htmlspecialchars( oeFormatShortDate($amendment_date), ENT_QUOTES) : oeFormatShortDate(); ?>'
210 <?php } else { ?>
211 <input type='text' size='10' name="amendment_date" id="amendment_date" readonly
212 value='<?php echo $amendment_date ? htmlspecialchars( oeFormatShortDate($amendment_date), ENT_QUOTES) : oeFormatShortDate(); ?>'
214 <?php } ?>
215 </td>
216 </tr>
218 <tr>
219 <td><span class=text ><?php echo xlt('Requested By'); ?></span></td>
220 <td>
221 <?php echo generate_select_list("form_amendment_by", "amendment_from", $amendment_by,'Amendment Request By',' ','','','',$customAttributes); ?>
222 </td>
223 </tr>
225 <tr>
226 <td><span class=text ><?php echo xlt('Request Description'); ?></span></td>
227 <td><textarea <?php echo ( $onlyRead ) ? "readonly" : ""; ?> id="desc" name="desc" rows="4" cols="30"><?php
228 if($amendment_id) { echo text($amendment_desc); }else{ echo ""; } ?></textarea></td>
229 </tr>
231 <tr>
232 <td><span class=text ><?php echo xlt('Request Status'); ?></span></td>
233 <td>
234 <?php echo generate_select_list("form_amendment_status", "amendment_status", $amendment_status,'Amendment Status',' ','','','',$customAttributes); ?>
235 </td>
236 </tr>
238 <tr>
239 <td><span class=text ><?php echo xlt('Comments'); ?></span></td>
240 <td><textarea <?php echo ( $onlyRead ) ? "readonly" : ""; ?> id="note" name="note" rows="4" cols="30"><?php
241 if($amendment_id) echo ""; else echo xlt('New amendment request'); ?></textarea></td>
242 </tr>
243 </table>
245 <?php if ( $amendment_id ) { ?>
246 <hr>
248 <span class="title"><?php echo xlt("History") ; ?></span>
250 <table border="1" cellpadding=3 cellspacing=0 class="historytbl">
252 <!-- some columns are sortable -->
253 <tr class='text bold'>
254 <th align="left" style="width:15%"><?php echo xlt('Date'); ?></th>
255 <th align="left" style="width:25%"><?php echo xlt('By'); ?></th>
256 <th align="left" style="width:15%"><?php echo xlt('Status'); ?></th>
257 <th align="left"><?php echo xlt('Comments'); ?></th>
258 </tr>
260 <?php
261 if (sqlNumRows($resultSet)) {
262 while ( $row = sqlFetchArray($resultSet) ) {
263 $created_date = date('Y-m-d', strtotime($row['created_time']));
264 echo "<tr>";
265 $userName = $row['lname'] . ", " . $row['fname'];
266 echo "<td align=left class=text>" . oeFormatShortDate($created_date) . "</td>";
267 echo "<td align=left class=text>" . text($userName) . "</td>";
268 echo "<td align=left class=text>" . ( ( $row['amendment_status'] ) ? generate_display_field(array('data_type'=>'1','list_id'=>'amendment_status'), $row['amendment_status']) : '') . "</td>";
269 echo "<td align=left class=text>" . text($row['amendment_note']) . "</td>";
270 echo "<tr>";
274 </table>
275 <?php } ?>
277 <input type="hidden" id="mode" name="mode" value=""/>
278 <input type="hidden" id="amendment_id" name="amendment_id" value="<?php echo attr($amendment_id); ?>"/>
279 </form>
280 </body>
281 </html>