2 // Copyright (C) 2007-2009 Rod Roark <rod@sunsetsystems.com>
3 // Copyright © 2010 by Andrew Moore <amoore@cpan.org>
4 // Copyright © 2010 by "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // Functions for managing the lists and layouts
13 // Note: there are translation wrappers for the lists and layout labels
14 // at library/translation.inc.php. The functions are titled
15 // xl_list_label() and xl_layout_label() and are controlled by the
16 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
17 // flags in globals.php
19 require_once("formdata.inc.php");
20 require_once("formatting.inc.php");
24 function get_pharmacies() {
25 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
26 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
27 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
28 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
30 "ORDER BY name, area_code, prefix, number");
33 // Function to generate a drop-list.
35 function generate_select_list($tag_name, $list_id, $currvalue, $title,
36 $empty_name=' ', $class='', $onchange='')
39 $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))
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>";
61 $s .= " <font color='red' title='" .
62 xl('Please choose a valid selection from the list.') . "'>" .
63 xl('Fix this') . "!</font>";
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'
89 if (isset($frow['empty_title'])) {
90 if ($frow['empty_title'] == "SKIP") {
91 //do not display an 'empty' choice
93 $empty_title = "Unassigned";
96 $empty_title = $frow['empty_title'];
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 : '');
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\")'";
128 // long or multi-line text field
129 else if ($data_type == 3) {
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>";
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>";
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>";
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)) {
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>";
202 else if ($data_type == 13) {
203 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
204 echo "<option value=''> </option>";
205 $squads = acl_get_squads();
207 foreach ($squads as $key => $value) {
208 echo "<option value='$key'";
209 if ($currvalue == $key) echo " selected";
210 echo ">" . $value[3] . "</option>\n";
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
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%'";
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%' ) " .
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>";
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" .
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>";
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']);
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>";
300 // a set of labeled text input fields
301 else if ($data_type == 22) {
302 $tmp = explode('|', $currvalue);
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']) . " </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>";
331 // a set of exam results; 3 radio buttons and a text field:
332 else if ($data_type == 23) {
333 $tmp = explode('|', $currvalue);
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> </td><td class='bold'>" . xl('N/A') .
346 " </td><td class='bold'>" . xl('Nor') . " </td>" .
347 "<td class='bold'>" . xl('Abn') . " </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']) . " </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]'" .
362 if ($restype === "$i") echo " checked";
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>";
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 " .
382 // echo "<!-- $query -->\n"; // debugging
383 $lres = sqlStatement($query);
385 while ($lrow = sqlFetchArray($lres)) {
386 if ($count++
) echo "<br />";
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);
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']) . " </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 " /> </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>";
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))
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>";
449 echo " <font color='red' title='" . xl('Please choose a valid selection from the list.') . "'>" . xl('Fix this') . "!</font>";
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;
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>";
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))
487 $got_selected = TRUE;
489 echo ">" . xl_list_label($lrow['title']);
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>";
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)) {
521 $resdate = $restype = "";
524 $restype = $resdate = $resnote = "";
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'>";
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' /> </td>";
539 echo "<td class='bold'> ".xl('Status').": </td>";
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')." </td>";
547 echo "/>".xl('Current')." </td>";
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')." </td>";
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') . "' /> </td>";
563 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
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')." </td>";
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')." </td>";
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.
600 if (isset($frow['empty_title'])) {
601 if ($frow['empty_title'] == "SKIP") {
602 //do not display an 'empty' choice
604 $empty_title = "Unassigned";
607 $empty_title = $frow['empty_title'];
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') {
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'" .
636 *****************************************************************/
637 if ($tmp === '') $tmp = ' ';
642 else if ($data_type == 2 ||
$data_type == 15) {
643 /*****************************************************************
644 echo "<input type='text'" .
645 " size='$fld_length'" .
646 " value='$currescaped'" .
649 *****************************************************************/
650 if ($currescaped === '') $currescaped = ' ';
654 // long or multi-line text field
655 else if ($data_type == 3) {
657 " cols='$fld_length'" .
658 " rows='" . $frow['max_length'] . "'>" .
659 $currescaped . "</textarea>";
663 else if ($data_type == 4) {
664 /*****************************************************************
665 echo "<input type='text' size='10'" .
666 " value='$currescaped'" .
667 " title='$description'" .
670 *****************************************************************/
671 if ($currescaped === '') $currescaped = ' ';
672 echo oeFormatShortDate($currescaped);
676 else if ($data_type == 10 ||
$data_type == 11) {
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'" .
690 *****************************************************************/
691 if ($tmp === '') $tmp = ' ';
696 else if ($data_type == 12) {
699 $pres = get_pharmacies();
700 while ($prow = sqlFetchArray($pres)) {
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'" .
716 *****************************************************************/
717 if ($tmp === '') $tmp = ' ';
722 else if ($data_type == 13) {
725 $squads = acl_get_squads();
727 foreach ($squads as $key => $value) {
728 if ($currvalue == $key) {
733 if (empty($tmp)) $tmp = "($currvalue)";
735 /*****************************************************************
736 echo "<input type='text'" .
737 " size='$fld_length'" .
741 *****************************************************************/
742 if ($tmp === '') $tmp = ' ';
747 else if ($data_type == 14) {
750 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
751 "WHERE id = '$currvalue'");
752 $uname = $urow['lname'];
753 if ($urow['fname']) $uname .= ", " . $urow['fname'];
755 if (empty($tmp)) $tmp = "($currvalue)";
757 /*****************************************************************
758 echo "<input type='text'" .
759 " size='$fld_length'" .
763 *****************************************************************/
764 if ($tmp === '') $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>";
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']);
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>";
799 // a set of labeled text input fields
800 else if ($data_type == 22) {
801 $tmp = explode('|', $currvalue);
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']) . " </td>";
816 echo "<td><input type='text'" .
817 " size='$fldlength'" .
818 " value='" . $avalue[$option_id] . "'" .
825 // a set of exam results; 3 radio buttons and a text field:
826 else if ($data_type == 23) {
827 $tmp = explode('|', $currvalue);
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> </td><td class='bold'>" . xl('N/A') .
840 " </td><td class='bold'>" . xl('Nor') . " </td>" .
841 "<td class='bold'>" . xl('Abn') . " </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']) . " </td>";
848 for ($i = 0; $i < 3; ++
$i) {
849 echo "<td><input type='radio'";
850 if ($restype === "$i") echo " checked";
853 echo "<td><input type='text'" .
854 " size='$fldlength'" .
855 " value='$resnote'" .
856 " class='under' /></td>" .
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 " .
868 $lres = sqlStatement($query);
870 while ($lrow = sqlFetchArray($lres)) {
871 if ($count++
) echo "<br />";
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);
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']) . " </td>";
896 echo "<td><input type='checkbox'";
897 if ($restype) echo " checked";
898 echo " /> </td>";
899 echo "<td><input type='text'" .
900 " size='$fldlength'" .
901 " value='$resnote'" .
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>";
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))
930 echo ">" . xl_list_label($lrow['title']);
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>";
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)) {
959 $resdate = $restype = "";
962 $restype = $resdate = $resnote = "";
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'>";
970 echo "<td><input type='text'" .
971 " size='$fldlength'" .
973 " value='$resnote' /></td>";
974 echo "<td class='bold'> ".xl('Status').": </td>";
975 echo "<td><input type='radio'";
976 if ($restype == "current".$field_id) echo " checked";
977 echo "/>".xl('Current')." </td>";
979 echo "<td><input type='radio'";
980 if ($restype == "current".$field_id) echo " checked";
981 echo "/>".xl('Quit')." </td>";
983 echo "<td><input type='text' size='6'" .
984 " value='$resdate'" .
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')." </td>";
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'];
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) {
1020 // long or multi-line text field
1021 else if ($data_type == 3) {
1022 $s = nl2br($currvalue);
1026 else if ($data_type == 4) {
1027 $s = oeFormatShortDate($currvalue);
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']);
1038 else if ($data_type == 12) {
1039 $pres = get_pharmacies();
1040 while ($prow = sqlFetchArray($pres)) {
1042 if ($currvalue == $key) {
1043 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
1044 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1045 $prow['line1'] . ' / ' . $prow['city'];
1051 else if ($data_type == 13) {
1052 $squads = acl_get_squads();
1054 foreach ($squads as $key => $value) {
1055 if ($currvalue == $key) {
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'];
1072 else if ($data_type == 15) {
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");
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);
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']) . ": </td>";
1113 $s .= "<td class='text' valign='top'>" . $avalue[$option_id] . "</td></tr>";
1118 // a set of exam results; 3 radio buttons and a text field:
1119 else if ($data_type == 23) {
1120 $tmp = explode('|', $currvalue);
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']) . " </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 </td>";
1143 $s .= "<td class='text' valign='top'>$resnote</td>";
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 " .
1154 // echo "<!-- $query -->\n"; // debugging
1155 $lres = sqlStatement($query);
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);
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']) . " </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>";
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)) {
1209 $resdate = $restype = "";
1212 $restype = $resdate = $resnote = "";
1215 $s .= "<table cellpadding='0' cellspacing='0'>";
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 </td>";
1226 if (!empty($res)) $s .= "<td class='text' valign='top'><b>".xl('Status')."</b>: ".$res." </td>";
1227 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>$resdate </td>";
1235 $CPR = 4; // cells per row of generic data
1240 function disp_end_cell() {
1241 global $item_count, $cell_count;
1242 if ($item_count > 0) {
1248 function disp_end_row() {
1249 global $cell_count, $CPR;
1251 if ($cell_count > 0) {
1252 for (; $cell_count < $CPR; ++
$cell_count) echo "<td></td>";
1258 function disp_end_group() {
1260 if (strlen($last_group) > 0) {
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'];
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];
1294 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
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;
1307 $last_group = $this_group;
1310 // Handle starting of a new row.
1311 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
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));
1324 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1325 echo "<td valign='top'> ";
1330 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1332 // Handle starting of a new label cell.
1333 if ($titlecols > 0) {
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'";
1339 $cell_count +
= $titlecols;
1343 // Added 5-09 by BM - Translate label if applicable
1344 if ($frow['title']) echo (xl_layout_label($frow['title']).":"); else echo " ";
1346 // Handle starting of a new data cell.
1347 if ($datacols > 0) {
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'";
1353 $cell_count +
= $datacols;
1357 echo generate_display_field($frow, $currvalue);
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");
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
>
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");
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'];
1400 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1401 "WHERE form_id = '$formtype' AND uor > 0 AND group_name = '$this_group' " .
1405 <div
class="tab <?php echo $first ? 'current' : '' ?>">
1406 <table border
='0' cellpadding
='0'>
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'];
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];
1431 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
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) {
1452 if ($item_count == 0 && $titlecols == 0) {
1456 // Handle starting of a new label cell.
1457 if ($titlecols > 0) {
1459 echo "<td class='label' colspan='$titlecols' ";
1461 $cell_count +
= $titlecols;
1465 // Added 5-09 by BM - Translate label if applicable
1466 if ($group_fields['title']) echo (xl_layout_label($group_fields['title']).":"); else echo " ";
1468 // Handle starting of a new data cell.
1469 if ($datacols > 0) {
1471 echo "<td class='text data' colspan='$datacols'";
1473 $cell_count +
= $datacols;
1477 echo generate_display_field($group_fields, $currvalue);
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");
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'];
1510 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1511 "WHERE form_id = '$formtype' AND uor > 0 AND group_name = '$this_group' " .
1515 <div
class="tab <?php echo $first ? 'current' : '' ?>" id
="tab_<?php echo $group_name?>" >
1516 <table border
='0' cellpadding
='0'>
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'];
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];
1541 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
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) {
1562 if ($item_count == 0 && $titlecols == 0) {
1566 // Handle starting of a new label cell.
1567 if ($titlecols > 0) {
1569 echo "<td class='label' colspan='$titlecols' ";
1571 $cell_count +
= $titlecols;
1575 // Added 5-09 by BM - Translate label if applicable
1576 if ($group_fields['title']) echo (xl_layout_label($group_fields['title']).":"); else echo " ";
1578 // Handle starting of a new data cell.
1579 if ($datacols > 0) {
1581 echo "<td class='text data' colspan='$datacols'";
1583 $cell_count +
= $datacols;
1587 echo generate_form_field($group_fields, $currvalue);
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'];
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 .= '|';
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";
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 /> <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) {
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" .
1697 case 27: // radio buttons
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" .
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" .
1716 " $('#form_" . $field_id . "').attr('style',''); " .
1717 " $('#form_" . $field_id . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
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
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";
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";