7 * @link https://www.open-emr.org
8 * @author Eldho Chacko <eldho@zhservices.com>
9 * @author Jacob T Paul <jacob@zhservices.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2011 Z&H Consultancy Services Private Limited <sam@zhservices.com>
12 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once("../../interface/globals.php");
18 use OpenEMR\Common\Acl\AclMain
;
19 use OpenEMR\Core\Header
;
21 $list_id = $_REQUEST['list_id'] ?
$_REQUEST['list_id'] : $_REQUEST['filter_context'];
23 function Delete_Rows($id)
25 sqlStatement("DELETE FROM template_users WHERE tu_template_id=? AND tu_user_id=?", array($id, $_SESSION['authUserID']));
28 function Insert_Rows($id, $order = "")
30 sqlStatement("REPLACE INTO template_users (tu_template_id,tu_user_id,tu_template_order) VALUES (?,?,?)", array($id, $_SESSION['authUserID'], $order));
33 if (isset($_REQUEST['submitform']) && $_REQUEST['submitform'] == 'save') {
34 $topersonalized = $_REQUEST['topersonalized'];
35 $personalized = $_REQUEST['personalized'];
36 foreach ($topersonalized as $key => $value) {
37 $arr = explode("|", $value);
38 $res = sqlStatement("SELECT * FROM template_users WHERE tu_template_id=? AND tu_user_id=?", array($arr[0], $_SESSION['authUserID']));
39 if (sqlNumRows($res)) {
41 $qry = sqlStatement("SELECT * FROM customlists WHERE cl_list_id=? AND cl_deleted=0", array($arr[0]));
42 while ($row = sqlFetchArray($qry)) {
43 Delete_Rows($row['cl_list_slno']);
49 foreach ($personalized as $key => $value) {
50 $arr = explode("|", $value);
52 $res = sqlStatement("SELECT * FROM template_users WHERE tu_template_id=? AND tu_user_id=?", array($arr[0], $_SESSION['authUserID']));
54 $qry = sqlStatement("SELECT * FROM customlists WHERE cl_list_id=? AND cl_deleted=0", array($arr[0]));
55 while ($row = sqlFetchArray($qry)) {
56 $qryTU = sqlStatement("SELECT * FROM template_users WHERE tu_template_id=? AND tu_user_id=?", array($row['cl_list_slno'], $arr[1]));
57 while ($rowTU = sqlFetchArray($qryTU)) {
58 Insert_Rows($rowTU['tu_template_id'], $rowTU['tu_template_order']);
63 $qry = sqlStatement("SELECT * FROM customlists WHERE cl_list_id=? AND cl_deleted=0", array($arr[0]));
64 while ($row = sqlFetchArray($qry)) {
65 Insert_Rows($row['cl_list_slno'], $row['cl_order']);
74 <?php Header
::setupHeader(['common', 'opener']); ?
>
78 function refreshme() {
80 document
.location
.reload();
87 $
(".iframe_small").on('click', function (e
) {
90 dlgopen('', '', 400, 250, '', '', {
92 {text
: '<?php echo xla('Close
'); ?>', close
: true, style
: 'secondary btn-sm'}
94 onClosed
: 'refreshme',
96 url
: $
(this
).attr('href')
100 $
(".iframe_medium").on('click', function (e
) {
103 dlgopen('', '', 450, 300, '', '', {
105 {text
: '<?php echo xla('Close
'); ?>', close
: true, style
: 'secondary btn-sm'}
107 onClosed
: 'refreshme',
109 url
: $
(this
).attr('href')
113 $
(".iframe_abvmedium").on('click', function (e
) {
116 dlgopen('', '', 700, 550, '', '', {
118 {text
: '<?php echo xla('Close
'); ?>', close
: true, style
: 'secondary btn-sm'}
120 onClosed
: 'refreshme',
122 url
: $
(this
).attr('href')
128 function check_user_category(form
, selectFrom
, selectedList
) {
129 top
.restoreSession();
130 var total_selected
= form
.elements
[selectedList
].length
- 1;
132 for (total_selected
; total_selected
>= 0; total_selected
--) {
133 if (form
.elements
[selectedList
].options
[total_selected
].selected
) {
134 if (document
.getElementById('filter_users').value
) {
137 url
: "ajax_code.php",
140 item
: form
.elements
[selectedList
].options
[total_selected
].value
,
141 list_id
: document
.getElementById('filter_users').value
,
145 success
: function (thedata
) {
146 if (thedata
== 'OK') {
147 total_clients
= form
.elements
[selectFrom
].length
;
148 opt
= new Option(form
.elements
[selectedList
].options
[total_selected
].text
, form
.elements
[selectedList
].options
[total_selected
].value
);
149 form
.elements
[selectFrom
].options
[total_clients
] = opt
;
150 form
.elements
[selectedList
].options
[total_selected
] = null;
153 msg +
= form
.elements
[selectedList
].options
[total_selected
].text +
"\n";
162 total_clients
= form
.elements
[selectFrom
].length
;
163 opt
= new Option(form
.elements
[selectedList
].options
[total_selected
].text
, form
.elements
[selectedList
].options
[total_selected
].value
);
164 form
.elements
[selectFrom
].options
[total_clients
] = opt
;
165 form
.elements
[selectedList
].options
[total_selected
] = null;
169 jsub_sortNow(form
.elements
[selectFrom
]);
171 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?'));?>")) {
172 remove_selected(form
, selectedList
);
178 function remove_selected(form
, selectedList
) {
179 top
.restoreSession();
180 var total_selected
= form
.elements
[selectedList
].length
- 1;
181 for (total_selected
; total_selected
>= 0; total_selected
--) {
182 if (form
.elements
[selectedList
].options
[total_selected
].selected
) {
183 form
.elements
[selectedList
].options
[total_selected
] = null;
186 jsub_sortNow(form
.elements
[selectFrom
]);
190 function all_selected(selectedList
) {
191 top
.restoreSession();
192 var total_selected
= document
.getElementById(selectedList
).length
- 1;
193 for (total_selected
; total_selected
>= 0; total_selected
--) {
194 document
.getElementById(selectedList
).options
[total_selected
].selected
= true;
198 function all_deselected(selectedList
) {
199 top
.restoreSession();
200 var total_selected
= document
.getElementById(selectedList
).length
- 1;
201 for (total_selected
; total_selected
>= 0; total_selected
--) {
202 document
.getElementById(selectedList
).options
[total_selected
].selected
= false;
206 function jsub_selected(form
, selectFrom
, selectedList
) {
207 top
.restoreSession();
208 var total_selected
= form
.elements
[selectedList
].length
- 1;
209 for (total_selected
; total_selected
>= 0; total_selected
--) {
210 if (form
.elements
[selectedList
].options
[total_selected
].selected
) {
211 total_clients
= form
.elements
[selectFrom
].length
;
212 opt
= new Option(form
.elements
[selectedList
].options
[total_selected
].text
, form
.elements
[selectedList
].options
[total_selected
].value
);
213 form
.elements
[selectFrom
].options
[total_clients
] = opt
;
214 form
.elements
[selectedList
].options
[total_selected
] = null;
217 jsub_sortNow(form
.elements
[selectFrom
]);
221 function display_category_item(form
, selectedList
) {
222 top
.restoreSession();
224 var selectedval
= '';
225 var total_selected
= form
.elements
[selectedList
].length
- 1;
226 for (total_selected
; total_selected
>= 0; total_selected
--) {
227 if (form
.elements
[selectedList
].options
[total_selected
].selected
) {
228 selectedval
= form
.elements
[selectedList
].options
[total_selected
].value
;
233 document
.getElementById('itemdiv').style
.display
= 'none';
236 document
.getElementById('itemdiv').style
.display
= '';
239 url
: "ajax_code.php",
242 list_id
: selectedval
,
246 success
: function (thedata
) {
247 document
.getElementById('itemdiv').innerHTML
= thedata
;
257 function jsub_sortNow(obj
) {
258 top
.restoreSession();
259 var len
= obj
.length
- 1;
260 var text
= new Array();
261 var values
= new Array();
262 var sortarr
= new Array();
263 for (var i
= len
; i
>= 0; i
--) {
264 text
[i
] = obj
.options
[i
].text
;
265 values
[i
] = obj
.options
[i
].value
;
266 sortarr
[i
] = obj
.options
[i
].text
;
270 for (i
= 0; i
<= len
; i++
) {
271 for (j
= 0; j
<= len
; j++
) {
272 if (sortarr
[i
] == text
[j
]) {
276 opt
= new Option(text
[j
], values
[j
]);
277 obj
.options
[i
] = opt
;
281 function personalize_save() {
282 top
.restoreSession();
283 document
.getElementById('submitform').value
= 'save';
284 all_selected('topersonalized');
285 all_selected('personalized');
286 document
.myform
.submit();
290 <body
class="body_top">
291 <form name
="myform" method
="post" onsubmit
="top.restoreSession();">
292 <div
class="container-fluid">
293 <h3
><?php
echo htmlspecialchars(xl('Filter'), ENT_QUOTES
); ?
></h3
>
295 <label
class="col-form-label col-sm-1"><?php
echo htmlspecialchars(xl('Context'), ENT_QUOTES
); ?
></label
>
296 <div
class="col-sm-5">
297 <select name
='filter_context' class="form-control" id
='filter_context' onchange
='javascript:document.myform.submit();'>
298 <option value
=''><?php
echo htmlspecialchars(xl('Select a Context'), ENT_QUOTES
); ?
></option
>
300 $context_sql = "SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0";
301 $context_res = sqlStatement($context_sql);
302 while ($context_row = sqlFetchArray($context_res)) {
303 echo "<option value='" . htmlspecialchars($context_row['cl_list_slno'], ENT_QUOTES
) . "' ";
304 echo ($_REQUEST['filter_context'] == $context_row['cl_list_slno']) ?
'selected' : '';
305 echo ">" . htmlspecialchars($context_row['cl_list_item_long'], ENT_QUOTES
) . "</option>";
310 <label
class="col-form-label col-sm-1"><?php
echo htmlspecialchars(xl('Users'), ENT_QUOTES
); ?
></label
>
311 <div
class="col-sm-5">
312 <select name
='filter_users' class="form-control" id
='filter_users' onchange
='javascript:document.myform.submit();'>
313 <option value
=''><?php
echo htmlspecialchars(xl('Select a User'), ENT_QUOTES
); ?
></option
>
315 $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!=?";
316 $user_res = sqlStatement($user_sql, array($_SESSION['authUserID']));
317 while ($user_row = sqlFetchArray($user_res)) {
318 echo "<option value='" . htmlspecialchars($user_row['tu_user_id'], ENT_QUOTES
) . "' ";
319 echo ($_REQUEST['filter_users'] == $user_row['tu_user_id']) ?
'selected' : '';
320 echo ">" . htmlspecialchars($user_row['fname'] . " " . $user_row['lname'], ENT_QUOTES
) . "</option>";
325 <div
class="col-12 my-2 text-center">
326 <a href
="#" class="btn btn-primary" onclick
="top.restoreSession();personalize_save()"><?php
echo htmlspecialchars(xl('Save'), ENT_QUOTES
); ?
></a
>
328 if (AclMain
::aclCheckCore('nationnotes', 'nn_configure')) {
330 <a href
="delete_category.php" id
="share_link" class="iframe_medium btn btn-primary" onclick
="top.restoreSession();"><?php
echo htmlspecialchars(xl('Delete Category'), ENT_QUOTES
); ?
></a
>
335 if (AclMain
::aclCheckCore('nationnotes', 'nn_configure')) {
337 <a href
="add_template.php?list_id=<?php echo attr($_REQUEST['list_id']); ?>" onclick
="top.restoreSession();" class="iframe_small btn btn-primary" title
="<?php echo htmlspecialchars(xl('Add Category'), ENT_QUOTES); ?>"><?php
echo htmlspecialchars(xl('Add Category'), ENT_QUOTES
); ?
></a
>
342 if (AclMain
::aclCheckCore('nationnotes', 'nn_configure')) {
344 <a href
="add_context.php" class="iframe_medium btn btn-primary" onclick
="top.restoreSession();" title
="<?php echo htmlspecialchars(xl('Add Context'), ENT_QUOTES); ?>"><?php
echo htmlspecialchars(xl('Add Context'), ENT_QUOTES
); ?
></a
>
349 <div
class="col-sm-5 text">
350 <?php
echo htmlspecialchars(xl('Available categories'), ENT_QUOTES
); ?
>
352 <div
class="col-sm-2">
355 <div
class="col-sm-5 text">
356 <?php
$user = sqlQuery("SELECT * FROM users WHERE id=?", array($_SESSION['authUserID'])); ?
>
357 <?php
echo htmlspecialchars(xl('Categories for') . " " . $user['fname'] . " " . $user['lname'], ENT_QUOTES
); ?
>
359 <div
class="col-sm-5">
360 <select multiple name
="topersonalized[]" class="form-control" id
="topersonalized" size
="6" onchange
="display_category_item(document.myform,'topersonalized');">
364 $arval = array($_SESSION['authUserID']);
365 $arval1 = array($_REQUEST['filter_users'], $_SESSION['authUserID']);
366 if ($_REQUEST['filter_context']) {
367 $where .= " AND cl_list_id=?";
368 array_push($arval, $_REQUEST['filter_context']);
369 array_push($arval1, $_REQUEST['filter_context']);
371 $sql = "SELECT * FROM template_users AS tu LEFT OUTER JOIN customlists AS c ON tu.tu_template_id=c.cl_list_slno
372 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
375 " ORDER BY cl_list_id,tu_user_id,cl_list_item_long";
376 $resTemplates = sqlStatement($sql, $arval);
377 if ($_REQUEST['filter_users']) {
378 $sql = " SELECT * FROM template_users AS tu LEFT OUTER JOIN customlists AS c ON tu.tu_template_id=c.cl_list_slno WHERE
379 tu.tu_user_id=? AND c.cl_list_type=3 AND cl_deleted=0 AND tu.tu_template_id NOT IN
380 (SELECT tu_template_id FROM template_users AS tuser WHERE tu_user_id=?)" .
382 "ORDER BY cl_list_id,tu_user_id,c.cl_list_item_long";
383 $resTemplates = sqlStatement($sql, $arval1);
385 while ($rowTemplates = sqlFetchArray($resTemplates)) {
387 if (!$_REQUEST['filter_context']) {
388 $context = sqlQuery("SELECT * FROM customlists WHERE cl_list_slno=?", array($rowTemplates['cl_list_id']));
389 $cntxt .= $context['cl_list_item_long'] . "->";
391 if (!$_REQUEST['filter_users']) {
392 $context = sqlQuery("SELECT * FROM users WHERE id=?", array($rowTemplates['tu_user_id']));
393 $cntxt .= $context['username'] . "->";
395 echo "<option value='" . htmlspecialchars($rowTemplates['cl_list_slno'] . "|" . $rowTemplates['tu_user_id'], ENT_QUOTES
) . "'>" . htmlspecialchars($cntxt . $rowTemplates['cl_list_item_long'], ENT_QUOTES
) . "</option>";
397 $sqlorphan = "SELECT * FROM customlists WHERE cl_list_type=3 AND cl_deleted=0 AND cl_list_slno " .
398 " NOT IN (SELECT DISTINCT tu_template_id FROM template_users) " .
400 " ORDER BY cl_list_id,cl_list_item_long";
401 $resorphan = sqlStatement($sqlorphan);
402 while ($roworphan = sqlFetchArray($resorphan)) {
404 if (!$_REQUEST['filter_context']) {
405 $context = sqlQuery("SELECT * FROM customlists WHERE cl_list_slno=?", array($roworphan['cl_list_id']));
406 $cntxt .= $context['cl_list_item_long'] . "->";
408 echo "<option value='" . htmlspecialchars($roworphan['cl_list_slno'] . "|", ENT_QUOTES
) . "'>" . htmlspecialchars($cntxt . $roworphan['cl_list_item_long'], ENT_QUOTES
) . "</option>";
413 <div
class="col-sm-2 text-center">
414 <button name
="remove" class="btn btn-secondary" onclick
="jsub_selected(document.myform,'personalized','topersonalized')">»
;</button
><br
/>
415 <button name
="remove" class="btn btn-secondary" onclick
="check_user_category(document.myform,'topersonalized','personalized')">«
;</button
>
417 <div
class="col-sm-5">
418 <select multiple
class="form-control" name
="personalized[]" id
="personalized" size
="6">
421 if ($_REQUEST['filter_context']) {
422 $where .= " AND cl_list_id='" . $_REQUEST['filter_context'] . "'";
424 $sql = "SELECT * FROM template_users AS tu LEFT OUTER JOIN customlists AS c ON tu.tu_template_id=c.cl_list_slno WHERE
425 tu.tu_user_id=? AND c.cl_list_type=3 AND cl_deleted=0 " .
427 "ORDER BY c.cl_list_item_long";
428 $resTemplates = sqlStatement($sql, array($_SESSION['authUserID']));
429 while ($rowTemplates = sqlFetchArray($resTemplates)) {
431 if (!$_REQUEST['filter_context']) {
432 $context = sqlQuery("SELECT * FROM customlists WHERE cl_list_slno=?", array($rowTemplates['cl_list_id']));
433 $cntxt .= $context['cl_list_item_long'] . "->";
435 echo "<option value='" . htmlspecialchars($rowTemplates['cl_list_slno'] . "|" . $rowTemplates['tu_user_id'], ENT_QUOTES
) . "'>" . htmlspecialchars($cntxt . $rowTemplates['cl_list_item_long'], ENT_QUOTES
) . "</option>";
441 <input type
="hidden" name
="submitform" id
="submitform" value
="" />
442 <div
class="w-100 overflow-auto" style
="height:150px" id
="itemdiv"></div
>