Merge pull request #2003 from sjpadgett/bug-fix
[openemr.git] / portal / import_template_ui.php
blobdd3715b562cf67a31cf3d3614dc4d7d746fed244
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}','{PatientName}', '{PatientSex}', '{PatientDOB}', '{PatientPhone}', '{PatientSignature}', '{Address}', '{City}', '{State}', '{Zip}', '{AdminSignature}', '{Medications}', '{ProblemList}', '{Allergies}', '{ChiefComplaint}'
155 label: 'Tags / Directives',
156 tooltip: 'Insert at current cursor location.'
158 options: {
159 'label': 'Tags/Directives',
160 'tooltip': 'Insert Tag or Directive'
164 else if (mode == 'save') {
165 $('#templatecontent').summernote('destroy');
166 location.reload();
168 else if (mode == 'delete') {
169 location.reload();
174 </script>
175 <style>
176 .modal.modal-wide .modal-dialog {
177 width: 55%;
179 .modal-wide .modal-body {
180 overflow-y: auto;
182 </style>
183 <body class="skin-blue">
184 <div class='container' style='display: block;'>
185 <hr>
186 <h3><?php echo xlt('Patient Document Template Upload'); ?></h3>
187 <h4><em><?php echo xlt('File base name becomes Menu selection'); ?>.<br><?php echo xlt('Automatically applies correct extension on successful upload'); ?>.<br>
188 <?php echo xlt('Example Privacy_Agreement.txt becomes Privacy Agreement button in Patient Documents'); ?>.</em></h4>
189 <form id="form_upload" class="form" action="import_template.php" method="post" enctype="multipart/form-data">
190 <input class="btn btn-info" type="file" name="tplFile">
191 <br>
192 <button class="btn btn-primary" type="button" onclick="location.href='./patient/provider'"><?php echo xlt('Home'); ?></button>
193 <input type='hidden' name="up_dir" value='<?php global $getdir;
194 echo $getdir;?>' />
195 <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>
196 </form>
197 <div class='row'>
198 <h3><?php echo xlt('Active Templates'); ?></h3>
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 echo "</select></div>";
217 echo '<button type="submit" class="btn btn-default">' . xlt('Refresh') . '</button>';
218 echo '</form></div>';
219 $dirlist = getTemplateList($tdir);
220 echo "<table class='table table-striped table-bordered'>";
221 echo "<thead>";
222 echo "<tr><th>" . xlt("Template") . " - <i>" . xlt("Click to edit") . "</i></th><th>" . xlt("Size") . "</th><th>" . xlt("Last Modified") . "</th></tr>";
223 echo "</thead>";
224 echo "<tbody>";
225 foreach ($dirlist as $file) {
226 $t = "'" . $file['pathname'] . "'";
227 echo "<tr>";
228 echo '<td><button id="tedit' . attr($t) . '" class="btn btn-sm btn-primary" onclick="tedit(' . attr($t) . ')" type="button">' . text($file['name']) . '</button>
229 <button id="tdelete' . attr($t) . '" class="btn btn-xs btn-danger" onclick="tdelete(' . attr($t) . ')" type="button">' . xlt("Delete") . '</button></td>';
230 echo "<td>{$file['size']}</td>";
231 echo "<td>", date('r', $file['lastmod']), "</td>";
232 echo "</tr>";
235 echo "</tbody>";
236 echo "</table>";
238 <script>
239 $(document).ready(function(){
240 $("#popeditor").on("show.bs.modal", function() {
241 var height = $(window).height() - 200;
242 $(this).find(".modal-body").css("max-height", height);
244 $("#sel_pt").change(function(){
245 $("#edit_form").submit();
247 $("#ptstatus").text($("#sel_pt").find(":selected").text())
249 </script>
250 </div>
251 <div class="modal modal-wide fade" id="popeditor">
252 <div class="modal-dialog modal-lg">
253 <div class="modal-content">
254 <div class="modal-header">
255 <button type="button" class="close" data-dismiss="modal">
256 <span aria-hidden="true">&times;</span>
257 <span class="sr-only"><?php echo xlt('Close'); ?></span>
258 </button>
259 <h4 class="modal-title"><?php echo xlt('Edit Template'); ?></h4>
260 </div>
261 <div class="modal-body">
262 <div class="edittpl" id="templatecontent"></div>
263 </div>
264 <div class="modal-footer">
265 <button type="button" class="btn btn-danger btn-xs" data-dismiss="modal"><?php echo xlt('Dismiss'); ?></button>
266 <button type="button" class="btn btn-success btn-xs" data-dismiss="modal" onclick="tsave()"><?php echo xlt('Save'); ?></button>
267 </div>
268 </div>
269 </div>
270 </div>
271 </body>
272 </html>