2 // Copyright (C) 2007-2008 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("$srcdir/acl.inc");
11 require_once("../../custom/code_types.inc.php");
13 $list_id = empty($_REQUEST['list_id']) ?
'language' : $_REQUEST['list_id'];
15 // Check authorization.
16 $thisauth = acl_check('admin', 'super');
17 if (!$thisauth) die("Not authorized.");
19 // If we are saving, then save.
21 if ($_POST['formaction']=='save' && $list_id) {
23 if ($list_id == 'feesheet') {
24 // special case for the feesheet list
25 sqlStatement("DELETE FROM fee_sheet_options");
26 for ($lino = 1; isset($opt["$lino"]['category']); ++
$lino) {
27 $iter = $opt["$lino"];
28 $category = trim($iter['category']);
29 $option = trim($iter['option']);
30 $codes = $iter['codes'];
31 if (strlen($category) > 0 && strlen($option) > 0) {
32 sqlInsert("INSERT INTO fee_sheet_options ( " .
33 "fs_category, fs_option, fs_codes " .
45 // erase lists options and recreate them from the submitted form data
46 sqlStatement("DELETE FROM list_options WHERE list_id = '$list_id'");
47 for ($lino = 1; isset($opt["$lino"]['id']); ++
$lino) {
48 $iter = $opt["$lino"];
49 $value = empty($iter['value']) ?
0 : (trim($iter['value']) +
0);
50 if (strlen(trim($iter['id'])) > 0) {
51 sqlInsert("INSERT INTO list_options ( " .
52 "list_id, option_id, title, seq, is_default, option_value " .
55 "'" . trim($iter['id']) . "', " .
56 "'" . trim($iter['title']) . "', " .
57 "'" . trim($iter['seq']) . "', " .
58 "'" . trim($iter['default']) . "', " .
65 else if ($_POST['formaction']=='addlist') {
66 // make a new list ID from the new list name
67 $newlistID = $_POST['newlistname'];
68 $newlistID = preg_replace("/\W/", "_", $newlistID);
70 // determine the position of this new list
71 $row = sqlQuery("SELECT max(seq) as maxseq FROM list_options WHERE list_id= 'lists'");
73 // add the new list to the list-of-lists
74 sqlInsert("INSERT INTO list_options ( " .
75 "list_id, option_id, title, seq, is_default, option_value " .
77 "'lists',". // the master list-of-lists
79 "'".$_POST['newlistname']."', ".
80 "'".($row['maxseq']+
1)."',".
84 else if ($_POST['formaction']=='deletelist') {
85 // delete the lists options
86 sqlStatement("DELETE FROM list_options WHERE list_id = '".$_POST['list_id']."'");
87 // delete the list from the master list-of-lists
88 sqlStatement("DELETE FROM list_options WHERE list_id = 'lists' and option_id='".$_POST['list_id']."'");
93 // Given a string of multiple instances of code_type|code|selector,
94 // make a description for each.
95 function getCodeDescriptions($codes) {
97 $arrcodes = explode('~', $codes);
99 foreach ($arrcodes as $codestring) {
100 if ($codestring === '') continue;
101 $arrcode = explode('|', $codestring);
102 $code_type = $arrcode[0];
104 $selector = $arrcode[2];
106 if ($code_type == 'PROD') {
107 $row = sqlQuery("SELECT name FROM drugs WHERE drug_id = '$code' ");
108 $desc = "$code:$selector " . $row['name'];
111 $row = sqlQuery("SELECT code_text FROM codes WHERE " .
112 "code_type = '" . $code_types[$code_type]['id'] . "' AND " .
113 "code = '$code' ORDER BY modifier LIMIT 1");
114 $desc = "$code_type:$code " . ucfirst(strtolower($row['code_text']));
116 $desc = str_replace('~', ' ', $desc);
123 // Write one option line to the form.
125 function writeOptionLine($option_id, $title, $seq, $default, $value) {
126 global $opt_line_no, $list_id;
128 $bgcolor = "#" . (($opt_line_no & 1) ?
"ddddff" : "ffdddd");
129 $checked = $default ?
" checked" : "";
131 echo " <tr bgcolor='$bgcolor'>\n";
133 echo " <td align='center' class='optcell'>";
134 echo "<input type='text' name='opt[$opt_line_no][id]' value='" .
135 htmlspecialchars($option_id, ENT_QUOTES
) . "' size='20' maxlength='63' class='optin' />";
138 echo " <td align='center' class='optcell'>";
139 echo "<input type='text' name='opt[$opt_line_no][title]' value='" .
140 htmlspecialchars($title, ENT_QUOTES
) . "' size='20' maxlength='63' class='optin' />";
143 echo " <td align='center' class='optcell'>";
144 echo "<input type='text' name='opt[$opt_line_no][seq]' value='" .
145 htmlspecialchars($seq, ENT_QUOTES
) . "' size='4' maxlength='10' class='optin' />";
148 echo " <td align='center' class='optcell'>";
149 echo "<input type='checkbox' name='opt[$opt_line_no][default]' value='1'$checked class='optin' />";
152 if ($list_id == 'taxrate') {
153 echo " <td align='center' class='optcell'>";
154 echo "<input type='text' name='opt[$opt_line_no][value]' value='" .
155 htmlspecialchars($value, ENT_QUOTES
) . "' size='8' maxlength='15' class='optin' />";
162 // Write a form line as above but for the special case of the Fee Sheet.
164 function writeFSLine($category, $option, $codes) {
168 $bgcolor = "#" . (($opt_line_no & 1) ?
"ddddff" : "ffdddd");
170 $descs = getCodeDescriptions($codes);
172 echo " <tr bgcolor='$bgcolor'>\n";
174 echo " <td align='center' class='optcell'>";
175 echo "<input type='text' name='opt[$opt_line_no][category]' value='" .
176 htmlspecialchars($category, ENT_QUOTES
) . "' size='20' maxlength='63' class='optin' />";
179 echo " <td align='center' class='optcell'>";
180 echo "<input type='text' name='opt[$opt_line_no][option]' value='" .
181 htmlspecialchars($option, ENT_QUOTES
) . "' size='20' maxlength='63' class='optin' />";
184 echo " <td align='left' class='optcell'>";
185 echo "<a href='' id='codelist_$opt_line_no' onclick='return select_code($opt_line_no)'>";
186 if (strlen($descs)) {
187 $arrdescs = explode('~', $descs);
188 foreach ($arrdescs as $desc) {
196 echo "<input type='hidden' name='opt[$opt_line_no][codes]' value='" .
197 htmlspecialchars($codes, ENT_QUOTES
) . "' />";
198 echo "<input type='hidden' name='opt[$opt_line_no][descs]' value='" .
199 htmlspecialchars($descs, ENT_QUOTES
) . "' />";
208 <?php
html_header_show();?
>
210 <!-- supporting javascript code
-->
211 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script
>
213 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
214 <title
><?php
xl('List Editor','e'); ?
></title
>
217 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
218 tr
.detail
{ font
-size
:10pt
; }
219 td
{ font
-size
:10pt
; }
220 input
{ font
-size
:10pt
; }
221 a
, a
:visited
, a
:hover
{ color
:#0000cc; }
223 .optin
{ background
-color
:transparent
; }
226 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
228 <script language
="JavaScript">
230 var current_lino
= 0;
232 // Helper function to set the contents of a div.
233 // This is for Fee Sheet administration.
234 function setDivContent(id
, content
) {
235 if (document
.getElementById
) {
236 var x
= document
.getElementById(id
);
238 x
.innerHTML
= content
;
240 else if (document
.all
) {
241 var x
= document
.all
[id
];
242 x
.innerHTML
= content
;
246 // Given a line number, redisplay its descriptive list of codes.
247 // This is for Fee Sheet administration.
248 function displayCodes(lino
) {
249 var f
= document
.forms
[0];
251 var descs
= f
['opt[' + lino +
'][descs]'].value
;
253 var arrdescs
= descs
.split('~');
254 for (var i
= 0; i
< arrdescs
.length
; ++i
) {
255 s +
= arrdescs
[i
] +
'<br />';
258 if (s
.length
== 0) s
= '[Add]';
259 setDivContent('codelist_' + lino
, s
);
262 // This invokes the find-code popup.
263 // For Fee Sheet administration.
264 function select_code(lino
) {
266 dlgopen('../patient_file/encounter/find_code_popup.php', '_blank', 700, 400);
270 // This is for callback by the find-code popup.
271 // For Fee Sheet administration.
272 function set_related(codetype
, code
, selector
, codedesc
) {
273 var f
= document
.forms
[0];
274 var celem
= f
['opt[' + current_lino +
'][codes]'];
275 var delem
= f
['opt[' + current_lino +
'][descs]'];
277 while ((i
= codedesc
.indexOf('~')) >= 0) {
278 codedesc
= codedesc
.substring(0, i
) +
' ' + codedesc
.substring(i+
1);
285 celem
.value +
= codetype +
'|' + code +
'|' + selector
;
286 if (codetype
== 'PROD') delem
.value +
= code +
':' + selector +
' ' + codedesc
;
287 else delem
.value +
= codetype +
':' + code +
' ' + codedesc
;
292 displayCodes(current_lino
);
299 <body
class="body_top">
302 <form method
='post' name
='theform' id
='theform' action
='edit_list.php'>
303 <input type
="hidden" name
="formaction" id
="formaction">
305 <p
><b
>Edit
list:</b
> 
;
306 <select name
='list_id' id
="list_id">
308 // The list of lists is also kept incestuously in the lists table.
309 // It could include itself, but to maintain sanity we avoid that.
310 $res = sqlStatement("SELECT * FROM list_options WHERE " .
311 "list_id = 'lists' ORDER BY seq");
312 while ($row = sqlFetchArray($res)) {
313 $key = $row['option_id'];
314 echo "<option value='$key'";
315 if ($key == $list_id) echo " selected";
316 echo ">" . $row['title'] . "</option>\n";
320 <input type
="button" id
="<?php echo $list_id; ?>" class="deletelist" value
="Delete this List">
321 <input type
="button" id
="newlist" class="newlist" value
="New List">
326 <table cellpadding
='2' cellspacing
='0'>
328 <?php
if ($list_id == 'feesheet') { ?
>
329 <td
><b
><?php
xl('Group' ,'e'); ?
></b
></td
>
330 <td
><b
><?php
xl('Option' ,'e'); ?
></b
></td
>
331 <td
><b
><?php
xl('Generates','e'); ?
></b
></td
>
333 <td title
='Click to edit'><b
><?php
xl('ID','e'); ?
></b
></td
>
334 <td
><b
><?php
xl('Title' ,'e'); ?
></b
></td
>
335 <td
><b
><?php
xl('Order' ,'e'); ?
></b
></td
>
336 <td
><b
><?php
xl('Default','e'); ?
></b
></td
>
337 <?php
if ($list_id == 'taxrate') { ?
>
338 <td
><b
><?php
xl('Rate' ,'e'); ?
></b
></td
>
344 // Get the selected list's elements.
346 if ($list_id == 'feesheet') {
347 $res = sqlStatement("SELECT * FROM fee_sheet_options " .
348 "ORDER BY fs_category, fs_option");
349 while ($row = sqlFetchArray($res)) {
350 writeFSLine($row['fs_category'], $row['fs_option'], $row['fs_codes']);
352 for ($i = 0; $i < 3; ++
$i) {
353 writeFSLine('', '', '');
357 $res = sqlStatement("SELECT * FROM list_options WHERE " .
358 "list_id = '$list_id' ORDER BY seq");
359 while ($row = sqlFetchArray($res)) {
360 writeOptionLine($row['option_id'], $row['title'], $row['seq'],
361 $row['is_default'], $row['option_value']);
363 for ($i = 0; $i < 3; ++
$i) {
364 writeOptionLine('', '', '', '', 0);
373 <input type
='button' name
='form_save' id
='form_save' value
='<?php xl('Save
','e
'); ?>' />
379 <!-- template DIV that appears when user chooses to make a
new list -->
380 <div id
="newlistdetail" style
="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
381 List Name
: <input type
="textbox" size
="20" maxlength
="30" name
="newlistname" id
="newlistname">
383 <input type
="button" class="savenewlist" value
="Save new list">
384 <input type
="button" class="cancelnewlist" value
="Cancel">
387 <script language
="javascript">
388 // jQuery stuff to make the page a little easier to use
390 $
(document
).ready(function(){
391 $
("#form_save").click(function() { SaveChanges(); });
392 $
("#list_id").change(function() { $
('#theform').submit(); });
394 $
(".newlist").click(function() { NewList(this
); });
395 $
(".savenewlist").click(function() { SaveNewList(this
); });
396 $
(".deletelist").click(function() { DeleteList(this
); });
397 $
(".cancelnewlist").click(function() { CancelNewList(this
); });
399 var SaveChanges
= function() {
400 $
("#formaction").val("save");
401 $
('#theform').submit();
404 // show the DIV to create a new list
405 var NewList
= function(btnObj
) {
406 // show the field details DIV
407 $
('#newlistdetail').css('visibility', 'visible');
408 $
('#newlistdetail').css('display', 'block');
409 $
(btnObj
).parent().append($
("#newlistdetail"));
410 $
('#newlistdetail > #newlistname').focus();
413 var SaveNewList
= function() {
414 // the list name can only have letters, numbers, spaces and underscores
415 // AND it cannot start with a number
416 if ($
("#newlistname").val().match(/^\d+
/)) {
417 alert("List names cannot start with numbers.");
420 var validname
= $
("#newlistname").val().replace(/[^A
-za
-z0
-9 -]/g
, "_"); // match any non-word characters and replace them
421 if (validname
!= $
("#newlistname").val()) {
422 if (! confirm("Your list name has been changed to meet naming requirements.\nPlease compare the new name, '"+validname+
"' with the old name, '"+$
("#newlistname").val()+
"'. Do you wish to continue with the new name?"))
427 $
("#newlistname").val(validname
);
429 // submit the form to add a new field to a specific group
430 $
("#formaction").val("addlist");
431 $
("#theform").submit();
433 // actually delete an entire list from the database
434 var DeleteList
= function(btnObj
) {
435 var listid
= $
(btnObj
).attr("id");
436 if (confirm("WARNING - This action cannot be undone.\n Are you sure you wish to delete the entire list("+listid+
")?")) {
437 // submit the form to add a new field to a specific group
438 $
("#formaction").val("deletelist");
439 $
("#deletelistname").val(listid
);
440 $
("#theform").submit();
444 // just hide the new list DIV
445 var CancelNewList
= function(btnObj
) {
446 // hide the list details DIV
447 $
('#newlistdetail').css('visibility', 'hidden');
448 $
('#newlistdetail').css('display', 'none');
449 // reset the new group values to a default
450 $
('#newlistdetail > #newlistname').val("");