Integrate adodb binding functionality to allow sql queries with binding to prevent...
[openemr.git] / library / options.inc.php
blob164814f9fc4a436be8bb8343f71bee8aeb43c5f4
1 <?php
2 // Copyright (C) 2007-2009 Rod Roark <rod@sunsetsystems.com>
3 // Copyright © 2010 by Andrew Moore <amoore@cpan.org>
4 // Copyright © 2010 by "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
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 $s .= "<select name='$tag_name' id='$tag_name'";
40 if ($class) $s .= " class='$class'";
41 if ($onchange) $s .= " onchange='$onchange'";
42 $s .= " title='$title'>";
43 if ($empty_name) $s .= "<option value=''>" . xl($empty_name) . "</option>";
44 $lres = sqlStatement("SELECT * FROM list_options " .
45 "WHERE list_id = '$list_id' ORDER BY seq, title");
46 $got_selected = FALSE;
47 while ($lrow = sqlFetchArray($lres)) {
48 $s .= "<option value='" . $lrow['option_id'] . "'";
49 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
50 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
52 $s .= " selected";
53 $got_selected = TRUE;
55 $s .= ">" . xl_list_label($lrow['title']) . "</option>\n";
57 if (!$got_selected && strlen($currvalue) > 0) {
58 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
59 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
60 $s .= "</select>";
61 $s .= " <font color='red' title='" .
62 xl('Please choose a valid selection from the list.') . "'>" .
63 xl('Fix this') . "!</font>";
65 else {
66 $s .= "</select>";
68 return $s;
71 function generate_form_field($frow, $currvalue) {
72 global $rootdir, $date_init;
74 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
76 $data_type = $frow['data_type'];
77 $field_id = $frow['field_id'];
78 $list_id = $frow['list_id'];
80 // Added 5-09 by BM - Translate description if applicable
81 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
83 // added 5-2009 by BM to allow modification of the 'empty' text title field.
84 // Can pass $frow['empty_title'] with this variable, otherwise
85 // will default to 'Unassigned'.
86 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
87 // if make $frow['empty_title'] equal to 'SKIP'
88 $showEmpty = true;
89 if (isset($frow['empty_title'])) {
90 if ($frow['empty_title'] == "SKIP") {
91 //do not display an 'empty' choice
92 $showEmpty = false;
93 $empty_title = "Unassigned";
95 else {
96 $empty_title = $frow['empty_title'];
99 else {
100 $empty_title = "Unassigned";
103 // generic single-selection list
104 if ($data_type == 1) {
105 echo generate_select_list("form_$field_id", $list_id, $currvalue,
106 $description, $showEmpty ? $empty_title : '');
109 // simple text field
110 else if ($data_type == 2) {
111 echo "<input type='text'" .
112 " name='form_$field_id'" .
113 " id='form_$field_id'" .
114 " size='" . $frow['fld_length'] . "'" .
115 " maxlength='" . $frow['max_length'] . "'" .
116 " title='$description'" .
117 " value='$currescaped'";
118 if (strpos($frow['edit_options'], 'C') !== FALSE)
119 echo " onchange='capitalizeMe(this)'";
120 $tmp = addslashes($GLOBALS['gbl_mask_patient_id']);
121 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
122 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
123 echo " onblur='maskblur(this,\"$tmp\")'";
125 echo " />";
128 // long or multi-line text field
129 else if ($data_type == 3) {
130 echo "<textarea" .
131 " name='form_$field_id'" .
132 " id='form_$field_id'" .
133 " title='$description'" .
134 " cols='" . $frow['fld_length'] . "'" .
135 " rows='" . $frow['max_length'] . "'>" .
136 $currescaped . "</textarea>";
139 // date
140 else if ($data_type == 4) {
141 echo "<input type='text' size='10' name='form_$field_id' id='form_$field_id'" .
142 " value='$currescaped'" .
143 " title='$description'" .
144 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
145 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
146 " id='img_$field_id' border='0' alt='[?]' style='cursor:pointer'" .
147 " title='" . xl('Click here to choose a date') . "' />";
148 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
151 // provider list, local providers only
152 else if ($data_type == 10) {
153 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
154 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
155 "AND authorized = 1 " .
156 "ORDER BY lname, fname");
157 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
158 echo "<option value=''>" . xl('Unassigned') . "</option>";
159 while ($urow = sqlFetchArray($ures)) {
160 $uname = $urow['fname'] . ' ' . $urow['lname'];
161 echo "<option value='" . $urow['id'] . "'";
162 if ($urow['id'] == $currvalue) echo " selected";
163 echo ">$uname</option>";
165 echo "</select>";
168 // provider list, including address book entries with an NPI number
169 else if ($data_type == 11) {
170 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
171 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
172 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
173 "ORDER BY lname, fname");
174 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
175 echo "<option value=''>" . xl('Unassigned') . "</option>";
176 while ($urow = sqlFetchArray($ures)) {
177 $uname = $urow['fname'] . ' ' . $urow['lname'];
178 echo "<option value='" . $urow['id'] . "'";
179 if ($urow['id'] == $currvalue) echo " selected";
180 echo ">$uname</option>";
182 echo "</select>";
185 // pharmacy list
186 else if ($data_type == 12) {
187 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
188 echo "<option value='0'></option>";
189 $pres = get_pharmacies();
190 while ($prow = sqlFetchArray($pres)) {
191 $key = $prow['id'];
192 echo "<option value='$key'";
193 if ($currvalue == $key) echo " selected";
194 echo '>' . $prow['name'] . ' ' . $prow['area_code'] . '-' .
195 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
196 $prow['line1'] . ' / ' . $prow['city'] . "</option>";
198 echo "</select>";
201 // squads
202 else if ($data_type == 13) {
203 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
204 echo "<option value=''>&nbsp;</option>";
205 $squads = acl_get_squads();
206 if ($squads) {
207 foreach ($squads as $key => $value) {
208 echo "<option value='$key'";
209 if ($currvalue == $key) echo " selected";
210 echo ">" . $value[3] . "</option>\n";
213 echo "</select>";
216 // Address book, preferring organization name if it exists and is not in
217 // parentheses, and excluding local users who are not providers.
218 // Supports "referred to" practitioners and facilities.
219 // Alternatively the letter O in edit_options means that abook_type
220 // must begin with "ord_", indicating types used with the procedure
221 // ordering system.
222 // Alternatively the letter V in edit_options means that abook_type
223 // must be "vendor", indicating the Vendor type.
224 else if ($data_type == 14) {
225 if (strpos($frow['edit_options'], 'O') !== FALSE)
226 $tmp = "abook_type LIKE 'ord\\_%'";
227 else if (strpos($frow['edit_options'], 'V') !== FALSE)
228 $tmp = "abook_type LIKE 'vendor%'";
229 else
230 $tmp = "( username = '' OR authorized = 1 )";
231 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
232 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
233 "AND $tmp " .
234 "ORDER BY organization, lname, fname");
235 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
236 echo "<option value=''>" . xl('Unassigned') . "</option>";
237 while ($urow = sqlFetchArray($ures)) {
238 $uname = $urow['organization'];
239 if (empty($uname) || substr($uname, 0, 1) == '(') {
240 $uname = $urow['lname'];
241 if ($urow['fname']) $uname .= ", " . $urow['fname'];
243 echo "<option value='" . $urow['id'] . "'";
244 $title = $urow['username'] ? xl('Local') : xl('External');
245 echo " title='$title'";
246 if ($urow['id'] == $currvalue) echo " selected";
247 echo ">$uname</option>";
249 echo "</select>";
252 // a billing code (only one of these allowed!)
253 else if ($data_type == 15) {
254 echo "<input type='text'" .
255 " name='form_$field_id'" .
256 " id='form_related_code'" .
257 " size='" . $frow['fld_length'] . "'" .
258 " maxlength='" . $frow['max_length'] . "'" .
259 " title='$description'" .
260 " value='$currescaped'" .
261 " onclick='sel_related()' readonly" .
262 " />";
265 // a set of labeled checkboxes
266 else if ($data_type == 21) {
267 // In this special case, fld_length is the number of columns generated.
268 $cols = max(1, $frow['fld_length']);
269 $avalue = explode('|', $currvalue);
270 $lres = sqlStatement("SELECT * FROM list_options " .
271 "WHERE list_id = '$list_id' ORDER BY seq, title");
272 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
273 $tdpct = (int) (100 / $cols);
274 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
275 $option_id = $lrow['option_id'];
276 // if ($count) echo "<br />";
277 if ($count % $cols == 0) {
278 if ($count) echo "</tr>";
279 echo "<tr>";
281 echo "<td width='$tdpct%'>";
282 echo "<input type='checkbox' name='form_{$field_id}[$option_id]' id='form_{$field_id}[$option_id]' value='1'";
283 if (in_array($option_id, $avalue)) echo " checked";
285 // Added 5-09 by BM - Translate label if applicable
286 echo ">" . xl_list_label($lrow['title']);
288 echo "</td>";
290 if ($count) {
291 echo "</tr>";
292 if ($count > $cols) {
293 // Add some space after multiple rows of checkboxes.
294 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
297 echo "</table>";
300 // a set of labeled text input fields
301 else if ($data_type == 22) {
302 $tmp = explode('|', $currvalue);
303 $avalue = array();
304 foreach ($tmp as $value) {
305 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
306 $avalue[$matches[1]] = $matches[2];
309 $lres = sqlStatement("SELECT * FROM list_options " .
310 "WHERE list_id = '$list_id' ORDER BY seq, title");
311 echo "<table cellpadding='0' cellspacing='0'>";
312 while ($lrow = sqlFetchArray($lres)) {
313 $option_id = $lrow['option_id'];
314 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
315 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
317 // Added 5-09 by BM - Translate label if applicable
318 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
320 echo "<td><input type='text'" .
321 " name='form_{$field_id}[$option_id]'" .
322 " id='form_{$field_id}[$option_id]'" .
323 " size='$fldlength'" .
324 " maxlength='$maxlength'" .
325 " value='" . $avalue[$option_id] . "'";
326 echo " /></td></tr>";
328 echo "</table>";
331 // a set of exam results; 3 radio buttons and a text field:
332 else if ($data_type == 23) {
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 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
341 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
342 $lres = sqlStatement("SELECT * FROM list_options " .
343 "WHERE list_id = '$list_id' ORDER BY seq, title");
344 echo "<table cellpadding='0' cellspacing='0'>";
345 echo "<tr><td>&nbsp;</td><td class='bold'>" . xl('N/A') .
346 "&nbsp;</td><td class='bold'>" . xl('Nor') . "&nbsp;</td>" .
347 "<td class='bold'>" . xl('Abn') . "&nbsp;</td><td class='bold'>" .
348 xl('Date/Notes') . "</td></tr>";
349 while ($lrow = sqlFetchArray($lres)) {
350 $option_id = $lrow['option_id'];
351 $restype = substr($avalue[$option_id], 0, 1);
352 $resnote = substr($avalue[$option_id], 2);
354 // Added 5-09 by BM - Translate label if applicable
355 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
357 for ($i = 0; $i < 3; ++$i) {
358 echo "<td><input type='radio'" .
359 " name='radio_{$field_id}[$option_id]'" .
360 " id='radio_{$field_id}[$option_id]'" .
361 " value='$i'";
362 if ($restype === "$i") echo " checked";
363 echo " /></td>";
365 echo "<td><input type='text'" .
366 " name='form_{$field_id}[$option_id]'" .
367 " id='form_{$field_id}[$option_id]'" .
368 " size='$fldlength'" .
369 " maxlength='$maxlength'" .
370 " value='$resnote' /></td>";
371 echo "</tr>";
373 echo "</table>";
376 // the list of active allergies for the current patient
377 // this is read-only!
378 else if ($data_type == 24) {
379 $query = "SELECT title, comments FROM lists WHERE " .
380 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
381 "ORDER BY begdate";
382 // echo "<!-- $query -->\n"; // debugging
383 $lres = sqlStatement($query);
384 $count = 0;
385 while ($lrow = sqlFetchArray($lres)) {
386 if ($count++) echo "<br />";
387 echo $lrow['title'];
388 if ($lrow['comments']) echo ' (' . $lrow['comments'] . ')';
392 // a set of labeled checkboxes, each with a text field:
393 else if ($data_type == 25) {
394 $tmp = explode('|', $currvalue);
395 $avalue = array();
396 foreach ($tmp as $value) {
397 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
398 $avalue[$matches[1]] = $matches[2];
401 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
402 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
403 $lres = sqlStatement("SELECT * FROM list_options " .
404 "WHERE list_id = '$list_id' ORDER BY seq, title");
405 echo "<table cellpadding='0' cellspacing='0'>";
406 while ($lrow = sqlFetchArray($lres)) {
407 $option_id = $lrow['option_id'];
408 $restype = substr($avalue[$option_id], 0, 1);
409 $resnote = substr($avalue[$option_id], 2);
411 // Added 5-09 by BM - Translate label if applicable
412 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
414 echo "<td><input type='checkbox' name='check_{$field_id}[$option_id]' id='check_{$field_id}[$option_id]' value='1'";
415 if ($restype) echo " checked";
416 echo " />&nbsp;</td>";
417 echo "<td><input type='text'" .
418 " name='form_{$field_id}[$option_id]'" .
419 " id='form_{$field_id}[$option_id]'" .
420 " size='$fldlength'" .
421 " maxlength='$maxlength'" .
422 " value='$resnote' /></td>";
423 echo "</tr>";
425 echo "</table>";
428 // single-selection list with ability to add to it
429 else if ($data_type == 26) {
430 echo "<select class='addtolistclass_$list_id' name='form_$field_id' id='form_$field_id' title='$description'>";
431 if ($showEmpty) echo "<option value=''>" . xl($empty_title) . "</option>";
432 $lres = sqlStatement("SELECT * FROM list_options " .
433 "WHERE list_id = '$list_id' ORDER BY seq, title");
434 $got_selected = FALSE;
435 while ($lrow = sqlFetchArray($lres)) {
436 echo "<option value='" . $lrow['option_id'] . "'";
437 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
438 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
440 echo " selected";
441 $got_selected = TRUE;
443 // Added 5-09 by BM - Translate label if applicable
444 echo ">" . xl_list_label($lrow['title']) . "</option>\n";
446 if (!$got_selected && strlen($currvalue) > 0) {
447 echo "<option value='$currescaped' selected>* $currescaped *</option>";
448 echo "</select>";
449 echo " <font color='red' title='" . xl('Please choose a valid selection from the list.') . "'>" . xl('Fix this') . "!</font>";
451 else {
452 echo "</select>";
454 // show the add button if user has access to correct list
455 $outputAddButton = "<input type='button' id='addtolistid_".$list_id."' fieldid='form_".$field_id."' class='addtolist' value='" . xl('Add') . "'>";
456 if (aco_exist('lists', $list_id)) {
457 // a specific aco exist for this list, so ensure access
458 if (acl_check('lists', $list_id)) echo $outputAddButton;
460 else {
461 // no specific aco exist for this list, so check for access to 'default' list
462 if (acl_check('lists', 'default')) echo $outputAddButton;
466 // a set of labeled radio buttons
467 else if ($data_type == 27) {
468 // In this special case, fld_length is the number of columns generated.
469 $cols = max(1, $frow['fld_length']);
470 $lres = sqlStatement("SELECT * FROM list_options " .
471 "WHERE list_id = '$list_id' ORDER BY seq, title");
472 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
473 $tdpct = (int) (100 / $cols);
474 $got_selected = FALSE;
475 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
476 $option_id = $lrow['option_id'];
477 if ($count % $cols == 0) {
478 if ($count) echo "</tr>";
479 echo "<tr>";
481 echo "<td width='$tdpct%'>";
482 echo "<input type='radio' name='form_{$field_id}' id='form_{$field_id}[$option_id]' value='$option_id'";
483 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
484 (strlen($currvalue) > 0 && $option_id == $currvalue))
486 echo " checked";
487 $got_selected = TRUE;
489 echo ">" . xl_list_label($lrow['title']);
490 echo "</td>";
492 if ($count) {
493 echo "</tr>";
494 if ($count > $cols) {
495 // Add some space after multiple rows of radio buttons.
496 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
499 echo "</table>";
500 if (!$got_selected && strlen($currvalue) > 0) {
501 echo "$currvalue <font color='red' title='" . xl('Please choose a valid selection.') . "'>" . xl('Fix this') . "!</font>";
505 // special case for history of lifestyle status; 3 radio buttons and a date text field:
506 else if ($data_type == 28) {
507 $tmp = explode('|', $currvalue);
508 switch(count($tmp)) {
509 case "3": {
510 $resnote = $tmp[0];
511 $restype = $tmp[1];
512 $resdate = $tmp[2];
513 } break;
514 case "2": {
515 $resnote = $tmp[0];
516 $restype = $tmp[1];
517 $resdate = "";
518 } break;
519 case "1": {
520 $resnote = $tmp[0];
521 $resdate = $restype = "";
522 } break;
523 default: {
524 $restype = $resdate = $resnote = "";
525 } break;
527 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
528 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
530 echo "<table cellpadding='0' cellspacing='0'>";
531 echo "<tr>";
532 // input text
533 echo "<td><input type='text'" .
534 " name='form_$field_id'" .
535 " id='form_$field_id'" .
536 " size='$fldlength'" .
537 " maxlength='$maxlength'" .
538 " value='$resnote' />&nbsp;</td>";
539 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;".xl('Status').":&nbsp;</td>";
540 // current
541 echo "<td><input type='radio'" .
542 " name='radio_{$field_id}'" .
543 " id='radio_{$field_id}[current]'" .
544 " value='current".$field_id."'";
545 if ($restype == "current".$field_id) echo " checked";
546 // echo " onclick=\"return clinical_alerts_popup(this.value,'Patient_History')\" />".xl('Current')."&nbsp;</td>";
547 echo "/>".xl('Current')."&nbsp;</td>";
548 // quit
549 echo "<td><input type='radio'" .
550 " name='radio_{$field_id}'" .
551 " id='radio_{$field_id}[quit]'" .
552 " value='quit".$field_id."'";
553 if ($restype == "quit".$field_id) echo " checked";
554 echo "/>".xl('Quit')."&nbsp;</td>";
555 // quit date
556 echo "<td><input type='text' size='6' name='date_$field_id' id='date_$field_id'" .
557 " value='$resdate'" .
558 " title='$description'" .
559 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
560 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
561 " id='img_$field_id' border='0' alt='[?]' style='cursor:pointer'" .
562 " title='" . xl('Click here to choose a date') . "' />&nbsp;</td>";
563 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
564 // never
565 echo "<td><input type='radio'" .
566 " name='radio_{$field_id}'" .
567 " id='radio_{$field_id}[never]'" .
568 " value='never".$field_id."'";
569 if ($restype == "never".$field_id) echo " checked";
570 echo " />".xl('Never')."&nbsp;</td>";
571 // Not Applicable
572 echo "<td><input type='radio'" .
573 " name='radio_{$field_id}'" .
574 " id='radio_{$field_id}[not_applicable]'" .
575 " value='not_applicable".$field_id."'";
576 if ($restype == "not_applicable".$field_id) echo " checked";
577 echo " />".xl('N/A')."&nbsp;</td>";
578 echo "</tr>";
579 echo "</table>";
584 function generate_print_field($frow, $currvalue) {
585 global $rootdir, $date_init;
587 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
589 $data_type = $frow['data_type'];
590 $field_id = $frow['field_id'];
591 $list_id = $frow['list_id'];
592 $fld_length = $frow['fld_length'];
594 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
596 // Can pass $frow['empty_title'] with this variable, otherwise
597 // will default to 'Unassigned'.
598 // If it is 'SKIP' then an empty text title is completely skipped.
599 $showEmpty = true;
600 if (isset($frow['empty_title'])) {
601 if ($frow['empty_title'] == "SKIP") {
602 //do not display an 'empty' choice
603 $showEmpty = false;
604 $empty_title = "Unassigned";
606 else {
607 $empty_title = $frow['empty_title'];
610 else {
611 $empty_title = "Unassigned";
614 // generic single-selection list
615 if ($data_type == 1 || $data_type == 26) {
616 if (empty($fld_length)) {
617 if ($list_id == 'titles') {
618 $fld_length = 3;
619 } else {
620 $fld_length = 10;
623 $tmp = '';
624 if ($currvalue) {
625 $lrow = sqlQuery("SELECT title FROM list_options " .
626 "WHERE list_id = '$list_id' AND option_id = '$currvalue'");
627 $tmp = xl_list_label($lrow['title']);
628 if (empty($tmp)) $tmp = "($currvalue)";
630 /*****************************************************************
631 echo "<input type='text'" .
632 " size='$fld_length'" .
633 " value='$tmp'" .
634 " class='under'" .
635 " />";
636 *****************************************************************/
637 if ($tmp === '') $tmp = '&nbsp;';
638 echo $tmp;
641 // simple text field
642 else if ($data_type == 2 || $data_type == 15) {
643 /*****************************************************************
644 echo "<input type='text'" .
645 " size='$fld_length'" .
646 " value='$currescaped'" .
647 " class='under'" .
648 " />";
649 *****************************************************************/
650 if ($currescaped === '') $currescaped = '&nbsp;';
651 echo $currescaped;
654 // long or multi-line text field
655 else if ($data_type == 3) {
656 echo "<textarea" .
657 " cols='$fld_length'" .
658 " rows='" . $frow['max_length'] . "'>" .
659 $currescaped . "</textarea>";
662 // date
663 else if ($data_type == 4) {
664 /*****************************************************************
665 echo "<input type='text' size='10'" .
666 " value='$currescaped'" .
667 " title='$description'" .
668 " class='under'" .
669 " />";
670 *****************************************************************/
671 if ($currescaped === '') $currescaped = '&nbsp;';
672 echo oeFormatShortDate($currescaped);
675 // provider list
676 else if ($data_type == 10 || $data_type == 11) {
677 $tmp = '';
678 if ($currvalue) {
679 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
680 "WHERE id = '$currvalue'");
681 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
682 if (empty($tmp)) $tmp = "($currvalue)";
684 /*****************************************************************
685 echo "<input type='text'" .
686 " size='$fld_length'" .
687 " value='$tmp'" .
688 " class='under'" .
689 " />";
690 *****************************************************************/
691 if ($tmp === '') $tmp = '&nbsp;';
692 echo $tmp;
695 // pharmacy list
696 else if ($data_type == 12) {
697 $tmp = '';
698 if ($currvalue) {
699 $pres = get_pharmacies();
700 while ($prow = sqlFetchArray($pres)) {
701 $key = $prow['id'];
702 if ($currvalue == $key) {
703 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
704 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
705 $prow['line1'] . ' / ' . $prow['city'];
708 if (empty($tmp)) $tmp = "($currvalue)";
710 /*****************************************************************
711 echo "<input type='text'" .
712 " size='$fld_length'" .
713 " value='$tmp'" .
714 " class='under'" .
715 " />";
716 *****************************************************************/
717 if ($tmp === '') $tmp = '&nbsp;';
718 echo $tmp;
721 // squads
722 else if ($data_type == 13) {
723 $tmp = '';
724 if ($currvalue) {
725 $squads = acl_get_squads();
726 if ($squads) {
727 foreach ($squads as $key => $value) {
728 if ($currvalue == $key) {
729 $tmp = $value[3];
733 if (empty($tmp)) $tmp = "($currvalue)";
735 /*****************************************************************
736 echo "<input type='text'" .
737 " size='$fld_length'" .
738 " value='$tmp'" .
739 " class='under'" .
740 " />";
741 *****************************************************************/
742 if ($tmp === '') $tmp = '&nbsp;';
743 echo $tmp;
746 // Address book.
747 else if ($data_type == 14) {
748 $tmp = '';
749 if ($currvalue) {
750 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
751 "WHERE id = '$currvalue'");
752 $uname = $urow['lname'];
753 if ($urow['fname']) $uname .= ", " . $urow['fname'];
754 $tmp = $uname;
755 if (empty($tmp)) $tmp = "($currvalue)";
757 /*****************************************************************
758 echo "<input type='text'" .
759 " size='$fld_length'" .
760 " value='$tmp'" .
761 " class='under'" .
762 " />";
763 *****************************************************************/
764 if ($tmp === '') $tmp = '&nbsp;';
765 echo $tmp;
768 // a set of labeled checkboxes
769 else if ($data_type == 21) {
770 // In this special case, fld_length is the number of columns generated.
771 $cols = max(1, $fld_length);
772 $avalue = explode('|', $currvalue);
773 $lres = sqlStatement("SELECT * FROM list_options " .
774 "WHERE list_id = '$list_id' ORDER BY seq, title");
775 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
776 $tdpct = (int) (100 / $cols);
777 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
778 $option_id = $lrow['option_id'];
779 if ($count % $cols == 0) {
780 if ($count) echo "</tr>";
781 echo "<tr>";
783 echo "<td width='$tdpct%'>";
784 echo "<input type='checkbox'";
785 if (in_array($option_id, $avalue)) echo " checked";
786 echo ">" . xl_list_label($lrow['title']);
787 echo "</td>";
789 if ($count) {
790 echo "</tr>";
791 if ($count > $cols) {
792 // Add some space after multiple rows of checkboxes.
793 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
796 echo "</table>";
799 // a set of labeled text input fields
800 else if ($data_type == 22) {
801 $tmp = explode('|', $currvalue);
802 $avalue = array();
803 foreach ($tmp as $value) {
804 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
805 $avalue[$matches[1]] = $matches[2];
808 $lres = sqlStatement("SELECT * FROM list_options " .
809 "WHERE list_id = '$list_id' ORDER BY seq, title");
810 echo "<table cellpadding='0' cellspacing='0'>";
811 while ($lrow = sqlFetchArray($lres)) {
812 $option_id = $lrow['option_id'];
813 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
814 $fldlength = empty($fld_length) ? 20 : $fld_length;
815 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
816 echo "<td><input type='text'" .
817 " size='$fldlength'" .
818 " value='" . $avalue[$option_id] . "'" .
819 " class='under'" .
820 " /></td></tr>";
822 echo "</table>";
825 // a set of exam results; 3 radio buttons and a text field:
826 else if ($data_type == 23) {
827 $tmp = explode('|', $currvalue);
828 $avalue = array();
829 foreach ($tmp as $value) {
830 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
831 $avalue[$matches[1]] = $matches[2];
834 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
835 $fldlength = empty($fld_length) ? 20 : $fld_length;
836 $lres = sqlStatement("SELECT * FROM list_options " .
837 "WHERE list_id = '$list_id' ORDER BY seq, title");
838 echo "<table cellpadding='0' cellspacing='0'>";
839 echo "<tr><td>&nbsp;</td><td class='bold'>" . xl('N/A') .
840 "&nbsp;</td><td class='bold'>" . xl('Nor') . "&nbsp;</td>" .
841 "<td class='bold'>" . xl('Abn') . "&nbsp;</td><td class='bold'>" .
842 xl('Date/Notes') . "</td></tr>";
843 while ($lrow = sqlFetchArray($lres)) {
844 $option_id = $lrow['option_id'];
845 $restype = substr($avalue[$option_id], 0, 1);
846 $resnote = substr($avalue[$option_id], 2);
847 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
848 for ($i = 0; $i < 3; ++$i) {
849 echo "<td><input type='radio'";
850 if ($restype === "$i") echo " checked";
851 echo " /></td>";
853 echo "<td><input type='text'" .
854 " size='$fldlength'" .
855 " value='$resnote'" .
856 " class='under' /></td>" .
857 "</tr>";
859 echo "</table>";
862 // the list of active allergies for the current patient
863 // this is read-only!
864 else if ($data_type == 24) {
865 $query = "SELECT title, comments FROM lists WHERE " .
866 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
867 "ORDER BY begdate";
868 $lres = sqlStatement($query);
869 $count = 0;
870 while ($lrow = sqlFetchArray($lres)) {
871 if ($count++) echo "<br />";
872 echo $lrow['title'];
873 if ($lrow['comments']) echo ' (' . $lrow['comments'] . ')';
877 // a set of labeled checkboxes, each with a text field:
878 else if ($data_type == 25) {
879 $tmp = explode('|', $currvalue);
880 $avalue = array();
881 foreach ($tmp as $value) {
882 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
883 $avalue[$matches[1]] = $matches[2];
886 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
887 $fldlength = empty($fld_length) ? 20 : $fld_length;
888 $lres = sqlStatement("SELECT * FROM list_options " .
889 "WHERE list_id = '$list_id' ORDER BY seq, title");
890 echo "<table cellpadding='0' cellspacing='0'>";
891 while ($lrow = sqlFetchArray($lres)) {
892 $option_id = $lrow['option_id'];
893 $restype = substr($avalue[$option_id], 0, 1);
894 $resnote = substr($avalue[$option_id], 2);
895 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
896 echo "<td><input type='checkbox'";
897 if ($restype) echo " checked";
898 echo " />&nbsp;</td>";
899 echo "<td><input type='text'" .
900 " size='$fldlength'" .
901 " value='$resnote'" .
902 " class='under'" .
903 " /></td>" .
904 "</tr>";
906 echo "</table>";
909 // a set of labeled radio buttons
910 else if ($data_type == 27) {
911 // In this special case, fld_length is the number of columns generated.
912 $cols = max(1, $frow['fld_length']);
913 $lres = sqlStatement("SELECT * FROM list_options " .
914 "WHERE list_id = '$list_id' ORDER BY seq, title");
915 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
916 $tdpct = (int) (100 / $cols);
917 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
918 $option_id = $lrow['option_id'];
919 if ($count % $cols == 0) {
920 if ($count) echo "</tr>";
921 echo "<tr>";
923 echo "<td width='$tdpct%'>";
924 echo "<input type='radio'";
925 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
926 (strlen($currvalue) > 0 && $option_id == $currvalue))
928 echo " checked";
930 echo ">" . xl_list_label($lrow['title']);
931 echo "</td>";
933 if ($count) {
934 echo "</tr>";
935 if ($count > $cols) {
936 // Add some space after multiple rows of radio buttons.
937 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
940 echo "</table>";
943 // special case for history of lifestyle status; 3 radio buttons and a date text field:
944 else if ($data_type == 28) {
945 $tmp = explode('|', $currvalue);
946 switch(count($tmp)) {
947 case "3": {
948 $resnote = $tmp[0];
949 $restype = $tmp[1];
950 $resdate = $tmp[2];
951 } break;
952 case "2": {
953 $resnote = $tmp[0];
954 $restype = $tmp[1];
955 $resdate = "";
956 } break;
957 case "1": {
958 $resnote = $tmp[0];
959 $resdate = $restype = "";
960 } break;
961 default: {
962 $restype = $resdate = $resnote = "";
963 } break;
965 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
966 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
967 echo "<table cellpadding='0' cellspacing='0'>";
968 echo "<tr>";
970 echo "<td><input type='text'" .
971 " size='$fldlength'" .
972 " class='under'" .
973 " value='$resnote' /></td>";
974 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;".xl('Status').":&nbsp;</td>";
975 echo "<td><input type='radio'";
976 if ($restype == "current".$field_id) echo " checked";
977 echo "/>".xl('Current')."&nbsp;</td>";
979 echo "<td><input type='radio'";
980 if ($restype == "current".$field_id) echo " checked";
981 echo "/>".xl('Quit')."&nbsp;</td>";
983 echo "<td><input type='text' size='6'" .
984 " value='$resdate'" .
985 " class='under'" .
986 " /></td>";
988 echo "<td><input type='radio'";
989 if ($restype == "current".$field_id) echo " checked";
990 echo " />".xl('Never')."</td>";
992 echo "<td><input type='radio'";
993 if ($restype == "not_applicable".$field_id) echo " checked";
994 echo " />".xl('N/A')."&nbsp;</td>";
995 echo "</tr>";
996 echo "</table>";
1001 function generate_display_field($frow, $currvalue) {
1002 $data_type = $frow['data_type'];
1003 $field_id = $frow['field_id'];
1004 $list_id = $frow['list_id'];
1005 $s = '';
1007 // generic selection list or the generic selection list with add on the fly
1008 // feature, or radio buttons
1009 if ($data_type == 1 || $data_type == 26 || $data_type == 27) {
1010 $lrow = sqlQuery("SELECT title FROM list_options " .
1011 "WHERE list_id = '$list_id' AND option_id = '$currvalue'");
1012 $s = xl_list_label($lrow['title']);
1015 // simple text field
1016 else if ($data_type == 2) {
1017 $s = $currvalue;
1020 // long or multi-line text field
1021 else if ($data_type == 3) {
1022 $s = nl2br($currvalue);
1025 // date
1026 else if ($data_type == 4) {
1027 $s = oeFormatShortDate($currvalue);
1030 // provider
1031 else if ($data_type == 10 || $data_type == 11) {
1032 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1033 "WHERE id = '$currvalue'");
1034 $s = ucwords($urow['fname'] . " " . $urow['lname']);
1037 // pharmacy list
1038 else if ($data_type == 12) {
1039 $pres = get_pharmacies();
1040 while ($prow = sqlFetchArray($pres)) {
1041 $key = $prow['id'];
1042 if ($currvalue == $key) {
1043 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
1044 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1045 $prow['line1'] . ' / ' . $prow['city'];
1050 // squads
1051 else if ($data_type == 13) {
1052 $squads = acl_get_squads();
1053 if ($squads) {
1054 foreach ($squads as $key => $value) {
1055 if ($currvalue == $key) {
1056 $s .= $value[3];
1062 // address book
1063 else if ($data_type == 14) {
1064 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1065 "WHERE id = '$currvalue'");
1066 $uname = $urow['lname'];
1067 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1068 $s = $uname;
1071 // billing code
1072 else if ($data_type == 15) {
1073 $s = $currvalue;
1076 // a set of labeled checkboxes
1077 else if ($data_type == 21) {
1078 $avalue = explode('|', $currvalue);
1079 $lres = sqlStatement("SELECT * FROM list_options " .
1080 "WHERE list_id = '$list_id' ORDER BY seq, title");
1081 $count = 0;
1082 while ($lrow = sqlFetchArray($lres)) {
1083 $option_id = $lrow['option_id'];
1084 if (in_array($option_id, $avalue)) {
1085 if ($count++) $s .= "<br />";
1087 // Added 5-09 by BM - Translate label if applicable
1088 $s .= xl_list_label($lrow['title']);
1094 // a set of labeled text input fields
1095 else if ($data_type == 22) {
1096 $tmp = explode('|', $currvalue);
1097 $avalue = array();
1098 foreach ($tmp as $value) {
1099 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1100 $avalue[$matches[1]] = $matches[2];
1103 $lres = sqlStatement("SELECT * FROM list_options " .
1104 "WHERE list_id = '$list_id' ORDER BY seq, title");
1105 $s .= "<table cellpadding='0' cellspacing='0'>";
1106 while ($lrow = sqlFetchArray($lres)) {
1107 $option_id = $lrow['option_id'];
1108 if (empty($avalue[$option_id])) continue;
1110 // Added 5-09 by BM - Translate label if applicable
1111 $s .= "<tr><td class='bold' valign='top'>" . xl_list_label($lrow['title']) . ":&nbsp;</td>";
1113 $s .= "<td class='text' valign='top'>" . $avalue[$option_id] . "</td></tr>";
1115 $s .= "</table>";
1118 // a set of exam results; 3 radio buttons and a text field:
1119 else if ($data_type == 23) {
1120 $tmp = explode('|', $currvalue);
1121 $avalue = array();
1122 foreach ($tmp as $value) {
1123 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1124 $avalue[$matches[1]] = $matches[2];
1127 $lres = sqlStatement("SELECT * FROM list_options " .
1128 "WHERE list_id = '$list_id' ORDER BY seq, title");
1129 $s .= "<table cellpadding='0' cellspacing='0'>";
1130 while ($lrow = sqlFetchArray($lres)) {
1131 $option_id = $lrow['option_id'];
1132 $restype = substr($avalue[$option_id], 0, 1);
1133 $resnote = substr($avalue[$option_id], 2);
1134 if (empty($restype) && empty($resnote)) continue;
1136 // Added 5-09 by BM - Translate label if applicable
1137 $s .= "<tr><td class='bold' valign='top'>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
1139 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1140 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1141 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1142 $s .= "<td class='text' valign='top'>$restype&nbsp;</td>";
1143 $s .= "<td class='text' valign='top'>$resnote</td>";
1144 $s .= "</tr>";
1146 $s .= "</table>";
1149 // the list of active allergies for the current patient
1150 else if ($data_type == 24) {
1151 $query = "SELECT title, comments FROM lists WHERE " .
1152 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
1153 "ORDER BY begdate";
1154 // echo "<!-- $query -->\n"; // debugging
1155 $lres = sqlStatement($query);
1156 $count = 0;
1157 while ($lrow = sqlFetchArray($lres)) {
1158 if ($count++) $s .= "<br />";
1159 $s .= $lrow['title'];
1160 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
1164 // a set of labeled checkboxes, each with a text field:
1165 else if ($data_type == 25) {
1166 $tmp = explode('|', $currvalue);
1167 $avalue = array();
1168 foreach ($tmp as $value) {
1169 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1170 $avalue[$matches[1]] = $matches[2];
1173 $lres = sqlStatement("SELECT * FROM list_options " .
1174 "WHERE list_id = '$list_id' ORDER BY seq, title");
1175 $s .= "<table cellpadding='0' cellspacing='0'>";
1176 while ($lrow = sqlFetchArray($lres)) {
1177 $option_id = $lrow['option_id'];
1178 $restype = substr($avalue[$option_id], 0, 1);
1179 $resnote = substr($avalue[$option_id], 2);
1180 if (empty($restype) && empty($resnote)) continue;
1182 // Added 5-09 by BM - Translate label if applicable
1183 $s .= "<tr><td class='bold' valign='top'>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
1185 $restype = $restype ? xl('Yes') : xl('No');
1186 $s .= "<td class='text' valign='top'>$restype</td></tr>";
1187 $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1188 $s .= "</tr>";
1190 $s .= "</table>";
1193 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1194 else if ($data_type == 28) {
1195 $tmp = explode('|', $currvalue);
1196 switch(count($tmp)) {
1197 case "3": {
1198 $resnote = $tmp[0];
1199 $restype = $tmp[1];
1200 $resdate = $tmp[2];
1201 } break;
1202 case "2": {
1203 $resnote = $tmp[0];
1204 $restype = $tmp[1];
1205 $resdate = "";
1206 } break;
1207 case "1": {
1208 $resnote = $tmp[0];
1209 $resdate = $restype = "";
1210 } break;
1211 default: {
1212 $restype = $resdate = $resnote = "";
1213 } break;
1215 $s .= "<table cellpadding='0' cellspacing='0'>";
1217 $s .= "<tr>";
1218 $res = "";
1219 if ($restype == "current".$field_id) $res = xl('Current');
1220 if ($restype == "quit".$field_id) $res = xl('Quit');
1221 if ($restype == "never".$field_id) $res = xl('Never');
1222 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1223 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1224 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1225 if (!empty($resnote)) $s .= "<td class='text' valign='top'>$resnote&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1226 if (!empty($res)) $s .= "<td class='text' valign='top'><b>".xl('Status')."</b>:&nbsp;".$res."&nbsp;</td>";
1227 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>$resdate&nbsp;</td>";
1228 $s .= "</tr>";
1229 $s .= "</table>";
1232 return $s;
1235 $CPR = 4; // cells per row of generic data
1236 $last_group = '';
1237 $cell_count = 0;
1238 $item_count = 0;
1240 function disp_end_cell() {
1241 global $item_count, $cell_count;
1242 if ($item_count > 0) {
1243 echo "</td>";
1244 $item_count = 0;
1248 function disp_end_row() {
1249 global $cell_count, $CPR;
1250 disp_end_cell();
1251 if ($cell_count > 0) {
1252 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
1253 echo "</tr>\n";
1254 $cell_count = 0;
1258 function disp_end_group() {
1259 global $last_group;
1260 if (strlen($last_group) > 0) {
1261 disp_end_row();
1265 function display_layout_rows($formtype, $result1, $result2='') {
1266 global $item_count, $cell_count, $last_group, $CPR;
1268 $fres = sqlStatement("SELECT * FROM layout_options " .
1269 "WHERE form_id = '$formtype' AND uor > 0 " .
1270 "ORDER BY group_name, seq");
1272 while ($frow = sqlFetchArray($fres)) {
1273 $this_group = $frow['group_name'];
1274 $titlecols = $frow['titlecols'];
1275 $datacols = $frow['datacols'];
1276 $data_type = $frow['data_type'];
1277 $field_id = $frow['field_id'];
1278 $list_id = $frow['list_id'];
1279 $currvalue = '';
1281 if ($formtype == 'DEM') {
1282 if ($GLOBALS['athletic_team']) {
1283 // Skip fitness level and return-to-play date because those appear
1284 // in a special display/update form on this page.
1285 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1287 if (strpos($field_id, 'em_') === 0) {
1288 // Skip employer related fields, if it's disabled.
1289 if ($GLOBALS['omit_employers']) continue;
1290 $tmp = substr($field_id, 3);
1291 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1293 else {
1294 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1297 else {
1298 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1301 // Handle a data category (group) change.
1302 if (strcmp($this_group, $last_group) != 0) {
1303 $group_name = substr($this_group, 1);
1304 // totally skip generating the employer category, if it's disabled.
1305 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1306 disp_end_group();
1307 $last_group = $this_group;
1310 // Handle starting of a new row.
1311 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1312 disp_end_row();
1313 echo "<tr>";
1314 if ($group_name) {
1315 echo "<td class='groupname'>";
1316 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1317 //echo "<font color='#008800'>$group_name</font>";
1319 // Added 5-09 by BM - Translate label if applicable
1320 echo (xl_layout_label($group_name));
1322 $group_name = '';
1323 } else {
1324 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1325 echo "<td valign='top'>&nbsp;";
1327 echo "</td>";
1330 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1332 // Handle starting of a new label cell.
1333 if ($titlecols > 0) {
1334 disp_end_cell();
1335 //echo "<td class='label' colspan='$titlecols' valign='top'";
1336 echo "<td class='label' colspan='$titlecols' ";
1337 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1338 echo ">";
1339 $cell_count += $titlecols;
1341 ++$item_count;
1343 // Added 5-09 by BM - Translate label if applicable
1344 if ($frow['title']) echo (xl_layout_label($frow['title']).":"); else echo "&nbsp;";
1346 // Handle starting of a new data cell.
1347 if ($datacols > 0) {
1348 disp_end_cell();
1349 //echo "<td class='text data' colspan='$datacols' valign='top'";
1350 echo "<td class='text data' colspan='$datacols'";
1351 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1352 echo ">";
1353 $cell_count += $datacols;
1356 ++$item_count;
1357 echo generate_display_field($frow, $currvalue);
1360 disp_end_group();
1363 function display_layout_tabs($formtype, $result1, $result2='') {
1364 global $item_count, $cell_count, $last_group, $CPR;
1366 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1367 "WHERE form_id = '$formtype' AND uor > 0 " .
1368 "ORDER BY group_name, seq");
1370 $first = true;
1371 while ($frow = sqlFetchArray($fres)) {
1372 $this_group = $frow['group_name'];
1373 $group_name = substr($this_group, 1);
1375 <li <?php echo $first ? 'class="current"' : '' ?>>
1376 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo $group_name?>"><?php echo xl_layout_label($group_name); ?></a>
1377 </li>
1378 <?php
1379 $first = false;
1383 function display_layout_tabs_data($formtype, $result1, $result2='') {
1384 global $item_count, $cell_count, $last_group, $CPR;
1386 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1387 "WHERE form_id = '$formtype' AND uor > 0 " .
1388 "ORDER BY group_name, seq");
1390 $first = true;
1391 while ($frow = sqlFetchArray($fres)) {
1392 $this_group = $frow['group_name'];
1393 $titlecols = $frow['titlecols'];
1394 $datacols = $frow['datacols'];
1395 $data_type = $frow['data_type'];
1396 $field_id = $frow['field_id'];
1397 $list_id = $frow['list_id'];
1398 $currvalue = '';
1400 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1401 "WHERE form_id = '$formtype' AND uor > 0 AND group_name = '$this_group' " .
1402 "ORDER BY seq");
1405 <div class="tab <?php echo $first ? 'current' : '' ?>">
1406 <table border='0' cellpadding='0'>
1408 <?php
1409 while ($group_fields = sqlFetchArray($group_fields_query)) {
1411 $titlecols = $group_fields['titlecols'];
1412 $datacols = $group_fields['datacols'];
1413 $data_type = $group_fields['data_type'];
1414 $field_id = $group_fields['field_id'];
1415 $list_id = $group_fields['list_id'];
1416 $currvalue = '';
1418 if ($formtype == 'DEM') {
1419 if ($GLOBALS['athletic_team']) {
1420 // Skip fitness level and return-to-play date because those appear
1421 // in a special display/update form on this page.
1422 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1424 if (strpos($field_id, 'em_') === 0) {
1425 // Skip employer related fields, if it's disabled.
1426 if ($GLOBALS['omit_employers']) continue;
1427 $tmp = substr($field_id, 3);
1428 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1430 else {
1431 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1434 else {
1435 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1438 // Handle a data category (group) change.
1439 if (strcmp($this_group, $last_group) != 0) {
1440 $group_name = substr($this_group, 1);
1441 // totally skip generating the employer category, if it's disabled.
1442 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1443 $last_group = $this_group;
1446 // Handle starting of a new row.
1447 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1448 disp_end_row();
1449 echo "<tr>";
1452 if ($item_count == 0 && $titlecols == 0) {
1453 $titlecols = 1;
1456 // Handle starting of a new label cell.
1457 if ($titlecols > 0) {
1458 disp_end_cell();
1459 echo "<td class='label' colspan='$titlecols' ";
1460 echo ">";
1461 $cell_count += $titlecols;
1463 ++$item_count;
1465 // Added 5-09 by BM - Translate label if applicable
1466 if ($group_fields['title']) echo (xl_layout_label($group_fields['title']).":"); else echo "&nbsp;";
1468 // Handle starting of a new data cell.
1469 if ($datacols > 0) {
1470 disp_end_cell();
1471 echo "<td class='text data' colspan='$datacols'";
1472 echo ">";
1473 $cell_count += $datacols;
1476 ++$item_count;
1477 echo generate_display_field($group_fields, $currvalue);
1481 </table>
1482 </div>
1484 <?php
1486 $first = false;
1492 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1493 global $item_count, $cell_count, $last_group, $CPR;
1495 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1496 "WHERE form_id = '$formtype' AND uor > 0 " .
1497 "ORDER BY group_name, seq");
1499 $first = true;
1500 while ($frow = sqlFetchArray($fres)) {
1501 $this_group = $frow['group_name'];
1502 $group_name = substr($this_group, 1);
1503 $titlecols = $frow['titlecols'];
1504 $datacols = $frow['datacols'];
1505 $data_type = $frow['data_type'];
1506 $field_id = $frow['field_id'];
1507 $list_id = $frow['list_id'];
1508 $currvalue = '';
1510 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1511 "WHERE form_id = '$formtype' AND uor > 0 AND group_name = '$this_group' " .
1512 "ORDER BY seq");
1515 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name?>" >
1516 <table border='0' cellpadding='0'>
1518 <?php
1519 while ($group_fields = sqlFetchArray($group_fields_query)) {
1521 $titlecols = $group_fields['titlecols'];
1522 $datacols = $group_fields['datacols'];
1523 $data_type = $group_fields['data_type'];
1524 $field_id = $group_fields['field_id'];
1525 $list_id = $group_fields['list_id'];
1526 $currvalue = '';
1528 if ($formtype == 'DEM') {
1529 if ($GLOBALS['athletic_team']) {
1530 // Skip fitness level and return-to-play date because those appear
1531 // in a special display/update form on this page.
1532 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1534 if (strpos($field_id, 'em_') === 0) {
1535 // Skip employer related fields, if it's disabled.
1536 if ($GLOBALS['omit_employers']) continue;
1537 $tmp = substr($field_id, 3);
1538 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1540 else {
1541 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1544 else {
1545 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1548 // Handle a data category (group) change.
1549 if (strcmp($this_group, $last_group) != 0) {
1550 $group_name = substr($this_group, 1);
1551 // totally skip generating the employer category, if it's disabled.
1552 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1553 $last_group = $this_group;
1556 // Handle starting of a new row.
1557 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1558 disp_end_row();
1559 echo "<tr>";
1562 if ($item_count == 0 && $titlecols == 0) {
1563 $titlecols = 1;
1566 // Handle starting of a new label cell.
1567 if ($titlecols > 0) {
1568 disp_end_cell();
1569 echo "<td class='label' colspan='$titlecols' ";
1570 echo ">";
1571 $cell_count += $titlecols;
1573 ++$item_count;
1575 // Added 5-09 by BM - Translate label if applicable
1576 if ($group_fields['title']) echo (xl_layout_label($group_fields['title']).":"); else echo "&nbsp;";
1578 // Handle starting of a new data cell.
1579 if ($datacols > 0) {
1580 disp_end_cell();
1581 echo "<td class='text data' colspan='$datacols'";
1582 echo ">";
1583 $cell_count += $datacols;
1586 ++$item_count;
1587 echo generate_form_field($group_fields, $currvalue);
1591 </table>
1592 </div>
1594 <?php
1596 $first = false;
1601 // From the currently posted HTML form, this gets the value of the
1602 // field corresponding to the provided layout_options table row.
1604 function get_layout_form_value($frow, $maxlength=255) {
1605 $data_type = $frow['data_type'];
1606 $field_id = $frow['field_id'];
1607 $value = '';
1608 if (isset($_POST["form_$field_id"])) {
1609 if ($data_type == 21) {
1610 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1611 // must be concatenated into a |-separated string.
1612 foreach ($_POST["form_$field_id"] as $key => $val) {
1613 if (strlen($value)) $value .= '|';
1614 $value .= $key;
1617 else if ($data_type == 22) {
1618 // $_POST["form_$field_id"] is an array of text fields to be imploded
1619 // into "key:value|key:value|...".
1620 foreach ($_POST["form_$field_id"] as $key => $val) {
1621 $val = str_replace('|', ' ', $val);
1622 if (strlen($value)) $value .= '|';
1623 $value .= "$key:$val";
1626 else if ($data_type == 23) {
1627 // $_POST["form_$field_id"] is an array of text fields with companion
1628 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1629 foreach ($_POST["form_$field_id"] as $key => $val) {
1630 $restype = $_POST["radio_{$field_id}"][$key];
1631 if (empty($restype)) $restype = '0';
1632 $val = str_replace('|', ' ', $val);
1633 if (strlen($value)) $value .= '|';
1634 $value .= "$key:$restype:$val";
1637 else if ($data_type == 25) {
1638 // $_POST["form_$field_id"] is an array of text fields with companion
1639 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1640 foreach ($_POST["form_$field_id"] as $key => $val) {
1641 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
1642 $val = str_replace('|', ' ', $val);
1643 if (strlen($value)) $value .= '|';
1644 $value .= "$key:$restype:$val";
1647 else if ($data_type == 28) {
1648 // $_POST["form_$field_id"] is an date text fields with companion
1649 // radio buttons to be imploded into "notes|type|date".
1650 $restype = $_POST["radio_{$field_id}"];
1651 if (empty($restype)) $restype = '0';
1652 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1653 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1654 $value = "$resnote|$restype|$resdate";
1656 else {
1657 $value = $_POST["form_$field_id"];
1661 // Better to die than to silently truncate data!
1662 if ($maxlength && $data_type != 3 && strlen($value) > $maxlength)
1663 die(xl('ERROR: Field') . " '$field_id' " . xl('is too long') .
1664 ":<br />&nbsp;<br />$value");
1666 // Make sure the return value is quote-safe.
1667 return formTrim($value);
1670 // Generate JavaScript validation logic for the required fields.
1672 function generate_layout_validation($form_id) {
1673 $fres = sqlStatement("SELECT * FROM layout_options " .
1674 "WHERE form_id = '$form_id' AND uor > 0 AND field_id != '' " .
1675 "ORDER BY group_name, seq");
1677 while ($frow = sqlFetchArray($fres)) {
1678 if ($frow['uor'] < 2) continue;
1679 $data_type = $frow['data_type'];
1680 $field_id = $frow['field_id'];
1681 $fldtitle = $frow['title'];
1682 if (!$fldtitle) $fldtitle = $frow['description'];
1683 $fldname = "form_$field_id";
1684 switch($data_type) {
1685 case 1:
1686 case 11:
1687 case 12:
1688 case 13:
1689 case 14:
1690 case 26:
1691 echo
1692 " if (f.$fldname.selectedIndex <= 0) {\n" .
1693 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1694 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
1695 " }\n";
1696 break;
1697 case 27: // radio buttons
1698 echo
1699 " var i = 0;\n" .
1700 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
1701 " if (i >= f.$fldname.length) {\n" .
1702 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
1703 " }\n";
1704 break;
1705 case 2:
1706 case 3:
1707 case 4:
1708 case 15:
1709 echo
1710 " if (trimlen(f.$fldname.value) == 0) {\n" .
1711 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1712 " $('#form_" . $field_id . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
1713 " $('#form_" . $field_id . "').attr('style','background:red'); \n" .
1714 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
1715 " } else { " .
1716 " $('#form_" . $field_id . "').attr('style',''); " .
1717 " $('#form_" . $field_id . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
1718 " } \n";
1719 break;
1725 * DROPDOWN FOR FACILITIES
1727 * build a dropdown with all facilities
1729 * @param string $selected - name of the currently selected facility
1730 * use '0' for "unspecified facility"
1731 * use '' for "All facilities" (the default)
1732 * @param string $name - the name/id for select form (defaults to "form_facility")
1733 * @param boolean $allow_unspecified - include an option for "unspecified" facility
1734 * defaults to true
1735 * @return void - just echo the html encoded string
1737 * Note: This should become a data-type at some point, according to Brady
1739 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true) {
1740 $have_selected = false;
1741 $query = "SELECT id, name FROM facility ORDER BY name";
1742 $fres = sqlStatement($query);
1744 $name = htmlspecialchars($name, ENT_QUOTES);
1745 echo " <select name=\"$name\">\n";
1747 $option_value = '';
1748 $option_selected_attr = '';
1749 if ($selected == '') {
1750 $option_selected_attr = ' selected="selected"';
1751 $have_selected = true;
1753 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
1754 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1756 while ($frow = sqlFetchArray($fres)) {
1757 $facility_id = $frow['id'];
1758 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
1759 $option_selected_attr = '';
1760 if ($selected == $facility_id) {
1761 $option_selected_attr = ' selected="selected"';
1762 $have_selected = true;
1764 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
1765 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1768 if ($allow_unspecified) {
1769 $option_value = '0';
1770 $option_selected_attr = '';
1771 if ( $selected == '0' ) {
1772 $option_selected_attr = ' selected="selected"';
1773 $have_selected = true;
1775 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
1776 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1779 if (!$have_selected) {
1780 $option_value = htmlspecialchars($selected, ENT_QUOTES);
1781 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
1782 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
1783 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
1785 echo " </select>\n";