2 // Copyright (C) 2007-2010 Rod Roark <rod@sunsetsystems.com>
3 // Copyright © 2010 by Andrew Moore <amoore@cpan.org>
4 // Copyright © 2010 by "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // Functions for managing the lists and layouts
13 // Note: there are translation wrappers for the lists and layout labels
14 // at library/translation.inc.php. The functions are titled
15 // xl_list_label() and xl_layout_label() and are controlled by the
16 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
17 // flags in globals.php
19 // Documentation for layout_options.edit_options:
21 // C = Capitalize first letter of each word (text fields)
22 // D = Check for duplicates in New Patient form
23 // G = Graphable (for numeric fields in forms supporting historical data)
24 // H = Read-only field copied from static history
25 // L = Lab Order ("ord_lab") types only (address book)
26 // N = Show in New Patient form
27 // O = Procedure Order ("ord_*") types only (address book)
28 // R = Distributor types only (address book)
29 // U = Capitalize all letters (text fields)
30 // V = Vendor types only (address book)
31 // 1 = Write Once (not editable when not empty) (text fields)
33 require_once("formdata.inc.php");
34 require_once("formatting.inc.php");
35 require_once("user.inc");
39 function get_pharmacies() {
40 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
41 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
42 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
43 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
45 "ORDER BY name, area_code, prefix, number");
48 // Function to generate a drop-list.
50 function generate_select_list($tag_name, $list_id, $currvalue, $title,
51 $empty_name=' ', $class='', $onchange='', $tag_id = '', $custom_attributes = null )
54 $tag_name_esc = htmlspecialchars( $tag_name, ENT_QUOTES
);
55 $s .= "<select name='$tag_name_esc'";
56 $tag_id_esc = $tag_name_esc;
57 if ( $tag_id != '' ) {
58 $tag_id_esc = htmlspecialchars( $tag_id, ENT_QUOTES
);
60 $s .= " id='$tag_id_esc'";
61 if ($class) $s .= " class='$class'";
62 if ($onchange) $s .= " onchange='$onchange'";
63 if ( $custom_attributes != null && is_array($custom_attributes) ) {
64 foreach ( $custom_attributes as $attr => $val ) {
65 if ( isset($custom_attributes[$attr] ) ) {
66 $s .= " ".htmlspecialchars( $attr, ENT_QUOTES
)."='".htmlspecialchars( $val, ENT_QUOTES
)."'";
70 $selectTitle = htmlspecialchars( $title, ENT_QUOTES
);
71 $s .= " title='$selectTitle'>";
72 $selectEmptyName = htmlspecialchars( xl($empty_name), ENT_NOQUOTES
);
73 if ($empty_name) $s .= "<option value=''>" . $selectEmptyName . "</option>";
74 $lres = sqlStatement("SELECT * FROM list_options " .
75 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
76 $got_selected = FALSE;
77 while ($lrow = sqlFetchArray($lres)) {
78 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES
);
79 $s .= "<option value='$optionValue'";
80 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
81 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
86 $optionLabel = htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
87 $s .= ">$optionLabel</option>\n";
89 if (!$got_selected && strlen($currvalue) > 0) {
90 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
91 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
93 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_QUOTES
);
94 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
95 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
103 // $frow is a row from the layout_options table.
104 // $currvalue is the current value, if any, of the associated item.
106 function generate_form_field($frow, $currvalue) {
107 global $rootdir, $date_init;
109 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
111 $data_type = $frow['data_type'];
112 $field_id = $frow['field_id'];
113 $list_id = $frow['list_id'];
114 // escaped variables to use in html
115 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES
);
116 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES
);
118 // Added 5-09 by BM - Translate description if applicable
119 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
121 // added 5-2009 by BM to allow modification of the 'empty' text title field.
122 // Can pass $frow['empty_title'] with this variable, otherwise
123 // will default to 'Unassigned'.
124 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
125 // if make $frow['empty_title'] equal to 'SKIP'
127 if (isset($frow['empty_title'])) {
128 if ($frow['empty_title'] == "SKIP") {
129 //do not display an 'empty' choice
131 $empty_title = "Unassigned";
134 $empty_title = $frow['empty_title'];
138 $empty_title = "Unassigned";
141 // generic single-selection list
142 if ($data_type == 1) {
143 echo generate_select_list("form_$field_id", $list_id, $currvalue,
144 $description, $showEmpty ?
$empty_title : '');
148 else if ($data_type == 2) {
149 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
150 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
151 echo "<input type='text'" .
152 " name='form_$field_id_esc'" .
153 " id='form_$field_id_esc'" .
154 " size='$fldlength'" .
155 " maxlength='$maxlength'" .
156 " title='$description'" .
157 " value='$currescaped'";
158 if (strpos($frow['edit_options'], 'C') !== FALSE)
159 echo " onchange='capitalizeMe(this)'";
160 else if (strpos($frow['edit_options'], 'U') !== FALSE)
161 echo " onchange='this.value = this.value.toUpperCase()'";
162 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES
);
163 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
164 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
165 echo " onblur='maskblur(this,\"$tmp\")'";
167 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0)
172 // long or multi-line text field
173 else if ($data_type == 3) {
174 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
175 $textRows = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
177 " name='form_$field_id_esc'" .
178 " id='form_$field_id_esc'" .
179 " title='$description'" .
180 " cols='$textCols'" .
181 " rows='$textRows'>" .
182 $currescaped . "</textarea>";
186 else if ($data_type == 4) {
187 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
188 " value='$currescaped'" .
189 " title='$description'" .
190 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
191 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
192 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
193 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES
) . "' />";
194 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
197 // provider list, local providers only
198 else if ($data_type == 10) {
199 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
200 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
201 "AND authorized = 1 " .
202 "ORDER BY lname, fname");
203 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
204 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
205 while ($urow = sqlFetchArray($ures)) {
206 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES
);
207 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES
);
208 echo "<option value='$optionId'";
209 if ($urow['id'] == $currvalue) echo " selected";
210 echo ">$uname</option>";
215 // provider list, including address book entries with an NPI number
216 else if ($data_type == 11) {
217 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
218 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
219 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
220 "ORDER BY lname, fname");
221 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
222 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
223 while ($urow = sqlFetchArray($ures)) {
224 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES
);
225 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES
);
226 echo "<option value='$optionId'";
227 if ($urow['id'] == $currvalue) echo " selected";
228 echo ">$uname</option>";
234 else if ($data_type == 12) {
235 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
236 echo "<option value='0'></option>";
237 $pres = get_pharmacies();
238 while ($prow = sqlFetchArray($pres)) {
240 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
241 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
242 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
243 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES
);
244 echo "<option value='$optionValue'";
245 if ($currvalue == $key) echo " selected";
246 echo ">$optionLabel</option>";
252 else if ($data_type == 13) {
253 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
254 echo "<option value=''> </option>";
255 $squads = acl_get_squads();
257 foreach ($squads as $key => $value) {
258 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
259 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES
);
260 echo "<option value='$optionValue'";
261 if ($currvalue == $key) echo " selected";
262 echo ">$optionLabel</option>\n";
268 // Address book, preferring organization name if it exists and is not in
269 // parentheses, and excluding local users who are not providers.
270 // Supports "referred to" practitioners and facilities.
271 // Alternatively the letter L in edit_options means that abook_type
272 // must be "ord_lab", indicating types used with the procedure
273 // lab ordering system.
274 // Alternatively the letter O in edit_options means that abook_type
275 // must begin with "ord_", indicating types used with the procedure
277 // Alternatively the letter V in edit_options means that abook_type
278 // must be "vendor", indicating the Vendor type.
279 // Alternatively the letter R in edit_options means that abook_type
280 // must be "dist", indicating the Distributor type.
281 else if ($data_type == 14) {
282 if (strpos($frow['edit_options'], 'L') !== FALSE)
283 $tmp = "abook_type = 'ord_lab'";
284 else if (strpos($frow['edit_options'], 'O') !== FALSE)
285 $tmp = "abook_type LIKE 'ord\\_%'";
286 else if (strpos($frow['edit_options'], 'V') !== FALSE)
287 $tmp = "abook_type LIKE 'vendor%'";
288 else if (strpos($frow['edit_options'], 'R') !== FALSE)
289 $tmp = "abook_type LIKE 'dist'";
291 $tmp = "( username = '' OR authorized = 1 )";
292 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
293 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
295 "ORDER BY organization, lname, fname");
296 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
297 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
298 while ($urow = sqlFetchArray($ures)) {
299 $uname = $urow['organization'];
300 if (empty($uname) ||
substr($uname, 0, 1) == '(') {
301 $uname = $urow['lname'];
302 if ($urow['fname']) $uname .= ", " . $urow['fname'];
304 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES
);
305 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES
);
306 echo "<option value='$optionValue'";
307 $title = $urow['username'] ?
xl('Local') : xl('External');
308 $optionTitle = htmlspecialchars( $title, ENT_QUOTES
);
309 echo " title='$optionTitle'";
310 if ($urow['id'] == $currvalue) echo " selected";
311 echo ">$optionLabel</option>";
317 else if ($data_type == 15) {
318 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
319 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
320 echo "<input type='text'" .
321 " name='form_$field_id_esc'" .
322 " id='form_related_code'" .
323 " size='$fldlength'" .
324 " maxlength='$maxlength'" .
325 " title='$description'" .
326 " value='$currescaped'" .
327 " onclick='sel_related(this)' readonly" .
331 // a set of labeled checkboxes
332 else if ($data_type == 21) {
333 // In this special case, fld_length is the number of columns generated.
334 $cols = max(1, $frow['fld_length']);
335 $avalue = explode('|', $currvalue);
336 $lres = sqlStatement("SELECT * FROM list_options " .
337 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
338 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
339 $tdpct = (int) (100 / $cols);
340 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
341 $option_id = $lrow['option_id'];
342 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
343 // if ($count) echo "<br />";
344 if ($count %
$cols == 0) {
345 if ($count) echo "</tr>";
348 echo "<td width='$tdpct%'>";
349 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]' id='form_{$field_id_esc}[$option_id_esc]' value='1'";
350 if (in_array($option_id, $avalue)) echo " checked";
352 // Added 5-09 by BM - Translate label if applicable
353 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
359 if ($count > $cols) {
360 // Add some space after multiple rows of checkboxes.
361 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
362 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
368 // a set of labeled text input fields
369 else if ($data_type == 22) {
370 $tmp = explode('|', $currvalue);
372 foreach ($tmp as $value) {
373 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
374 $avalue[$matches[1]] = $matches[2];
377 $lres = sqlStatement("SELECT * FROM list_options " .
378 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
379 echo "<table cellpadding='0' cellspacing='0'>";
380 while ($lrow = sqlFetchArray($lres)) {
381 $option_id = $lrow['option_id'];
382 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
383 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
384 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
386 // Added 5-09 by BM - Translate label if applicable
387 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
388 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
389 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
390 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
391 echo "<td><input type='text'" .
392 " name='form_{$field_id_esc}[$option_id_esc]'" .
393 " id='form_{$field_id_esc}[$option_id_esc]'" .
394 " size='$fldlength'" .
395 " maxlength='$maxlength'" .
396 " value='$optionValue'";
397 echo " /></td></tr>";
402 // a set of exam results; 3 radio buttons and a text field:
403 else if ($data_type == 23) {
404 $tmp = explode('|', $currvalue);
406 foreach ($tmp as $value) {
407 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
408 $avalue[$matches[1]] = $matches[2];
411 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
412 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
413 $lres = sqlStatement("SELECT * FROM list_options " .
414 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
415 echo "<table cellpadding='0' cellspacing='0'>";
416 echo "<tr><td> </td><td class='bold'>" .
417 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
418 " </td><td class='bold'>" .
419 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
420 "<td class='bold'>" .
421 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
422 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
423 while ($lrow = sqlFetchArray($lres)) {
424 $option_id = $lrow['option_id'];
425 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
426 $restype = substr($avalue[$option_id], 0, 1);
427 $resnote = substr($avalue[$option_id], 2);
429 // Added 5-09 by BM - Translate label if applicable
430 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
432 for ($i = 0; $i < 3; ++
$i) {
433 $inputValue = htmlspecialchars( $i, ENT_QUOTES
);
434 echo "<td><input type='radio'" .
435 " name='radio_{$field_id_esc}[$option_id_esc]'" .
436 " id='radio_{$field_id_esc}[$option_id_esc]'" .
437 " value='$inputValue'";
438 if ($restype === "$i") echo " checked";
441 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
442 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
443 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
444 echo "<td><input type='text'" .
445 " name='form_{$field_id_esc}[$option_id_esc]'" .
446 " id='form_{$field_id_esc}[$option_id_esc]'" .
447 " size='$fldlength'" .
448 " maxlength='$maxlength'" .
449 " value='$resnote' /></td>";
455 // the list of active allergies for the current patient
456 // this is read-only!
457 else if ($data_type == 24) {
458 $query = "SELECT title, comments FROM lists WHERE " .
459 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
461 // echo "<!-- $query -->\n"; // debugging
462 $lres = sqlStatement($query, array($GLOBALS['pid']));
464 while ($lrow = sqlFetchArray($lres)) {
465 if ($count++
) echo "<br />";
466 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES
);
467 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES
) . ')';
471 // a set of labeled checkboxes, each with a text field:
472 else if ($data_type == 25) {
473 $tmp = explode('|', $currvalue);
475 foreach ($tmp as $value) {
476 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
477 $avalue[$matches[1]] = $matches[2];
480 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
481 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
482 $lres = sqlStatement("SELECT * FROM list_options " .
483 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
484 echo "<table cellpadding='0' cellspacing='0'>";
485 while ($lrow = sqlFetchArray($lres)) {
486 $option_id = $lrow['option_id'];
487 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
488 $restype = substr($avalue[$option_id], 0, 1);
489 $resnote = substr($avalue[$option_id], 2);
491 // Added 5-09 by BM - Translate label if applicable
492 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
494 $option_id = htmlspecialchars( $option_id, ENT_QUOTES
);
495 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]' id='check_{$field_id_esc}[$option_id_esc]' value='1'";
496 if ($restype) echo " checked";
497 echo " /> </td>";
498 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
499 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
500 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
501 echo "<td><input type='text'" .
502 " name='form_{$field_id_esc}[$option_id_esc]'" .
503 " id='form_{$field_id_esc}[$option_id_esc]'" .
504 " size='$fldlength'" .
505 " maxlength='$maxlength'" .
506 " value='$resnote' /></td>";
512 // single-selection list with ability to add to it
513 else if ($data_type == 26) {
514 echo "<select class='addtolistclass_$list_id_esc' name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
515 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES
) . "</option>";
516 $lres = sqlStatement("SELECT * FROM list_options " .
517 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
518 $got_selected = FALSE;
519 while ($lrow = sqlFetchArray($lres)) {
520 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES
);
521 echo "<option value='$optionValue'";
522 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
523 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
526 $got_selected = TRUE;
528 // Added 5-09 by BM - Translate label if applicable
529 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . "</option>\n";
531 if (!$got_selected && strlen($currvalue) > 0) {
532 echo "<option value='$currescaped' selected>* $currescaped *</option>";
534 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES
);
535 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
536 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
541 // show the add button if user has access to correct list
542 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES
);
543 $outputAddButton = "<input type='button' id='addtolistid_".$list_id_esc."' fieldid='form_".$field_id_esc."' class='addtolist' value='$inputValue'>";
544 if (aco_exist('lists', $list_id)) {
545 // a specific aco exist for this list, so ensure access
546 if (acl_check('lists', $list_id)) echo $outputAddButton;
549 // no specific aco exist for this list, so check for access to 'default' list
550 if (acl_check('lists', 'default')) echo $outputAddButton;
554 // a set of labeled radio buttons
555 else if ($data_type == 27) {
556 // In this special case, fld_length is the number of columns generated.
557 $cols = max(1, $frow['fld_length']);
558 $lres = sqlStatement("SELECT * FROM list_options " .
559 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
560 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
561 $tdpct = (int) (100 / $cols);
562 $got_selected = FALSE;
563 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
564 $option_id = $lrow['option_id'];
565 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
566 if ($count %
$cols == 0) {
567 if ($count) echo "</tr>";
570 echo "<td width='$tdpct%'>";
571 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]' value='$option_id_esc'";
572 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
573 (strlen($currvalue) > 0 && $option_id == $currvalue))
576 $got_selected = TRUE;
578 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
583 if ($count > $cols) {
584 // Add some space after multiple rows of radio buttons.
585 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
586 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
590 if (!$got_selected && strlen($currvalue) > 0) {
591 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES
);
592 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
593 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
597 // special case for history of lifestyle status; 3 radio buttons and a date text field:
598 // VicarePlus :: A selection list box for smoking status:
599 else if ($data_type == 28 ||
$data_type == 32) {
600 $tmp = explode('|', $currvalue);
601 switch(count($tmp)) {
620 $resdate = $restype = "";
623 $restype = $resdate = $resnote = "";
626 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
627 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
629 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
630 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
631 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
632 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
633 echo "<table cellpadding='0' cellspacing='0'>";
635 if ($data_type == 28)
638 echo "<td><input type='text'" .
639 " name='form_$field_id_esc'" .
640 " id='form_$field_id_esc'" .
641 " size='$fldlength'" .
642 " maxlength='$maxlength'" .
643 " value='$resnote' /> </td>";
644 echo "<td class='bold'> ".
645 " ".
646 htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
648 else if($data_type == 32)
651 echo "<tr><td><input type='text'" .
652 " name='form_text_$field_id_esc'" .
653 " id='form_text_$field_id_esc'" .
654 " size='$fldlength'" .
655 " maxlength='$maxlength'" .
656 " value='$resnote' /> </td></tr>";
658 //Selection list for smoking status
659 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
660 echo generate_select_list("form_$field_id", $list_id, $reslist,
661 $description, $showEmpty ?
$empty_title : '', '', $onchange)."</td>";
662 echo "<td class='bold'> ".htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
665 echo "<td><input type='radio'" .
666 " name='radio_{$field_id_esc}'" .
667 " id='radio_{$field_id_esc}[current]'" .
668 " value='current".$field_id_esc."'";
669 if ($restype == "current".$field_id) echo " checked";
670 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Current'), ENT_NOQUOTES
)." </td>";
672 echo "<td><input type='radio'" .
673 " name='radio_{$field_id_esc}'" .
674 " id='radio_{$field_id_esc}[quit]'" .
675 " value='quit".$field_id_esc."'";
676 if ($restype == "quit".$field_id) echo " checked";
677 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Quit'), ENT_NOQUOTES
)." </td>";
679 echo "<td><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
680 " value='$resdate'" .
681 " title='$description'" .
682 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
683 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
684 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
685 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES
) . "' /> </td>";
686 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
688 echo "<td><input type='radio'" .
689 " name='radio_{$field_id_esc}'" .
690 " id='radio_{$field_id_esc}[never]'" .
691 " value='never".$field_id_esc."'";
692 if ($restype == "never".$field_id) echo " checked";
693 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Never'), ENT_NOQUOTES
)." </td>";
695 echo "<td><input type='radio'" .
696 " name='radio_{$field_id}'" .
697 " id='radio_{$field_id}[not_applicable]'" .
698 " value='not_applicable".$field_id."'";
699 if ($restype == "not_applicable".$field_id) echo " checked";
700 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('N/A'), ENT_QUOTES
)." </td>";
705 // static text. read-only, of course.
706 else if ($data_type == 31) {
707 echo nl2br($frow['description']);
710 //VicarePlus :: A single selection list for Race and Ethnicity, which is specialized to check the 'ethrace' list if the entry does not exist in the list_id of the given list. At some point in the future (when able to input two lists via the layouts engine), this function could be expanded to allow using any list as a backup entry.
711 else if ($data_type == 33) {
712 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
713 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES
) . "</option>";
714 $lres = sqlStatement("SELECT * FROM list_options " .
715 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
716 $got_selected = FALSE;
717 while ($lrow = sqlFetchArray($lres)) {
718 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES
);
719 echo "<option value='$optionValue'";
720 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
721 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
724 $got_selected = TRUE;
727 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . "</option>\n";
729 if (!$got_selected && strlen($currvalue) > 0)
731 //Check 'ethrace' list if the entry does not exist in the list_id of the given list(Race or Ethnicity).
733 $lrow = sqlQuery("SELECT title FROM list_options " .
734 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
737 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
738 echo "<option value='$currvalue' selected> $s </option>";
743 echo "<option value='$currescaped' selected>* $currescaped *</option>";
745 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES
);
746 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
747 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
756 function generate_print_field($frow, $currvalue) {
757 global $rootdir, $date_init;
759 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
761 $data_type = $frow['data_type'];
762 $field_id = $frow['field_id'];
763 $list_id = $frow['list_id'];
764 $fld_length = $frow['fld_length'];
766 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
768 // Can pass $frow['empty_title'] with this variable, otherwise
769 // will default to 'Unassigned'.
770 // If it is 'SKIP' then an empty text title is completely skipped.
772 if (isset($frow['empty_title'])) {
773 if ($frow['empty_title'] == "SKIP") {
774 //do not display an 'empty' choice
776 $empty_title = "Unassigned";
779 $empty_title = $frow['empty_title'];
783 $empty_title = "Unassigned";
786 // generic single-selection list
787 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33) {
788 if (empty($fld_length)) {
789 if ($list_id == 'titles') {
797 $lrow = sqlQuery("SELECT title FROM list_options " .
798 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
799 $tmp = xl_list_label($lrow['title']);
800 if (empty($tmp)) $tmp = "($currvalue)";
802 /*****************************************************************
803 echo "<input type='text'" .
804 " size='$fld_length'" .
808 *****************************************************************/
809 if ($tmp === '') { $tmp = ' '; }
810 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
815 else if ($data_type == 2 ||
$data_type == 15) {
816 /*****************************************************************
817 echo "<input type='text'" .
818 " size='$fld_length'" .
819 " value='$currescaped'" .
822 *****************************************************************/
823 if ($currescaped === '') $currescaped = ' ';
827 // long or multi-line text field
828 else if ($data_type == 3) {
829 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES
);
830 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
832 " cols='$fldlength'" .
833 " rows='$maxlength'>" .
834 $currescaped . "</textarea>";
838 else if ($data_type == 4) {
839 /*****************************************************************
840 echo "<input type='text' size='10'" .
841 " value='$currescaped'" .
842 " title='$description'" .
845 *****************************************************************/
846 if ($currvalue === '') { $tmp = oeFormatShortDate(' '); }
847 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES
); }
852 else if ($data_type == 10 ||
$data_type == 11) {
855 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
856 "WHERE id = ?", array($currvalue) );
857 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
858 if (empty($tmp)) $tmp = "($currvalue)";
860 /*****************************************************************
861 echo "<input type='text'" .
862 " size='$fld_length'" .
866 *****************************************************************/
867 if ($tmp === '') { $tmp = ' '; }
868 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
873 else if ($data_type == 12) {
876 $pres = get_pharmacies();
877 while ($prow = sqlFetchArray($pres)) {
879 if ($currvalue == $key) {
880 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
881 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
882 $prow['line1'] . ' / ' . $prow['city'];
885 if (empty($tmp)) $tmp = "($currvalue)";
887 /*****************************************************************
888 echo "<input type='text'" .
889 " size='$fld_length'" .
893 *****************************************************************/
894 if ($tmp === '') { $tmp = ' '; }
895 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
900 else if ($data_type == 13) {
903 $squads = acl_get_squads();
905 foreach ($squads as $key => $value) {
906 if ($currvalue == $key) {
911 if (empty($tmp)) $tmp = "($currvalue)";
913 /*****************************************************************
914 echo "<input type='text'" .
915 " size='$fld_length'" .
919 *****************************************************************/
920 if ($tmp === '') { $tmp = ' '; }
921 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
926 else if ($data_type == 14) {
929 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
930 "WHERE id = ?", array($currvalue) );
931 $uname = $urow['lname'];
932 if ($urow['fname']) $uname .= ", " . $urow['fname'];
934 if (empty($tmp)) $tmp = "($currvalue)";
936 /*****************************************************************
937 echo "<input type='text'" .
938 " size='$fld_length'" .
942 *****************************************************************/
943 if ($tmp === '') { $tmp = ' '; }
944 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
948 // a set of labeled checkboxes
949 else if ($data_type == 21) {
950 // In this special case, fld_length is the number of columns generated.
951 $cols = max(1, $fld_length);
952 $avalue = explode('|', $currvalue);
953 $lres = sqlStatement("SELECT * FROM list_options " .
954 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
955 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
956 $tdpct = (int) (100 / $cols);
957 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
958 $option_id = $lrow['option_id'];
959 if ($count %
$cols == 0) {
960 if ($count) echo "</tr>";
963 echo "<td width='$tdpct%'>";
964 echo "<input type='checkbox'";
965 if (in_array($option_id, $avalue)) echo " checked";
966 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
971 if ($count > $cols) {
972 // Add some space after multiple rows of checkboxes.
973 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
974 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
980 // a set of labeled text input fields
981 else if ($data_type == 22) {
982 $tmp = explode('|', $currvalue);
984 foreach ($tmp as $value) {
985 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
986 $avalue[$matches[1]] = $matches[2];
989 $lres = sqlStatement("SELECT * FROM list_options " .
990 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
991 echo "<table cellpadding='0' cellspacing='0'>";
992 while ($lrow = sqlFetchArray($lres)) {
993 $option_id = $lrow['option_id'];
994 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
995 $fldlength = empty($fld_length) ?
20 : $fld_length;
996 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
997 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
998 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
999 echo "<td><input type='text'" .
1000 " size='$fldlength'" .
1001 " value='$inputValue'" .
1008 // a set of exam results; 3 radio buttons and a text field:
1009 else if ($data_type == 23) {
1010 $tmp = explode('|', $currvalue);
1012 foreach ($tmp as $value) {
1013 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1014 $avalue[$matches[1]] = $matches[2];
1017 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
1018 $fldlength = empty($fld_length) ?
20 : $fld_length;
1019 $lres = sqlStatement("SELECT * FROM list_options " .
1020 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1021 echo "<table cellpadding='0' cellspacing='0'>";
1022 echo "<tr><td> </td><td class='bold'>" .
1023 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
1024 " </td><td class='bold'>" .
1025 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
1026 "<td class='bold'>" .
1027 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
1028 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
1029 while ($lrow = sqlFetchArray($lres)) {
1030 $option_id = $lrow['option_id'];
1031 $restype = substr($avalue[$option_id], 0, 1);
1032 $resnote = substr($avalue[$option_id], 2);
1033 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1034 for ($i = 0; $i < 3; ++
$i) {
1035 echo "<td><input type='radio'";
1036 if ($restype === "$i") echo " checked";
1039 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1040 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1041 echo "<td><input type='text'" .
1042 " size='$fldlength'" .
1043 " value='$resnote'" .
1044 " class='under' /></td>" .
1050 // the list of active allergies for the current patient
1051 // this is read-only!
1052 else if ($data_type == 24) {
1053 $query = "SELECT title, comments FROM lists WHERE " .
1054 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1056 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1058 while ($lrow = sqlFetchArray($lres)) {
1059 if ($count++
) echo "<br />";
1060 echo htmlspecialchars( $lrow['title'], ENT_QUOTES
);
1061 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES
);
1065 // a set of labeled checkboxes, each with a text field:
1066 else if ($data_type == 25) {
1067 $tmp = explode('|', $currvalue);
1069 foreach ($tmp as $value) {
1070 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1071 $avalue[$matches[1]] = $matches[2];
1074 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
1075 $fldlength = empty($fld_length) ?
20 : $fld_length;
1076 $lres = sqlStatement("SELECT * FROM list_options " .
1077 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1078 echo "<table cellpadding='0' cellspacing='0'>";
1079 while ($lrow = sqlFetchArray($lres)) {
1080 $option_id = $lrow['option_id'];
1081 $restype = substr($avalue[$option_id], 0, 1);
1082 $resnote = substr($avalue[$option_id], 2);
1083 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1084 echo "<td><input type='checkbox'";
1085 if ($restype) echo " checked";
1086 echo " /> </td>";
1087 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1088 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1089 echo "<td><input type='text'" .
1090 " size='$fldlength'" .
1091 " value='$resnote'" .
1099 // a set of labeled radio buttons
1100 else if ($data_type == 27) {
1101 // In this special case, fld_length is the number of columns generated.
1102 $cols = max(1, $frow['fld_length']);
1103 $lres = sqlStatement("SELECT * FROM list_options " .
1104 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1105 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1106 $tdpct = (int) (100 / $cols);
1107 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1108 $option_id = $lrow['option_id'];
1109 if ($count %
$cols == 0) {
1110 if ($count) echo "</tr>";
1113 echo "<td width='$tdpct%'>";
1114 echo "<input type='radio'";
1115 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1116 (strlen($currvalue) > 0 && $option_id == $currvalue))
1120 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
1125 if ($count > $cols) {
1126 // Add some space after multiple rows of radio buttons.
1127 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
1128 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1134 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1135 else if ($data_type == 28 ||
$data_type == 32) {
1136 $tmp = explode('|', $currvalue);
1137 switch(count($tmp)) {
1156 $resdate = $restype = "";
1159 $restype = $resdate = $resnote = "";
1162 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
1163 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
1164 echo "<table cellpadding='0' cellspacing='0'>";
1166 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1167 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1168 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
1169 if($data_type == 28)
1171 echo "<td><input type='text'" .
1172 " size='$fldlength'" .
1174 " value='$resnote' /></td>";
1175 echo "<td class='bold'> ".
1176 " ".
1177 htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
1179 else if($data_type == 32)
1181 echo "<tr><td><input type='text'" .
1182 " size='$fldlength'" .
1184 " value='$resnote' /></td></tr>";
1186 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1187 echo "<td><input type='text'" .
1188 " size='$fldlength'" .
1190 " value='$smoking_status_title' /></td>";
1191 echo "<td class='bold'> ".htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
1193 echo "<td><input type='radio'";
1194 if ($restype == "current".$field_id) echo " checked";
1195 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES
)." </td>";
1197 echo "<td><input type='radio'";
1198 if ($restype == "current".$field_id) echo " checked";
1199 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES
)." </td>";
1201 echo "<td><input type='text' size='6'" .
1202 " value='$resdate'" .
1206 echo "<td><input type='radio'";
1207 if ($restype == "current".$field_id) echo " checked";
1208 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES
)."</td>";
1210 echo "<td><input type='radio'";
1211 if ($restype == "not_applicable".$field_id) echo " checked";
1212 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES
)." </td>";
1217 // static text. read-only, of course.
1218 else if ($data_type == 31) {
1219 echo nl2br($frow['description']);
1224 function generate_display_field($frow, $currvalue) {
1225 $data_type = $frow['data_type'];
1226 $field_id = $frow['field_id'];
1227 $list_id = $frow['list_id'];
1230 // generic selection list or the generic selection list with add on the fly
1231 // feature, or radio buttons
1232 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 27 ||
$data_type == 33) {
1233 $lrow = sqlQuery("SELECT title FROM list_options " .
1234 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1235 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1236 //For lists Race and Ethnicity if there is no matching value in the corresponding lists check ethrace list
1237 if ($lrow == 0 && $data_type == 33)
1240 $lrow_ethrace = sqlQuery("SELECT title FROM list_options " .
1241 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1242 $s = htmlspecialchars(xl_list_label($lrow_ethrace['title']),ENT_NOQUOTES
);
1246 // simple text field
1247 else if ($data_type == 2) {
1248 $s = htmlspecialchars($currvalue,ENT_NOQUOTES
);
1251 // long or multi-line text field
1252 else if ($data_type == 3) {
1253 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES
));
1257 else if ($data_type == 4) {
1258 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES
);
1262 else if ($data_type == 10 ||
$data_type == 11) {
1263 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1264 "WHERE id = ?", array($currvalue) );
1265 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES
);
1269 else if ($data_type == 12) {
1270 $pres = get_pharmacies();
1271 while ($prow = sqlFetchArray($pres)) {
1273 if ($currvalue == $key) {
1274 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1275 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1276 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES
);
1282 else if ($data_type == 13) {
1283 $squads = acl_get_squads();
1285 foreach ($squads as $key => $value) {
1286 if ($currvalue == $key) {
1287 $s .= htmlspecialchars($value[3],ENT_NOQUOTES
);
1294 else if ($data_type == 14) {
1295 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1296 "WHERE id = ?", array($currvalue));
1297 $uname = $urow['lname'];
1298 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1299 $s = htmlspecialchars($uname,ENT_NOQUOTES
);
1303 else if ($data_type == 15) {
1304 $s = htmlspecialchars($currvalue,ENT_NOQUOTES
);
1307 // a set of labeled checkboxes
1308 else if ($data_type == 21) {
1309 $avalue = explode('|', $currvalue);
1310 $lres = sqlStatement("SELECT * FROM list_options " .
1311 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1313 while ($lrow = sqlFetchArray($lres)) {
1314 $option_id = $lrow['option_id'];
1315 if (in_array($option_id, $avalue)) {
1316 if ($count++
) $s .= "<br />";
1318 // Added 5-09 by BM - Translate label if applicable
1319 $s .= htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1325 // a set of labeled text input fields
1326 else if ($data_type == 22) {
1327 $tmp = explode('|', $currvalue);
1329 foreach ($tmp as $value) {
1330 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1331 $avalue[$matches[1]] = $matches[2];
1334 $lres = sqlStatement("SELECT * FROM list_options " .
1335 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1336 $s .= "<table cellpadding='0' cellspacing='0'>";
1337 while ($lrow = sqlFetchArray($lres)) {
1338 $option_id = $lrow['option_id'];
1339 if (empty($avalue[$option_id])) continue;
1341 // Added 5-09 by BM - Translate label if applicable
1342 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . ": </td>";
1344 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES
) . "</td></tr>";
1349 // a set of exam results; 3 radio buttons and a text field:
1350 else if ($data_type == 23) {
1351 $tmp = explode('|', $currvalue);
1353 foreach ($tmp as $value) {
1354 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1355 $avalue[$matches[1]] = $matches[2];
1358 $lres = sqlStatement("SELECT * FROM list_options " .
1359 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1360 $s .= "<table cellpadding='0' cellspacing='0'>";
1361 while ($lrow = sqlFetchArray($lres)) {
1362 $option_id = $lrow['option_id'];
1363 $restype = substr($avalue[$option_id], 0, 1);
1364 $resnote = substr($avalue[$option_id], 2);
1365 if (empty($restype) && empty($resnote)) continue;
1367 // Added 5-09 by BM - Translate label if applicable
1368 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1370 $restype = ($restype == '1') ?
xl('Normal') : (($restype == '2') ?
xl('Abnormal') : xl('N/A'));
1371 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1372 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1373 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . " </td>";
1374 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td>";
1380 // the list of active allergies for the current patient
1381 else if ($data_type == 24) {
1382 $query = "SELECT title, comments FROM lists WHERE " .
1383 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1385 // echo "<!-- $query -->\n"; // debugging
1386 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1388 while ($lrow = sqlFetchArray($lres)) {
1389 if ($count++
) $s .= "<br />";
1390 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES
);
1391 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES
) . ')';
1395 // a set of labeled checkboxes, each with a text field:
1396 else if ($data_type == 25) {
1397 $tmp = explode('|', $currvalue);
1399 foreach ($tmp as $value) {
1400 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1401 $avalue[$matches[1]] = $matches[2];
1404 $lres = sqlStatement("SELECT * FROM list_options " .
1405 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1406 $s .= "<table cellpadding='0' cellspacing='0'>";
1407 while ($lrow = sqlFetchArray($lres)) {
1408 $option_id = $lrow['option_id'];
1409 $restype = substr($avalue[$option_id], 0, 1);
1410 $resnote = substr($avalue[$option_id], 2);
1411 if (empty($restype) && empty($resnote)) continue;
1413 // Added 5-09 by BM - Translate label if applicable
1414 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1416 $restype = $restype ?
xl('Yes') : xl('No');
1417 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . "</td></tr>";
1418 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td></tr>";
1424 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1425 // VicarePlus :: A selection list for smoking status.
1426 else if ($data_type == 28 ||
$data_type == 32) {
1427 $tmp = explode('|', $currvalue);
1428 switch(count($tmp)) {
1447 $resdate = $restype = "";
1450 $restype = $resdate = $resnote = "";
1453 $s .= "<table cellpadding='0' cellspacing='0'>";
1457 if ($restype == "current".$field_id) $res = xl('Current');
1458 if ($restype == "quit".$field_id) $res = xl('Quit');
1459 if ($restype == "never".$field_id) $res = xl('Never');
1460 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1461 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1462 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1463 if ($data_type == 28)
1465 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . " </td>";
1467 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1468 else if ($data_type == 32)
1470 if (!empty($reslist)) $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist) . " </td>";
1471 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . " </td>";
1474 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES
) . "</b>: " . htmlspecialchars($res,ENT_NOQUOTES
) . " </td>";
1475 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES
) . " </td>";
1480 // static text. read-only, of course.
1481 else if ($data_type == 31) {
1482 $s .= nl2br($frow['description']);
1488 $CPR = 4; // cells per row of generic data
1493 function disp_end_cell() {
1494 global $item_count, $cell_count;
1495 if ($item_count > 0) {
1501 function disp_end_row() {
1502 global $cell_count, $CPR;
1504 if ($cell_count > 0) {
1505 for (; $cell_count < $CPR; ++
$cell_count) echo "<td></td>";
1511 function disp_end_group() {
1513 if (strlen($last_group) > 0) {
1518 function display_layout_rows($formtype, $result1, $result2='') {
1519 global $item_count, $cell_count, $last_group, $CPR;
1521 $fres = sqlStatement("SELECT * FROM layout_options " .
1522 "WHERE form_id = ? AND uor > 0 " .
1523 "ORDER BY group_name, seq", array($formtype) );
1525 while ($frow = sqlFetchArray($fres)) {
1526 $this_group = $frow['group_name'];
1527 $titlecols = $frow['titlecols'];
1528 $datacols = $frow['datacols'];
1529 $data_type = $frow['data_type'];
1530 $field_id = $frow['field_id'];
1531 $list_id = $frow['list_id'];
1534 if ($formtype == 'DEM') {
1535 if ($GLOBALS['athletic_team']) {
1536 // Skip fitness level and return-to-play date because those appear
1537 // in a special display/update form on this page.
1538 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
1540 if (strpos($field_id, 'em_') === 0) {
1541 // Skip employer related fields, if it's disabled.
1542 if ($GLOBALS['omit_employers']) continue;
1543 $tmp = substr($field_id, 3);
1544 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1547 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1551 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1554 // Handle a data category (group) change.
1555 if (strcmp($this_group, $last_group) != 0) {
1556 $group_name = substr($this_group, 1);
1557 // totally skip generating the employer category, if it's disabled.
1558 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1560 $last_group = $this_group;
1563 // Handle starting of a new row.
1564 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
1568 echo "<td class='groupname'>";
1569 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1570 //echo "<font color='#008800'>$group_name</font>";
1572 // Added 5-09 by BM - Translate label if applicable
1573 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
);
1577 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1578 echo "<td valign='top'> ";
1583 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1585 // Handle starting of a new label cell.
1586 if ($titlecols > 0) {
1588 //echo "<td class='label' colspan='$titlecols' valign='top'";
1589 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
1590 echo "<td class='label' colspan='$titlecols_esc' ";
1591 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1593 $cell_count +
= $titlecols;
1597 // Added 5-09 by BM - Translate label if applicable
1598 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES
); else echo " ";
1600 // Handle starting of a new data cell.
1601 if ($datacols > 0) {
1603 //echo "<td class='text data' colspan='$datacols' valign='top'";
1604 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
1605 echo "<td class='text data' colspan='$datacols_esc'";
1606 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1608 $cell_count +
= $datacols;
1612 echo generate_display_field($frow, $currvalue);
1618 function display_layout_tabs($formtype, $result1, $result2='') {
1619 global $item_count, $cell_count, $last_group, $CPR;
1621 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1622 "WHERE form_id = ? AND uor > 0 " .
1623 "ORDER BY group_name, seq", array($formtype) );
1626 while ($frow = sqlFetchArray($fres)) {
1627 $this_group = $frow['group_name'];
1628 $group_name = substr($this_group, 1);
1630 <li
<?php
echo $first ?
'class="current"' : '' ?
>>
1631 <a href
="/play/javascript-tabbed-navigation/" id
="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES
)."?>">
1632 <?php
echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
); ?
></a
>
1639 function display_layout_tabs_data($formtype, $result1, $result2='') {
1640 global $item_count, $cell_count, $last_group, $CPR;
1642 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1643 "WHERE form_id = ? AND uor > 0 " .
1644 "ORDER BY group_name, seq", array($formtype));
1647 while ($frow = sqlFetchArray($fres)) {
1648 $this_group = $frow['group_name'];
1649 $titlecols = $frow['titlecols'];
1650 $datacols = $frow['datacols'];
1651 $data_type = $frow['data_type'];
1652 $field_id = $frow['field_id'];
1653 $list_id = $frow['list_id'];
1656 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1657 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1658 "ORDER BY seq", array($formtype, $this_group) );
1661 <div
class="tab <?php echo $first ? 'current' : '' ?>">
1662 <table border
='0' cellpadding
='0'>
1665 while ($group_fields = sqlFetchArray($group_fields_query)) {
1667 $titlecols = $group_fields['titlecols'];
1668 $datacols = $group_fields['datacols'];
1669 $data_type = $group_fields['data_type'];
1670 $field_id = $group_fields['field_id'];
1671 $list_id = $group_fields['list_id'];
1674 if ($formtype == 'DEM') {
1675 if ($GLOBALS['athletic_team']) {
1676 // Skip fitness level and return-to-play date because those appear
1677 // in a special display/update form on this page.
1678 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
1680 if (strpos($field_id, 'em_') === 0) {
1681 // Skip employer related fields, if it's disabled.
1682 if ($GLOBALS['omit_employers']) continue;
1683 $tmp = substr($field_id, 3);
1684 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1687 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1691 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1694 // Handle a data category (group) change.
1695 if (strcmp($this_group, $last_group) != 0) {
1696 $group_name = substr($this_group, 1);
1697 // totally skip generating the employer category, if it's disabled.
1698 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1699 $last_group = $this_group;
1702 // Handle starting of a new row.
1703 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
1708 if ($item_count == 0 && $titlecols == 0) {
1712 // Handle starting of a new label cell.
1713 if ($titlecols > 0) {
1715 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
1716 echo "<td class='label' colspan='$titlecols_esc' ";
1718 $cell_count +
= $titlecols;
1722 // Added 5-09 by BM - Translate label if applicable
1723 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES
); else echo " ";
1725 // Handle starting of a new data cell.
1726 if ($datacols > 0) {
1728 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
1729 echo "<td class='text data' colspan='$datacols_esc'";
1731 $cell_count +
= $datacols;
1735 echo generate_display_field($group_fields, $currvalue);
1752 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1753 global $item_count, $cell_count, $last_group, $CPR;
1755 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1756 "WHERE form_id = ? AND uor > 0 " .
1757 "ORDER BY group_name, seq", array($formtype) );
1760 while ($frow = sqlFetchArray($fres)) {
1761 $this_group = $frow['group_name'];
1762 $group_name = substr($this_group, 1);
1763 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES
);
1764 $titlecols = $frow['titlecols'];
1765 $datacols = $frow['datacols'];
1766 $data_type = $frow['data_type'];
1767 $field_id = $frow['field_id'];
1768 $list_id = $frow['list_id'];
1771 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1772 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1773 "ORDER BY seq", array($formtype,$this_group) );
1776 <div
class="tab <?php echo $first ? 'current' : '' ?>" id
="tab_<?php echo $group_name_esc?>" >
1777 <table border
='0' cellpadding
='0'>
1780 while ($group_fields = sqlFetchArray($group_fields_query)) {
1782 $titlecols = $group_fields['titlecols'];
1783 $datacols = $group_fields['datacols'];
1784 $data_type = $group_fields['data_type'];
1785 $field_id = $group_fields['field_id'];
1786 $list_id = $group_fields['list_id'];
1789 if ($formtype == 'DEM') {
1790 if ($GLOBALS['athletic_team']) {
1791 // Skip fitness level and return-to-play date because those appear
1792 // in a special display/update form on this page.
1793 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
1795 if (strpos($field_id, 'em_') === 0) {
1796 // Skip employer related fields, if it's disabled.
1797 if ($GLOBALS['omit_employers']) continue;
1798 $tmp = substr($field_id, 3);
1799 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1802 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1806 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1809 // Handle a data category (group) change.
1810 if (strcmp($this_group, $last_group) != 0) {
1811 $group_name = substr($this_group, 1);
1812 // totally skip generating the employer category, if it's disabled.
1813 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1814 $last_group = $this_group;
1817 // Handle starting of a new row.
1818 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
1823 if ($item_count == 0 && $titlecols == 0) {
1827 // Handle starting of a new label cell.
1828 if ($titlecols > 0) {
1830 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
1831 echo "<td class='label' colspan='$titlecols_esc' ";
1833 $cell_count +
= $titlecols;
1837 // Added 5-09 by BM - Translate label if applicable
1838 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES
).":"); else echo " ";
1840 // Handle starting of a new data cell.
1841 if ($datacols > 0) {
1843 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
1844 echo "<td class='text data' colspan='$datacols_esc'";
1846 $cell_count +
= $datacols;
1850 echo generate_form_field($group_fields, $currvalue);
1864 // From the currently posted HTML form, this gets the value of the
1865 // field corresponding to the provided layout_options table row.
1867 function get_layout_form_value($frow, $maxlength=255) {
1868 // Bring in $sanitize_all_escapes variable, which will decide
1869 // the variable escaping method.
1870 global $sanitize_all_escapes;
1872 $data_type = $frow['data_type'];
1873 $field_id = $frow['field_id'];
1875 if (isset($_POST["form_$field_id"])) {
1876 if ($data_type == 21) {
1877 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1878 // must be concatenated into a |-separated string.
1879 foreach ($_POST["form_$field_id"] as $key => $val) {
1880 if (strlen($value)) $value .= '|';
1884 else if ($data_type == 22) {
1885 // $_POST["form_$field_id"] is an array of text fields to be imploded
1886 // into "key:value|key:value|...".
1887 foreach ($_POST["form_$field_id"] as $key => $val) {
1888 $val = str_replace('|', ' ', $val);
1889 if (strlen($value)) $value .= '|';
1890 $value .= "$key:$val";
1893 else if ($data_type == 23) {
1894 // $_POST["form_$field_id"] is an array of text fields with companion
1895 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1896 foreach ($_POST["form_$field_id"] as $key => $val) {
1897 $restype = $_POST["radio_{$field_id}"][$key];
1898 if (empty($restype)) $restype = '0';
1899 $val = str_replace('|', ' ', $val);
1900 if (strlen($value)) $value .= '|';
1901 $value .= "$key:$restype:$val";
1904 else if ($data_type == 25) {
1905 // $_POST["form_$field_id"] is an array of text fields with companion
1906 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1907 foreach ($_POST["form_$field_id"] as $key => $val) {
1908 $restype = empty($_POST["check_{$field_id}"][$key]) ?
'0' : '1';
1909 $val = str_replace('|', ' ', $val);
1910 if (strlen($value)) $value .= '|';
1911 $value .= "$key:$restype:$val";
1914 else if ($data_type == 28 ||
$data_type == 32) {
1915 // $_POST["form_$field_id"] is an date text fields with companion
1916 // radio buttons to be imploded into "notes|type|date".
1917 $restype = $_POST["radio_{$field_id}"];
1918 if (empty($restype)) $restype = '0';
1919 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1920 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1921 if ($data_type == 32)
1923 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
1924 $reslist = str_replace('|', ' ', $_POST["form_$field_id"]);
1925 $res_text_note = str_replace('|', ' ', $_POST["form_text_$field_id"]);
1926 $value = "$res_text_note|$restype|$resdate|$reslist";
1929 $value = "$resnote|$restype|$resdate";
1932 $value = $_POST["form_$field_id"];
1936 // Better to die than to silently truncate data!
1937 if ($maxlength && $data_type != 3 && strlen($value) > $maxlength)
1938 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES
) .
1939 ":<br /> <br />".htmlspecialchars( $value, ENT_NOQUOTES
));
1941 // Make sure the return value is quote-safe.
1942 if ($sanitize_all_escapes) {
1943 //escapes already removed and using binding/placemarks in sql calls
1944 // so only need to trim value
1945 return trim($value);
1948 //need to explicitly prepare value
1949 return formTrim($value);
1953 // Generate JavaScript validation logic for the required fields.
1955 function generate_layout_validation($form_id) {
1956 $fres = sqlStatement("SELECT * FROM layout_options " .
1957 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
1958 "ORDER BY group_name, seq", array($form_id) );
1960 while ($frow = sqlFetchArray($fres)) {
1961 if ($frow['uor'] < 2) continue;
1962 $data_type = $frow['data_type'];
1963 $field_id = $frow['field_id'];
1964 $fldtitle = $frow['title'];
1965 if (!$fldtitle) $fldtitle = $frow['description'];
1966 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES
);
1967 switch($data_type) {
1976 " if (f.$fldname.selectedIndex <= 0) {\n" .
1977 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1978 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
1981 case 27: // radio buttons
1984 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
1985 " if (i >= f.$fldname.length) {\n" .
1986 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
1994 " if (trimlen(f.$fldname.value) == 0) {\n" .
1995 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1996 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
1997 " $('#" . $fldname . "').attr('style','background:red'); \n" .
1998 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
2000 " $('#" . $fldname . "').attr('style',''); " .
2001 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2009 * DROPDOWN FOR FACILITIES
2011 * build a dropdown with all facilities
2013 * @param string $selected - name of the currently selected facility
2014 * use '0' for "unspecified facility"
2015 * use '' for "All facilities" (the default)
2016 * @param string $name - the name/id for select form (defaults to "form_facility")
2017 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2019 * @return void - just echo the html encoded string
2021 * Note: This should become a data-type at some point, according to Brady
2023 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true) {
2024 $have_selected = false;
2025 $query = "SELECT id, name FROM facility ORDER BY name";
2026 $fres = sqlStatement($query);
2028 $name = htmlspecialchars($name, ENT_QUOTES
);
2029 echo " <select name=\"$name\">\n";
2032 $option_selected_attr = '';
2033 if ($selected == '') {
2034 $option_selected_attr = ' selected="selected"';
2035 $have_selected = true;
2037 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES
);
2038 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2040 while ($frow = sqlFetchArray($fres)) {
2041 $facility_id = $frow['id'];
2042 $option_value = htmlspecialchars($facility_id, ENT_QUOTES
);
2043 $option_selected_attr = '';
2044 if ($selected == $facility_id) {
2045 $option_selected_attr = ' selected="selected"';
2046 $have_selected = true;
2048 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES
);
2049 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2052 if ($allow_unspecified) {
2053 $option_value = '0';
2054 $option_selected_attr = '';
2055 if ( $selected == '0' ) {
2056 $option_selected_attr = ' selected="selected"';
2057 $have_selected = true;
2059 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
2060 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2063 if (!$have_selected) {
2064 $option_value = htmlspecialchars($selected, ENT_QUOTES
);
2065 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES
);
2066 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES
);
2067 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2069 echo " </select>\n";
2072 // Expand Collapse Widget
2073 // This forms the header and functionality component of the widget. The information that is displayed
2074 // then follows this function followed by a closing div tag
2076 // $title is the title of the section (already translated)
2077 // $label is identifier used in the tag id's and sql columns
2078 // $buttonLabel is the button label text (already translated)
2079 // $buttonLink is the button link information
2080 // $buttonClass is any additional needed class elements for the button tag
2081 // $linkMethod is the button link method ('javascript' vs 'html')
2082 // $bodyClass is to set class(es) of the body
2083 // $auth is a flag to decide whether to show the button
2084 // $fixedWidth is to flag whether width is fixed
2085 // $forceExpandAlways is a flag to force the widget to always be expanded
2087 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2089 echo "<div class='section-header'>";
2092 echo "<div class='section-header-dynamic'>";
2096 // show button, since authorized
2097 // first prepare class string
2099 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES
);
2102 $class_string = "css_button_small";
2104 // next, create the link
2105 if ($linkMethod == "javascript") {
2106 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2109 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'" .
2110 " onclick='top.restoreSession()'";
2112 if (!$GLOBALS['concurrent_layout']) {
2113 echo " target='Main'";
2116 htmlspecialchars( $buttonLabel, ENT_NOQUOTES
) . "</span></a></td>";
2118 if ($forceExpandAlways){
2119 // Special case to force the widget to always be expanded
2120 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES
) . "</b></span>";
2121 $indicatorTag ="style='display:none'";
2123 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2124 htmlspecialchars( $label, ENT_QUOTES
) . "_ps_expand\")'><span class='text'><b>";
2125 echo htmlspecialchars( $title, ENT_NOQUOTES
) . "</b></span>";
2126 if (getUserSetting($label."_ps_expand")) {
2127 $text = xl('collapse');
2130 $text = xl('expand');
2132 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES
) .
2133 "</span>)</a></td>";
2134 echo "</tr></table>";
2136 if ($forceExpandAlways) {
2137 // Special case to force the widget to always be expanded
2140 else if (getUserSetting($label."_ps_expand")) {
2144 $styling = "style='display:none'";
2147 $styling .= " class='" . $bodyClass . "'";
2149 //next, create the first div tag to hold the information
2150 // note the code that calls this function will then place the ending div tag after the data
2151 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES
) . "_ps_expand' " . $styling . ">";
2154 //billing_facility fuction will give the dropdown list which contain billing faciliies.
2155 function billing_facility($name,$select){
2156 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
2157 echo " <select id='".htmlspecialchars($name, ENT_QUOTES
)."' name='".htmlspecialchars($name, ENT_QUOTES
)."'>";
2158 while ($facrow = sqlFetchArray($qsql)) {
2159 $selected = ( $facrow['id'] == $select ) ?
'selected="selected"' : '' ;
2160 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES
)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES
)."</option>";