Fix for U2F on HTTP server that is behind a HTTPS proxy.
[openemr.git] / portal / import_template_ui.php
blobce9e1b2ee2abaa0c36d27903d65d5518d4e46e10
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
24 require_once("../interface/globals.php");
25 $getdir = isset($_POST['sel_pt']) ? $_POST['sel_pt'] : 0;
26 if ($getdir > 0) {
27 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/' . convert_safe_file_dir_name($getdir) . '/';
28 if (!is_dir($tdir)) {
29 if (!mkdir($tdir, 0755, true)) {
30 die(xl('Failed to create folder'));
33 } else {
34 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/';
37 function getAuthUsers()
39 $response = sqlStatement("SELECT patient_data.pid, Concat_Ws(' ', patient_data.fname, patient_data.lname) as ptname FROM patient_data WHERE allow_patient_portal = 'YES'");
40 $resultpd = array ();
41 while ($row = sqlFetchArray($response)) {
42 $resultpd[] = $row;
45 return $resultpd;
47 function getTemplateList($dir)
49 $retval = array();
50 if (substr($dir, -1) != "/") {
51 $dir .= "/";
54 $d = @dir($dir) or die("File List: Failed opening directory " . text($dir) . " for reading");
55 while (false !== ($entry = $d->read())) {
56 if ($entry[0] == "." || substr($entry, -3) != 'tpl') {
57 continue;
60 if (is_dir("$dir$entry")) {
61 $retval[] = array(
62 'pathname' => "$dir$entry",
63 'name' => "$entry",
64 'size' => 0,
65 'lastmod' => filemtime("$dir$entry")
67 } elseif (is_readable("$dir$entry")) {
68 $retval[] = array(
69 'pathname' => "$dir$entry",
70 'name' => "$entry",
71 'size' => filesize("$dir$entry"),
72 'lastmod' => filemtime("$dir$entry")
77 $d->close();
78 return $retval;
81 <html>
82 <head>
83 <meta charset="UTF-8">
84 <title><?php echo xlt('OpenEMR Portal'); ?> | <?php echo xlt('Import'); ?></title>
85 <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
86 <meta name="description" content="Developed By sjpadgett@gmail.com">
88 <link href="<?php echo $GLOBALS['assets_static_relative']; ?>/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
89 <link href="<?php echo $GLOBALS['assets_static_relative']; ?>/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
90 <?php if ($_SESSION['language_direction'] == 'rtl') { ?>
91 <link href="<?php echo $GLOBALS['assets_static_relative']; ?>/bootstrap-rtl/dist/css/bootstrap-rtl.min.css" rel="stylesheet" type="text/css" />
92 <?php } ?>
93 <link href="assets/css/style.css?v=<?php echo $v_js_includes; ?>" rel="stylesheet" type="text/css" />
94 <script src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-1-11-3/dist/jquery.js" type="text/javascript"></script>
95 <script src="<?php echo $GLOBALS['assets_static_relative']; ?>/bootstrap/dist/js/bootstrap.min.js" type="text/javascript"></script>
96 <link href="<?php echo $GLOBALS['assets_static_relative']; ?>/summernote/dist/summernote.css" rel="stylesheet" type="text/css" />
97 <script type='text/javascript' src="<?php echo $GLOBALS['assets_static_relative']; ?>/summernote/dist/summernote.js"></script>
98 <script type='text/javascript' src="<?php echo $GLOBALS['assets_static_relative']; ?>/summernote-nugget/plugins/nugget/summernote-ext-nugget.js"></script>
99 </head>
100 <script>
101 var currentEdit = "";
102 var tedit = function(docname) {
103 currentEdit = docname;
104 getDocument(docname, 'get', '')
105 return false;
108 var tsave = function() {
109 var makrup = $('#templatecontent').summernote('code');
110 getDocument(currentEdit, 'save', makrup)
112 var tdelete = function(docname) {
113 var delok = confirm("<?php echo xls('You are about to delete template'); ?>: "+docname+"\n<?php echo xls('Is this Okay?'); ?>");
114 if(delok === true) {getDocument(docname, 'delete', '')}
115 return false;
118 function getDocument(docname, mode, content) {
119 var liburl = 'import_template.php';
120 $.ajax({
121 type: "POST",
122 url: liburl,
123 data: {docid: docname, mode: mode, content: content},
124 beforeSend: function (xhr) {
125 console.log("Please wait..." + content);
127 error: function (qXHR, textStatus, errorThrow) {
128 console.log("There was an error");
129 alert('<?php echo xlt("File Error") ?>' + "\n" + docname)
131 success: function (templateHtml, textStatus, jqXHR) {
132 if (mode == 'get') {
133 //console.log("File get..."+templateHtml);
134 $('#templatecontent').summernote('destroy');
135 $('#templatecontent').empty().append(templateHtml);
136 $('#popeditor').modal({backdrop: "static"});
137 $('#templatecontent').summernote({
138 // height: 200,
139 focus: true,
140 placeholder: '',
141 toolbar: [
142 ['style', ['bold', 'italic', 'underline', 'clear']],
143 ['fontsize', ['fontsize']],
144 ['color', ['color']],
145 ['para', ['ul', 'ol', 'paragraph']],
146 ['insert', ['link', 'picture', 'video', 'hr']],
147 ['view', ['fullscreen', 'codeview']],
148 ['insert', ['nugget']],
149 ['edit', ['undo', 'redo']]
151 nugget: {
152 list: [
153 '{ParseAsHTML}{TextInput}', '{smTextInput}', '{CheckMark}', '{ynRadioGroup}', '{DOS}', '{ReferringDOC}', '{PatientID}',
154 '{PatientName}', '{PatientSex}', '{PatientDOB}', '{PatientPhone}', '{PatientSignature}', '{Address}', '{City}', '{State}', '{Zip}',
155 '{AdminSignature}', '{Medications}', '{ProblemList}', '{Allergies}', '{ChiefComplaint}'
157 label: 'Tags / Directives',
158 tooltip: 'Insert at current cursor location.'
160 options: {
161 'label': 'Tags/Directives',
162 'tooltip': 'Insert Tag or Directive'
166 else if (mode == 'save') {
167 $('#templatecontent').summernote('destroy');
168 location.reload();
170 else if (mode == 'delete') {
171 location.reload();
176 </script>
177 <style>
178 .modal.modal-wide .modal-dialog {
179 width: 55%;
181 .modal-wide .modal-body {
182 overflow-y: auto;
184 </style>
185 <body class="skin-blue">
186 <div class='container' style='display: block;'>
187 <hr>
188 <h3><?php echo xlt('Patient Document Template Upload'); ?></h3>
189 <h4><em><?php echo xlt('File base name becomes Menu selection'); ?>.<br><?php echo xlt('Automatically applies correct extension on successful upload'); ?>.<br>
190 <?php echo xlt('Example Privacy_Agreement.txt becomes Privacy Agreement button in Patient Documents'); ?>.</em></h4>
191 <form id="form_upload" class="form" action="import_template.php" method="post" enctype="multipart/form-data">
192 <input class="btn btn-info" type="file" name="tplFile">
193 <br>
194 <button class="btn btn-primary" type="button" onclick="location.href='./patient/provider'"><?php echo xlt('Home'); ?></button>
195 <input type='hidden' name="up_dir" value='<?php global $getdir;
196 echo $getdir;?>' />
197 <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>
198 </form>
199 <div class='row'>
200 <h3><?php echo xlt('Active Templates'); ?></h3>
201 <div class='col col-md col-lg'>
202 <form id = "edit_form" name = "edit_form" class="form-inline" action="" method="post">
203 <div class="form-group">
204 <label for="sel_pt"><?php echo xlt('Patient'); ?></label>
205 <select class="form-control" id="sel_pt" name="sel_pt">
206 <option value='0'><?php echo xlt("Global All Patients")?></option>
207 <?PHP
208 $ppt = getAuthUsers();
209 global $getdir;
210 foreach ($ppt as $pt) {
211 if ($getdir != $pt['pid']) {
212 echo "<option value=" . attr($pt['pid']) . ">" . text($pt['ptname']) . "</option>";
213 } else {
214 echo "<option value='" . attr($pt['pid']) . "' selected='selected'>" . text($pt['ptname']) . "</option>";
218 echo "</select></div>";
219 echo '<button type="submit" class="btn btn-default">' . xlt('Refresh') . '</button>';
220 echo '</form></div>';
221 $dirlist = getTemplateList($tdir);
222 echo "<table class='table 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>";
230 echo '<td><button id="tedit' . attr($t) . '" class="btn btn-sm btn-primary" onclick="tedit(' . attr($t) . ')" type="button">' . text($file['name']) . '</button>
231 <button id="tdelete' . attr($t) . '" class="btn btn-xs btn-danger" onclick="tdelete(' . attr($t) . ')" type="button">' . xlt("Delete") . '</button></td>';
232 echo "<td>{$file['size']}</td>";
233 echo "<td>", date('r', $file['lastmod']), "</td>";
234 echo "</tr>";
237 echo "</tbody>";
238 echo "</table>";
240 <script>
241 $(document).ready(function(){
242 $("#popeditor").on("show.bs.modal", function() {
243 var height = $(window).height() - 200;
244 $(this).find(".modal-body").css("max-height", height);
246 $("#sel_pt").change(function(){
247 $("#edit_form").submit();
249 $("#ptstatus").text($("#sel_pt").find(":selected").text())
251 </script>
252 </div>
253 <div class="modal modal-wide fade" id="popeditor">
254 <div class="modal-dialog modal-lg">
255 <div class="modal-content">
256 <div class="modal-header">
257 <button type="button" class="close" data-dismiss="modal">
258 <span aria-hidden="true">&times;</span>
259 <span class="sr-only"><?php echo xlt('Close'); ?></span>
260 </button>
261 <h4 class="modal-title"><?php echo xlt('Edit Template'); ?></h4>
262 </div>
263 <div class="modal-body">
264 <div class="edittpl" id="templatecontent"></div>
265 </div>
266 <div class="modal-footer">
267 <button type="button" class="btn btn-danger btn-xs" data-dismiss="modal"><?php echo xlt('Dismiss'); ?></button>
268 <button type="button" class="btn btn-success btn-xs" data-dismiss="modal" onclick="tsave()"><?php echo xlt('Save'); ?></button>
269 </div>
270 </div>
271 </div>
272 </div>
273 </body>
274 </html>