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)) {
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']);
47 foreach ($personalized as $key => $value) {
48 $arr = explode("|", $value);
50 $res = sqlStatement("SELECT * FROM template_users WHERE tu_template_id=? AND tu_user_id=?", array($arr[0], $_SESSION['authId']));
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']);
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']);
72 <?php Header
::setupHeader(['common', 'opener', 'jquery-ui',]); ?
>
74 <script type
="text/javascript">
76 function refreshme() {
78 document
.location
.reload();
81 $
(document
).ready(function () {
85 $
(".iframe_small").on('click', function (e
) {
88 dlgopen('', '', 400, 170, '', '', {
90 {text
: '<?php echo xla('Close
'); ?>', close
: true, style
: 'default btn-sm'}
92 onClosed
: 'refreshme',
94 url
: $
(this
).attr('href')
98 $
(".iframe_medium").on('click', function (e
) {
101 dlgopen('', '', 450, 250, '', '', {
103 {text
: '<?php echo xla('Close
'); ?>', close
: true, style
: 'default btn-sm'}
105 onClosed
: 'refreshme',
107 url
: $
(this
).attr('href')
111 $
(".iframe_abvmedium").on('click', function (e
) {
114 dlgopen('', '', 700, 500, '', '', {
116 {text
: '<?php echo xla('Close
'); ?>', close
: true, style
: 'default btn-sm'}
118 onClosed
: 'refreshme',
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;
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
) {
135 url
: "ajax_code.php",
138 item
: form
.elements
[selectedList
].options
[total_selected
].value
,
139 list_id
: document
.getElementById('filter_users').value
,
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;
151 msg +
= form
.elements
[selectedList
].options
[total_selected
].text +
"\n";
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
]);
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
);
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
]);
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
]);
219 function display_category_item(form
, selectedList
) {
220 top
.restoreSession();
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
;
231 document
.getElementById('itemdiv').style
.display
= 'none';
234 document
.getElementById('itemdiv').style
.display
= '';
237 url
: "ajax_code.php",
240 list_id
: selectedval
,
244 success
: function (thedata
) {
245 document
.getElementById('itemdiv').innerHTML
= thedata
;
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
;
268 for (i
= 0; i
<= len
; i++
) {
269 for (j
= 0; j
<= len
; j++
) {
270 if (sortarr
[i
] == text
[j
]) {
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();
288 <body
class="body_top">
289 <form name
="myform" method
="post" onsubmit
="top.restoreSession();">
291 <legend
><span
class="text"><?php
echo htmlspecialchars(xl('Filter'), ENT_QUOTES
); ?
></span
></legend
>
294 <td
><?php
echo htmlspecialchars(xl('Context'), ENT_QUOTES
); ?
></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
>
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>";
309 <td
><?php
echo htmlspecialchars(xl('Users'), ENT_QUOTES
); ?
></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
>
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>";
327 <table align
="center" width
="100%">
330 <a href
=# class="css_button"
331 onclick
="top.restoreSession();personalize_save()"><span
><?php
echo htmlspecialchars(xl('Save'), ENT_QUOTES
); ?
></span
></a
>
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
>
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
>
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
>
358 <th
><?php
echo htmlspecialchars(xl('Available categories'), ENT_QUOTES
); ?
></th
>
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
>
367 <select multiple name
="topersonalized[]" id
="topersonalized" size
="6" style
="width:220px"
368 onchange
="display_category_item(document.myform,'topersonalized');">
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
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=?)" .
390 "ORDER BY cl_list_id,tu_user_id,c.cl_list_item_long";
391 $resTemplates = sqlStatement($sql, $arval1);
393 while ($rowTemplates = sqlFetchArray($resTemplates)) {
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) " .
408 " ORDER BY cl_list_id,cl_list_item_long";
409 $resorphan = sqlStatement($sqlorphan);
410 while ($roworphan = sqlFetchArray($resorphan)) {
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>";
422 <input type
="button" name
="remove" value
=»
;
423 onclick
="jsub_selected(document.myform,'personalized','topersonalized')"></br
>
424 <input type
="button" name
="remove" value
=«
;
425 onclick
="check_user_category(document.myform,'topersonalized','personalized')">
428 <select multiple name
="personalized[]" id
="personalized" size
="6" style
="width:220px">
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 " .
437 "ORDER BY c.cl_list_item_long";
438 $resTemplates = sqlStatement($sql, array($_SESSION['authId']));
439 while ($rowTemplates = sqlFetchArray($resTemplates)) {
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>";
454 <td
><input type
="hidden" name
="submitform" id
="submitform" value
=""></td
>
458 <div style
="width:100%;overflow:auto;height:150px" id
="itemdiv"></div
>