bug fixes - original language-ethnicity was deleted
[openemr.git] / library / options.inc.php
blob9e4b3cd96c2abb0597d6caa0d0ff8bc66b759867
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");
18 require_once("formatting.inc.php");
20 $date_init = "";
22 function get_pharmacies() {
23 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
24 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
25 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
26 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
27 "AND p.type = 2 " .
28 "ORDER BY name, area_code, prefix, number");
31 // Function to generate a drop-list.
33 function generate_select_list($tag_name, $list_id, $currvalue, $title,
34 $empty_name=' ', $class='', $onchange='')
36 $s = '';
37 $s .= "<select name='$tag_name' id='$tag_name'";
38 if ($class) $s .= " class='$class'";
39 if ($onchange) $s .= " onchange='$onchange'";
40 $s .= " title='$title'>";
41 if ($empty_name) $s .= "<option value=''>" . xl($empty_name) . "</option>";
42 $lres = sqlStatement("SELECT * FROM list_options " .
43 "WHERE list_id = '$list_id' ORDER BY seq, title");
44 $got_selected = FALSE;
45 while ($lrow = sqlFetchArray($lres)) {
46 $s .= "<option value='" . $lrow['option_id'] . "'";
47 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
48 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
50 $s .= " selected";
51 $got_selected = TRUE;
53 $s .= ">" . xl_list_label($lrow['title']) . "</option>\n";
55 if (!$got_selected && strlen($currvalue) > 0) {
56 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
57 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
58 $s .= "</select>";
59 $s .= " <font color='red' title='" .
60 xl('Please choose a valid selection from the list.') . "'>" .
61 xl('Fix this') . "!</font>";
63 else {
64 $s .= "</select>";
66 return $s;
69 function generate_form_field($frow, $currvalue) {
70 global $rootdir, $date_init;
72 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
74 $data_type = $frow['data_type'];
75 $field_id = $frow['field_id'];
76 $list_id = $frow['list_id'];
78 // Added 5-09 by BM - Translate description if applicable
79 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
81 // added 5-2009 by BM to allow modification of the 'empty' text title field.
82 // Can pass $frow['empty_title'] with this variable, otherwise
83 // will default to 'Unassigned'.
84 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
85 // if make $frow['empty_title'] equal to 'SKIP'
86 $showEmpty = true;
87 if (isset($frow['empty_title'])) {
88 if ($frow['empty_title'] == "SKIP") {
89 //do not display an 'empty' choice
90 $showEmpty = false;
91 $empty_title = "Unassigned";
93 else {
94 $empty_title = $frow['empty_title'];
97 else {
98 $empty_title = "Unassigned";
101 // generic single-selection list
102 if ($data_type == 1) {
103 echo generate_select_list("form_$field_id", $list_id, $currvalue,
104 $description, $showEmpty ? $empty_title : '');
107 // simple text field
108 else if ($data_type == 2) {
109 echo "<input type='text'" .
110 " name='form_$field_id'" .
111 " id='form_$field_id'" .
112 " size='" . $frow['fld_length'] . "'" .
113 " maxlength='" . $frow['max_length'] . "'" .
114 " title='$description'" .
115 " value='$currescaped'";
116 if (strpos($frow['edit_options'], 'C') !== FALSE)
117 echo " onchange='capitalizeMe(this)'";
118 $tmp = addslashes($GLOBALS['gbl_mask_patient_id']);
119 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
120 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
121 echo " onblur='maskblur(this,\"$tmp\")'";
123 echo " />";
126 // long or multi-line text field
127 else if ($data_type == 3) {
128 echo "<textarea" .
129 " name='form_$field_id'" .
130 " id='form_$field_id'" .
131 " title='$description'" .
132 " cols='" . $frow['fld_length'] . "'" .
133 " rows='" . $frow['max_length'] . "'>" .
134 $currescaped . "</textarea>";
137 // date
138 else if ($data_type == 4) {
139 echo "<input type='text' size='10' name='form_$field_id' id='form_$field_id'" .
140 " value='$currescaped'" .
141 " title='$description'" .
142 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
143 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
144 " id='img_$field_id' border='0' alt='[?]' style='cursor:pointer'" .
145 " title='" . xl('Click here to choose a date') . "' />";
146 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
149 // provider list, local providers only
150 else if ($data_type == 10) {
151 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
152 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
153 "AND authorized = 1 " .
154 "ORDER BY lname, fname");
155 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
156 echo "<option value=''>" . xl('Unassigned') . "</option>";
157 while ($urow = sqlFetchArray($ures)) {
158 $uname = $urow['fname'] . ' ' . $urow['lname'];
159 echo "<option value='" . $urow['id'] . "'";
160 if ($urow['id'] == $currvalue) echo " selected";
161 echo ">$uname</option>";
163 echo "</select>";
166 // provider list, including address book entries with an NPI number
167 else if ($data_type == 11) {
168 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
169 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
170 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
171 "ORDER BY lname, fname");
172 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
173 echo "<option value=''>" . xl('Unassigned') . "</option>";
174 while ($urow = sqlFetchArray($ures)) {
175 $uname = $urow['fname'] . ' ' . $urow['lname'];
176 echo "<option value='" . $urow['id'] . "'";
177 if ($urow['id'] == $currvalue) echo " selected";
178 echo ">$uname</option>";
180 echo "</select>";
183 // pharmacy list
184 else if ($data_type == 12) {
185 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
186 echo "<option value='0'></option>";
187 $pres = get_pharmacies();
188 while ($prow = sqlFetchArray($pres)) {
189 $key = $prow['id'];
190 echo "<option value='$key'";
191 if ($currvalue == $key) echo " selected";
192 echo '>' . $prow['name'] . ' ' . $prow['area_code'] . '-' .
193 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
194 $prow['line1'] . ' / ' . $prow['city'] . "</option>";
196 echo "</select>";
199 // squads
200 else if ($data_type == 13) {
201 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
202 echo "<option value=''>&nbsp;</option>";
203 $squads = acl_get_squads();
204 if ($squads) {
205 foreach ($squads as $key => $value) {
206 echo "<option value='$key'";
207 if ($currvalue == $key) echo " selected";
208 echo ">" . $value[3] . "</option>\n";
211 echo "</select>";
214 // Address book, preferring organization name if it exists and is not in
215 // parentheses, and excluding local users who are not providers.
216 // Supports "referred to" practitioners and facilities.
217 // Alternatively the letter O in edit_options means that abook_type
218 // must begin with "ord_", indicating types used with the procedure
219 // ordering system.
220 // Alternatively the letter V in edit_options means that abook_type
221 // must be "vendor", indicating the Vendor type.
222 else if ($data_type == 14) {
223 if (strpos($frow['edit_options'], 'O') !== FALSE)
224 $tmp = "abook_type LIKE 'ord\\_%'";
225 else if (strpos($frow['edit_options'], 'V') !== FALSE)
226 $tmp = "abook_type LIKE 'vendor%'";
227 else
228 $tmp = "( username = '' OR authorized = 1 )";
229 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
230 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
231 "AND $tmp " .
232 "ORDER BY organization, lname, fname");
233 echo "<select name='form_$field_id' id='form_$field_id' title='$description'>";
234 echo "<option value=''>" . xl('Unassigned') . "</option>";
235 while ($urow = sqlFetchArray($ures)) {
236 $uname = $urow['organization'];
237 if (empty($uname) || substr($uname, 0, 1) == '(') {
238 $uname = $urow['lname'];
239 if ($urow['fname']) $uname .= ", " . $urow['fname'];
241 echo "<option value='" . $urow['id'] . "'";
242 $title = $urow['username'] ? xl('Local') : xl('External');
243 echo " title='$title'";
244 if ($urow['id'] == $currvalue) echo " selected";
245 echo ">$uname</option>";
247 echo "</select>";
250 // a billing code (only one of these allowed!)
251 else if ($data_type == 15) {
252 echo "<input type='text'" .
253 " name='form_$field_id'" .
254 " id='form_related_code'" .
255 " size='" . $frow['fld_length'] . "'" .
256 " maxlength='" . $frow['max_length'] . "'" .
257 " title='$description'" .
258 " value='$currescaped'" .
259 " onclick='sel_related()' readonly" .
260 " />";
263 // a set of labeled checkboxes
264 else if ($data_type == 21) {
265 // In this special case, fld_length is the number of columns generated.
266 $cols = max(1, $frow['fld_length']);
267 $avalue = explode('|', $currvalue);
268 $lres = sqlStatement("SELECT * FROM list_options " .
269 "WHERE list_id = '$list_id' ORDER BY seq, title");
270 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
271 $tdpct = (int) (100 / $cols);
272 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
273 $option_id = $lrow['option_id'];
274 // if ($count) echo "<br />";
275 if ($count % $cols == 0) {
276 if ($count) echo "</tr>";
277 echo "<tr>";
279 echo "<td width='$tdpct%'>";
280 echo "<input type='checkbox' name='form_{$field_id}[$option_id]' id='form_{$field_id}[$option_id]' value='1'";
281 if (in_array($option_id, $avalue)) echo " checked";
283 // Added 5-09 by BM - Translate label if applicable
284 echo ">" . xl_list_label($lrow['title']);
286 echo "</td>";
288 if ($count) {
289 echo "</tr>";
290 if ($count > $cols) {
291 // Add some space after multiple rows of checkboxes.
292 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
295 echo "</table>";
298 // a set of labeled text input fields
299 else if ($data_type == 22) {
300 $tmp = explode('|', $currvalue);
301 $avalue = array();
302 foreach ($tmp as $value) {
303 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
304 $avalue[$matches[1]] = $matches[2];
307 $lres = sqlStatement("SELECT * FROM list_options " .
308 "WHERE list_id = '$list_id' ORDER BY seq, title");
309 echo "<table cellpadding='0' cellspacing='0'>";
310 while ($lrow = sqlFetchArray($lres)) {
311 $option_id = $lrow['option_id'];
312 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
313 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
315 // Added 5-09 by BM - Translate label if applicable
316 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
318 echo "<td><input type='text'" .
319 " name='form_{$field_id}[$option_id]'" .
320 " id='form_{$field_id}[$option_id]'" .
321 " size='$fldlength'" .
322 " maxlength='$maxlength'" .
323 " value='" . $avalue[$option_id] . "'";
324 echo " /></td></tr>";
326 echo "</table>";
329 // a set of exam results; 3 radio buttons and a text field:
330 else if ($data_type == 23) {
331 $tmp = explode('|', $currvalue);
332 $avalue = array();
333 foreach ($tmp as $value) {
334 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
335 $avalue[$matches[1]] = $matches[2];
338 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
339 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
340 $lres = sqlStatement("SELECT * FROM list_options " .
341 "WHERE list_id = '$list_id' ORDER BY seq, title");
342 echo "<table cellpadding='0' cellspacing='0'>";
343 echo "<tr><td>&nbsp;</td><td class='bold'>" . xl('N/A') .
344 "&nbsp;</td><td class='bold'>" . xl('Nor') . "&nbsp;</td>" .
345 "<td class='bold'>" . xl('Abn') . "&nbsp;</td><td class='bold'>" .
346 xl('Date/Notes') . "</td></tr>";
347 while ($lrow = sqlFetchArray($lres)) {
348 $option_id = $lrow['option_id'];
349 $restype = substr($avalue[$option_id], 0, 1);
350 $resnote = substr($avalue[$option_id], 2);
352 // Added 5-09 by BM - Translate label if applicable
353 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
355 for ($i = 0; $i < 3; ++$i) {
356 echo "<td><input type='radio'" .
357 " name='radio_{$field_id}[$option_id]'" .
358 " id='radio_{$field_id}[$option_id]'" .
359 " value='$i'";
360 if ($restype === "$i") echo " checked";
361 echo " /></td>";
363 echo "<td><input type='text'" .
364 " name='form_{$field_id}[$option_id]'" .
365 " id='form_{$field_id}[$option_id]'" .
366 " size='$fldlength'" .
367 " maxlength='$maxlength'" .
368 " value='$resnote' /></td>";
369 echo "</tr>";
371 echo "</table>";
374 // the list of active allergies for the current patient
375 // this is read-only!
376 else if ($data_type == 24) {
377 $query = "SELECT title, comments FROM lists WHERE " .
378 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
379 "ORDER BY begdate";
380 // echo "<!-- $query -->\n"; // debugging
381 $lres = sqlStatement($query);
382 $count = 0;
383 while ($lrow = sqlFetchArray($lres)) {
384 if ($count++) echo "<br />";
385 echo $lrow['title'];
386 if ($lrow['comments']) echo ' (' . $lrow['comments'] . ')';
390 // a set of labeled checkboxes, each with a text field:
391 else if ($data_type == 25) {
392 $tmp = explode('|', $currvalue);
393 $avalue = array();
394 foreach ($tmp as $value) {
395 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
396 $avalue[$matches[1]] = $matches[2];
399 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
400 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
401 $lres = sqlStatement("SELECT * FROM list_options " .
402 "WHERE list_id = '$list_id' ORDER BY seq, title");
403 echo "<table cellpadding='0' cellspacing='0'>";
404 while ($lrow = sqlFetchArray($lres)) {
405 $option_id = $lrow['option_id'];
406 $restype = substr($avalue[$option_id], 0, 1);
407 $resnote = substr($avalue[$option_id], 2);
409 // Added 5-09 by BM - Translate label if applicable
410 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
412 echo "<td><input type='checkbox' name='check_{$field_id}[$option_id]' id='check_{$field_id}[$option_id]' value='1'";
413 if ($restype) echo " checked";
414 echo " />&nbsp;</td>";
415 echo "<td><input type='text'" .
416 " name='form_{$field_id}[$option_id]'" .
417 " id='form_{$field_id}[$option_id]'" .
418 " size='$fldlength'" .
419 " maxlength='$maxlength'" .
420 " value='$resnote' /></td>";
421 echo "</tr>";
423 echo "</table>";
426 // single-selection list with ability to add to it
427 else if ($data_type == 26) {
428 echo "<select class='addtolistclass_$list_id' name='form_$field_id' id='form_$field_id' title='$description'>";
429 if ($showEmpty) echo "<option value=''>" . xl($empty_title) . "</option>";
430 $lres = sqlStatement("SELECT * FROM list_options " .
431 "WHERE list_id = '$list_id' ORDER BY seq, title");
432 $got_selected = FALSE;
433 while ($lrow = sqlFetchArray($lres)) {
434 echo "<option value='" . $lrow['option_id'] . "'";
435 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
436 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
438 echo " selected";
439 $got_selected = TRUE;
441 // Added 5-09 by BM - Translate label if applicable
442 echo ">" . xl_list_label($lrow['title']) . "</option>\n";
444 if (!$got_selected && strlen($currvalue) > 0) {
445 echo "<option value='$currescaped' selected>* $currescaped *</option>";
446 echo "</select>";
447 echo " <font color='red' title='" . xl('Please choose a valid selection from the list.') . "'>" . xl('Fix this') . "!</font>";
449 else {
450 echo "</select>";
452 // show the add button if user has access to correct list
453 $outputAddButton = "<input type='button' id='addtolistid_".$list_id."' fieldid='form_".$field_id."' class='addtolist' value='" . xl('Add') . "'>";
454 if (aco_exist('lists', $list_id)) {
455 // a specific aco exist for this list, so ensure access
456 if (acl_check('lists', $list_id)) echo $outputAddButton;
458 else {
459 // no specific aco exist for this list, so check for access to 'default' list
460 if (acl_check('lists', 'default')) echo $outputAddButton;
464 // a set of labeled radio buttons
465 else if ($data_type == 27) {
466 // In this special case, fld_length is the number of columns generated.
467 $cols = max(1, $frow['fld_length']);
468 $lres = sqlStatement("SELECT * FROM list_options " .
469 "WHERE list_id = '$list_id' ORDER BY seq, title");
470 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
471 $tdpct = (int) (100 / $cols);
472 $got_selected = FALSE;
473 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
474 $option_id = $lrow['option_id'];
475 if ($count % $cols == 0) {
476 if ($count) echo "</tr>";
477 echo "<tr>";
479 echo "<td width='$tdpct%'>";
480 echo "<input type='radio' name='form_{$field_id}' id='form_{$field_id}[$option_id]' value='$option_id'";
481 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
482 (strlen($currvalue) > 0 && $option_id == $currvalue))
484 echo " checked";
485 $got_selected = TRUE;
487 echo ">" . xl_list_label($lrow['title']);
488 echo "</td>";
490 if ($count) {
491 echo "</tr>";
492 if ($count > $cols) {
493 // Add some space after multiple rows of radio buttons.
494 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
497 echo "</table>";
498 if (!$got_selected && strlen($currvalue) > 0) {
499 echo "$currvalue <font color='red' title='" . xl('Please choose a valid selection.') . "'>" . xl('Fix this') . "!</font>";
503 // special case for history of lifestyle status; 3 radio buttons and a date text field:
504 else if ($data_type == 28) {
505 $tmp = explode('|', $currvalue);
506 switch(count($tmp)) {
507 case "3": {
508 $resnote = $tmp[0];
509 $restype = $tmp[1];
510 $resdate = $tmp[2];
511 } break;
512 case "2": {
513 $resnote = $tmp[0];
514 $restype = $tmp[1];
515 $resdate = "";
516 } break;
517 case "1": {
518 $resnote = $tmp[0];
519 $resdate = $restype = "";
520 } break;
521 default: {
522 $restype = $resdate = $resnote = "";
523 } break;
525 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
526 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
528 echo "<table cellpadding='0' cellspacing='0'>";
529 echo "<tr>";
530 // input text
531 echo "<td><input type='text'" .
532 " name='form_$field_id'" .
533 " id='form_$field_id'" .
534 " size='$fldlength'" .
535 " maxlength='$maxlength'" .
536 " value='$resnote' />&nbsp;</td>";
537 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;".xl('Status').":&nbsp;</td>";
538 // current
539 echo "<td><input type='radio'" .
540 " name='radio_{$field_id}'" .
541 " id='radio_{$field_id}[current]'" .
542 " value='current".$field_id."'";
543 if ($restype == "current".$field_id) echo " checked";
544 // echo " onclick=\"return clinical_alerts_popup(this.value,'Patient_History')\" />".xl('Current')."&nbsp;</td>";
545 echo "/>".xl('Current')."&nbsp;</td>";
546 // quit
547 echo "<td><input type='radio'" .
548 " name='radio_{$field_id}'" .
549 " id='radio_{$field_id}[quit]'" .
550 " value='quit".$field_id."'";
551 if ($restype == "quit".$field_id) echo " checked";
552 echo "/>".xl('Quit')."&nbsp;</td>";
553 // quit date
554 echo "<td><input type='text' size='6' name='date_$field_id' id='date_$field_id'" .
555 " value='$resdate'" .
556 " title='$description'" .
557 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
558 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
559 " id='img_$field_id' border='0' alt='[?]' style='cursor:pointer'" .
560 " title='" . xl('Click here to choose a date') . "' />&nbsp;</td>";
561 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
562 // never
563 echo "<td><input type='radio'" .
564 " name='radio_{$field_id}'" .
565 " id='radio_{$field_id}[never]'" .
566 " value='never".$field_id."'";
567 if ($restype == "never".$field_id) echo " checked";
568 echo " />".xl('Never')."&nbsp;</td>";
569 // Not Applicable
570 echo "<td><input type='radio'" .
571 " name='radio_{$field_id}'" .
572 " id='radio_{$field_id}[not_applicable]'" .
573 " value='not_applicable".$field_id."'";
574 if ($restype == "not_applicable".$field_id) echo " checked";
575 echo " />".xl('N/A')."&nbsp;</td>";
576 echo "</tr>";
577 echo "</table>";
582 function generate_print_field($frow, $currvalue) {
583 global $rootdir, $date_init;
585 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
587 $data_type = $frow['data_type'];
588 $field_id = $frow['field_id'];
589 $list_id = $frow['list_id'];
590 $fld_length = $frow['fld_length'];
592 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
594 // Can pass $frow['empty_title'] with this variable, otherwise
595 // will default to 'Unassigned'.
596 // If it is 'SKIP' then an empty text title is completely skipped.
597 $showEmpty = true;
598 if (isset($frow['empty_title'])) {
599 if ($frow['empty_title'] == "SKIP") {
600 //do not display an 'empty' choice
601 $showEmpty = false;
602 $empty_title = "Unassigned";
604 else {
605 $empty_title = $frow['empty_title'];
608 else {
609 $empty_title = "Unassigned";
612 // generic single-selection list
613 if ($data_type == 1 || $data_type == 26) {
614 if (empty($fld_length)) {
615 if ($list_id == 'titles') {
616 $fld_length = 3;
617 } else {
618 $fld_length = 10;
621 $tmp = '';
622 if ($currvalue) {
623 $lrow = sqlQuery("SELECT title FROM list_options " .
624 "WHERE list_id = '$list_id' AND option_id = '$currvalue'");
625 $tmp = xl_list_label($lrow['title']);
626 if (empty($tmp)) $tmp = "($currvalue)";
628 /*****************************************************************
629 echo "<input type='text'" .
630 " size='$fld_length'" .
631 " value='$tmp'" .
632 " class='under'" .
633 " />";
634 *****************************************************************/
635 if ($tmp === '') $tmp = '&nbsp;';
636 echo $tmp;
639 // simple text field
640 else if ($data_type == 2 || $data_type == 15) {
641 /*****************************************************************
642 echo "<input type='text'" .
643 " size='$fld_length'" .
644 " value='$currescaped'" .
645 " class='under'" .
646 " />";
647 *****************************************************************/
648 if ($currescaped === '') $currescaped = '&nbsp;';
649 echo $currescaped;
652 // long or multi-line text field
653 else if ($data_type == 3) {
654 echo "<textarea" .
655 " cols='$fld_length'" .
656 " rows='" . $frow['max_length'] . "'>" .
657 $currescaped . "</textarea>";
660 // date
661 else if ($data_type == 4) {
662 /*****************************************************************
663 echo "<input type='text' size='10'" .
664 " value='$currescaped'" .
665 " title='$description'" .
666 " class='under'" .
667 " />";
668 *****************************************************************/
669 if ($currescaped === '') $currescaped = '&nbsp;';
670 echo oeFormatShortDate($currescaped);
673 // provider list
674 else if ($data_type == 10 || $data_type == 11) {
675 $tmp = '';
676 if ($currvalue) {
677 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
678 "WHERE id = '$currvalue'");
679 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
680 if (empty($tmp)) $tmp = "($currvalue)";
682 /*****************************************************************
683 echo "<input type='text'" .
684 " size='$fld_length'" .
685 " value='$tmp'" .
686 " class='under'" .
687 " />";
688 *****************************************************************/
689 if ($tmp === '') $tmp = '&nbsp;';
690 echo $tmp;
693 // pharmacy list
694 else if ($data_type == 12) {
695 $tmp = '';
696 if ($currvalue) {
697 $pres = get_pharmacies();
698 while ($prow = sqlFetchArray($pres)) {
699 $key = $prow['id'];
700 if ($currvalue == $key) {
701 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
702 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
703 $prow['line1'] . ' / ' . $prow['city'];
706 if (empty($tmp)) $tmp = "($currvalue)";
708 /*****************************************************************
709 echo "<input type='text'" .
710 " size='$fld_length'" .
711 " value='$tmp'" .
712 " class='under'" .
713 " />";
714 *****************************************************************/
715 if ($tmp === '') $tmp = '&nbsp;';
716 echo $tmp;
719 // squads
720 else if ($data_type == 13) {
721 $tmp = '';
722 if ($currvalue) {
723 $squads = acl_get_squads();
724 if ($squads) {
725 foreach ($squads as $key => $value) {
726 if ($currvalue == $key) {
727 $tmp = $value[3];
731 if (empty($tmp)) $tmp = "($currvalue)";
733 /*****************************************************************
734 echo "<input type='text'" .
735 " size='$fld_length'" .
736 " value='$tmp'" .
737 " class='under'" .
738 " />";
739 *****************************************************************/
740 if ($tmp === '') $tmp = '&nbsp;';
741 echo $tmp;
744 // Address book.
745 else if ($data_type == 14) {
746 $tmp = '';
747 if ($currvalue) {
748 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
749 "WHERE id = '$currvalue'");
750 $uname = $urow['lname'];
751 if ($urow['fname']) $uname .= ", " . $urow['fname'];
752 $tmp = $uname;
753 if (empty($tmp)) $tmp = "($currvalue)";
755 /*****************************************************************
756 echo "<input type='text'" .
757 " size='$fld_length'" .
758 " value='$tmp'" .
759 " class='under'" .
760 " />";
761 *****************************************************************/
762 if ($tmp === '') $tmp = '&nbsp;';
763 echo $tmp;
766 // a set of labeled checkboxes
767 else if ($data_type == 21) {
768 // In this special case, fld_length is the number of columns generated.
769 $cols = max(1, $fld_length);
770 $avalue = explode('|', $currvalue);
771 $lres = sqlStatement("SELECT * FROM list_options " .
772 "WHERE list_id = '$list_id' ORDER BY seq, title");
773 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
774 $tdpct = (int) (100 / $cols);
775 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
776 $option_id = $lrow['option_id'];
777 if ($count % $cols == 0) {
778 if ($count) echo "</tr>";
779 echo "<tr>";
781 echo "<td width='$tdpct%'>";
782 echo "<input type='checkbox'";
783 if (in_array($option_id, $avalue)) echo " checked";
784 echo ">" . xl_list_label($lrow['title']);
785 echo "</td>";
787 if ($count) {
788 echo "</tr>";
789 if ($count > $cols) {
790 // Add some space after multiple rows of checkboxes.
791 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
794 echo "</table>";
797 // a set of labeled text input fields
798 else if ($data_type == 22) {
799 $tmp = explode('|', $currvalue);
800 $avalue = array();
801 foreach ($tmp as $value) {
802 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
803 $avalue[$matches[1]] = $matches[2];
806 $lres = sqlStatement("SELECT * FROM list_options " .
807 "WHERE list_id = '$list_id' ORDER BY seq, title");
808 echo "<table cellpadding='0' cellspacing='0'>";
809 while ($lrow = sqlFetchArray($lres)) {
810 $option_id = $lrow['option_id'];
811 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
812 $fldlength = empty($fld_length) ? 20 : $fld_length;
813 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
814 echo "<td><input type='text'" .
815 " size='$fldlength'" .
816 " value='" . $avalue[$option_id] . "'" .
817 " class='under'" .
818 " /></td></tr>";
820 echo "</table>";
823 // a set of exam results; 3 radio buttons and a text field:
824 else if ($data_type == 23) {
825 $tmp = explode('|', $currvalue);
826 $avalue = array();
827 foreach ($tmp as $value) {
828 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
829 $avalue[$matches[1]] = $matches[2];
832 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
833 $fldlength = empty($fld_length) ? 20 : $fld_length;
834 $lres = sqlStatement("SELECT * FROM list_options " .
835 "WHERE list_id = '$list_id' ORDER BY seq, title");
836 echo "<table cellpadding='0' cellspacing='0'>";
837 echo "<tr><td>&nbsp;</td><td class='bold'>" . xl('N/A') .
838 "&nbsp;</td><td class='bold'>" . xl('Nor') . "&nbsp;</td>" .
839 "<td class='bold'>" . xl('Abn') . "&nbsp;</td><td class='bold'>" .
840 xl('Date/Notes') . "</td></tr>";
841 while ($lrow = sqlFetchArray($lres)) {
842 $option_id = $lrow['option_id'];
843 $restype = substr($avalue[$option_id], 0, 1);
844 $resnote = substr($avalue[$option_id], 2);
845 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
846 for ($i = 0; $i < 3; ++$i) {
847 echo "<td><input type='radio'";
848 if ($restype === "$i") echo " checked";
849 echo " /></td>";
851 echo "<td><input type='text'" .
852 " size='$fldlength'" .
853 " value='$resnote'" .
854 " class='under' /></td>" .
855 "</tr>";
857 echo "</table>";
860 // the list of active allergies for the current patient
861 // this is read-only!
862 else if ($data_type == 24) {
863 $query = "SELECT title, comments FROM lists WHERE " .
864 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
865 "ORDER BY begdate";
866 $lres = sqlStatement($query);
867 $count = 0;
868 while ($lrow = sqlFetchArray($lres)) {
869 if ($count++) echo "<br />";
870 echo $lrow['title'];
871 if ($lrow['comments']) echo ' (' . $lrow['comments'] . ')';
875 // a set of labeled checkboxes, each with a text field:
876 else if ($data_type == 25) {
877 $tmp = explode('|', $currvalue);
878 $avalue = array();
879 foreach ($tmp as $value) {
880 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
881 $avalue[$matches[1]] = $matches[2];
884 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
885 $fldlength = empty($fld_length) ? 20 : $fld_length;
886 $lres = sqlStatement("SELECT * FROM list_options " .
887 "WHERE list_id = '$list_id' ORDER BY seq, title");
888 echo "<table cellpadding='0' cellspacing='0'>";
889 while ($lrow = sqlFetchArray($lres)) {
890 $option_id = $lrow['option_id'];
891 $restype = substr($avalue[$option_id], 0, 1);
892 $resnote = substr($avalue[$option_id], 2);
893 echo "<tr><td>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
894 echo "<td><input type='checkbox'";
895 if ($restype) echo " checked";
896 echo " />&nbsp;</td>";
897 echo "<td><input type='text'" .
898 " size='$fldlength'" .
899 " value='$resnote'" .
900 " class='under'" .
901 " /></td>" .
902 "</tr>";
904 echo "</table>";
907 // a set of labeled radio buttons
908 else if ($data_type == 27) {
909 // In this special case, fld_length is the number of columns generated.
910 $cols = max(1, $frow['fld_length']);
911 $lres = sqlStatement("SELECT * FROM list_options " .
912 "WHERE list_id = '$list_id' ORDER BY seq, title");
913 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
914 $tdpct = (int) (100 / $cols);
915 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
916 $option_id = $lrow['option_id'];
917 if ($count % $cols == 0) {
918 if ($count) echo "</tr>";
919 echo "<tr>";
921 echo "<td width='$tdpct%'>";
922 echo "<input type='radio'";
923 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
924 (strlen($currvalue) > 0 && $option_id == $currvalue))
926 echo " checked";
928 echo ">" . xl_list_label($lrow['title']);
929 echo "</td>";
931 if ($count) {
932 echo "</tr>";
933 if ($count > $cols) {
934 // Add some space after multiple rows of radio buttons.
935 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
938 echo "</table>";
941 // special case for history of lifestyle status; 3 radio buttons and a date text field:
942 else if ($data_type == 28) {
943 $tmp = explode('|', $currvalue);
944 switch(count($tmp)) {
945 case "3": {
946 $resnote = $tmp[0];
947 $restype = $tmp[1];
948 $resdate = $tmp[2];
949 } break;
950 case "2": {
951 $resnote = $tmp[0];
952 $restype = $tmp[1];
953 $resdate = "";
954 } break;
955 case "1": {
956 $resnote = $tmp[0];
957 $resdate = $restype = "";
958 } break;
959 default: {
960 $restype = $resdate = $resnote = "";
961 } break;
963 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
964 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
965 echo "<table cellpadding='0' cellspacing='0'>";
966 echo "<tr>";
968 echo "<td><input type='text'" .
969 " size='$fldlength'" .
970 " class='under'" .
971 " value='$resnote' /></td>";
972 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;".xl('Status').":&nbsp;</td>";
973 echo "<td><input type='radio'";
974 if ($restype == "current".$field_id) echo " checked";
975 echo "/>".xl('Current')."&nbsp;</td>";
977 echo "<td><input type='radio'";
978 if ($restype == "current".$field_id) echo " checked";
979 echo "/>".xl('Quit')."&nbsp;</td>";
981 echo "<td><input type='text' size='6'" .
982 " value='$resdate'" .
983 " class='under'" .
984 " /></td>";
986 echo "<td><input type='radio'";
987 if ($restype == "current".$field_id) echo " checked";
988 echo " />".xl('Never')."</td>";
990 echo "<td><input type='radio'";
991 if ($restype == "not_applicable".$field_id) echo " checked";
992 echo " />".xl('N/A')."&nbsp;</td>";
993 echo "</tr>";
994 echo "</table>";
999 function generate_display_field($frow, $currvalue) {
1000 $data_type = $frow['data_type'];
1001 $field_id = $frow['field_id'];
1002 $list_id = $frow['list_id'];
1003 $s = '';
1005 // generic selection list or the generic selection list with add on the fly
1006 // feature, or radio buttons
1007 if ($data_type == 1 || $data_type == 26 || $data_type == 27) {
1008 $lrow = sqlQuery("SELECT title FROM list_options " .
1009 "WHERE list_id = '$list_id' AND option_id = '$currvalue'");
1010 $s = xl_list_label($lrow['title']);
1013 // simple text field
1014 else if ($data_type == 2) {
1015 $s = $currvalue;
1018 // long or multi-line text field
1019 else if ($data_type == 3) {
1020 $s = nl2br($currvalue);
1023 // date
1024 else if ($data_type == 4) {
1025 $s = oeFormatShortDate($currvalue);
1028 // provider
1029 else if ($data_type == 10 || $data_type == 11) {
1030 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1031 "WHERE id = '$currvalue'");
1032 $s = ucwords($urow['fname'] . " " . $urow['lname']);
1035 // pharmacy list
1036 else if ($data_type == 12) {
1037 $pres = get_pharmacies();
1038 while ($prow = sqlFetchArray($pres)) {
1039 $key = $prow['id'];
1040 if ($currvalue == $key) {
1041 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
1042 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1043 $prow['line1'] . ' / ' . $prow['city'];
1048 // squads
1049 else if ($data_type == 13) {
1050 $squads = acl_get_squads();
1051 if ($squads) {
1052 foreach ($squads as $key => $value) {
1053 if ($currvalue == $key) {
1054 $s .= $value[3];
1060 // address book
1061 else if ($data_type == 14) {
1062 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1063 "WHERE id = '$currvalue'");
1064 $uname = $urow['lname'];
1065 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1066 $s = $uname;
1069 // billing code
1070 else if ($data_type == 15) {
1071 $s = $currvalue;
1074 // a set of labeled checkboxes
1075 else if ($data_type == 21) {
1076 $avalue = explode('|', $currvalue);
1077 $lres = sqlStatement("SELECT * FROM list_options " .
1078 "WHERE list_id = '$list_id' ORDER BY seq, title");
1079 $count = 0;
1080 while ($lrow = sqlFetchArray($lres)) {
1081 $option_id = $lrow['option_id'];
1082 if (in_array($option_id, $avalue)) {
1083 if ($count++) $s .= "<br />";
1085 // Added 5-09 by BM - Translate label if applicable
1086 $s .= xl_list_label($lrow['title']);
1092 // a set of labeled text input fields
1093 else if ($data_type == 22) {
1094 $tmp = explode('|', $currvalue);
1095 $avalue = array();
1096 foreach ($tmp as $value) {
1097 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1098 $avalue[$matches[1]] = $matches[2];
1101 $lres = sqlStatement("SELECT * FROM list_options " .
1102 "WHERE list_id = '$list_id' ORDER BY seq, title");
1103 $s .= "<table cellpadding='0' cellspacing='0'>";
1104 while ($lrow = sqlFetchArray($lres)) {
1105 $option_id = $lrow['option_id'];
1106 if (empty($avalue[$option_id])) continue;
1108 // Added 5-09 by BM - Translate label if applicable
1109 $s .= "<tr><td class='bold' valign='top'>" . xl_list_label($lrow['title']) . ":&nbsp;</td>";
1111 $s .= "<td class='text' valign='top'>" . $avalue[$option_id] . "</td></tr>";
1113 $s .= "</table>";
1116 // a set of exam results; 3 radio buttons and a text field:
1117 else if ($data_type == 23) {
1118 $tmp = explode('|', $currvalue);
1119 $avalue = array();
1120 foreach ($tmp as $value) {
1121 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1122 $avalue[$matches[1]] = $matches[2];
1125 $lres = sqlStatement("SELECT * FROM list_options " .
1126 "WHERE list_id = '$list_id' ORDER BY seq, title");
1127 $s .= "<table cellpadding='0' cellspacing='0'>";
1128 while ($lrow = sqlFetchArray($lres)) {
1129 $option_id = $lrow['option_id'];
1130 $restype = substr($avalue[$option_id], 0, 1);
1131 $resnote = substr($avalue[$option_id], 2);
1132 if (empty($restype) && empty($resnote)) continue;
1134 // Added 5-09 by BM - Translate label if applicable
1135 $s .= "<tr><td class='bold' valign='top'>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
1137 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1138 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1139 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1140 $s .= "<td class='text' valign='top'>$restype&nbsp;</td>";
1141 $s .= "<td class='text' valign='top'>$resnote</td>";
1142 $s .= "</tr>";
1144 $s .= "</table>";
1147 // the list of active allergies for the current patient
1148 else if ($data_type == 24) {
1149 $query = "SELECT title, comments FROM lists WHERE " .
1150 "pid = '" . $GLOBALS['pid'] . "' AND type = 'allergy' AND enddate IS NULL " .
1151 "ORDER BY begdate";
1152 // echo "<!-- $query -->\n"; // debugging
1153 $lres = sqlStatement($query);
1154 $count = 0;
1155 while ($lrow = sqlFetchArray($lres)) {
1156 if ($count++) $s .= "<br />";
1157 $s .= $lrow['title'];
1158 if ($lrow['comments']) $s .= ' (' . $lrow['comments'] . ')';
1162 // a set of labeled checkboxes, each with a text field:
1163 else if ($data_type == 25) {
1164 $tmp = explode('|', $currvalue);
1165 $avalue = array();
1166 foreach ($tmp as $value) {
1167 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1168 $avalue[$matches[1]] = $matches[2];
1171 $lres = sqlStatement("SELECT * FROM list_options " .
1172 "WHERE list_id = '$list_id' ORDER BY seq, title");
1173 $s .= "<table cellpadding='0' cellspacing='0'>";
1174 while ($lrow = sqlFetchArray($lres)) {
1175 $option_id = $lrow['option_id'];
1176 $restype = substr($avalue[$option_id], 0, 1);
1177 $resnote = substr($avalue[$option_id], 2);
1178 if (empty($restype) && empty($resnote)) continue;
1180 // Added 5-09 by BM - Translate label if applicable
1181 $s .= "<tr><td class='bold' valign='top'>" . xl_list_label($lrow['title']) . "&nbsp;</td>";
1183 $restype = $restype ? xl('Yes') : xl('No');
1184 $s .= "<td class='text' valign='top'>$restype</td></tr>";
1185 $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1186 $s .= "</tr>";
1188 $s .= "</table>";
1191 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1192 else if ($data_type == 28) {
1193 $tmp = explode('|', $currvalue);
1194 switch(count($tmp)) {
1195 case "3": {
1196 $resnote = $tmp[0];
1197 $restype = $tmp[1];
1198 $resdate = $tmp[2];
1199 } break;
1200 case "2": {
1201 $resnote = $tmp[0];
1202 $restype = $tmp[1];
1203 $resdate = "";
1204 } break;
1205 case "1": {
1206 $resnote = $tmp[0];
1207 $resdate = $restype = "";
1208 } break;
1209 default: {
1210 $restype = $resdate = $resnote = "";
1211 } break;
1213 $s .= "<table cellpadding='0' cellspacing='0'>";
1215 $s .= "<tr>";
1216 $res = "";
1217 if ($restype == "current".$field_id) $res = xl('Current');
1218 if ($restype == "quit".$field_id) $res = xl('Quit');
1219 if ($restype == "never".$field_id) $res = xl('Never');
1220 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1221 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1222 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1223 if (!empty($resnote)) $s .= "<td class='text' valign='top'>$resnote&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1224 if (!empty($res)) $s .= "<td class='text' valign='top'><b>".xl('Status')."</b>:&nbsp;".$res."&nbsp;</td>";
1225 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>$resdate&nbsp;</td>";
1226 $s .= "</tr>";
1227 $s .= "</table>";
1230 return $s;
1233 $CPR = 4; // cells per row of generic data
1234 $last_group = '';
1235 $cell_count = 0;
1236 $item_count = 0;
1238 function disp_end_cell() {
1239 global $item_count, $cell_count;
1240 if ($item_count > 0) {
1241 echo "</td>";
1242 $item_count = 0;
1246 function disp_end_row() {
1247 global $cell_count, $CPR;
1248 disp_end_cell();
1249 if ($cell_count > 0) {
1250 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
1251 echo "</tr>\n";
1252 $cell_count = 0;
1256 function disp_end_group() {
1257 global $last_group;
1258 if (strlen($last_group) > 0) {
1259 disp_end_row();
1263 function display_layout_rows($formtype, $result1, $result2='') {
1264 global $item_count, $cell_count, $last_group, $CPR;
1266 $fres = sqlStatement("SELECT * FROM layout_options " .
1267 "WHERE form_id = '$formtype' AND uor > 0 " .
1268 "ORDER BY group_name, seq");
1270 while ($frow = sqlFetchArray($fres)) {
1271 $this_group = $frow['group_name'];
1272 $titlecols = $frow['titlecols'];
1273 $datacols = $frow['datacols'];
1274 $data_type = $frow['data_type'];
1275 $field_id = $frow['field_id'];
1276 $list_id = $frow['list_id'];
1277 $currvalue = '';
1279 if ($formtype == 'DEM') {
1280 if ($GLOBALS['athletic_team']) {
1281 // Skip fitness level and return-to-play date because those appear
1282 // in a special display/update form on this page.
1283 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1285 if (strpos($field_id, 'em_') === 0) {
1286 // Skip employer related fields, if it's disabled.
1287 if ($GLOBALS['omit_employers']) continue;
1288 $tmp = substr($field_id, 3);
1289 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1291 else {
1292 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1295 else {
1296 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1299 // Handle a data category (group) change.
1300 if (strcmp($this_group, $last_group) != 0) {
1301 $group_name = substr($this_group, 1);
1302 // totally skip generating the employer category, if it's disabled.
1303 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1304 disp_end_group();
1305 $last_group = $this_group;
1308 // Handle starting of a new row.
1309 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1310 disp_end_row();
1311 echo "<tr>";
1312 if ($group_name) {
1313 echo "<td class='groupname'>";
1314 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1315 //echo "<font color='#008800'>$group_name</font>";
1317 // Added 5-09 by BM - Translate label if applicable
1318 echo (xl_layout_label($group_name));
1320 $group_name = '';
1321 } else {
1322 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1323 echo "<td valign='top'>&nbsp;";
1325 echo "</td>";
1328 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1330 // Handle starting of a new label cell.
1331 if ($titlecols > 0) {
1332 disp_end_cell();
1333 //echo "<td class='label' colspan='$titlecols' valign='top'";
1334 echo "<td class='label' colspan='$titlecols' ";
1335 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1336 echo ">";
1337 $cell_count += $titlecols;
1339 ++$item_count;
1341 // Added 5-09 by BM - Translate label if applicable
1342 if ($frow['title']) echo (xl_layout_label($frow['title']).":"); else echo "&nbsp;";
1344 // Handle starting of a new data cell.
1345 if ($datacols > 0) {
1346 disp_end_cell();
1347 //echo "<td class='text data' colspan='$datacols' valign='top'";
1348 echo "<td class='text data' colspan='$datacols'";
1349 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1350 echo ">";
1351 $cell_count += $datacols;
1354 ++$item_count;
1355 echo generate_display_field($frow, $currvalue);
1358 disp_end_group();
1361 function display_layout_tabs($formtype, $result1, $result2='') {
1362 global $item_count, $cell_count, $last_group, $CPR;
1364 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1365 "WHERE form_id = '$formtype' AND uor > 0 " .
1366 "ORDER BY group_name, seq");
1368 $first = true;
1369 while ($frow = sqlFetchArray($fres)) {
1370 $this_group = $frow['group_name'];
1371 $group_name = substr($this_group, 1);
1373 <li <?php echo $first ? 'class="current"' : '' ?>>
1374 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo $group_name?>"><?php echo xl_layout_label($group_name); ?></a>
1375 </li>
1376 <?php
1377 $first = false;
1381 function display_layout_tabs_data($formtype, $result1, $result2='') {
1382 global $item_count, $cell_count, $last_group, $CPR;
1384 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1385 "WHERE form_id = '$formtype' AND uor > 0 " .
1386 "ORDER BY group_name, seq");
1388 $first = true;
1389 while ($frow = sqlFetchArray($fres)) {
1390 $this_group = $frow['group_name'];
1391 $titlecols = $frow['titlecols'];
1392 $datacols = $frow['datacols'];
1393 $data_type = $frow['data_type'];
1394 $field_id = $frow['field_id'];
1395 $list_id = $frow['list_id'];
1396 $currvalue = '';
1398 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1399 "WHERE form_id = '$formtype' AND uor > 0 AND group_name = '$this_group' " .
1400 "ORDER BY seq");
1403 <div class="tab <?php echo $first ? 'current' : '' ?>">
1404 <table border='0' cellpadding='0'>
1406 <?php
1407 while ($group_fields = sqlFetchArray($group_fields_query)) {
1409 $titlecols = $group_fields['titlecols'];
1410 $datacols = $group_fields['datacols'];
1411 $data_type = $group_fields['data_type'];
1412 $field_id = $group_fields['field_id'];
1413 $list_id = $group_fields['list_id'];
1414 $currvalue = '';
1416 if ($formtype == 'DEM') {
1417 if ($GLOBALS['athletic_team']) {
1418 // Skip fitness level and return-to-play date because those appear
1419 // in a special display/update form on this page.
1420 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1422 if (strpos($field_id, 'em_') === 0) {
1423 // Skip employer related fields, if it's disabled.
1424 if ($GLOBALS['omit_employers']) continue;
1425 $tmp = substr($field_id, 3);
1426 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1428 else {
1429 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1432 else {
1433 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1436 // Handle a data category (group) change.
1437 if (strcmp($this_group, $last_group) != 0) {
1438 $group_name = substr($this_group, 1);
1439 // totally skip generating the employer category, if it's disabled.
1440 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1441 $last_group = $this_group;
1444 // Handle starting of a new row.
1445 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1446 disp_end_row();
1447 echo "<tr>";
1450 if ($item_count == 0 && $titlecols == 0) {
1451 $titlecols = 1;
1454 // Handle starting of a new label cell.
1455 if ($titlecols > 0) {
1456 disp_end_cell();
1457 echo "<td class='label' colspan='$titlecols' ";
1458 echo ">";
1459 $cell_count += $titlecols;
1461 ++$item_count;
1463 // Added 5-09 by BM - Translate label if applicable
1464 if ($group_fields['title']) echo (xl_layout_label($group_fields['title']).":"); else echo "&nbsp;";
1466 // Handle starting of a new data cell.
1467 if ($datacols > 0) {
1468 disp_end_cell();
1469 echo "<td class='text data' colspan='$datacols'";
1470 echo ">";
1471 $cell_count += $datacols;
1474 ++$item_count;
1475 echo generate_display_field($group_fields, $currvalue);
1479 </table>
1480 </div>
1482 <?php
1484 $first = false;
1490 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1491 global $item_count, $cell_count, $last_group, $CPR;
1493 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1494 "WHERE form_id = '$formtype' AND uor > 0 " .
1495 "ORDER BY group_name, seq");
1497 $first = true;
1498 while ($frow = sqlFetchArray($fres)) {
1499 $this_group = $frow['group_name'];
1500 $group_name = substr($this_group, 1);
1501 $titlecols = $frow['titlecols'];
1502 $datacols = $frow['datacols'];
1503 $data_type = $frow['data_type'];
1504 $field_id = $frow['field_id'];
1505 $list_id = $frow['list_id'];
1506 $currvalue = '';
1508 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1509 "WHERE form_id = '$formtype' AND uor > 0 AND group_name = '$this_group' " .
1510 "ORDER BY seq");
1513 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name?>" >
1514 <table border='0' cellpadding='0'>
1516 <?php
1517 while ($group_fields = sqlFetchArray($group_fields_query)) {
1519 $titlecols = $group_fields['titlecols'];
1520 $datacols = $group_fields['datacols'];
1521 $data_type = $group_fields['data_type'];
1522 $field_id = $group_fields['field_id'];
1523 $list_id = $group_fields['list_id'];
1524 $currvalue = '';
1526 if ($formtype == 'DEM') {
1527 if ($GLOBALS['athletic_team']) {
1528 // Skip fitness level and return-to-play date because those appear
1529 // in a special display/update form on this page.
1530 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1532 if (strpos($field_id, 'em_') === 0) {
1533 // Skip employer related fields, if it's disabled.
1534 if ($GLOBALS['omit_employers']) continue;
1535 $tmp = substr($field_id, 3);
1536 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1538 else {
1539 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1542 else {
1543 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1546 // Handle a data category (group) change.
1547 if (strcmp($this_group, $last_group) != 0) {
1548 $group_name = substr($this_group, 1);
1549 // totally skip generating the employer category, if it's disabled.
1550 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1551 $last_group = $this_group;
1554 // Handle starting of a new row.
1555 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1556 disp_end_row();
1557 echo "<tr>";
1560 if ($item_count == 0 && $titlecols == 0) {
1561 $titlecols = 1;
1564 // Handle starting of a new label cell.
1565 if ($titlecols > 0) {
1566 disp_end_cell();
1567 echo "<td class='label' colspan='$titlecols' ";
1568 echo ">";
1569 $cell_count += $titlecols;
1571 ++$item_count;
1573 // Added 5-09 by BM - Translate label if applicable
1574 if ($group_fields['title']) echo (xl_layout_label($group_fields['title']).":"); else echo "&nbsp;";
1576 // Handle starting of a new data cell.
1577 if ($datacols > 0) {
1578 disp_end_cell();
1579 echo "<td class='text data' colspan='$datacols'";
1580 echo ">";
1581 $cell_count += $datacols;
1584 ++$item_count;
1585 echo generate_form_field($group_fields, $currvalue);
1589 </table>
1590 </div>
1592 <?php
1594 $first = false;
1599 // From the currently posted HTML form, this gets the value of the
1600 // field corresponding to the provided layout_options table row.
1602 function get_layout_form_value($frow, $maxlength=255) {
1603 $data_type = $frow['data_type'];
1604 $field_id = $frow['field_id'];
1605 $value = '';
1606 if (isset($_POST["form_$field_id"])) {
1607 if ($data_type == 21) {
1608 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1609 // must be concatenated into a |-separated string.
1610 foreach ($_POST["form_$field_id"] as $key => $val) {
1611 if (strlen($value)) $value .= '|';
1612 $value .= $key;
1615 else if ($data_type == 22) {
1616 // $_POST["form_$field_id"] is an array of text fields to be imploded
1617 // into "key:value|key:value|...".
1618 foreach ($_POST["form_$field_id"] as $key => $val) {
1619 $val = str_replace('|', ' ', $val);
1620 if (strlen($value)) $value .= '|';
1621 $value .= "$key:$val";
1624 else if ($data_type == 23) {
1625 // $_POST["form_$field_id"] is an array of text fields with companion
1626 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1627 foreach ($_POST["form_$field_id"] as $key => $val) {
1628 $restype = $_POST["radio_{$field_id}"][$key];
1629 if (empty($restype)) $restype = '0';
1630 $val = str_replace('|', ' ', $val);
1631 if (strlen($value)) $value .= '|';
1632 $value .= "$key:$restype:$val";
1635 else if ($data_type == 25) {
1636 // $_POST["form_$field_id"] is an array of text fields with companion
1637 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1638 foreach ($_POST["form_$field_id"] as $key => $val) {
1639 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
1640 $val = str_replace('|', ' ', $val);
1641 if (strlen($value)) $value .= '|';
1642 $value .= "$key:$restype:$val";
1645 else if ($data_type == 28) {
1646 // $_POST["form_$field_id"] is an date text fields with companion
1647 // radio buttons to be imploded into "notes|type|date".
1648 $restype = $_POST["radio_{$field_id}"];
1649 if (empty($restype)) $restype = '0';
1650 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1651 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1652 $value = "$resnote|$restype|$resdate";
1654 else {
1655 $value = $_POST["form_$field_id"];
1659 // Better to die than to silently truncate data!
1660 if ($maxlength && $data_type != 3 && strlen($value) > $maxlength)
1661 die(xl('ERROR: Field') . " '$field_id' " . xl('is too long') .
1662 ":<br />&nbsp;<br />$value");
1664 // Make sure the return value is quote-safe.
1665 return formTrim($value);
1668 // Generate JavaScript validation logic for the required fields.
1670 function generate_layout_validation($form_id) {
1671 $fres = sqlStatement("SELECT * FROM layout_options " .
1672 "WHERE form_id = '$form_id' AND uor > 0 AND field_id != '' " .
1673 "ORDER BY group_name, seq");
1675 while ($frow = sqlFetchArray($fres)) {
1676 if ($frow['uor'] < 2) continue;
1677 $data_type = $frow['data_type'];
1678 $field_id = $frow['field_id'];
1679 $fldtitle = $frow['title'];
1680 if (!$fldtitle) $fldtitle = $frow['description'];
1681 $fldname = "form_$field_id";
1682 switch($data_type) {
1683 case 1:
1684 case 11:
1685 case 12:
1686 case 13:
1687 case 14:
1688 case 26:
1689 echo
1690 " if (f.$fldname.selectedIndex <= 0) {\n" .
1691 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1692 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
1693 " }\n";
1694 break;
1695 case 27: // radio buttons
1696 echo
1697 " var i = 0;\n" .
1698 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
1699 " if (i >= f.$fldname.length) {\n" .
1700 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
1701 " }\n";
1702 break;
1703 case 2:
1704 case 3:
1705 case 4:
1706 case 15:
1707 echo
1708 " if (trimlen(f.$fldname.value) == 0) {\n" .
1709 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1710 " $('#form_" . $field_id . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
1711 " $('#form_" . $field_id . "').attr('style','background:red'); \n" .
1712 " errMsgs[errMsgs.length] = '" . addslashes(xl_layout_label($fldtitle)) . "'; \n" .
1713 " } else { " .
1714 " $('#form_" . $field_id . "').attr('style',''); " .
1715 " $('#form_" . $field_id . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
1716 " } \n";
1717 break;