quick minor path updates (#1968)
[openemr.git] / library / custom_template / personalize.php
blobecdf837726fc3c63cd1d0f79330a2685292f418e
1 <?php
2 /**
3 * personalize.php
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Eldho Chacko <eldho@zhservices.com>
8 * @author Jacob T Paul <jacob@zhservices.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2011 Z&H Consultancy Services Private Limited <sam@zhservices.com>
11 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once("../../interface/globals.php");
17 $list_id = $_REQUEST['list_id'] ? $_REQUEST['list_id'] : $_REQUEST['filter_context'];
19 use OpenEMR\Core\Header;
21 function Delete_Rows($id)
23 sqlStatement("DELETE FROM template_users WHERE tu_template_id=? AND tu_user_id=?", array($id, $_SESSION['authId']));
26 function Insert_Rows($id, $order = "")
28 sqlStatement("REPLACE INTO template_users (tu_template_id,tu_user_id,tu_template_order) VALUES (?,?,?)", array($id, $_SESSION['authId'], $order));
31 if (isset($_REQUEST['submitform']) && $_REQUEST['submitform'] == 'save') {
32 $topersonalized = $_REQUEST['topersonalized'];
33 $personalized = $_REQUEST['personalized'];
34 foreach ($topersonalized as $key => $value) {
35 $arr = explode("|", $value);
36 $res = sqlStatement("SELECT * FROM template_users WHERE tu_template_id=? AND tu_user_id=?", array($arr[0], $_SESSION['authId']));
37 if (sqlNumRows($res)) {
38 Delete_Rows($arr[0]);
39 $qry = sqlStatement("SELECT * FROM customlists WHERE cl_list_id=? AND cl_deleted=0", array($arr[0]));
40 while ($row = sqlFetchArray($qry)) {
41 Delete_Rows($row['cl_list_slno']);
46 //Add new Categories
47 foreach ($personalized as $key => $value) {
48 $arr = explode("|", $value);
49 if ($arr[1]) {
50 $res = sqlStatement("SELECT * FROM template_users WHERE tu_template_id=? AND tu_user_id=?", array($arr[0], $_SESSION['authId']));
51 Insert_Rows($arr[0]);
52 $qry = sqlStatement("SELECT * FROM customlists WHERE cl_list_id=? AND cl_deleted=0", array($arr[0]));
53 while ($row = sqlFetchArray($qry)) {
54 $qryTU = sqlStatement("SELECT * FROM template_users WHERE tu_template_id=? AND tu_user_id=?", array($row['cl_list_slno'], $arr[1]));
55 while ($rowTU = sqlFetchArray($qryTU)) {
56 Insert_Rows($rowTU['tu_template_id'], $rowTU['tu_template_order']);
59 } else {
60 Insert_Rows($arr[0]);
61 $qry = sqlStatement("SELECT * FROM customlists WHERE cl_list_id=? AND cl_deleted=0", array($arr[0]));
62 while ($row = sqlFetchArray($qry)) {
63 Insert_Rows($row['cl_list_slno'], $row['cl_order']);
69 <html>
70 <head>
72 <?php Header::setupHeader(['common', 'opener', 'jquery-ui',]); ?>
74 <script type="text/javascript">
76 function refreshme() {
77 top.restoreSession();
78 document.location.reload();
81 $(document).ready(function () {
83 tabbify();
85 $(".iframe_small").on('click', function (e) {
86 e.preventDefault();
87 e.stopPropagation();
88 dlgopen('', '', 400, 170, '', '', {
89 buttons: [
90 {text: '<?php echo xla('Close'); ?>', close: true, style: 'default btn-sm'}
92 onClosed: 'refreshme',
93 type: 'iframe',
94 url: $(this).attr('href')
95 });
96 });
98 $(".iframe_medium").on('click', function (e) {
99 e.preventDefault();
100 e.stopPropagation();
101 dlgopen('', '', 450, 250, '', '', {
102 buttons: [
103 {text: '<?php echo xla('Close'); ?>', close: true, style: 'default btn-sm'}
105 onClosed: 'refreshme',
106 type: 'iframe',
107 url: $(this).attr('href')
111 $(".iframe_abvmedium").on('click', function (e) {
112 e.preventDefault();
113 e.stopPropagation();
114 dlgopen('', '', 700, 500, '', '', {
115 buttons: [
116 {text: '<?php echo xla('Close'); ?>', close: true, style: 'default btn-sm'}
118 onClosed: 'refreshme',
119 type: 'iframe',
120 url: $(this).attr('href')
126 function check_user_category(form, selectFrom, selectedList) {
127 top.restoreSession();
128 var total_selected = form.elements[selectedList].length - 1;
129 var msg = '';
130 for (total_selected; total_selected >= 0; total_selected--) {
131 if (form.elements[selectedList].options[total_selected].selected) {
132 if (document.getElementById('filter_users').value) {
133 $.ajax({
134 type: "POST",
135 url: "ajax_code.php",
136 dataType: "html",
137 data: {
138 item: form.elements[selectedList].options[total_selected].value,
139 list_id: document.getElementById('filter_users').value,
140 source: "check_item"
142 async: false,
143 success: function (thedata) {
144 if (thedata == 'OK') {
145 total_clients = form.elements[selectFrom].length;
146 opt = new Option(form.elements[selectedList].options[total_selected].text, form.elements[selectedList].options[total_selected].value);
147 form.elements[selectFrom].options[total_clients] = opt;
148 form.elements[selectedList].options[total_selected] = null;
150 else {
151 msg += form.elements[selectedList].options[total_selected].text + "\n";
154 error: function () {
155 alert("fail");
159 else {
160 total_clients = form.elements[selectFrom].length;
161 opt = new Option(form.elements[selectedList].options[total_selected].text, form.elements[selectedList].options[total_selected].value);
162 form.elements[selectFrom].options[total_clients] = opt;
163 form.elements[selectedList].options[total_selected] = null;
167 jsub_sortNow(form.elements[selectFrom]);
168 if (msg != '') {
169 if (confirm("<?php echo addslashes(xl('The following categories will be removed from your category List'));?> \n" + msg + "\n <?php echo addslashes(xl('Do you want to continue?'));?>")) {
170 remove_selected(form, selectedList);
173 return;
176 function remove_selected(form, selectedList) {
177 top.restoreSession();
178 var total_selected = form.elements[selectedList].length - 1;
179 for (total_selected; total_selected >= 0; total_selected--) {
180 if (form.elements[selectedList].options[total_selected].selected) {
181 form.elements[selectedList].options[total_selected] = null;
184 jsub_sortNow(form.elements[selectFrom]);
185 return;
188 function all_selected(selectedList) {
189 top.restoreSession();
190 var total_selected = document.getElementById(selectedList).length - 1;
191 for (total_selected; total_selected >= 0; total_selected--) {
192 document.getElementById(selectedList).options[total_selected].selected = true;
196 function all_deselected(selectedList) {
197 top.restoreSession();
198 var total_selected = document.getElementById(selectedList).length - 1;
199 for (total_selected; total_selected >= 0; total_selected--) {
200 document.getElementById(selectedList).options[total_selected].selected = false;
204 function jsub_selected(form, selectFrom, selectedList) {
205 top.restoreSession();
206 var total_selected = form.elements[selectedList].length - 1;
207 for (total_selected; total_selected >= 0; total_selected--) {
208 if (form.elements[selectedList].options[total_selected].selected) {
209 total_clients = form.elements[selectFrom].length;
210 opt = new Option(form.elements[selectedList].options[total_selected].text, form.elements[selectedList].options[total_selected].value);
211 form.elements[selectFrom].options[total_clients] = opt;
212 form.elements[selectedList].options[total_selected] = null;
215 jsub_sortNow(form.elements[selectFrom]);
216 return;
219 function display_category_item(form, selectedList) {
220 top.restoreSession();
221 var len = 0;
222 var selectedval = '';
223 var total_selected = form.elements[selectedList].length - 1;
224 for (total_selected; total_selected >= 0; total_selected--) {
225 if (form.elements[selectedList].options[total_selected].selected) {
226 selectedval = form.elements[selectedList].options[total_selected].value;
227 len++;
230 if (len > 1) {
231 document.getElementById('itemdiv').style.display = 'none';
233 else if (len == 1) {
234 document.getElementById('itemdiv').style.display = '';
235 $.ajax({
236 type: "POST",
237 url: "ajax_code.php",
238 dataType: "html",
239 data: {
240 list_id: selectedval,
241 source: "item_show"
243 async: false,
244 success: function (thedata) {
245 document.getElementById('itemdiv').innerHTML = thedata;
247 error: function () {
248 alert("fail");
251 return;
255 function jsub_sortNow(obj) {
256 top.restoreSession();
257 var len = obj.length - 1;
258 var text = new Array();
259 var values = new Array();
260 var sortarr = new Array();
261 for (var i = len; i >= 0; i--) {
262 text[i] = obj.options[i].text;
263 values[i] = obj.options[i].value;
264 sortarr[i] = obj.options[i].text;
266 sortarr.sort();
267 obj.length = 0;
268 for (i = 0; i <= len; i++) {
269 for (j = 0; j <= len; j++) {
270 if (sortarr[i] == text[j]) {
271 break;
274 opt = new Option(text[j], values[j]);
275 obj.options[i] = opt;
279 function personalize_save() {
280 top.restoreSession();
281 document.getElementById('submitform').value = 'save';
282 all_selected('topersonalized');
283 all_selected('personalized');
284 document.myform.submit();
286 </script>
287 </head>
288 <body class="body_top">
289 <form name="myform" method="post" onsubmit="top.restoreSession();">
290 <fieldset>
291 <legend><span class="text"><?php echo htmlspecialchars(xl('Filter'), ENT_QUOTES); ?></span></legend>
292 <table>
293 <tr class="text">
294 <td><?php echo htmlspecialchars(xl('Context'), ENT_QUOTES); ?></td>
295 <td>
296 <select name='filter_context' id='filter_context' onchange='javascript:document.myform.submit();'>
297 <option value=''><?php echo htmlspecialchars(xl('Select a Context'), ENT_QUOTES); ?></option>
298 <?php
299 $context_sql = "SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0";
300 $context_res = sqlStatement($context_sql);
301 while ($context_row = sqlFetchArray($context_res)) {
302 echo "<option value='" . htmlspecialchars($context_row['cl_list_slno'], ENT_QUOTES) . "' ";
303 echo ($_REQUEST['filter_context'] == $context_row['cl_list_slno']) ? 'selected' : '';
304 echo ">" . htmlspecialchars($context_row['cl_list_item_long'], ENT_QUOTES) . "</option>";
307 </select>
308 </td>
309 <td><?php echo htmlspecialchars(xl('Users'), ENT_QUOTES); ?></td>
310 <td>
311 <select name='filter_users' id='filter_users' onchange='javascript:document.myform.submit();'>
312 <option value=''><?php echo htmlspecialchars(xl('Select a User'), ENT_QUOTES); ?></option>
313 <?php
314 $user_sql = "SELECT DISTINCT(tu.tu_user_id),u.fname,u.lname FROM template_users AS tu LEFT OUTER JOIN users AS u ON tu.tu_user_id=u.id WHERE tu.tu_user_id!=?";
315 $user_res = sqlStatement($user_sql, array($_SESSION['authId']));
316 while ($user_row = sqlFetchArray($user_res)) {
317 echo "<option value='" . htmlspecialchars($user_row['tu_user_id'], ENT_QUOTES) . "' ";
318 echo ($_REQUEST['filter_users'] == $user_row['tu_user_id']) ? 'selected' : '';
319 echo ">" . htmlspecialchars($user_row['fname'] . " " . $user_row['lname'], ENT_QUOTES) . "</option>";
322 </select>
323 </td>
324 </tr>
325 </table>
326 </fieldset>
327 <table align="center" width="100%">
328 <tr class="text">
329 <td colspan="3">
330 <a href=# class="css_button"
331 onclick="top.restoreSession();personalize_save()"><span><?php echo htmlspecialchars(xl('Save'), ENT_QUOTES); ?></span></a>
332 <?php
333 if (acl_check('nationnotes', 'nn_configure')) {
335 <a href="delete_category.php" id="share_link" class="iframe_medium css_button"
336 onclick="top.restoreSession();"><span><?php echo htmlspecialchars(xl('Delete Category'), ENT_QUOTES); ?></span></a>
337 <?php
340 <?php
341 if (acl_check('nationnotes', 'nn_configure')) {
343 <a href="add_template.php?list_id=<?php echo attr($_REQUEST['list_id']); ?>"
344 onclick="top.restoreSession();" class="iframe_small css_button"
345 title="<?php echo htmlspecialchars(xl('Add Category'), ENT_QUOTES); ?>"><span><?php echo htmlspecialchars(xl('Add Category'), ENT_QUOTES); ?></span></a>
346 <?php
349 <?php
350 if (acl_check('nationnotes', 'nn_configure')) {
352 <a href="add_context.php" class="iframe_medium css_button" onclick="top.restoreSession();"
353 title="<?php echo htmlspecialchars(xl('Add Context'), ENT_QUOTES); ?>"><span><?php echo htmlspecialchars(xl('Add Context'), ENT_QUOTES); ?></span></a>
354 <?php
357 <tr class="text">
358 <th><?php echo htmlspecialchars(xl('Available categories'), ENT_QUOTES); ?></th>
359 <th>&nbsp;</th>
360 <?php
361 $user = sqlQuery("SELECT * FROM users WHERE id=?", array($_SESSION['authId']));
363 <th><?php echo htmlspecialchars(xl('Categories for') . " " . $user['fname'] . " " . $user['lname'], ENT_QUOTES); ?></th>
364 </tr>
365 <tr class="text">
366 <td align=right>
367 <select multiple name="topersonalized[]" id="topersonalized" size="6" style="width:220px"
368 onchange="display_category_item(document.myform,'topersonalized');">
369 <?php
370 $where = '';
371 $join = '';
372 $arval = array($_SESSION['authId']);
373 $arval1 = array($_REQUEST['filter_users'], $_SESSION['authId']);
374 if ($_REQUEST['filter_context']) {
375 $where .= " AND cl_list_id=?";
376 array_push($arval, $_REQUEST['filter_context']);
377 array_push($arval1, $_REQUEST['filter_context']);
379 $sql = "SELECT * FROM template_users AS tu LEFT OUTER JOIN customlists AS c ON tu.tu_template_id=c.cl_list_slno
380 WHERE cl_list_type=3 AND cl_deleted=0 AND tu.tu_template_id NOT IN (SELECT tu_template_id FROM template_users AS tuser WHERE
381 tu_user_id=?) " .
382 $where .
383 " ORDER BY cl_list_id,tu_user_id,cl_list_item_long";
384 $resTemplates = sqlStatement($sql, $arval);
385 if ($_REQUEST['filter_users']) {
386 $sql = " SELECT * FROM template_users AS tu LEFT OUTER JOIN customlists AS c ON tu.tu_template_id=c.cl_list_slno WHERE
387 tu.tu_user_id=? AND c.cl_list_type=3 AND cl_deleted=0 AND tu.tu_template_id NOT IN
388 (SELECT tu_template_id FROM template_users AS tuser WHERE tu_user_id=?)" .
389 $where .
390 "ORDER BY cl_list_id,tu_user_id,c.cl_list_item_long";
391 $resTemplates = sqlStatement($sql, $arval1);
393 while ($rowTemplates = sqlFetchArray($resTemplates)) {
394 $cntxt = '';
395 if (!$_REQUEST['filter_context']) {
396 $context = sqlQuery("SELECT * FROM customlists WHERE cl_list_slno=?", array($rowTemplates['cl_list_id']));
397 $cntxt .= $context['cl_list_item_long'] . "->";
399 if (!$_REQUEST['filter_users']) {
400 $context = sqlQuery("SELECT * FROM users WHERE id=?", array($rowTemplates['tu_user_id']));
401 $cntxt .= $context['username'] . "->";
403 echo "<option value='" . htmlspecialchars($rowTemplates['cl_list_slno'] . "|" . $rowTemplates['tu_user_id'], ENT_QUOTES) . "'>" . htmlspecialchars($cntxt . $rowTemplates['cl_list_item_long'], ENT_QUOTES) . "</option>";
405 $sqlorphan = "SELECT * FROM customlists WHERE cl_list_type=3 AND cl_deleted=0 AND cl_list_slno " .
406 " NOT IN (SELECT DISTINCT tu_template_id FROM template_users) " .
407 $where .
408 " ORDER BY cl_list_id,cl_list_item_long";
409 $resorphan = sqlStatement($sqlorphan);
410 while ($roworphan = sqlFetchArray($resorphan)) {
411 $cntxt = '';
412 if (!$_REQUEST['filter_context']) {
413 $context = sqlQuery("SELECT * FROM customlists WHERE cl_list_slno=?", array($roworphan['cl_list_id']));
414 $cntxt .= $context['cl_list_item_long'] . "->";
416 echo "<option value='" . htmlspecialchars($roworphan['cl_list_slno'] . "|", ENT_QUOTES) . "'>" . htmlspecialchars($cntxt . $roworphan['cl_list_item_long'], ENT_QUOTES) . "</option>";
419 </select>
420 </td>
421 <td align="center">
422 <input type="button" name="remove" value=&raquo;
423 onclick="jsub_selected(document.myform,'personalized','topersonalized')"></br>
424 <input type="button" name="remove" value=&laquo;
425 onclick="check_user_category(document.myform,'topersonalized','personalized')">
426 </td>
427 <td align=left>
428 <select multiple name="personalized[]" id="personalized" size="6" style="width:220px">
429 <?php
430 $where = '';
431 if ($_REQUEST['filter_context']) {
432 $where .= " AND cl_list_id='" . $_REQUEST['filter_context'] . "'";
434 $sql = "SELECT * FROM template_users AS tu LEFT OUTER JOIN customlists AS c ON tu.tu_template_id=c.cl_list_slno WHERE
435 tu.tu_user_id=? AND c.cl_list_type=3 AND cl_deleted=0 " .
436 $where .
437 "ORDER BY c.cl_list_item_long";
438 $resTemplates = sqlStatement($sql, array($_SESSION['authId']));
439 while ($rowTemplates = sqlFetchArray($resTemplates)) {
440 $cntxt = '';
441 if (!$_REQUEST['filter_context']) {
442 $context = sqlQuery("SELECT * FROM customlists WHERE cl_list_slno=?", array($rowTemplates['cl_list_id']));
443 $cntxt .= $context['cl_list_item_long'] . "->";
445 echo "<option value='" . htmlspecialchars($rowTemplates['cl_list_slno'] . "|" . $rowTemplates['tu_user_id'], ENT_QUOTES) . "'>" . htmlspecialchars($cntxt . $rowTemplates['cl_list_item_long'], ENT_QUOTES) . "</option>";
448 </select>
449 </td>
450 </tr>
451 <tr class="text">
452 <td>&nbsp;</td>
453 <td>&nbsp;</td>
454 <td><input type="hidden" name="submitform" id="submitform" value=""></td>
455 </tr>
456 <tr class="text">
457 <td colspan="3">
458 <div style="width:100%;overflow:auto;height:150px" id="itemdiv"></div>
459 </td>
460 </tr>
461 </table>
462 </form>
463 </body>
464 </html>