language constants and translations update
[openemr.git] / library / options.inc.php
blobfda3f84c558f5a6af345f4008de8f197c6166897
1 <?php
2 // Copyright (C) 2007-2009 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // Functions for managing the lists and layouts
11 // Note: there are translation wrappers for the lists and layout labels
12 // at library/translation.inc.php. The functions are titled
13 // xl_list_label() and xl_layout_label() and are controlled by the
14 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
15 // flags in globals.php
17 require_once("formdata.inc.php");
19 $date_init = "";
21 function get_pharmacies() {
22 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
23 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
24 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
25 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
26 "AND p.type = 2 " .
27 "ORDER BY name, area_code, prefix, number");
30 // Function to generate a drop-list.
32 function generate_select_list($tag_name, $list_id, $currvalue, $title,
33 $empty_name=' ', $class='', $onchange='')
35 $s = '';
36 $s .= "<select name='$tag_name' id='$tag_name'";
37 if ($class) $s .= " class='$class'";
38 if ($onchange) $s .= " onchange='$onchange'";
39 $s .= " title='$title'>";
40 if ($empty_name) $s .= "<option value=''>" . xl($empty_name) . "</option>";
41 $lres = sqlStatement("SELECT * FROM list_options " .
42 "WHERE list_id = '$list_id' ORDER BY seq, title");
43 $got_selected = FALSE;
44 while ($lrow = sqlFetchArray($lres)) {
45 $s .= "<option value='" . $lrow['option_id'] . "'";
46 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
47 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
49 $s .= " selected";
50 $got_selected = TRUE;
52 $s .= ">" . xl_list_label($lrow['title']) . "</option>\n";
54 if (!$got_selected && strlen($currvalue) > 0) {
55 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
56 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
57 $s .= "</select>";
58 $s .= " <font color='red' title='" .
59 xl('Please choose a valid selection from the list.') . "'>" .
60 xl('Fix this') . "!</font>";
62 else {
63 $s .= "</select>";
65 return $s;
68 function generate_form_field($frow, $currvalue) {
69 global $rootdir, $date_init;
71 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
73 $data_type = $frow['data_type'];
74 $field_id = $frow['field_id'];
75 $list_id = $frow['list_id'];
77 // Added 5-09 by BM - Translate description if applicable
78 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
80 // added 5-2009 by BM to allow modification of the 'empty' text title field.
81 // Can pass $frow['empty_title'] with this variable, otherwise
82 // will default to 'Unassigned'.
83 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
84 // if make $frow['empty_title'] equal to 'SKIP'
85 $showEmpty = true;
86 if (isset($frow['empty_title'])) {
87 if ($frow['empty_title'] == "SKIP") {
88 //do not display an 'empty' choice
89 $showEmpty = false;
90 $empty_title = "Unassigned";
92 else {
93 $empty_title = $frow['empty_title'];
96 else {
97 $empty_title = "Unassigned";
100 // generic single-selection list
101 if ($data_type == 1) {
102 echo generate_select_list("form_$field_id", $list_id, $currvalue,
103 $description, $showEmpty ? $empty_title : '');
106 // simple text field
107 else if ($data_type == 2) {
108 echo "<input type='text'" .
109 " name='form_$field_id'" .
110 " id='form_$field_id'" .
111 " size='" . $frow['fld_length'] . "'" .
112 " maxlength='" . $frow['max_length'] . "'" .
113 " title='$description'" .
114 " value='$currescaped'";
115 if (strpos($frow['edit_options'], 'C') !== FALSE)
116 echo " onchange='capitalizeMe(this)'";
117 echo " />";
120 // long or multi-line text field
121 else if ($data_type == 3) {
122 echo "<textarea" .
123 " name='form_$field_id'" .
124 " id='form_$field_id'" .
125 " title='$description'" .
126 " cols='" . $frow['fld_length'] . "'" .
127 " rows='" . $frow['max_length'] . "'>" .
128 $currescaped . "</textarea>";
131 // date
132 else if ($data_type == 4) {
133 echo "<input type='text' size='10' name='form_$field_id' id='form_$field_id'" .
134 " value='$currescaped'" .
135 " title='$description'" .
136 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
137 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
138 " id='img_$field_id' border='0' alt='[?]' style='cursor:pointer'" .
139 " title='" . xl('Click here to choose a date') . "' />";
140 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
143 // provider list, local providers only
144 else if ($data_type == 10) {
145 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
146 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
147 "AND authorized = 1 " .
148 "ORDER BY lname, fname");
149 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
150 echo "<option value=''>" . xl('Unassigned') . "</option>";
151 while ($urow = sqlFetchArray($ures)) {
152 $uname = $urow['fname'] . ' ' . $urow['lname'];
153 echo "<option value='" . $urow['id'] . "'";
154 if ($urow['id'] == $currvalue) echo " selected";
155 echo ">$uname</option>";
157 echo "</select>";
160 // provider list, including address book entries with an NPI number
161 else if ($data_type == 11) {
162 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
163 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
164 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
165 "ORDER BY lname, fname");
166 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
167 echo "<option value=''>" . xl('Unassigned') . "</option>";
168 while ($urow = sqlFetchArray($ures)) {
169 $uname = $urow['fname'] . ' ' . $urow['lname'];
170 echo "<option value='" . $urow['id'] . "'";
171 if ($urow['id'] == $currvalue) echo " selected";
172 echo ">$uname</option>";
174 echo "</select>";
177 // pharmacy list
178 else if ($data_type == 12) {
179 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
180 echo "<option value='0'></option>";
181 $pres = get_pharmacies();
182 while ($prow = sqlFetchArray($pres)) {
183 $key = $prow['id'];
184 echo "<option value='$key'";
185 if ($currvalue == $key) echo " selected";
186 echo '>' . $prow['name'] . ' ' . $prow['area_code'] . '-' .
187 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
188 $prow['line1'] . ' / ' . $prow['city'] . "</option>";
190 echo "</select>";
193 // squads
194 else if ($data_type == 13) {
195 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
196 echo "<option value=''>&nbsp;</option>";
197 $squads = acl_get_squads();
198 if ($squads) {
199 foreach ($squads as $key => $value) {
200 echo "<option value='$key'";
201 if ($currvalue == $key) echo " selected";
202 echo ">" . $value[3] . "</option>\n";
205 echo "</select>";
208 // Address book, preferring organization name if it exists and is not in
209 // parentheses, and excluding local users who are not providers.
210 // Supports "referred to" practitioners and facilities.
211 // Alternatively the letter O in edit_options means that abook_type
212 // must begin with "ord_", indicating types used with the procedure
213 // ordering system.
214 // Alternatively the letter V in edit_options means that abook_type
215 // must be "vendor", indicating the Vendor type.
216 else if ($data_type == 14) {
217 if (strpos($frow['edit_options'], 'O') !== FALSE)
218 $tmp = "abook_type LIKE 'ord\\_%'";
219 else if (strpos($frow['edit_options'], 'V') !== FALSE)
220 $tmp = "abook_type LIKE 'vendor%'";
221 else
222 $tmp = "( username = '' OR authorized = 1 )";
223 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
224 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
225 "AND $tmp " .
226 "ORDER BY organization, lname, fname");
227 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
228 echo "<option value=''>" . xl('Unassigned') . "</option>";
229 while ($urow = sqlFetchArray($ures)) {
230 $uname = $urow['organization'];
231 if (empty($uname) || substr($uname, 0, 1) == '(') {
232 $uname = $urow['lname'];
233 if ($urow['fname']) $uname .= ", " . $urow['fname'];
235 echo "<option value='" . $urow['id'] . "'";
236 $title = $urow['username'] ? xl('Local') : xl('External');
237 echo " title='$title'";
238 if ($urow['id'] == $currvalue) echo " selected";
239 echo ">$uname</option>";
241 echo "</select>";
244 // a billing code (only one of these allowed!)
245 else if ($data_type == 15) {
246 echo "<input type='text'" .
247 " name='form_$field_id'" .
248 " id='form_related_code'" .
249 " size='" . $frow['fld_length'] . "'" .
250 " maxlength='" . $frow['max_length'] . "'" .
251 " title='$description'" .
252 " value='$currescaped'" .
253 " onclick='sel_related()' readonly" .
254 " />";
257 // a set of labeled checkboxes
258 else if ($data_type == 21) {
259 // In this special case, fld_length is the number of columns generated.
260 $cols = max(1, $frow['fld_length']);
261 $avalue = explode('|', $currvalue);
262 $lres = sqlStatement("SELECT * FROM list_options " .
263 "WHERE list_id = '$list_id' ORDER BY seq, title");
264 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
265 $tdpct = (int) (100 / $cols);
266 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
267 $option_id = $lrow['option_id'];
268 // if ($count) echo "<br />";
269 if ($count % $cols == 0) {
270 if ($count) echo "</tr>";
271 echo "<tr>";
273 echo "<td width='$tdpct%'>";
274 echo "<input type='checkbox' name='form_{$field_id}[$option_id]' id='form_{$field_id}[$option_id]' value='1'";
275 if (in_array($option_id, $avalue)) echo " checked";
277 // Added 5-09 by BM - Translate label if applicable
278 echo ">" . xl_list_label($lrow['title']);
280 echo "</td>";
282 if ($count) {
283 echo "</tr>";
284 if ($count > $cols) {
285 // Add some space after multiple rows of checkboxes.
286 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
289 echo "</table>";
292 // a set of labeled text input fields
293 else if ($data_type == 22) {
294 $tmp = explode('|', $currvalue);
295 $avalue = array();
296 foreach ($tmp as $value) {
297 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
298 $avalue[$matches[1]] = $matches[2];
301 $lres = sqlStatement("SELECT * FROM list_options " .
302 "WHERE list_id = '$list_id' ORDER BY seq, title");
303 echo "<table cellpadding='0' cellspacing='0'>";
304 while ($lrow = sqlFetchArray($lres)) {
305 $option_id = $lrow['option_id'];
306 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
307 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
309 // Added 5-09 by BM - Translate label if applicable
310 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
312 echo "<td><input type='text'" .
313 " name='form_{$field_id}[$option_id]'" .
314 " id='form_{$field_id}[$option_id]'" .
315 " size='$fldlength'" .
316 " maxlength='$maxlength'" .
317 " value='" . $avalue[$option_id] . "'";
318 echo " /></td></tr>";
320 echo "</table>";
323 // a set of exam results; 3 radio buttons and a text field:
324 else if ($data_type == 23) {
325 $tmp = explode('|', $currvalue);
326 $avalue = array();
327 foreach ($tmp as $value) {
328 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
329 $avalue[$matches[1]] = $matches[2];
332 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
333 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
334 $lres = sqlStatement("SELECT * FROM list_options " .
335 "WHERE list_id = '$list_id' ORDER BY seq, title");
336 echo "<table cellpadding='0' cellspacing='0'>";
337 echo "<tr><td>&nbsp;</td><td class='bold'>" . xl('N/A') .
338 "&nbsp;</td><td class='bold'>" . xl('Nor') . "&nbsp;</td>" .
339 "<td class='bold'>" . xl('Abn') . "&nbsp;</td><td class='bold'>" .
340 xl('Date/Notes') . "</td></tr>";
341 while ($lrow = sqlFetchArray($lres)) {
342 $option_id = $lrow['option_id'];
343 $restype = substr($avalue[$option_id], 0, 1);
344 $resnote = substr($avalue[$option_id], 2);
346 // Added 5-09 by BM - Translate label if applicable
347 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
349 for ($i = 0; $i < 3; ++$i) {
350 echo "<td><input type='radio'" .
351 " name='radio_{$field_id}[$option_id]'" .
352 " id='radio_{$field_id}[$option_id]'" .
353 " value='$i'";
354 if ($restype === "$i") echo " checked";
355 echo " /></td>";
357 echo "<td><input type='text'" .
358 " name='form_{$field_id}[$option_id]'" .
359 " id='form_{$field_id}[$option_id]'" .
360 " size='$fldlength'" .
361 " maxlength='$maxlength'" .
362 " value='$resnote' /></td>";
363 echo "</tr>";
365 echo "</table>";
368 // the list of active allergies for the current patient
369 // this is read-only!
370 else if ($data_type == 24) {
371 $query = "SELECT title, comments FROM lists WHERE " .
372 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
373 "ORDER BY begdate";
374 // echo "<!-- $query -->\n"; // debugging
375 $lres = sqlStatement($query);
376 $count = 0;
377 while ($lrow = sqlFetchArray($lres)) {
378 if ($count++) echo "<br />";
379 echo $lrow['title'];
380 if ($lrow['comments']) echo ' (' . $lrow['comments'] . ')';
384 // a set of labeled checkboxes, each with a text field:
385 else if ($data_type == 25) {
386 $tmp = explode('|', $currvalue);
387 $avalue = array();
388 foreach ($tmp as $value) {
389 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
390 $avalue[$matches[1]] = $matches[2];
393 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
394 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
395 $lres = sqlStatement("SELECT * FROM list_options " .
396 "WHERE list_id = '$list_id' ORDER BY seq, title");
397 echo "<table cellpadding='0' cellspacing='0'>";
398 while ($lrow = sqlFetchArray($lres)) {
399 $option_id = $lrow['option_id'];
400 $restype = substr($avalue[$option_id], 0, 1);
401 $resnote = substr($avalue[$option_id], 2);
403 // Added 5-09 by BM - Translate label if applicable
404 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
406 echo "<td><input type='checkbox' name='check_{$field_id}[$option_id]' id='check_{$field_id}[$option_id]' value='1'";
407 if ($restype) echo " checked";
408 echo " />&nbsp;</td>";
409 echo "<td><input type='text'" .
410 " name='form_{$field_id}[$option_id]'" .
411 " id='form_{$field_id}[$option_id]'" .
412 " size='$fldlength'" .
413 " maxlength='$maxlength'" .
414 " value='$resnote' /></td>";
415 echo "</tr>";
417 echo "</table>";
420 // single-selection list with ability to add to it
421 else if ($data_type == 26) {
422 echo "<select class='addtolistclass_$list_id' name='form_$field_id' id='form_$field_id' title='$description'>";
423 if ($showEmpty) echo "<option value=''>" . xl($empty_title) . "</option>";
424 $lres = sqlStatement("SELECT * FROM list_options " .
425 "WHERE list_id = '$list_id' ORDER BY seq, title");
426 $got_selected = FALSE;
427 while ($lrow = sqlFetchArray($lres)) {
428 echo "<option value='" . $lrow['option_id'] . "'";
429 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
430 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
432 echo " selected";
433 $got_selected = TRUE;
435 // Added 5-09 by BM - Translate label if applicable
436 echo ">" . xl_list_label($lrow['title']) . "</option>\n";
438 if (!$got_selected && strlen($currvalue) > 0) {
439 echo "<option value='$currescaped' selected>* $currescaped *</option>";
440 echo "</select>";
441 echo " <font color='red' title='" . xl('Please choose a valid selection from the list.') . "'>" . xl('Fix this') . "!</font>";
443 else {
444 echo "</select>";
446 // show the add button if user has access to correct list
447 $outputAddButton = "<input type='button' id='addtolistid_".$list_id."' fieldid='form_".$field_id."' class='addtolist' value='" . xl('Add') . "'>";
448 if (aco_exist('lists', $list_id)) {
449 // a specific aco exist for this list, so ensure access
450 if (acl_check('lists', $list_id)) echo $outputAddButton;
452 else {
453 // no specific aco exist for this list, so check for access to 'default' list
454 if (acl_check('lists', 'default')) echo $outputAddButton;
458 // a set of labeled radio buttons
459 else if ($data_type == 27) {
460 // In this special case, fld_length is the number of columns generated.
461 $cols = max(1, $frow['fld_length']);
462 $lres = sqlStatement("SELECT * FROM list_options " .
463 "WHERE list_id = '$list_id' ORDER BY seq, title");
464 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
465 $tdpct = (int) (100 / $cols);
466 $got_selected = FALSE;
467 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
468 $option_id = $lrow['option_id'];
469 if ($count % $cols == 0) {
470 if ($count) echo "</tr>";
471 echo "<tr>";
473 echo "<td width='$tdpct%'>";
474 echo "<input type='radio' name='form_{$field_id}' id='form_{$field_id}[$option_id]' value='$option_id'";
475 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
476 (strlen($currvalue) > 0 && $option_id == $currvalue))
478 echo " checked";
479 $got_selected = TRUE;
481 echo ">" . xl_list_label($lrow['title']);
482 echo "</td>";
484 if ($count) {
485 echo "</tr>";
486 if ($count > $cols) {
487 // Add some space after multiple rows of radio buttons.
488 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
491 echo "</table>";
492 if (!$got_selected && strlen($currvalue) > 0) {
493 echo "$currvalue <font color='red' title='" . xl('Please choose a valid selection.') . "'>" . xl('Fix this') . "!</font>";
497 // special case for history of lifestyle status; 3 radio buttons and a date text field:
498 else if ($data_type == 28) {
499 $tmp = explode('|', $currvalue);
500 switch(count($tmp)) {
501 case "3": {
502 $resnote = $tmp[0];
503 $restype = $tmp[1];
504 $resdate = $tmp[2];
505 } break;
506 case "2": {
507 $resnote = $tmp[0];
508 $restype = $tmp[1];
509 $resdate = "";
510 } break;
511 case "1": {
512 $resnote = $tmp[0];
513 $resdate = $restype = "";
514 } break;
515 default: {
516 $restype = $resdate = $resnote = "";
517 } break;
519 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
520 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
522 echo "<table cellpadding='0' cellspacing='0'>";
523 echo "<tr>";
524 // input text
525 echo "<td><input type='text'" .
526 " name='form_$field_id'" .
527 " id='form_$field_id'" .
528 " size='$fldlength'" .
529 " maxlength='$maxlength'" .
530 " value='$resnote' />&nbsp;</td>";
531 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;".xl('Status').":&nbsp;</td>";
532 // current
533 echo "<td><input type='radio'" .
534 " name='radio_{$field_id}'" .
535 " id='radio_{$field_id}[current]'" .
536 " value='current".$field_id."'";
537 if ($restype == "current".$field_id) echo " checked";
538 // echo " onclick=\"return clinical_alerts_popup(this.value,'Patient_History')\" />".xl('Current')."&nbsp;</td>";
539 echo "/>".xl('Current')."&nbsp;</td>";
540 // quit
541 echo "<td><input type='radio'" .
542 " name='radio_{$field_id}'" .
543 " id='radio_{$field_id}[quit]'" .
544 " value='quit".$field_id."'";
545 if ($restype == "quit".$field_id) echo " checked";
546 echo "/>".xl('Quit')."&nbsp;</td>";
547 // quit date
548 echo "<td><input type='text' size='6' name='date_$field_id' id='date_$field_id'" .
549 " value='$resdate'" .
550 " title='$description'" .
551 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
552 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
553 " id='img_$field_id' border='0' alt='[?]' style='cursor:pointer'" .
554 " title='" . xl('Click here to choose a date') . "' />&nbsp;</td>";
555 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
556 // never
557 echo "<td><input type='radio'" .
558 " name='radio_{$field_id}'" .
559 " id='radio_{$field_id}[never]'" .
560 " value='never".$field_id."'";
561 if ($restype == "never".$field_id) echo " checked";
562 echo " />".xl('Never')."&nbsp;</td>";
563 // Not Applicable
564 echo "<td><input type='radio'" .
565 " name='radio_{$field_id}'" .
566 " id='radio_{$field_id}[not_applicable]'" .
567 " value='not_applicable".$field_id."'";
568 if ($restype == "not_applicable".$field_id) echo " checked";
569 echo " />".xl('N/A')."&nbsp;</td>";
570 echo "</tr>";
571 echo "</table>";
576 function generate_print_field($frow, $currvalue) {
577 global $rootdir, $date_init;
579 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
581 $data_type = $frow['data_type'];
582 $field_id = $frow['field_id'];
583 $list_id = $frow['list_id'];
584 $fld_length = $frow['fld_length'];
586 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
588 // Can pass $frow['empty_title'] with this variable, otherwise
589 // will default to 'Unassigned'.
590 // If it is 'SKIP' then an empty text title is completely skipped.
591 $showEmpty = true;
592 if (isset($frow['empty_title'])) {
593 if ($frow['empty_title'] == "SKIP") {
594 //do not display an 'empty' choice
595 $showEmpty = false;
596 $empty_title = "Unassigned";
598 else {
599 $empty_title = $frow['empty_title'];
602 else {
603 $empty_title = "Unassigned";
606 // generic single-selection list
607 if ($data_type == 1 || $data_type == 26) {
608 if (empty($fld_length)) {
609 if ($list_id == 'titles') {
610 $fld_length = 3;
611 } else {
612 $fld_length = 10;
615 $tmp = '';
616 if ($currvalue) {
617 $lrow = sqlQuery("SELECT title FROM list_options " .
618 "WHERE list_id = '$list_id' AND option_id = '$currvalue'");
619 $tmp = xl_list_label($lrow['title']);
620 if (empty($tmp)) $tmp = "($currvalue)";
622 /*****************************************************************
623 echo "<input type='text'" .
624 " size='$fld_length'" .
625 " value='$tmp'" .
626 " class='under'" .
627 " />";
628 *****************************************************************/
629 if ($tmp === '') $tmp = '&nbsp;';
630 echo $tmp;
633 // simple text field
634 else if ($data_type == 2 || $data_type == 15) {
635 /*****************************************************************
636 echo "<input type='text'" .
637 " size='$fld_length'" .
638 " value='$currescaped'" .
639 " class='under'" .
640 " />";
641 *****************************************************************/
642 if ($currescaped === '') $currescaped = '&nbsp;';
643 echo $currescaped;
646 // long or multi-line text field
647 else if ($data_type == 3) {
648 echo "<textarea" .
649 " cols='$fld_length'" .
650 " rows='" . $frow['max_length'] . "'>" .
651 $currescaped . "</textarea>";
654 // date
655 else if ($data_type == 4) {
656 /*****************************************************************
657 echo "<input type='text' size='10'" .
658 " value='$currescaped'" .
659 " title='$description'" .
660 " class='under'" .
661 " />";
662 *****************************************************************/
663 if ($currescaped === '') $currescaped = '&nbsp;';
664 echo $currescaped;
667 // provider list
668 else if ($data_type == 10 || $data_type == 11) {
669 $tmp = '';
670 if ($currvalue) {
671 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
672 "WHERE id = '$currvalue'");
673 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
674 if (empty($tmp)) $tmp = "($currvalue)";
676 /*****************************************************************
677 echo "<input type='text'" .
678 " size='$fld_length'" .
679 " value='$tmp'" .
680 " class='under'" .
681 " />";
682 *****************************************************************/
683 if ($tmp === '') $tmp = '&nbsp;';
684 echo $tmp;
687 // pharmacy list
688 else if ($data_type == 12) {
689 $tmp = '';
690 if ($currvalue) {
691 $pres = get_pharmacies();
692 while ($prow = sqlFetchArray($pres)) {
693 $key = $prow['id'];
694 if ($currvalue == $key) {
695 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
696 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
697 $prow['line1'] . ' / ' . $prow['city'];
700 if (empty($tmp)) $tmp = "($currvalue)";
702 /*****************************************************************
703 echo "<input type='text'" .
704 " size='$fld_length'" .
705 " value='$tmp'" .
706 " class='under'" .
707 " />";
708 *****************************************************************/
709 if ($tmp === '') $tmp = '&nbsp;';
710 echo $tmp;
713 // squads
714 else if ($data_type == 13) {
715 $tmp = '';
716 if ($currvalue) {
717 $squads = acl_get_squads();
718 if ($squads) {
719 foreach ($squads as $key => $value) {
720 if ($currvalue == $key) {
721 $tmp = $value[3];
725 if (empty($tmp)) $tmp = "($currvalue)";
727 /*****************************************************************
728 echo "<input type='text'" .
729 " size='$fld_length'" .
730 " value='$tmp'" .
731 " class='under'" .
732 " />";
733 *****************************************************************/
734 if ($tmp === '') $tmp = '&nbsp;';
735 echo $tmp;
738 // Address book.
739 else if ($data_type == 14) {
740 $tmp = '';
741 if ($currvalue) {
742 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
743 "WHERE id = '$currvalue'");
744 $uname = $urow['lname'];
745 if ($urow['fname']) $uname .= ", " . $urow['fname'];
746 $tmp = $uname;
747 if (empty($tmp)) $tmp = "($currvalue)";
749 /*****************************************************************
750 echo "<input type='text'" .
751 " size='$fld_length'" .
752 " value='$tmp'" .
753 " class='under'" .
754 " />";
755 *****************************************************************/
756 if ($tmp === '') $tmp = '&nbsp;';
757 echo $tmp;
760 // a set of labeled checkboxes
761 else if ($data_type == 21) {
762 // In this special case, fld_length is the number of columns generated.
763 $cols = max(1, $fld_length);
764 $avalue = explode('|', $currvalue);
765 $lres = sqlStatement("SELECT * FROM list_options " .
766 "WHERE list_id = '$list_id' ORDER BY seq, title");
767 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
768 $tdpct = (int) (100 / $cols);
769 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
770 $option_id = $lrow['option_id'];
771 if ($count % $cols == 0) {
772 if ($count) echo "</tr>";
773 echo "<tr>";
775 echo "<td width='$tdpct%'>";
776 echo "<input type='checkbox'";
777 if (in_array($option_id, $avalue)) echo " checked";
778 echo ">" . xl_list_label($lrow['title']);
779 echo "</td>";
781 if ($count) {
782 echo "</tr>";
783 if ($count > $cols) {
784 // Add some space after multiple rows of checkboxes.
785 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
788 echo "</table>";
791 // a set of labeled text input fields
792 else if ($data_type == 22) {
793 $tmp = explode('|', $currvalue);
794 $avalue = array();
795 foreach ($tmp as $value) {
796 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
797 $avalue[$matches[1]] = $matches[2];
800 $lres = sqlStatement("SELECT * FROM list_options " .
801 "WHERE list_id = '$list_id' ORDER BY seq, title");
802 echo "<table cellpadding='0' cellspacing='0'>";
803 while ($lrow = sqlFetchArray($lres)) {
804 $option_id = $lrow['option_id'];
805 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
806 $fldlength = empty($fld_length) ? 20 : $fld_length;
807 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
808 echo "<td><input type='text'" .
809 " size='$fldlength'" .
810 " value='" . $avalue[$option_id] . "'" .
811 " class='under'" .
812 " /></td></tr>";
814 echo "</table>";
817 // a set of exam results; 3 radio buttons and a text field:
818 else if ($data_type == 23) {
819 $tmp = explode('|', $currvalue);
820 $avalue = array();
821 foreach ($tmp as $value) {
822 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
823 $avalue[$matches[1]] = $matches[2];
826 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
827 $fldlength = empty($fld_length) ? 20 : $fld_length;
828 $lres = sqlStatement("SELECT * FROM list_options " .
829 "WHERE list_id = '$list_id' ORDER BY seq, title");
830 echo "<table cellpadding='0' cellspacing='0'>";
831 echo "<tr><td>&nbsp;</td><td class='bold'>" . xl('N/A') .
832 "&nbsp;</td><td class='bold'>" . xl('Nor') . "&nbsp;</td>" .
833 "<td class='bold'>" . xl('Abn') . "&nbsp;</td><td class='bold'>" .
834 xl('Date/Notes') . "</td></tr>";
835 while ($lrow = sqlFetchArray($lres)) {
836 $option_id = $lrow['option_id'];
837 $restype = substr($avalue[$option_id], 0, 1);
838 $resnote = substr($avalue[$option_id], 2);
839 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
840 for ($i = 0; $i < 3; ++$i) {
841 echo "<td><input type='radio'";
842 if ($restype === "$i") echo " checked";
843 echo " /></td>";
845 echo "<td><input type='text'" .
846 " size='$fldlength'" .
847 " value='$resnote'" .
848 " class='under' /></td>" .
849 "</tr>";
851 echo "</table>";
854 // the list of active allergies for the current patient
855 // this is read-only!
856 else if ($data_type == 24) {
857 $query = "SELECT title, comments FROM lists WHERE " .
858 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
859 "ORDER BY begdate";
860 $lres = sqlStatement($query);
861 $count = 0;
862 while ($lrow = sqlFetchArray($lres)) {
863 if ($count++) echo "<br />";
864 echo $lrow['title'];
865 if ($lrow['comments']) echo ' (' . $lrow['comments'] . ')';
869 // a set of labeled checkboxes, each with a text field:
870 else if ($data_type == 25) {
871 $tmp = explode('|', $currvalue);
872 $avalue = array();
873 foreach ($tmp as $value) {
874 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
875 $avalue[$matches[1]] = $matches[2];
878 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
879 $fldlength = empty($fld_length) ? 20 : $fld_length;
880 $lres = sqlStatement("SELECT * FROM list_options " .
881 "WHERE list_id = '$list_id' ORDER BY seq, title");
882 echo "<table cellpadding='0' cellspacing='0'>";
883 while ($lrow = sqlFetchArray($lres)) {
884 $option_id = $lrow['option_id'];
885 $restype = substr($avalue[$option_id], 0, 1);
886 $resnote = substr($avalue[$option_id], 2);
887 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
888 echo "<td><input type='checkbox'";
889 if ($restype) echo " checked";
890 echo " />&nbsp;</td>";
891 echo "<td><input type='text'" .
892 " size='$fldlength'" .
893 " value='$resnote'" .
894 " class='under'" .
895 " /></td>" .
896 "</tr>";
898 echo "</table>";
901 // a set of labeled radio buttons
902 else if ($data_type == 27) {
903 // In this special case, fld_length is the number of columns generated.
904 $cols = max(1, $frow['fld_length']);
905 $lres = sqlStatement("SELECT * FROM list_options " .
906 "WHERE list_id = '$list_id' ORDER BY seq, title");
907 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
908 $tdpct = (int) (100 / $cols);
909 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
910 $option_id = $lrow['option_id'];
911 if ($count % $cols == 0) {
912 if ($count) echo "</tr>";
913 echo "<tr>";
915 echo "<td width='$tdpct%'>";
916 echo "<input type='radio'";
917 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
918 (strlen($currvalue) > 0 && $option_id == $currvalue))
920 echo " checked";
922 echo ">" . xl_list_label($lrow['title']);
923 echo "</td>";
925 if ($count) {
926 echo "</tr>";
927 if ($count > $cols) {
928 // Add some space after multiple rows of radio buttons.
929 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
932 echo "</table>";
935 // special case for history of lifestyle status; 3 radio buttons and a date text field:
936 else if ($data_type == 28) {
937 $tmp = explode('|', $currvalue);
938 switch(count($tmp)) {
939 case "3": {
940 $resnote = $tmp[0];
941 $restype = $tmp[1];
942 $resdate = $tmp[2];
943 } break;
944 case "2": {
945 $resnote = $tmp[0];
946 $restype = $tmp[1];
947 $resdate = "";
948 } break;
949 case "1": {
950 $resnote = $tmp[0];
951 $resdate = $restype = "";
952 } break;
953 default: {
954 $restype = $resdate = $resnote = "";
955 } break;
957 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
958 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
959 echo "<table cellpadding='0' cellspacing='0'>";
960 echo "<tr>";
962 echo "<td><input type='text'" .
963 " size='$fldlength'" .
964 " class='under'" .
965 " value='$resnote' /></td>";
966 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;".xl('Status').":&nbsp;</td>";
967 echo "<td><input type='radio'";
968 if ($restype == "current".$field_id) echo " checked";
969 echo "/>".xl('Current')."&nbsp;</td>";
971 echo "<td><input type='radio'";
972 if ($restype == "current".$field_id) echo " checked";
973 echo "/>".xl('Quit')."&nbsp;</td>";
975 echo "<td><input type='text' size='6'" .
976 " value='$resdate'" .
977 " class='under'" .
978 " /></td>";
980 echo "<td><input type='radio'";
981 if ($restype == "current".$field_id) echo " checked";
982 echo " />".xl('Never')."</td>";
984 echo "<td><input type='radio'";
985 if ($restype == "not_applicable".$field_id) echo " checked";
986 echo " />".xl('N/A')."&nbsp;</td>";
987 echo "</tr>";
988 echo "</table>";
993 function generate_display_field($frow, $currvalue) {
994 $data_type = $frow['data_type'];
995 $field_id = $frow['field_id'];
996 $list_id = $frow['list_id'];
997 $s = '';
999 // generic selection list or the generic selection list with add on the fly
1000 // feature, or radio buttons
1001 if ($data_type == 1 || $data_type == 26 || $data_type == 27) {
1002 $lrow = sqlQuery("SELECT title FROM list_options " .
1003 "WHERE list_id = '$list_id' AND option_id = '$currvalue'");
1004 $s = xl_list_label($lrow['title']);
1007 // simple text field
1008 else if ($data_type == 2) {
1009 $s = $currvalue;
1012 // long or multi-line text field
1013 else if ($data_type == 3) {
1014 $s = nl2br($currvalue);
1017 // date
1018 else if ($data_type == 4) {
1019 $s = $currvalue;
1022 // provider
1023 else if ($data_type == 10 || $data_type == 11) {
1024 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1025 "WHERE id = '$currvalue'");
1026 $s = ucwords($urow['fname'] . " " . $urow['lname']);
1029 // pharmacy list
1030 else if ($data_type == 12) {
1031 $pres = get_pharmacies();
1032 while ($prow = sqlFetchArray($pres)) {
1033 $key = $prow['id'];
1034 if ($currvalue == $key) {
1035 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
1036 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1037 $prow['line1'] . ' / ' . $prow['city'];
1042 // squads
1043 else if ($data_type == 13) {
1044 $squads = acl_get_squads();
1045 if ($squads) {
1046 foreach ($squads as $key => $value) {
1047 if ($currvalue == $key) {
1048 $s .= $value[3];
1054 // address book
1055 else if ($data_type == 14) {
1056 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1057 "WHERE id = '$currvalue'");
1058 $uname = $urow['lname'];
1059 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1060 $s = $uname;
1063 // billing code
1064 else if ($data_type == 15) {
1065 $s = $currvalue;
1068 // a set of labeled checkboxes
1069 else if ($data_type == 21) {
1070 $avalue = explode('|', $currvalue);
1071 $lres = sqlStatement("SELECT * FROM list_options " .
1072 "WHERE list_id = '$list_id' ORDER BY seq, title");
1073 $count = 0;
1074 while ($lrow = sqlFetchArray($lres)) {
1075 $option_id = $lrow['option_id'];
1076 if (in_array($option_id, $avalue)) {
1077 if ($count++) $s .= "<br />";
1079 // Added 5-09 by BM - Translate label if applicable
1080 $s .= xl_list_label($lrow['title']);
1086 // a set of labeled text input fields
1087 else if ($data_type == 22) {
1088 $tmp = explode('|', $currvalue);
1089 $avalue = array();
1090 foreach ($tmp as $value) {
1091 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1092 $avalue[$matches[1]] = $matches[2];
1095 $lres = sqlStatement("SELECT * FROM list_options " .
1096 "WHERE list_id = '$list_id' ORDER BY seq, title");
1097 $s .= "<table cellpadding='0' cellspacing='0'>";
1098 while ($lrow = sqlFetchArray($lres)) {
1099 $option_id = $lrow['option_id'];
1100 if (empty($avalue[$option_id])) continue;
1102 // Added 5-09 by BM - Translate label if applicable
1103 $s .= "<tr><td class='bold' valign='top'>" . xl_list_label($lrow['title']) . ":&nbsp;</td>";
1105 $s .= "<td class='text' valign='top'>" . $avalue[$option_id] . "</td></tr>";
1107 $s .= "</table>";
1110 // a set of exam results; 3 radio buttons and a text field:
1111 else if ($data_type == 23) {
1112 $tmp = explode('|', $currvalue);
1113 $avalue = array();
1114 foreach ($tmp as $value) {
1115 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1116 $avalue[$matches[1]] = $matches[2];
1119 $lres = sqlStatement("SELECT * FROM list_options " .
1120 "WHERE list_id = '$list_id' ORDER BY seq, title");
1121 $s .= "<table cellpadding='0' cellspacing='0'>";
1122 while ($lrow = sqlFetchArray($lres)) {
1123 $option_id = $lrow['option_id'];
1124 $restype = substr($avalue[$option_id], 0, 1);
1125 $resnote = substr($avalue[$option_id], 2);
1126 if (empty($restype) && empty($resnote)) continue;
1128 // Added 5-09 by BM - Translate label if applicable
1129 $s .= "<tr><td class='bold' valign='top'>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
1131 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1132 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1133 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1134 $s .= "<td class='text' valign='top'>$restype&nbsp;</td>";
1135 $s .= "<td class='text' valign='top'>$resnote</td>";
1136 $s .= "</tr>";
1138 $s .= "</table>";
1141 // the list of active allergies for the current patient
1142 else if ($data_type == 24) {
1143 $query = "SELECT title, comments FROM lists WHERE " .
1144 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
1145 "ORDER BY begdate";
1146 // echo "<!-- $query -->\n"; // debugging
1147 $lres = sqlStatement($query);
1148 $count = 0;
1149 while ($lrow = sqlFetchArray($lres)) {
1150 if ($count++) $s .= "<br />";
1151 $s .= $lrow['title'];
1152 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
1156 // a set of labeled checkboxes, each with a text field:
1157 else if ($data_type == 25) {
1158 $tmp = explode('|', $currvalue);
1159 $avalue = array();
1160 foreach ($tmp as $value) {
1161 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1162 $avalue[$matches[1]] = $matches[2];
1165 $lres = sqlStatement("SELECT * FROM list_options " .
1166 "WHERE list_id = '$list_id' ORDER BY seq, title");
1167 $s .= "<table cellpadding='0' cellspacing='0'>";
1168 while ($lrow = sqlFetchArray($lres)) {
1169 $option_id = $lrow['option_id'];
1170 $restype = substr($avalue[$option_id], 0, 1);
1171 $resnote = substr($avalue[$option_id], 2);
1172 if (empty($restype) && empty($resnote)) continue;
1174 // Added 5-09 by BM - Translate label if applicable
1175 $s .= "<tr><td class='bold' valign='top'>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
1177 $restype = $restype ? xl('Yes') : xl('No');
1178 $s .= "<td class='text' valign='top'>$restype</td></tr>";
1179 $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1180 $s .= "</tr>";
1182 $s .= "</table>";
1185 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1186 else if ($data_type == 28) {
1187 $tmp = explode('|', $currvalue);
1188 switch(count($tmp)) {
1189 case "3": {
1190 $resnote = $tmp[0];
1191 $restype = $tmp[1];
1192 $resdate = $tmp[2];
1193 } break;
1194 case "2": {
1195 $resnote = $tmp[0];
1196 $restype = $tmp[1];
1197 $resdate = "";
1198 } break;
1199 case "1": {
1200 $resnote = $tmp[0];
1201 $resdate = $restype = "";
1202 } break;
1203 default: {
1204 $restype = $resdate = $resnote = "";
1205 } break;
1207 $s .= "<table cellpadding='0' cellspacing='0'>";
1209 $s .= "<tr>";
1210 $res = "";
1211 if ($restype == "current".$field_id) $res = xl('Current');
1212 if ($restype == "quit".$field_id) $res = xl('Quit');
1213 if ($restype == "never".$field_id) $res = xl('Never');
1214 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1215 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1216 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1217 if (!empty($resnote)) $s .= "<td class='text' valign='top'>$resnote&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1218 if (!empty($res)) $s .= "<td class='text' valign='top'><b>".xl('Status')."</b>:&nbsp;".$res."&nbsp;</td>";
1219 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>$resdate&nbsp;</td>";
1220 $s .= "</tr>";
1221 $s .= "</table>";
1224 return $s;
1227 $CPR = 4; // cells per row of generic data
1228 $last_group = '';
1229 $cell_count = 0;
1230 $item_count = 0;
1232 function disp_end_cell() {
1233 global $item_count, $cell_count;
1234 if ($item_count > 0) {
1235 echo "</td>";
1236 $item_count = 0;
1240 function disp_end_row() {
1241 global $cell_count, $CPR;
1242 disp_end_cell();
1243 if ($cell_count > 0) {
1244 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
1245 echo "</tr>\n";
1246 $cell_count = 0;
1250 function disp_end_group() {
1251 global $last_group;
1252 if (strlen($last_group) > 0) {
1253 disp_end_row();
1257 function display_layout_rows($formtype, $result1, $result2='') {
1258 global $item_count, $cell_count, $last_group, $CPR;
1260 $fres = sqlStatement("SELECT * FROM layout_options " .
1261 "WHERE form_id = '$formtype' AND uor > 0 " .
1262 "ORDER BY group_name, seq");
1264 while ($frow = sqlFetchArray($fres)) {
1265 $this_group = $frow['group_name'];
1266 $titlecols = $frow['titlecols'];
1267 $datacols = $frow['datacols'];
1268 $data_type = $frow['data_type'];
1269 $field_id = $frow['field_id'];
1270 $list_id = $frow['list_id'];
1271 $currvalue = '';
1273 if ($formtype == 'DEM') {
1274 if ($GLOBALS['athletic_team']) {
1275 // Skip fitness level and return-to-play date because those appear
1276 // in a special display/update form on this page.
1277 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1279 if (strpos($field_id, 'em_') === 0) {
1280 // Skip employer related fields, if it's disabled.
1281 if ($GLOBALS['omit_employers']) continue;
1282 $tmp = substr($field_id, 3);
1283 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1285 else {
1286 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1289 else {
1290 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1293 // Handle a data category (group) change.
1294 if (strcmp($this_group, $last_group) != 0) {
1295 $group_name = substr($this_group, 1);
1296 // totally skip generating the employer category, if it's disabled.
1297 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1298 disp_end_group();
1299 $last_group = $this_group;
1302 // Handle starting of a new row.
1303 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1304 disp_end_row();
1305 echo "<tr>";
1306 if ($group_name) {
1307 echo "<td class='groupname'>";
1308 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1309 //echo "<font color='#008800'>$group_name</font>";
1311 // Added 5-09 by BM - Translate label if applicable
1312 echo (xl_layout_label($group_name));
1314 $group_name = '';
1315 } else {
1316 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1317 echo "<td valign='top'>&nbsp;";
1319 echo "</td>";
1322 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1324 // Handle starting of a new label cell.
1325 if ($titlecols > 0) {
1326 disp_end_cell();
1327 //echo "<td class='label' colspan='$titlecols' valign='top'";
1328 echo "<td class='label' colspan='$titlecols' ";
1329 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1330 echo ">";
1331 $cell_count += $titlecols;
1333 ++$item_count;
1335 // Added 5-09 by BM - Translate label if applicable
1336 if ($frow['title']) echo (xl_layout_label($frow['title']).":"); else echo "&nbsp;";
1338 // Handle starting of a new data cell.
1339 if ($datacols > 0) {
1340 disp_end_cell();
1341 //echo "<td class='text data' colspan='$datacols' valign='top'";
1342 echo "<td class='text data' colspan='$datacols'";
1343 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1344 echo ">";
1345 $cell_count += $datacols;
1348 ++$item_count;
1349 echo generate_display_field($frow, $currvalue);
1352 disp_end_group();
1355 function display_layout_tabs($formtype, $result1, $result2='') {
1356 global $item_count, $cell_count, $last_group, $CPR;
1358 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1359 "WHERE form_id = '$formtype' AND uor > 0 " .
1360 "ORDER BY group_name, seq");
1362 $first = true;
1363 while ($frow = sqlFetchArray($fres)) {
1364 $this_group = $frow['group_name'];
1365 $group_name = substr($this_group, 1);
1367 <li <?php echo $first ? 'class="current"' : '' ?>>
1368 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo $group_name?>"><?php echo xl_layout_label($group_name); ?></a>
1369 </li>
1370 <?php
1371 $first = false;
1375 function display_layout_tabs_data($formtype, $result1, $result2='') {
1376 global $item_count, $cell_count, $last_group, $CPR;
1378 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1379 "WHERE form_id = '$formtype' AND uor > 0 " .
1380 "ORDER BY group_name, seq");
1382 $first = true;
1383 while ($frow = sqlFetchArray($fres)) {
1384 $this_group = $frow['group_name'];
1385 $titlecols = $frow['titlecols'];
1386 $datacols = $frow['datacols'];
1387 $data_type = $frow['data_type'];
1388 $field_id = $frow['field_id'];
1389 $list_id = $frow['list_id'];
1390 $currvalue = '';
1392 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1393 "WHERE form_id = '$formtype' AND uor > 0 AND group_name = '$this_group' " .
1394 "ORDER BY seq");
1397 <div class="tab <?php echo $first ? 'current' : '' ?>">
1398 <table border='0' cellpadding='0'>
1400 <?php
1401 while ($group_fields = sqlFetchArray($group_fields_query)) {
1403 $titlecols = $group_fields['titlecols'];
1404 $datacols = $group_fields['datacols'];
1405 $data_type = $group_fields['data_type'];
1406 $field_id = $group_fields['field_id'];
1407 $list_id = $group_fields['list_id'];
1408 $currvalue = '';
1410 if ($formtype == 'DEM') {
1411 if ($GLOBALS['athletic_team']) {
1412 // Skip fitness level and return-to-play date because those appear
1413 // in a special display/update form on this page.
1414 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1416 if (strpos($field_id, 'em_') === 0) {
1417 // Skip employer related fields, if it's disabled.
1418 if ($GLOBALS['omit_employers']) continue;
1419 $tmp = substr($field_id, 3);
1420 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1422 else {
1423 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1426 else {
1427 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1430 // Handle a data category (group) change.
1431 if (strcmp($this_group, $last_group) != 0) {
1432 $group_name = substr($this_group, 1);
1433 // totally skip generating the employer category, if it's disabled.
1434 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1435 $last_group = $this_group;
1438 // Handle starting of a new row.
1439 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1440 disp_end_row();
1441 echo "<tr>";
1444 if ($item_count == 0 && $titlecols == 0) {
1445 $titlecols = 1;
1448 // Handle starting of a new label cell.
1449 if ($titlecols > 0) {
1450 disp_end_cell();
1451 echo "<td class='label' colspan='$titlecols' ";
1452 echo ">";
1453 $cell_count += $titlecols;
1455 ++$item_count;
1457 // Added 5-09 by BM - Translate label if applicable
1458 if ($group_fields['title']) echo (xl_layout_label($group_fields['title']).":"); else echo "&nbsp;";
1460 // Handle starting of a new data cell.
1461 if ($datacols > 0) {
1462 disp_end_cell();
1463 echo "<td class='text data' colspan='$datacols'";
1464 echo ">";
1465 $cell_count += $datacols;
1468 ++$item_count;
1469 echo generate_display_field($group_fields, $currvalue);
1473 </table>
1474 </div>
1476 <?php
1478 $first = false;
1484 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1485 global $item_count, $cell_count, $last_group, $CPR;
1487 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1488 "WHERE form_id = '$formtype' AND uor > 0 " .
1489 "ORDER BY group_name, seq");
1491 $first = true;
1492 while ($frow = sqlFetchArray($fres)) {
1493 $this_group = $frow['group_name'];
1494 $group_name = substr($this_group, 1);
1495 $titlecols = $frow['titlecols'];
1496 $datacols = $frow['datacols'];
1497 $data_type = $frow['data_type'];
1498 $field_id = $frow['field_id'];
1499 $list_id = $frow['list_id'];
1500 $currvalue = '';
1502 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1503 "WHERE form_id = '$formtype' AND uor > 0 AND group_name = '$this_group' " .
1504 "ORDER BY seq");
1507 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name?>" >
1508 <table border='0' cellpadding='0'>
1510 <?php
1511 while ($group_fields = sqlFetchArray($group_fields_query)) {
1513 $titlecols = $group_fields['titlecols'];
1514 $datacols = $group_fields['datacols'];
1515 $data_type = $group_fields['data_type'];
1516 $field_id = $group_fields['field_id'];
1517 $list_id = $group_fields['list_id'];
1518 $currvalue = '';
1520 if ($formtype == 'DEM') {
1521 if ($GLOBALS['athletic_team']) {
1522 // Skip fitness level and return-to-play date because those appear
1523 // in a special display/update form on this page.
1524 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1526 if (strpos($field_id, 'em_') === 0) {
1527 // Skip employer related fields, if it's disabled.
1528 if ($GLOBALS['omit_employers']) continue;
1529 $tmp = substr($field_id, 3);
1530 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1532 else {
1533 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1536 else {
1537 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1540 // Handle a data category (group) change.
1541 if (strcmp($this_group, $last_group) != 0) {
1542 $group_name = substr($this_group, 1);
1543 // totally skip generating the employer category, if it's disabled.
1544 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1545 $last_group = $this_group;
1548 // Handle starting of a new row.
1549 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1550 disp_end_row();
1551 echo "<tr>";
1554 if ($item_count == 0 && $titlecols == 0) {
1555 $titlecols = 1;
1558 // Handle starting of a new label cell.
1559 if ($titlecols > 0) {
1560 disp_end_cell();
1561 echo "<td class='label' colspan='$titlecols' ";
1562 echo ">";
1563 $cell_count += $titlecols;
1565 ++$item_count;
1567 // Added 5-09 by BM - Translate label if applicable
1568 if ($group_fields['title']) echo (xl_layout_label($group_fields['title']).":"); else echo "&nbsp;";
1570 // Handle starting of a new data cell.
1571 if ($datacols > 0) {
1572 disp_end_cell();
1573 echo "<td class='text data' colspan='$datacols'";
1574 echo ">";
1575 $cell_count += $datacols;
1578 ++$item_count;
1579 echo generate_form_field($group_fields, $currvalue);
1583 </table>
1584 </div>
1586 <?php
1588 $first = false;
1593 // From the currently posted HTML form, this gets the value of the
1594 // field corresponding to the provided layout_options table row.
1596 function get_layout_form_value($frow, $maxlength=255) {
1597 $data_type = $frow['data_type'];
1598 $field_id = $frow['field_id'];
1599 $value = '';
1600 if (isset($_POST["form_$field_id"])) {
1601 if ($data_type == 21) {
1602 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1603 // must be concatenated into a |-separated string.
1604 foreach ($_POST["form_$field_id"] as $key => $val) {
1605 if (strlen($value)) $value .= '|';
1606 $value .= $key;
1609 else if ($data_type == 22) {
1610 // $_POST["form_$field_id"] is an array of text fields to be imploded
1611 // into "key:value|key:value|...".
1612 foreach ($_POST["form_$field_id"] as $key => $val) {
1613 $val = str_replace('|', ' ', $val);
1614 if (strlen($value)) $value .= '|';
1615 $value .= "$key:$val";
1618 else if ($data_type == 23) {
1619 // $_POST["form_$field_id"] is an array of text fields with companion
1620 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1621 foreach ($_POST["form_$field_id"] as $key => $val) {
1622 $restype = $_POST["radio_{$field_id}"][$key];
1623 if (empty($restype)) $restype = '0';
1624 $val = str_replace('|', ' ', $val);
1625 if (strlen($value)) $value .= '|';
1626 $value .= "$key:$restype:$val";
1629 else if ($data_type == 25) {
1630 // $_POST["form_$field_id"] is an array of text fields with companion
1631 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1632 foreach ($_POST["form_$field_id"] as $key => $val) {
1633 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
1634 $val = str_replace('|', ' ', $val);
1635 if (strlen($value)) $value .= '|';
1636 $value .= "$key:$restype:$val";
1639 else if ($data_type == 28) {
1640 // $_POST["form_$field_id"] is an date text fields with companion
1641 // radio buttons to be imploded into "notes|type|date".
1642 $restype = $_POST["radio_{$field_id}"];
1643 if (empty($restype)) $restype = '0';
1644 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1645 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1646 $value = "$resnote|$restype|$resdate";
1648 else {
1649 $value = $_POST["form_$field_id"];
1653 // Better to die than to silently truncate data!
1654 if ($maxlength && $data_type != 3 && strlen($value) > $maxlength)
1655 die(xl('ERROR: Field') . " '$field_id' " . xl('is too long') .
1656 ":<br />&nbsp;<br />$value");
1658 // Make sure the return value is quote-safe.
1659 return formTrim($value);
1662 // Generate JavaScript validation logic for the required fields.
1664 function generate_layout_validation($form_id) {
1665 $fres = sqlStatement("SELECT * FROM layout_options " .
1666 "WHERE form_id = '$form_id' AND uor > 0 AND field_id != '' " .
1667 "ORDER BY group_name, seq");
1669 while ($frow = sqlFetchArray($fres)) {
1670 if ($frow['uor'] < 2) continue;
1671 $data_type = $frow['data_type'];
1672 $field_id = $frow['field_id'];
1673 $fldtitle = $frow['title'];
1674 if (!$fldtitle) $fldtitle = $frow['description'];
1675 $fldname = "form_$field_id";
1676 switch($data_type) {
1677 case 1:
1678 case 11:
1679 case 12:
1680 case 13:
1681 case 14:
1682 case 26:
1683 echo
1684 " if (f.$fldname.selectedIndex <= 0) {\n" .
1685 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1686 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
1687 " }\n";
1688 break;
1689 case 27: // radio buttons
1690 echo
1691 " var i = 0;\n" .
1692 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
1693 " if (i >= f.$fldname.length) {\n" .
1694 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
1695 " }\n";
1696 break;
1697 case 2:
1698 case 3:
1699 case 4:
1700 case 15:
1701 echo
1702 " if (trimlen(f.$fldname.value) == 0) {\n" .
1703 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1704 " $('#form_" . $field_id . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
1705 " $('#form_" . $field_id . "').attr('style','background:red'); \n" .
1706 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
1707 " } else { " .
1708 " $('#form_" . $field_id . "').attr('style',''); " .
1709 " $('#form_" . $field_id . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
1710 " } \n";
1711 break;