Openemr fix 4723 module install script uses OpenEMR sql upgrade service (#4724)
[openemr.git] / portal / import_template_ui.php
blob50d327f00fe80122c70bebd53e1733fcf95c72c5
1 <?php
3 /**
4 * import_template_ui.php
6 * @package OpenEMR
7 * @link https://www.open-emr.org
8 * @author Jerry Padgett <sjpadgett@gmail.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2016-2021 Jerry Padgett <sjpadgett@gmail.com>
11 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../interface/globals.php");
17 use OpenEMR\Core\Header;
19 $patient = (int)($_POST['sel_pt'] ?? 0);
20 $patient_dir = $patient > 0 ? convert_safe_file_dir_name($patient . "_tpls") : "";
21 $cat_dir = convert_safe_file_dir_name($_POST['doc_category']) ?? "";
22 // default root
23 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/';
24 if (!empty($patient_dir)) {
25 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/' . $patient_dir . '/';
26 } elseif (!empty($cat_dir)) {
27 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/' . $cat_dir . '/';
30 $rtn = sqlStatement("SELECT `option_id`, `title`, `seq` FROM `list_options` WHERE `list_id` = ? ORDER BY `seq`", array('Document_Template_Categories'));
31 $category_list = array();
32 while ($row = sqlFetchArray($rtn)) {
33 $category_list[] = $row;
36 function getAuthUsers()
38 $response = sqlStatement("SELECT patient_data.pid, Concat_Ws(' ', patient_data.fname, patient_data.lname) as ptname FROM patient_data WHERE allow_patient_portal = 'YES'");
39 $resultpd = array();
40 while ($row = sqlFetchArray($response)) {
41 $resultpd[] = $row;
44 return $resultpd;
47 function getTemplateList($dir, $location = "")
49 $retval = array();
50 if (substr($dir, -1) !== "/") {
51 $dir .= "/";
54 if (false === $d = @dir($dir)) {
55 return false;
57 while (false !== ($entry = $d->read())) {
58 if ($entry[0] === "." || substr($entry, -3) !== 'tpl') {
59 continue;
61 if (is_dir("$dir$entry")) {
62 continue;
65 if (is_readable("$dir$entry")) {
66 $retval[] = array(
67 'pathname' => "$dir$entry",
68 'name' => "$entry",
69 'size' => filesize("$dir$entry"),
70 'lastmod' => filemtime("$dir$entry"),
71 'location' => text("./documents/onsite_portal_documents/templates/" . $location)
76 $d->close();
77 return $retval;
81 <!DOCTYPE html>
82 <html>
83 <head>
84 <meta charset="UTF-8">
85 <title><?php echo xlt('Portal'); ?> | <?php echo xlt('Templates'); ?></title>
86 <meta name="description" content="Developed By sjpadgett@gmail.com">
87 <?php Header::setupHeader(['datetime-picker', 'summernote', 'summernote-ext-nugget']); ?>
89 </head>
90 <script>
91 let currentEdit = "";
92 let tedit = function (docname) {
93 currentEdit = docname;
94 getDocument(docname, 'get', '');
95 return false;
98 let tsave = function () {
99 let makrup = $('#templatecontent').summernote('code');
100 getDocument(currentEdit, 'save', makrup)
102 let tdelete = function (docname) {
103 let delok = confirm(<?php echo xlj('You are about to delete template'); ?> +": " + docname + "\n" + <?php echo xlj('Is this Okay?'); ?>);
104 if (delok === true) {
105 getDocument(docname, 'delete', '')
107 return false;
110 function getDocument(docname, mode, content) {
111 let liburl = 'import_template.php';
112 $.ajax({
113 type: "POST",
114 url: liburl,
115 data: {docid: docname, mode: mode, content: content},
116 beforeSend: function (xhr) {
117 console.log("Please wait..." + content);
119 error: function (qXHR, textStatus, errorThrow) {
120 console.log("There was an error");
121 alert(<?php echo xlj("File Error") ?> +"\n" + docname)
123 success: function (templateHtml, textStatus, jqXHR) {
124 if (mode == 'get') {
125 let editHtml = '<div class="edittpl" id="templatecontent"></div>';
126 dlgopen('', 'popeditor', 'modal-full', 850, '', '', {
127 buttons: [
128 {text: <?php echo xlj('Save'); ?>, close: false, style: 'success btn-sm', click: tsave},
129 {text: <?php echo xlj('Dismiss'); ?>, style: 'danger btn-sm', close: true}
131 allowDrag: false,
132 allowResize: true,
133 sizeHeight: 'full',
134 onClosed: 'reload',
135 html: editHtml,
136 type: 'alert'
138 $('#templatecontent').summernote('destroy');
139 $('#templatecontent').empty().append(templateHtml);
140 $('#templatecontent').summernote({
141 focus: true,
142 placeholder: '',
143 toolbar: [
144 ['style', ['bold', 'italic', 'underline', 'clear']],
145 ['fontsize', ['fontsize']],
146 ['color', ['color']],
147 ['para', ['ul', 'ol', 'paragraph']],
148 ['insert', ['link', 'picture', 'video', 'hr']],
149 ['view', ['fullscreen', 'codeview']],
150 ['insert', ['nugget']],
151 ['edit', ['undo', 'redo']]
153 nugget: {
154 list: [
155 '{ParseAsHTML}', '{TextInput}', '{sizedTextInput:120px}', '{smTextInput}', '{TextBox:03x080}', '{DatePicker}', '{CheckMark}', '{ynRadioGroup}', '{TrueFalseRadioGroup}', '{DateTimePicker}', '{StandardDatePicker}', '{DOS}', '{ReferringDOC}', '{PatientID}', '{PatientName}', '{PatientSex}', '{PatientDOB}', '{PatientPhone}', '{Address}', '{City}', '{State}', '{Zip}', '{PatientSignature}', '{AdminSignature}', '{Medications}', '{ProblemList}', '{Allergies}', '{ChiefComplaint}', '{EncounterForm:LBF}', '{DEM: }', '{HIS: }', '{LBF: }', '{GRP}{/GRP}'
157 label: 'Directives',
158 tooltip: 'Select Directive to insert at current cursor position.'
160 options: {}
162 } else if (mode === 'save') {
163 $('#templatecontent').summernote('destroy');
164 location.reload();
165 } else if (mode === 'delete') {
166 location.reload();
171 </script>
172 <style>
173 .modal.modal-wide .modal-dialog {
174 width: 55%;
177 .modal-wide .modal-body {
178 overflow-y: auto;
180 </style>
181 <body class="body-top">
182 <div class='container'>
183 <h3><?php echo xlt('Patient Document Template Maintenance'); ?></h3>
184 <hr />
185 <div class="jumbotron jumbotron-fluid p-1 text-center">
187 <?php echo xlt('Select a text or html template and upload for selected patient or all portal patients.'); ?><br /><?php echo xlt('Files base name becomes a pending document selection in Portal Documents.'); ?><br />
188 <em><?php echo xlt('For example: Privacy_Agreement.txt becomes Privacy Agreement button in Patient Documents.'); ?></em>
189 </p>
190 </div>
191 <form id="form_upload" class="form-inline" action="import_template.php" method="post" enctype="multipart/form-data">
192 <div class="form-group">
193 <div class="btn-group">
194 <input class="btn btn-outline-info" type="file" name="tplFile">
195 <button class="btn btn-outline-primary" type="submit" name="upload_submit" id="upload_submit"><?php echo xlt('Uploading For'); ?> <label id='ptstatus'></label></button>
196 </div>
197 <button class="btn btn-success ml-2" type="button" onclick="location.href='./patient/provider'"><?php echo xlt('Dashboard'); ?></button>
198 </div>
199 <input type='hidden' name="up_dir" value='<?php global $patient_dir;
200 echo $patient_dir; ?>' />
201 <input type='hidden' name="doc_category" value='<?php global $cat_dir;
202 echo $cat_dir; ?>' />
203 </form>
204 <hr>
205 <div class='row'>
206 <h4><?php echo xlt('Active Templates'); ?></h4>
207 <div class='col col-md col-lg'>
208 <form id="edit_form" name="edit_form" class="form-inline mb-2" action="" method="post">
209 <div class="form-group">
210 <label class="label mx-1" for="doc_category"><?php echo xlt('Category'); ?></label>
211 <select class="form-control" id="doc_category" name="doc_category">
212 <option value=""><?php echo xlt('General'); ?></option>
213 <?php
214 foreach ($category_list as $dir) {
215 if ($cat_dir == $dir['option_id']) {
216 echo "<option value='" . text($dir['option_id']) . "' selected>" . text($dir['title']) . "</option>\n";
217 } else {
218 echo "<option value='" . text($dir['option_id']) . "'>" . text($dir['title']) . "</option>\n";
222 </select>
223 <label class="label mx-1" for="sel_pt"><?php echo xlt('Patient'); ?></label>
224 <select class="form-control" id="sel_pt" name="sel_pt">
225 <option value='0'><?php echo xlt("All Patients") ?></option>
226 <?PHP
227 $ppt = getAuthUsers();
228 global $patient_dir;
229 foreach ($ppt as $pt) {
230 if ($patient_dir != $pt['pid'] . "_tpls") {
231 echo "<option value=" . attr($pt['pid']) . ">" . text($pt['ptname']) . "</option>";
232 } else {
233 echo "<option value='" . attr($pt['pid']) . "' selected='selected'>" . text($pt['ptname']) . "</option>";
237 </select>
238 </div>
239 <button type="submit" class="btn btn-secondary"><?php echo xlt('Refresh'); ?></button>
240 </form>
241 </div>
242 <?php
243 $dir_list = [];
244 $show_cat_flag = false;
245 if (!empty($cat_dir)) {
246 $dir_list['general'] = getTemplateList($tdir);
247 } else {
248 $dir_list['general'] = getTemplateList($tdir);
249 foreach ($category_list as $cat) {
250 if (!empty($cat_dir) && $cat_dir != $cat['option_id']) {
251 continue;
253 if ($cat_dir_iter = getTemplateList(($tdir . $cat['option_id']), $cat['option_id'])) {
254 $dir_list[$cat['title']] = $cat_dir_iter;
258 echo "<table class='table table-sm table-striped table-bordered'>\n";
259 echo "<thead>\n";
260 echo "<tr>\n" .
261 "<th>" . xlt("Template") . " - <i>" . xlt("Click to edit") . "</i></th>" .
262 "<th>" . xlt("Category") . "</th><th>" . xlt("Location") . "</th><th>" . xlt("Size") . "</th><th>" . xlt("Last Modified") . "</th>" .
263 "</tr>\n";
264 echo "</thead>\n";
265 echo "<tbody>\n";
266 foreach ($dir_list as $cat => $files) {
267 foreach ($files as $file) {
268 $t = $file['pathname'];
269 echo "<tr><td>";
270 echo '<button id="tedit' . attr($t) .
271 '" class="btn btn-sm btn-outline-primary" onclick="tedit(' . attr_js($t) . ')" type="button">' . text($file['name']) . '</button>' .
272 '<button id="tdelete' . attr($t) .
273 '" class="btn btn-sm btn-outline-danger" onclick="tdelete(' . attr_js($t) . ')" type="button">' . xlt("Delete") . '</button>';
274 echo "</td><td>" . text(ucwords($cat)) . "</td>";
275 echo "<td>" . text($file['location']) . "</td>";
276 echo "<td>" . text($file['size']) . "</td>";
277 echo "<td>" . text(date('r', $file['lastmod'])) . "</td>";
278 echo "</tr>";
281 echo "</tbody>";
282 echo "</table>";
284 </div>
285 </div>
286 <script>
287 $(function () {
288 $("#sel_pt").change(function () {
289 if (checkCategory()) {
290 $("#edit_form").submit();
294 $("#doc_category").change(function () {
295 if (checkCategory()) {
296 $("#edit_form").submit();
300 $("#ptstatus").text($("#sel_pt").find(":selected").text());
301 $("#ptstatus").append(' ' + xl("to Category") + ' ');
302 $("#ptstatus").append($("#doc_category").find(":selected").text());
304 function checkCategory() {
305 let cat = $("#doc_category").val();
306 let patient = $("#sel_pt").val();
307 if (patient !== "0" && cat !== "") {
308 alert(xl("Alert! Can only use the General category with patients."));
309 $("#doc_category").val("");
310 return false;
312 return true;
315 </script>
316 </body>
317 </html>