Minor fixes to links and comments
[openemr.git] / library / options.inc.php
blobf2e55417795bf02e18cfbe6524ebf03126901522
1 <?php
2 // Copyright (C) 2007-2010 Rod Roark <rod@sunsetsystems.com>
3 // Copyright © 2010 by Andrew Moore <amoore@cpan.org>
4 // Copyright © 2010 by "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // Functions for managing the lists and layouts
13 // Note: there are translation wrappers for the lists and layout labels
14 // at library/translation.inc.php. The functions are titled
15 // xl_list_label() and xl_layout_label() and are controlled by the
16 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
17 // flags in globals.php
19 require_once("formdata.inc.php");
20 require_once("formatting.inc.php");
22 $date_init = "";
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 " .
29 "AND p.type = 2 " .
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='')
38 $s = '';
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))
56 $s .= " selected";
57 $got_selected = TRUE;
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>";
65 $s .= "</select>";
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>";
70 else {
71 $s .= "</select>";
73 return $s;
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'
99 $showEmpty = true;
100 if (isset($frow['empty_title'])) {
101 if ($frow['empty_title'] == "SKIP") {
102 //do not display an 'empty' choice
103 $showEmpty = false;
104 $empty_title = "Unassigned";
106 else {
107 $empty_title = $frow['empty_title'];
110 else {
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 : '');
120 // simple text field
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\")'";
138 echo " />";
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);
145 echo "<textarea" .
146 " name='form_$field_id_esc'" .
147 " id='form_$field_id_esc'" .
148 " title='$description'" .
149 " cols='$textCols'" .
150 " rows='$textRows'>" .
151 $currescaped . "</textarea>";
154 // date
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>";
181 echo "</select>";
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>";
199 echo "</select>";
202 // pharmacy list
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)) {
208 $key = $prow['id'];
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>";
217 echo "</select>";
220 // squads
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=''>&nbsp;</option>";
224 $squads = acl_get_squads();
225 if ($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";
234 echo "</select>";
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
242 // ordering system.
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%'";
250 else
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%' ) " .
254 "AND $tmp " .
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>";
273 echo "</select>";
276 // a billing code
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" .
288 " />";
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>";
306 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);
315 echo "</td>";
317 if ($count) {
318 echo "</tr>";
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>";
325 echo "</table>";
328 // a set of labeled text input fields
329 else if ($data_type == 22) {
330 $tmp = explode('|', $currvalue);
331 $avalue = array();
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) . "&nbsp;</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>";
359 echo "</table>";
362 // a set of exam results; 3 radio buttons and a text field:
363 else if ($data_type == 23) {
364 $tmp = explode('|', $currvalue);
365 $avalue = array();
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>&nbsp;</td><td class='bold'>" .
377 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
378 "&nbsp;</td><td class='bold'>" .
379 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
380 "<td class='bold'>" .
381 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</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) . "&nbsp;</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";
399 echo " /></td>";
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>";
410 echo "</tr>";
412 echo "</table>";
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 " .
420 "ORDER BY begdate";
421 // echo "<!-- $query -->\n"; // debugging
422 $lres = sqlStatement($query, array($GLOBALS['pid']));
423 $count = 0;
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);
434 $avalue = array();
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) . "&nbsp;</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 " />&nbsp;</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>";
467 echo "</tr>";
469 echo "</table>";
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))
485 echo " selected";
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>";
493 echo "</select>";
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>";
498 else {
499 echo "</select>";
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;
508 else {
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>";
528 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))
535 echo " checked";
536 $got_selected = TRUE;
538 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
539 echo "</td>";
541 if ($count) {
542 echo "</tr>";
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>";
549 echo "</table>";
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)) {
561 case "3": {
562 $resnote = $tmp[0];
563 $restype = $tmp[1];
564 $resdate = $tmp[2];
565 } break;
566 case "2": {
567 $resnote = $tmp[0];
568 $restype = $tmp[1];
569 $resdate = "";
570 } break;
571 case "1": {
572 $resnote = $tmp[0];
573 $resdate = $restype = "";
574 } break;
575 default: {
576 $restype = $resdate = $resnote = "";
577 } break;
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'>";
587 echo "<tr>";
588 // input text
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' />&nbsp;</td>";
595 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
596 // current
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)."&nbsp;</td>";
603 // quit
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)."&nbsp;</td>";
610 // quit date
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) . "' />&nbsp;</td>";
618 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
619 // never
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)."&nbsp;</td>";
626 // Not Applicable
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)."&nbsp;</td>";
633 echo "</tr>";
634 echo "</table>";
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.
659 $showEmpty = true;
660 if (isset($frow['empty_title'])) {
661 if ($frow['empty_title'] == "SKIP") {
662 //do not display an 'empty' choice
663 $showEmpty = false;
664 $empty_title = "Unassigned";
666 else {
667 $empty_title = $frow['empty_title'];
670 else {
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') {
678 $fld_length = 3;
679 } else {
680 $fld_length = 10;
683 $tmp = '';
684 if ($currvalue) {
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'" .
693 " value='$tmp'" .
694 " class='under'" .
695 " />";
696 *****************************************************************/
697 if ($tmp === '') { $tmp = '&nbsp;'; }
698 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
699 echo $tmp;
702 // simple text field
703 else if ($data_type == 2 || $data_type == 15) {
704 /*****************************************************************
705 echo "<input type='text'" .
706 " size='$fld_length'" .
707 " value='$currescaped'" .
708 " class='under'" .
709 " />";
710 *****************************************************************/
711 if ($currescaped === '') $currescaped = '&nbsp;';
712 echo $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);
719 echo "<textarea" .
720 " cols='$fldlength'" .
721 " rows='$maxlength'>" .
722 $currescaped . "</textarea>";
725 // date
726 else if ($data_type == 4) {
727 /*****************************************************************
728 echo "<input type='text' size='10'" .
729 " value='$currescaped'" .
730 " title='$description'" .
731 " class='under'" .
732 " />";
733 *****************************************************************/
734 if ($currvalue === '') { $tmp = oeFormatShortDate('&nbsp;'); }
735 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES); }
736 echo $tmp;
739 // provider list
740 else if ($data_type == 10 || $data_type == 11) {
741 $tmp = '';
742 if ($currvalue) {
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'" .
751 " value='$tmp'" .
752 " class='under'" .
753 " />";
754 *****************************************************************/
755 if ($tmp === '') { $tmp = '&nbsp;'; }
756 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
757 echo $tmp;
760 // pharmacy list
761 else if ($data_type == 12) {
762 $tmp = '';
763 if ($currvalue) {
764 $pres = get_pharmacies();
765 while ($prow = sqlFetchArray($pres)) {
766 $key = $prow['id'];
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'" .
778 " value='$tmp'" .
779 " class='under'" .
780 " />";
781 *****************************************************************/
782 if ($tmp === '') { $tmp = '&nbsp;'; }
783 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
784 echo $tmp;
787 // squads
788 else if ($data_type == 13) {
789 $tmp = '';
790 if ($currvalue) {
791 $squads = acl_get_squads();
792 if ($squads) {
793 foreach ($squads as $key => $value) {
794 if ($currvalue == $key) {
795 $tmp = $value[3];
799 if (empty($tmp)) $tmp = "($currvalue)";
801 /*****************************************************************
802 echo "<input type='text'" .
803 " size='$fld_length'" .
804 " value='$tmp'" .
805 " class='under'" .
806 " />";
807 *****************************************************************/
808 if ($tmp === '') { $tmp = '&nbsp;'; }
809 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
810 echo $tmp;
813 // Address book.
814 else if ($data_type == 14) {
815 $tmp = '';
816 if ($currvalue) {
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'];
821 $tmp = $uname;
822 if (empty($tmp)) $tmp = "($currvalue)";
824 /*****************************************************************
825 echo "<input type='text'" .
826 " size='$fld_length'" .
827 " value='$tmp'" .
828 " class='under'" .
829 " />";
830 *****************************************************************/
831 if ($tmp === '') { $tmp = '&nbsp;'; }
832 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
833 echo $tmp;
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>";
849 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);
855 echo "</td>";
857 if ($count) {
858 echo "</tr>";
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>";
865 echo "</table>";
868 // a set of labeled text input fields
869 else if ($data_type == 22) {
870 $tmp = explode('|', $currvalue);
871 $avalue = array();
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) . "&nbsp;</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'" .
890 " class='under'" .
891 " /></td></tr>";
893 echo "</table>";
896 // a set of exam results; 3 radio buttons and a text field:
897 else if ($data_type == 23) {
898 $tmp = explode('|', $currvalue);
899 $avalue = array();
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>&nbsp;</td><td class='bold'>" .
911 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
912 "&nbsp;</td><td class='bold'>" .
913 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
914 "<td class='bold'>" .
915 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</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) . "&nbsp;</td>";
922 for ($i = 0; $i < 3; ++$i) {
923 echo "<td><input type='radio'";
924 if ($restype === "$i") echo " checked";
925 echo " /></td>";
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>" .
933 "</tr>";
935 echo "</table>";
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 " .
943 "ORDER BY begdate";
944 $lres = sqlStatement($query, array($GLOBALS['pid']) );
945 $count = 0;
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);
956 $avalue = array();
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) . "&nbsp;</td>";
972 echo "<td><input type='checkbox'";
973 if ($restype) echo " checked";
974 echo " />&nbsp;</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'" .
980 " class='under'" .
981 " /></td>" .
982 "</tr>";
984 echo "</table>";
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>";
999 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))
1006 echo " checked";
1008 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1009 echo "</td>";
1011 if ($count) {
1012 echo "</tr>";
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>";
1019 echo "</table>";
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)) {
1026 case "3": {
1027 $resnote = $tmp[0];
1028 $restype = $tmp[1];
1029 $resdate = $tmp[2];
1030 } break;
1031 case "2": {
1032 $resnote = $tmp[0];
1033 $restype = $tmp[1];
1034 $resdate = "";
1035 } break;
1036 case "1": {
1037 $resnote = $tmp[0];
1038 $resdate = $restype = "";
1039 } break;
1040 default: {
1041 $restype = $resdate = $resnote = "";
1042 } break;
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'>";
1047 echo "<tr>";
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'" .
1053 " class='under'" .
1054 " value='$resnote' /></td>";
1055 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;".
1056 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1057 echo "<td><input type='radio'";
1058 if ($restype == "current".$field_id) echo " checked";
1059 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1061 echo "<td><input type='radio'";
1062 if ($restype == "current".$field_id) echo " checked";
1063 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1065 echo "<td><input type='text' size='6'" .
1066 " value='$resdate'" .
1067 " class='under'" .
1068 " /></td>";
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)."&nbsp;</td>";
1077 echo "</tr>";
1078 echo "</table>";
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'];
1092 $s = '';
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));
1112 // date
1113 else if ($data_type == 4) {
1114 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES);
1117 // provider
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);
1124 // pharmacy list
1125 else if ($data_type == 12) {
1126 $pres = get_pharmacies();
1127 while ($prow = sqlFetchArray($pres)) {
1128 $key = $prow['id'];
1129 if ($currvalue == $key) {
1130 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1131 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1132 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1137 // squads
1138 else if ($data_type == 13) {
1139 $squads = acl_get_squads();
1140 if ($squads) {
1141 foreach ($squads as $key => $value) {
1142 if ($currvalue == $key) {
1143 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1149 // address book
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);
1158 // billing code
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) );
1168 $count = 0;
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);
1184 $avalue = array();
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) . ":&nbsp;</td>";
1200 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1202 $s .= "</table>";
1205 // a set of exam results; 3 radio buttons and a text field:
1206 else if ($data_type == 23) {
1207 $tmp = explode('|', $currvalue);
1208 $avalue = array();
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) . "&nbsp;</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) . "&nbsp;</td>";
1230 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1231 $s .= "</tr>";
1233 $s .= "</table>";
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 " .
1240 "ORDER BY begdate";
1241 // echo "<!-- $query -->\n"; // debugging
1242 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1243 $count = 0;
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);
1254 $avalue = array();
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) . "&nbsp;</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>";
1275 $s .= "</tr>";
1277 $s .= "</table>";
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)) {
1284 case "3": {
1285 $resnote = $tmp[0];
1286 $restype = $tmp[1];
1287 $resdate = $tmp[2];
1288 } break;
1289 case "2": {
1290 $resnote = $tmp[0];
1291 $restype = $tmp[1];
1292 $resdate = "";
1293 } break;
1294 case "1": {
1295 $resnote = $tmp[0];
1296 $resdate = $restype = "";
1297 } break;
1298 default: {
1299 $restype = $resdate = $resnote = "";
1300 } break;
1302 $s .= "<table cellpadding='0' cellspacing='0'>";
1304 $s .= "<tr>";
1305 $res = "";
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) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1313 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1314 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1315 $s .= "</tr>";
1316 $s .= "</table>";
1319 // static text. read-only, of course.
1320 else if ($data_type == 31) {
1321 $s .= nl2br($frow['description']);
1324 return $s;
1327 $CPR = 4; // cells per row of generic data
1328 $last_group = '';
1329 $cell_count = 0;
1330 $item_count = 0;
1332 function disp_end_cell() {
1333 global $item_count, $cell_count;
1334 if ($item_count > 0) {
1335 echo "</td>";
1336 $item_count = 0;
1340 function disp_end_row() {
1341 global $cell_count, $CPR;
1342 disp_end_cell();
1343 if ($cell_count > 0) {
1344 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
1345 echo "</tr>\n";
1346 $cell_count = 0;
1350 function disp_end_group() {
1351 global $last_group;
1352 if (strlen($last_group) > 0) {
1353 disp_end_row();
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'];
1371 $currvalue = '';
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];
1385 else {
1386 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1389 else {
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;
1398 disp_end_group();
1399 $last_group = $this_group;
1402 // Handle starting of a new row.
1403 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1404 disp_end_row();
1405 echo "<tr>";
1406 if ($group_name) {
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);
1414 $group_name = '';
1415 } else {
1416 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1417 echo "<td valign='top'>&nbsp;";
1419 echo "</td>";
1422 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1424 // Handle starting of a new label cell.
1425 if ($titlecols > 0) {
1426 disp_end_cell();
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'";
1431 echo ">";
1432 $cell_count += $titlecols;
1434 ++$item_count;
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 "&nbsp;";
1439 // Handle starting of a new data cell.
1440 if ($datacols > 0) {
1441 disp_end_cell();
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'";
1446 echo ">";
1447 $cell_count += $datacols;
1450 ++$item_count;
1451 echo generate_display_field($frow, $currvalue);
1454 disp_end_group();
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) );
1464 $first = true;
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>
1472 </li>
1473 <?php
1474 $first = false;
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));
1485 $first = true;
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'];
1493 $currvalue = '';
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'>
1503 <?php
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'];
1511 $currvalue = '';
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];
1525 else {
1526 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1529 else {
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) {
1543 disp_end_row();
1544 echo "<tr>";
1547 if ($item_count == 0 && $titlecols == 0) {
1548 $titlecols = 1;
1551 // Handle starting of a new label cell.
1552 if ($titlecols > 0) {
1553 disp_end_cell();
1554 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1555 echo "<td class='label' colspan='$titlecols_esc' ";
1556 echo ">";
1557 $cell_count += $titlecols;
1559 ++$item_count;
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 "&nbsp;";
1564 // Handle starting of a new data cell.
1565 if ($datacols > 0) {
1566 disp_end_cell();
1567 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1568 echo "<td class='text data' colspan='$datacols_esc'";
1569 echo ">";
1570 $cell_count += $datacols;
1573 ++$item_count;
1574 echo generate_display_field($group_fields, $currvalue);
1578 </table>
1579 </div>
1581 <?php
1583 $first = false;
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) );
1596 $first = true;
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'];
1606 $currvalue = '';
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'>
1616 <?php
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'];
1624 $currvalue = '';
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];
1638 else {
1639 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1642 else {
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) {
1656 disp_end_row();
1657 echo "<tr>";
1660 if ($item_count == 0 && $titlecols == 0) {
1661 $titlecols = 1;
1664 // Handle starting of a new label cell.
1665 if ($titlecols > 0) {
1666 disp_end_cell();
1667 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1668 echo "<td class='label' colspan='$titlecols_esc' ";
1669 echo ">";
1670 $cell_count += $titlecols;
1672 ++$item_count;
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 "&nbsp;";
1677 // Handle starting of a new data cell.
1678 if ($datacols > 0) {
1679 disp_end_cell();
1680 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1681 echo "<td class='text data' colspan='$datacols_esc'";
1682 echo ">";
1683 $cell_count += $datacols;
1686 ++$item_count;
1687 echo generate_form_field($group_fields, $currvalue);
1691 </table>
1692 </div>
1694 <?php
1696 $first = false;
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'];
1711 $value = '';
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 .= '|';
1718 $value .= $key;
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";
1760 else {
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 />&nbsp;<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);
1776 else {
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) {
1797 case 1:
1798 case 11:
1799 case 12:
1800 case 13:
1801 case 14:
1802 case 26:
1803 echo
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" .
1807 " }\n";
1808 break;
1809 case 27: // radio buttons
1810 echo
1811 " var i = 0;\n" .
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" .
1815 " }\n";
1816 break;
1817 case 2:
1818 case 3:
1819 case 4:
1820 case 15:
1821 echo
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" .
1827 " } else { " .
1828 " $('#" . $fldname . "').attr('style',''); " .
1829 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
1830 " } \n";
1831 break;
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
1846 * defaults to true
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";
1859 $option_value = '';
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";