Some requested security fixes.
[openemr.git] / library / options.inc.php
blobc1b0ba18167b65d72fb95aead2e69382d9f44cb4
1 <?php
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>
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 // 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");
37 $date_init = "";
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 " .
44 "AND p.type = 2 " .
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 )
53 $s = '';
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))
83 $s .= " selected";
84 $got_selected = TRUE;
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>";
92 $s .= "</select>";
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>";
97 else {
98 $s .= "</select>";
100 return $s;
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'
126 $showEmpty = true;
127 if (isset($frow['empty_title'])) {
128 if ($frow['empty_title'] == "SKIP") {
129 //do not display an 'empty' choice
130 $showEmpty = false;
131 $empty_title = "Unassigned";
133 else {
134 $empty_title = $frow['empty_title'];
137 else {
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 : '');
147 // simple text field
148 else if ($data_type == 2) {
149 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
150 $maxlength = $frow['max_length'];
151 $string_maxlength = "";
152 // if max_length is set to zero, then do not set a maxlength
153 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
154 echo "<input type='text'" .
155 " name='form_$field_id_esc'" .
156 " id='form_$field_id_esc'" .
157 " size='$fldlength'" .
158 " $string_maxlength" .
159 " title='$description'" .
160 " value='$currescaped'";
161 if (strpos($frow['edit_options'], 'C') !== FALSE)
162 echo " onchange='capitalizeMe(this)'";
163 else if (strpos($frow['edit_options'], 'U') !== FALSE)
164 echo " onchange='this.value = this.value.toUpperCase()'";
165 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
166 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
167 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
168 echo " onblur='maskblur(this,\"$tmp\")'";
170 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0)
171 echo " readonly";
172 echo " />";
175 // long or multi-line text field
176 else if ($data_type == 3) {
177 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
178 $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
179 echo "<textarea" .
180 " name='form_$field_id_esc'" .
181 " id='form_$field_id_esc'" .
182 " title='$description'" .
183 " cols='$textCols'" .
184 " rows='$textRows'>" .
185 $currescaped . "</textarea>";
188 // date
189 else if ($data_type == 4) {
190 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
191 " value='$currescaped'" .
192 " title='$description'" .
193 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
194 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
195 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
196 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
197 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
200 // provider list, local providers only
201 else if ($data_type == 10) {
202 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
203 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
204 "AND authorized = 1 " .
205 "ORDER BY lname, fname");
206 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
207 echo "<option value=''>" . htmlspecialchars(xl($empty_title), ENT_NOQUOTES) . "</option>";
208 while ($urow = sqlFetchArray($ures)) {
209 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
210 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
211 echo "<option value='$optionId'";
212 if ($urow['id'] == $currvalue) echo " selected";
213 echo ">$uname</option>";
215 echo "</select>";
218 // provider list, including address book entries with an NPI number
219 else if ($data_type == 11) {
220 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
221 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
222 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
223 "ORDER BY lname, fname");
224 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
225 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
226 while ($urow = sqlFetchArray($ures)) {
227 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
228 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
229 echo "<option value='$optionId'";
230 if ($urow['id'] == $currvalue) echo " selected";
231 echo ">$uname</option>";
233 echo "</select>";
236 // pharmacy list
237 else if ($data_type == 12) {
238 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
239 echo "<option value='0'></option>";
240 $pres = get_pharmacies();
241 while ($prow = sqlFetchArray($pres)) {
242 $key = $prow['id'];
243 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
244 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
245 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
246 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
247 echo "<option value='$optionValue'";
248 if ($currvalue == $key) echo " selected";
249 echo ">$optionLabel</option>";
251 echo "</select>";
254 // squads
255 else if ($data_type == 13) {
256 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
257 echo "<option value=''>&nbsp;</option>";
258 $squads = acl_get_squads();
259 if ($squads) {
260 foreach ($squads as $key => $value) {
261 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
262 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
263 echo "<option value='$optionValue'";
264 if ($currvalue == $key) echo " selected";
265 echo ">$optionLabel</option>\n";
268 echo "</select>";
271 // Address book, preferring organization name if it exists and is not in
272 // parentheses, and excluding local users who are not providers.
273 // Supports "referred to" practitioners and facilities.
274 // Alternatively the letter L in edit_options means that abook_type
275 // must be "ord_lab", indicating types used with the procedure
276 // lab ordering system.
277 // Alternatively the letter O in edit_options means that abook_type
278 // must begin with "ord_", indicating types used with the procedure
279 // ordering system.
280 // Alternatively the letter V in edit_options means that abook_type
281 // must be "vendor", indicating the Vendor type.
282 // Alternatively the letter R in edit_options means that abook_type
283 // must be "dist", indicating the Distributor type.
284 else if ($data_type == 14) {
285 if (strpos($frow['edit_options'], 'L') !== FALSE)
286 $tmp = "abook_type = 'ord_lab'";
287 else if (strpos($frow['edit_options'], 'O') !== FALSE)
288 $tmp = "abook_type LIKE 'ord\\_%'";
289 else if (strpos($frow['edit_options'], 'V') !== FALSE)
290 $tmp = "abook_type LIKE 'vendor%'";
291 else if (strpos($frow['edit_options'], 'R') !== FALSE)
292 $tmp = "abook_type LIKE 'dist'";
293 else
294 $tmp = "( username = '' OR authorized = 1 )";
295 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
296 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
297 "AND $tmp " .
298 "ORDER BY organization, lname, fname");
299 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
300 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
301 while ($urow = sqlFetchArray($ures)) {
302 $uname = $urow['organization'];
303 if (empty($uname) || substr($uname, 0, 1) == '(') {
304 $uname = $urow['lname'];
305 if ($urow['fname']) $uname .= ", " . $urow['fname'];
307 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
308 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
309 echo "<option value='$optionValue'";
310 $title = $urow['username'] ? xl('Local') : xl('External');
311 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
312 echo " title='$optionTitle'";
313 if ($urow['id'] == $currvalue) echo " selected";
314 echo ">$optionLabel</option>";
316 echo "</select>";
319 // a billing code
320 else if ($data_type == 15) {
321 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
322 $maxlength = $frow['max_length'];
323 $string_maxlength = "";
324 // if max_length is set to zero, then do not set a maxlength
325 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
326 echo "<input type='text'" .
327 " name='form_$field_id_esc'" .
328 " id='form_related_code'" .
329 " size='$fldlength'" .
330 " $string_maxlength" .
331 " title='$description'" .
332 " value='$currescaped'" .
333 " onclick='sel_related(this)' readonly" .
334 " />";
337 // a set of labeled checkboxes
338 else if ($data_type == 21) {
339 // In this special case, fld_length is the number of columns generated.
340 $cols = max(1, $frow['fld_length']);
341 $avalue = explode('|', $currvalue);
342 $lres = sqlStatement("SELECT * FROM list_options " .
343 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
344 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
345 $tdpct = (int) (100 / $cols);
346 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
347 $option_id = $lrow['option_id'];
348 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
349 // if ($count) echo "<br />";
350 if ($count % $cols == 0) {
351 if ($count) echo "</tr>";
352 echo "<tr>";
354 echo "<td width='$tdpct%'>";
355 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]' id='form_{$field_id_esc}[$option_id_esc]' value='1'";
356 if (in_array($option_id, $avalue)) echo " checked";
358 // Added 5-09 by BM - Translate label if applicable
359 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
361 echo "</td>";
363 if ($count) {
364 echo "</tr>";
365 if ($count > $cols) {
366 // Add some space after multiple rows of checkboxes.
367 $cols = htmlspecialchars( $cols, ENT_QUOTES);
368 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
371 echo "</table>";
374 // a set of labeled text input fields
375 else if ($data_type == 22) {
376 $tmp = explode('|', $currvalue);
377 $avalue = array();
378 foreach ($tmp as $value) {
379 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
380 $avalue[$matches[1]] = $matches[2];
383 $lres = sqlStatement("SELECT * FROM list_options " .
384 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
385 echo "<table cellpadding='0' cellspacing='0'>";
386 while ($lrow = sqlFetchArray($lres)) {
387 $option_id = $lrow['option_id'];
388 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
389 $maxlength = $frow['max_length'];
390 $string_maxlength = "";
391 // if max_length is set to zero, then do not set a maxlength
392 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
393 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
395 // Added 5-09 by BM - Translate label if applicable
396 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
397 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
398 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
399 echo "<td><input type='text'" .
400 " name='form_{$field_id_esc}[$option_id_esc]'" .
401 " id='form_{$field_id_esc}[$option_id_esc]'" .
402 " size='$fldlength'" .
403 " $string_maxlength" .
404 " value='$optionValue'";
405 echo " /></td></tr>";
407 echo "</table>";
410 // a set of exam results; 3 radio buttons and a text field:
411 else if ($data_type == 23) {
412 $tmp = explode('|', $currvalue);
413 $avalue = array();
414 foreach ($tmp as $value) {
415 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
416 $avalue[$matches[1]] = $matches[2];
419 $maxlength = $frow['max_length'];
420 $string_maxlength = "";
421 // if max_length is set to zero, then do not set a maxlength
422 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
423 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
424 $lres = sqlStatement("SELECT * FROM list_options " .
425 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
426 echo "<table cellpadding='0' cellspacing='0'>";
427 echo "<tr><td>&nbsp;</td><td class='bold'>" .
428 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
429 "&nbsp;</td><td class='bold'>" .
430 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
431 "<td class='bold'>" .
432 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
433 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
434 while ($lrow = sqlFetchArray($lres)) {
435 $option_id = $lrow['option_id'];
436 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
437 $restype = substr($avalue[$option_id], 0, 1);
438 $resnote = substr($avalue[$option_id], 2);
440 // Added 5-09 by BM - Translate label if applicable
441 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
443 for ($i = 0; $i < 3; ++$i) {
444 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
445 echo "<td><input type='radio'" .
446 " name='radio_{$field_id_esc}[$option_id_esc]'" .
447 " id='radio_{$field_id_esc}[$option_id_esc]'" .
448 " value='$inputValue'";
449 if ($restype === "$i") echo " checked";
450 echo " /></td>";
452 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
453 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
454 echo "<td><input type='text'" .
455 " name='form_{$field_id_esc}[$option_id_esc]'" .
456 " id='form_{$field_id_esc}[$option_id_esc]'" .
457 " size='$fldlength'" .
458 " $string_maxlength" .
459 " value='$resnote' /></td>";
460 echo "</tr>";
462 echo "</table>";
465 // the list of active allergies for the current patient
466 // this is read-only!
467 else if ($data_type == 24) {
468 $query = "SELECT title, comments FROM lists WHERE " .
469 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
470 "ORDER BY begdate";
471 // echo "<!-- $query -->\n"; // debugging
472 $lres = sqlStatement($query, array($GLOBALS['pid']));
473 $count = 0;
474 while ($lrow = sqlFetchArray($lres)) {
475 if ($count++) echo "<br />";
476 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
477 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
481 // a set of labeled checkboxes, each with a text field:
482 else if ($data_type == 25) {
483 $tmp = explode('|', $currvalue);
484 $avalue = array();
485 foreach ($tmp as $value) {
486 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
487 $avalue[$matches[1]] = $matches[2];
490 $maxlength = $frow['max_length'];
491 $string_maxlength = "";
492 // if max_length is set to zero, then do not set a maxlength
493 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
494 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
495 $lres = sqlStatement("SELECT * FROM list_options " .
496 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
497 echo "<table cellpadding='0' cellspacing='0'>";
498 while ($lrow = sqlFetchArray($lres)) {
499 $option_id = $lrow['option_id'];
500 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
501 $restype = substr($avalue[$option_id], 0, 1);
502 $resnote = substr($avalue[$option_id], 2);
504 // Added 5-09 by BM - Translate label if applicable
505 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
507 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
508 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]' id='check_{$field_id_esc}[$option_id_esc]' value='1'";
509 if ($restype) echo " checked";
510 echo " />&nbsp;</td>";
511 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
512 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
513 echo "<td><input type='text'" .
514 " name='form_{$field_id_esc}[$option_id_esc]'" .
515 " id='form_{$field_id_esc}[$option_id_esc]'" .
516 " size='$fldlength'" .
517 " $string_maxlength" .
518 " value='$resnote' /></td>";
519 echo "</tr>";
521 echo "</table>";
524 // single-selection list with ability to add to it
525 else if ($data_type == 26) {
526 echo "<select class='addtolistclass_$list_id_esc' name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
527 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES) . "</option>";
528 $lres = sqlStatement("SELECT * FROM list_options " .
529 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
530 $got_selected = FALSE;
531 while ($lrow = sqlFetchArray($lres)) {
532 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
533 echo "<option value='$optionValue'";
534 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
535 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
537 echo " selected";
538 $got_selected = TRUE;
540 // Added 5-09 by BM - Translate label if applicable
541 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n";
543 if (!$got_selected && strlen($currvalue) > 0) {
544 echo "<option value='$currescaped' selected>* $currescaped *</option>";
545 echo "</select>";
546 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES);
547 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
548 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
550 else {
551 echo "</select>";
553 // show the add button if user has access to correct list
554 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
555 $outputAddButton = "<input type='button' id='addtolistid_".$list_id_esc."' fieldid='form_".$field_id_esc."' class='addtolist' value='$inputValue'>";
556 if (aco_exist('lists', $list_id)) {
557 // a specific aco exist for this list, so ensure access
558 if (acl_check('lists', $list_id)) echo $outputAddButton;
560 else {
561 // no specific aco exist for this list, so check for access to 'default' list
562 if (acl_check('lists', 'default')) echo $outputAddButton;
566 // a set of labeled radio buttons
567 else if ($data_type == 27) {
568 // In this special case, fld_length is the number of columns generated.
569 $cols = max(1, $frow['fld_length']);
570 $lres = sqlStatement("SELECT * FROM list_options " .
571 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
572 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
573 $tdpct = (int) (100 / $cols);
574 $got_selected = FALSE;
575 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
576 $option_id = $lrow['option_id'];
577 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
578 if ($count % $cols == 0) {
579 if ($count) echo "</tr>";
580 echo "<tr>";
582 echo "<td width='$tdpct%'>";
583 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]' value='$option_id_esc'";
584 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
585 (strlen($currvalue) > 0 && $option_id == $currvalue))
587 echo " checked";
588 $got_selected = TRUE;
590 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
591 echo "</td>";
593 if ($count) {
594 echo "</tr>";
595 if ($count > $cols) {
596 // Add some space after multiple rows of radio buttons.
597 $cols = htmlspecialchars( $cols, ENT_QUOTES);
598 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
601 echo "</table>";
602 if (!$got_selected && strlen($currvalue) > 0) {
603 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
604 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
605 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
609 // special case for history of lifestyle status; 3 radio buttons and a date text field:
610 // VicarePlus :: A selection list box for smoking status:
611 else if ($data_type == 28 || $data_type == 32) {
612 $tmp = explode('|', $currvalue);
613 switch(count($tmp)) {
614 case "4": {
615 $resnote = $tmp[0];
616 $restype = $tmp[1];
617 $resdate = $tmp[2];
618 $reslist = $tmp[3];
619 } break;
620 case "3": {
621 $resnote = $tmp[0];
622 $restype = $tmp[1];
623 $resdate = $tmp[2];
624 } break;
625 case "2": {
626 $resnote = $tmp[0];
627 $restype = $tmp[1];
628 $resdate = "";
629 } break;
630 case "1": {
631 $resnote = $tmp[0];
632 $resdate = $restype = "";
633 } break;
634 default: {
635 $restype = $resdate = $resnote = "";
636 } break;
638 $maxlength = $frow['max_length'];
639 $string_maxlength = "";
640 // if max_length is set to zero, then do not set a maxlength
641 if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
642 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
644 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
645 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
646 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
647 echo "<table cellpadding='0' cellspacing='0'>";
648 echo "<tr>";
649 if ($data_type == 28)
651 // input text
652 echo "<td><input type='text'" .
653 " name='form_$field_id_esc'" .
654 " id='form_$field_id_esc'" .
655 " size='$fldlength'" .
656 " $string_maxlength" .
657 " value='$resnote' />&nbsp;</td>";
658 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
659 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
660 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
662 else if($data_type == 32)
664 // input text
665 echo "<tr><td><input type='text'" .
666 " name='form_text_$field_id_esc'" .
667 " id='form_text_$field_id_esc'" .
668 " size='$fldlength'" .
669 " $string_maxlength" .
670 " value='$resnote' />&nbsp;</td></tr>";
671 echo "<td>";
672 //Selection list for smoking status
673 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
674 echo generate_select_list("form_$field_id", $list_id, $reslist,
675 $description, $showEmpty ? $empty_title : '', '', $onchange)."</td>";
676 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
678 // current
679 echo "<td><input type='radio'" .
680 " name='radio_{$field_id_esc}'" .
681 " id='radio_{$field_id_esc}[current]'" .
682 " value='current".$field_id_esc."'";
683 if ($restype == "current".$field_id) echo " checked";
684 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
685 // quit
686 echo "<td><input type='radio'" .
687 " name='radio_{$field_id_esc}'" .
688 " id='radio_{$field_id_esc}[quit]'" .
689 " value='quit".$field_id_esc."'";
690 if ($restype == "quit".$field_id) echo " checked";
691 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
692 // quit date
693 echo "<td><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
694 " value='$resdate'" .
695 " title='$description'" .
696 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
697 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
698 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
699 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />&nbsp;</td>";
700 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
701 // never
702 echo "<td><input type='radio'" .
703 " name='radio_{$field_id_esc}'" .
704 " id='radio_{$field_id_esc}[never]'" .
705 " value='never".$field_id_esc."'";
706 if ($restype == "never".$field_id) echo " checked";
707 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."&nbsp;</td>";
708 // Not Applicable
709 echo "<td><input type='radio'" .
710 " name='radio_{$field_id}'" .
711 " id='radio_{$field_id}[not_applicable]'" .
712 " value='not_applicable".$field_id."'";
713 if ($restype == "not_applicable".$field_id) echo " checked";
714 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('N/A'), ENT_QUOTES)."&nbsp;</td>";
715 echo "</tr>";
716 echo "</table>";
719 // static text. read-only, of course.
720 else if ($data_type == 31) {
721 echo nl2br($frow['description']);
724 //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.
725 else if ($data_type == 33) {
726 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
727 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES) . "</option>";
728 $lres = sqlStatement("SELECT * FROM list_options " .
729 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
730 $got_selected = FALSE;
731 while ($lrow = sqlFetchArray($lres)) {
732 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
733 echo "<option value='$optionValue'";
734 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
735 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
737 echo " selected";
738 $got_selected = TRUE;
741 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n";
743 if (!$got_selected && strlen($currvalue) > 0)
745 //Check 'ethrace' list if the entry does not exist in the list_id of the given list(Race or Ethnicity).
746 $list_id='ethrace';
747 $lrow = sqlQuery("SELECT title FROM list_options " .
748 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
749 if ($lrow > 0)
751 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
752 echo "<option value='$currvalue' selected> $s </option>";
753 echo "</select>";
755 else
757 echo "<option value='$currescaped' selected>* $currescaped *</option>";
758 echo "</select>";
759 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES);
760 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
761 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
764 else {
765 echo "</select>";
768 else if($data_type == 34){
769 $arr = explode("|*|*|*|",$currvalue);
770 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;'>";
771 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
772 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'>".$currvalue."</textarea></div>";
773 echo "</a>";
776 //facilities drop-down list
777 else if ($data_type == 35) {
778 if (empty($currvalue)){
779 $currvalue = 0;
781 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
786 function generate_print_field($frow, $currvalue) {
787 global $rootdir, $date_init;
789 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
791 $data_type = $frow['data_type'];
792 $field_id = $frow['field_id'];
793 $list_id = $frow['list_id'];
794 $fld_length = $frow['fld_length'];
796 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
798 // Can pass $frow['empty_title'] with this variable, otherwise
799 // will default to 'Unassigned'.
800 // If it is 'SKIP' then an empty text title is completely skipped.
801 $showEmpty = true;
802 if (isset($frow['empty_title'])) {
803 if ($frow['empty_title'] == "SKIP") {
804 //do not display an 'empty' choice
805 $showEmpty = false;
806 $empty_title = "Unassigned";
808 else {
809 $empty_title = $frow['empty_title'];
812 else {
813 $empty_title = "Unassigned";
816 // generic single-selection list
817 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
818 if (empty($fld_length)) {
819 if ($list_id == 'titles') {
820 $fld_length = 3;
821 } else {
822 $fld_length = 10;
825 $tmp = '';
826 if ($currvalue) {
827 $lrow = sqlQuery("SELECT title FROM list_options " .
828 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
829 $tmp = xl_list_label($lrow['title']);
830 if (empty($tmp)) $tmp = "($currvalue)";
832 /*****************************************************************
833 echo "<input type='text'" .
834 " size='$fld_length'" .
835 " value='$tmp'" .
836 " class='under'" .
837 " />";
838 *****************************************************************/
839 if ($tmp === '') { $tmp = '&nbsp;'; }
840 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
841 echo $tmp;
844 // simple text field
845 else if ($data_type == 2 || $data_type == 15) {
846 /*****************************************************************
847 echo "<input type='text'" .
848 " size='$fld_length'" .
849 " value='$currescaped'" .
850 " class='under'" .
851 " />";
852 *****************************************************************/
853 if ($currescaped === '') $currescaped = '&nbsp;';
854 echo $currescaped;
857 // long or multi-line text field
858 else if ($data_type == 3) {
859 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
860 $maxlength = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
861 echo "<textarea" .
862 " cols='$fldlength'" .
863 " rows='$maxlength'>" .
864 $currescaped . "</textarea>";
867 // date
868 else if ($data_type == 4) {
869 /*****************************************************************
870 echo "<input type='text' size='10'" .
871 " value='$currescaped'" .
872 " title='$description'" .
873 " class='under'" .
874 " />";
875 *****************************************************************/
876 if ($currvalue === '') { $tmp = oeFormatShortDate('&nbsp;'); }
877 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES); }
878 echo $tmp;
881 // provider list
882 else if ($data_type == 10 || $data_type == 11) {
883 $tmp = '';
884 if ($currvalue) {
885 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
886 "WHERE id = ?", array($currvalue) );
887 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
888 if (empty($tmp)) $tmp = "($currvalue)";
890 /*****************************************************************
891 echo "<input type='text'" .
892 " size='$fld_length'" .
893 " value='$tmp'" .
894 " class='under'" .
895 " />";
896 *****************************************************************/
897 if ($tmp === '') { $tmp = '&nbsp;'; }
898 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
899 echo $tmp;
902 // pharmacy list
903 else if ($data_type == 12) {
904 $tmp = '';
905 if ($currvalue) {
906 $pres = get_pharmacies();
907 while ($prow = sqlFetchArray($pres)) {
908 $key = $prow['id'];
909 if ($currvalue == $key) {
910 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
911 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
912 $prow['line1'] . ' / ' . $prow['city'];
915 if (empty($tmp)) $tmp = "($currvalue)";
917 /*****************************************************************
918 echo "<input type='text'" .
919 " size='$fld_length'" .
920 " value='$tmp'" .
921 " class='under'" .
922 " />";
923 *****************************************************************/
924 if ($tmp === '') { $tmp = '&nbsp;'; }
925 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
926 echo $tmp;
929 // squads
930 else if ($data_type == 13) {
931 $tmp = '';
932 if ($currvalue) {
933 $squads = acl_get_squads();
934 if ($squads) {
935 foreach ($squads as $key => $value) {
936 if ($currvalue == $key) {
937 $tmp = $value[3];
941 if (empty($tmp)) $tmp = "($currvalue)";
943 /*****************************************************************
944 echo "<input type='text'" .
945 " size='$fld_length'" .
946 " value='$tmp'" .
947 " class='under'" .
948 " />";
949 *****************************************************************/
950 if ($tmp === '') { $tmp = '&nbsp;'; }
951 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
952 echo $tmp;
955 // Address book.
956 else if ($data_type == 14) {
957 $tmp = '';
958 if ($currvalue) {
959 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
960 "WHERE id = ?", array($currvalue) );
961 $uname = $urow['lname'];
962 if ($urow['fname']) $uname .= ", " . $urow['fname'];
963 $tmp = $uname;
964 if (empty($tmp)) $tmp = "($currvalue)";
966 /*****************************************************************
967 echo "<input type='text'" .
968 " size='$fld_length'" .
969 " value='$tmp'" .
970 " class='under'" .
971 " />";
972 *****************************************************************/
973 if ($tmp === '') { $tmp = '&nbsp;'; }
974 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
975 echo $tmp;
978 // a set of labeled checkboxes
979 else if ($data_type == 21) {
980 // In this special case, fld_length is the number of columns generated.
981 $cols = max(1, $fld_length);
982 $avalue = explode('|', $currvalue);
983 $lres = sqlStatement("SELECT * FROM list_options " .
984 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
985 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
986 $tdpct = (int) (100 / $cols);
987 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
988 $option_id = $lrow['option_id'];
989 if ($count % $cols == 0) {
990 if ($count) echo "</tr>";
991 echo "<tr>";
993 echo "<td width='$tdpct%'>";
994 echo "<input type='checkbox'";
995 if (in_array($option_id, $avalue)) echo " checked";
996 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
997 echo "</td>";
999 if ($count) {
1000 echo "</tr>";
1001 if ($count > $cols) {
1002 // Add some space after multiple rows of checkboxes.
1003 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1004 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1007 echo "</table>";
1010 // a set of labeled text input fields
1011 else if ($data_type == 22) {
1012 $tmp = explode('|', $currvalue);
1013 $avalue = array();
1014 foreach ($tmp as $value) {
1015 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1016 $avalue[$matches[1]] = $matches[2];
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 while ($lrow = sqlFetchArray($lres)) {
1023 $option_id = $lrow['option_id'];
1024 $fldlength = empty($fld_length) ? 20 : $fld_length;
1025 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1026 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1027 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
1028 echo "<td><input type='text'" .
1029 " size='$fldlength'" .
1030 " value='$inputValue'" .
1031 " class='under'" .
1032 " /></td></tr>";
1034 echo "</table>";
1037 // a set of exam results; 3 radio buttons and a text field:
1038 else if ($data_type == 23) {
1039 $tmp = explode('|', $currvalue);
1040 $avalue = array();
1041 foreach ($tmp as $value) {
1042 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1043 $avalue[$matches[1]] = $matches[2];
1046 $fldlength = empty($fld_length) ? 20 : $fld_length;
1047 $lres = sqlStatement("SELECT * FROM list_options " .
1048 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1049 echo "<table cellpadding='0' cellspacing='0'>";
1050 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1051 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1052 "&nbsp;</td><td class='bold'>" .
1053 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1054 "<td class='bold'>" .
1055 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1056 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1057 while ($lrow = sqlFetchArray($lres)) {
1058 $option_id = $lrow['option_id'];
1059 $restype = substr($avalue[$option_id], 0, 1);
1060 $resnote = substr($avalue[$option_id], 2);
1061 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1062 for ($i = 0; $i < 3; ++$i) {
1063 echo "<td><input type='radio'";
1064 if ($restype === "$i") echo " checked";
1065 echo " /></td>";
1067 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1068 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1069 echo "<td><input type='text'" .
1070 " size='$fldlength'" .
1071 " value='$resnote'" .
1072 " class='under' /></td>" .
1073 "</tr>";
1075 echo "</table>";
1078 // the list of active allergies for the current patient
1079 // this is read-only!
1080 else if ($data_type == 24) {
1081 $query = "SELECT title, comments FROM lists WHERE " .
1082 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1083 "ORDER BY begdate";
1084 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1085 $count = 0;
1086 while ($lrow = sqlFetchArray($lres)) {
1087 if ($count++) echo "<br />";
1088 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1089 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1093 // a set of labeled checkboxes, each with a text field:
1094 else if ($data_type == 25) {
1095 $tmp = explode('|', $currvalue);
1096 $avalue = array();
1097 foreach ($tmp as $value) {
1098 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1099 $avalue[$matches[1]] = $matches[2];
1102 $fldlength = empty($fld_length) ? 20 : $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'>";
1106 while ($lrow = sqlFetchArray($lres)) {
1107 $option_id = $lrow['option_id'];
1108 $restype = substr($avalue[$option_id], 0, 1);
1109 $resnote = substr($avalue[$option_id], 2);
1110 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1111 echo "<td><input type='checkbox'";
1112 if ($restype) echo " checked";
1113 echo " />&nbsp;</td>";
1114 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1115 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1116 echo "<td><input type='text'" .
1117 " size='$fldlength'" .
1118 " value='$resnote'" .
1119 " class='under'" .
1120 " /></td>" .
1121 "</tr>";
1123 echo "</table>";
1126 // a set of labeled radio buttons
1127 else if ($data_type == 27) {
1128 // In this special case, fld_length is the number of columns generated.
1129 $cols = max(1, $frow['fld_length']);
1130 $lres = sqlStatement("SELECT * FROM list_options " .
1131 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1132 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1133 $tdpct = (int) (100 / $cols);
1134 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1135 $option_id = $lrow['option_id'];
1136 if ($count % $cols == 0) {
1137 if ($count) echo "</tr>";
1138 echo "<tr>";
1140 echo "<td width='$tdpct%'>";
1141 echo "<input type='radio'";
1142 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1143 (strlen($currvalue) > 0 && $option_id == $currvalue))
1145 echo " checked";
1147 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1148 echo "</td>";
1150 if ($count) {
1151 echo "</tr>";
1152 if ($count > $cols) {
1153 // Add some space after multiple rows of radio buttons.
1154 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1155 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1158 echo "</table>";
1161 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1162 else if ($data_type == 28 || $data_type == 32) {
1163 $tmp = explode('|', $currvalue);
1164 switch(count($tmp)) {
1165 case "4": {
1166 $resnote = $tmp[0];
1167 $restype = $tmp[1];
1168 $resdate = $tmp[2];
1169 $reslist = $tmp[3];
1170 } break;
1171 case "3": {
1172 $resnote = $tmp[0];
1173 $restype = $tmp[1];
1174 $resdate = $tmp[2];
1175 } break;
1176 case "2": {
1177 $resnote = $tmp[0];
1178 $restype = $tmp[1];
1179 $resdate = "";
1180 } break;
1181 case "1": {
1182 $resnote = $tmp[0];
1183 $resdate = $restype = "";
1184 } break;
1185 default: {
1186 $restype = $resdate = $resnote = "";
1187 } break;
1189 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1190 echo "<table cellpadding='0' cellspacing='0'>";
1191 echo "<tr>";
1192 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1193 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1194 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1195 if($data_type == 28)
1197 echo "<td><input type='text'" .
1198 " size='$fldlength'" .
1199 " class='under'" .
1200 " value='$resnote' /></td>";
1201 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1202 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1203 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1205 else if($data_type == 32)
1207 echo "<tr><td><input type='text'" .
1208 " size='$fldlength'" .
1209 " class='under'" .
1210 " value='$resnote' /></td></tr>";
1211 $fldlength = 30;
1212 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1213 echo "<td><input type='text'" .
1214 " size='$fldlength'" .
1215 " class='under'" .
1216 " value='$smoking_status_title' /></td>";
1217 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1219 echo "<td><input type='radio'";
1220 if ($restype == "current".$field_id) echo " checked";
1221 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1223 echo "<td><input type='radio'";
1224 if ($restype == "current".$field_id) echo " checked";
1225 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1227 echo "<td><input type='text' size='6'" .
1228 " value='$resdate'" .
1229 " class='under'" .
1230 " /></td>";
1232 echo "<td><input type='radio'";
1233 if ($restype == "current".$field_id) echo " checked";
1234 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1236 echo "<td><input type='radio'";
1237 if ($restype == "not_applicable".$field_id) echo " checked";
1238 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1239 echo "</tr>";
1240 echo "</table>";
1243 // static text. read-only, of course.
1244 else if ($data_type == 31) {
1245 echo nl2br($frow['description']);
1248 else if($data_type == 34){
1249 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;'>";
1250 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1251 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1252 echo "</a>";
1255 //facilities drop-down list
1256 else if ($data_type == 35) {
1257 if (empty($currvalue)){
1258 $currvalue = 0;
1260 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1265 function generate_display_field($frow, $currvalue) {
1266 $data_type = $frow['data_type'];
1267 $field_id = isset($frow['field_id']) ? $frow['field_id'] : null;
1268 $list_id = $frow['list_id'];
1269 $s = '';
1271 // generic selection list or the generic selection list with add on the fly
1272 // feature, or radio buttons
1273 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1274 $lrow = sqlQuery("SELECT title FROM list_options " .
1275 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1276 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1277 //For lists Race and Ethnicity if there is no matching value in the corresponding lists check ethrace list
1278 if ($lrow == 0 && $data_type == 33)
1280 $list_id='ethrace';
1281 $lrow_ethrace = sqlQuery("SELECT title FROM list_options " .
1282 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1283 $s = htmlspecialchars(xl_list_label($lrow_ethrace['title']),ENT_NOQUOTES);
1287 // simple text field
1288 else if ($data_type == 2) {
1289 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1292 // long or multi-line text field
1293 else if ($data_type == 3) {
1294 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1297 // date
1298 else if ($data_type == 4) {
1299 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES);
1302 // provider
1303 else if ($data_type == 10 || $data_type == 11) {
1304 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1305 "WHERE id = ?", array($currvalue) );
1306 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1309 // pharmacy list
1310 else if ($data_type == 12) {
1311 $pres = get_pharmacies();
1312 while ($prow = sqlFetchArray($pres)) {
1313 $key = $prow['id'];
1314 if ($currvalue == $key) {
1315 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1316 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1317 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1322 // squads
1323 else if ($data_type == 13) {
1324 $squads = acl_get_squads();
1325 if ($squads) {
1326 foreach ($squads as $key => $value) {
1327 if ($currvalue == $key) {
1328 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1334 // address book
1335 else if ($data_type == 14) {
1336 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1337 "WHERE id = ?", array($currvalue));
1338 $uname = $urow['lname'];
1339 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1340 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1343 // billing code
1344 else if ($data_type == 15) {
1345 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1348 // a set of labeled checkboxes
1349 else if ($data_type == 21) {
1350 $avalue = explode('|', $currvalue);
1351 $lres = sqlStatement("SELECT * FROM list_options " .
1352 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1353 $count = 0;
1354 while ($lrow = sqlFetchArray($lres)) {
1355 $option_id = $lrow['option_id'];
1356 if (in_array($option_id, $avalue)) {
1357 if ($count++) $s .= "<br />";
1359 // Added 5-09 by BM - Translate label if applicable
1360 $s .= htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1366 // a set of labeled text input fields
1367 else if ($data_type == 22) {
1368 $tmp = explode('|', $currvalue);
1369 $avalue = array();
1370 foreach ($tmp as $value) {
1371 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1372 $avalue[$matches[1]] = $matches[2];
1375 $lres = sqlStatement("SELECT * FROM list_options " .
1376 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1377 $s .= "<table cellpadding='0' cellspacing='0'>";
1378 while ($lrow = sqlFetchArray($lres)) {
1379 $option_id = $lrow['option_id'];
1380 if (empty($avalue[$option_id])) continue;
1382 // Added 5-09 by BM - Translate label if applicable
1383 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1385 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1387 $s .= "</table>";
1390 // a set of exam results; 3 radio buttons and a text field:
1391 else if ($data_type == 23) {
1392 $tmp = explode('|', $currvalue);
1393 $avalue = array();
1394 foreach ($tmp as $value) {
1395 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1396 $avalue[$matches[1]] = $matches[2];
1399 $lres = sqlStatement("SELECT * FROM list_options " .
1400 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1401 $s .= "<table cellpadding='0' cellspacing='0'>";
1402 while ($lrow = sqlFetchArray($lres)) {
1403 $option_id = $lrow['option_id'];
1404 $restype = substr($avalue[$option_id], 0, 1);
1405 $resnote = substr($avalue[$option_id], 2);
1406 if (empty($restype) && empty($resnote)) continue;
1408 // Added 5-09 by BM - Translate label if applicable
1409 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1411 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1412 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1413 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1414 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1415 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1416 $s .= "</tr>";
1418 $s .= "</table>";
1421 // the list of active allergies for the current patient
1422 else if ($data_type == 24) {
1423 $query = "SELECT title, comments FROM lists WHERE " .
1424 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1425 "ORDER BY begdate";
1426 // echo "<!-- $query -->\n"; // debugging
1427 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1428 $count = 0;
1429 while ($lrow = sqlFetchArray($lres)) {
1430 if ($count++) $s .= "<br />";
1431 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1432 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1436 // a set of labeled checkboxes, each with a text field:
1437 else if ($data_type == 25) {
1438 $tmp = explode('|', $currvalue);
1439 $avalue = array();
1440 foreach ($tmp as $value) {
1441 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1442 $avalue[$matches[1]] = $matches[2];
1445 $lres = sqlStatement("SELECT * FROM list_options " .
1446 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1447 $s .= "<table cellpadding='0' cellspacing='0'>";
1448 while ($lrow = sqlFetchArray($lres)) {
1449 $option_id = $lrow['option_id'];
1450 $restype = substr($avalue[$option_id], 0, 1);
1451 $resnote = substr($avalue[$option_id], 2);
1452 if (empty($restype) && empty($resnote)) continue;
1454 // Added 5-09 by BM - Translate label if applicable
1455 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1457 $restype = $restype ? xl('Yes') : xl('No');
1458 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1459 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1460 $s .= "</tr>";
1462 $s .= "</table>";
1465 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1466 // VicarePlus :: A selection list for smoking status.
1467 else if ($data_type == 28 || $data_type == 32) {
1468 $tmp = explode('|', $currvalue);
1469 switch(count($tmp)) {
1470 case "4": {
1471 $resnote = $tmp[0];
1472 $restype = $tmp[1];
1473 $resdate = $tmp[2];
1474 $reslist = $tmp[3];
1475 } break;
1476 case "3": {
1477 $resnote = $tmp[0];
1478 $restype = $tmp[1];
1479 $resdate = $tmp[2];
1480 } break;
1481 case "2": {
1482 $resnote = $tmp[0];
1483 $restype = $tmp[1];
1484 $resdate = "";
1485 } break;
1486 case "1": {
1487 $resnote = $tmp[0];
1488 $resdate = $restype = "";
1489 } break;
1490 default: {
1491 $restype = $resdate = $resnote = "";
1492 } break;
1494 $s .= "<table cellpadding='0' cellspacing='0'>";
1496 $s .= "<tr>";
1497 $res = "";
1498 if ($restype == "current".$field_id) $res = xl('Current');
1499 if ($restype == "quit".$field_id) $res = xl('Quit');
1500 if ($restype == "never".$field_id) $res = xl('Never');
1501 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1502 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1503 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1504 if ($data_type == 28)
1506 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1508 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1509 else if ($data_type == 32)
1511 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>";
1512 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
1515 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1516 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1517 $s .= "</tr>";
1518 $s .= "</table>";
1521 // static text. read-only, of course.
1522 else if ($data_type == 31) {
1523 $s .= nl2br($frow['description']);
1526 else if($data_type == 34){
1527 $arr = explode("|*|*|*|",$currvalue);
1528 for($i=0;$i<sizeof($arr);$i++){
1529 $s.=$arr[$i];
1533 // facility
1534 else if ($data_type == 35) {
1535 $urow = sqlQuery("SELECT id, name FROM facility ".
1536 "WHERE id = ?", array($currvalue) );
1537 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES);
1540 return $s;
1543 $CPR = 4; // cells per row of generic data
1544 $last_group = '';
1545 $cell_count = 0;
1546 $item_count = 0;
1548 function disp_end_cell() {
1549 global $item_count, $cell_count;
1550 if ($item_count > 0) {
1551 echo "</td>";
1552 $item_count = 0;
1556 function disp_end_row() {
1557 global $cell_count, $CPR;
1558 disp_end_cell();
1559 if ($cell_count > 0) {
1560 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
1561 echo "</tr>\n";
1562 $cell_count = 0;
1566 function disp_end_group() {
1567 global $last_group;
1568 if (strlen($last_group) > 0) {
1569 disp_end_row();
1573 function display_layout_rows($formtype, $result1, $result2='') {
1574 global $item_count, $cell_count, $last_group, $CPR;
1576 $fres = sqlStatement("SELECT * FROM layout_options " .
1577 "WHERE form_id = ? AND uor > 0 " .
1578 "ORDER BY group_name, seq", array($formtype) );
1580 while ($frow = sqlFetchArray($fres)) {
1581 $this_group = $frow['group_name'];
1582 $titlecols = $frow['titlecols'];
1583 $datacols = $frow['datacols'];
1584 $data_type = $frow['data_type'];
1585 $field_id = $frow['field_id'];
1586 $list_id = $frow['list_id'];
1587 $currvalue = '';
1589 if ($formtype == 'DEM') {
1590 if ($GLOBALS['athletic_team']) {
1591 // Skip fitness level and return-to-play date because those appear
1592 // in a special display/update form on this page.
1593 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1595 if (strpos($field_id, 'em_') === 0) {
1596 // Skip employer related fields, if it's disabled.
1597 if ($GLOBALS['omit_employers']) continue;
1598 $tmp = substr($field_id, 3);
1599 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1601 else {
1602 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1605 else {
1606 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1609 // Handle a data category (group) change.
1610 if (strcmp($this_group, $last_group) != 0) {
1611 $group_name = substr($this_group, 1);
1612 // totally skip generating the employer category, if it's disabled.
1613 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1614 disp_end_group();
1615 $last_group = $this_group;
1618 // Handle starting of a new row.
1619 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1620 disp_end_row();
1621 echo "<tr>";
1622 if ($group_name) {
1623 echo "<td class='groupname'>";
1624 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1625 //echo "<font color='#008800'>$group_name</font>";
1627 // Added 5-09 by BM - Translate label if applicable
1628 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
1630 $group_name = '';
1631 } else {
1632 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1633 echo "<td valign='top'>&nbsp;";
1635 echo "</td>";
1638 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1640 // Handle starting of a new label cell.
1641 if ($titlecols > 0) {
1642 disp_end_cell();
1643 //echo "<td class='label' colspan='$titlecols' valign='top'";
1644 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1645 echo "<td class='label' colspan='$titlecols_esc' ";
1646 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1647 echo ">";
1648 $cell_count += $titlecols;
1650 ++$item_count;
1652 // Added 5-09 by BM - Translate label if applicable
1653 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1655 // Handle starting of a new data cell.
1656 if ($datacols > 0) {
1657 disp_end_cell();
1658 //echo "<td class='text data' colspan='$datacols' valign='top'";
1659 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1660 echo "<td class='text data' colspan='$datacols_esc'";
1661 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1662 echo ">";
1663 $cell_count += $datacols;
1666 ++$item_count;
1667 echo generate_display_field($frow, $currvalue);
1670 disp_end_group();
1673 function display_layout_tabs($formtype, $result1, $result2='') {
1674 global $item_count, $cell_count, $last_group, $CPR;
1676 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1677 "WHERE form_id = ? AND uor > 0 " .
1678 "ORDER BY group_name, seq", array($formtype) );
1680 $first = true;
1681 while ($frow = sqlFetchArray($fres)) {
1682 $this_group = $frow['group_name'];
1683 $group_name = substr($this_group, 1);
1685 <li <?php echo $first ? 'class="current"' : '' ?>>
1686 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES)."?>">
1687 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
1688 </li>
1689 <?php
1690 $first = false;
1694 function display_layout_tabs_data($formtype, $result1, $result2='') {
1695 global $item_count, $cell_count, $last_group, $CPR;
1697 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1698 "WHERE form_id = ? AND uor > 0 " .
1699 "ORDER BY group_name, seq", array($formtype));
1701 $first = true;
1702 while ($frow = sqlFetchArray($fres)) {
1703 $this_group = isset($frow['group_name']) ? $frow['group_name'] : "" ;
1704 $titlecols = isset($frow['titlecols']) ? $frow['titlecols'] : "";
1705 $datacols = isset($frow['datacols']) ? $frow['datacols'] : "";
1706 $data_type = isset($frow['data_type']) ? $frow['data_type'] : "";
1707 $field_id = isset($frow['field_id']) ? $frow['field_id'] : "";
1708 $list_id = isset($frow['list_id']) ? $frow['list_id'] : "";
1709 $currvalue = '';
1711 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1712 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1713 "ORDER BY seq", array($formtype, $this_group) );
1716 <div class="tab <?php echo $first ? 'current' : '' ?>">
1717 <table border='0' cellpadding='0'>
1719 <?php
1720 while ($group_fields = sqlFetchArray($group_fields_query)) {
1722 $titlecols = $group_fields['titlecols'];
1723 $datacols = $group_fields['datacols'];
1724 $data_type = $group_fields['data_type'];
1725 $field_id = $group_fields['field_id'];
1726 $list_id = $group_fields['list_id'];
1727 $currvalue = '';
1729 if ($formtype == 'DEM') {
1730 if ($GLOBALS['athletic_team']) {
1731 // Skip fitness level and return-to-play date because those appear
1732 // in a special display/update form on this page.
1733 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1735 if (strpos($field_id, 'em_') === 0) {
1736 // Skip employer related fields, if it's disabled.
1737 if ($GLOBALS['omit_employers']) continue;
1738 $tmp = substr($field_id, 3);
1739 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1741 else {
1742 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1745 else {
1746 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1749 // Handle a data category (group) change.
1750 if (strcmp($this_group, $last_group) != 0) {
1751 $group_name = substr($this_group, 1);
1752 // totally skip generating the employer category, if it's disabled.
1753 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1754 $last_group = $this_group;
1757 // Handle starting of a new row.
1758 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1759 disp_end_row();
1760 echo "<tr>";
1763 if ($item_count == 0 && $titlecols == 0) {
1764 $titlecols = 1;
1767 // Handle starting of a new label cell.
1768 if ($titlecols > 0) {
1769 disp_end_cell();
1770 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1771 echo "<td class='label' colspan='$titlecols_esc' ";
1772 echo ">";
1773 $cell_count += $titlecols;
1775 ++$item_count;
1777 // Added 5-09 by BM - Translate label if applicable
1778 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1780 // Handle starting of a new data cell.
1781 if ($datacols > 0) {
1782 disp_end_cell();
1783 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1784 echo "<td class='text data' colspan='$datacols_esc'";
1785 echo ">";
1786 $cell_count += $datacols;
1789 ++$item_count;
1790 echo generate_display_field($group_fields, $currvalue);
1793 disp_end_row();
1796 </table>
1797 </div>
1799 <?php
1801 $first = false;
1807 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1808 global $item_count, $cell_count, $last_group, $CPR;
1810 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1811 "WHERE form_id = ? AND uor > 0 " .
1812 "ORDER BY group_name, seq", array($formtype) );
1814 $first = true;
1815 while ($frow = sqlFetchArray($fres)) {
1816 $this_group = $frow['group_name'];
1817 $group_name = substr($this_group, 1);
1818 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
1819 $titlecols = $frow['titlecols'];
1820 $datacols = $frow['datacols'];
1821 $data_type = $frow['data_type'];
1822 $field_id = $frow['field_id'];
1823 $list_id = $frow['list_id'];
1824 $currvalue = '';
1826 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1827 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1828 "ORDER BY seq", array($formtype,$this_group) );
1831 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name_esc?>" >
1832 <table border='0' cellpadding='0'>
1834 <?php
1835 while ($group_fields = sqlFetchArray($group_fields_query)) {
1837 $titlecols = $group_fields['titlecols'];
1838 $datacols = $group_fields['datacols'];
1839 $data_type = $group_fields['data_type'];
1840 $field_id = $group_fields['field_id'];
1841 $list_id = $group_fields['list_id'];
1842 $currvalue = '';
1844 if ($formtype == 'DEM') {
1845 if ($GLOBALS['athletic_team']) {
1846 // Skip fitness level and return-to-play date because those appear
1847 // in a special display/update form on this page.
1848 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1850 if (strpos($field_id, 'em_') === 0) {
1851 // Skip employer related fields, if it's disabled.
1852 if ($GLOBALS['omit_employers']) continue;
1853 $tmp = substr($field_id, 3);
1854 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1856 else {
1857 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1860 else {
1861 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1864 // Handle a data category (group) change.
1865 if (strcmp($this_group, $last_group) != 0) {
1866 $group_name = substr($this_group, 1);
1867 // totally skip generating the employer category, if it's disabled.
1868 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1869 $last_group = $this_group;
1872 // Handle starting of a new row.
1873 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1874 disp_end_row();
1875 echo "<tr>";
1878 if ($item_count == 0 && $titlecols == 0) {
1879 $titlecols = 1;
1882 // Handle starting of a new label cell.
1883 if ($titlecols > 0) {
1884 disp_end_cell();
1885 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1886 echo "<td class='label' colspan='$titlecols_esc' ";
1887 echo ">";
1888 $cell_count += $titlecols;
1890 ++$item_count;
1892 // Added 5-09 by BM - Translate label if applicable
1893 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
1895 // Handle starting of a new data cell.
1896 if ($datacols > 0) {
1897 disp_end_cell();
1898 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1899 echo "<td class='text data' colspan='$datacols_esc'";
1900 echo ">";
1901 $cell_count += $datacols;
1904 ++$item_count;
1905 echo generate_form_field($group_fields, $currvalue);
1909 </table>
1910 </div>
1912 <?php
1914 $first = false;
1919 // From the currently posted HTML form, this gets the value of the
1920 // field corresponding to the provided layout_options table row.
1922 function get_layout_form_value($frow) {
1923 // Bring in $sanitize_all_escapes variable, which will decide
1924 // the variable escaping method.
1925 global $sanitize_all_escapes;
1927 $maxlength = $frow['max_length'];
1928 $data_type = $frow['data_type'];
1929 $field_id = $frow['field_id'];
1930 $value = '';
1931 if (isset($_POST["form_$field_id"])) {
1932 if ($data_type == 21) {
1933 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1934 // must be concatenated into a |-separated string.
1935 foreach ($_POST["form_$field_id"] as $key => $val) {
1936 if (strlen($value)) $value .= '|';
1937 $value .= $key;
1940 else if ($data_type == 22) {
1941 // $_POST["form_$field_id"] is an array of text fields to be imploded
1942 // into "key:value|key:value|...".
1943 foreach ($_POST["form_$field_id"] as $key => $val) {
1944 $val = str_replace('|', ' ', $val);
1945 if (strlen($value)) $value .= '|';
1946 $value .= "$key:$val";
1949 else if ($data_type == 23) {
1950 // $_POST["form_$field_id"] is an array of text fields with companion
1951 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1952 foreach ($_POST["form_$field_id"] as $key => $val) {
1953 $restype = $_POST["radio_{$field_id}"][$key];
1954 if (empty($restype)) $restype = '0';
1955 $val = str_replace('|', ' ', $val);
1956 if (strlen($value)) $value .= '|';
1957 $value .= "$key:$restype:$val";
1960 else if ($data_type == 25) {
1961 // $_POST["form_$field_id"] is an array of text fields with companion
1962 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1963 foreach ($_POST["form_$field_id"] as $key => $val) {
1964 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
1965 $val = str_replace('|', ' ', $val);
1966 if (strlen($value)) $value .= '|';
1967 $value .= "$key:$restype:$val";
1970 else if ($data_type == 28 || $data_type == 32) {
1971 // $_POST["form_$field_id"] is an date text fields with companion
1972 // radio buttons to be imploded into "notes|type|date".
1973 $restype = $_POST["radio_{$field_id}"];
1974 if (empty($restype)) $restype = '0';
1975 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1976 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1977 if ($data_type == 32)
1979 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
1980 $reslist = str_replace('|', ' ', $_POST["form_$field_id"]);
1981 $res_text_note = str_replace('|', ' ', $_POST["form_text_$field_id"]);
1982 $value = "$res_text_note|$restype|$resdate|$reslist";
1984 else
1985 $value = "$resnote|$restype|$resdate";
1987 else {
1988 $value = $_POST["form_$field_id"];
1992 // Better to die than to silently truncate data!
1993 if ($maxlength && $maxlength != 0 && strlen($value) > $maxlength)
1994 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
1995 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
1997 // Make sure the return value is quote-safe.
1998 if ($sanitize_all_escapes) {
1999 //escapes already removed and using binding/placemarks in sql calls
2000 // so only need to trim value
2001 return trim($value);
2003 else {
2004 //need to explicitly prepare value
2005 return formTrim($value);
2009 // Generate JavaScript validation logic for the required fields.
2011 function generate_layout_validation($form_id) {
2012 $fres = sqlStatement("SELECT * FROM layout_options " .
2013 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2014 "ORDER BY group_name, seq", array($form_id) );
2016 while ($frow = sqlFetchArray($fres)) {
2017 if ($frow['uor'] < 2) continue;
2018 $data_type = $frow['data_type'];
2019 $field_id = $frow['field_id'];
2020 $fldtitle = $frow['title'];
2021 if (!$fldtitle) $fldtitle = $frow['description'];
2022 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES);
2023 switch($data_type) {
2024 case 1:
2025 case 11:
2026 case 12:
2027 case 13:
2028 case 14:
2029 case 26:
2030 case 33:
2031 echo
2032 " if (f.$fldname.selectedIndex <= 0) {\n" .
2033 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2034 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2035 " }\n";
2036 break;
2037 case 27: // radio buttons
2038 echo
2039 " var i = 0;\n" .
2040 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2041 " if (i >= f.$fldname.length) {\n" .
2042 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2043 " }\n";
2044 break;
2045 case 2:
2046 case 3:
2047 case 4:
2048 case 15:
2049 echo
2050 " if (trimlen(f.$fldname.value) == 0) {\n" .
2051 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2052 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2053 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2054 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
2055 " } else { " .
2056 " $('#" . $fldname . "').attr('style',''); " .
2057 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2058 " } \n";
2059 break;
2065 * DROPDOWN FOR FACILITIES
2067 * build a dropdown with all facilities
2069 * @param string $selected - name of the currently selected facility
2070 * use '0' for "unspecified facility"
2071 * use '' for "All facilities" (the default)
2072 * @param string $name - the name/id for select form (defaults to "form_facility")
2073 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2074 * defaults to true
2075 * @return void - just echo the html encoded string
2077 * Note: This should become a data-type at some point, according to Brady
2079 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true, $allow_allfacilities = true) {
2080 $have_selected = false;
2081 $query = "SELECT id, name FROM facility ORDER BY name";
2082 $fres = sqlStatement($query);
2084 $name = htmlspecialchars($name, ENT_QUOTES);
2085 echo " <select name=\"$name\" id=\"$name\">\n";
2087 if ($allow_allfacilities) {
2088 $option_value = '';
2089 $option_selected_attr = '';
2090 if ($selected == '') {
2091 $option_selected_attr = ' selected="selected"';
2092 $have_selected = true;
2094 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2095 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2096 } elseif ($allow_unspecified) {
2097 $option_value = '0';
2098 $option_selected_attr = '';
2099 if ( $selected == '0' ) {
2100 $option_selected_attr = ' selected="selected"';
2101 $have_selected = true;
2103 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2104 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2107 while ($frow = sqlFetchArray($fres)) {
2108 $facility_id = $frow['id'];
2109 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2110 $option_selected_attr = '';
2111 if ($selected == $facility_id) {
2112 $option_selected_attr = ' selected="selected"';
2113 $have_selected = true;
2115 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2116 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2119 if ($allow_unspecified && $allow_allfacilities) {
2120 $option_value = '0';
2121 $option_selected_attr = '';
2122 if ( $selected == '0' ) {
2123 $option_selected_attr = ' selected="selected"';
2124 $have_selected = true;
2126 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2127 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2130 if (!$have_selected) {
2131 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2132 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2133 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2134 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2136 echo " </select>\n";
2139 // Expand Collapse Widget
2140 // This forms the header and functionality component of the widget. The information that is displayed
2141 // then follows this function followed by a closing div tag
2143 // $title is the title of the section (already translated)
2144 // $label is identifier used in the tag id's and sql columns
2145 // $buttonLabel is the button label text (already translated)
2146 // $buttonLink is the button link information
2147 // $buttonClass is any additional needed class elements for the button tag
2148 // $linkMethod is the button link method ('javascript' vs 'html')
2149 // $bodyClass is to set class(es) of the body
2150 // $auth is a flag to decide whether to show the button
2151 // $fixedWidth is to flag whether width is fixed
2152 // $forceExpandAlways is a flag to force the widget to always be expanded
2154 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2155 if ($fixedWidth) {
2156 echo "<div class='section-header'>";
2158 else {
2159 echo "<div class='section-header-dynamic'>";
2161 echo "<table><tr>";
2162 if ($auth) {
2163 // show button, since authorized
2164 // first prepare class string
2165 if ($buttonClass) {
2166 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
2168 else {
2169 $class_string = "css_button_small";
2171 // next, create the link
2172 if ($linkMethod == "javascript") {
2173 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2175 else {
2176 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
2177 if (!isset($_SESSION['patient_portal_onsite'])) {
2178 // prevent an error from occuring when calling the function from the patient portal
2179 echo " onclick='top.restoreSession()'";
2182 if (!$GLOBALS['concurrent_layout']) {
2183 echo " target='Main'";
2185 echo "><span>" .
2186 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
2188 if ($forceExpandAlways){
2189 // Special case to force the widget to always be expanded
2190 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2191 $indicatorTag ="style='display:none'";
2193 $indicatorTag = isset($indicatorTag) ? $indicatorTag : "";
2194 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2195 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
2196 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2198 if (isset($_SESSION['patient_portal_onsite'])) {
2199 // collapse all entries in the patient portal
2200 $text = xl('expand');
2202 else if (getUserSetting($label."_ps_expand")) {
2203 $text = xl('collapse');
2205 else {
2206 $text = xl('expand');
2208 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
2209 "</span>)</a></td>";
2210 echo "</tr></table>";
2211 echo "</div>";
2212 if ($forceExpandAlways) {
2213 // Special case to force the widget to always be expanded
2214 $styling = "";
2216 else if (isset($_SESSION['patient_portal_onsite'])) {
2217 // collapse all entries in the patient portal
2218 $styling = "style='display:none'";
2220 else if (getUserSetting($label."_ps_expand")) {
2221 $styling = "";
2223 else {
2224 $styling = "style='display:none'";
2226 if ($bodyClass) {
2227 $styling .= " class='" . $bodyClass . "'";
2229 //next, create the first div tag to hold the information
2230 // note the code that calls this function will then place the ending div tag after the data
2231 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
2234 //billing_facility fuction will give the dropdown list which contain billing faciliies.
2235 function billing_facility($name,$select){
2236 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
2237 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
2238 while ($facrow = sqlFetchArray($qsql)) {
2239 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
2240 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
2242 echo "</select>";