Added access controls for encounter categories
[openemr.git] / portal / import_template_ui.php
blob371dbee94987b43510af04fa8166e60689959875
1 <?php
2 /**
4 * Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
6 * LICENSE: This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * 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 Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @package OpenEMR
20 * @author Jerry Padgett <sjpadgett@gmail.com>
21 * @link http://www.open-emr.org
23 //$ignoreAuth = true;
26 require_once("../interface/globals.php");
27 $getdir = isset($_POST['sel_pt']) ? $_POST['sel_pt'] : 0;
28 if( $getdir > 0){
29 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/' . $getdir . '/';
30 if(!is_dir($tdir)){
31 if (!mkdir($tdir, 0755, true)) {
32 die(xl('Failed to create folder'));
36 else {
37 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/';
39 function getAuthUsers()
41 $response = sqlStatement( "SELECT patient_data.pid, Concat_Ws(' ', patient_data.fname, patient_data.lname) as ptname FROM patient_data WHERE allow_patient_portal = 'YES'" );
42 $resultpd = array ();
43 while( $row = sqlFetchArray($response) ){
44 $resultpd[] = $row;
46 return $resultpd;
48 function getTemplateList($dir)
50 $retval = array();
51 if(substr($dir, -1) != "/") $dir .= "/";
52 $d = @dir($dir) or die("File List: Failed opening directory " . text($dir) . " for reading");
53 while(false !== ($entry = $d->read())) {
54 if($entry[0] == "." || substr($entry,-3) != 'tpl') continue;
56 if(is_dir("$dir$entry")) {
57 $retval[] = array(
58 'pathname' => "$dir$entry",
59 'name' => "$entry",
60 'size' => 0,
61 'lastmod' => filemtime("$dir$entry")
63 } elseif(is_readable("$dir$entry")) {
64 $retval[] = array(
65 'pathname' => "$dir$entry",
66 'name' => "$entry",
67 'size' => filesize("$dir$entry"),
68 'lastmod' => filemtime("$dir$entry")
72 $d->close();
73 return $retval;
76 <html>
77 <head>
78 <meta charset="UTF-8">
79 <title><?php echo xlt('OpenEMR Portal'); ?> | <?php echo xlt('Import'); ?></title>
80 <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
81 <meta name="description" content="Developed By sjpadgett@gmail.com">
83 <link href="<?php echo $GLOBALS['assets_static_relative']; ?>/font-awesome-4-6-3/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
84 <link href="<?php echo $GLOBALS['assets_static_relative']; ?>/bootstrap-3-3-4/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
85 <?php if ($_SESSION['language_direction'] == 'rtl') { ?>
86 <link href="<?php echo $GLOBALS['assets_static_relative']; ?>/bootstrap-rtl-3-3-4/dist/css/bootstrap-rtl.min.css" rel="stylesheet" type="text/css" />
87 <?php } ?>
88 <link href="assets/css/style.css?v=<?php echo $v_js_includes; ?>" rel="stylesheet" type="text/css" />
89 <script src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-11-3/index.js" type="text/javascript"></script>
90 <script src="<?php echo $GLOBALS['assets_static_relative']; ?>/bootstrap-3-3-4/dist/js/bootstrap.min.js" type="text/javascript"></script>
91 <link href="<?php echo $GLOBALS['assets_static_relative']; ?>/summernote-0-8-2/dist/summernote.css" rel="stylesheet" type="text/css" />
92 <script type='text/javascript' src="<?php echo $GLOBALS['assets_static_relative']; ?>/summernote-0-8-2/dist/summernote.js"></script>
93 <script type='text/javascript' src="<?php echo $GLOBALS['assets_static_relative']; ?>/summernote-0-8-2/dist/plugin/nugget/summernote-ext-nugget.js"></script>
94 </head>
95 <script>
96 var currentEdit = "";
97 var tedit = function(docname) {
98 currentEdit = docname;
99 getDocument(docname, 'get', '')
100 return false;
103 var tsave = function() {
104 var makrup = $('#templatecontent').summernote('code');
105 getDocument(currentEdit, 'save', makrup)
107 var tdelete = function(docname) {
108 var delok = confirm("<?php echo xls('You are about to delete template'); ?>: "+docname+"\n<?php echo xls('Is this Okay?'); ?>");
109 if(delok === true) {getDocument(docname, 'delete', '')}
110 return false;
112 function getDocument(docname, mode, content){
113 var liburl = 'import_template.php';
114 $.ajax({
115 type: "POST",
116 url: liburl,
117 data: {docid: docname, mode: mode,content: content},
118 beforeSend: function(xhr){
119 console.log("Please wait..."+content);
121 error: function(qXHR, textStatus, errorThrow){
122 console.log("There was an error");
124 success: function(templateHtml, textStatus, jqXHR){
125 if(mode == 'get'){
126 //console.log("File get..."+templateHtml);
127 $('#templatecontent').summernote('destroy');
128 $('#templatecontent').empty().append(templateHtml);
129 $('#popeditor').modal({backdrop: "static"});
130 $('#templatecontent').summernote({
131 // height: 200,
132 focus: true,
133 placeholder: '',
134 toolbar: [
135 ['style', ['bold', 'italic', 'underline', 'clear']],
136 ['fontsize', ['fontsize']],
137 ['color', ['color']],
138 ['para', ['ul', 'ol', 'paragraph']],
139 ['insert', ['link','picture', 'video', 'hr']],
140 ['view', ['fullscreen', 'codeview']],
141 ['insert', ['nugget']],
142 ['edit',['undo','redo']]
144 nugget: {
145 list: [
146 '{ParseAsHTML}{TextInput}', '{smTextInput}', '{CheckMark}', '{ynRadioGroup}', '{DOS}','{ReferringDOC}', '{PatientID}',
147 '{PatientName}', '{PatientSex}', '{PatientDOB}', '{PatientPhone}', '{PatientSignature}', '{Address}', '{City}', '{State}', '{Zip}',
148 '{AdminSignature}', '{Medications}', '{ProblemList}', '{Allergies}', '{ChiefComplaint}'
150 label: 'Tags / Directives',
151 tooltip: 'Insert at current cursor location.'
153 options:{'label': 'Tags/Directives',
154 'tooltip': 'Insert Tag or Directive'}
157 else if(mode == 'save'){
158 $('#templatecontent').summernote('destroy');
159 location.reload();
161 else if(mode == 'delete'){
162 location.reload();
167 </script>
168 <style>
169 .modal.modal-wide .modal-dialog {
170 width: 75%;
172 .modal-wide .modal-body {
173 overflow-y: auto;
175 </style>
176 <body class="skin-blue">
177 <div class='container' style='display: block;'>
178 <hr>
179 <h3><?php echo xlt('Patient Document Template Upload'); ?></h3>
180 <h4><em><?php echo xlt('File base name becomes Menu selection'); ?>.<br><?php echo xlt('Automatically applies correct extension on successful upload'); ?>.<br>
181 <?php echo xlt('Example Privacy_Agreement.txt becomes Privacy Agreement button in Patient Documents'); ?>.</em></h4>
182 <form id="form_upload" class="form" action="import_template.php" method="post" enctype="multipart/form-data">
183 <input class="btn btn-info" type="file" name="tplFile">
184 <br>
185 <button class="btn btn-primary" type="button" onclick="location.href='./patient/provider'"><?php echo xlt('Home'); ?></button>
186 <input type='hidden' name="up_dir" value='<?php global $getdir;
187 echo $getdir;?>' />
188 <button class="btn btn-success" type="submit" name="upload_submit" id="upload_submit"><?php echo xlt('Upload Template for'); ?> <span style="font-size: 14px;" class="label label-default" id='ptstatus'></span></button>
189 </form>
190 <div class='row'>
191 <h3><?php echo xlt('Active Templates'); ?></h3>
192 <div class='col col-md col-lg'>
193 <form id = "edit_form" name = "edit_form" class="form-inline" action="" method="post">
194 <div class="form-group">
195 <label for="sel_pt"><?php echo xlt('Patient'); ?></label>
196 <select class="form-control" id="sel_pt" name="sel_pt">
197 <option value='0'><?php echo xlt("Global All Patients")?></option>
198 <?PHP
199 $ppt = getAuthUsers();
200 global $getdir;
201 foreach ($ppt as $pt) {
202 if ($getdir != $pt['pid']) {
203 echo "<option value=" . attr($pt['pid']) . ">" . text($pt['ptname']) . "</option>";
204 } else {
205 echo "<option value='" . attr($pt['pid']) . "' selected='selected'>" . text($pt['ptname']) . "</option>";
208 echo "</select></div>";
209 echo '<button type="submit" class="btn btn-default">' . xlt('Refresh') . '</button>';
210 echo '</form></div>';
211 $dirlist = getTemplateList($tdir);
212 echo "<table class='table table-striped table-bordered'>";
213 echo "<thead>";
214 echo "<tr><th>" . xlt("Template") . " - <i>" . xlt("Click to edit") . "</i></th><th>" . xlt("Size") . "</th><th>" . xlt("Last Modified") . "</th></tr>";
215 echo "</thead>";
216 echo "<tbody>";
217 foreach ($dirlist as $file) {
218 $t = "'" . $file['pathname'] . "'";
219 echo "<tr>";
220 echo '<td><button id="tedit' . attr($t) . '" class="btn btn-sm btn-primary" onclick="tedit(' . attr($t) . ')" type="button">' . text($file['name']) . '</button>
221 <button id="tdelete' . attr($t) . '" class="btn btn-xs btn-danger" onclick="tdelete(' . attr($t) . ')" type="button">' . xlt("Delete") . '</button></td>';
222 echo "<td>{$file['size']}</td>";
223 echo "<td>", date('r', $file['lastmod']), "</td>";
224 echo "</tr>";
226 echo "</tbody>";
227 echo "</table>";
229 <script>
230 $(document).ready(function(){
231 $("#popeditor").on("show.bs.modal", function() {
232 var height = $(window).height() - 200;
233 $(this).find(".modal-body").css("max-height", height);
235 $("#sel_pt").change(function(){
236 $("#edit_form").submit();
238 $("#ptstatus").text($("#sel_pt").find(":selected").text())
240 </script>
241 </div>
242 <div class="modal modal-wide fade" id="popeditor">
243 <div class="modal-dialog modal-lg">
244 <div class="modal-content">
245 <div class="modal-header">
246 <button type="button" class="close" data-dismiss="modal">
247 <span aria-hidden="true">&times;</span>
248 <span class="sr-only"><?php echo xlt('Close'); ?></span>
249 </button>
250 <h4 class="modal-title"><?php echo xlt('Edit Template'); ?></h4>
251 </div>
252 <div class="modal-body">
253 <div class="edittpl" id="templatecontent"></div>
254 </div>
255 <div class="modal-footer">
256 <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal"><?php echo xlt('Dismiss'); ?></button>
257 <button type="button" class="btn btn-success" data-dismiss="modal" onclick="tsave()"><?php echo xlt('Save'); ?></button>
258 </div>
259 </div>
260 </div>
261 </div>
262 </body>
263 </html>