2 // Copyright (C) 2007-2010 Rod Roark <rod@sunsetsystems.com>
3 // Copyright © 2010 by Andrew Moore <amoore@cpan.org>
4 // Copyright © 2010 by "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // Functions for managing the lists and layouts
13 // Note: there are translation wrappers for the lists and layout labels
14 // at library/translation.inc.php. The functions are titled
15 // xl_list_label() and xl_layout_label() and are controlled by the
16 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
17 // flags in globals.php
19 require_once("formdata.inc.php");
20 require_once("formatting.inc.php");
24 function get_pharmacies() {
25 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
26 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
27 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
28 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
30 "ORDER BY name, area_code, prefix, number");
33 // Function to generate a drop-list.
35 function generate_select_list($tag_name, $list_id, $currvalue, $title,
36 $empty_name=' ', $class='', $onchange='')
39 $tag_name_esc = htmlspecialchars( $tag_name, ENT_QUOTES
);
40 $s .= "<select name='$tag_name_esc' id='$tag_name_esc'";
41 if ($class) $s .= " class='$class'";
42 if ($onchange) $s .= " onchange='$onchange'";
43 $selectTitle = htmlspecialchars( $title, ENT_QUOTES
);
44 $s .= " title='$selectTitle'>";
45 $selectEmptyName = htmlspecialchars( xl($empty_name), ENT_NOQUOTES
);
46 if ($empty_name) $s .= "<option value=''>" . $selectEmptyName . "</option>";
47 $lres = sqlStatement("SELECT * FROM list_options " .
48 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
49 $got_selected = FALSE;
50 while ($lrow = sqlFetchArray($lres)) {
51 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES
);
52 $s .= "<option value='$optionValue'";
53 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
54 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
59 $optionLabel = htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
60 $s .= ">$optionLabel</option>\n";
62 if (!$got_selected && strlen($currvalue) > 0) {
63 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
64 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
66 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_QUOTES
);
67 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
68 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
76 // $frow is a row from the layout_options table.
77 // $currvalue is the current value, if any, of the associated item.
79 function generate_form_field($frow, $currvalue) {
80 global $rootdir, $date_init;
82 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
84 $data_type = $frow['data_type'];
85 $field_id = $frow['field_id'];
86 $list_id = $frow['list_id'];
87 // escaped variables to use in html
88 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES
);
89 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES
);
91 // Added 5-09 by BM - Translate description if applicable
92 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
94 // added 5-2009 by BM to allow modification of the 'empty' text title field.
95 // Can pass $frow['empty_title'] with this variable, otherwise
96 // will default to 'Unassigned'.
97 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
98 // if make $frow['empty_title'] equal to 'SKIP'
100 if (isset($frow['empty_title'])) {
101 if ($frow['empty_title'] == "SKIP") {
102 //do not display an 'empty' choice
104 $empty_title = "Unassigned";
107 $empty_title = $frow['empty_title'];
111 $empty_title = "Unassigned";
114 // generic single-selection list
115 if ($data_type == 1) {
116 echo generate_select_list("form_$field_id", $list_id, $currvalue,
117 $description, $showEmpty ?
$empty_title : '');
121 else if ($data_type == 2) {
122 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
123 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
124 echo "<input type='text'" .
125 " name='form_$field_id_esc'" .
126 " id='form_$field_id_esc'" .
127 " size='$fldlength'" .
128 " maxlength='$maxlength'" .
129 " title='$description'" .
130 " value='$currescaped'";
131 if (strpos($frow['edit_options'], 'C') !== FALSE)
132 echo " onchange='capitalizeMe(this)'";
133 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES
);
134 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
135 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
136 echo " onblur='maskblur(this,\"$tmp\")'";
141 // long or multi-line text field
142 else if ($data_type == 3) {
143 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
144 $textRows = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
146 " name='form_$field_id_esc'" .
147 " id='form_$field_id_esc'" .
148 " title='$description'" .
149 " cols='$textCols'" .
150 " rows='$textRows'>" .
151 $currescaped . "</textarea>";
155 else if ($data_type == 4) {
156 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
157 " value='$currescaped'" .
158 " title='$description'" .
159 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
160 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
161 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
162 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES
) . "' />";
163 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
166 // provider list, local providers only
167 else if ($data_type == 10) {
168 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
169 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
170 "AND authorized = 1 " .
171 "ORDER BY lname, fname");
172 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
173 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
174 while ($urow = sqlFetchArray($ures)) {
175 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES
);
176 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES
);
177 echo "<option value='$optionId'";
178 if ($urow['id'] == $currvalue) echo " selected";
179 echo ">$uname</option>";
184 // provider list, including address book entries with an NPI number
185 else if ($data_type == 11) {
186 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
187 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
188 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
189 "ORDER BY lname, fname");
190 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
191 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
192 while ($urow = sqlFetchArray($ures)) {
193 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES
);
194 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES
);
195 echo "<option value='$optionId'";
196 if ($urow['id'] == $currvalue) echo " selected";
197 echo ">$uname</option>";
203 else if ($data_type == 12) {
204 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
205 echo "<option value='0'></option>";
206 $pres = get_pharmacies();
207 while ($prow = sqlFetchArray($pres)) {
209 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
210 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
211 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
212 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES
);
213 echo "<option value='$optionValue'";
214 if ($currvalue == $key) echo " selected";
215 echo ">$optionLabel</option>";
221 else if ($data_type == 13) {
222 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
223 echo "<option value=''> </option>";
224 $squads = acl_get_squads();
226 foreach ($squads as $key => $value) {
227 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
228 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES
);
229 echo "<option value='$optionValue'";
230 if ($currvalue == $key) echo " selected";
231 echo ">$optionLabel</option>\n";
237 // Address book, preferring organization name if it exists and is not in
238 // parentheses, and excluding local users who are not providers.
239 // Supports "referred to" practitioners and facilities.
240 // Alternatively the letter O in edit_options means that abook_type
241 // must begin with "ord_", indicating types used with the procedure
243 // Alternatively the letter V in edit_options means that abook_type
244 // must be "vendor", indicating the Vendor type.
245 else if ($data_type == 14) {
246 if (strpos($frow['edit_options'], 'O') !== FALSE)
247 $tmp = "abook_type LIKE 'ord\\_%'";
248 else if (strpos($frow['edit_options'], 'V') !== FALSE)
249 $tmp = "abook_type LIKE 'vendor%'";
251 $tmp = "( username = '' OR authorized = 1 )";
252 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
253 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
255 "ORDER BY organization, lname, fname");
256 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
257 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
258 while ($urow = sqlFetchArray($ures)) {
259 $uname = $urow['organization'];
260 if (empty($uname) ||
substr($uname, 0, 1) == '(') {
261 $uname = $urow['lname'];
262 if ($urow['fname']) $uname .= ", " . $urow['fname'];
264 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES
);
265 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES
);
266 echo "<option value='$optionValue'";
267 $title = $urow['username'] ?
xl('Local') : xl('External');
268 $optionTitle = htmlspecialchars( $title, ENT_QUOTES
);
269 echo " title='$optionTitle'";
270 if ($urow['id'] == $currvalue) echo " selected";
271 echo ">$optionLabel</option>";
277 else if ($data_type == 15) {
278 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
279 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
280 echo "<input type='text'" .
281 " name='form_$field_id_esc'" .
282 " id='form_related_code'" .
283 " size='$fldlength'" .
284 " maxlength='$maxlength'" .
285 " title='$description'" .
286 " value='$currescaped'" .
287 " onclick='sel_related(this)' readonly" .
291 // a set of labeled checkboxes
292 else if ($data_type == 21) {
293 // In this special case, fld_length is the number of columns generated.
294 $cols = max(1, $frow['fld_length']);
295 $avalue = explode('|', $currvalue);
296 $lres = sqlStatement("SELECT * FROM list_options " .
297 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
298 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
299 $tdpct = (int) (100 / $cols);
300 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
301 $option_id = $lrow['option_id'];
302 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
303 // if ($count) echo "<br />";
304 if ($count %
$cols == 0) {
305 if ($count) echo "</tr>";
308 echo "<td width='$tdpct%'>";
309 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]' id='form_{$field_id_esc}[$option_id_esc]' value='1'";
310 if (in_array($option_id, $avalue)) echo " checked";
312 // Added 5-09 by BM - Translate label if applicable
313 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
319 if ($count > $cols) {
320 // Add some space after multiple rows of checkboxes.
321 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
322 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
328 // a set of labeled text input fields
329 else if ($data_type == 22) {
330 $tmp = explode('|', $currvalue);
332 foreach ($tmp as $value) {
333 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
334 $avalue[$matches[1]] = $matches[2];
337 $lres = sqlStatement("SELECT * FROM list_options " .
338 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
339 echo "<table cellpadding='0' cellspacing='0'>";
340 while ($lrow = sqlFetchArray($lres)) {
341 $option_id = $lrow['option_id'];
342 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
343 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
344 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
346 // Added 5-09 by BM - Translate label if applicable
347 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
348 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
349 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
350 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
351 echo "<td><input type='text'" .
352 " name='form_{$field_id_esc}[$option_id_esc]'" .
353 " id='form_{$field_id_esc}[$option_id_esc]'" .
354 " size='$fldlength'" .
355 " maxlength='$maxlength'" .
356 " value='$optionValue'";
357 echo " /></td></tr>";
362 // a set of exam results; 3 radio buttons and a text field:
363 else if ($data_type == 23) {
364 $tmp = explode('|', $currvalue);
366 foreach ($tmp as $value) {
367 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
368 $avalue[$matches[1]] = $matches[2];
371 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
372 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
373 $lres = sqlStatement("SELECT * FROM list_options " .
374 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
375 echo "<table cellpadding='0' cellspacing='0'>";
376 echo "<tr><td> </td><td class='bold'>" .
377 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
378 " </td><td class='bold'>" .
379 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
380 "<td class='bold'>" .
381 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
382 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
383 while ($lrow = sqlFetchArray($lres)) {
384 $option_id = $lrow['option_id'];
385 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
386 $restype = substr($avalue[$option_id], 0, 1);
387 $resnote = substr($avalue[$option_id], 2);
389 // Added 5-09 by BM - Translate label if applicable
390 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
392 for ($i = 0; $i < 3; ++
$i) {
393 $inputValue = htmlspecialchars( $i, ENT_QUOTES
);
394 echo "<td><input type='radio'" .
395 " name='radio_{$field_id_esc}[$option_id_esc]'" .
396 " id='radio_{$field_id_esc}[$option_id_esc]'" .
397 " value='$inputValue'";
398 if ($restype === "$i") echo " checked";
401 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
402 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
403 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
404 echo "<td><input type='text'" .
405 " name='form_{$field_id_esc}[$option_id_esc]'" .
406 " id='form_{$field_id_esc}[$option_id_esc]'" .
407 " size='$fldlength'" .
408 " maxlength='$maxlength'" .
409 " value='$resnote' /></td>";
415 // the list of active allergies for the current patient
416 // this is read-only!
417 else if ($data_type == 24) {
418 $query = "SELECT title, comments FROM lists WHERE " .
419 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
421 // echo "<!-- $query -->\n"; // debugging
422 $lres = sqlStatement($query, array($GLOBALS['pid']));
424 while ($lrow = sqlFetchArray($lres)) {
425 if ($count++
) echo "<br />";
426 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES
);
427 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES
) . ')';
431 // a set of labeled checkboxes, each with a text field:
432 else if ($data_type == 25) {
433 $tmp = explode('|', $currvalue);
435 foreach ($tmp as $value) {
436 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
437 $avalue[$matches[1]] = $matches[2];
440 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
441 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
442 $lres = sqlStatement("SELECT * FROM list_options " .
443 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
444 echo "<table cellpadding='0' cellspacing='0'>";
445 while ($lrow = sqlFetchArray($lres)) {
446 $option_id = $lrow['option_id'];
447 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
448 $restype = substr($avalue[$option_id], 0, 1);
449 $resnote = substr($avalue[$option_id], 2);
451 // Added 5-09 by BM - Translate label if applicable
452 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
454 $option_id = htmlspecialchars( $option_id, ENT_QUOTES
);
455 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]' id='check_{$field_id_esc}[$option_id_esc]' value='1'";
456 if ($restype) echo " checked";
457 echo " /> </td>";
458 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
459 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
460 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
461 echo "<td><input type='text'" .
462 " name='form_{$field_id_esc}[$option_id_esc]'" .
463 " id='form_{$field_id_esc}[$option_id_esc]'" .
464 " size='$fldlength'" .
465 " maxlength='$maxlength'" .
466 " value='$resnote' /></td>";
472 // single-selection list with ability to add to it
473 else if ($data_type == 26) {
474 echo "<select class='addtolistclass_$list_id_esc' name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
475 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES
) . "</option>";
476 $lres = sqlStatement("SELECT * FROM list_options " .
477 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
478 $got_selected = FALSE;
479 while ($lrow = sqlFetchArray($lres)) {
480 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES
);
481 echo "<option value='$optionValue'";
482 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
483 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
486 $got_selected = TRUE;
488 // Added 5-09 by BM - Translate label if applicable
489 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . "</option>\n";
491 if (!$got_selected && strlen($currvalue) > 0) {
492 echo "<option value='$currescaped' selected>* $currescaped *</option>";
494 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES
);
495 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
496 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
501 // show the add button if user has access to correct list
502 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES
);
503 $outputAddButton = "<input type='button' id='addtolistid_".$list_id_esc."' fieldid='form_".$field_id_esc."' class='addtolist' value='$inputValue'>";
504 if (aco_exist('lists', $list_id)) {
505 // a specific aco exist for this list, so ensure access
506 if (acl_check('lists', $list_id)) echo $outputAddButton;
509 // no specific aco exist for this list, so check for access to 'default' list
510 if (acl_check('lists', 'default')) echo $outputAddButton;
514 // a set of labeled radio buttons
515 else if ($data_type == 27) {
516 // In this special case, fld_length is the number of columns generated.
517 $cols = max(1, $frow['fld_length']);
518 $lres = sqlStatement("SELECT * FROM list_options " .
519 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
520 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
521 $tdpct = (int) (100 / $cols);
522 $got_selected = FALSE;
523 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
524 $option_id = $lrow['option_id'];
525 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
526 if ($count %
$cols == 0) {
527 if ($count) echo "</tr>";
530 echo "<td width='$tdpct%'>";
531 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]' value='$option_id_esc'";
532 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
533 (strlen($currvalue) > 0 && $option_id == $currvalue))
536 $got_selected = TRUE;
538 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
543 if ($count > $cols) {
544 // Add some space after multiple rows of radio buttons.
545 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
546 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
550 if (!$got_selected && strlen($currvalue) > 0) {
551 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES
);
552 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
553 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
557 // special case for history of lifestyle status; 3 radio buttons and a date text field:
558 else if ($data_type == 28) {
559 $tmp = explode('|', $currvalue);
560 switch(count($tmp)) {
573 $resdate = $restype = "";
576 $restype = $resdate = $resnote = "";
579 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
580 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
582 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
583 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
584 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
585 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
586 echo "<table cellpadding='0' cellspacing='0'>";
589 echo "<td><input type='text'" .
590 " name='form_$field_id_esc'" .
591 " id='form_$field_id_esc'" .
592 " size='$fldlength'" .
593 " maxlength='$maxlength'" .
594 " value='$resnote' /> </td>";
595 echo "<td class='bold'> ".htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
597 echo "<td><input type='radio'" .
598 " name='radio_{$field_id_esc}'" .
599 " id='radio_{$field_id_esc}[current]'" .
600 " value='current".$field_id_esc."'";
601 if ($restype == "current".$field_id) echo " checked";
602 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES
)." </td>";
604 echo "<td><input type='radio'" .
605 " name='radio_{$field_id_esc}'" .
606 " id='radio_{$field_id_esc}[quit]'" .
607 " value='quit".$field_id_esc."'";
608 if ($restype == "quit".$field_id) echo " checked";
609 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES
)." </td>";
611 echo "<td><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
612 " value='$resdate'" .
613 " title='$description'" .
614 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
615 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
616 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
617 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES
) . "' /> </td>";
618 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
620 echo "<td><input type='radio'" .
621 " name='radio_{$field_id_esc}'" .
622 " id='radio_{$field_id_esc}[never]'" .
623 " value='never".$field_id_esc."'";
624 if ($restype == "never".$field_id) echo " checked";
625 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES
)." </td>";
627 echo "<td><input type='radio'" .
628 " name='radio_{$field_id}'" .
629 " id='radio_{$field_id}[not_applicable]'" .
630 " value='not_applicable".$field_id."'";
631 if ($restype == "not_applicable".$field_id) echo " checked";
632 echo " />".htmlspecialchars( xl('N/A'), ENT_QUOTES
)." </td>";
637 // static text. read-only, of course.
638 else if ($data_type == 31) {
639 echo nl2br($frow['description']);
644 function generate_print_field($frow, $currvalue) {
645 global $rootdir, $date_init;
647 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
649 $data_type = $frow['data_type'];
650 $field_id = $frow['field_id'];
651 $list_id = $frow['list_id'];
652 $fld_length = $frow['fld_length'];
654 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
656 // Can pass $frow['empty_title'] with this variable, otherwise
657 // will default to 'Unassigned'.
658 // If it is 'SKIP' then an empty text title is completely skipped.
660 if (isset($frow['empty_title'])) {
661 if ($frow['empty_title'] == "SKIP") {
662 //do not display an 'empty' choice
664 $empty_title = "Unassigned";
667 $empty_title = $frow['empty_title'];
671 $empty_title = "Unassigned";
674 // generic single-selection list
675 if ($data_type == 1 ||
$data_type == 26) {
676 if (empty($fld_length)) {
677 if ($list_id == 'titles') {
685 $lrow = sqlQuery("SELECT title FROM list_options " .
686 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
687 $tmp = xl_list_label($lrow['title']);
688 if (empty($tmp)) $tmp = "($currvalue)";
690 /*****************************************************************
691 echo "<input type='text'" .
692 " size='$fld_length'" .
696 *****************************************************************/
697 if ($tmp === '') { $tmp = ' '; }
698 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
703 else if ($data_type == 2 ||
$data_type == 15) {
704 /*****************************************************************
705 echo "<input type='text'" .
706 " size='$fld_length'" .
707 " value='$currescaped'" .
710 *****************************************************************/
711 if ($currescaped === '') $currescaped = ' ';
715 // long or multi-line text field
716 else if ($data_type == 3) {
717 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES
);
718 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
720 " cols='$fldlength'" .
721 " rows='$maxlength'>" .
722 $currescaped . "</textarea>";
726 else if ($data_type == 4) {
727 /*****************************************************************
728 echo "<input type='text' size='10'" .
729 " value='$currescaped'" .
730 " title='$description'" .
733 *****************************************************************/
734 if ($currvalue === '') { $tmp = oeFormatShortDate(' '); }
735 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES
); }
740 else if ($data_type == 10 ||
$data_type == 11) {
743 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
744 "WHERE id = ?", array($currvalue) );
745 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
746 if (empty($tmp)) $tmp = "($currvalue)";
748 /*****************************************************************
749 echo "<input type='text'" .
750 " size='$fld_length'" .
754 *****************************************************************/
755 if ($tmp === '') { $tmp = ' '; }
756 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
761 else if ($data_type == 12) {
764 $pres = get_pharmacies();
765 while ($prow = sqlFetchArray($pres)) {
767 if ($currvalue == $key) {
768 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
769 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
770 $prow['line1'] . ' / ' . $prow['city'];
773 if (empty($tmp)) $tmp = "($currvalue)";
775 /*****************************************************************
776 echo "<input type='text'" .
777 " size='$fld_length'" .
781 *****************************************************************/
782 if ($tmp === '') { $tmp = ' '; }
783 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
788 else if ($data_type == 13) {
791 $squads = acl_get_squads();
793 foreach ($squads as $key => $value) {
794 if ($currvalue == $key) {
799 if (empty($tmp)) $tmp = "($currvalue)";
801 /*****************************************************************
802 echo "<input type='text'" .
803 " size='$fld_length'" .
807 *****************************************************************/
808 if ($tmp === '') { $tmp = ' '; }
809 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
814 else if ($data_type == 14) {
817 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
818 "WHERE id = ?", array($currvalue) );
819 $uname = $urow['lname'];
820 if ($urow['fname']) $uname .= ", " . $urow['fname'];
822 if (empty($tmp)) $tmp = "($currvalue)";
824 /*****************************************************************
825 echo "<input type='text'" .
826 " size='$fld_length'" .
830 *****************************************************************/
831 if ($tmp === '') { $tmp = ' '; }
832 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
836 // a set of labeled checkboxes
837 else if ($data_type == 21) {
838 // In this special case, fld_length is the number of columns generated.
839 $cols = max(1, $fld_length);
840 $avalue = explode('|', $currvalue);
841 $lres = sqlStatement("SELECT * FROM list_options " .
842 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
843 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
844 $tdpct = (int) (100 / $cols);
845 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
846 $option_id = $lrow['option_id'];
847 if ($count %
$cols == 0) {
848 if ($count) echo "</tr>";
851 echo "<td width='$tdpct%'>";
852 echo "<input type='checkbox'";
853 if (in_array($option_id, $avalue)) echo " checked";
854 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
859 if ($count > $cols) {
860 // Add some space after multiple rows of checkboxes.
861 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
862 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
868 // a set of labeled text input fields
869 else if ($data_type == 22) {
870 $tmp = explode('|', $currvalue);
872 foreach ($tmp as $value) {
873 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
874 $avalue[$matches[1]] = $matches[2];
877 $lres = sqlStatement("SELECT * FROM list_options " .
878 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
879 echo "<table cellpadding='0' cellspacing='0'>";
880 while ($lrow = sqlFetchArray($lres)) {
881 $option_id = $lrow['option_id'];
882 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
883 $fldlength = empty($fld_length) ?
20 : $fld_length;
884 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
885 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
886 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
887 echo "<td><input type='text'" .
888 " size='$fldlength'" .
889 " value='$inputValue'" .
896 // a set of exam results; 3 radio buttons and a text field:
897 else if ($data_type == 23) {
898 $tmp = explode('|', $currvalue);
900 foreach ($tmp as $value) {
901 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
902 $avalue[$matches[1]] = $matches[2];
905 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
906 $fldlength = empty($fld_length) ?
20 : $fld_length;
907 $lres = sqlStatement("SELECT * FROM list_options " .
908 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
909 echo "<table cellpadding='0' cellspacing='0'>";
910 echo "<tr><td> </td><td class='bold'>" .
911 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
912 " </td><td class='bold'>" .
913 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
914 "<td class='bold'>" .
915 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
916 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
917 while ($lrow = sqlFetchArray($lres)) {
918 $option_id = $lrow['option_id'];
919 $restype = substr($avalue[$option_id], 0, 1);
920 $resnote = substr($avalue[$option_id], 2);
921 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
922 for ($i = 0; $i < 3; ++
$i) {
923 echo "<td><input type='radio'";
924 if ($restype === "$i") echo " checked";
927 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
928 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
929 echo "<td><input type='text'" .
930 " size='$fldlength'" .
931 " value='$resnote'" .
932 " class='under' /></td>" .
938 // the list of active allergies for the current patient
939 // this is read-only!
940 else if ($data_type == 24) {
941 $query = "SELECT title, comments FROM lists WHERE " .
942 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
944 $lres = sqlStatement($query, array($GLOBALS['pid']) );
946 while ($lrow = sqlFetchArray($lres)) {
947 if ($count++
) echo "<br />";
948 echo htmlspecialchars( $lrow['title'], ENT_QUOTES
);
949 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES
);
953 // a set of labeled checkboxes, each with a text field:
954 else if ($data_type == 25) {
955 $tmp = explode('|', $currvalue);
957 foreach ($tmp as $value) {
958 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
959 $avalue[$matches[1]] = $matches[2];
962 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
963 $fldlength = empty($fld_length) ?
20 : $fld_length;
964 $lres = sqlStatement("SELECT * FROM list_options " .
965 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
966 echo "<table cellpadding='0' cellspacing='0'>";
967 while ($lrow = sqlFetchArray($lres)) {
968 $option_id = $lrow['option_id'];
969 $restype = substr($avalue[$option_id], 0, 1);
970 $resnote = substr($avalue[$option_id], 2);
971 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
972 echo "<td><input type='checkbox'";
973 if ($restype) echo " checked";
974 echo " /> </td>";
975 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
976 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
977 echo "<td><input type='text'" .
978 " size='$fldlength'" .
979 " value='$resnote'" .
987 // a set of labeled radio buttons
988 else if ($data_type == 27) {
989 // In this special case, fld_length is the number of columns generated.
990 $cols = max(1, $frow['fld_length']);
991 $lres = sqlStatement("SELECT * FROM list_options " .
992 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
993 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
994 $tdpct = (int) (100 / $cols);
995 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
996 $option_id = $lrow['option_id'];
997 if ($count %
$cols == 0) {
998 if ($count) echo "</tr>";
1001 echo "<td width='$tdpct%'>";
1002 echo "<input type='radio'";
1003 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1004 (strlen($currvalue) > 0 && $option_id == $currvalue))
1008 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
1013 if ($count > $cols) {
1014 // Add some space after multiple rows of radio buttons.
1015 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
1016 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1022 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1023 else if ($data_type == 28) {
1024 $tmp = explode('|', $currvalue);
1025 switch(count($tmp)) {
1038 $resdate = $restype = "";
1041 $restype = $resdate = $resnote = "";
1044 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
1045 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
1046 echo "<table cellpadding='0' cellspacing='0'>";
1048 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1049 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1050 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
1051 echo "<td><input type='text'" .
1052 " size='$fldlength'" .
1054 " value='$resnote' /></td>";
1055 echo "<td class='bold'> ".
1056 htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
1057 echo "<td><input type='radio'";
1058 if ($restype == "current".$field_id) echo " checked";
1059 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES
)." </td>";
1061 echo "<td><input type='radio'";
1062 if ($restype == "current".$field_id) echo " checked";
1063 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES
)." </td>";
1065 echo "<td><input type='text' size='6'" .
1066 " value='$resdate'" .
1070 echo "<td><input type='radio'";
1071 if ($restype == "current".$field_id) echo " checked";
1072 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES
)."</td>";
1074 echo "<td><input type='radio'";
1075 if ($restype == "not_applicable".$field_id) echo " checked";
1076 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES
)." </td>";
1081 // static text. read-only, of course.
1082 else if ($data_type == 31) {
1083 echo nl2br($frow['description']);
1088 function generate_display_field($frow, $currvalue) {
1089 $data_type = $frow['data_type'];
1090 $field_id = $frow['field_id'];
1091 $list_id = $frow['list_id'];
1094 // generic selection list or the generic selection list with add on the fly
1095 // feature, or radio buttons
1096 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 27) {
1097 $lrow = sqlQuery("SELECT title FROM list_options " .
1098 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1099 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1102 // simple text field
1103 else if ($data_type == 2) {
1104 $s = htmlspecialchars($currvalue,ENT_NOQUOTES
);
1107 // long or multi-line text field
1108 else if ($data_type == 3) {
1109 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES
));
1113 else if ($data_type == 4) {
1114 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES
);
1118 else if ($data_type == 10 ||
$data_type == 11) {
1119 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1120 "WHERE id = ?", array($currvalue) );
1121 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES
);
1125 else if ($data_type == 12) {
1126 $pres = get_pharmacies();
1127 while ($prow = sqlFetchArray($pres)) {
1129 if ($currvalue == $key) {
1130 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1131 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1132 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES
);
1138 else if ($data_type == 13) {
1139 $squads = acl_get_squads();
1141 foreach ($squads as $key => $value) {
1142 if ($currvalue == $key) {
1143 $s .= htmlspecialchars($value[3],ENT_NOQUOTES
);
1150 else if ($data_type == 14) {
1151 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1152 "WHERE id = ?", array($currvalue));
1153 $uname = $urow['lname'];
1154 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1155 $s = htmlspecialchars($uname,ENT_NOQUOTES
);
1159 else if ($data_type == 15) {
1160 $s = htmlspecialchars($currvalue,ENT_NOQUOTES
);
1163 // a set of labeled checkboxes
1164 else if ($data_type == 21) {
1165 $avalue = explode('|', $currvalue);
1166 $lres = sqlStatement("SELECT * FROM list_options " .
1167 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1169 while ($lrow = sqlFetchArray($lres)) {
1170 $option_id = $lrow['option_id'];
1171 if (in_array($option_id, $avalue)) {
1172 if ($count++
) $s .= "<br />";
1174 // Added 5-09 by BM - Translate label if applicable
1175 $s .= htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1181 // a set of labeled text input fields
1182 else if ($data_type == 22) {
1183 $tmp = explode('|', $currvalue);
1185 foreach ($tmp as $value) {
1186 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1187 $avalue[$matches[1]] = $matches[2];
1190 $lres = sqlStatement("SELECT * FROM list_options " .
1191 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1192 $s .= "<table cellpadding='0' cellspacing='0'>";
1193 while ($lrow = sqlFetchArray($lres)) {
1194 $option_id = $lrow['option_id'];
1195 if (empty($avalue[$option_id])) continue;
1197 // Added 5-09 by BM - Translate label if applicable
1198 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . ": </td>";
1200 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES
) . "</td></tr>";
1205 // a set of exam results; 3 radio buttons and a text field:
1206 else if ($data_type == 23) {
1207 $tmp = explode('|', $currvalue);
1209 foreach ($tmp as $value) {
1210 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1211 $avalue[$matches[1]] = $matches[2];
1214 $lres = sqlStatement("SELECT * FROM list_options " .
1215 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1216 $s .= "<table cellpadding='0' cellspacing='0'>";
1217 while ($lrow = sqlFetchArray($lres)) {
1218 $option_id = $lrow['option_id'];
1219 $restype = substr($avalue[$option_id], 0, 1);
1220 $resnote = substr($avalue[$option_id], 2);
1221 if (empty($restype) && empty($resnote)) continue;
1223 // Added 5-09 by BM - Translate label if applicable
1224 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1226 $restype = ($restype == '1') ?
xl('Normal') : (($restype == '2') ?
xl('Abnormal') : xl('N/A'));
1227 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1228 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1229 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . " </td>";
1230 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td>";
1236 // the list of active allergies for the current patient
1237 else if ($data_type == 24) {
1238 $query = "SELECT title, comments FROM lists WHERE " .
1239 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1241 // echo "<!-- $query -->\n"; // debugging
1242 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1244 while ($lrow = sqlFetchArray($lres)) {
1245 if ($count++
) $s .= "<br />";
1246 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES
);
1247 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES
) . ')';
1251 // a set of labeled checkboxes, each with a text field:
1252 else if ($data_type == 25) {
1253 $tmp = explode('|', $currvalue);
1255 foreach ($tmp as $value) {
1256 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1257 $avalue[$matches[1]] = $matches[2];
1260 $lres = sqlStatement("SELECT * FROM list_options " .
1261 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1262 $s .= "<table cellpadding='0' cellspacing='0'>";
1263 while ($lrow = sqlFetchArray($lres)) {
1264 $option_id = $lrow['option_id'];
1265 $restype = substr($avalue[$option_id], 0, 1);
1266 $resnote = substr($avalue[$option_id], 2);
1267 if (empty($restype) && empty($resnote)) continue;
1269 // Added 5-09 by BM - Translate label if applicable
1270 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1272 $restype = $restype ?
xl('Yes') : xl('No');
1273 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . "</td></tr>";
1274 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td></tr>";
1280 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1281 else if ($data_type == 28) {
1282 $tmp = explode('|', $currvalue);
1283 switch(count($tmp)) {
1296 $resdate = $restype = "";
1299 $restype = $resdate = $resnote = "";
1302 $s .= "<table cellpadding='0' cellspacing='0'>";
1306 if ($restype == "current".$field_id) $res = xl('Current');
1307 if ($restype == "quit".$field_id) $res = xl('Quit');
1308 if ($restype == "never".$field_id) $res = xl('Never');
1309 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1310 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1311 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1312 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . " </td>";
1313 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES
) . "</b>: " . htmlspecialchars($res,ENT_NOQUOTES
) . " </td>";
1314 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES
) . " </td>";
1319 // static text. read-only, of course.
1320 else if ($data_type == 31) {
1321 $s .= nl2br($frow['description']);
1327 $CPR = 4; // cells per row of generic data
1332 function disp_end_cell() {
1333 global $item_count, $cell_count;
1334 if ($item_count > 0) {
1340 function disp_end_row() {
1341 global $cell_count, $CPR;
1343 if ($cell_count > 0) {
1344 for (; $cell_count < $CPR; ++
$cell_count) echo "<td></td>";
1350 function disp_end_group() {
1352 if (strlen($last_group) > 0) {
1357 function display_layout_rows($formtype, $result1, $result2='') {
1358 global $item_count, $cell_count, $last_group, $CPR;
1360 $fres = sqlStatement("SELECT * FROM layout_options " .
1361 "WHERE form_id = ? AND uor > 0 " .
1362 "ORDER BY group_name, seq", array($formtype) );
1364 while ($frow = sqlFetchArray($fres)) {
1365 $this_group = $frow['group_name'];
1366 $titlecols = $frow['titlecols'];
1367 $datacols = $frow['datacols'];
1368 $data_type = $frow['data_type'];
1369 $field_id = $frow['field_id'];
1370 $list_id = $frow['list_id'];
1373 if ($formtype == 'DEM') {
1374 if ($GLOBALS['athletic_team']) {
1375 // Skip fitness level and return-to-play date because those appear
1376 // in a special display/update form on this page.
1377 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
1379 if (strpos($field_id, 'em_') === 0) {
1380 // Skip employer related fields, if it's disabled.
1381 if ($GLOBALS['omit_employers']) continue;
1382 $tmp = substr($field_id, 3);
1383 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1386 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1390 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1393 // Handle a data category (group) change.
1394 if (strcmp($this_group, $last_group) != 0) {
1395 $group_name = substr($this_group, 1);
1396 // totally skip generating the employer category, if it's disabled.
1397 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1399 $last_group = $this_group;
1402 // Handle starting of a new row.
1403 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
1407 echo "<td class='groupname'>";
1408 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1409 //echo "<font color='#008800'>$group_name</font>";
1411 // Added 5-09 by BM - Translate label if applicable
1412 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
);
1416 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1417 echo "<td valign='top'> ";
1422 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1424 // Handle starting of a new label cell.
1425 if ($titlecols > 0) {
1427 //echo "<td class='label' colspan='$titlecols' valign='top'";
1428 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
1429 echo "<td class='label' colspan='$titlecols_esc' ";
1430 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1432 $cell_count +
= $titlecols;
1436 // Added 5-09 by BM - Translate label if applicable
1437 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES
); else echo " ";
1439 // Handle starting of a new data cell.
1440 if ($datacols > 0) {
1442 //echo "<td class='text data' colspan='$datacols' valign='top'";
1443 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
1444 echo "<td class='text data' colspan='$datacols_esc'";
1445 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1447 $cell_count +
= $datacols;
1451 echo generate_display_field($frow, $currvalue);
1457 function display_layout_tabs($formtype, $result1, $result2='') {
1458 global $item_count, $cell_count, $last_group, $CPR;
1460 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1461 "WHERE form_id = ? AND uor > 0 " .
1462 "ORDER BY group_name, seq", array($formtype) );
1465 while ($frow = sqlFetchArray($fres)) {
1466 $this_group = $frow['group_name'];
1467 $group_name = substr($this_group, 1);
1469 <li
<?php
echo $first ?
'class="current"' : '' ?
>>
1470 <a href
="/play/javascript-tabbed-navigation/" id
="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES
)."?>">
1471 <?php
echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
); ?
></a
>
1478 function display_layout_tabs_data($formtype, $result1, $result2='') {
1479 global $item_count, $cell_count, $last_group, $CPR;
1481 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1482 "WHERE form_id = ? AND uor > 0 " .
1483 "ORDER BY group_name, seq", array($formtype));
1486 while ($frow = sqlFetchArray($fres)) {
1487 $this_group = $frow['group_name'];
1488 $titlecols = $frow['titlecols'];
1489 $datacols = $frow['datacols'];
1490 $data_type = $frow['data_type'];
1491 $field_id = $frow['field_id'];
1492 $list_id = $frow['list_id'];
1495 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1496 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1497 "ORDER BY seq", array($formtype, $this_group) );
1500 <div
class="tab <?php echo $first ? 'current' : '' ?>">
1501 <table border
='0' cellpadding
='0'>
1504 while ($group_fields = sqlFetchArray($group_fields_query)) {
1506 $titlecols = $group_fields['titlecols'];
1507 $datacols = $group_fields['datacols'];
1508 $data_type = $group_fields['data_type'];
1509 $field_id = $group_fields['field_id'];
1510 $list_id = $group_fields['list_id'];
1513 if ($formtype == 'DEM') {
1514 if ($GLOBALS['athletic_team']) {
1515 // Skip fitness level and return-to-play date because those appear
1516 // in a special display/update form on this page.
1517 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
1519 if (strpos($field_id, 'em_') === 0) {
1520 // Skip employer related fields, if it's disabled.
1521 if ($GLOBALS['omit_employers']) continue;
1522 $tmp = substr($field_id, 3);
1523 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1526 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1530 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1533 // Handle a data category (group) change.
1534 if (strcmp($this_group, $last_group) != 0) {
1535 $group_name = substr($this_group, 1);
1536 // totally skip generating the employer category, if it's disabled.
1537 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1538 $last_group = $this_group;
1541 // Handle starting of a new row.
1542 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
1547 if ($item_count == 0 && $titlecols == 0) {
1551 // Handle starting of a new label cell.
1552 if ($titlecols > 0) {
1554 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
1555 echo "<td class='label' colspan='$titlecols_esc' ";
1557 $cell_count +
= $titlecols;
1561 // Added 5-09 by BM - Translate label if applicable
1562 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES
); else echo " ";
1564 // Handle starting of a new data cell.
1565 if ($datacols > 0) {
1567 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
1568 echo "<td class='text data' colspan='$datacols_esc'";
1570 $cell_count +
= $datacols;
1574 echo generate_display_field($group_fields, $currvalue);
1589 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1590 global $item_count, $cell_count, $last_group, $CPR;
1592 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1593 "WHERE form_id = ? AND uor > 0 " .
1594 "ORDER BY group_name, seq", array($formtype) );
1597 while ($frow = sqlFetchArray($fres)) {
1598 $this_group = $frow['group_name'];
1599 $group_name = substr($this_group, 1);
1600 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES
);
1601 $titlecols = $frow['titlecols'];
1602 $datacols = $frow['datacols'];
1603 $data_type = $frow['data_type'];
1604 $field_id = $frow['field_id'];
1605 $list_id = $frow['list_id'];
1608 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1609 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1610 "ORDER BY seq", array($formtype,$this_group) );
1613 <div
class="tab <?php echo $first ? 'current' : '' ?>" id
="tab_<?php echo $group_name_esc?>" >
1614 <table border
='0' cellpadding
='0'>
1617 while ($group_fields = sqlFetchArray($group_fields_query)) {
1619 $titlecols = $group_fields['titlecols'];
1620 $datacols = $group_fields['datacols'];
1621 $data_type = $group_fields['data_type'];
1622 $field_id = $group_fields['field_id'];
1623 $list_id = $group_fields['list_id'];
1626 if ($formtype == 'DEM') {
1627 if ($GLOBALS['athletic_team']) {
1628 // Skip fitness level and return-to-play date because those appear
1629 // in a special display/update form on this page.
1630 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
1632 if (strpos($field_id, 'em_') === 0) {
1633 // Skip employer related fields, if it's disabled.
1634 if ($GLOBALS['omit_employers']) continue;
1635 $tmp = substr($field_id, 3);
1636 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1639 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1643 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1646 // Handle a data category (group) change.
1647 if (strcmp($this_group, $last_group) != 0) {
1648 $group_name = substr($this_group, 1);
1649 // totally skip generating the employer category, if it's disabled.
1650 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1651 $last_group = $this_group;
1654 // Handle starting of a new row.
1655 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
1660 if ($item_count == 0 && $titlecols == 0) {
1664 // Handle starting of a new label cell.
1665 if ($titlecols > 0) {
1667 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
1668 echo "<td class='label' colspan='$titlecols_esc' ";
1670 $cell_count +
= $titlecols;
1674 // Added 5-09 by BM - Translate label if applicable
1675 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES
).":"); else echo " ";
1677 // Handle starting of a new data cell.
1678 if ($datacols > 0) {
1680 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
1681 echo "<td class='text data' colspan='$datacols_esc'";
1683 $cell_count +
= $datacols;
1687 echo generate_form_field($group_fields, $currvalue);
1701 // From the currently posted HTML form, this gets the value of the
1702 // field corresponding to the provided layout_options table row.
1704 function get_layout_form_value($frow, $maxlength=255) {
1705 // Bring in $sanitize_all_escapes variable, which will decide
1706 // the variable escaping method.
1707 global $sanitize_all_escapes;
1709 $data_type = $frow['data_type'];
1710 $field_id = $frow['field_id'];
1712 if (isset($_POST["form_$field_id"])) {
1713 if ($data_type == 21) {
1714 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1715 // must be concatenated into a |-separated string.
1716 foreach ($_POST["form_$field_id"] as $key => $val) {
1717 if (strlen($value)) $value .= '|';
1721 else if ($data_type == 22) {
1722 // $_POST["form_$field_id"] is an array of text fields to be imploded
1723 // into "key:value|key:value|...".
1724 foreach ($_POST["form_$field_id"] as $key => $val) {
1725 $val = str_replace('|', ' ', $val);
1726 if (strlen($value)) $value .= '|';
1727 $value .= "$key:$val";
1730 else if ($data_type == 23) {
1731 // $_POST["form_$field_id"] is an array of text fields with companion
1732 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1733 foreach ($_POST["form_$field_id"] as $key => $val) {
1734 $restype = $_POST["radio_{$field_id}"][$key];
1735 if (empty($restype)) $restype = '0';
1736 $val = str_replace('|', ' ', $val);
1737 if (strlen($value)) $value .= '|';
1738 $value .= "$key:$restype:$val";
1741 else if ($data_type == 25) {
1742 // $_POST["form_$field_id"] is an array of text fields with companion
1743 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1744 foreach ($_POST["form_$field_id"] as $key => $val) {
1745 $restype = empty($_POST["check_{$field_id}"][$key]) ?
'0' : '1';
1746 $val = str_replace('|', ' ', $val);
1747 if (strlen($value)) $value .= '|';
1748 $value .= "$key:$restype:$val";
1751 else if ($data_type == 28) {
1752 // $_POST["form_$field_id"] is an date text fields with companion
1753 // radio buttons to be imploded into "notes|type|date".
1754 $restype = $_POST["radio_{$field_id}"];
1755 if (empty($restype)) $restype = '0';
1756 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1757 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1758 $value = "$resnote|$restype|$resdate";
1761 $value = $_POST["form_$field_id"];
1765 // Better to die than to silently truncate data!
1766 if ($maxlength && $data_type != 3 && strlen($value) > $maxlength)
1767 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES
) .
1768 ":<br /> <br />".htmlspecialchars( $value, ENT_NOQUOTES
));
1770 // Make sure the return value is quote-safe.
1771 if ($sanitize_all_escapes) {
1772 //escapes already removed and using binding/placemarks in sql calls
1773 // so only need to trim value
1774 return trim($value);
1777 //need to explicitly prepare value
1778 return formTrim($value);
1782 // Generate JavaScript validation logic for the required fields.
1784 function generate_layout_validation($form_id) {
1785 $fres = sqlStatement("SELECT * FROM layout_options " .
1786 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
1787 "ORDER BY group_name, seq", array($form_id) );
1789 while ($frow = sqlFetchArray($fres)) {
1790 if ($frow['uor'] < 2) continue;
1791 $data_type = $frow['data_type'];
1792 $field_id = $frow['field_id'];
1793 $fldtitle = $frow['title'];
1794 if (!$fldtitle) $fldtitle = $frow['description'];
1795 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES
);
1796 switch($data_type) {
1804 " if (f.$fldname.selectedIndex <= 0) {\n" .
1805 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1806 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
1809 case 27: // radio buttons
1812 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
1813 " if (i >= f.$fldname.length) {\n" .
1814 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
1822 " if (trimlen(f.$fldname.value) == 0) {\n" .
1823 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1824 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
1825 " $('#" . $fldname . "').attr('style','background:red'); \n" .
1826 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
1828 " $('#" . $fldname . "').attr('style',''); " .
1829 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
1837 * DROPDOWN FOR FACILITIES
1839 * build a dropdown with all facilities
1841 * @param string $selected - name of the currently selected facility
1842 * use '0' for "unspecified facility"
1843 * use '' for "All facilities" (the default)
1844 * @param string $name - the name/id for select form (defaults to "form_facility")
1845 * @param boolean $allow_unspecified - include an option for "unspecified" facility
1847 * @return void - just echo the html encoded string
1849 * Note: This should become a data-type at some point, according to Brady
1851 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true) {
1852 $have_selected = false;
1853 $query = "SELECT id, name FROM facility ORDER BY name";
1854 $fres = sqlStatement($query);
1856 $name = htmlspecialchars($name, ENT_QUOTES
);
1857 echo " <select name=\"$name\">\n";
1860 $option_selected_attr = '';
1861 if ($selected == '') {
1862 $option_selected_attr = ' selected="selected"';
1863 $have_selected = true;
1865 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES
);
1866 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1868 while ($frow = sqlFetchArray($fres)) {
1869 $facility_id = $frow['id'];
1870 $option_value = htmlspecialchars($facility_id, ENT_QUOTES
);
1871 $option_selected_attr = '';
1872 if ($selected == $facility_id) {
1873 $option_selected_attr = ' selected="selected"';
1874 $have_selected = true;
1876 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES
);
1877 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1880 if ($allow_unspecified) {
1881 $option_value = '0';
1882 $option_selected_attr = '';
1883 if ( $selected == '0' ) {
1884 $option_selected_attr = ' selected="selected"';
1885 $have_selected = true;
1887 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
1888 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1891 if (!$have_selected) {
1892 $option_value = htmlspecialchars($selected, ENT_QUOTES
);
1893 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES
);
1894 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES
);
1895 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
1897 echo " </select>\n";