updates to make oauth2/api compatible with php8 (#4069)
[openemr.git] / portal / import_template_ui.php
blob6cabe68358d56313dd1bac3f1b429b90843f6224
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-2020 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 $getdir = isset($_POST['sel_pt']) ? $_POST['sel_pt'] : 0;
20 if ($getdir > 0) {
21 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/' . convert_safe_file_dir_name($getdir) . '/';
22 if (!is_dir($tdir)) {
23 if (!mkdir($tdir, 0755, true) && !is_dir($tdir)) {
24 die(xl('Failed to create folder'));
27 } else {
28 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/';
31 function getAuthUsers()
33 $response = sqlStatement("SELECT patient_data.pid, Concat_Ws(' ', patient_data.fname, patient_data.lname) as ptname FROM patient_data WHERE allow_patient_portal = 'YES'");
34 $resultpd = array();
35 while ($row = sqlFetchArray($response)) {
36 $resultpd[] = $row;
39 return $resultpd;
42 function getTemplateList($dir)
44 $retval = array();
45 if (substr($dir, -1) !== "/") {
46 $dir .= "/";
49 $d = @dir($dir) or die("File List: Failed opening directory " . text($dir) . " for reading");
50 while (false !== ($entry = $d->read())) {
51 if ($entry[0] === "." || substr($entry, -3) !== 'tpl') {
52 continue;
55 if (is_dir("$dir$entry")) {
56 $retval[] = array(
57 'pathname' => "$dir$entry",
58 'name' => "$entry",
59 'size' => 0,
60 'lastmod' => filemtime("$dir$entry")
62 } elseif (is_readable("$dir$entry")) {
63 $retval[] = array(
64 'pathname' => "$dir$entry",
65 'name' => "$entry",
66 'size' => filesize("$dir$entry"),
67 'lastmod' => filemtime("$dir$entry")
72 $d->close();
73 return $retval;
77 <!DOCTYPE html>
78 <html>
79 <head>
80 <meta charset="UTF-8">
81 <title><?php echo xlt('Portal'); ?> | <?php echo xlt('Templates'); ?></title>
82 <meta name="description" content="Developed By sjpadgett@gmail.com">
83 <?php Header::setupHeader(['no_main-theme', 'datetime-picker', 'summernote', 'summernote-ext-nugget', 'patientportal-style']); ?>
85 </head>
86 <script>
87 let currentEdit = "";
88 let tedit = function (docname) {
89 currentEdit = docname;
90 getDocument(docname, 'get', '');
91 return false;
94 let tsave = function () {
95 let makrup = $('#templatecontent').summernote('code');
96 getDocument(currentEdit, 'save', makrup)
98 let tdelete = function (docname) {
99 let delok = confirm(<?php echo xlj('You are about to delete template'); ?> +": " + docname + "\n" + <?php echo xlj('Is this Okay?'); ?>);
100 if (delok === true) {
101 getDocument(docname, 'delete', '')
103 return false;
106 function getDocument(docname, mode, content) {
107 let liburl = 'import_template.php';
108 $.ajax({
109 type: "POST",
110 url: liburl,
111 data: {docid: docname, mode: mode, content: content},
112 beforeSend: function (xhr) {
113 console.log("Please wait..." + content);
115 error: function (qXHR, textStatus, errorThrow) {
116 console.log("There was an error");
117 alert(<?php echo xlj("File Error") ?> +"\n" + docname)
119 success: function (templateHtml, textStatus, jqXHR) {
120 if (mode == 'get') {
121 let editHtml = '<div class="edittpl" id="templatecontent"></div>';
122 dlgopen('','popeditor','modal-full', 850,'', '', {
123 buttons: [
124 {text: <?php echo xlj('Save'); ?>, close: false, style: 'success btn-sm', click: tsave},
125 {text: <?php echo xlj('Dismiss'); ?>, style: 'danger btn-sm', close: true}
127 allowDrag: false,
128 allowResize: true,
129 sizeHeight: 'full',
130 onClosed: 'reload',
131 html: editHtml,
132 type: 'alert'
134 $('#templatecontent').summernote('destroy');
135 $('#templatecontent').empty().append(templateHtml);
136 $('#templatecontent').summernote({
137 focus: true,
138 placeholder: '',
139 toolbar: [
140 ['style', ['bold', 'italic', 'underline', 'clear']],
141 ['fontsize', ['fontsize']],
142 ['color', ['color']],
143 ['para', ['ul', 'ol', 'paragraph']],
144 ['insert', ['link', 'picture', 'video', 'hr']],
145 ['view', ['fullscreen', 'codeview']],
146 ['insert', ['nugget']],
147 ['edit', ['undo', 'redo']]
149 nugget: {
150 list: [
151 '{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}'
153 label: 'Directives',
154 tooltip: 'Select Directive to insert at current cursor position.'
156 options: {}
158 } else if (mode === 'save') {
159 $('#templatecontent').summernote('destroy');
160 location.reload();
161 } else if (mode === 'delete') {
162 location.reload();
167 </script>
168 <style>
169 .modal.modal-wide .modal-dialog {
170 width: 55%;
173 .modal-wide .modal-body {
174 overflow-y: auto;
176 </style>
177 <body class="body-top">
178 <div class='container'>
179 <h3><?php echo xlt('Patient Document Template Maintenance'); ?></h3>
180 <hr />
181 <div class="jumbotron jumbotron-fluid p-1 text-center">
183 <?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 />
184 <em><?php echo xlt('For example: Privacy_Agreement.txt becomes Privacy Agreement button in Patient Documents.'); ?></em>
185 </p>
186 </div>
187 <form id="form_upload" class="form" action="import_template.php" method="post" enctype="multipart/form-data">
188 <div class="btn-group my-2">
189 <input class="btn btn-outline-info" type="file" name="tplFile">
190 <button class="btn btn-outline-primary" type="submit" name="upload_submit" id="upload_submit"><?php echo xlt('Upload For'); ?> <span class="badge badge-warning" id='ptstatus'></span></button>
191 <button class="btn btn-success" type="button" onclick="location.href='./patient/provider'"><?php echo xlt('Dashboard'); ?></button>
192 </div>
193 <input type='hidden' name="up_dir" value='<?php global $getdir;
194 echo $getdir; ?>' />
195 </form>
196 <hr>
197 <div class='row'>
198 <h4><?php echo xlt('Active Templates'); ?></h4>
199 <div class='col col-md col-lg'>
200 <form id="edit_form" name="edit_form" class="form-inline" action="" method="post">
201 <div class="form-group">
202 <label for="sel_pt"><?php echo xlt('Patient'); ?></label>
203 <select class="form-control" id="sel_pt" name="sel_pt">
204 <option value='0'><?php echo xlt("Global All Patients") ?></option>
205 <?PHP
206 $ppt = getAuthUsers();
207 global $getdir;
208 foreach ($ppt as $pt) {
209 if ($getdir != $pt['pid']) {
210 echo "<option value=" . attr($pt['pid']) . ">" . text($pt['ptname']) . "</option>";
211 } else {
212 echo "<option value='" . attr($pt['pid']) . "' selected='selected'>" . text($pt['ptname']) . "</option>";
216 </select></div>
217 <button type="submit" class="btn btn-secondary"><?php echo xlt('Refresh'); ?></button>
218 </form>
219 </div>
220 <?php
221 $dirlist = getTemplateList($tdir);
222 echo "<table class='table table-responsive-sm table-striped table-bordered'>";
223 echo "<thead>";
224 echo "<tr><th>" . xlt("Template") . " - <i>" . xlt("Click to edit") . "</i></th><th>" . xlt("Size") . "</th><th>" . xlt("Last Modified") . "</th></tr>";
225 echo "</thead>";
226 echo "<tbody>";
227 foreach ($dirlist as $file) {
228 $t = $file['pathname'];
229 echo "<tr><td>";
230 echo '<button id="tedit' . attr($t) .
231 '" class="btn btn-sm btn-outline-primary" onclick="tedit(' . attr_js($t) . ')" type="button">' . text($file['name']) . '</button>' .
232 '<button id="tdelete' . attr($t) .
233 '" class="btn btn-sm btn-outline-danger" onclick="tdelete(' . attr_js($t) . ')" type="button">' . xlt("Delete") . '</button>';
234 echo "</td><td>" . text($file['size']) . "</td>";
235 echo "<td>" . text(date('r', $file['lastmod'])) . "</td>";
236 echo "</tr>";
239 echo "</tbody>";
240 echo "</table>";
242 <script>
243 $(function () {
244 $("#sel_pt").change(function () {
245 $("#edit_form").submit();
247 $("#ptstatus").text($("#sel_pt").find(":selected").text())
249 </script>
250 </div>
251 </div>
252 </body>
253 </html>