2 // Copyright (C) 2007-2009 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>";
78 function generate_form_field($frow, $currvalue) {
79 global $rootdir, $date_init;
81 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
83 $data_type = $frow['data_type'];
84 $field_id = $frow['field_id'];
85 $list_id = $frow['list_id'];
86 // escaped variables to use in html
87 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES
);
88 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES
);
90 // Added 5-09 by BM - Translate description if applicable
91 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
93 // added 5-2009 by BM to allow modification of the 'empty' text title field.
94 // Can pass $frow['empty_title'] with this variable, otherwise
95 // will default to 'Unassigned'.
96 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
97 // if make $frow['empty_title'] equal to 'SKIP'
99 if (isset($frow['empty_title'])) {
100 if ($frow['empty_title'] == "SKIP") {
101 //do not display an 'empty' choice
103 $empty_title = "Unassigned";
106 $empty_title = $frow['empty_title'];
110 $empty_title = "Unassigned";
113 // generic single-selection list
114 if ($data_type == 1) {
115 echo generate_select_list("form_$field_id", $list_id, $currvalue,
116 $description, $showEmpty ?
$empty_title : '');
120 else if ($data_type == 2) {
121 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
122 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
123 echo "<input type='text'" .
124 " name='form_$field_id_esc'" .
125 " id='form_$field_id_esc'" .
126 " size='$fldlength'" .
127 " maxlength='$maxlength'" .
128 " title='$description'" .
129 " value='$currescaped'";
130 if (strpos($frow['edit_options'], 'C') !== FALSE)
131 echo " onchange='capitalizeMe(this)'";
132 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES
);
133 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
134 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
135 echo " onblur='maskblur(this,\"$tmp\")'";
140 // long or multi-line text field
141 else if ($data_type == 3) {
142 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
143 $textRows = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
145 " name='form_$field_id_esc'" .
146 " id='form_$field_id_esc'" .
147 " title='$description'" .
148 " cols='$textCols'" .
149 " rows='$textRows'>" .
150 $currescaped . "</textarea>";
154 else if ($data_type == 4) {
155 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
156 " value='$currescaped'" .
157 " title='$description'" .
158 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
159 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
160 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
161 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES
) . "' />";
162 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
165 // provider list, local providers only
166 else if ($data_type == 10) {
167 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
168 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
169 "AND authorized = 1 " .
170 "ORDER BY lname, fname");
171 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
172 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
173 while ($urow = sqlFetchArray($ures)) {
174 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES
);
175 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES
);
176 echo "<option value='$optionId'";
177 if ($urow['id'] == $currvalue) echo " selected";
178 echo ">$uname</option>";
183 // provider list, including address book entries with an NPI number
184 else if ($data_type == 11) {
185 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
186 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
187 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
188 "ORDER BY lname, fname");
189 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
190 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
191 while ($urow = sqlFetchArray($ures)) {
192 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES
);
193 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES
);
194 echo "<option value='$optionId'";
195 if ($urow['id'] == $currvalue) echo " selected";
196 echo ">$uname</option>";
202 else if ($data_type == 12) {
203 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
204 echo "<option value='0'></option>";
205 $pres = get_pharmacies();
206 while ($prow = sqlFetchArray($pres)) {
208 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
209 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
210 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
211 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES
);
212 echo "<option value='$optionValue'";
213 if ($currvalue == $key) echo " selected";
214 echo ">$optionLabel</option>";
220 else if ($data_type == 13) {
221 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
222 echo "<option value=''> </option>";
223 $squads = acl_get_squads();
225 foreach ($squads as $key => $value) {
226 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
227 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES
);
228 echo "<option value='$optionValue'";
229 if ($currvalue == $key) echo " selected";
230 echo ">$optionLabel</option>\n";
236 // Address book, preferring organization name if it exists and is not in
237 // parentheses, and excluding local users who are not providers.
238 // Supports "referred to" practitioners and facilities.
239 // Alternatively the letter O in edit_options means that abook_type
240 // must begin with "ord_", indicating types used with the procedure
242 // Alternatively the letter V in edit_options means that abook_type
243 // must be "vendor", indicating the Vendor type.
244 else if ($data_type == 14) {
245 if (strpos($frow['edit_options'], 'O') !== FALSE)
246 $tmp = "abook_type LIKE 'ord\\_%'";
247 else if (strpos($frow['edit_options'], 'V') !== FALSE)
248 $tmp = "abook_type LIKE 'vendor%'";
250 $tmp = "( username = '' OR authorized = 1 )";
251 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
252 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
254 "ORDER BY organization, lname, fname");
255 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
256 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
257 while ($urow = sqlFetchArray($ures)) {
258 $uname = $urow['organization'];
259 if (empty($uname) ||
substr($uname, 0, 1) == '(') {
260 $uname = $urow['lname'];
261 if ($urow['fname']) $uname .= ", " . $urow['fname'];
263 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES
);
264 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES
);
265 echo "<option value='$optionValue'";
266 $title = $urow['username'] ?
xl('Local') : xl('External');
267 $optionTitle = htmlspecialchars( $title, ENT_QUOTES
);
268 echo " title='$optionTitle'";
269 if ($urow['id'] == $currvalue) echo " selected";
270 echo ">$optionLabel</option>";
275 // a billing code (only one of these allowed!)
276 else if ($data_type == 15) {
277 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
278 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
279 echo "<input type='text'" .
280 " name='form_$field_id_esc'" .
281 " id='form_related_code'" .
282 " size='$fldlength'" .
283 " maxlength='$maxlength'" .
284 " title='$description'" .
285 " value='$currescaped'" .
286 " onclick='sel_related()' readonly" .
290 // a set of labeled checkboxes
291 else if ($data_type == 21) {
292 // In this special case, fld_length is the number of columns generated.
293 $cols = max(1, $frow['fld_length']);
294 $avalue = explode('|', $currvalue);
295 $lres = sqlStatement("SELECT * FROM list_options " .
296 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
297 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
298 $tdpct = (int) (100 / $cols);
299 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
300 $option_id = $lrow['option_id'];
301 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
302 // if ($count) echo "<br />";
303 if ($count %
$cols == 0) {
304 if ($count) echo "</tr>";
307 echo "<td width='$tdpct%'>";
308 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]' id='form_{$field_id_esc}[$option_id_esc]' value='1'";
309 if (in_array($option_id, $avalue)) echo " checked";
311 // Added 5-09 by BM - Translate label if applicable
312 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
318 if ($count > $cols) {
319 // Add some space after multiple rows of checkboxes.
320 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
321 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
327 // a set of labeled text input fields
328 else if ($data_type == 22) {
329 $tmp = explode('|', $currvalue);
331 foreach ($tmp as $value) {
332 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
333 $avalue[$matches[1]] = $matches[2];
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'>";
339 while ($lrow = sqlFetchArray($lres)) {
340 $option_id = $lrow['option_id'];
341 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
342 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
343 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
345 // Added 5-09 by BM - Translate label if applicable
346 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
347 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
348 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
349 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
350 echo "<td><input type='text'" .
351 " name='form_{$field_id_esc}[$option_id_esc]'" .
352 " id='form_{$field_id_esc}[$option_id_esc]'" .
353 " size='$fldlength'" .
354 " maxlength='$maxlength'" .
355 " value='$optionValue'";
356 echo " /></td></tr>";
361 // a set of exam results; 3 radio buttons and a text field:
362 else if ($data_type == 23) {
363 $tmp = explode('|', $currvalue);
365 foreach ($tmp as $value) {
366 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
367 $avalue[$matches[1]] = $matches[2];
370 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
371 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
372 $lres = sqlStatement("SELECT * FROM list_options " .
373 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
374 echo "<table cellpadding='0' cellspacing='0'>";
375 echo "<tr><td> </td><td class='bold'>" .
376 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
377 " </td><td class='bold'>" .
378 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
379 "<td class='bold'>" .
380 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
381 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
382 while ($lrow = sqlFetchArray($lres)) {
383 $option_id = $lrow['option_id'];
384 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
385 $restype = substr($avalue[$option_id], 0, 1);
386 $resnote = substr($avalue[$option_id], 2);
388 // Added 5-09 by BM - Translate label if applicable
389 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
391 for ($i = 0; $i < 3; ++
$i) {
392 $inputValue = htmlspecialchars( $i, ENT_QUOTES
);
393 echo "<td><input type='radio'" .
394 " name='radio_{$field_id_esc}[$option_id_esc]'" .
395 " id='radio_{$field_id_esc}[$option_id_esc]'" .
396 " value='$inputValue'";
397 if ($restype === "$i") echo " checked";
400 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
401 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
402 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
403 echo "<td><input type='text'" .
404 " name='form_{$field_id_esc}[$option_id_esc]'" .
405 " id='form_{$field_id_esc}[$option_id_esc]'" .
406 " size='$fldlength'" .
407 " maxlength='$maxlength'" .
408 " value='$resnote' /></td>";
414 // the list of active allergies for the current patient
415 // this is read-only!
416 else if ($data_type == 24) {
417 $query = "SELECT title, comments FROM lists WHERE " .
418 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
420 // echo "<!-- $query -->\n"; // debugging
421 $lres = sqlStatement($query, array($GLOBALS['pid']));
423 while ($lrow = sqlFetchArray($lres)) {
424 if ($count++
) echo "<br />";
425 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES
);
426 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES
) . ')';
430 // a set of labeled checkboxes, each with a text field:
431 else if ($data_type == 25) {
432 $tmp = explode('|', $currvalue);
434 foreach ($tmp as $value) {
435 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
436 $avalue[$matches[1]] = $matches[2];
439 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
440 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
441 $lres = sqlStatement("SELECT * FROM list_options " .
442 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
443 echo "<table cellpadding='0' cellspacing='0'>";
444 while ($lrow = sqlFetchArray($lres)) {
445 $option_id = $lrow['option_id'];
446 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
447 $restype = substr($avalue[$option_id], 0, 1);
448 $resnote = substr($avalue[$option_id], 2);
450 // Added 5-09 by BM - Translate label if applicable
451 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
453 $option_id = htmlspecialchars( $option_id, ENT_QUOTES
);
454 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]' id='check_{$field_id_esc}[$option_id_esc]' value='1'";
455 if ($restype) echo " checked";
456 echo " /> </td>";
457 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
458 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
459 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
460 echo "<td><input type='text'" .
461 " name='form_{$field_id_esc}[$option_id_esc]'" .
462 " id='form_{$field_id_esc}[$option_id_esc]'" .
463 " size='$fldlength'" .
464 " maxlength='$maxlength'" .
465 " value='$resnote' /></td>";
471 // single-selection list with ability to add to it
472 else if ($data_type == 26) {
473 echo "<select class='addtolistclass_$list_id_esc' name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
474 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES
) . "</option>";
475 $lres = sqlStatement("SELECT * FROM list_options " .
476 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
477 $got_selected = FALSE;
478 while ($lrow = sqlFetchArray($lres)) {
479 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES
);
480 echo "<option value='$optionValue'";
481 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
482 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
485 $got_selected = TRUE;
487 // Added 5-09 by BM - Translate label if applicable
488 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . "</option>\n";
490 if (!$got_selected && strlen($currvalue) > 0) {
491 echo "<option value='$currescaped' selected>* $currescaped *</option>";
493 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES
);
494 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
495 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
500 // show the add button if user has access to correct list
501 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES
);
502 $outputAddButton = "<input type='button' id='addtolistid_".$list_id_esc."' fieldid='form_".$field_id_esc."' class='addtolist' value='$inputValue'>";
503 if (aco_exist('lists', $list_id)) {
504 // a specific aco exist for this list, so ensure access
505 if (acl_check('lists', $list_id)) echo $outputAddButton;
508 // no specific aco exist for this list, so check for access to 'default' list
509 if (acl_check('lists', 'default')) echo $outputAddButton;
513 // a set of labeled radio buttons
514 else if ($data_type == 27) {
515 // In this special case, fld_length is the number of columns generated.
516 $cols = max(1, $frow['fld_length']);
517 $lres = sqlStatement("SELECT * FROM list_options " .
518 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
519 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
520 $tdpct = (int) (100 / $cols);
521 $got_selected = FALSE;
522 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
523 $option_id = $lrow['option_id'];
524 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
525 if ($count %
$cols == 0) {
526 if ($count) echo "</tr>";
529 echo "<td width='$tdpct%'>";
530 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]' value='$option_id_esc'";
531 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
532 (strlen($currvalue) > 0 && $option_id == $currvalue))
535 $got_selected = TRUE;
537 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
542 if ($count > $cols) {
543 // Add some space after multiple rows of radio buttons.
544 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
545 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
549 if (!$got_selected && strlen($currvalue) > 0) {
550 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES
);
551 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
552 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
556 // special case for history of lifestyle status; 3 radio buttons and a date text field:
557 else if ($data_type == 28) {
558 $tmp = explode('|', $currvalue);
559 switch(count($tmp)) {
572 $resdate = $restype = "";
575 $restype = $resdate = $resnote = "";
578 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
579 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
581 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
582 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
583 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
584 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
585 echo "<table cellpadding='0' cellspacing='0'>";
588 echo "<td><input type='text'" .
589 " name='form_$field_id_esc'" .
590 " id='form_$field_id_esc'" .
591 " size='$fldlength'" .
592 " maxlength='$maxlength'" .
593 " value='$resnote' /> </td>";
594 echo "<td class='bold'> ".htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
596 echo "<td><input type='radio'" .
597 " name='radio_{$field_id_esc}'" .
598 " id='radio_{$field_id_esc}[current]'" .
599 " value='current".$field_id_esc."'";
600 if ($restype == "current".$field_id) echo " checked";
601 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES
)." </td>";
603 echo "<td><input type='radio'" .
604 " name='radio_{$field_id_esc}'" .
605 " id='radio_{$field_id_esc}[quit]'" .
606 " value='quit".$field_id_esc."'";
607 if ($restype == "quit".$field_id) echo " checked";
608 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES
)." </td>";
610 echo "<td><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
611 " value='$resdate'" .
612 " title='$description'" .
613 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
614 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
615 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
616 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES
) . "' /> </td>";
617 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
619 echo "<td><input type='radio'" .
620 " name='radio_{$field_id_esc}'" .
621 " id='radio_{$field_id_esc}[never]'" .
622 " value='never".$field_id_esc."'";
623 if ($restype == "never".$field_id) echo " checked";
624 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES
)." </td>";
626 echo "<td><input type='radio'" .
627 " name='radio_{$field_id}'" .
628 " id='radio_{$field_id}[not_applicable]'" .
629 " value='not_applicable".$field_id."'";
630 if ($restype == "not_applicable".$field_id) echo " checked";
631 echo " />".htmlspecialchars( xl('N/A'), ENT_QUOTES
)." </td>";
638 function generate_print_field($frow, $currvalue) {
639 global $rootdir, $date_init;
641 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
643 $data_type = $frow['data_type'];
644 $field_id = $frow['field_id'];
645 $list_id = $frow['list_id'];
646 $fld_length = $frow['fld_length'];
648 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
650 // Can pass $frow['empty_title'] with this variable, otherwise
651 // will default to 'Unassigned'.
652 // If it is 'SKIP' then an empty text title is completely skipped.
654 if (isset($frow['empty_title'])) {
655 if ($frow['empty_title'] == "SKIP") {
656 //do not display an 'empty' choice
658 $empty_title = "Unassigned";
661 $empty_title = $frow['empty_title'];
665 $empty_title = "Unassigned";
668 // generic single-selection list
669 if ($data_type == 1 ||
$data_type == 26) {
670 if (empty($fld_length)) {
671 if ($list_id == 'titles') {
679 $lrow = sqlQuery("SELECT title FROM list_options " .
680 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
681 $tmp = xl_list_label($lrow['title']);
682 if (empty($tmp)) $tmp = "($currvalue)";
684 /*****************************************************************
685 echo "<input type='text'" .
686 " size='$fld_length'" .
690 *****************************************************************/
691 if ($tmp === '') { $tmp = ' '; }
692 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
697 else if ($data_type == 2 ||
$data_type == 15) {
698 /*****************************************************************
699 echo "<input type='text'" .
700 " size='$fld_length'" .
701 " value='$currescaped'" .
704 *****************************************************************/
705 if ($currescaped === '') $currescaped = ' ';
709 // long or multi-line text field
710 else if ($data_type == 3) {
711 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES
);
712 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
714 " cols='$fldlength'" .
715 " rows='$maxlength'>" .
716 $currescaped . "</textarea>";
720 else if ($data_type == 4) {
721 /*****************************************************************
722 echo "<input type='text' size='10'" .
723 " value='$currescaped'" .
724 " title='$description'" .
727 *****************************************************************/
728 if ($currvalue === '') { $tmp = oeFormatShortDate(' '); }
729 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES
); }
734 else if ($data_type == 10 ||
$data_type == 11) {
737 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
738 "WHERE id = ?", array($currvalue) );
739 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
740 if (empty($tmp)) $tmp = "($currvalue)";
742 /*****************************************************************
743 echo "<input type='text'" .
744 " size='$fld_length'" .
748 *****************************************************************/
749 if ($tmp === '') { $tmp = ' '; }
750 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
755 else if ($data_type == 12) {
758 $pres = get_pharmacies();
759 while ($prow = sqlFetchArray($pres)) {
761 if ($currvalue == $key) {
762 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
763 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
764 $prow['line1'] . ' / ' . $prow['city'];
767 if (empty($tmp)) $tmp = "($currvalue)";
769 /*****************************************************************
770 echo "<input type='text'" .
771 " size='$fld_length'" .
775 *****************************************************************/
776 if ($tmp === '') { $tmp = ' '; }
777 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
782 else if ($data_type == 13) {
785 $squads = acl_get_squads();
787 foreach ($squads as $key => $value) {
788 if ($currvalue == $key) {
793 if (empty($tmp)) $tmp = "($currvalue)";
795 /*****************************************************************
796 echo "<input type='text'" .
797 " size='$fld_length'" .
801 *****************************************************************/
802 if ($tmp === '') { $tmp = ' '; }
803 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
808 else if ($data_type == 14) {
811 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
812 "WHERE id = ?", array($currvalue) );
813 $uname = $urow['lname'];
814 if ($urow['fname']) $uname .= ", " . $urow['fname'];
816 if (empty($tmp)) $tmp = "($currvalue)";
818 /*****************************************************************
819 echo "<input type='text'" .
820 " size='$fld_length'" .
824 *****************************************************************/
825 if ($tmp === '') { $tmp = ' '; }
826 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
830 // a set of labeled checkboxes
831 else if ($data_type == 21) {
832 // In this special case, fld_length is the number of columns generated.
833 $cols = max(1, $fld_length);
834 $avalue = explode('|', $currvalue);
835 $lres = sqlStatement("SELECT * FROM list_options " .
836 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
837 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
838 $tdpct = (int) (100 / $cols);
839 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
840 $option_id = $lrow['option_id'];
841 if ($count %
$cols == 0) {
842 if ($count) echo "</tr>";
845 echo "<td width='$tdpct%'>";
846 echo "<input type='checkbox'";
847 if (in_array($option_id, $avalue)) echo " checked";
848 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
853 if ($count > $cols) {
854 // Add some space after multiple rows of checkboxes.
855 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
856 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
862 // a set of labeled text input fields
863 else if ($data_type == 22) {
864 $tmp = explode('|', $currvalue);
866 foreach ($tmp as $value) {
867 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
868 $avalue[$matches[1]] = $matches[2];
871 $lres = sqlStatement("SELECT * FROM list_options " .
872 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
873 echo "<table cellpadding='0' cellspacing='0'>";
874 while ($lrow = sqlFetchArray($lres)) {
875 $option_id = $lrow['option_id'];
876 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
877 $fldlength = empty($fld_length) ?
20 : $fld_length;
878 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
879 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
880 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
881 echo "<td><input type='text'" .
882 " size='$fldlength'" .
883 " value='$inputValue'" .
890 // a set of exam results; 3 radio buttons and a text field:
891 else if ($data_type == 23) {
892 $tmp = explode('|', $currvalue);
894 foreach ($tmp as $value) {
895 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
896 $avalue[$matches[1]] = $matches[2];
899 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
900 $fldlength = empty($fld_length) ?
20 : $fld_length;
901 $lres = sqlStatement("SELECT * FROM list_options " .
902 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
903 echo "<table cellpadding='0' cellspacing='0'>";
904 echo "<tr><td> </td><td class='bold'>" .
905 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
906 " </td><td class='bold'>" .
907 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
908 "<td class='bold'>" .
909 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
910 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
911 while ($lrow = sqlFetchArray($lres)) {
912 $option_id = $lrow['option_id'];
913 $restype = substr($avalue[$option_id], 0, 1);
914 $resnote = substr($avalue[$option_id], 2);
915 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
916 for ($i = 0; $i < 3; ++
$i) {
917 echo "<td><input type='radio'";
918 if ($restype === "$i") echo " checked";
921 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
922 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
923 echo "<td><input type='text'" .
924 " size='$fldlength'" .
925 " value='$resnote'" .
926 " class='under' /></td>" .
932 // the list of active allergies for the current patient
933 // this is read-only!
934 else if ($data_type == 24) {
935 $query = "SELECT title, comments FROM lists WHERE " .
936 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
938 $lres = sqlStatement($query, array($GLOBALS['pid']) );
940 while ($lrow = sqlFetchArray($lres)) {
941 if ($count++
) echo "<br />";
942 echo htmlspecialchars( $lrow['title'], ENT_QUOTES
);
943 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES
);
947 // a set of labeled checkboxes, each with a text field:
948 else if ($data_type == 25) {
949 $tmp = explode('|', $currvalue);
951 foreach ($tmp as $value) {
952 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
953 $avalue[$matches[1]] = $matches[2];
956 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
957 $fldlength = empty($fld_length) ?
20 : $fld_length;
958 $lres = sqlStatement("SELECT * FROM list_options " .
959 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
960 echo "<table cellpadding='0' cellspacing='0'>";
961 while ($lrow = sqlFetchArray($lres)) {
962 $option_id = $lrow['option_id'];
963 $restype = substr($avalue[$option_id], 0, 1);
964 $resnote = substr($avalue[$option_id], 2);
965 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
966 echo "<td><input type='checkbox'";
967 if ($restype) echo " checked";
968 echo " /> </td>";
969 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
970 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
971 echo "<td><input type='text'" .
972 " size='$fldlength'" .
973 " value='$resnote'" .
981 // a set of labeled radio buttons
982 else if ($data_type == 27) {
983 // In this special case, fld_length is the number of columns generated.
984 $cols = max(1, $frow['fld_length']);
985 $lres = sqlStatement("SELECT * FROM list_options " .
986 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
987 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
988 $tdpct = (int) (100 / $cols);
989 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
990 $option_id = $lrow['option_id'];
991 if ($count %
$cols == 0) {
992 if ($count) echo "</tr>";
995 echo "<td width='$tdpct%'>";
996 echo "<input type='radio'";
997 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
998 (strlen($currvalue) > 0 && $option_id == $currvalue))
1002 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
1007 if ($count > $cols) {
1008 // Add some space after multiple rows of radio buttons.
1009 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
1010 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1016 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1017 else if ($data_type == 28) {
1018 $tmp = explode('|', $currvalue);
1019 switch(count($tmp)) {
1032 $resdate = $restype = "";
1035 $restype = $resdate = $resnote = "";
1038 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
1039 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
1040 echo "<table cellpadding='0' cellspacing='0'>";
1042 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1043 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1044 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
1045 echo "<td><input type='text'" .
1046 " size='$fldlength'" .
1048 " value='$resnote' /></td>";
1049 echo "<td class='bold'> ".
1050 htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
1051 echo "<td><input type='radio'";
1052 if ($restype == "current".$field_id) echo " checked";
1053 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES
)." </td>";
1055 echo "<td><input type='radio'";
1056 if ($restype == "current".$field_id) echo " checked";
1057 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES
)." </td>";
1059 echo "<td><input type='text' size='6'" .
1060 " value='$resdate'" .
1064 echo "<td><input type='radio'";
1065 if ($restype == "current".$field_id) echo " checked";
1066 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES
)."</td>";
1068 echo "<td><input type='radio'";
1069 if ($restype == "not_applicable".$field_id) echo " checked";
1070 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES
)." </td>";
1077 function generate_display_field($frow, $currvalue) {
1078 $data_type = $frow['data_type'];
1079 $field_id = $frow['field_id'];
1080 $list_id = $frow['list_id'];
1083 // generic selection list or the generic selection list with add on the fly
1084 // feature, or radio buttons
1085 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 27) {
1086 $lrow = sqlQuery("SELECT title FROM list_options " .
1087 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1088 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1091 // simple text field
1092 else if ($data_type == 2) {
1093 $s = htmlspecialchars($currvalue,ENT_NOQUOTES
);
1096 // long or multi-line text field
1097 else if ($data_type == 3) {
1098 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES
));
1102 else if ($data_type == 4) {
1103 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES
);
1107 else if ($data_type == 10 ||
$data_type == 11) {
1108 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1109 "WHERE id = ?", array($currvalue) );
1110 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES
);
1114 else if ($data_type == 12) {
1115 $pres = get_pharmacies();
1116 while ($prow = sqlFetchArray($pres)) {
1118 if ($currvalue == $key) {
1119 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1120 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1121 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES
);
1127 else if ($data_type == 13) {
1128 $squads = acl_get_squads();
1130 foreach ($squads as $key => $value) {
1131 if ($currvalue == $key) {
1132 $s .= htmlspecialchars($value[3],ENT_NOQUOTES
);
1139 else if ($data_type == 14) {
1140 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1141 "WHERE id = ?", array($currvalue));
1142 $uname = $urow['lname'];
1143 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1144 $s = htmlspecialchars($uname,ENT_NOQUOTES
);
1148 else if ($data_type == 15) {
1149 $s = htmlspecialchars($currvalue,ENT_NOQUOTES
);
1152 // a set of labeled checkboxes
1153 else if ($data_type == 21) {
1154 $avalue = explode('|', $currvalue);
1155 $lres = sqlStatement("SELECT * FROM list_options " .
1156 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1158 while ($lrow = sqlFetchArray($lres)) {
1159 $option_id = $lrow['option_id'];
1160 if (in_array($option_id, $avalue)) {
1161 if ($count++
) $s .= "<br />";
1163 // Added 5-09 by BM - Translate label if applicable
1164 $s .= htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1170 // a set of labeled text input fields
1171 else if ($data_type == 22) {
1172 $tmp = explode('|', $currvalue);
1174 foreach ($tmp as $value) {
1175 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1176 $avalue[$matches[1]] = $matches[2];
1179 $lres = sqlStatement("SELECT * FROM list_options " .
1180 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1181 $s .= "<table cellpadding='0' cellspacing='0'>";
1182 while ($lrow = sqlFetchArray($lres)) {
1183 $option_id = $lrow['option_id'];
1184 if (empty($avalue[$option_id])) continue;
1186 // Added 5-09 by BM - Translate label if applicable
1187 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . ": </td>";
1189 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES
) . "</td></tr>";
1194 // a set of exam results; 3 radio buttons and a text field:
1195 else if ($data_type == 23) {
1196 $tmp = explode('|', $currvalue);
1198 foreach ($tmp as $value) {
1199 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1200 $avalue[$matches[1]] = $matches[2];
1203 $lres = sqlStatement("SELECT * FROM list_options " .
1204 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1205 $s .= "<table cellpadding='0' cellspacing='0'>";
1206 while ($lrow = sqlFetchArray($lres)) {
1207 $option_id = $lrow['option_id'];
1208 $restype = substr($avalue[$option_id], 0, 1);
1209 $resnote = substr($avalue[$option_id], 2);
1210 if (empty($restype) && empty($resnote)) continue;
1212 // Added 5-09 by BM - Translate label if applicable
1213 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1215 $restype = ($restype == '1') ?
xl('Normal') : (($restype == '2') ?
xl('Abnormal') : xl('N/A'));
1216 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1217 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1218 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . " </td>";
1219 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td>";
1225 // the list of active allergies for the current patient
1226 else if ($data_type == 24) {
1227 $query = "SELECT title, comments FROM lists WHERE " .
1228 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1230 // echo "<!-- $query -->\n"; // debugging
1231 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1233 while ($lrow = sqlFetchArray($lres)) {
1234 if ($count++
) $s .= "<br />";
1235 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES
);
1236 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES
) . ')';
1240 // a set of labeled checkboxes, each with a text field:
1241 else if ($data_type == 25) {
1242 $tmp = explode('|', $currvalue);
1244 foreach ($tmp as $value) {
1245 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1246 $avalue[$matches[1]] = $matches[2];
1249 $lres = sqlStatement("SELECT * FROM list_options " .
1250 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1251 $s .= "<table cellpadding='0' cellspacing='0'>";
1252 while ($lrow = sqlFetchArray($lres)) {
1253 $option_id = $lrow['option_id'];
1254 $restype = substr($avalue[$option_id], 0, 1);
1255 $resnote = substr($avalue[$option_id], 2);
1256 if (empty($restype) && empty($resnote)) continue;
1258 // Added 5-09 by BM - Translate label if applicable
1259 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1261 $restype = $restype ?
xl('Yes') : xl('No');
1262 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . "</td></tr>";
1263 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td></tr>";
1269 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1270 else if ($data_type == 28) {
1271 $tmp = explode('|', $currvalue);
1272 switch(count($tmp)) {
1285 $resdate = $restype = "";
1288 $restype = $resdate = $resnote = "";
1291 $s .= "<table cellpadding='0' cellspacing='0'>";
1295 if ($restype == "current".$field_id) $res = xl('Current');
1296 if ($restype == "quit".$field_id) $res = xl('Quit');
1297 if ($restype == "never".$field_id) $res = xl('Never');
1298 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1299 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1300 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1301 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . " </td>";
1302 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES
) . "</b>: " . htmlspecialchars($res,ENT_NOQUOTES
) . " </td>";
1303 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES
) . " </td>";
1311 $CPR = 4; // cells per row of generic data
1316 function disp_end_cell() {
1317 global $item_count, $cell_count;
1318 if ($item_count > 0) {
1324 function disp_end_row() {
1325 global $cell_count, $CPR;
1327 if ($cell_count > 0) {
1328 for (; $cell_count < $CPR; ++
$cell_count) echo "<td></td>";
1334 function disp_end_group() {
1336 if (strlen($last_group) > 0) {
1341 function display_layout_rows($formtype, $result1, $result2='') {
1342 global $item_count, $cell_count, $last_group, $CPR;
1344 $fres = sqlStatement("SELECT * FROM layout_options " .
1345 "WHERE form_id = ? AND uor > 0 " .
1346 "ORDER BY group_name, seq", array($formtype) );
1348 while ($frow = sqlFetchArray($fres)) {
1349 $this_group = $frow['group_name'];
1350 $titlecols = $frow['titlecols'];
1351 $datacols = $frow['datacols'];
1352 $data_type = $frow['data_type'];
1353 $field_id = $frow['field_id'];
1354 $list_id = $frow['list_id'];
1357 if ($formtype == 'DEM') {
1358 if ($GLOBALS['athletic_team']) {
1359 // Skip fitness level and return-to-play date because those appear
1360 // in a special display/update form on this page.
1361 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
1363 if (strpos($field_id, 'em_') === 0) {
1364 // Skip employer related fields, if it's disabled.
1365 if ($GLOBALS['omit_employers']) continue;
1366 $tmp = substr($field_id, 3);
1367 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1370 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1374 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1377 // Handle a data category (group) change.
1378 if (strcmp($this_group, $last_group) != 0) {
1379 $group_name = substr($this_group, 1);
1380 // totally skip generating the employer category, if it's disabled.
1381 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1383 $last_group = $this_group;
1386 // Handle starting of a new row.
1387 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
1391 echo "<td class='groupname'>";
1392 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1393 //echo "<font color='#008800'>$group_name</font>";
1395 // Added 5-09 by BM - Translate label if applicable
1396 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
);
1400 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1401 echo "<td valign='top'> ";
1406 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1408 // Handle starting of a new label cell.
1409 if ($titlecols > 0) {
1411 //echo "<td class='label' colspan='$titlecols' valign='top'";
1412 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
1413 echo "<td class='label' colspan='$titlecols_esc' ";
1414 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1416 $cell_count +
= $titlecols;
1420 // Added 5-09 by BM - Translate label if applicable
1421 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES
); else echo " ";
1423 // Handle starting of a new data cell.
1424 if ($datacols > 0) {
1426 //echo "<td class='text data' colspan='$datacols' valign='top'";
1427 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
1428 echo "<td class='text data' colspan='$datacols_esc'";
1429 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1431 $cell_count +
= $datacols;
1435 echo generate_display_field($frow, $currvalue);
1441 function display_layout_tabs($formtype, $result1, $result2='') {
1442 global $item_count, $cell_count, $last_group, $CPR;
1444 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1445 "WHERE form_id = ? AND uor > 0 " .
1446 "ORDER BY group_name, seq", array($formtype) );
1449 while ($frow = sqlFetchArray($fres)) {
1450 $this_group = $frow['group_name'];
1451 $group_name = substr($this_group, 1);
1453 <li
<?php
echo $first ?
'class="current"' : '' ?
>>
1454 <a href
="/play/javascript-tabbed-navigation/" id
="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES
)."?>">
1455 <?php
echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
); ?
></a
>
1462 function display_layout_tabs_data($formtype, $result1, $result2='') {
1463 global $item_count, $cell_count, $last_group, $CPR;
1465 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1466 "WHERE form_id = ? AND uor > 0 " .
1467 "ORDER BY group_name, seq", array($formtype));
1470 while ($frow = sqlFetchArray($fres)) {
1471 $this_group = $frow['group_name'];
1472 $titlecols = $frow['titlecols'];
1473 $datacols = $frow['datacols'];
1474 $data_type = $frow['data_type'];
1475 $field_id = $frow['field_id'];
1476 $list_id = $frow['list_id'];
1479 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1480 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1481 "ORDER BY seq", array($formtype, $this_group) );
1484 <div
class="tab <?php echo $first ? 'current' : '' ?>">
1485 <table border
='0' cellpadding
='0'>
1488 while ($group_fields = sqlFetchArray($group_fields_query)) {
1490 $titlecols = $group_fields['titlecols'];
1491 $datacols = $group_fields['datacols'];
1492 $data_type = $group_fields['data_type'];
1493 $field_id = $group_fields['field_id'];
1494 $list_id = $group_fields['list_id'];
1497 if ($formtype == 'DEM') {
1498 if ($GLOBALS['athletic_team']) {
1499 // Skip fitness level and return-to-play date because those appear
1500 // in a special display/update form on this page.
1501 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
1503 if (strpos($field_id, 'em_') === 0) {
1504 // Skip employer related fields, if it's disabled.
1505 if ($GLOBALS['omit_employers']) continue;
1506 $tmp = substr($field_id, 3);
1507 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1510 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1514 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1517 // Handle a data category (group) change.
1518 if (strcmp($this_group, $last_group) != 0) {
1519 $group_name = substr($this_group, 1);
1520 // totally skip generating the employer category, if it's disabled.
1521 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1522 $last_group = $this_group;
1525 // Handle starting of a new row.
1526 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
1531 if ($item_count == 0 && $titlecols == 0) {
1535 // Handle starting of a new label cell.
1536 if ($titlecols > 0) {
1538 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
1539 echo "<td class='label' colspan='$titlecols_esc' ";
1541 $cell_count +
= $titlecols;
1545 // Added 5-09 by BM - Translate label if applicable
1546 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES
); else echo " ";
1548 // Handle starting of a new data cell.
1549 if ($datacols > 0) {
1551 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
1552 echo "<td class='text data' colspan='$datacols_esc'";
1554 $cell_count +
= $datacols;
1558 echo generate_display_field($group_fields, $currvalue);
1573 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1574 global $item_count, $cell_count, $last_group, $CPR;
1576 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1577 "WHERE form_id = ? AND uor > 0 " .
1578 "ORDER BY group_name, seq", array($formtype) );
1581 while ($frow = sqlFetchArray($fres)) {
1582 $this_group = $frow['group_name'];
1583 $group_name = substr($this_group, 1);
1584 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES
);
1585 $titlecols = $frow['titlecols'];
1586 $datacols = $frow['datacols'];
1587 $data_type = $frow['data_type'];
1588 $field_id = $frow['field_id'];
1589 $list_id = $frow['list_id'];
1592 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1593 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1594 "ORDER BY seq", array($formtype,$this_group) );
1597 <div
class="tab <?php echo $first ? 'current' : '' ?>" id
="tab_<?php echo $group_name_esc?>" >
1598 <table border
='0' cellpadding
='0'>
1601 while ($group_fields = sqlFetchArray($group_fields_query)) {
1603 $titlecols = $group_fields['titlecols'];
1604 $datacols = $group_fields['datacols'];
1605 $data_type = $group_fields['data_type'];
1606 $field_id = $group_fields['field_id'];
1607 $list_id = $group_fields['list_id'];
1610 if ($formtype == 'DEM') {
1611 if ($GLOBALS['athletic_team']) {
1612 // Skip fitness level and return-to-play date because those appear
1613 // in a special display/update form on this page.
1614 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
1616 if (strpos($field_id, 'em_') === 0) {
1617 // Skip employer related fields, if it's disabled.
1618 if ($GLOBALS['omit_employers']) continue;
1619 $tmp = substr($field_id, 3);
1620 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1623 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1627 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1630 // Handle a data category (group) change.
1631 if (strcmp($this_group, $last_group) != 0) {
1632 $group_name = substr($this_group, 1);
1633 // totally skip generating the employer category, if it's disabled.
1634 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1635 $last_group = $this_group;
1638 // Handle starting of a new row.
1639 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
1644 if ($item_count == 0 && $titlecols == 0) {
1648 // Handle starting of a new label cell.
1649 if ($titlecols > 0) {
1651 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
1652 echo "<td class='label' colspan='$titlecols_esc' ";
1654 $cell_count +
= $titlecols;
1658 // Added 5-09 by BM - Translate label if applicable
1659 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES
).":"); else echo " ";
1661 // Handle starting of a new data cell.
1662 if ($datacols > 0) {
1664 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
1665 echo "<td class='text data' colspan='$datacols_esc'";
1667 $cell_count +
= $datacols;
1671 echo generate_form_field($group_fields, $currvalue);
1685 // From the currently posted HTML form, this gets the value of the
1686 // field corresponding to the provided layout_options table row.
1688 function get_layout_form_value($frow, $maxlength=255) {
1689 // Bring in $sanitize_all_escapes variable, which will decide
1690 // the variable escaping method.
1691 global $sanitize_all_escapes;
1693 $data_type = $frow['data_type'];
1694 $field_id = $frow['field_id'];
1696 if (isset($_POST["form_$field_id"])) {
1697 if ($data_type == 21) {
1698 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1699 // must be concatenated into a |-separated string.
1700 foreach ($_POST["form_$field_id"] as $key => $val) {
1701 if (strlen($value)) $value .= '|';
1705 else if ($data_type == 22) {
1706 // $_POST["form_$field_id"] is an array of text fields to be imploded
1707 // into "key:value|key:value|...".
1708 foreach ($_POST["form_$field_id"] as $key => $val) {
1709 $val = str_replace('|', ' ', $val);
1710 if (strlen($value)) $value .= '|';
1711 $value .= "$key:$val";
1714 else if ($data_type == 23) {
1715 // $_POST["form_$field_id"] is an array of text fields with companion
1716 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1717 foreach ($_POST["form_$field_id"] as $key => $val) {
1718 $restype = $_POST["radio_{$field_id}"][$key];
1719 if (empty($restype)) $restype = '0';
1720 $val = str_replace('|', ' ', $val);
1721 if (strlen($value)) $value .= '|';
1722 $value .= "$key:$restype:$val";
1725 else if ($data_type == 25) {
1726 // $_POST["form_$field_id"] is an array of text fields with companion
1727 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1728 foreach ($_POST["form_$field_id"] as $key => $val) {
1729 $restype = empty($_POST["check_{$field_id}"][$key]) ?
'0' : '1';
1730 $val = str_replace('|', ' ', $val);
1731 if (strlen($value)) $value .= '|';
1732 $value .= "$key:$restype:$val";
1735 else if ($data_type == 28) {
1736 // $_POST["form_$field_id"] is an date text fields with companion
1737 // radio buttons to be imploded into "notes|type|date".
1738 $restype = $_POST["radio_{$field_id}"];
1739 if (empty($restype)) $restype = '0';
1740 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1741 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1742 $value = "$resnote|$restype|$resdate";
1745 $value = $_POST["form_$field_id"];
1749 // Better to die than to silently truncate data!
1750 if ($maxlength && $data_type != 3 && strlen($value) > $maxlength)
1751 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES
) .
1752 ":<br /> <br />".htmlspecialchars( $value, ENT_NOQUOTES
));
1754 // Make sure the return value is quote-safe.
1755 if ($sanitize_all_escapes) {
1756 //escapes already removed and using binding/placemarks in sql calls
1757 // so only need to trim value
1758 return trim($value);
1761 //need to explicitly prepare value
1762 return formTrim($value);
1766 // Generate JavaScript validation logic for the required fields.
1768 function generate_layout_validation($form_id) {
1769 $fres = sqlStatement("SELECT * FROM layout_options " .
1770 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
1771 "ORDER BY group_name, seq", array($form_id) );
1773 while ($frow = sqlFetchArray($fres)) {
1774 if ($frow['uor'] < 2) continue;
1775 $data_type = $frow['data_type'];
1776 $field_id = $frow['field_id'];
1777 $fldtitle = $frow['title'];
1778 if (!$fldtitle) $fldtitle = $frow['description'];
1779 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES
);
1780 switch($data_type) {
1788 " if (f.$fldname.selectedIndex <= 0) {\n" .
1789 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1790 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
1793 case 27: // radio buttons
1796 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
1797 " if (i >= f.$fldname.length) {\n" .
1798 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
1806 " if (trimlen(f.$fldname.value) == 0) {\n" .
1807 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1808 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
1809 " $('#" . $fldname . "').attr('style','background:red'); \n" .
1810 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
1812 " $('#" . $fldname . "').attr('style',''); " .
1813 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
1821 * DROPDOWN FOR FACILITIES
1823 * build a dropdown with all facilities
1825 * @param string $selected - name of the currently selected facility
1826 * use '0' for "unspecified facility"
1827 * use '' for "All facilities" (the default)
1828 * @param string $name - the name/id for select form (defaults to "form_facility")
1829 * @param boolean $allow_unspecified - include an option for "unspecified" facility
1831 * @return void - just echo the html encoded string
1833 * Note: This should become a data-type at some point, according to Brady
1835 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true) {
1836 $have_selected = false;
1837 $query = "SELECT id, name FROM facility ORDER BY name";
1838 $fres = sqlStatement($query);
1840 $name = htmlspecialchars($name, ENT_QUOTES
);
1841 echo " <select name=\"$name\">\n";
1844 $option_selected_attr = '';
1845 if ($selected == '') {
1846 $option_selected_attr = ' selected="selected"';
1847 $have_selected = true;
1849 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES
);
1850 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1852 while ($frow = sqlFetchArray($fres)) {
1853 $facility_id = $frow['id'];
1854 $option_value = htmlspecialchars($facility_id, ENT_QUOTES
);
1855 $option_selected_attr = '';
1856 if ($selected == $facility_id) {
1857 $option_selected_attr = ' selected="selected"';
1858 $have_selected = true;
1860 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES
);
1861 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1864 if ($allow_unspecified) {
1865 $option_value = '0';
1866 $option_selected_attr = '';
1867 if ( $selected == '0' ) {
1868 $option_selected_attr = ' selected="selected"';
1869 $have_selected = true;
1871 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
1872 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1875 if (!$have_selected) {
1876 $option_value = htmlspecialchars($selected, ENT_QUOTES
);
1877 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES
);
1878 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES
);
1879 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
1881 echo " </select>\n";