sql-injection fix in demographics
[openemr.git] / library / options.inc.php
blob3a40a65acf57fa00a5203e866fc4deabf71e5d69
1 <?php
2 // Copyright (C) 2007-2013 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>
5 //
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 // T = Use description as default Text
30 // U = Capitalize all letters (text fields)
31 // V = Vendor types only (address book)
32 // 1 = Write Once (not editable when not empty) (text fields)
34 require_once("formdata.inc.php");
35 require_once("formatting.inc.php");
36 require_once("user.inc");
38 $date_init = "";
40 function get_pharmacies() {
41 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
42 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
43 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
44 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
45 "AND p.type = 2 " .
46 "ORDER BY name, area_code, prefix, number");
49 // Function to generate a drop-list.
51 function generate_select_list($tag_name, $list_id, $currvalue, $title,
52 $empty_name=' ', $class='', $onchange='', $tag_id = '', $custom_attributes = null )
54 $s = '';
55 $tag_name_esc = htmlspecialchars( $tag_name, ENT_QUOTES);
56 $s .= "<select name='$tag_name_esc'";
57 $tag_id_esc = $tag_name_esc;
58 if ( $tag_id != '' ) {
59 $tag_id_esc = htmlspecialchars( $tag_id, ENT_QUOTES);
61 $s .= " id='$tag_id_esc'";
62 if ($class) $s .= " class='$class'";
63 if ($onchange) $s .= " onchange='$onchange'";
64 if ( $custom_attributes != null && is_array($custom_attributes) ) {
65 foreach ( $custom_attributes as $attr => $val ) {
66 if ( isset($custom_attributes[$attr] ) ) {
67 $s .= " ".htmlspecialchars( $attr, ENT_QUOTES)."='".htmlspecialchars( $val, ENT_QUOTES)."'";
71 $selectTitle = htmlspecialchars( $title, ENT_QUOTES);
72 $s .= " title='$selectTitle'>";
73 $selectEmptyName = htmlspecialchars( xl($empty_name), ENT_NOQUOTES);
74 if ($empty_name) $s .= "<option value=''>" . $selectEmptyName . "</option>";
75 $lres = sqlStatement("SELECT * FROM list_options " .
76 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
77 $got_selected = FALSE;
78 while ($lrow = sqlFetchArray($lres)) {
79 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
80 $s .= "<option value='$optionValue'";
81 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
82 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
84 $s .= " selected";
85 $got_selected = TRUE;
87 $optionLabel = htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
88 $s .= ">$optionLabel</option>\n";
90 if (!$got_selected && strlen($currvalue) > 0) {
91 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
92 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
93 $s .= "</select>";
94 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_QUOTES);
95 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
96 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
98 else {
99 $s .= "</select>";
101 return $s;
104 // $frow is a row from the layout_options table.
105 // $currvalue is the current value, if any, of the associated item.
107 function generate_form_field($frow, $currvalue) {
108 global $rootdir, $date_init;
110 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
112 $data_type = $frow['data_type'];
113 $field_id = $frow['field_id'];
114 $list_id = $frow['list_id'];
115 // escaped variables to use in html
116 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
117 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
119 // Added 5-09 by BM - Translate description if applicable
120 $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
122 // Support edit option T which assigns the (possibly very long) description as
123 // the default value.
124 if (strpos($frow['edit_options'], 'T') !== FALSE) {
125 if (strlen($currescaped) == 0) $currescaped = $description;
126 // Description used in this way is not suitable as a title.
127 $description = '';
130 // added 5-2009 by BM to allow modification of the 'empty' text title field.
131 // Can pass $frow['empty_title'] with this variable, otherwise
132 // will default to 'Unassigned'.
133 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
134 // if make $frow['empty_title'] equal to 'SKIP'
135 $showEmpty = true;
136 if (isset($frow['empty_title'])) {
137 if ($frow['empty_title'] == "SKIP") {
138 //do not display an 'empty' choice
139 $showEmpty = false;
140 $empty_title = "Unassigned";
142 else {
143 $empty_title = $frow['empty_title'];
146 else {
147 $empty_title = "Unassigned";
150 // generic single-selection list
151 if ($data_type == 1) {
152 echo generate_select_list("form_$field_id", $list_id, $currvalue,
153 $description, $showEmpty ? $empty_title : '');
156 // simple text field
157 else if ($data_type == 2) {
158 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
159 $maxlength = $frow['max_length'];
160 $string_maxlength = "";
161 // if max_length is set to zero, then do not set a maxlength
162 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
163 echo "<input type='text'" .
164 " name='form_$field_id_esc'" .
165 " id='form_$field_id_esc'" .
166 " size='$fldlength'" .
167 " $string_maxlength" .
168 " title='$description'" .
169 " value='$currescaped'";
170 if (strpos($frow['edit_options'], 'C') !== FALSE)
171 echo " onchange='capitalizeMe(this)'";
172 else if (strpos($frow['edit_options'], 'U') !== FALSE)
173 echo " onchange='this.value = this.value.toUpperCase()'";
174 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
175 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
176 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
177 echo " onblur='maskblur(this,\"$tmp\")'";
179 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0)
180 echo " readonly";
181 echo " />";
184 // long or multi-line text field
185 else if ($data_type == 3) {
186 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
187 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
188 echo "<textarea" .
189 " name='form_$field_id_esc'" .
190 " id='form_$field_id_esc'" .
191 " title='$description'" .
192 " cols='$textCols'" .
193 " rows='$textRows'>" .
194 $currescaped . "</textarea>";
197 // date
198 else if ($data_type == 4) {
199 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
200 " value='$currescaped'" .
201 " title='$description'" .
202 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
203 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
204 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
205 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
206 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
209 // provider list, local providers only
210 else if ($data_type == 10) {
211 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
212 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
213 "AND authorized = 1 " .
214 "ORDER BY lname, fname");
215 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
216 echo "<option value=''>" . htmlspecialchars(xl($empty_title), ENT_NOQUOTES) . "</option>";
217 while ($urow = sqlFetchArray($ures)) {
218 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
219 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
220 echo "<option value='$optionId'";
221 if ($urow['id'] == $currvalue) echo " selected";
222 echo ">$uname</option>";
224 echo "</select>";
227 // provider list, including address book entries with an NPI number
228 else if ($data_type == 11) {
229 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
230 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
231 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
232 "ORDER BY lname, fname");
233 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
234 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
235 while ($urow = sqlFetchArray($ures)) {
236 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
237 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
238 echo "<option value='$optionId'";
239 if ($urow['id'] == $currvalue) echo " selected";
240 echo ">$uname</option>";
242 echo "</select>";
245 // pharmacy list
246 else if ($data_type == 12) {
247 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
248 echo "<option value='0'></option>";
249 $pres = get_pharmacies();
250 while ($prow = sqlFetchArray($pres)) {
251 $key = $prow['id'];
252 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
253 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
254 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
255 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
256 echo "<option value='$optionValue'";
257 if ($currvalue == $key) echo " selected";
258 echo ">$optionLabel</option>";
260 echo "</select>";
263 // squads
264 else if ($data_type == 13) {
265 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
266 echo "<option value=''>&nbsp;</option>";
267 $squads = acl_get_squads();
268 if ($squads) {
269 foreach ($squads as $key => $value) {
270 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
271 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
272 echo "<option value='$optionValue'";
273 if ($currvalue == $key) echo " selected";
274 echo ">$optionLabel</option>\n";
277 echo "</select>";
280 // Address book, preferring organization name if it exists and is not in
281 // parentheses, and excluding local users who are not providers.
282 // Supports "referred to" practitioners and facilities.
283 // Alternatively the letter L in edit_options means that abook_type
284 // must be "ord_lab", indicating types used with the procedure
285 // lab ordering system.
286 // Alternatively the letter O in edit_options means that abook_type
287 // must begin with "ord_", indicating types used with the procedure
288 // ordering system.
289 // Alternatively the letter V in edit_options means that abook_type
290 // must be "vendor", indicating the Vendor type.
291 // Alternatively the letter R in edit_options means that abook_type
292 // must be "dist", indicating the Distributor type.
293 else if ($data_type == 14) {
294 if (strpos($frow['edit_options'], 'L') !== FALSE)
295 $tmp = "abook_type = 'ord_lab'";
296 else if (strpos($frow['edit_options'], 'O') !== FALSE)
297 $tmp = "abook_type LIKE 'ord\\_%'";
298 else if (strpos($frow['edit_options'], 'V') !== FALSE)
299 $tmp = "abook_type LIKE 'vendor%'";
300 else if (strpos($frow['edit_options'], 'R') !== FALSE)
301 $tmp = "abook_type LIKE 'dist'";
302 else
303 $tmp = "( username = '' OR authorized = 1 )";
304 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
305 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
306 "AND $tmp " .
307 "ORDER BY organization, lname, fname");
308 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
309 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
310 while ($urow = sqlFetchArray($ures)) {
311 $uname = $urow['organization'];
312 if (empty($uname) || substr($uname, 0, 1) == '(') {
313 $uname = $urow['lname'];
314 if ($urow['fname']) $uname .= ", " . $urow['fname'];
316 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
317 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
318 echo "<option value='$optionValue'";
319 $title = $urow['username'] ? xl('Local') : xl('External');
320 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
321 echo " title='$optionTitle'";
322 if ($urow['id'] == $currvalue) echo " selected";
323 echo ">$optionLabel</option>";
325 echo "</select>";
328 // a billing code
329 else if ($data_type == 15) {
330 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
331 $maxlength = $frow['max_length'];
332 $string_maxlength = "";
333 // if max_length is set to zero, then do not set a maxlength
334 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
335 echo "<input type='text'" .
336 " name='form_$field_id_esc'" .
337 " id='form_related_code'" .
338 " size='$fldlength'" .
339 " $string_maxlength" .
340 " title='$description'" .
341 " value='$currescaped'" .
342 " onclick='sel_related(this)' readonly" .
343 " />";
346 // a set of labeled checkboxes
347 else if ($data_type == 21) {
348 // In this special case, fld_length is the number of columns generated.
349 $cols = max(1, $frow['fld_length']);
350 $avalue = explode('|', $currvalue);
351 $lres = sqlStatement("SELECT * FROM list_options " .
352 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
353 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
354 $tdpct = (int) (100 / $cols);
355 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
356 $option_id = $lrow['option_id'];
357 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
358 // if ($count) echo "<br />";
359 if ($count % $cols == 0) {
360 if ($count) echo "</tr>";
361 echo "<tr>";
363 echo "<td width='$tdpct%'>";
364 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]' id='form_{$field_id_esc}[$option_id_esc]' value='1'";
365 if (in_array($option_id, $avalue)) echo " checked";
367 // Added 5-09 by BM - Translate label if applicable
368 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
370 echo "</td>";
372 if ($count) {
373 echo "</tr>";
374 if ($count > $cols) {
375 // Add some space after multiple rows of checkboxes.
376 $cols = htmlspecialchars( $cols, ENT_QUOTES);
377 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
380 echo "</table>";
383 // a set of labeled text input fields
384 else if ($data_type == 22) {
385 $tmp = explode('|', $currvalue);
386 $avalue = array();
387 foreach ($tmp as $value) {
388 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
389 $avalue[$matches[1]] = $matches[2];
392 $lres = sqlStatement("SELECT * FROM list_options " .
393 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
394 echo "<table cellpadding='0' cellspacing='0'>";
395 while ($lrow = sqlFetchArray($lres)) {
396 $option_id = $lrow['option_id'];
397 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
398 $maxlength = $frow['max_length'];
399 $string_maxlength = "";
400 // if max_length is set to zero, then do not set a maxlength
401 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
402 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
404 // Added 5-09 by BM - Translate label if applicable
405 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
406 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
407 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
408 echo "<td><input type='text'" .
409 " name='form_{$field_id_esc}[$option_id_esc]'" .
410 " id='form_{$field_id_esc}[$option_id_esc]'" .
411 " size='$fldlength'" .
412 " $string_maxlength" .
413 " value='$optionValue'";
414 echo " /></td></tr>";
416 echo "</table>";
419 // a set of exam results; 3 radio buttons and a text field:
420 else if ($data_type == 23) {
421 $tmp = explode('|', $currvalue);
422 $avalue = array();
423 foreach ($tmp as $value) {
424 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
425 $avalue[$matches[1]] = $matches[2];
428 $maxlength = $frow['max_length'];
429 $string_maxlength = "";
430 // if max_length is set to zero, then do not set a maxlength
431 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
432 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
433 $lres = sqlStatement("SELECT * FROM list_options " .
434 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
435 echo "<table cellpadding='0' cellspacing='0'>";
436 echo "<tr><td>&nbsp;</td><td class='bold'>" .
437 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
438 "&nbsp;</td><td class='bold'>" .
439 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
440 "<td class='bold'>" .
441 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
442 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
443 while ($lrow = sqlFetchArray($lres)) {
444 $option_id = $lrow['option_id'];
445 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
446 $restype = substr($avalue[$option_id], 0, 1);
447 $resnote = substr($avalue[$option_id], 2);
449 // Added 5-09 by BM - Translate label if applicable
450 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
452 for ($i = 0; $i < 3; ++$i) {
453 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
454 echo "<td><input type='radio'" .
455 " name='radio_{$field_id_esc}[$option_id_esc]'" .
456 " id='radio_{$field_id_esc}[$option_id_esc]'" .
457 " value='$inputValue'";
458 if ($restype === "$i") echo " checked";
459 echo " /></td>";
461 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
462 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
463 echo "<td><input type='text'" .
464 " name='form_{$field_id_esc}[$option_id_esc]'" .
465 " id='form_{$field_id_esc}[$option_id_esc]'" .
466 " size='$fldlength'" .
467 " $string_maxlength" .
468 " value='$resnote' /></td>";
469 echo "</tr>";
471 echo "</table>";
474 // the list of active allergies for the current patient
475 // this is read-only!
476 else if ($data_type == 24) {
477 $query = "SELECT title, comments FROM lists WHERE " .
478 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
479 "ORDER BY begdate";
480 // echo "<!-- $query -->\n"; // debugging
481 $lres = sqlStatement($query, array($GLOBALS['pid']));
482 $count = 0;
483 while ($lrow = sqlFetchArray($lres)) {
484 if ($count++) echo "<br />";
485 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
486 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
490 // a set of labeled checkboxes, each with a text field:
491 else if ($data_type == 25) {
492 $tmp = explode('|', $currvalue);
493 $avalue = array();
494 foreach ($tmp as $value) {
495 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
496 $avalue[$matches[1]] = $matches[2];
499 $maxlength = $frow['max_length'];
500 $string_maxlength = "";
501 // if max_length is set to zero, then do not set a maxlength
502 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
503 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
504 $lres = sqlStatement("SELECT * FROM list_options " .
505 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
506 echo "<table cellpadding='0' cellspacing='0'>";
507 while ($lrow = sqlFetchArray($lres)) {
508 $option_id = $lrow['option_id'];
509 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
510 $restype = substr($avalue[$option_id], 0, 1);
511 $resnote = substr($avalue[$option_id], 2);
513 // Added 5-09 by BM - Translate label if applicable
514 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
516 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
517 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]' id='check_{$field_id_esc}[$option_id_esc]' value='1'";
518 if ($restype) echo " checked";
519 echo " />&nbsp;</td>";
520 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
521 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
522 echo "<td><input type='text'" .
523 " name='form_{$field_id_esc}[$option_id_esc]'" .
524 " id='form_{$field_id_esc}[$option_id_esc]'" .
525 " size='$fldlength'" .
526 " $string_maxlength" .
527 " value='$resnote' /></td>";
528 echo "</tr>";
530 echo "</table>";
533 // single-selection list with ability to add to it
534 else if ($data_type == 26) {
535 echo "<select class='addtolistclass_$list_id_esc' name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
536 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES) . "</option>";
537 $lres = sqlStatement("SELECT * FROM list_options " .
538 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
539 $got_selected = FALSE;
540 while ($lrow = sqlFetchArray($lres)) {
541 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
542 echo "<option value='$optionValue'";
543 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
544 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
546 echo " selected";
547 $got_selected = TRUE;
549 // Added 5-09 by BM - Translate label if applicable
550 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n";
552 if (!$got_selected && strlen($currvalue) > 0) {
553 echo "<option value='$currescaped' selected>* $currescaped *</option>";
554 echo "</select>";
555 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES);
556 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
557 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
559 else {
560 echo "</select>";
562 // show the add button if user has access to correct list
563 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
564 $outputAddButton = "<input type='button' id='addtolistid_".$list_id_esc."' fieldid='form_".$field_id_esc."' class='addtolist' value='$inputValue'>";
565 if (aco_exist('lists', $list_id)) {
566 // a specific aco exist for this list, so ensure access
567 if (acl_check('lists', $list_id)) echo $outputAddButton;
569 else {
570 // no specific aco exist for this list, so check for access to 'default' list
571 if (acl_check('lists', 'default')) echo $outputAddButton;
575 // a set of labeled radio buttons
576 else if ($data_type == 27) {
577 // In this special case, fld_length is the number of columns generated.
578 $cols = max(1, $frow['fld_length']);
579 $lres = sqlStatement("SELECT * FROM list_options " .
580 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
581 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
582 $tdpct = (int) (100 / $cols);
583 $got_selected = FALSE;
584 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
585 $option_id = $lrow['option_id'];
586 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
587 if ($count % $cols == 0) {
588 if ($count) echo "</tr>";
589 echo "<tr>";
591 echo "<td width='$tdpct%'>";
592 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]' value='$option_id_esc'";
593 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
594 (strlen($currvalue) > 0 && $option_id == $currvalue))
596 echo " checked";
597 $got_selected = TRUE;
599 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
600 echo "</td>";
602 if ($count) {
603 echo "</tr>";
604 if ($count > $cols) {
605 // Add some space after multiple rows of radio buttons.
606 $cols = htmlspecialchars( $cols, ENT_QUOTES);
607 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
610 echo "</table>";
611 if (!$got_selected && strlen($currvalue) > 0) {
612 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
613 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
614 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
618 // special case for history of lifestyle status; 3 radio buttons and a date text field:
619 // VicarePlus :: A selection list box for smoking status:
620 else if ($data_type == 28 || $data_type == 32) {
621 $tmp = explode('|', $currvalue);
622 switch(count($tmp)) {
623 case "4": {
624 $resnote = $tmp[0];
625 $restype = $tmp[1];
626 $resdate = $tmp[2];
627 $reslist = $tmp[3];
628 } break;
629 case "3": {
630 $resnote = $tmp[0];
631 $restype = $tmp[1];
632 $resdate = $tmp[2];
633 } break;
634 case "2": {
635 $resnote = $tmp[0];
636 $restype = $tmp[1];
637 $resdate = "";
638 } break;
639 case "1": {
640 $resnote = $tmp[0];
641 $resdate = $restype = "";
642 } break;
643 default: {
644 $restype = $resdate = $resnote = "";
645 } break;
647 $maxlength = $frow['max_length'];
648 $string_maxlength = "";
649 // if max_length is set to zero, then do not set a maxlength
650 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
651 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
653 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
654 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
655 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
656 echo "<table cellpadding='0' cellspacing='0'>";
657 echo "<tr>";
658 if ($data_type == 28)
660 // input text
661 echo "<td><input type='text'" .
662 " name='form_$field_id_esc'" .
663 " id='form_$field_id_esc'" .
664 " size='$fldlength'" .
665 " $string_maxlength" .
666 " value='$resnote' />&nbsp;</td>";
667 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
668 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
669 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
671 else if($data_type == 32)
673 // input text
674 echo "<tr><td><input type='text'" .
675 " name='form_text_$field_id_esc'" .
676 " id='form_text_$field_id_esc'" .
677 " size='$fldlength'" .
678 " $string_maxlength" .
679 " value='$resnote' />&nbsp;</td></tr>";
680 echo "<td>";
681 //Selection list for smoking status
682 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
683 echo generate_select_list("form_$field_id", $list_id, $reslist,
684 $description, $showEmpty ? $empty_title : '', '', $onchange)."</td>";
685 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
687 // current
688 echo "<td><input type='radio'" .
689 " name='radio_{$field_id_esc}'" .
690 " id='radio_{$field_id_esc}[current]'" .
691 " value='current".$field_id_esc."'";
692 if ($restype == "current".$field_id) echo " checked";
693 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
694 // quit
695 echo "<td><input type='radio'" .
696 " name='radio_{$field_id_esc}'" .
697 " id='radio_{$field_id_esc}[quit]'" .
698 " value='quit".$field_id_esc."'";
699 if ($restype == "quit".$field_id) echo " checked";
700 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
701 // quit date
702 echo "<td><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
703 " value='$resdate'" .
704 " title='$description'" .
705 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
706 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
707 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
708 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />&nbsp;</td>";
709 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
710 // never
711 echo "<td><input type='radio'" .
712 " name='radio_{$field_id_esc}'" .
713 " id='radio_{$field_id_esc}[never]'" .
714 " value='never".$field_id_esc."'";
715 if ($restype == "never".$field_id) echo " checked";
716 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."&nbsp;</td>";
717 // Not Applicable
718 echo "<td><input type='radio'" .
719 " name='radio_{$field_id}'" .
720 " id='radio_{$field_id}[not_applicable]'" .
721 " value='not_applicable".$field_id."'";
722 if ($restype == "not_applicable".$field_id) echo " checked";
723 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('N/A'), ENT_QUOTES)."&nbsp;</td>";
724 echo "</tr>";
725 echo "</table>";
728 // static text. read-only, of course.
729 else if ($data_type == 31) {
730 echo nl2br($frow['description']);
733 //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.
734 else if ($data_type == 33) {
735 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
736 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES) . "</option>";
737 $lres = sqlStatement("SELECT * FROM list_options " .
738 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
739 $got_selected = FALSE;
740 while ($lrow = sqlFetchArray($lres)) {
741 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
742 echo "<option value='$optionValue'";
743 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
744 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
746 echo " selected";
747 $got_selected = TRUE;
750 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n";
752 if (!$got_selected && strlen($currvalue) > 0)
754 //Check 'ethrace' list if the entry does not exist in the list_id of the given list(Race or Ethnicity).
755 $list_id='ethrace';
756 $lrow = sqlQuery("SELECT title FROM list_options " .
757 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
758 if ($lrow > 0)
760 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
761 echo "<option value='$currvalue' selected> $s </option>";
762 echo "</select>";
764 else
766 echo "<option value='$currescaped' selected>* $currescaped *</option>";
767 echo "</select>";
768 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES);
769 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
770 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
773 else {
774 echo "</select>";
777 else if($data_type == 34){
778 $arr = explode("|*|*|*|",$currvalue);
779 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc,ENT_QUOTES)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
780 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
781 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'>".$currvalue."</textarea></div>";
782 echo "</a>";
785 //facilities drop-down list
786 else if ($data_type == 35) {
787 if (empty($currvalue)){
788 $currvalue = 0;
790 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
795 function generate_print_field($frow, $currvalue) {
796 global $rootdir, $date_init;
798 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
800 $data_type = $frow['data_type'];
801 $field_id = $frow['field_id'];
802 $list_id = $frow['list_id'];
803 $fld_length = $frow['fld_length'];
805 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
807 // Can pass $frow['empty_title'] with this variable, otherwise
808 // will default to 'Unassigned'.
809 // If it is 'SKIP' then an empty text title is completely skipped.
810 $showEmpty = true;
811 if (isset($frow['empty_title'])) {
812 if ($frow['empty_title'] == "SKIP") {
813 //do not display an 'empty' choice
814 $showEmpty = false;
815 $empty_title = "Unassigned";
817 else {
818 $empty_title = $frow['empty_title'];
821 else {
822 $empty_title = "Unassigned";
825 // generic single-selection list
826 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
827 if (empty($fld_length)) {
828 if ($list_id == 'titles') {
829 $fld_length = 3;
830 } else {
831 $fld_length = 10;
834 $tmp = '';
835 if ($currvalue) {
836 $lrow = sqlQuery("SELECT title FROM list_options " .
837 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
838 $tmp = xl_list_label($lrow['title']);
839 if (empty($tmp)) $tmp = "($currvalue)";
841 /*****************************************************************
842 echo "<input type='text'" .
843 " size='$fld_length'" .
844 " value='$tmp'" .
845 " class='under'" .
846 " />";
847 *****************************************************************/
848 if ($tmp === '') { $tmp = '&nbsp;'; }
849 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
850 echo $tmp;
853 // simple text field
854 else if ($data_type == 2 || $data_type == 15) {
855 /*****************************************************************
856 echo "<input type='text'" .
857 " size='$fld_length'" .
858 " value='$currescaped'" .
859 " class='under'" .
860 " />";
861 *****************************************************************/
862 if ($currescaped === '') $currescaped = '&nbsp;';
863 echo $currescaped;
866 // long or multi-line text field
867 else if ($data_type == 3) {
868 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
869 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
870 echo "<textarea" .
871 " cols='$fldlength'" .
872 " rows='$maxlength'>" .
873 $currescaped . "</textarea>";
876 // date
877 else if ($data_type == 4) {
878 /*****************************************************************
879 echo "<input type='text' size='10'" .
880 " value='$currescaped'" .
881 " title='$description'" .
882 " class='under'" .
883 " />";
884 *****************************************************************/
885 if ($currvalue === '') { $tmp = oeFormatShortDate('&nbsp;'); }
886 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES); }
887 echo $tmp;
890 // provider list
891 else if ($data_type == 10 || $data_type == 11) {
892 $tmp = '';
893 if ($currvalue) {
894 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
895 "WHERE id = ?", array($currvalue) );
896 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
897 if (empty($tmp)) $tmp = "($currvalue)";
899 /*****************************************************************
900 echo "<input type='text'" .
901 " size='$fld_length'" .
902 " value='$tmp'" .
903 " class='under'" .
904 " />";
905 *****************************************************************/
906 if ($tmp === '') { $tmp = '&nbsp;'; }
907 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
908 echo $tmp;
911 // pharmacy list
912 else if ($data_type == 12) {
913 $tmp = '';
914 if ($currvalue) {
915 $pres = get_pharmacies();
916 while ($prow = sqlFetchArray($pres)) {
917 $key = $prow['id'];
918 if ($currvalue == $key) {
919 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
920 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
921 $prow['line1'] . ' / ' . $prow['city'];
924 if (empty($tmp)) $tmp = "($currvalue)";
926 /*****************************************************************
927 echo "<input type='text'" .
928 " size='$fld_length'" .
929 " value='$tmp'" .
930 " class='under'" .
931 " />";
932 *****************************************************************/
933 if ($tmp === '') { $tmp = '&nbsp;'; }
934 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
935 echo $tmp;
938 // squads
939 else if ($data_type == 13) {
940 $tmp = '';
941 if ($currvalue) {
942 $squads = acl_get_squads();
943 if ($squads) {
944 foreach ($squads as $key => $value) {
945 if ($currvalue == $key) {
946 $tmp = $value[3];
950 if (empty($tmp)) $tmp = "($currvalue)";
952 /*****************************************************************
953 echo "<input type='text'" .
954 " size='$fld_length'" .
955 " value='$tmp'" .
956 " class='under'" .
957 " />";
958 *****************************************************************/
959 if ($tmp === '') { $tmp = '&nbsp;'; }
960 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
961 echo $tmp;
964 // Address book.
965 else if ($data_type == 14) {
966 $tmp = '';
967 if ($currvalue) {
968 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
969 "WHERE id = ?", array($currvalue) );
970 $uname = $urow['lname'];
971 if ($urow['fname']) $uname .= ", " . $urow['fname'];
972 $tmp = $uname;
973 if (empty($tmp)) $tmp = "($currvalue)";
975 /*****************************************************************
976 echo "<input type='text'" .
977 " size='$fld_length'" .
978 " value='$tmp'" .
979 " class='under'" .
980 " />";
981 *****************************************************************/
982 if ($tmp === '') { $tmp = '&nbsp;'; }
983 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
984 echo $tmp;
987 // a set of labeled checkboxes
988 else if ($data_type == 21) {
989 // In this special case, fld_length is the number of columns generated.
990 $cols = max(1, $fld_length);
991 $avalue = explode('|', $currvalue);
992 $lres = sqlStatement("SELECT * FROM list_options " .
993 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
994 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
995 $tdpct = (int) (100 / $cols);
996 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
997 $option_id = $lrow['option_id'];
998 if ($count % $cols == 0) {
999 if ($count) echo "</tr>";
1000 echo "<tr>";
1002 echo "<td width='$tdpct%'>";
1003 echo "<input type='checkbox'";
1004 if (in_array($option_id, $avalue)) echo " checked";
1005 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1006 echo "</td>";
1008 if ($count) {
1009 echo "</tr>";
1010 if ($count > $cols) {
1011 // Add some space after multiple rows of checkboxes.
1012 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1013 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1016 echo "</table>";
1019 // a set of labeled text input fields
1020 else if ($data_type == 22) {
1021 $tmp = explode('|', $currvalue);
1022 $avalue = array();
1023 foreach ($tmp as $value) {
1024 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1025 $avalue[$matches[1]] = $matches[2];
1028 $lres = sqlStatement("SELECT * FROM list_options " .
1029 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1030 echo "<table cellpadding='0' cellspacing='0'>";
1031 while ($lrow = sqlFetchArray($lres)) {
1032 $option_id = $lrow['option_id'];
1033 $fldlength = empty($fld_length) ? 20 : $fld_length;
1034 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1035 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1036 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1037 echo "<td><input type='text'" .
1038 " size='$fldlength'" .
1039 " value='$inputValue'" .
1040 " class='under'" .
1041 " /></td></tr>";
1043 echo "</table>";
1046 // a set of exam results; 3 radio buttons and a text field:
1047 else if ($data_type == 23) {
1048 $tmp = explode('|', $currvalue);
1049 $avalue = array();
1050 foreach ($tmp as $value) {
1051 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1052 $avalue[$matches[1]] = $matches[2];
1055 $fldlength = empty($fld_length) ? 20 : $fld_length;
1056 $lres = sqlStatement("SELECT * FROM list_options " .
1057 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1058 echo "<table cellpadding='0' cellspacing='0'>";
1059 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1060 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1061 "&nbsp;</td><td class='bold'>" .
1062 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1063 "<td class='bold'>" .
1064 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1065 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1066 while ($lrow = sqlFetchArray($lres)) {
1067 $option_id = $lrow['option_id'];
1068 $restype = substr($avalue[$option_id], 0, 1);
1069 $resnote = substr($avalue[$option_id], 2);
1070 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1071 for ($i = 0; $i < 3; ++$i) {
1072 echo "<td><input type='radio'";
1073 if ($restype === "$i") echo " checked";
1074 echo " /></td>";
1076 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1077 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1078 echo "<td><input type='text'" .
1079 " size='$fldlength'" .
1080 " value='$resnote'" .
1081 " class='under' /></td>" .
1082 "</tr>";
1084 echo "</table>";
1087 // the list of active allergies for the current patient
1088 // this is read-only!
1089 else if ($data_type == 24) {
1090 $query = "SELECT title, comments FROM lists WHERE " .
1091 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1092 "ORDER BY begdate";
1093 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1094 $count = 0;
1095 while ($lrow = sqlFetchArray($lres)) {
1096 if ($count++) echo "<br />";
1097 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1098 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1102 // a set of labeled checkboxes, each with a text field:
1103 else if ($data_type == 25) {
1104 $tmp = explode('|', $currvalue);
1105 $avalue = array();
1106 foreach ($tmp as $value) {
1107 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1108 $avalue[$matches[1]] = $matches[2];
1111 $fldlength = empty($fld_length) ? 20 : $fld_length;
1112 $lres = sqlStatement("SELECT * FROM list_options " .
1113 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1114 echo "<table cellpadding='0' cellspacing='0'>";
1115 while ($lrow = sqlFetchArray($lres)) {
1116 $option_id = $lrow['option_id'];
1117 $restype = substr($avalue[$option_id], 0, 1);
1118 $resnote = substr($avalue[$option_id], 2);
1119 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1120 echo "<td><input type='checkbox'";
1121 if ($restype) echo " checked";
1122 echo " />&nbsp;</td>";
1123 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1124 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1125 echo "<td><input type='text'" .
1126 " size='$fldlength'" .
1127 " value='$resnote'" .
1128 " class='under'" .
1129 " /></td>" .
1130 "</tr>";
1132 echo "</table>";
1135 // a set of labeled radio buttons
1136 else if ($data_type == 27) {
1137 // In this special case, fld_length is the number of columns generated.
1138 $cols = max(1, $frow['fld_length']);
1139 $lres = sqlStatement("SELECT * FROM list_options " .
1140 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1141 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1142 $tdpct = (int) (100 / $cols);
1143 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1144 $option_id = $lrow['option_id'];
1145 if ($count % $cols == 0) {
1146 if ($count) echo "</tr>";
1147 echo "<tr>";
1149 echo "<td width='$tdpct%'>";
1150 echo "<input type='radio'";
1151 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1152 (strlen($currvalue) > 0 && $option_id == $currvalue))
1154 echo " checked";
1156 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1157 echo "</td>";
1159 if ($count) {
1160 echo "</tr>";
1161 if ($count > $cols) {
1162 // Add some space after multiple rows of radio buttons.
1163 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1164 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1167 echo "</table>";
1170 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1171 else if ($data_type == 28 || $data_type == 32) {
1172 $tmp = explode('|', $currvalue);
1173 switch(count($tmp)) {
1174 case "4": {
1175 $resnote = $tmp[0];
1176 $restype = $tmp[1];
1177 $resdate = $tmp[2];
1178 $reslist = $tmp[3];
1179 } break;
1180 case "3": {
1181 $resnote = $tmp[0];
1182 $restype = $tmp[1];
1183 $resdate = $tmp[2];
1184 } break;
1185 case "2": {
1186 $resnote = $tmp[0];
1187 $restype = $tmp[1];
1188 $resdate = "";
1189 } break;
1190 case "1": {
1191 $resnote = $tmp[0];
1192 $resdate = $restype = "";
1193 } break;
1194 default: {
1195 $restype = $resdate = $resnote = "";
1196 } break;
1198 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1199 echo "<table cellpadding='0' cellspacing='0'>";
1200 echo "<tr>";
1201 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1202 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1203 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1204 if($data_type == 28)
1206 echo "<td><input type='text'" .
1207 " size='$fldlength'" .
1208 " class='under'" .
1209 " value='$resnote' /></td>";
1210 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1211 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1212 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1214 else if($data_type == 32)
1216 echo "<tr><td><input type='text'" .
1217 " size='$fldlength'" .
1218 " class='under'" .
1219 " value='$resnote' /></td></tr>";
1220 $fldlength = 30;
1221 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1222 echo "<td><input type='text'" .
1223 " size='$fldlength'" .
1224 " class='under'" .
1225 " value='$smoking_status_title' /></td>";
1226 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1228 echo "<td><input type='radio'";
1229 if ($restype == "current".$field_id) echo " checked";
1230 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1232 echo "<td><input type='radio'";
1233 if ($restype == "current".$field_id) echo " checked";
1234 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1236 echo "<td><input type='text' size='6'" .
1237 " value='$resdate'" .
1238 " class='under'" .
1239 " /></td>";
1241 echo "<td><input type='radio'";
1242 if ($restype == "current".$field_id) echo " checked";
1243 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1245 echo "<td><input type='radio'";
1246 if ($restype == "not_applicable".$field_id) echo " checked";
1247 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1248 echo "</tr>";
1249 echo "</table>";
1252 // static text. read-only, of course.
1253 else if ($data_type == 31) {
1254 echo nl2br($frow['description']);
1257 else if($data_type == 34){
1258 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc,ENT_QUOTES)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
1259 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1260 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1261 echo "</a>";
1264 //facilities drop-down list
1265 else if ($data_type == 35) {
1266 if (empty($currvalue)){
1267 $currvalue = 0;
1269 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1274 function generate_display_field($frow, $currvalue) {
1275 $data_type = $frow['data_type'];
1276 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1277 $list_id = $frow['list_id'];
1278 $s = '';
1280 // generic selection list or the generic selection list with add on the fly
1281 // feature, or radio buttons
1282 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1283 $lrow = sqlQuery("SELECT title FROM list_options " .
1284 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1285 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1286 //For lists Race and Ethnicity if there is no matching value in the corresponding lists check ethrace list
1287 if ($lrow == 0 && $data_type == 33)
1289 $list_id='ethrace';
1290 $lrow_ethrace = sqlQuery("SELECT title FROM list_options " .
1291 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1292 $s = htmlspecialchars(xl_list_label($lrow_ethrace['title']),ENT_NOQUOTES);
1296 // simple text field
1297 else if ($data_type == 2) {
1298 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1301 // long or multi-line text field
1302 else if ($data_type == 3) {
1303 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1306 // date
1307 else if ($data_type == 4) {
1308 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES);
1311 // provider
1312 else if ($data_type == 10 || $data_type == 11) {
1313 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1314 "WHERE id = ?", array($currvalue) );
1315 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1318 // pharmacy list
1319 else if ($data_type == 12) {
1320 $pres = get_pharmacies();
1321 while ($prow = sqlFetchArray($pres)) {
1322 $key = $prow['id'];
1323 if ($currvalue == $key) {
1324 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1325 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1326 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1331 // squads
1332 else if ($data_type == 13) {
1333 $squads = acl_get_squads();
1334 if ($squads) {
1335 foreach ($squads as $key => $value) {
1336 if ($currvalue == $key) {
1337 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1343 // address book
1344 else if ($data_type == 14) {
1345 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1346 "WHERE id = ?", array($currvalue));
1347 $uname = $urow['lname'];
1348 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1349 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1352 // billing code
1353 else if ($data_type == 15) {
1354 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1357 // a set of labeled checkboxes
1358 else if ($data_type == 21) {
1359 $avalue = explode('|', $currvalue);
1360 $lres = sqlStatement("SELECT * FROM list_options " .
1361 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1362 $count = 0;
1363 while ($lrow = sqlFetchArray($lres)) {
1364 $option_id = $lrow['option_id'];
1365 if (in_array($option_id, $avalue)) {
1366 if ($count++) $s .= "<br />";
1368 // Added 5-09 by BM - Translate label if applicable
1369 $s .= htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1375 // a set of labeled text input fields
1376 else if ($data_type == 22) {
1377 $tmp = explode('|', $currvalue);
1378 $avalue = array();
1379 foreach ($tmp as $value) {
1380 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1381 $avalue[$matches[1]] = $matches[2];
1384 $lres = sqlStatement("SELECT * FROM list_options " .
1385 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1386 $s .= "<table cellpadding='0' cellspacing='0'>";
1387 while ($lrow = sqlFetchArray($lres)) {
1388 $option_id = $lrow['option_id'];
1389 if (empty($avalue[$option_id])) continue;
1391 // Added 5-09 by BM - Translate label if applicable
1392 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1394 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1396 $s .= "</table>";
1399 // a set of exam results; 3 radio buttons and a text field:
1400 else if ($data_type == 23) {
1401 $tmp = explode('|', $currvalue);
1402 $avalue = array();
1403 foreach ($tmp as $value) {
1404 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1405 $avalue[$matches[1]] = $matches[2];
1408 $lres = sqlStatement("SELECT * FROM list_options " .
1409 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1410 $s .= "<table cellpadding='0' cellspacing='0'>";
1411 while ($lrow = sqlFetchArray($lres)) {
1412 $option_id = $lrow['option_id'];
1413 $restype = substr($avalue[$option_id], 0, 1);
1414 $resnote = substr($avalue[$option_id], 2);
1415 if (empty($restype) && empty($resnote)) continue;
1417 // Added 5-09 by BM - Translate label if applicable
1418 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1420 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1421 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1422 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1423 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1424 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1425 $s .= "</tr>";
1427 $s .= "</table>";
1430 // the list of active allergies for the current patient
1431 else if ($data_type == 24) {
1432 $query = "SELECT title, comments FROM lists WHERE " .
1433 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1434 "ORDER BY begdate";
1435 // echo "<!-- $query -->\n"; // debugging
1436 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1437 $count = 0;
1438 while ($lrow = sqlFetchArray($lres)) {
1439 if ($count++) $s .= "<br />";
1440 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1441 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1445 // a set of labeled checkboxes, each with a text field:
1446 else if ($data_type == 25) {
1447 $tmp = explode('|', $currvalue);
1448 $avalue = array();
1449 foreach ($tmp as $value) {
1450 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1451 $avalue[$matches[1]] = $matches[2];
1454 $lres = sqlStatement("SELECT * FROM list_options " .
1455 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1456 $s .= "<table cellpadding='0' cellspacing='0'>";
1457 while ($lrow = sqlFetchArray($lres)) {
1458 $option_id = $lrow['option_id'];
1459 $restype = substr($avalue[$option_id], 0, 1);
1460 $resnote = substr($avalue[$option_id], 2);
1461 if (empty($restype) && empty($resnote)) continue;
1463 // Added 5-09 by BM - Translate label if applicable
1464 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1466 $restype = $restype ? xl('Yes') : xl('No');
1467 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1468 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1469 $s .= "</tr>";
1471 $s .= "</table>";
1474 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1475 // VicarePlus :: A selection list for smoking status.
1476 else if ($data_type == 28 || $data_type == 32) {
1477 $tmp = explode('|', $currvalue);
1478 switch(count($tmp)) {
1479 case "4": {
1480 $resnote = $tmp[0];
1481 $restype = $tmp[1];
1482 $resdate = $tmp[2];
1483 $reslist = $tmp[3];
1484 } break;
1485 case "3": {
1486 $resnote = $tmp[0];
1487 $restype = $tmp[1];
1488 $resdate = $tmp[2];
1489 } break;
1490 case "2": {
1491 $resnote = $tmp[0];
1492 $restype = $tmp[1];
1493 $resdate = "";
1494 } break;
1495 case "1": {
1496 $resnote = $tmp[0];
1497 $resdate = $restype = "";
1498 } break;
1499 default: {
1500 $restype = $resdate = $resnote = "";
1501 } break;
1503 $s .= "<table cellpadding='0' cellspacing='0'>";
1505 $s .= "<tr>";
1506 $res = "";
1507 if ($restype == "current".$field_id) $res = xl('Current');
1508 if ($restype == "quit".$field_id) $res = xl('Quit');
1509 if ($restype == "never".$field_id) $res = xl('Never');
1510 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1511 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1512 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1513 if ($data_type == 28)
1515 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1517 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1518 else if ($data_type == 32)
1520 if (!empty($reslist)) $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1521 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
1524 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1525 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1526 $s .= "</tr>";
1527 $s .= "</table>";
1530 // static text. read-only, of course.
1531 else if ($data_type == 31) {
1532 $s .= nl2br($frow['description']);
1535 else if($data_type == 34){
1536 $arr = explode("|*|*|*|",$currvalue);
1537 for($i=0;$i<sizeof($arr);$i++){
1538 $s.=$arr[$i];
1542 // facility
1543 else if ($data_type == 35) {
1544 $urow = sqlQuery("SELECT id, name FROM facility ".
1545 "WHERE id = ?", array($currvalue) );
1546 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES);
1549 return $s;
1552 $CPR = 4; // cells per row of generic data
1553 $last_group = '';
1554 $cell_count = 0;
1555 $item_count = 0;
1557 function disp_end_cell() {
1558 global $item_count, $cell_count;
1559 if ($item_count > 0) {
1560 echo "</td>";
1561 $item_count = 0;
1565 function disp_end_row() {
1566 global $cell_count, $CPR;
1567 disp_end_cell();
1568 if ($cell_count > 0) {
1569 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
1570 echo "</tr>\n";
1571 $cell_count = 0;
1575 function disp_end_group() {
1576 global $last_group;
1577 if (strlen($last_group) > 0) {
1578 disp_end_row();
1582 function display_layout_rows($formtype, $result1, $result2='') {
1583 global $item_count, $cell_count, $last_group, $CPR;
1585 $fres = sqlStatement("SELECT * FROM layout_options " .
1586 "WHERE form_id = ? AND uor > 0 " .
1587 "ORDER BY group_name, seq", array($formtype) );
1589 while ($frow = sqlFetchArray($fres)) {
1590 $this_group = $frow['group_name'];
1591 $titlecols = $frow['titlecols'];
1592 $datacols = $frow['datacols'];
1593 $data_type = $frow['data_type'];
1594 $field_id = $frow['field_id'];
1595 $list_id = $frow['list_id'];
1596 $currvalue = '';
1598 if ($formtype == 'DEM') {
1599 if ($GLOBALS['athletic_team']) {
1600 // Skip fitness level and return-to-play date because those appear
1601 // in a special display/update form on this page.
1602 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1604 if (strpos($field_id, 'em_') === 0) {
1605 // Skip employer related fields, if it's disabled.
1606 if ($GLOBALS['omit_employers']) continue;
1607 $tmp = substr($field_id, 3);
1608 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1610 else {
1611 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1614 else {
1615 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1618 // Handle a data category (group) change.
1619 if (strcmp($this_group, $last_group) != 0) {
1620 $group_name = substr($this_group, 1);
1621 // totally skip generating the employer category, if it's disabled.
1622 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1623 disp_end_group();
1624 $last_group = $this_group;
1627 // filter out all the empty field data from the patient report.
1628 if (!empty($currvalue) && !($currvalue == '0000-00-00 00:00:00')) {
1629 // Handle starting of a new row.
1630 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1631 disp_end_row();
1632 echo "<tr>";
1633 if ($group_name) {
1634 echo "<td class='groupname'>";
1635 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1636 //echo "<font color='#008800'>$group_name</font>";
1638 // Added 5-09 by BM - Translate label if applicable
1639 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
1641 $group_name = '';
1642 } else {
1643 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1644 echo "<td valign='top'>&nbsp;";
1646 echo "</td>";
1649 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1651 // Handle starting of a new label cell.
1652 if ($titlecols > 0) {
1653 disp_end_cell();
1654 //echo "<td class='label' colspan='$titlecols' valign='top'";
1655 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1656 echo "<td class='label' colspan='$titlecols_esc' ";
1657 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1658 echo ">";
1659 $cell_count += $titlecols;
1661 ++$item_count;
1663 // Added 5-09 by BM - Translate label if applicable
1664 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1666 // Handle starting of a new data cell.
1667 if ($datacols > 0) {
1668 disp_end_cell();
1669 //echo "<td class='text data' colspan='$datacols' valign='top'";
1670 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1671 echo "<td class='text data' colspan='$datacols_esc'";
1672 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1673 echo ">";
1674 $cell_count += $datacols;
1677 ++$item_count;
1678 echo generate_display_field($frow, $currvalue);
1682 disp_end_group();
1685 function display_layout_tabs($formtype, $result1, $result2='') {
1686 global $item_count, $cell_count, $last_group, $CPR;
1688 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1689 "WHERE form_id = ? AND uor > 0 " .
1690 "ORDER BY group_name, seq", array($formtype) );
1692 $first = true;
1693 while ($frow = sqlFetchArray($fres)) {
1694 $this_group = $frow['group_name'];
1695 $group_name = substr($this_group, 1);
1697 <li <?php echo $first ? 'class="current"' : '' ?>>
1698 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES)."?>">
1699 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
1700 </li>
1701 <?php
1702 $first = false;
1706 function display_layout_tabs_data($formtype, $result1, $result2='') {
1707 global $item_count, $cell_count, $last_group, $CPR;
1709 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1710 "WHERE form_id = ? AND uor > 0 " .
1711 "ORDER BY group_name, seq", array($formtype));
1713 $first = true;
1714 while ($frow = sqlFetchArray($fres)) {
1715 $this_group = isset($frow['group_name']) ? $frow['group_name'] : "" ;
1716 $titlecols = isset($frow['titlecols']) ? $frow['titlecols'] : "";
1717 $datacols = isset($frow['datacols']) ? $frow['datacols'] : "";
1718 $data_type = isset($frow['data_type']) ? $frow['data_type'] : "";
1719 $field_id = isset($frow['field_id']) ? $frow['field_id'] : "";
1720 $list_id = isset($frow['list_id']) ? $frow['list_id'] : "";
1721 $currvalue = '';
1723 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1724 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1725 "ORDER BY seq", array($formtype, $this_group) );
1728 <div class="tab <?php echo $first ? 'current' : '' ?>">
1729 <table border='0' cellpadding='0'>
1731 <?php
1732 while ($group_fields = sqlFetchArray($group_fields_query)) {
1734 $titlecols = $group_fields['titlecols'];
1735 $datacols = $group_fields['datacols'];
1736 $data_type = $group_fields['data_type'];
1737 $field_id = $group_fields['field_id'];
1738 $list_id = $group_fields['list_id'];
1739 $currvalue = '';
1741 if ($formtype == 'DEM') {
1742 if ($GLOBALS['athletic_team']) {
1743 // Skip fitness level and return-to-play date because those appear
1744 // in a special display/update form on this page.
1745 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1747 if (strpos($field_id, 'em_') === 0) {
1748 // Skip employer related fields, if it's disabled.
1749 if ($GLOBALS['omit_employers']) continue;
1750 $tmp = substr($field_id, 3);
1751 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1753 else {
1754 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1757 else {
1758 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1761 // Handle a data category (group) change.
1762 if (strcmp($this_group, $last_group) != 0) {
1763 $group_name = substr($this_group, 1);
1764 // totally skip generating the employer category, if it's disabled.
1765 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1766 $last_group = $this_group;
1769 // Handle starting of a new row.
1770 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1771 disp_end_row();
1772 echo "<tr>";
1775 if ($item_count == 0 && $titlecols == 0) {
1776 $titlecols = 1;
1779 // Handle starting of a new label cell.
1780 if ($titlecols > 0) {
1781 disp_end_cell();
1782 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1783 echo "<td class='label' colspan='$titlecols_esc' ";
1784 echo ">";
1785 $cell_count += $titlecols;
1787 ++$item_count;
1789 // Added 5-09 by BM - Translate label if applicable
1790 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1792 // Handle starting of a new data cell.
1793 if ($datacols > 0) {
1794 disp_end_cell();
1795 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1796 echo "<td class='text data' colspan='$datacols_esc'";
1797 echo ">";
1798 $cell_count += $datacols;
1801 ++$item_count;
1802 echo generate_display_field($group_fields, $currvalue);
1805 disp_end_row();
1808 </table>
1809 </div>
1811 <?php
1813 $first = false;
1819 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1820 global $item_count, $cell_count, $last_group, $CPR;
1822 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1823 "WHERE form_id = ? AND uor > 0 " .
1824 "ORDER BY group_name, seq", array($formtype) );
1826 $first = true;
1827 while ($frow = sqlFetchArray($fres)) {
1828 $this_group = $frow['group_name'];
1829 $group_name = substr($this_group, 1);
1830 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
1831 $titlecols = $frow['titlecols'];
1832 $datacols = $frow['datacols'];
1833 $data_type = $frow['data_type'];
1834 $field_id = $frow['field_id'];
1835 $list_id = $frow['list_id'];
1836 $currvalue = '';
1838 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1839 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1840 "ORDER BY seq", array($formtype,$this_group) );
1843 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name_esc?>" >
1844 <table border='0' cellpadding='0'>
1846 <?php
1847 while ($group_fields = sqlFetchArray($group_fields_query)) {
1849 $titlecols = $group_fields['titlecols'];
1850 $datacols = $group_fields['datacols'];
1851 $data_type = $group_fields['data_type'];
1852 $field_id = $group_fields['field_id'];
1853 $list_id = $group_fields['list_id'];
1854 $currvalue = '';
1856 if ($formtype == 'DEM') {
1857 if ($GLOBALS['athletic_team']) {
1858 // Skip fitness level and return-to-play date because those appear
1859 // in a special display/update form on this page.
1860 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1862 if (strpos($field_id, 'em_') === 0) {
1863 // Skip employer related fields, if it's disabled.
1864 if ($GLOBALS['omit_employers']) continue;
1865 $tmp = substr($field_id, 3);
1866 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1868 else {
1869 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1872 else {
1873 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1876 // Handle a data category (group) change.
1877 if (strcmp($this_group, $last_group) != 0) {
1878 $group_name = substr($this_group, 1);
1879 // totally skip generating the employer category, if it's disabled.
1880 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1881 $last_group = $this_group;
1884 // Handle starting of a new row.
1885 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1886 disp_end_row();
1887 echo "<tr>";
1890 if ($item_count == 0 && $titlecols == 0) {
1891 $titlecols = 1;
1894 // Handle starting of a new label cell.
1895 if ($titlecols > 0) {
1896 disp_end_cell();
1897 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1898 echo "<td class='label' colspan='$titlecols_esc' ";
1899 echo ">";
1900 $cell_count += $titlecols;
1902 ++$item_count;
1904 // Added 5-09 by BM - Translate label if applicable
1905 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
1907 // Handle starting of a new data cell.
1908 if ($datacols > 0) {
1909 disp_end_cell();
1910 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1911 echo "<td class='text data' colspan='$datacols_esc'";
1912 echo ">";
1913 $cell_count += $datacols;
1916 ++$item_count;
1917 echo generate_form_field($group_fields, $currvalue);
1921 </table>
1922 </div>
1924 <?php
1926 $first = false;
1931 // From the currently posted HTML form, this gets the value of the
1932 // field corresponding to the provided layout_options table row.
1934 function get_layout_form_value($frow) {
1935 // Bring in $sanitize_all_escapes variable, which will decide
1936 // the variable escaping method.
1937 global $sanitize_all_escapes;
1939 $maxlength = $frow['max_length'];
1940 $data_type = $frow['data_type'];
1941 $field_id = $frow['field_id'];
1942 $value = '';
1943 if (isset($_POST["form_$field_id"])) {
1944 if ($data_type == 21) {
1945 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1946 // must be concatenated into a |-separated string.
1947 foreach ($_POST["form_$field_id"] as $key => $val) {
1948 if (strlen($value)) $value .= '|';
1949 $value .= $key;
1952 else if ($data_type == 22) {
1953 // $_POST["form_$field_id"] is an array of text fields to be imploded
1954 // into "key:value|key:value|...".
1955 foreach ($_POST["form_$field_id"] as $key => $val) {
1956 $val = str_replace('|', ' ', $val);
1957 if (strlen($value)) $value .= '|';
1958 $value .= "$key:$val";
1961 else if ($data_type == 23) {
1962 // $_POST["form_$field_id"] is an array of text fields with companion
1963 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1964 foreach ($_POST["form_$field_id"] as $key => $val) {
1965 $restype = $_POST["radio_{$field_id}"][$key];
1966 if (empty($restype)) $restype = '0';
1967 $val = str_replace('|', ' ', $val);
1968 if (strlen($value)) $value .= '|';
1969 $value .= "$key:$restype:$val";
1972 else if ($data_type == 25) {
1973 // $_POST["form_$field_id"] is an array of text fields with companion
1974 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1975 foreach ($_POST["form_$field_id"] as $key => $val) {
1976 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
1977 $val = str_replace('|', ' ', $val);
1978 if (strlen($value)) $value .= '|';
1979 $value .= "$key:$restype:$val";
1982 else if ($data_type == 28 || $data_type == 32) {
1983 // $_POST["form_$field_id"] is an date text fields with companion
1984 // radio buttons to be imploded into "notes|type|date".
1985 $restype = $_POST["radio_{$field_id}"];
1986 if (empty($restype)) $restype = '0';
1987 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1988 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1989 if ($data_type == 32)
1991 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
1992 $reslist = str_replace('|', ' ', $_POST["form_$field_id"]);
1993 $res_text_note = str_replace('|', ' ', $_POST["form_text_$field_id"]);
1994 $value = "$res_text_note|$restype|$resdate|$reslist";
1996 else
1997 $value = "$resnote|$restype|$resdate";
1999 else {
2000 $value = $_POST["form_$field_id"];
2004 // Better to die than to silently truncate data!
2005 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
2006 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
2007 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
2009 // Make sure the return value is quote-safe.
2010 if ($sanitize_all_escapes) {
2011 //escapes already removed and using binding/placemarks in sql calls
2012 // so only need to trim value
2013 return trim($value);
2015 else {
2016 //need to explicitly prepare value
2017 return formTrim($value);
2021 // Generate JavaScript validation logic for the required fields.
2023 function generate_layout_validation($form_id) {
2024 $fres = sqlStatement("SELECT * FROM layout_options " .
2025 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2026 "ORDER BY group_name, seq", array($form_id) );
2028 while ($frow = sqlFetchArray($fres)) {
2029 if ($frow['uor'] < 2) continue;
2030 $data_type = $frow['data_type'];
2031 $field_id = $frow['field_id'];
2032 $fldtitle = $frow['title'];
2033 if (!$fldtitle) $fldtitle = $frow['description'];
2034 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES);
2035 switch($data_type) {
2036 case 1:
2037 case 11:
2038 case 12:
2039 case 13:
2040 case 14:
2041 case 26:
2042 case 33:
2043 echo
2044 " if (f.$fldname.selectedIndex <= 0) {\n" .
2045 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2046 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2047 " }\n";
2048 break;
2049 case 27: // radio buttons
2050 echo
2051 " var i = 0;\n" .
2052 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2053 " if (i >= f.$fldname.length) {\n" .
2054 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2055 " }\n";
2056 break;
2057 case 2:
2058 case 3:
2059 case 4:
2060 case 15:
2061 echo
2062 " if (trimlen(f.$fldname.value) == 0) {\n" .
2063 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2064 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2065 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2066 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2067 " } else { " .
2068 " $('#" . $fldname . "').attr('style',''); " .
2069 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2070 " } \n";
2071 break;
2077 * DROPDOWN FOR FACILITIES
2079 * build a dropdown with all facilities
2081 * @param string $selected - name of the currently selected facility
2082 * use '0' for "unspecified facility"
2083 * use '' for "All facilities" (the default)
2084 * @param string $name - the name/id for select form (defaults to "form_facility")
2085 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2086 * defaults to true
2087 * @return void - just echo the html encoded string
2089 * Note: This should become a data-type at some point, according to Brady
2091 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true, $allow_allfacilities = true) {
2092 $have_selected = false;
2093 $query = "SELECT id, name FROM facility ORDER BY name";
2094 $fres = sqlStatement($query);
2096 $name = htmlspecialchars($name, ENT_QUOTES);
2097 echo " <select name=\"$name\" id=\"$name\">\n";
2099 if ($allow_allfacilities) {
2100 $option_value = '';
2101 $option_selected_attr = '';
2102 if ($selected == '') {
2103 $option_selected_attr = ' selected="selected"';
2104 $have_selected = true;
2106 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2107 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2108 } elseif ($allow_unspecified) {
2109 $option_value = '0';
2110 $option_selected_attr = '';
2111 if ( $selected == '0' ) {
2112 $option_selected_attr = ' selected="selected"';
2113 $have_selected = true;
2115 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2116 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2119 while ($frow = sqlFetchArray($fres)) {
2120 $facility_id = $frow['id'];
2121 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2122 $option_selected_attr = '';
2123 if ($selected == $facility_id) {
2124 $option_selected_attr = ' selected="selected"';
2125 $have_selected = true;
2127 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2128 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2131 if ($allow_unspecified && $allow_allfacilities) {
2132 $option_value = '0';
2133 $option_selected_attr = '';
2134 if ( $selected == '0' ) {
2135 $option_selected_attr = ' selected="selected"';
2136 $have_selected = true;
2138 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2139 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2142 if (!$have_selected) {
2143 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2144 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2145 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2146 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2148 echo " </select>\n";
2151 // Expand Collapse Widget
2152 // This forms the header and functionality component of the widget. The information that is displayed
2153 // then follows this function followed by a closing div tag
2155 // $title is the title of the section (already translated)
2156 // $label is identifier used in the tag id's and sql columns
2157 // $buttonLabel is the button label text (already translated)
2158 // $buttonLink is the button link information
2159 // $buttonClass is any additional needed class elements for the button tag
2160 // $linkMethod is the button link method ('javascript' vs 'html')
2161 // $bodyClass is to set class(es) of the body
2162 // $auth is a flag to decide whether to show the button
2163 // $fixedWidth is to flag whether width is fixed
2164 // $forceExpandAlways is a flag to force the widget to always be expanded
2166 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2167 if ($fixedWidth) {
2168 echo "<div class='section-header'>";
2170 else {
2171 echo "<div class='section-header-dynamic'>";
2173 echo "<table><tr>";
2174 if ($auth) {
2175 // show button, since authorized
2176 // first prepare class string
2177 if ($buttonClass) {
2178 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
2180 else {
2181 $class_string = "css_button_small";
2183 // next, create the link
2184 if ($linkMethod == "javascript") {
2185 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2187 else {
2188 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
2189 if (!isset($_SESSION['patient_portal_onsite'])) {
2190 // prevent an error from occuring when calling the function from the patient portal
2191 echo " onclick='top.restoreSession()'";
2194 if (!$GLOBALS['concurrent_layout']) {
2195 echo " target='Main'";
2197 echo "><span>" .
2198 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
2200 if ($forceExpandAlways){
2201 // Special case to force the widget to always be expanded
2202 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2203 $indicatorTag ="style='display:none'";
2205 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
2206 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2207 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
2208 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2210 if (isset($_SESSION['patient_portal_onsite'])) {
2211 // collapse all entries in the patient portal
2212 $text = xl('expand');
2214 else if (getUserSetting($label."_ps_expand")) {
2215 $text = xl('collapse');
2217 else {
2218 $text = xl('expand');
2220 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
2221 "</span>)</a></td>";
2222 echo "</tr></table>";
2223 echo "</div>";
2224 if ($forceExpandAlways) {
2225 // Special case to force the widget to always be expanded
2226 $styling = "";
2228 else if (isset($_SESSION['patient_portal_onsite'])) {
2229 // collapse all entries in the patient portal
2230 $styling = "style='display:none'";
2232 else if (getUserSetting($label."_ps_expand")) {
2233 $styling = "";
2235 else {
2236 $styling = "style='display:none'";
2238 if ($bodyClass) {
2239 $styling .= " class='" . $bodyClass . "'";
2241 //next, create the first div tag to hold the information
2242 // note the code that calls this function will then place the ending div tag after the data
2243 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
2246 //billing_facility fuction will give the dropdown list which contain billing faciliies.
2247 function billing_facility($name,$select){
2248 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
2249 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
2250 while ($facrow = sqlFetchArray($qsql)) {
2251 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
2252 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
2254 echo "</select>";