Fix for show/hide menu link formatting issues in IE, Chrome, Safari.
[openemr.git] / library / options.inc.php
blob4405f8c8497cc8d7686a61a404401b8350c58a98
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 = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
151 echo "<input type='text'" .
152 " name='form_$field_id_esc'" .
153 " id='form_$field_id_esc'" .
154 " size='$fldlength'" .
155 " maxlength='$maxlength'" .
156 " title='$description'" .
157 " value='$currescaped'";
158 if (strpos($frow['edit_options'], 'C') !== FALSE)
159 echo " onchange='capitalizeMe(this)'";
160 else if (strpos($frow['edit_options'], 'U') !== FALSE)
161 echo " onchange='this.value = this.value.toUpperCase()'";
162 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
163 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
164 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
165 echo " onblur='maskblur(this,\"$tmp\")'";
167 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0)
168 echo " readonly";
169 echo " />";
172 // long or multi-line text field
173 else if ($data_type == 3) {
174 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
175 $textRows = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
176 echo "<textarea" .
177 " name='form_$field_id_esc'" .
178 " id='form_$field_id_esc'" .
179 " title='$description'" .
180 " cols='$textCols'" .
181 " rows='$textRows'>" .
182 $currescaped . "</textarea>";
185 // date
186 else if ($data_type == 4) {
187 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
188 " value='$currescaped'" .
189 " title='$description'" .
190 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
191 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
192 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
193 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
194 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
197 // provider list, local providers only
198 else if ($data_type == 10) {
199 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
200 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
201 "AND authorized = 1 " .
202 "ORDER BY lname, fname");
203 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
204 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
205 while ($urow = sqlFetchArray($ures)) {
206 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
207 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
208 echo "<option value='$optionId'";
209 if ($urow['id'] == $currvalue) echo " selected";
210 echo ">$uname</option>";
212 echo "</select>";
215 // provider list, including address book entries with an NPI number
216 else if ($data_type == 11) {
217 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
218 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
219 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
220 "ORDER BY lname, fname");
221 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
222 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
223 while ($urow = sqlFetchArray($ures)) {
224 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
225 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
226 echo "<option value='$optionId'";
227 if ($urow['id'] == $currvalue) echo " selected";
228 echo ">$uname</option>";
230 echo "</select>";
233 // pharmacy list
234 else if ($data_type == 12) {
235 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
236 echo "<option value='0'></option>";
237 $pres = get_pharmacies();
238 while ($prow = sqlFetchArray($pres)) {
239 $key = $prow['id'];
240 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
241 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
242 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
243 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
244 echo "<option value='$optionValue'";
245 if ($currvalue == $key) echo " selected";
246 echo ">$optionLabel</option>";
248 echo "</select>";
251 // squads
252 else if ($data_type == 13) {
253 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
254 echo "<option value=''>&nbsp;</option>";
255 $squads = acl_get_squads();
256 if ($squads) {
257 foreach ($squads as $key => $value) {
258 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
259 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
260 echo "<option value='$optionValue'";
261 if ($currvalue == $key) echo " selected";
262 echo ">$optionLabel</option>\n";
265 echo "</select>";
268 // Address book, preferring organization name if it exists and is not in
269 // parentheses, and excluding local users who are not providers.
270 // Supports "referred to" practitioners and facilities.
271 // Alternatively the letter L in edit_options means that abook_type
272 // must be "ord_lab", indicating types used with the procedure
273 // lab ordering system.
274 // Alternatively the letter O in edit_options means that abook_type
275 // must begin with "ord_", indicating types used with the procedure
276 // ordering system.
277 // Alternatively the letter V in edit_options means that abook_type
278 // must be "vendor", indicating the Vendor type.
279 // Alternatively the letter R in edit_options means that abook_type
280 // must be "dist", indicating the Distributor type.
281 else if ($data_type == 14) {
282 if (strpos($frow['edit_options'], 'L') !== FALSE)
283 $tmp = "abook_type = 'ord_lab'";
284 else if (strpos($frow['edit_options'], 'O') !== FALSE)
285 $tmp = "abook_type LIKE 'ord\\_%'";
286 else if (strpos($frow['edit_options'], 'V') !== FALSE)
287 $tmp = "abook_type LIKE 'vendor%'";
288 else if (strpos($frow['edit_options'], 'R') !== FALSE)
289 $tmp = "abook_type LIKE 'dist'";
290 else
291 $tmp = "( username = '' OR authorized = 1 )";
292 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
293 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
294 "AND $tmp " .
295 "ORDER BY organization, lname, fname");
296 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
297 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
298 while ($urow = sqlFetchArray($ures)) {
299 $uname = $urow['organization'];
300 if (empty($uname) || substr($uname, 0, 1) == '(') {
301 $uname = $urow['lname'];
302 if ($urow['fname']) $uname .= ", " . $urow['fname'];
304 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
305 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
306 echo "<option value='$optionValue'";
307 $title = $urow['username'] ? xl('Local') : xl('External');
308 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
309 echo " title='$optionTitle'";
310 if ($urow['id'] == $currvalue) echo " selected";
311 echo ">$optionLabel</option>";
313 echo "</select>";
316 // a billing code
317 else if ($data_type == 15) {
318 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
319 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
320 echo "<input type='text'" .
321 " name='form_$field_id_esc'" .
322 " id='form_related_code'" .
323 " size='$fldlength'" .
324 " maxlength='$maxlength'" .
325 " title='$description'" .
326 " value='$currescaped'" .
327 " onclick='sel_related(this)' readonly" .
328 " />";
331 // a set of labeled checkboxes
332 else if ($data_type == 21) {
333 // In this special case, fld_length is the number of columns generated.
334 $cols = max(1, $frow['fld_length']);
335 $avalue = explode('|', $currvalue);
336 $lres = sqlStatement("SELECT * FROM list_options " .
337 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
338 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
339 $tdpct = (int) (100 / $cols);
340 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
341 $option_id = $lrow['option_id'];
342 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
343 // if ($count) echo "<br />";
344 if ($count % $cols == 0) {
345 if ($count) echo "</tr>";
346 echo "<tr>";
348 echo "<td width='$tdpct%'>";
349 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]' id='form_{$field_id_esc}[$option_id_esc]' value='1'";
350 if (in_array($option_id, $avalue)) echo " checked";
352 // Added 5-09 by BM - Translate label if applicable
353 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
355 echo "</td>";
357 if ($count) {
358 echo "</tr>";
359 if ($count > $cols) {
360 // Add some space after multiple rows of checkboxes.
361 $cols = htmlspecialchars( $cols, ENT_QUOTES);
362 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
365 echo "</table>";
368 // a set of labeled text input fields
369 else if ($data_type == 22) {
370 $tmp = explode('|', $currvalue);
371 $avalue = array();
372 foreach ($tmp as $value) {
373 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
374 $avalue[$matches[1]] = $matches[2];
377 $lres = sqlStatement("SELECT * FROM list_options " .
378 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
379 echo "<table cellpadding='0' cellspacing='0'>";
380 while ($lrow = sqlFetchArray($lres)) {
381 $option_id = $lrow['option_id'];
382 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
383 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
384 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
386 // Added 5-09 by BM - Translate label if applicable
387 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
388 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
389 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
390 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
391 echo "<td><input type='text'" .
392 " name='form_{$field_id_esc}[$option_id_esc]'" .
393 " id='form_{$field_id_esc}[$option_id_esc]'" .
394 " size='$fldlength'" .
395 " maxlength='$maxlength'" .
396 " value='$optionValue'";
397 echo " /></td></tr>";
399 echo "</table>";
402 // a set of exam results; 3 radio buttons and a text field:
403 else if ($data_type == 23) {
404 $tmp = explode('|', $currvalue);
405 $avalue = array();
406 foreach ($tmp as $value) {
407 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
408 $avalue[$matches[1]] = $matches[2];
411 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
412 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
413 $lres = sqlStatement("SELECT * FROM list_options " .
414 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
415 echo "<table cellpadding='0' cellspacing='0'>";
416 echo "<tr><td>&nbsp;</td><td class='bold'>" .
417 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
418 "&nbsp;</td><td class='bold'>" .
419 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
420 "<td class='bold'>" .
421 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
422 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
423 while ($lrow = sqlFetchArray($lres)) {
424 $option_id = $lrow['option_id'];
425 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
426 $restype = substr($avalue[$option_id], 0, 1);
427 $resnote = substr($avalue[$option_id], 2);
429 // Added 5-09 by BM - Translate label if applicable
430 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
432 for ($i = 0; $i < 3; ++$i) {
433 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
434 echo "<td><input type='radio'" .
435 " name='radio_{$field_id_esc}[$option_id_esc]'" .
436 " id='radio_{$field_id_esc}[$option_id_esc]'" .
437 " value='$inputValue'";
438 if ($restype === "$i") echo " checked";
439 echo " /></td>";
441 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
442 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
443 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
444 echo "<td><input type='text'" .
445 " name='form_{$field_id_esc}[$option_id_esc]'" .
446 " id='form_{$field_id_esc}[$option_id_esc]'" .
447 " size='$fldlength'" .
448 " maxlength='$maxlength'" .
449 " value='$resnote' /></td>";
450 echo "</tr>";
452 echo "</table>";
455 // the list of active allergies for the current patient
456 // this is read-only!
457 else if ($data_type == 24) {
458 $query = "SELECT title, comments FROM lists WHERE " .
459 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
460 "ORDER BY begdate";
461 // echo "<!-- $query -->\n"; // debugging
462 $lres = sqlStatement($query, array($GLOBALS['pid']));
463 $count = 0;
464 while ($lrow = sqlFetchArray($lres)) {
465 if ($count++) echo "<br />";
466 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
467 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
471 // a set of labeled checkboxes, each with a text field:
472 else if ($data_type == 25) {
473 $tmp = explode('|', $currvalue);
474 $avalue = array();
475 foreach ($tmp as $value) {
476 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
477 $avalue[$matches[1]] = $matches[2];
480 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
481 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
482 $lres = sqlStatement("SELECT * FROM list_options " .
483 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
484 echo "<table cellpadding='0' cellspacing='0'>";
485 while ($lrow = sqlFetchArray($lres)) {
486 $option_id = $lrow['option_id'];
487 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
488 $restype = substr($avalue[$option_id], 0, 1);
489 $resnote = substr($avalue[$option_id], 2);
491 // Added 5-09 by BM - Translate label if applicable
492 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
494 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
495 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]' id='check_{$field_id_esc}[$option_id_esc]' value='1'";
496 if ($restype) echo " checked";
497 echo " />&nbsp;</td>";
498 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
499 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
500 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
501 echo "<td><input type='text'" .
502 " name='form_{$field_id_esc}[$option_id_esc]'" .
503 " id='form_{$field_id_esc}[$option_id_esc]'" .
504 " size='$fldlength'" .
505 " maxlength='$maxlength'" .
506 " value='$resnote' /></td>";
507 echo "</tr>";
509 echo "</table>";
512 // single-selection list with ability to add to it
513 else if ($data_type == 26) {
514 echo "<select class='addtolistclass_$list_id_esc' name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
515 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES) . "</option>";
516 $lres = sqlStatement("SELECT * FROM list_options " .
517 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
518 $got_selected = FALSE;
519 while ($lrow = sqlFetchArray($lres)) {
520 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
521 echo "<option value='$optionValue'";
522 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
523 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
525 echo " selected";
526 $got_selected = TRUE;
528 // Added 5-09 by BM - Translate label if applicable
529 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n";
531 if (!$got_selected && strlen($currvalue) > 0) {
532 echo "<option value='$currescaped' selected>* $currescaped *</option>";
533 echo "</select>";
534 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES);
535 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
536 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
538 else {
539 echo "</select>";
541 // show the add button if user has access to correct list
542 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
543 $outputAddButton = "<input type='button' id='addtolistid_".$list_id_esc."' fieldid='form_".$field_id_esc."' class='addtolist' value='$inputValue'>";
544 if (aco_exist('lists', $list_id)) {
545 // a specific aco exist for this list, so ensure access
546 if (acl_check('lists', $list_id)) echo $outputAddButton;
548 else {
549 // no specific aco exist for this list, so check for access to 'default' list
550 if (acl_check('lists', 'default')) echo $outputAddButton;
554 // a set of labeled radio buttons
555 else if ($data_type == 27) {
556 // In this special case, fld_length is the number of columns generated.
557 $cols = max(1, $frow['fld_length']);
558 $lres = sqlStatement("SELECT * FROM list_options " .
559 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
560 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
561 $tdpct = (int) (100 / $cols);
562 $got_selected = FALSE;
563 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
564 $option_id = $lrow['option_id'];
565 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
566 if ($count % $cols == 0) {
567 if ($count) echo "</tr>";
568 echo "<tr>";
570 echo "<td width='$tdpct%'>";
571 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]' value='$option_id_esc'";
572 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
573 (strlen($currvalue) > 0 && $option_id == $currvalue))
575 echo " checked";
576 $got_selected = TRUE;
578 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
579 echo "</td>";
581 if ($count) {
582 echo "</tr>";
583 if ($count > $cols) {
584 // Add some space after multiple rows of radio buttons.
585 $cols = htmlspecialchars( $cols, ENT_QUOTES);
586 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
589 echo "</table>";
590 if (!$got_selected && strlen($currvalue) > 0) {
591 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
592 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
593 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
597 // special case for history of lifestyle status; 3 radio buttons and a date text field:
598 // VicarePlus :: A selection list box for smoking status:
599 else if ($data_type == 28 || $data_type == 32) {
600 $tmp = explode('|', $currvalue);
601 switch(count($tmp)) {
602 case "4": {
603 $resnote = $tmp[0];
604 $restype = $tmp[1];
605 $resdate = $tmp[2];
606 $reslist = $tmp[3];
607 } break;
608 case "3": {
609 $resnote = $tmp[0];
610 $restype = $tmp[1];
611 $resdate = $tmp[2];
612 } break;
613 case "2": {
614 $resnote = $tmp[0];
615 $restype = $tmp[1];
616 $resdate = "";
617 } break;
618 case "1": {
619 $resnote = $tmp[0];
620 $resdate = $restype = "";
621 } break;
622 default: {
623 $restype = $resdate = $resnote = "";
624 } break;
626 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
627 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
629 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
630 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
631 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
632 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
633 echo "<table cellpadding='0' cellspacing='0'>";
634 echo "<tr>";
635 if ($data_type == 28)
637 // input text
638 echo "<td><input type='text'" .
639 " name='form_$field_id_esc'" .
640 " id='form_$field_id_esc'" .
641 " size='$fldlength'" .
642 " maxlength='$maxlength'" .
643 " value='$resnote' />&nbsp;</td>";
644 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
645 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
646 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
648 else if($data_type == 32)
650 // input text
651 echo "<tr><td><input type='text'" .
652 " name='form_text_$field_id_esc'" .
653 " id='form_text_$field_id_esc'" .
654 " size='$fldlength'" .
655 " maxlength='$maxlength'" .
656 " value='$resnote' />&nbsp;</td></tr>";
657 echo "<td>";
658 //Selection list for smoking status
659 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
660 echo generate_select_list("form_$field_id", $list_id, $reslist,
661 $description, $showEmpty ? $empty_title : '', '', $onchange)."</td>";
662 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
664 // current
665 echo "<td><input type='radio'" .
666 " name='radio_{$field_id_esc}'" .
667 " id='radio_{$field_id_esc}[current]'" .
668 " value='current".$field_id_esc."'";
669 if ($restype == "current".$field_id) echo " checked";
670 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
671 // quit
672 echo "<td><input type='radio'" .
673 " name='radio_{$field_id_esc}'" .
674 " id='radio_{$field_id_esc}[quit]'" .
675 " value='quit".$field_id_esc."'";
676 if ($restype == "quit".$field_id) echo " checked";
677 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
678 // quit date
679 echo "<td><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
680 " value='$resdate'" .
681 " title='$description'" .
682 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
683 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
684 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
685 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />&nbsp;</td>";
686 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
687 // never
688 echo "<td><input type='radio'" .
689 " name='radio_{$field_id_esc}'" .
690 " id='radio_{$field_id_esc}[never]'" .
691 " value='never".$field_id_esc."'";
692 if ($restype == "never".$field_id) echo " checked";
693 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."&nbsp;</td>";
694 // Not Applicable
695 echo "<td><input type='radio'" .
696 " name='radio_{$field_id}'" .
697 " id='radio_{$field_id}[not_applicable]'" .
698 " value='not_applicable".$field_id."'";
699 if ($restype == "not_applicable".$field_id) echo " checked";
700 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('N/A'), ENT_QUOTES)."&nbsp;</td>";
701 echo "</tr>";
702 echo "</table>";
705 // static text. read-only, of course.
706 else if ($data_type == 31) {
707 echo nl2br($frow['description']);
710 //VicarePlus :: A single selection list for Race and Ethnicity, which is specialized to check the 'ethrace' list if the entry does not exist in the list_id of the given list. At some point in the future (when able to input two lists via the layouts engine), this function could be expanded to allow using any list as a backup entry.
711 else if ($data_type == 33) {
712 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
713 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES) . "</option>";
714 $lres = sqlStatement("SELECT * FROM list_options " .
715 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
716 $got_selected = FALSE;
717 while ($lrow = sqlFetchArray($lres)) {
718 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
719 echo "<option value='$optionValue'";
720 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
721 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
723 echo " selected";
724 $got_selected = TRUE;
727 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n";
729 if (!$got_selected && strlen($currvalue) > 0)
731 //Check 'ethrace' list if the entry does not exist in the list_id of the given list(Race or Ethnicity).
732 $list_id='ethrace';
733 $lrow = sqlQuery("SELECT title FROM list_options " .
734 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
735 if ($lrow > 0)
737 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
738 echo "<option value='$currvalue' selected> $s </option>";
739 echo "</select>";
741 else
743 echo "<option value='$currescaped' selected>* $currescaped *</option>";
744 echo "</select>";
745 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES);
746 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
747 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
750 else {
751 echo "</select>";
756 function generate_print_field($frow, $currvalue) {
757 global $rootdir, $date_init;
759 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
761 $data_type = $frow['data_type'];
762 $field_id = $frow['field_id'];
763 $list_id = $frow['list_id'];
764 $fld_length = $frow['fld_length'];
766 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
768 // Can pass $frow['empty_title'] with this variable, otherwise
769 // will default to 'Unassigned'.
770 // If it is 'SKIP' then an empty text title is completely skipped.
771 $showEmpty = true;
772 if (isset($frow['empty_title'])) {
773 if ($frow['empty_title'] == "SKIP") {
774 //do not display an 'empty' choice
775 $showEmpty = false;
776 $empty_title = "Unassigned";
778 else {
779 $empty_title = $frow['empty_title'];
782 else {
783 $empty_title = "Unassigned";
786 // generic single-selection list
787 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
788 if (empty($fld_length)) {
789 if ($list_id == 'titles') {
790 $fld_length = 3;
791 } else {
792 $fld_length = 10;
795 $tmp = '';
796 if ($currvalue) {
797 $lrow = sqlQuery("SELECT title FROM list_options " .
798 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
799 $tmp = xl_list_label($lrow['title']);
800 if (empty($tmp)) $tmp = "($currvalue)";
802 /*****************************************************************
803 echo "<input type='text'" .
804 " size='$fld_length'" .
805 " value='$tmp'" .
806 " class='under'" .
807 " />";
808 *****************************************************************/
809 if ($tmp === '') { $tmp = '&nbsp;'; }
810 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
811 echo $tmp;
814 // simple text field
815 else if ($data_type == 2 || $data_type == 15) {
816 /*****************************************************************
817 echo "<input type='text'" .
818 " size='$fld_length'" .
819 " value='$currescaped'" .
820 " class='under'" .
821 " />";
822 *****************************************************************/
823 if ($currescaped === '') $currescaped = '&nbsp;';
824 echo $currescaped;
827 // long or multi-line text field
828 else if ($data_type == 3) {
829 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
830 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
831 echo "<textarea" .
832 " cols='$fldlength'" .
833 " rows='$maxlength'>" .
834 $currescaped . "</textarea>";
837 // date
838 else if ($data_type == 4) {
839 /*****************************************************************
840 echo "<input type='text' size='10'" .
841 " value='$currescaped'" .
842 " title='$description'" .
843 " class='under'" .
844 " />";
845 *****************************************************************/
846 if ($currvalue === '') { $tmp = oeFormatShortDate('&nbsp;'); }
847 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES); }
848 echo $tmp;
851 // provider list
852 else if ($data_type == 10 || $data_type == 11) {
853 $tmp = '';
854 if ($currvalue) {
855 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
856 "WHERE id = ?", array($currvalue) );
857 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
858 if (empty($tmp)) $tmp = "($currvalue)";
860 /*****************************************************************
861 echo "<input type='text'" .
862 " size='$fld_length'" .
863 " value='$tmp'" .
864 " class='under'" .
865 " />";
866 *****************************************************************/
867 if ($tmp === '') { $tmp = '&nbsp;'; }
868 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
869 echo $tmp;
872 // pharmacy list
873 else if ($data_type == 12) {
874 $tmp = '';
875 if ($currvalue) {
876 $pres = get_pharmacies();
877 while ($prow = sqlFetchArray($pres)) {
878 $key = $prow['id'];
879 if ($currvalue == $key) {
880 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
881 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
882 $prow['line1'] . ' / ' . $prow['city'];
885 if (empty($tmp)) $tmp = "($currvalue)";
887 /*****************************************************************
888 echo "<input type='text'" .
889 " size='$fld_length'" .
890 " value='$tmp'" .
891 " class='under'" .
892 " />";
893 *****************************************************************/
894 if ($tmp === '') { $tmp = '&nbsp;'; }
895 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
896 echo $tmp;
899 // squads
900 else if ($data_type == 13) {
901 $tmp = '';
902 if ($currvalue) {
903 $squads = acl_get_squads();
904 if ($squads) {
905 foreach ($squads as $key => $value) {
906 if ($currvalue == $key) {
907 $tmp = $value[3];
911 if (empty($tmp)) $tmp = "($currvalue)";
913 /*****************************************************************
914 echo "<input type='text'" .
915 " size='$fld_length'" .
916 " value='$tmp'" .
917 " class='under'" .
918 " />";
919 *****************************************************************/
920 if ($tmp === '') { $tmp = '&nbsp;'; }
921 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
922 echo $tmp;
925 // Address book.
926 else if ($data_type == 14) {
927 $tmp = '';
928 if ($currvalue) {
929 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
930 "WHERE id = ?", array($currvalue) );
931 $uname = $urow['lname'];
932 if ($urow['fname']) $uname .= ", " . $urow['fname'];
933 $tmp = $uname;
934 if (empty($tmp)) $tmp = "($currvalue)";
936 /*****************************************************************
937 echo "<input type='text'" .
938 " size='$fld_length'" .
939 " value='$tmp'" .
940 " class='under'" .
941 " />";
942 *****************************************************************/
943 if ($tmp === '') { $tmp = '&nbsp;'; }
944 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
945 echo $tmp;
948 // a set of labeled checkboxes
949 else if ($data_type == 21) {
950 // In this special case, fld_length is the number of columns generated.
951 $cols = max(1, $fld_length);
952 $avalue = explode('|', $currvalue);
953 $lres = sqlStatement("SELECT * FROM list_options " .
954 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
955 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
956 $tdpct = (int) (100 / $cols);
957 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
958 $option_id = $lrow['option_id'];
959 if ($count % $cols == 0) {
960 if ($count) echo "</tr>";
961 echo "<tr>";
963 echo "<td width='$tdpct%'>";
964 echo "<input type='checkbox'";
965 if (in_array($option_id, $avalue)) echo " checked";
966 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
967 echo "</td>";
969 if ($count) {
970 echo "</tr>";
971 if ($count > $cols) {
972 // Add some space after multiple rows of checkboxes.
973 $cols = htmlspecialchars( $cols, ENT_QUOTES);
974 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
977 echo "</table>";
980 // a set of labeled text input fields
981 else if ($data_type == 22) {
982 $tmp = explode('|', $currvalue);
983 $avalue = array();
984 foreach ($tmp as $value) {
985 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
986 $avalue[$matches[1]] = $matches[2];
989 $lres = sqlStatement("SELECT * FROM list_options " .
990 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
991 echo "<table cellpadding='0' cellspacing='0'>";
992 while ($lrow = sqlFetchArray($lres)) {
993 $option_id = $lrow['option_id'];
994 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
995 $fldlength = empty($fld_length) ? 20 : $fld_length;
996 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
997 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
998 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
999 echo "<td><input type='text'" .
1000 " size='$fldlength'" .
1001 " value='$inputValue'" .
1002 " class='under'" .
1003 " /></td></tr>";
1005 echo "</table>";
1008 // a set of exam results; 3 radio buttons and a text field:
1009 else if ($data_type == 23) {
1010 $tmp = explode('|', $currvalue);
1011 $avalue = array();
1012 foreach ($tmp as $value) {
1013 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1014 $avalue[$matches[1]] = $matches[2];
1017 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1018 $fldlength = empty($fld_length) ? 20 : $fld_length;
1019 $lres = sqlStatement("SELECT * FROM list_options " .
1020 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1021 echo "<table cellpadding='0' cellspacing='0'>";
1022 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1023 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1024 "&nbsp;</td><td class='bold'>" .
1025 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1026 "<td class='bold'>" .
1027 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1028 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1029 while ($lrow = sqlFetchArray($lres)) {
1030 $option_id = $lrow['option_id'];
1031 $restype = substr($avalue[$option_id], 0, 1);
1032 $resnote = substr($avalue[$option_id], 2);
1033 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1034 for ($i = 0; $i < 3; ++$i) {
1035 echo "<td><input type='radio'";
1036 if ($restype === "$i") echo " checked";
1037 echo " /></td>";
1039 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1040 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1041 echo "<td><input type='text'" .
1042 " size='$fldlength'" .
1043 " value='$resnote'" .
1044 " class='under' /></td>" .
1045 "</tr>";
1047 echo "</table>";
1050 // the list of active allergies for the current patient
1051 // this is read-only!
1052 else if ($data_type == 24) {
1053 $query = "SELECT title, comments FROM lists WHERE " .
1054 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1055 "ORDER BY begdate";
1056 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1057 $count = 0;
1058 while ($lrow = sqlFetchArray($lres)) {
1059 if ($count++) echo "<br />";
1060 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1061 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1065 // a set of labeled checkboxes, each with a text field:
1066 else if ($data_type == 25) {
1067 $tmp = explode('|', $currvalue);
1068 $avalue = array();
1069 foreach ($tmp as $value) {
1070 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1071 $avalue[$matches[1]] = $matches[2];
1074 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1075 $fldlength = empty($fld_length) ? 20 : $fld_length;
1076 $lres = sqlStatement("SELECT * FROM list_options " .
1077 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1078 echo "<table cellpadding='0' cellspacing='0'>";
1079 while ($lrow = sqlFetchArray($lres)) {
1080 $option_id = $lrow['option_id'];
1081 $restype = substr($avalue[$option_id], 0, 1);
1082 $resnote = substr($avalue[$option_id], 2);
1083 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1084 echo "<td><input type='checkbox'";
1085 if ($restype) echo " checked";
1086 echo " />&nbsp;</td>";
1087 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1088 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1089 echo "<td><input type='text'" .
1090 " size='$fldlength'" .
1091 " value='$resnote'" .
1092 " class='under'" .
1093 " /></td>" .
1094 "</tr>";
1096 echo "</table>";
1099 // a set of labeled radio buttons
1100 else if ($data_type == 27) {
1101 // In this special case, fld_length is the number of columns generated.
1102 $cols = max(1, $frow['fld_length']);
1103 $lres = sqlStatement("SELECT * FROM list_options " .
1104 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1105 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1106 $tdpct = (int) (100 / $cols);
1107 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1108 $option_id = $lrow['option_id'];
1109 if ($count % $cols == 0) {
1110 if ($count) echo "</tr>";
1111 echo "<tr>";
1113 echo "<td width='$tdpct%'>";
1114 echo "<input type='radio'";
1115 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1116 (strlen($currvalue) > 0 && $option_id == $currvalue))
1118 echo " checked";
1120 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1121 echo "</td>";
1123 if ($count) {
1124 echo "</tr>";
1125 if ($count > $cols) {
1126 // Add some space after multiple rows of radio buttons.
1127 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1128 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1131 echo "</table>";
1134 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1135 else if ($data_type == 28 || $data_type == 32) {
1136 $tmp = explode('|', $currvalue);
1137 switch(count($tmp)) {
1138 case "4": {
1139 $resnote = $tmp[0];
1140 $restype = $tmp[1];
1141 $resdate = $tmp[2];
1142 $reslist = $tmp[3];
1143 } break;
1144 case "3": {
1145 $resnote = $tmp[0];
1146 $restype = $tmp[1];
1147 $resdate = $tmp[2];
1148 } break;
1149 case "2": {
1150 $resnote = $tmp[0];
1151 $restype = $tmp[1];
1152 $resdate = "";
1153 } break;
1154 case "1": {
1155 $resnote = $tmp[0];
1156 $resdate = $restype = "";
1157 } break;
1158 default: {
1159 $restype = $resdate = $resnote = "";
1160 } break;
1162 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1163 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1164 echo "<table cellpadding='0' cellspacing='0'>";
1165 echo "<tr>";
1166 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1167 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1168 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1169 if($data_type == 28)
1171 echo "<td><input type='text'" .
1172 " size='$fldlength'" .
1173 " class='under'" .
1174 " value='$resnote' /></td>";
1175 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1176 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1177 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1179 else if($data_type == 32)
1181 echo "<tr><td><input type='text'" .
1182 " size='$fldlength'" .
1183 " class='under'" .
1184 " value='$resnote' /></td></tr>";
1185 $fldlength = 30;
1186 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1187 echo "<td><input type='text'" .
1188 " size='$fldlength'" .
1189 " class='under'" .
1190 " value='$smoking_status_title' /></td>";
1191 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1193 echo "<td><input type='radio'";
1194 if ($restype == "current".$field_id) echo " checked";
1195 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1197 echo "<td><input type='radio'";
1198 if ($restype == "current".$field_id) echo " checked";
1199 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1201 echo "<td><input type='text' size='6'" .
1202 " value='$resdate'" .
1203 " class='under'" .
1204 " /></td>";
1206 echo "<td><input type='radio'";
1207 if ($restype == "current".$field_id) echo " checked";
1208 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1210 echo "<td><input type='radio'";
1211 if ($restype == "not_applicable".$field_id) echo " checked";
1212 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1213 echo "</tr>";
1214 echo "</table>";
1217 // static text. read-only, of course.
1218 else if ($data_type == 31) {
1219 echo nl2br($frow['description']);
1224 function generate_display_field($frow, $currvalue) {
1225 $data_type = $frow['data_type'];
1226 $field_id = $frow['field_id'];
1227 $list_id = $frow['list_id'];
1228 $s = '';
1230 // generic selection list or the generic selection list with add on the fly
1231 // feature, or radio buttons
1232 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1233 $lrow = sqlQuery("SELECT title FROM list_options " .
1234 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1235 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1236 //For lists Race and Ethnicity if there is no matching value in the corresponding lists check ethrace list
1237 if ($lrow == 0 && $data_type == 33)
1239 $list_id='ethrace';
1240 $lrow_ethrace = sqlQuery("SELECT title FROM list_options " .
1241 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1242 $s = htmlspecialchars(xl_list_label($lrow_ethrace['title']),ENT_NOQUOTES);
1246 // simple text field
1247 else if ($data_type == 2) {
1248 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1251 // long or multi-line text field
1252 else if ($data_type == 3) {
1253 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1256 // date
1257 else if ($data_type == 4) {
1258 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES);
1261 // provider
1262 else if ($data_type == 10 || $data_type == 11) {
1263 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1264 "WHERE id = ?", array($currvalue) );
1265 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1268 // pharmacy list
1269 else if ($data_type == 12) {
1270 $pres = get_pharmacies();
1271 while ($prow = sqlFetchArray($pres)) {
1272 $key = $prow['id'];
1273 if ($currvalue == $key) {
1274 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1275 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1276 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1281 // squads
1282 else if ($data_type == 13) {
1283 $squads = acl_get_squads();
1284 if ($squads) {
1285 foreach ($squads as $key => $value) {
1286 if ($currvalue == $key) {
1287 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1293 // address book
1294 else if ($data_type == 14) {
1295 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1296 "WHERE id = ?", array($currvalue));
1297 $uname = $urow['lname'];
1298 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1299 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1302 // billing code
1303 else if ($data_type == 15) {
1304 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1307 // a set of labeled checkboxes
1308 else if ($data_type == 21) {
1309 $avalue = explode('|', $currvalue);
1310 $lres = sqlStatement("SELECT * FROM list_options " .
1311 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1312 $count = 0;
1313 while ($lrow = sqlFetchArray($lres)) {
1314 $option_id = $lrow['option_id'];
1315 if (in_array($option_id, $avalue)) {
1316 if ($count++) $s .= "<br />";
1318 // Added 5-09 by BM - Translate label if applicable
1319 $s .= htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1325 // a set of labeled text input fields
1326 else if ($data_type == 22) {
1327 $tmp = explode('|', $currvalue);
1328 $avalue = array();
1329 foreach ($tmp as $value) {
1330 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1331 $avalue[$matches[1]] = $matches[2];
1334 $lres = sqlStatement("SELECT * FROM list_options " .
1335 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1336 $s .= "<table cellpadding='0' cellspacing='0'>";
1337 while ($lrow = sqlFetchArray($lres)) {
1338 $option_id = $lrow['option_id'];
1339 if (empty($avalue[$option_id])) continue;
1341 // Added 5-09 by BM - Translate label if applicable
1342 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1344 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1346 $s .= "</table>";
1349 // a set of exam results; 3 radio buttons and a text field:
1350 else if ($data_type == 23) {
1351 $tmp = explode('|', $currvalue);
1352 $avalue = array();
1353 foreach ($tmp as $value) {
1354 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1355 $avalue[$matches[1]] = $matches[2];
1358 $lres = sqlStatement("SELECT * FROM list_options " .
1359 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1360 $s .= "<table cellpadding='0' cellspacing='0'>";
1361 while ($lrow = sqlFetchArray($lres)) {
1362 $option_id = $lrow['option_id'];
1363 $restype = substr($avalue[$option_id], 0, 1);
1364 $resnote = substr($avalue[$option_id], 2);
1365 if (empty($restype) && empty($resnote)) continue;
1367 // Added 5-09 by BM - Translate label if applicable
1368 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1370 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1371 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1372 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1373 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1374 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1375 $s .= "</tr>";
1377 $s .= "</table>";
1380 // the list of active allergies for the current patient
1381 else if ($data_type == 24) {
1382 $query = "SELECT title, comments FROM lists WHERE " .
1383 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1384 "ORDER BY begdate";
1385 // echo "<!-- $query -->\n"; // debugging
1386 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1387 $count = 0;
1388 while ($lrow = sqlFetchArray($lres)) {
1389 if ($count++) $s .= "<br />";
1390 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1391 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1395 // a set of labeled checkboxes, each with a text field:
1396 else if ($data_type == 25) {
1397 $tmp = explode('|', $currvalue);
1398 $avalue = array();
1399 foreach ($tmp as $value) {
1400 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1401 $avalue[$matches[1]] = $matches[2];
1404 $lres = sqlStatement("SELECT * FROM list_options " .
1405 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1406 $s .= "<table cellpadding='0' cellspacing='0'>";
1407 while ($lrow = sqlFetchArray($lres)) {
1408 $option_id = $lrow['option_id'];
1409 $restype = substr($avalue[$option_id], 0, 1);
1410 $resnote = substr($avalue[$option_id], 2);
1411 if (empty($restype) && empty($resnote)) continue;
1413 // Added 5-09 by BM - Translate label if applicable
1414 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1416 $restype = $restype ? xl('Yes') : xl('No');
1417 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1418 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1419 $s .= "</tr>";
1421 $s .= "</table>";
1424 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1425 // VicarePlus :: A selection list for smoking status.
1426 else if ($data_type == 28 || $data_type == 32) {
1427 $tmp = explode('|', $currvalue);
1428 switch(count($tmp)) {
1429 case "4": {
1430 $resnote = $tmp[0];
1431 $restype = $tmp[1];
1432 $resdate = $tmp[2];
1433 $reslist = $tmp[3];
1434 } break;
1435 case "3": {
1436 $resnote = $tmp[0];
1437 $restype = $tmp[1];
1438 $resdate = $tmp[2];
1439 } break;
1440 case "2": {
1441 $resnote = $tmp[0];
1442 $restype = $tmp[1];
1443 $resdate = "";
1444 } break;
1445 case "1": {
1446 $resnote = $tmp[0];
1447 $resdate = $restype = "";
1448 } break;
1449 default: {
1450 $restype = $resdate = $resnote = "";
1451 } break;
1453 $s .= "<table cellpadding='0' cellspacing='0'>";
1455 $s .= "<tr>";
1456 $res = "";
1457 if ($restype == "current".$field_id) $res = xl('Current');
1458 if ($restype == "quit".$field_id) $res = xl('Quit');
1459 if ($restype == "never".$field_id) $res = xl('Never');
1460 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1461 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1462 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1463 if ($data_type == 28)
1465 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1467 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1468 else if ($data_type == 32)
1470 if (!empty($reslist)) $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1471 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
1474 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1475 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1476 $s .= "</tr>";
1477 $s .= "</table>";
1480 // static text. read-only, of course.
1481 else if ($data_type == 31) {
1482 $s .= nl2br($frow['description']);
1485 return $s;
1488 $CPR = 4; // cells per row of generic data
1489 $last_group = '';
1490 $cell_count = 0;
1491 $item_count = 0;
1493 function disp_end_cell() {
1494 global $item_count, $cell_count;
1495 if ($item_count > 0) {
1496 echo "</td>";
1497 $item_count = 0;
1501 function disp_end_row() {
1502 global $cell_count, $CPR;
1503 disp_end_cell();
1504 if ($cell_count > 0) {
1505 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
1506 echo "</tr>\n";
1507 $cell_count = 0;
1511 function disp_end_group() {
1512 global $last_group;
1513 if (strlen($last_group) > 0) {
1514 disp_end_row();
1518 function display_layout_rows($formtype, $result1, $result2='') {
1519 global $item_count, $cell_count, $last_group, $CPR;
1521 $fres = sqlStatement("SELECT * FROM layout_options " .
1522 "WHERE form_id = ? AND uor > 0 " .
1523 "ORDER BY group_name, seq", array($formtype) );
1525 while ($frow = sqlFetchArray($fres)) {
1526 $this_group = $frow['group_name'];
1527 $titlecols = $frow['titlecols'];
1528 $datacols = $frow['datacols'];
1529 $data_type = $frow['data_type'];
1530 $field_id = $frow['field_id'];
1531 $list_id = $frow['list_id'];
1532 $currvalue = '';
1534 if ($formtype == 'DEM') {
1535 if ($GLOBALS['athletic_team']) {
1536 // Skip fitness level and return-to-play date because those appear
1537 // in a special display/update form on this page.
1538 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1540 if (strpos($field_id, 'em_') === 0) {
1541 // Skip employer related fields, if it's disabled.
1542 if ($GLOBALS['omit_employers']) continue;
1543 $tmp = substr($field_id, 3);
1544 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1546 else {
1547 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1550 else {
1551 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1554 // Handle a data category (group) change.
1555 if (strcmp($this_group, $last_group) != 0) {
1556 $group_name = substr($this_group, 1);
1557 // totally skip generating the employer category, if it's disabled.
1558 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1559 disp_end_group();
1560 $last_group = $this_group;
1563 // Handle starting of a new row.
1564 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1565 disp_end_row();
1566 echo "<tr>";
1567 if ($group_name) {
1568 echo "<td class='groupname'>";
1569 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1570 //echo "<font color='#008800'>$group_name</font>";
1572 // Added 5-09 by BM - Translate label if applicable
1573 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
1575 $group_name = '';
1576 } else {
1577 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1578 echo "<td valign='top'>&nbsp;";
1580 echo "</td>";
1583 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1585 // Handle starting of a new label cell.
1586 if ($titlecols > 0) {
1587 disp_end_cell();
1588 //echo "<td class='label' colspan='$titlecols' valign='top'";
1589 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1590 echo "<td class='label' colspan='$titlecols_esc' ";
1591 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1592 echo ">";
1593 $cell_count += $titlecols;
1595 ++$item_count;
1597 // Added 5-09 by BM - Translate label if applicable
1598 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1600 // Handle starting of a new data cell.
1601 if ($datacols > 0) {
1602 disp_end_cell();
1603 //echo "<td class='text data' colspan='$datacols' valign='top'";
1604 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1605 echo "<td class='text data' colspan='$datacols_esc'";
1606 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1607 echo ">";
1608 $cell_count += $datacols;
1611 ++$item_count;
1612 echo generate_display_field($frow, $currvalue);
1615 disp_end_group();
1618 function display_layout_tabs($formtype, $result1, $result2='') {
1619 global $item_count, $cell_count, $last_group, $CPR;
1621 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1622 "WHERE form_id = ? AND uor > 0 " .
1623 "ORDER BY group_name, seq", array($formtype) );
1625 $first = true;
1626 while ($frow = sqlFetchArray($fres)) {
1627 $this_group = $frow['group_name'];
1628 $group_name = substr($this_group, 1);
1630 <li <?php echo $first ? 'class="current"' : '' ?>>
1631 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES)."?>">
1632 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
1633 </li>
1634 <?php
1635 $first = false;
1639 function display_layout_tabs_data($formtype, $result1, $result2='') {
1640 global $item_count, $cell_count, $last_group, $CPR;
1642 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1643 "WHERE form_id = ? AND uor > 0 " .
1644 "ORDER BY group_name, seq", array($formtype));
1646 $first = true;
1647 while ($frow = sqlFetchArray($fres)) {
1648 $this_group = $frow['group_name'];
1649 $titlecols = $frow['titlecols'];
1650 $datacols = $frow['datacols'];
1651 $data_type = $frow['data_type'];
1652 $field_id = $frow['field_id'];
1653 $list_id = $frow['list_id'];
1654 $currvalue = '';
1656 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1657 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1658 "ORDER BY seq", array($formtype, $this_group) );
1661 <div class="tab <?php echo $first ? 'current' : '' ?>">
1662 <table border='0' cellpadding='0'>
1664 <?php
1665 while ($group_fields = sqlFetchArray($group_fields_query)) {
1667 $titlecols = $group_fields['titlecols'];
1668 $datacols = $group_fields['datacols'];
1669 $data_type = $group_fields['data_type'];
1670 $field_id = $group_fields['field_id'];
1671 $list_id = $group_fields['list_id'];
1672 $currvalue = '';
1674 if ($formtype == 'DEM') {
1675 if ($GLOBALS['athletic_team']) {
1676 // Skip fitness level and return-to-play date because those appear
1677 // in a special display/update form on this page.
1678 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1680 if (strpos($field_id, 'em_') === 0) {
1681 // Skip employer related fields, if it's disabled.
1682 if ($GLOBALS['omit_employers']) continue;
1683 $tmp = substr($field_id, 3);
1684 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1686 else {
1687 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1690 else {
1691 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1694 // Handle a data category (group) change.
1695 if (strcmp($this_group, $last_group) != 0) {
1696 $group_name = substr($this_group, 1);
1697 // totally skip generating the employer category, if it's disabled.
1698 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1699 $last_group = $this_group;
1702 // Handle starting of a new row.
1703 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1704 disp_end_row();
1705 echo "<tr>";
1708 if ($item_count == 0 && $titlecols == 0) {
1709 $titlecols = 1;
1712 // Handle starting of a new label cell.
1713 if ($titlecols > 0) {
1714 disp_end_cell();
1715 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1716 echo "<td class='label' colspan='$titlecols_esc' ";
1717 echo ">";
1718 $cell_count += $titlecols;
1720 ++$item_count;
1722 // Added 5-09 by BM - Translate label if applicable
1723 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1725 // Handle starting of a new data cell.
1726 if ($datacols > 0) {
1727 disp_end_cell();
1728 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1729 echo "<td class='text data' colspan='$datacols_esc'";
1730 echo ">";
1731 $cell_count += $datacols;
1734 ++$item_count;
1735 echo generate_display_field($group_fields, $currvalue);
1738 disp_end_row();
1741 </table>
1742 </div>
1744 <?php
1746 $first = false;
1752 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1753 global $item_count, $cell_count, $last_group, $CPR;
1755 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1756 "WHERE form_id = ? AND uor > 0 " .
1757 "ORDER BY group_name, seq", array($formtype) );
1759 $first = true;
1760 while ($frow = sqlFetchArray($fres)) {
1761 $this_group = $frow['group_name'];
1762 $group_name = substr($this_group, 1);
1763 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
1764 $titlecols = $frow['titlecols'];
1765 $datacols = $frow['datacols'];
1766 $data_type = $frow['data_type'];
1767 $field_id = $frow['field_id'];
1768 $list_id = $frow['list_id'];
1769 $currvalue = '';
1771 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1772 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1773 "ORDER BY seq", array($formtype,$this_group) );
1776 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name_esc?>" >
1777 <table border='0' cellpadding='0'>
1779 <?php
1780 while ($group_fields = sqlFetchArray($group_fields_query)) {
1782 $titlecols = $group_fields['titlecols'];
1783 $datacols = $group_fields['datacols'];
1784 $data_type = $group_fields['data_type'];
1785 $field_id = $group_fields['field_id'];
1786 $list_id = $group_fields['list_id'];
1787 $currvalue = '';
1789 if ($formtype == 'DEM') {
1790 if ($GLOBALS['athletic_team']) {
1791 // Skip fitness level and return-to-play date because those appear
1792 // in a special display/update form on this page.
1793 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1795 if (strpos($field_id, 'em_') === 0) {
1796 // Skip employer related fields, if it's disabled.
1797 if ($GLOBALS['omit_employers']) continue;
1798 $tmp = substr($field_id, 3);
1799 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1801 else {
1802 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1805 else {
1806 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1809 // Handle a data category (group) change.
1810 if (strcmp($this_group, $last_group) != 0) {
1811 $group_name = substr($this_group, 1);
1812 // totally skip generating the employer category, if it's disabled.
1813 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1814 $last_group = $this_group;
1817 // Handle starting of a new row.
1818 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1819 disp_end_row();
1820 echo "<tr>";
1823 if ($item_count == 0 && $titlecols == 0) {
1824 $titlecols = 1;
1827 // Handle starting of a new label cell.
1828 if ($titlecols > 0) {
1829 disp_end_cell();
1830 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1831 echo "<td class='label' colspan='$titlecols_esc' ";
1832 echo ">";
1833 $cell_count += $titlecols;
1835 ++$item_count;
1837 // Added 5-09 by BM - Translate label if applicable
1838 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
1840 // Handle starting of a new data cell.
1841 if ($datacols > 0) {
1842 disp_end_cell();
1843 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1844 echo "<td class='text data' colspan='$datacols_esc'";
1845 echo ">";
1846 $cell_count += $datacols;
1849 ++$item_count;
1850 echo generate_form_field($group_fields, $currvalue);
1854 </table>
1855 </div>
1857 <?php
1859 $first = false;
1864 // From the currently posted HTML form, this gets the value of the
1865 // field corresponding to the provided layout_options table row.
1867 function get_layout_form_value($frow, $maxlength=255) {
1868 // Bring in $sanitize_all_escapes variable, which will decide
1869 // the variable escaping method.
1870 global $sanitize_all_escapes;
1872 $data_type = $frow['data_type'];
1873 $field_id = $frow['field_id'];
1874 $value = '';
1875 if (isset($_POST["form_$field_id"])) {
1876 if ($data_type == 21) {
1877 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1878 // must be concatenated into a |-separated string.
1879 foreach ($_POST["form_$field_id"] as $key => $val) {
1880 if (strlen($value)) $value .= '|';
1881 $value .= $key;
1884 else if ($data_type == 22) {
1885 // $_POST["form_$field_id"] is an array of text fields to be imploded
1886 // into "key:value|key:value|...".
1887 foreach ($_POST["form_$field_id"] as $key => $val) {
1888 $val = str_replace('|', ' ', $val);
1889 if (strlen($value)) $value .= '|';
1890 $value .= "$key:$val";
1893 else if ($data_type == 23) {
1894 // $_POST["form_$field_id"] is an array of text fields with companion
1895 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1896 foreach ($_POST["form_$field_id"] as $key => $val) {
1897 $restype = $_POST["radio_{$field_id}"][$key];
1898 if (empty($restype)) $restype = '0';
1899 $val = str_replace('|', ' ', $val);
1900 if (strlen($value)) $value .= '|';
1901 $value .= "$key:$restype:$val";
1904 else if ($data_type == 25) {
1905 // $_POST["form_$field_id"] is an array of text fields with companion
1906 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1907 foreach ($_POST["form_$field_id"] as $key => $val) {
1908 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
1909 $val = str_replace('|', ' ', $val);
1910 if (strlen($value)) $value .= '|';
1911 $value .= "$key:$restype:$val";
1914 else if ($data_type == 28 || $data_type == 32) {
1915 // $_POST["form_$field_id"] is an date text fields with companion
1916 // radio buttons to be imploded into "notes|type|date".
1917 $restype = $_POST["radio_{$field_id}"];
1918 if (empty($restype)) $restype = '0';
1919 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1920 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1921 if ($data_type == 32)
1923 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
1924 $reslist = str_replace('|', ' ', $_POST["form_$field_id"]);
1925 $res_text_note = str_replace('|', ' ', $_POST["form_text_$field_id"]);
1926 $value = "$res_text_note|$restype|$resdate|$reslist";
1928 else
1929 $value = "$resnote|$restype|$resdate";
1931 else {
1932 $value = $_POST["form_$field_id"];
1936 // Better to die than to silently truncate data!
1937 if ($maxlength && $data_type != 3 && strlen($value) > $maxlength)
1938 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
1939 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
1941 // Make sure the return value is quote-safe.
1942 if ($sanitize_all_escapes) {
1943 //escapes already removed and using binding/placemarks in sql calls
1944 // so only need to trim value
1945 return trim($value);
1947 else {
1948 //need to explicitly prepare value
1949 return formTrim($value);
1953 // Generate JavaScript validation logic for the required fields.
1955 function generate_layout_validation($form_id) {
1956 $fres = sqlStatement("SELECT * FROM layout_options " .
1957 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
1958 "ORDER BY group_name, seq", array($form_id) );
1960 while ($frow = sqlFetchArray($fres)) {
1961 if ($frow['uor'] < 2) continue;
1962 $data_type = $frow['data_type'];
1963 $field_id = $frow['field_id'];
1964 $fldtitle = $frow['title'];
1965 if (!$fldtitle) $fldtitle = $frow['description'];
1966 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES);
1967 switch($data_type) {
1968 case 1:
1969 case 11:
1970 case 12:
1971 case 13:
1972 case 14:
1973 case 26:
1974 case 33:
1975 echo
1976 " if (f.$fldname.selectedIndex <= 0) {\n" .
1977 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1978 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1979 " }\n";
1980 break;
1981 case 27: // radio buttons
1982 echo
1983 " var i = 0;\n" .
1984 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
1985 " if (i >= f.$fldname.length) {\n" .
1986 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1987 " }\n";
1988 break;
1989 case 2:
1990 case 3:
1991 case 4:
1992 case 15:
1993 echo
1994 " if (trimlen(f.$fldname.value) == 0) {\n" .
1995 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1996 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
1997 " $('#" . $fldname . "').attr('style','background:red'); \n" .
1998 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1999 " } else { " .
2000 " $('#" . $fldname . "').attr('style',''); " .
2001 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2002 " } \n";
2003 break;
2009 * DROPDOWN FOR FACILITIES
2011 * build a dropdown with all facilities
2013 * @param string $selected - name of the currently selected facility
2014 * use '0' for "unspecified facility"
2015 * use '' for "All facilities" (the default)
2016 * @param string $name - the name/id for select form (defaults to "form_facility")
2017 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2018 * defaults to true
2019 * @return void - just echo the html encoded string
2021 * Note: This should become a data-type at some point, according to Brady
2023 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true) {
2024 $have_selected = false;
2025 $query = "SELECT id, name FROM facility ORDER BY name";
2026 $fres = sqlStatement($query);
2028 $name = htmlspecialchars($name, ENT_QUOTES);
2029 echo " <select name=\"$name\">\n";
2031 $option_value = '';
2032 $option_selected_attr = '';
2033 if ($selected == '') {
2034 $option_selected_attr = ' selected="selected"';
2035 $have_selected = true;
2037 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2038 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2040 while ($frow = sqlFetchArray($fres)) {
2041 $facility_id = $frow['id'];
2042 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2043 $option_selected_attr = '';
2044 if ($selected == $facility_id) {
2045 $option_selected_attr = ' selected="selected"';
2046 $have_selected = true;
2048 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2049 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2052 if ($allow_unspecified) {
2053 $option_value = '0';
2054 $option_selected_attr = '';
2055 if ( $selected == '0' ) {
2056 $option_selected_attr = ' selected="selected"';
2057 $have_selected = true;
2059 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2060 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2063 if (!$have_selected) {
2064 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2065 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2066 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2067 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2069 echo " </select>\n";
2072 // Expand Collapse Widget
2073 // This forms the header and functionality component of the widget. The information that is displayed
2074 // then follows this function followed by a closing div tag
2076 // $title is the title of the section (already translated)
2077 // $label is identifier used in the tag id's and sql columns
2078 // $buttonLabel is the button label text (already translated)
2079 // $buttonLink is the button link information
2080 // $buttonClass is any additional needed class elements for the button tag
2081 // $linkMethod is the button link method ('javascript' vs 'html')
2082 // $bodyClass is to set class(es) of the body
2083 // $auth is a flag to decide whether to show the button
2084 // $fixedWidth is to flag whether width is fixed
2085 // $forceExpandAlways is a flag to force the widget to always be expanded
2087 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2088 if ($fixedWidth) {
2089 echo "<div class='section-header'>";
2091 else {
2092 echo "<div class='section-header-dynamic'>";
2094 echo "<table><tr>";
2095 if ($auth) {
2096 // show button, since authorized
2097 // first prepare class string
2098 if ($buttonClass) {
2099 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
2101 else {
2102 $class_string = "css_button_small";
2104 // next, create the link
2105 if ($linkMethod == "javascript") {
2106 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2108 else {
2109 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
2110 if (!isset($_SESSION['patient_portal_onsite'])) {
2111 // prevent an error from occuring when calling the function from the patient portal
2112 echo " onclick='top.restoreSession()'";
2115 if (!$GLOBALS['concurrent_layout']) {
2116 echo " target='Main'";
2118 echo "><span>" .
2119 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
2121 if ($forceExpandAlways){
2122 // Special case to force the widget to always be expanded
2123 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2124 $indicatorTag ="style='display:none'";
2126 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2127 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
2128 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2130 if (isset($_SESSION['patient_portal_onsite'])) {
2131 // collapse all entries in the patient portal
2132 $text = xl('expand');
2134 else if (getUserSetting($label."_ps_expand")) {
2135 $text = xl('collapse');
2137 else {
2138 $text = xl('expand');
2140 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
2141 "</span>)</a></td>";
2142 echo "</tr></table>";
2143 echo "</div>";
2144 if ($forceExpandAlways) {
2145 // Special case to force the widget to always be expanded
2146 $styling = "";
2148 else if (isset($_SESSION['patient_portal_onsite'])) {
2149 // collapse all entries in the patient portal
2150 $styling = "style='display:none'";
2152 else if (getUserSetting($label."_ps_expand")) {
2153 $styling = "";
2155 else {
2156 $styling = "style='display:none'";
2158 if ($bodyClass) {
2159 $styling .= " class='" . $bodyClass . "'";
2161 //next, create the first div tag to hold the information
2162 // note the code that calls this function will then place the ending div tag after the data
2163 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";
2166 //billing_facility fuction will give the dropdown list which contain billing faciliies.
2167 function billing_facility($name,$select){
2168 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
2169 echo " <select id='".htmlspecialchars($name, ENT_QUOTES)."' name='".htmlspecialchars($name, ENT_QUOTES)."'>";
2170 while ($facrow = sqlFetchArray($qsql)) {
2171 $selected = ( $facrow['id'] == $select ) ? 'selected="selected"' : '' ;
2172 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES)."</option>";
2174 echo "</select>";