Merge branch 'master' of git://github.com/openemr/openemr
[openemr.git] / library / options.inc.php
blob3034766fc0052b1eb0ec1e5f20d3276dbebc7484
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");
21 require_once("user.inc");
23 $date_init = "";
25 function get_pharmacies() {
26 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
27 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
28 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
29 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
30 "AND p.type = 2 " .
31 "ORDER BY name, area_code, prefix, number");
34 // Function to generate a drop-list.
36 function generate_select_list($tag_name, $list_id, $currvalue, $title,
37 $empty_name=' ', $class='', $onchange='')
39 $s = '';
40 $tag_name_esc = htmlspecialchars( $tag_name, ENT_QUOTES);
41 $s .= "<select name='$tag_name_esc' id='$tag_name_esc'";
42 if ($class) $s .= " class='$class'";
43 if ($onchange) $s .= " onchange='$onchange'";
44 $selectTitle = htmlspecialchars( $title, ENT_QUOTES);
45 $s .= " title='$selectTitle'>";
46 $selectEmptyName = htmlspecialchars( xl($empty_name), ENT_NOQUOTES);
47 if ($empty_name) $s .= "<option value=''>" . $selectEmptyName . "</option>";
48 $lres = sqlStatement("SELECT * FROM list_options " .
49 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
50 $got_selected = FALSE;
51 while ($lrow = sqlFetchArray($lres)) {
52 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
53 $s .= "<option value='$optionValue'";
54 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
55 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
57 $s .= " selected";
58 $got_selected = TRUE;
60 $optionLabel = htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
61 $s .= ">$optionLabel</option>\n";
63 if (!$got_selected && strlen($currvalue) > 0) {
64 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
65 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
66 $s .= "</select>";
67 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_QUOTES);
68 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
69 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
71 else {
72 $s .= "</select>";
74 return $s;
77 // $frow is a row from the layout_options table.
78 // $currvalue is the current value, if any, of the associated item.
80 function generate_form_field($frow, $currvalue) {
81 global $rootdir, $date_init;
83 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
85 $data_type = $frow['data_type'];
86 $field_id = $frow['field_id'];
87 $list_id = $frow['list_id'];
88 // escaped variables to use in html
89 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
90 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
92 // Added 5-09 by BM - Translate description if applicable
93 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
95 // added 5-2009 by BM to allow modification of the 'empty' text title field.
96 // Can pass $frow['empty_title'] with this variable, otherwise
97 // will default to 'Unassigned'.
98 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
99 // if make $frow['empty_title'] equal to 'SKIP'
100 $showEmpty = true;
101 if (isset($frow['empty_title'])) {
102 if ($frow['empty_title'] == "SKIP") {
103 //do not display an 'empty' choice
104 $showEmpty = false;
105 $empty_title = "Unassigned";
107 else {
108 $empty_title = $frow['empty_title'];
111 else {
112 $empty_title = "Unassigned";
115 // generic single-selection list
116 if ($data_type == 1) {
117 echo generate_select_list("form_$field_id", $list_id, $currvalue,
118 $description, $showEmpty ? $empty_title : '');
121 // simple text field
122 else if ($data_type == 2) {
123 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
124 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
125 echo "<input type='text'" .
126 " name='form_$field_id_esc'" .
127 " id='form_$field_id_esc'" .
128 " size='$fldlength'" .
129 " maxlength='$maxlength'" .
130 " title='$description'" .
131 " value='$currescaped'";
132 if (strpos($frow['edit_options'], 'C') !== FALSE)
133 echo " onchange='capitalizeMe(this)'";
134 else if (strpos($frow['edit_options'], 'U') !== FALSE)
135 echo " onchange='this.value = this.value.toUpperCase()'";
136 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
137 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
138 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
139 echo " onblur='maskblur(this,\"$tmp\")'";
141 echo " />";
144 // long or multi-line text field
145 else if ($data_type == 3) {
146 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
147 $textRows = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
148 echo "<textarea" .
149 " name='form_$field_id_esc'" .
150 " id='form_$field_id_esc'" .
151 " title='$description'" .
152 " cols='$textCols'" .
153 " rows='$textRows'>" .
154 $currescaped . "</textarea>";
157 // date
158 else if ($data_type == 4) {
159 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
160 " value='$currescaped'" .
161 " title='$description'" .
162 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
163 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
164 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
165 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
166 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
169 // provider list, local providers only
170 else if ($data_type == 10) {
171 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
172 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
173 "AND authorized = 1 " .
174 "ORDER BY lname, fname");
175 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
176 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
177 while ($urow = sqlFetchArray($ures)) {
178 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
179 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
180 echo "<option value='$optionId'";
181 if ($urow['id'] == $currvalue) echo " selected";
182 echo ">$uname</option>";
184 echo "</select>";
187 // provider list, including address book entries with an NPI number
188 else if ($data_type == 11) {
189 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
190 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
191 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
192 "ORDER BY lname, fname");
193 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
194 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
195 while ($urow = sqlFetchArray($ures)) {
196 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
197 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
198 echo "<option value='$optionId'";
199 if ($urow['id'] == $currvalue) echo " selected";
200 echo ">$uname</option>";
202 echo "</select>";
205 // pharmacy list
206 else if ($data_type == 12) {
207 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
208 echo "<option value='0'></option>";
209 $pres = get_pharmacies();
210 while ($prow = sqlFetchArray($pres)) {
211 $key = $prow['id'];
212 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
213 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
214 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
215 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
216 echo "<option value='$optionValue'";
217 if ($currvalue == $key) echo " selected";
218 echo ">$optionLabel</option>";
220 echo "</select>";
223 // squads
224 else if ($data_type == 13) {
225 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
226 echo "<option value=''>&nbsp;</option>";
227 $squads = acl_get_squads();
228 if ($squads) {
229 foreach ($squads as $key => $value) {
230 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
231 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
232 echo "<option value='$optionValue'";
233 if ($currvalue == $key) echo " selected";
234 echo ">$optionLabel</option>\n";
237 echo "</select>";
240 // Address book, preferring organization name if it exists and is not in
241 // parentheses, and excluding local users who are not providers.
242 // Supports "referred to" practitioners and facilities.
243 // Alternatively the letter O in edit_options means that abook_type
244 // must begin with "ord_", indicating types used with the procedure
245 // ordering system.
246 // Alternatively the letter V in edit_options means that abook_type
247 // must be "vendor", indicating the Vendor type.
248 else if ($data_type == 14) {
249 if (strpos($frow['edit_options'], 'O') !== FALSE)
250 $tmp = "abook_type LIKE 'ord\\_%'";
251 else if (strpos($frow['edit_options'], 'V') !== FALSE)
252 $tmp = "abook_type LIKE 'vendor%'";
253 else
254 $tmp = "( username = '' OR authorized = 1 )";
255 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
256 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
257 "AND $tmp " .
258 "ORDER BY organization, lname, fname");
259 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
260 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
261 while ($urow = sqlFetchArray($ures)) {
262 $uname = $urow['organization'];
263 if (empty($uname) || substr($uname, 0, 1) == '(') {
264 $uname = $urow['lname'];
265 if ($urow['fname']) $uname .= ", " . $urow['fname'];
267 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
268 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
269 echo "<option value='$optionValue'";
270 $title = $urow['username'] ? xl('Local') : xl('External');
271 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
272 echo " title='$optionTitle'";
273 if ($urow['id'] == $currvalue) echo " selected";
274 echo ">$optionLabel</option>";
276 echo "</select>";
279 // a billing code
280 else if ($data_type == 15) {
281 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
282 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
283 echo "<input type='text'" .
284 " name='form_$field_id_esc'" .
285 " id='form_related_code'" .
286 " size='$fldlength'" .
287 " maxlength='$maxlength'" .
288 " title='$description'" .
289 " value='$currescaped'" .
290 " onclick='sel_related(this)' readonly" .
291 " />";
294 // a set of labeled checkboxes
295 else if ($data_type == 21) {
296 // In this special case, fld_length is the number of columns generated.
297 $cols = max(1, $frow['fld_length']);
298 $avalue = explode('|', $currvalue);
299 $lres = sqlStatement("SELECT * FROM list_options " .
300 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
301 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
302 $tdpct = (int) (100 / $cols);
303 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
304 $option_id = $lrow['option_id'];
305 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
306 // if ($count) echo "<br />";
307 if ($count % $cols == 0) {
308 if ($count) echo "</tr>";
309 echo "<tr>";
311 echo "<td width='$tdpct%'>";
312 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]' id='form_{$field_id_esc}[$option_id_esc]' value='1'";
313 if (in_array($option_id, $avalue)) echo " checked";
315 // Added 5-09 by BM - Translate label if applicable
316 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
318 echo "</td>";
320 if ($count) {
321 echo "</tr>";
322 if ($count > $cols) {
323 // Add some space after multiple rows of checkboxes.
324 $cols = htmlspecialchars( $cols, ENT_QUOTES);
325 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
328 echo "</table>";
331 // a set of labeled text input fields
332 else if ($data_type == 22) {
333 $tmp = explode('|', $currvalue);
334 $avalue = array();
335 foreach ($tmp as $value) {
336 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
337 $avalue[$matches[1]] = $matches[2];
340 $lres = sqlStatement("SELECT * FROM list_options " .
341 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
342 echo "<table cellpadding='0' cellspacing='0'>";
343 while ($lrow = sqlFetchArray($lres)) {
344 $option_id = $lrow['option_id'];
345 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
346 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
347 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
349 // Added 5-09 by BM - Translate label if applicable
350 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
351 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
352 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
353 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
354 echo "<td><input type='text'" .
355 " name='form_{$field_id_esc}[$option_id_esc]'" .
356 " id='form_{$field_id_esc}[$option_id_esc]'" .
357 " size='$fldlength'" .
358 " maxlength='$maxlength'" .
359 " value='$optionValue'";
360 echo " /></td></tr>";
362 echo "</table>";
365 // a set of exam results; 3 radio buttons and a text field:
366 else if ($data_type == 23) {
367 $tmp = explode('|', $currvalue);
368 $avalue = array();
369 foreach ($tmp as $value) {
370 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
371 $avalue[$matches[1]] = $matches[2];
374 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
375 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
376 $lres = sqlStatement("SELECT * FROM list_options " .
377 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
378 echo "<table cellpadding='0' cellspacing='0'>";
379 echo "<tr><td>&nbsp;</td><td class='bold'>" .
380 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
381 "&nbsp;</td><td class='bold'>" .
382 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
383 "<td class='bold'>" .
384 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
385 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
386 while ($lrow = sqlFetchArray($lres)) {
387 $option_id = $lrow['option_id'];
388 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
389 $restype = substr($avalue[$option_id], 0, 1);
390 $resnote = substr($avalue[$option_id], 2);
392 // Added 5-09 by BM - Translate label if applicable
393 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
395 for ($i = 0; $i < 3; ++$i) {
396 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
397 echo "<td><input type='radio'" .
398 " name='radio_{$field_id_esc}[$option_id_esc]'" .
399 " id='radio_{$field_id_esc}[$option_id_esc]'" .
400 " value='$inputValue'";
401 if ($restype === "$i") echo " checked";
402 echo " /></td>";
404 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
405 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
406 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
407 echo "<td><input type='text'" .
408 " name='form_{$field_id_esc}[$option_id_esc]'" .
409 " id='form_{$field_id_esc}[$option_id_esc]'" .
410 " size='$fldlength'" .
411 " maxlength='$maxlength'" .
412 " value='$resnote' /></td>";
413 echo "</tr>";
415 echo "</table>";
418 // the list of active allergies for the current patient
419 // this is read-only!
420 else if ($data_type == 24) {
421 $query = "SELECT title, comments FROM lists WHERE " .
422 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
423 "ORDER BY begdate";
424 // echo "<!-- $query -->\n"; // debugging
425 $lres = sqlStatement($query, array($GLOBALS['pid']));
426 $count = 0;
427 while ($lrow = sqlFetchArray($lres)) {
428 if ($count++) echo "<br />";
429 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
430 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
434 // a set of labeled checkboxes, each with a text field:
435 else if ($data_type == 25) {
436 $tmp = explode('|', $currvalue);
437 $avalue = array();
438 foreach ($tmp as $value) {
439 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
440 $avalue[$matches[1]] = $matches[2];
443 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
444 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
445 $lres = sqlStatement("SELECT * FROM list_options " .
446 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
447 echo "<table cellpadding='0' cellspacing='0'>";
448 while ($lrow = sqlFetchArray($lres)) {
449 $option_id = $lrow['option_id'];
450 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
451 $restype = substr($avalue[$option_id], 0, 1);
452 $resnote = substr($avalue[$option_id], 2);
454 // Added 5-09 by BM - Translate label if applicable
455 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
457 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
458 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]' id='check_{$field_id_esc}[$option_id_esc]' value='1'";
459 if ($restype) echo " checked";
460 echo " />&nbsp;</td>";
461 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
462 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
463 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
464 echo "<td><input type='text'" .
465 " name='form_{$field_id_esc}[$option_id_esc]'" .
466 " id='form_{$field_id_esc}[$option_id_esc]'" .
467 " size='$fldlength'" .
468 " maxlength='$maxlength'" .
469 " value='$resnote' /></td>";
470 echo "</tr>";
472 echo "</table>";
475 // single-selection list with ability to add to it
476 else if ($data_type == 26) {
477 echo "<select class='addtolistclass_$list_id_esc' name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
478 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES) . "</option>";
479 $lres = sqlStatement("SELECT * FROM list_options " .
480 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
481 $got_selected = FALSE;
482 while ($lrow = sqlFetchArray($lres)) {
483 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
484 echo "<option value='$optionValue'";
485 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
486 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
488 echo " selected";
489 $got_selected = TRUE;
491 // Added 5-09 by BM - Translate label if applicable
492 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n";
494 if (!$got_selected && strlen($currvalue) > 0) {
495 echo "<option value='$currescaped' selected>* $currescaped *</option>";
496 echo "</select>";
497 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES);
498 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
499 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
501 else {
502 echo "</select>";
504 // show the add button if user has access to correct list
505 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
506 $outputAddButton = "<input type='button' id='addtolistid_".$list_id_esc."' fieldid='form_".$field_id_esc."' class='addtolist' value='$inputValue'>";
507 if (aco_exist('lists', $list_id)) {
508 // a specific aco exist for this list, so ensure access
509 if (acl_check('lists', $list_id)) echo $outputAddButton;
511 else {
512 // no specific aco exist for this list, so check for access to 'default' list
513 if (acl_check('lists', 'default')) echo $outputAddButton;
517 // a set of labeled radio buttons
518 else if ($data_type == 27) {
519 // In this special case, fld_length is the number of columns generated.
520 $cols = max(1, $frow['fld_length']);
521 $lres = sqlStatement("SELECT * FROM list_options " .
522 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
523 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
524 $tdpct = (int) (100 / $cols);
525 $got_selected = FALSE;
526 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
527 $option_id = $lrow['option_id'];
528 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
529 if ($count % $cols == 0) {
530 if ($count) echo "</tr>";
531 echo "<tr>";
533 echo "<td width='$tdpct%'>";
534 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]' value='$option_id_esc'";
535 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
536 (strlen($currvalue) > 0 && $option_id == $currvalue))
538 echo " checked";
539 $got_selected = TRUE;
541 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
542 echo "</td>";
544 if ($count) {
545 echo "</tr>";
546 if ($count > $cols) {
547 // Add some space after multiple rows of radio buttons.
548 $cols = htmlspecialchars( $cols, ENT_QUOTES);
549 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
552 echo "</table>";
553 if (!$got_selected && strlen($currvalue) > 0) {
554 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
555 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
556 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
560 // special case for history of lifestyle status; 3 radio buttons and a date text field:
561 else if ($data_type == 28) {
562 $tmp = explode('|', $currvalue);
563 switch(count($tmp)) {
564 case "3": {
565 $resnote = $tmp[0];
566 $restype = $tmp[1];
567 $resdate = $tmp[2];
568 } break;
569 case "2": {
570 $resnote = $tmp[0];
571 $restype = $tmp[1];
572 $resdate = "";
573 } break;
574 case "1": {
575 $resnote = $tmp[0];
576 $resdate = $restype = "";
577 } break;
578 default: {
579 $restype = $resdate = $resnote = "";
580 } break;
582 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
583 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
585 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
586 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
587 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
588 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
589 echo "<table cellpadding='0' cellspacing='0'>";
590 echo "<tr>";
591 // input text
592 echo "<td><input type='text'" .
593 " name='form_$field_id_esc'" .
594 " id='form_$field_id_esc'" .
595 " size='$fldlength'" .
596 " maxlength='$maxlength'" .
597 " value='$resnote' />&nbsp;</td>";
598 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
599 // current
600 echo "<td><input type='radio'" .
601 " name='radio_{$field_id_esc}'" .
602 " id='radio_{$field_id_esc}[current]'" .
603 " value='current".$field_id_esc."'";
604 if ($restype == "current".$field_id) echo " checked";
605 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
606 // quit
607 echo "<td><input type='radio'" .
608 " name='radio_{$field_id_esc}'" .
609 " id='radio_{$field_id_esc}[quit]'" .
610 " value='quit".$field_id_esc."'";
611 if ($restype == "quit".$field_id) echo " checked";
612 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
613 // quit date
614 echo "<td><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
615 " value='$resdate'" .
616 " title='$description'" .
617 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
618 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
619 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
620 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />&nbsp;</td>";
621 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
622 // never
623 echo "<td><input type='radio'" .
624 " name='radio_{$field_id_esc}'" .
625 " id='radio_{$field_id_esc}[never]'" .
626 " value='never".$field_id_esc."'";
627 if ($restype == "never".$field_id) echo " checked";
628 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."&nbsp;</td>";
629 // Not Applicable
630 echo "<td><input type='radio'" .
631 " name='radio_{$field_id}'" .
632 " id='radio_{$field_id}[not_applicable]'" .
633 " value='not_applicable".$field_id."'";
634 if ($restype == "not_applicable".$field_id) echo " checked";
635 echo " />".htmlspecialchars( xl('N/A'), ENT_QUOTES)."&nbsp;</td>";
636 echo "</tr>";
637 echo "</table>";
640 // static text. read-only, of course.
641 else if ($data_type == 31) {
642 echo nl2br($frow['description']);
647 function generate_print_field($frow, $currvalue) {
648 global $rootdir, $date_init;
650 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
652 $data_type = $frow['data_type'];
653 $field_id = $frow['field_id'];
654 $list_id = $frow['list_id'];
655 $fld_length = $frow['fld_length'];
657 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
659 // Can pass $frow['empty_title'] with this variable, otherwise
660 // will default to 'Unassigned'.
661 // If it is 'SKIP' then an empty text title is completely skipped.
662 $showEmpty = true;
663 if (isset($frow['empty_title'])) {
664 if ($frow['empty_title'] == "SKIP") {
665 //do not display an 'empty' choice
666 $showEmpty = false;
667 $empty_title = "Unassigned";
669 else {
670 $empty_title = $frow['empty_title'];
673 else {
674 $empty_title = "Unassigned";
677 // generic single-selection list
678 if ($data_type == 1 || $data_type == 26) {
679 if (empty($fld_length)) {
680 if ($list_id == 'titles') {
681 $fld_length = 3;
682 } else {
683 $fld_length = 10;
686 $tmp = '';
687 if ($currvalue) {
688 $lrow = sqlQuery("SELECT title FROM list_options " .
689 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
690 $tmp = xl_list_label($lrow['title']);
691 if (empty($tmp)) $tmp = "($currvalue)";
693 /*****************************************************************
694 echo "<input type='text'" .
695 " size='$fld_length'" .
696 " value='$tmp'" .
697 " class='under'" .
698 " />";
699 *****************************************************************/
700 if ($tmp === '') { $tmp = '&nbsp;'; }
701 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
702 echo $tmp;
705 // simple text field
706 else if ($data_type == 2 || $data_type == 15) {
707 /*****************************************************************
708 echo "<input type='text'" .
709 " size='$fld_length'" .
710 " value='$currescaped'" .
711 " class='under'" .
712 " />";
713 *****************************************************************/
714 if ($currescaped === '') $currescaped = '&nbsp;';
715 echo $currescaped;
718 // long or multi-line text field
719 else if ($data_type == 3) {
720 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
721 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
722 echo "<textarea" .
723 " cols='$fldlength'" .
724 " rows='$maxlength'>" .
725 $currescaped . "</textarea>";
728 // date
729 else if ($data_type == 4) {
730 /*****************************************************************
731 echo "<input type='text' size='10'" .
732 " value='$currescaped'" .
733 " title='$description'" .
734 " class='under'" .
735 " />";
736 *****************************************************************/
737 if ($currvalue === '') { $tmp = oeFormatShortDate('&nbsp;'); }
738 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES); }
739 echo $tmp;
742 // provider list
743 else if ($data_type == 10 || $data_type == 11) {
744 $tmp = '';
745 if ($currvalue) {
746 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
747 "WHERE id = ?", array($currvalue) );
748 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
749 if (empty($tmp)) $tmp = "($currvalue)";
751 /*****************************************************************
752 echo "<input type='text'" .
753 " size='$fld_length'" .
754 " value='$tmp'" .
755 " class='under'" .
756 " />";
757 *****************************************************************/
758 if ($tmp === '') { $tmp = '&nbsp;'; }
759 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
760 echo $tmp;
763 // pharmacy list
764 else if ($data_type == 12) {
765 $tmp = '';
766 if ($currvalue) {
767 $pres = get_pharmacies();
768 while ($prow = sqlFetchArray($pres)) {
769 $key = $prow['id'];
770 if ($currvalue == $key) {
771 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
772 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
773 $prow['line1'] . ' / ' . $prow['city'];
776 if (empty($tmp)) $tmp = "($currvalue)";
778 /*****************************************************************
779 echo "<input type='text'" .
780 " size='$fld_length'" .
781 " value='$tmp'" .
782 " class='under'" .
783 " />";
784 *****************************************************************/
785 if ($tmp === '') { $tmp = '&nbsp;'; }
786 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
787 echo $tmp;
790 // squads
791 else if ($data_type == 13) {
792 $tmp = '';
793 if ($currvalue) {
794 $squads = acl_get_squads();
795 if ($squads) {
796 foreach ($squads as $key => $value) {
797 if ($currvalue == $key) {
798 $tmp = $value[3];
802 if (empty($tmp)) $tmp = "($currvalue)";
804 /*****************************************************************
805 echo "<input type='text'" .
806 " size='$fld_length'" .
807 " value='$tmp'" .
808 " class='under'" .
809 " />";
810 *****************************************************************/
811 if ($tmp === '') { $tmp = '&nbsp;'; }
812 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
813 echo $tmp;
816 // Address book.
817 else if ($data_type == 14) {
818 $tmp = '';
819 if ($currvalue) {
820 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
821 "WHERE id = ?", array($currvalue) );
822 $uname = $urow['lname'];
823 if ($urow['fname']) $uname .= ", " . $urow['fname'];
824 $tmp = $uname;
825 if (empty($tmp)) $tmp = "($currvalue)";
827 /*****************************************************************
828 echo "<input type='text'" .
829 " size='$fld_length'" .
830 " value='$tmp'" .
831 " class='under'" .
832 " />";
833 *****************************************************************/
834 if ($tmp === '') { $tmp = '&nbsp;'; }
835 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
836 echo $tmp;
839 // a set of labeled checkboxes
840 else if ($data_type == 21) {
841 // In this special case, fld_length is the number of columns generated.
842 $cols = max(1, $fld_length);
843 $avalue = explode('|', $currvalue);
844 $lres = sqlStatement("SELECT * FROM list_options " .
845 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
846 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
847 $tdpct = (int) (100 / $cols);
848 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
849 $option_id = $lrow['option_id'];
850 if ($count % $cols == 0) {
851 if ($count) echo "</tr>";
852 echo "<tr>";
854 echo "<td width='$tdpct%'>";
855 echo "<input type='checkbox'";
856 if (in_array($option_id, $avalue)) echo " checked";
857 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
858 echo "</td>";
860 if ($count) {
861 echo "</tr>";
862 if ($count > $cols) {
863 // Add some space after multiple rows of checkboxes.
864 $cols = htmlspecialchars( $cols, ENT_QUOTES);
865 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
868 echo "</table>";
871 // a set of labeled text input fields
872 else if ($data_type == 22) {
873 $tmp = explode('|', $currvalue);
874 $avalue = array();
875 foreach ($tmp as $value) {
876 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
877 $avalue[$matches[1]] = $matches[2];
880 $lres = sqlStatement("SELECT * FROM list_options " .
881 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
882 echo "<table cellpadding='0' cellspacing='0'>";
883 while ($lrow = sqlFetchArray($lres)) {
884 $option_id = $lrow['option_id'];
885 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
886 $fldlength = empty($fld_length) ? 20 : $fld_length;
887 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
888 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
889 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
890 echo "<td><input type='text'" .
891 " size='$fldlength'" .
892 " value='$inputValue'" .
893 " class='under'" .
894 " /></td></tr>";
896 echo "</table>";
899 // a set of exam results; 3 radio buttons and a text field:
900 else if ($data_type == 23) {
901 $tmp = explode('|', $currvalue);
902 $avalue = array();
903 foreach ($tmp as $value) {
904 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
905 $avalue[$matches[1]] = $matches[2];
908 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
909 $fldlength = empty($fld_length) ? 20 : $fld_length;
910 $lres = sqlStatement("SELECT * FROM list_options " .
911 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
912 echo "<table cellpadding='0' cellspacing='0'>";
913 echo "<tr><td>&nbsp;</td><td class='bold'>" .
914 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
915 "&nbsp;</td><td class='bold'>" .
916 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
917 "<td class='bold'>" .
918 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
919 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
920 while ($lrow = sqlFetchArray($lres)) {
921 $option_id = $lrow['option_id'];
922 $restype = substr($avalue[$option_id], 0, 1);
923 $resnote = substr($avalue[$option_id], 2);
924 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
925 for ($i = 0; $i < 3; ++$i) {
926 echo "<td><input type='radio'";
927 if ($restype === "$i") echo " checked";
928 echo " /></td>";
930 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
931 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
932 echo "<td><input type='text'" .
933 " size='$fldlength'" .
934 " value='$resnote'" .
935 " class='under' /></td>" .
936 "</tr>";
938 echo "</table>";
941 // the list of active allergies for the current patient
942 // this is read-only!
943 else if ($data_type == 24) {
944 $query = "SELECT title, comments FROM lists WHERE " .
945 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
946 "ORDER BY begdate";
947 $lres = sqlStatement($query, array($GLOBALS['pid']) );
948 $count = 0;
949 while ($lrow = sqlFetchArray($lres)) {
950 if ($count++) echo "<br />";
951 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
952 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
956 // a set of labeled checkboxes, each with a text field:
957 else if ($data_type == 25) {
958 $tmp = explode('|', $currvalue);
959 $avalue = array();
960 foreach ($tmp as $value) {
961 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
962 $avalue[$matches[1]] = $matches[2];
965 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
966 $fldlength = empty($fld_length) ? 20 : $fld_length;
967 $lres = sqlStatement("SELECT * FROM list_options " .
968 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
969 echo "<table cellpadding='0' cellspacing='0'>";
970 while ($lrow = sqlFetchArray($lres)) {
971 $option_id = $lrow['option_id'];
972 $restype = substr($avalue[$option_id], 0, 1);
973 $resnote = substr($avalue[$option_id], 2);
974 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
975 echo "<td><input type='checkbox'";
976 if ($restype) echo " checked";
977 echo " />&nbsp;</td>";
978 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
979 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
980 echo "<td><input type='text'" .
981 " size='$fldlength'" .
982 " value='$resnote'" .
983 " class='under'" .
984 " /></td>" .
985 "</tr>";
987 echo "</table>";
990 // a set of labeled radio buttons
991 else if ($data_type == 27) {
992 // In this special case, fld_length is the number of columns generated.
993 $cols = max(1, $frow['fld_length']);
994 $lres = sqlStatement("SELECT * FROM list_options " .
995 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
996 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
997 $tdpct = (int) (100 / $cols);
998 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
999 $option_id = $lrow['option_id'];
1000 if ($count % $cols == 0) {
1001 if ($count) echo "</tr>";
1002 echo "<tr>";
1004 echo "<td width='$tdpct%'>";
1005 echo "<input type='radio'";
1006 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1007 (strlen($currvalue) > 0 && $option_id == $currvalue))
1009 echo " checked";
1011 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1012 echo "</td>";
1014 if ($count) {
1015 echo "</tr>";
1016 if ($count > $cols) {
1017 // Add some space after multiple rows of radio buttons.
1018 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1019 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1022 echo "</table>";
1025 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1026 else if ($data_type == 28) {
1027 $tmp = explode('|', $currvalue);
1028 switch(count($tmp)) {
1029 case "3": {
1030 $resnote = $tmp[0];
1031 $restype = $tmp[1];
1032 $resdate = $tmp[2];
1033 } break;
1034 case "2": {
1035 $resnote = $tmp[0];
1036 $restype = $tmp[1];
1037 $resdate = "";
1038 } break;
1039 case "1": {
1040 $resnote = $tmp[0];
1041 $resdate = $restype = "";
1042 } break;
1043 default: {
1044 $restype = $resdate = $resnote = "";
1045 } break;
1047 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1048 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1049 echo "<table cellpadding='0' cellspacing='0'>";
1050 echo "<tr>";
1051 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1052 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1053 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1054 echo "<td><input type='text'" .
1055 " size='$fldlength'" .
1056 " class='under'" .
1057 " value='$resnote' /></td>";
1058 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;".
1059 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1060 echo "<td><input type='radio'";
1061 if ($restype == "current".$field_id) echo " checked";
1062 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1064 echo "<td><input type='radio'";
1065 if ($restype == "current".$field_id) echo " checked";
1066 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1068 echo "<td><input type='text' size='6'" .
1069 " value='$resdate'" .
1070 " class='under'" .
1071 " /></td>";
1073 echo "<td><input type='radio'";
1074 if ($restype == "current".$field_id) echo " checked";
1075 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1077 echo "<td><input type='radio'";
1078 if ($restype == "not_applicable".$field_id) echo " checked";
1079 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1080 echo "</tr>";
1081 echo "</table>";
1084 // static text. read-only, of course.
1085 else if ($data_type == 31) {
1086 echo nl2br($frow['description']);
1091 function generate_display_field($frow, $currvalue) {
1092 $data_type = $frow['data_type'];
1093 $field_id = $frow['field_id'];
1094 $list_id = $frow['list_id'];
1095 $s = '';
1097 // generic selection list or the generic selection list with add on the fly
1098 // feature, or radio buttons
1099 if ($data_type == 1 || $data_type == 26 || $data_type == 27) {
1100 $lrow = sqlQuery("SELECT title FROM list_options " .
1101 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1102 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1105 // simple text field
1106 else if ($data_type == 2) {
1107 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1110 // long or multi-line text field
1111 else if ($data_type == 3) {
1112 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1115 // date
1116 else if ($data_type == 4) {
1117 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES);
1120 // provider
1121 else if ($data_type == 10 || $data_type == 11) {
1122 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1123 "WHERE id = ?", array($currvalue) );
1124 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1127 // pharmacy list
1128 else if ($data_type == 12) {
1129 $pres = get_pharmacies();
1130 while ($prow = sqlFetchArray($pres)) {
1131 $key = $prow['id'];
1132 if ($currvalue == $key) {
1133 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1134 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1135 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1140 // squads
1141 else if ($data_type == 13) {
1142 $squads = acl_get_squads();
1143 if ($squads) {
1144 foreach ($squads as $key => $value) {
1145 if ($currvalue == $key) {
1146 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1152 // address book
1153 else if ($data_type == 14) {
1154 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1155 "WHERE id = ?", array($currvalue));
1156 $uname = $urow['lname'];
1157 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1158 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1161 // billing code
1162 else if ($data_type == 15) {
1163 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1166 // a set of labeled checkboxes
1167 else if ($data_type == 21) {
1168 $avalue = explode('|', $currvalue);
1169 $lres = sqlStatement("SELECT * FROM list_options " .
1170 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1171 $count = 0;
1172 while ($lrow = sqlFetchArray($lres)) {
1173 $option_id = $lrow['option_id'];
1174 if (in_array($option_id, $avalue)) {
1175 if ($count++) $s .= "<br />";
1177 // Added 5-09 by BM - Translate label if applicable
1178 $s .= htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1184 // a set of labeled text input fields
1185 else if ($data_type == 22) {
1186 $tmp = explode('|', $currvalue);
1187 $avalue = array();
1188 foreach ($tmp as $value) {
1189 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1190 $avalue[$matches[1]] = $matches[2];
1193 $lres = sqlStatement("SELECT * FROM list_options " .
1194 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1195 $s .= "<table cellpadding='0' cellspacing='0'>";
1196 while ($lrow = sqlFetchArray($lres)) {
1197 $option_id = $lrow['option_id'];
1198 if (empty($avalue[$option_id])) continue;
1200 // Added 5-09 by BM - Translate label if applicable
1201 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1203 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1205 $s .= "</table>";
1208 // a set of exam results; 3 radio buttons and a text field:
1209 else if ($data_type == 23) {
1210 $tmp = explode('|', $currvalue);
1211 $avalue = array();
1212 foreach ($tmp as $value) {
1213 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1214 $avalue[$matches[1]] = $matches[2];
1217 $lres = sqlStatement("SELECT * FROM list_options " .
1218 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1219 $s .= "<table cellpadding='0' cellspacing='0'>";
1220 while ($lrow = sqlFetchArray($lres)) {
1221 $option_id = $lrow['option_id'];
1222 $restype = substr($avalue[$option_id], 0, 1);
1223 $resnote = substr($avalue[$option_id], 2);
1224 if (empty($restype) && empty($resnote)) continue;
1226 // Added 5-09 by BM - Translate label if applicable
1227 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1229 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1230 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1231 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1232 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1233 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1234 $s .= "</tr>";
1236 $s .= "</table>";
1239 // the list of active allergies for the current patient
1240 else if ($data_type == 24) {
1241 $query = "SELECT title, comments FROM lists WHERE " .
1242 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1243 "ORDER BY begdate";
1244 // echo "<!-- $query -->\n"; // debugging
1245 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1246 $count = 0;
1247 while ($lrow = sqlFetchArray($lres)) {
1248 if ($count++) $s .= "<br />";
1249 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1250 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1254 // a set of labeled checkboxes, each with a text field:
1255 else if ($data_type == 25) {
1256 $tmp = explode('|', $currvalue);
1257 $avalue = array();
1258 foreach ($tmp as $value) {
1259 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1260 $avalue[$matches[1]] = $matches[2];
1263 $lres = sqlStatement("SELECT * FROM list_options " .
1264 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1265 $s .= "<table cellpadding='0' cellspacing='0'>";
1266 while ($lrow = sqlFetchArray($lres)) {
1267 $option_id = $lrow['option_id'];
1268 $restype = substr($avalue[$option_id], 0, 1);
1269 $resnote = substr($avalue[$option_id], 2);
1270 if (empty($restype) && empty($resnote)) continue;
1272 // Added 5-09 by BM - Translate label if applicable
1273 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1275 $restype = $restype ? xl('Yes') : xl('No');
1276 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1277 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1278 $s .= "</tr>";
1280 $s .= "</table>";
1283 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1284 else if ($data_type == 28) {
1285 $tmp = explode('|', $currvalue);
1286 switch(count($tmp)) {
1287 case "3": {
1288 $resnote = $tmp[0];
1289 $restype = $tmp[1];
1290 $resdate = $tmp[2];
1291 } break;
1292 case "2": {
1293 $resnote = $tmp[0];
1294 $restype = $tmp[1];
1295 $resdate = "";
1296 } break;
1297 case "1": {
1298 $resnote = $tmp[0];
1299 $resdate = $restype = "";
1300 } break;
1301 default: {
1302 $restype = $resdate = $resnote = "";
1303 } break;
1305 $s .= "<table cellpadding='0' cellspacing='0'>";
1307 $s .= "<tr>";
1308 $res = "";
1309 if ($restype == "current".$field_id) $res = xl('Current');
1310 if ($restype == "quit".$field_id) $res = xl('Quit');
1311 if ($restype == "never".$field_id) $res = xl('Never');
1312 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1313 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1314 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1315 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1316 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1317 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1318 $s .= "</tr>";
1319 $s .= "</table>";
1322 // static text. read-only, of course.
1323 else if ($data_type == 31) {
1324 $s .= nl2br($frow['description']);
1327 return $s;
1330 $CPR = 4; // cells per row of generic data
1331 $last_group = '';
1332 $cell_count = 0;
1333 $item_count = 0;
1335 function disp_end_cell() {
1336 global $item_count, $cell_count;
1337 if ($item_count > 0) {
1338 echo "</td>";
1339 $item_count = 0;
1343 function disp_end_row() {
1344 global $cell_count, $CPR;
1345 disp_end_cell();
1346 if ($cell_count > 0) {
1347 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
1348 echo "</tr>\n";
1349 $cell_count = 0;
1353 function disp_end_group() {
1354 global $last_group;
1355 if (strlen($last_group) > 0) {
1356 disp_end_row();
1360 function display_layout_rows($formtype, $result1, $result2='') {
1361 global $item_count, $cell_count, $last_group, $CPR;
1363 $fres = sqlStatement("SELECT * FROM layout_options " .
1364 "WHERE form_id = ? AND uor > 0 " .
1365 "ORDER BY group_name, seq", array($formtype) );
1367 while ($frow = sqlFetchArray($fres)) {
1368 $this_group = $frow['group_name'];
1369 $titlecols = $frow['titlecols'];
1370 $datacols = $frow['datacols'];
1371 $data_type = $frow['data_type'];
1372 $field_id = $frow['field_id'];
1373 $list_id = $frow['list_id'];
1374 $currvalue = '';
1376 if ($formtype == 'DEM') {
1377 if ($GLOBALS['athletic_team']) {
1378 // Skip fitness level and return-to-play date because those appear
1379 // in a special display/update form on this page.
1380 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1382 if (strpos($field_id, 'em_') === 0) {
1383 // Skip employer related fields, if it's disabled.
1384 if ($GLOBALS['omit_employers']) continue;
1385 $tmp = substr($field_id, 3);
1386 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1388 else {
1389 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1392 else {
1393 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1396 // Handle a data category (group) change.
1397 if (strcmp($this_group, $last_group) != 0) {
1398 $group_name = substr($this_group, 1);
1399 // totally skip generating the employer category, if it's disabled.
1400 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1401 disp_end_group();
1402 $last_group = $this_group;
1405 // Handle starting of a new row.
1406 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1407 disp_end_row();
1408 echo "<tr>";
1409 if ($group_name) {
1410 echo "<td class='groupname'>";
1411 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1412 //echo "<font color='#008800'>$group_name</font>";
1414 // Added 5-09 by BM - Translate label if applicable
1415 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
1417 $group_name = '';
1418 } else {
1419 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1420 echo "<td valign='top'>&nbsp;";
1422 echo "</td>";
1425 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1427 // Handle starting of a new label cell.
1428 if ($titlecols > 0) {
1429 disp_end_cell();
1430 //echo "<td class='label' colspan='$titlecols' valign='top'";
1431 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1432 echo "<td class='label' colspan='$titlecols_esc' ";
1433 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1434 echo ">";
1435 $cell_count += $titlecols;
1437 ++$item_count;
1439 // Added 5-09 by BM - Translate label if applicable
1440 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1442 // Handle starting of a new data cell.
1443 if ($datacols > 0) {
1444 disp_end_cell();
1445 //echo "<td class='text data' colspan='$datacols' valign='top'";
1446 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1447 echo "<td class='text data' colspan='$datacols_esc'";
1448 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1449 echo ">";
1450 $cell_count += $datacols;
1453 ++$item_count;
1454 echo generate_display_field($frow, $currvalue);
1457 disp_end_group();
1460 function display_layout_tabs($formtype, $result1, $result2='') {
1461 global $item_count, $cell_count, $last_group, $CPR;
1463 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1464 "WHERE form_id = ? AND uor > 0 " .
1465 "ORDER BY group_name, seq", array($formtype) );
1467 $first = true;
1468 while ($frow = sqlFetchArray($fres)) {
1469 $this_group = $frow['group_name'];
1470 $group_name = substr($this_group, 1);
1472 <li <?php echo $first ? 'class="current"' : '' ?>>
1473 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES)."?>">
1474 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
1475 </li>
1476 <?php
1477 $first = false;
1481 function display_layout_tabs_data($formtype, $result1, $result2='') {
1482 global $item_count, $cell_count, $last_group, $CPR;
1484 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1485 "WHERE form_id = ? AND uor > 0 " .
1486 "ORDER BY group_name, seq", array($formtype));
1488 $first = true;
1489 while ($frow = sqlFetchArray($fres)) {
1490 $this_group = $frow['group_name'];
1491 $titlecols = $frow['titlecols'];
1492 $datacols = $frow['datacols'];
1493 $data_type = $frow['data_type'];
1494 $field_id = $frow['field_id'];
1495 $list_id = $frow['list_id'];
1496 $currvalue = '';
1498 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1499 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1500 "ORDER BY seq", array($formtype, $this_group) );
1503 <div class="tab <?php echo $first ? 'current' : '' ?>">
1504 <table border='0' cellpadding='0'>
1506 <?php
1507 while ($group_fields = sqlFetchArray($group_fields_query)) {
1509 $titlecols = $group_fields['titlecols'];
1510 $datacols = $group_fields['datacols'];
1511 $data_type = $group_fields['data_type'];
1512 $field_id = $group_fields['field_id'];
1513 $list_id = $group_fields['list_id'];
1514 $currvalue = '';
1516 if ($formtype == 'DEM') {
1517 if ($GLOBALS['athletic_team']) {
1518 // Skip fitness level and return-to-play date because those appear
1519 // in a special display/update form on this page.
1520 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1522 if (strpos($field_id, 'em_') === 0) {
1523 // Skip employer related fields, if it's disabled.
1524 if ($GLOBALS['omit_employers']) continue;
1525 $tmp = substr($field_id, 3);
1526 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1528 else {
1529 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1532 else {
1533 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1536 // Handle a data category (group) change.
1537 if (strcmp($this_group, $last_group) != 0) {
1538 $group_name = substr($this_group, 1);
1539 // totally skip generating the employer category, if it's disabled.
1540 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1541 $last_group = $this_group;
1544 // Handle starting of a new row.
1545 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1546 disp_end_row();
1547 echo "<tr>";
1550 if ($item_count == 0 && $titlecols == 0) {
1551 $titlecols = 1;
1554 // Handle starting of a new label cell.
1555 if ($titlecols > 0) {
1556 disp_end_cell();
1557 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1558 echo "<td class='label' colspan='$titlecols_esc' ";
1559 echo ">";
1560 $cell_count += $titlecols;
1562 ++$item_count;
1564 // Added 5-09 by BM - Translate label if applicable
1565 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1567 // Handle starting of a new data cell.
1568 if ($datacols > 0) {
1569 disp_end_cell();
1570 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1571 echo "<td class='text data' colspan='$datacols_esc'";
1572 echo ">";
1573 $cell_count += $datacols;
1576 ++$item_count;
1577 echo generate_display_field($group_fields, $currvalue);
1581 </table>
1582 </div>
1584 <?php
1586 $first = false;
1592 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1593 global $item_count, $cell_count, $last_group, $CPR;
1595 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1596 "WHERE form_id = ? AND uor > 0 " .
1597 "ORDER BY group_name, seq", array($formtype) );
1599 $first = true;
1600 while ($frow = sqlFetchArray($fres)) {
1601 $this_group = $frow['group_name'];
1602 $group_name = substr($this_group, 1);
1603 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
1604 $titlecols = $frow['titlecols'];
1605 $datacols = $frow['datacols'];
1606 $data_type = $frow['data_type'];
1607 $field_id = $frow['field_id'];
1608 $list_id = $frow['list_id'];
1609 $currvalue = '';
1611 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1612 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1613 "ORDER BY seq", array($formtype,$this_group) );
1616 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name_esc?>" >
1617 <table border='0' cellpadding='0'>
1619 <?php
1620 while ($group_fields = sqlFetchArray($group_fields_query)) {
1622 $titlecols = $group_fields['titlecols'];
1623 $datacols = $group_fields['datacols'];
1624 $data_type = $group_fields['data_type'];
1625 $field_id = $group_fields['field_id'];
1626 $list_id = $group_fields['list_id'];
1627 $currvalue = '';
1629 if ($formtype == 'DEM') {
1630 if ($GLOBALS['athletic_team']) {
1631 // Skip fitness level and return-to-play date because those appear
1632 // in a special display/update form on this page.
1633 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1635 if (strpos($field_id, 'em_') === 0) {
1636 // Skip employer related fields, if it's disabled.
1637 if ($GLOBALS['omit_employers']) continue;
1638 $tmp = substr($field_id, 3);
1639 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1641 else {
1642 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1645 else {
1646 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1649 // Handle a data category (group) change.
1650 if (strcmp($this_group, $last_group) != 0) {
1651 $group_name = substr($this_group, 1);
1652 // totally skip generating the employer category, if it's disabled.
1653 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1654 $last_group = $this_group;
1657 // Handle starting of a new row.
1658 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1659 disp_end_row();
1660 echo "<tr>";
1663 if ($item_count == 0 && $titlecols == 0) {
1664 $titlecols = 1;
1667 // Handle starting of a new label cell.
1668 if ($titlecols > 0) {
1669 disp_end_cell();
1670 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1671 echo "<td class='label' colspan='$titlecols_esc' ";
1672 echo ">";
1673 $cell_count += $titlecols;
1675 ++$item_count;
1677 // Added 5-09 by BM - Translate label if applicable
1678 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
1680 // Handle starting of a new data cell.
1681 if ($datacols > 0) {
1682 disp_end_cell();
1683 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1684 echo "<td class='text data' colspan='$datacols_esc'";
1685 echo ">";
1686 $cell_count += $datacols;
1689 ++$item_count;
1690 echo generate_form_field($group_fields, $currvalue);
1694 </table>
1695 </div>
1697 <?php
1699 $first = false;
1704 // From the currently posted HTML form, this gets the value of the
1705 // field corresponding to the provided layout_options table row.
1707 function get_layout_form_value($frow, $maxlength=255) {
1708 // Bring in $sanitize_all_escapes variable, which will decide
1709 // the variable escaping method.
1710 global $sanitize_all_escapes;
1712 $data_type = $frow['data_type'];
1713 $field_id = $frow['field_id'];
1714 $value = '';
1715 if (isset($_POST["form_$field_id"])) {
1716 if ($data_type == 21) {
1717 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1718 // must be concatenated into a |-separated string.
1719 foreach ($_POST["form_$field_id"] as $key => $val) {
1720 if (strlen($value)) $value .= '|';
1721 $value .= $key;
1724 else if ($data_type == 22) {
1725 // $_POST["form_$field_id"] is an array of text fields to be imploded
1726 // into "key:value|key:value|...".
1727 foreach ($_POST["form_$field_id"] as $key => $val) {
1728 $val = str_replace('|', ' ', $val);
1729 if (strlen($value)) $value .= '|';
1730 $value .= "$key:$val";
1733 else if ($data_type == 23) {
1734 // $_POST["form_$field_id"] is an array of text fields with companion
1735 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1736 foreach ($_POST["form_$field_id"] as $key => $val) {
1737 $restype = $_POST["radio_{$field_id}"][$key];
1738 if (empty($restype)) $restype = '0';
1739 $val = str_replace('|', ' ', $val);
1740 if (strlen($value)) $value .= '|';
1741 $value .= "$key:$restype:$val";
1744 else if ($data_type == 25) {
1745 // $_POST["form_$field_id"] is an array of text fields with companion
1746 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1747 foreach ($_POST["form_$field_id"] as $key => $val) {
1748 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
1749 $val = str_replace('|', ' ', $val);
1750 if (strlen($value)) $value .= '|';
1751 $value .= "$key:$restype:$val";
1754 else if ($data_type == 28) {
1755 // $_POST["form_$field_id"] is an date text fields with companion
1756 // radio buttons to be imploded into "notes|type|date".
1757 $restype = $_POST["radio_{$field_id}"];
1758 if (empty($restype)) $restype = '0';
1759 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1760 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1761 $value = "$resnote|$restype|$resdate";
1763 else {
1764 $value = $_POST["form_$field_id"];
1768 // Better to die than to silently truncate data!
1769 if ($maxlength && $data_type != 3 && strlen($value) > $maxlength)
1770 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
1771 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
1773 // Make sure the return value is quote-safe.
1774 if ($sanitize_all_escapes) {
1775 //escapes already removed and using binding/placemarks in sql calls
1776 // so only need to trim value
1777 return trim($value);
1779 else {
1780 //need to explicitly prepare value
1781 return formTrim($value);
1785 // Generate JavaScript validation logic for the required fields.
1787 function generate_layout_validation($form_id) {
1788 $fres = sqlStatement("SELECT * FROM layout_options " .
1789 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
1790 "ORDER BY group_name, seq", array($form_id) );
1792 while ($frow = sqlFetchArray($fres)) {
1793 if ($frow['uor'] < 2) continue;
1794 $data_type = $frow['data_type'];
1795 $field_id = $frow['field_id'];
1796 $fldtitle = $frow['title'];
1797 if (!$fldtitle) $fldtitle = $frow['description'];
1798 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES);
1799 switch($data_type) {
1800 case 1:
1801 case 11:
1802 case 12:
1803 case 13:
1804 case 14:
1805 case 26:
1806 echo
1807 " if (f.$fldname.selectedIndex <= 0) {\n" .
1808 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1809 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1810 " }\n";
1811 break;
1812 case 27: // radio buttons
1813 echo
1814 " var i = 0;\n" .
1815 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
1816 " if (i >= f.$fldname.length) {\n" .
1817 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1818 " }\n";
1819 break;
1820 case 2:
1821 case 3:
1822 case 4:
1823 case 15:
1824 echo
1825 " if (trimlen(f.$fldname.value) == 0) {\n" .
1826 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1827 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
1828 " $('#" . $fldname . "').attr('style','background:red'); \n" .
1829 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1830 " } else { " .
1831 " $('#" . $fldname . "').attr('style',''); " .
1832 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
1833 " } \n";
1834 break;
1840 * DROPDOWN FOR FACILITIES
1842 * build a dropdown with all facilities
1844 * @param string $selected - name of the currently selected facility
1845 * use '0' for "unspecified facility"
1846 * use '' for "All facilities" (the default)
1847 * @param string $name - the name/id for select form (defaults to "form_facility")
1848 * @param boolean $allow_unspecified - include an option for "unspecified" facility
1849 * defaults to true
1850 * @return void - just echo the html encoded string
1852 * Note: This should become a data-type at some point, according to Brady
1854 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true) {
1855 $have_selected = false;
1856 $query = "SELECT id, name FROM facility ORDER BY name";
1857 $fres = sqlStatement($query);
1859 $name = htmlspecialchars($name, ENT_QUOTES);
1860 echo " <select name=\"$name\">\n";
1862 $option_value = '';
1863 $option_selected_attr = '';
1864 if ($selected == '') {
1865 $option_selected_attr = ' selected="selected"';
1866 $have_selected = true;
1868 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
1869 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1871 while ($frow = sqlFetchArray($fres)) {
1872 $facility_id = $frow['id'];
1873 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
1874 $option_selected_attr = '';
1875 if ($selected == $facility_id) {
1876 $option_selected_attr = ' selected="selected"';
1877 $have_selected = true;
1879 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
1880 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1883 if ($allow_unspecified) {
1884 $option_value = '0';
1885 $option_selected_attr = '';
1886 if ( $selected == '0' ) {
1887 $option_selected_attr = ' selected="selected"';
1888 $have_selected = true;
1890 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
1891 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1894 if (!$have_selected) {
1895 $option_value = htmlspecialchars($selected, ENT_QUOTES);
1896 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
1897 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
1898 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
1900 echo " </select>\n";
1903 // Expand Collapse Widget
1904 // This forms the header and functionality component of the widget. The information that is displayed
1905 // then follows this function followed by a closing div tag
1907 // $title is the title of the section (already translated)
1908 // $label is identifier used in the tag id's and sql columns
1909 // $buttonLabel is the button label text (already translated)
1910 // $buttonLink is the button link information
1911 // $buttonClass is any additional needed class elements for the button tag
1912 // $linkMethod is the button link method ('javascript' vs 'html')
1913 // $bodyClass is to set class(es) of the body
1914 // $auth is a flag to decide whether to show the button
1915 // $fixedWidth is to flag whether width is fixed
1917 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth) {
1918 if ($fixedWidth) {
1919 echo "<div class='section-header'>";
1921 else {
1922 echo "<div class='section-header-dynamic'>";
1924 echo "<table><tr>";
1925 if ($auth) {
1926 // show button, since authorized
1927 // first prepare class string
1928 if ($buttonClass) {
1929 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
1931 else {
1932 $class_string = "css_button_small";
1934 // next, create the link
1935 if ($linkMethod == "javascript") {
1936 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
1938 else {
1939 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'" .
1940 " onclick='top.restoreSession()'";
1942 if (!$GLOBALS['concurrent_layout']) {
1943 echo " target='Main'";
1945 echo "><span>" .
1946 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
1948 echo "<td><a href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
1949 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
1950 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
1951 if (getUserSetting($label."_ps_expand")) {
1952 $text = xl('collapse');
1954 else {
1955 $text = xl('expand');
1957 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
1958 "</span>)</a></td>";
1959 echo "</tr></table>";
1960 echo "</div>";
1961 if (getUserSetting($label."_ps_expand")) {
1962 $styling = "";
1964 else {
1965 $styling = "style='display:none'";
1967 if ($bodyClass) {
1968 $styling .= " class='" . $bodyClass . "'";
1970 //next, create the first div tag to hold the information
1971 // note the code that calls this function will then place the ending div tag after the data
1972 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";