Minor translation bug fix
[openemr.git] / library / options.inc.php
blob1af811014d4116bf8fe7800910a08d4e5b4a5f8d
1 <?php
2 // Copyright (C) 2007-2010 Rod Roark <rod@sunsetsystems.com>
3 // Copyright © 2010 by Andrew Moore <amoore@cpan.org>
4 // Copyright © 2010 by "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // Functions for managing the lists and layouts
13 // Note: there are translation wrappers for the lists and layout labels
14 // at library/translation.inc.php. The functions are titled
15 // xl_list_label() and xl_layout_label() and are controlled by the
16 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
17 // flags in globals.php
19 // Documentation for layout_options.edit_options:
21 // C = Capitalize first letter of each word (text fields)
22 // D = Check for duplicates in New Patient form
23 // G = Graphable (for numeric fields in forms supporting historical data)
24 // H = Read-only field copied from static history
25 // L = Lab Order ("ord_lab") types only (address book)
26 // N = Show in New Patient form
27 // O = Procedure Order ("ord_*") types only (address book)
28 // R = Distributor types only (address book)
29 // U = Capitalize all letters (text fields)
30 // V = Vendor types only (address book)
31 // 1 = Write Once (not editable when not empty) (text fields)
33 require_once("formdata.inc.php");
34 require_once("formatting.inc.php");
35 require_once("user.inc");
37 $date_init = "";
39 function get_pharmacies() {
40 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
41 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
42 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
43 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
44 "AND p.type = 2 " .
45 "ORDER BY name, area_code, prefix, number");
48 // Function to generate a drop-list.
50 function generate_select_list($tag_name, $list_id, $currvalue, $title,
51 $empty_name=' ', $class='', $onchange='')
53 $s = '';
54 $tag_name_esc = htmlspecialchars( $tag_name, ENT_QUOTES);
55 $s .= "<select name='$tag_name_esc' id='$tag_name_esc'";
56 if ($class) $s .= " class='$class'";
57 if ($onchange) $s .= " onchange='$onchange'";
58 $selectTitle = htmlspecialchars( $title, ENT_QUOTES);
59 $s .= " title='$selectTitle'>";
60 $selectEmptyName = htmlspecialchars( xl($empty_name), ENT_NOQUOTES);
61 if ($empty_name) $s .= "<option value=''>" . $selectEmptyName . "</option>";
62 $lres = sqlStatement("SELECT * FROM list_options " .
63 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
64 $got_selected = FALSE;
65 while ($lrow = sqlFetchArray($lres)) {
66 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
67 $s .= "<option value='$optionValue'";
68 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
69 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
71 $s .= " selected";
72 $got_selected = TRUE;
74 $optionLabel = htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
75 $s .= ">$optionLabel</option>\n";
77 if (!$got_selected && strlen($currvalue) > 0) {
78 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
79 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
80 $s .= "</select>";
81 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_QUOTES);
82 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
83 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
85 else {
86 $s .= "</select>";
88 return $s;
91 // $frow is a row from the layout_options table.
92 // $currvalue is the current value, if any, of the associated item.
94 function generate_form_field($frow, $currvalue) {
95 global $rootdir, $date_init;
97 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
99 $data_type = $frow['data_type'];
100 $field_id = $frow['field_id'];
101 $list_id = $frow['list_id'];
102 // escaped variables to use in html
103 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
104 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
106 // Added 5-09 by BM - Translate description if applicable
107 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
109 // added 5-2009 by BM to allow modification of the 'empty' text title field.
110 // Can pass $frow['empty_title'] with this variable, otherwise
111 // will default to 'Unassigned'.
112 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
113 // if make $frow['empty_title'] equal to 'SKIP'
114 $showEmpty = true;
115 if (isset($frow['empty_title'])) {
116 if ($frow['empty_title'] == "SKIP") {
117 //do not display an 'empty' choice
118 $showEmpty = false;
119 $empty_title = "Unassigned";
121 else {
122 $empty_title = $frow['empty_title'];
125 else {
126 $empty_title = "Unassigned";
129 // generic single-selection list
130 if ($data_type == 1) {
131 echo generate_select_list("form_$field_id", $list_id, $currvalue,
132 $description, $showEmpty ? $empty_title : '');
135 // simple text field
136 else if ($data_type == 2) {
137 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
138 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
139 echo "<input type='text'" .
140 " name='form_$field_id_esc'" .
141 " id='form_$field_id_esc'" .
142 " size='$fldlength'" .
143 " maxlength='$maxlength'" .
144 " title='$description'" .
145 " value='$currescaped'";
146 if (strpos($frow['edit_options'], 'C') !== FALSE)
147 echo " onchange='capitalizeMe(this)'";
148 else if (strpos($frow['edit_options'], 'U') !== FALSE)
149 echo " onchange='this.value = this.value.toUpperCase()'";
150 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
151 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
152 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
153 echo " onblur='maskblur(this,\"$tmp\")'";
155 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0)
156 echo " readonly";
157 echo " />";
160 // long or multi-line text field
161 else if ($data_type == 3) {
162 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
163 $textRows = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
164 echo "<textarea" .
165 " name='form_$field_id_esc'" .
166 " id='form_$field_id_esc'" .
167 " title='$description'" .
168 " cols='$textCols'" .
169 " rows='$textRows'>" .
170 $currescaped . "</textarea>";
173 // date
174 else if ($data_type == 4) {
175 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
176 " value='$currescaped'" .
177 " title='$description'" .
178 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
179 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
180 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
181 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
182 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
185 // provider list, local providers only
186 else if ($data_type == 10) {
187 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
188 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
189 "AND authorized = 1 " .
190 "ORDER BY lname, fname");
191 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
192 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
193 while ($urow = sqlFetchArray($ures)) {
194 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
195 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
196 echo "<option value='$optionId'";
197 if ($urow['id'] == $currvalue) echo " selected";
198 echo ">$uname</option>";
200 echo "</select>";
203 // provider list, including address book entries with an NPI number
204 else if ($data_type == 11) {
205 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
206 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
207 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
208 "ORDER BY lname, fname");
209 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
210 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
211 while ($urow = sqlFetchArray($ures)) {
212 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
213 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
214 echo "<option value='$optionId'";
215 if ($urow['id'] == $currvalue) echo " selected";
216 echo ">$uname</option>";
218 echo "</select>";
221 // pharmacy list
222 else if ($data_type == 12) {
223 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
224 echo "<option value='0'></option>";
225 $pres = get_pharmacies();
226 while ($prow = sqlFetchArray($pres)) {
227 $key = $prow['id'];
228 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
229 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
230 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
231 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
232 echo "<option value='$optionValue'";
233 if ($currvalue == $key) echo " selected";
234 echo ">$optionLabel</option>";
236 echo "</select>";
239 // squads
240 else if ($data_type == 13) {
241 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
242 echo "<option value=''>&nbsp;</option>";
243 $squads = acl_get_squads();
244 if ($squads) {
245 foreach ($squads as $key => $value) {
246 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
247 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
248 echo "<option value='$optionValue'";
249 if ($currvalue == $key) echo " selected";
250 echo ">$optionLabel</option>\n";
253 echo "</select>";
256 // Address book, preferring organization name if it exists and is not in
257 // parentheses, and excluding local users who are not providers.
258 // Supports "referred to" practitioners and facilities.
259 // Alternatively the letter L in edit_options means that abook_type
260 // must be "ord_lab", indicating types used with the procedure
261 // lab ordering system.
262 // Alternatively the letter O in edit_options means that abook_type
263 // must begin with "ord_", indicating types used with the procedure
264 // ordering system.
265 // Alternatively the letter V in edit_options means that abook_type
266 // must be "vendor", indicating the Vendor type.
267 // Alternatively the letter R in edit_options means that abook_type
268 // must be "dist", indicating the Distributor type.
269 else if ($data_type == 14) {
270 if (strpos($frow['edit_options'], 'L') !== FALSE)
271 $tmp = "abook_type = 'ord_lab'";
272 else if (strpos($frow['edit_options'], 'O') !== FALSE)
273 $tmp = "abook_type LIKE 'ord\\_%'";
274 else if (strpos($frow['edit_options'], 'V') !== FALSE)
275 $tmp = "abook_type LIKE 'vendor%'";
276 else if (strpos($frow['edit_options'], 'R') !== FALSE)
277 $tmp = "abook_type LIKE 'dist'";
278 else
279 $tmp = "( username = '' OR authorized = 1 )";
280 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
281 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
282 "AND $tmp " .
283 "ORDER BY organization, lname, fname");
284 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
285 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
286 while ($urow = sqlFetchArray($ures)) {
287 $uname = $urow['organization'];
288 if (empty($uname) || substr($uname, 0, 1) == '(') {
289 $uname = $urow['lname'];
290 if ($urow['fname']) $uname .= ", " . $urow['fname'];
292 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
293 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
294 echo "<option value='$optionValue'";
295 $title = $urow['username'] ? xl('Local') : xl('External');
296 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
297 echo " title='$optionTitle'";
298 if ($urow['id'] == $currvalue) echo " selected";
299 echo ">$optionLabel</option>";
301 echo "</select>";
304 // a billing code
305 else if ($data_type == 15) {
306 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
307 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
308 echo "<input type='text'" .
309 " name='form_$field_id_esc'" .
310 " id='form_related_code'" .
311 " size='$fldlength'" .
312 " maxlength='$maxlength'" .
313 " title='$description'" .
314 " value='$currescaped'" .
315 " onclick='sel_related(this)' readonly" .
316 " />";
319 // a set of labeled checkboxes
320 else if ($data_type == 21) {
321 // In this special case, fld_length is the number of columns generated.
322 $cols = max(1, $frow['fld_length']);
323 $avalue = explode('|', $currvalue);
324 $lres = sqlStatement("SELECT * FROM list_options " .
325 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
326 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
327 $tdpct = (int) (100 / $cols);
328 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
329 $option_id = $lrow['option_id'];
330 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
331 // if ($count) echo "<br />";
332 if ($count % $cols == 0) {
333 if ($count) echo "</tr>";
334 echo "<tr>";
336 echo "<td width='$tdpct%'>";
337 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]' id='form_{$field_id_esc}[$option_id_esc]' value='1'";
338 if (in_array($option_id, $avalue)) echo " checked";
340 // Added 5-09 by BM - Translate label if applicable
341 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
343 echo "</td>";
345 if ($count) {
346 echo "</tr>";
347 if ($count > $cols) {
348 // Add some space after multiple rows of checkboxes.
349 $cols = htmlspecialchars( $cols, ENT_QUOTES);
350 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
353 echo "</table>";
356 // a set of labeled text input fields
357 else if ($data_type == 22) {
358 $tmp = explode('|', $currvalue);
359 $avalue = array();
360 foreach ($tmp as $value) {
361 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
362 $avalue[$matches[1]] = $matches[2];
365 $lres = sqlStatement("SELECT * FROM list_options " .
366 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
367 echo "<table cellpadding='0' cellspacing='0'>";
368 while ($lrow = sqlFetchArray($lres)) {
369 $option_id = $lrow['option_id'];
370 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
371 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
372 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
374 // Added 5-09 by BM - Translate label if applicable
375 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
376 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
377 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
378 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
379 echo "<td><input type='text'" .
380 " name='form_{$field_id_esc}[$option_id_esc]'" .
381 " id='form_{$field_id_esc}[$option_id_esc]'" .
382 " size='$fldlength'" .
383 " maxlength='$maxlength'" .
384 " value='$optionValue'";
385 echo " /></td></tr>";
387 echo "</table>";
390 // a set of exam results; 3 radio buttons and a text field:
391 else if ($data_type == 23) {
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 = ? ORDER BY seq, title", array($list_id) );
403 echo "<table cellpadding='0' cellspacing='0'>";
404 echo "<tr><td>&nbsp;</td><td class='bold'>" .
405 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
406 "&nbsp;</td><td class='bold'>" .
407 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
408 "<td class='bold'>" .
409 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
410 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
411 while ($lrow = sqlFetchArray($lres)) {
412 $option_id = $lrow['option_id'];
413 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
414 $restype = substr($avalue[$option_id], 0, 1);
415 $resnote = substr($avalue[$option_id], 2);
417 // Added 5-09 by BM - Translate label if applicable
418 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
420 for ($i = 0; $i < 3; ++$i) {
421 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
422 echo "<td><input type='radio'" .
423 " name='radio_{$field_id_esc}[$option_id_esc]'" .
424 " id='radio_{$field_id_esc}[$option_id_esc]'" .
425 " value='$inputValue'";
426 if ($restype === "$i") echo " checked";
427 echo " /></td>";
429 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
430 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
431 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
432 echo "<td><input type='text'" .
433 " name='form_{$field_id_esc}[$option_id_esc]'" .
434 " id='form_{$field_id_esc}[$option_id_esc]'" .
435 " size='$fldlength'" .
436 " maxlength='$maxlength'" .
437 " value='$resnote' /></td>";
438 echo "</tr>";
440 echo "</table>";
443 // the list of active allergies for the current patient
444 // this is read-only!
445 else if ($data_type == 24) {
446 $query = "SELECT title, comments FROM lists WHERE " .
447 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
448 "ORDER BY begdate";
449 // echo "<!-- $query -->\n"; // debugging
450 $lres = sqlStatement($query, array($GLOBALS['pid']));
451 $count = 0;
452 while ($lrow = sqlFetchArray($lres)) {
453 if ($count++) echo "<br />";
454 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
455 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
459 // a set of labeled checkboxes, each with a text field:
460 else if ($data_type == 25) {
461 $tmp = explode('|', $currvalue);
462 $avalue = array();
463 foreach ($tmp as $value) {
464 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
465 $avalue[$matches[1]] = $matches[2];
468 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
469 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
470 $lres = sqlStatement("SELECT * FROM list_options " .
471 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
472 echo "<table cellpadding='0' cellspacing='0'>";
473 while ($lrow = sqlFetchArray($lres)) {
474 $option_id = $lrow['option_id'];
475 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
476 $restype = substr($avalue[$option_id], 0, 1);
477 $resnote = substr($avalue[$option_id], 2);
479 // Added 5-09 by BM - Translate label if applicable
480 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
482 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
483 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]' id='check_{$field_id_esc}[$option_id_esc]' value='1'";
484 if ($restype) echo " checked";
485 echo " />&nbsp;</td>";
486 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
487 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
488 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
489 echo "<td><input type='text'" .
490 " name='form_{$field_id_esc}[$option_id_esc]'" .
491 " id='form_{$field_id_esc}[$option_id_esc]'" .
492 " size='$fldlength'" .
493 " maxlength='$maxlength'" .
494 " value='$resnote' /></td>";
495 echo "</tr>";
497 echo "</table>";
500 // single-selection list with ability to add to it
501 else if ($data_type == 26) {
502 echo "<select class='addtolistclass_$list_id_esc' name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
503 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES) . "</option>";
504 $lres = sqlStatement("SELECT * FROM list_options " .
505 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
506 $got_selected = FALSE;
507 while ($lrow = sqlFetchArray($lres)) {
508 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
509 echo "<option value='$optionValue'";
510 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
511 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
513 echo " selected";
514 $got_selected = TRUE;
516 // Added 5-09 by BM - Translate label if applicable
517 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n";
519 if (!$got_selected && strlen($currvalue) > 0) {
520 echo "<option value='$currescaped' selected>* $currescaped *</option>";
521 echo "</select>";
522 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES);
523 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
524 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
526 else {
527 echo "</select>";
529 // show the add button if user has access to correct list
530 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
531 $outputAddButton = "<input type='button' id='addtolistid_".$list_id_esc."' fieldid='form_".$field_id_esc."' class='addtolist' value='$inputValue'>";
532 if (aco_exist('lists', $list_id)) {
533 // a specific aco exist for this list, so ensure access
534 if (acl_check('lists', $list_id)) echo $outputAddButton;
536 else {
537 // no specific aco exist for this list, so check for access to 'default' list
538 if (acl_check('lists', 'default')) echo $outputAddButton;
542 // a set of labeled radio buttons
543 else if ($data_type == 27) {
544 // In this special case, fld_length is the number of columns generated.
545 $cols = max(1, $frow['fld_length']);
546 $lres = sqlStatement("SELECT * FROM list_options " .
547 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
548 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
549 $tdpct = (int) (100 / $cols);
550 $got_selected = FALSE;
551 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
552 $option_id = $lrow['option_id'];
553 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
554 if ($count % $cols == 0) {
555 if ($count) echo "</tr>";
556 echo "<tr>";
558 echo "<td width='$tdpct%'>";
559 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]' value='$option_id_esc'";
560 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
561 (strlen($currvalue) > 0 && $option_id == $currvalue))
563 echo " checked";
564 $got_selected = TRUE;
566 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
567 echo "</td>";
569 if ($count) {
570 echo "</tr>";
571 if ($count > $cols) {
572 // Add some space after multiple rows of radio buttons.
573 $cols = htmlspecialchars( $cols, ENT_QUOTES);
574 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
577 echo "</table>";
578 if (!$got_selected && strlen($currvalue) > 0) {
579 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
580 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
581 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
585 // special case for history of lifestyle status; 3 radio buttons and a date text field:
586 // VicarePlus :: A selection list box for smoking status:
587 else if ($data_type == 28 || $data_type == 32) {
588 $tmp = explode('|', $currvalue);
589 switch(count($tmp)) {
590 case "4": {
591 $resnote = $tmp[0];
592 $restype = $tmp[1];
593 $resdate = $tmp[2];
594 $reslist = $tmp[3];
595 } break;
596 case "3": {
597 $resnote = $tmp[0];
598 $restype = $tmp[1];
599 $resdate = $tmp[2];
600 } break;
601 case "2": {
602 $resnote = $tmp[0];
603 $restype = $tmp[1];
604 $resdate = "";
605 } break;
606 case "1": {
607 $resnote = $tmp[0];
608 $resdate = $restype = "";
609 } break;
610 default: {
611 $restype = $resdate = $resnote = "";
612 } break;
614 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
615 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
617 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
618 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
619 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
620 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
621 echo "<table cellpadding='0' cellspacing='0'>";
622 echo "<tr>";
623 if ($data_type == 28)
625 // input text
626 echo "<td><input type='text'" .
627 " name='form_$field_id_esc'" .
628 " id='form_$field_id_esc'" .
629 " size='$fldlength'" .
630 " maxlength='$maxlength'" .
631 " value='$resnote' />&nbsp;</td>";
632 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
633 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
634 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
636 else if($data_type == 32)
638 // input text
639 echo "<tr><td><input type='text'" .
640 " name='form_text_$field_id_esc'" .
641 " id='form_text_$field_id_esc'" .
642 " size='$fldlength'" .
643 " maxlength='$maxlength'" .
644 " value='$resnote' />&nbsp;</td></tr>";
645 echo "<td>";
646 //Selection list for smoking status
647 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
648 echo generate_select_list("form_$field_id", $list_id, $reslist,
649 $description, $showEmpty ? $empty_title : '', '', $onchange)."</td>";
650 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
652 // current
653 echo "<td><input type='radio'" .
654 " name='radio_{$field_id_esc}'" .
655 " id='radio_{$field_id_esc}[current]'" .
656 " value='current".$field_id_esc."'";
657 if ($restype == "current".$field_id) echo " checked";
658 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
659 // quit
660 echo "<td><input type='radio'" .
661 " name='radio_{$field_id_esc}'" .
662 " id='radio_{$field_id_esc}[quit]'" .
663 " value='quit".$field_id_esc."'";
664 if ($restype == "quit".$field_id) echo " checked";
665 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
666 // quit date
667 echo "<td><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
668 " value='$resdate'" .
669 " title='$description'" .
670 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
671 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
672 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
673 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />&nbsp;</td>";
674 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
675 // never
676 echo "<td><input type='radio'" .
677 " name='radio_{$field_id_esc}'" .
678 " id='radio_{$field_id_esc}[never]'" .
679 " value='never".$field_id_esc."'";
680 if ($restype == "never".$field_id) echo " checked";
681 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."&nbsp;</td>";
682 // Not Applicable
683 echo "<td><input type='radio'" .
684 " name='radio_{$field_id}'" .
685 " id='radio_{$field_id}[not_applicable]'" .
686 " value='not_applicable".$field_id."'";
687 if ($restype == "not_applicable".$field_id) echo " checked";
688 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('N/A'), ENT_QUOTES)."&nbsp;</td>";
689 echo "</tr>";
690 echo "</table>";
693 // static text. read-only, of course.
694 else if ($data_type == 31) {
695 echo nl2br($frow['description']);
698 //VicarePlus :: A single selection list for Race and Ethnicity, which is specialized to check the 'ethrace' list if the entry does not exist in the list_id of the given list. At some point in the future (when able to input two lists via the layouts engine), this function could be expanded to allow using any list as a backup entry.
699 else if ($data_type == 33) {
700 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
701 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES) . "</option>";
702 $lres = sqlStatement("SELECT * FROM list_options " .
703 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
704 $got_selected = FALSE;
705 while ($lrow = sqlFetchArray($lres)) {
706 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
707 echo "<option value='$optionValue'";
708 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
709 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
711 echo " selected";
712 $got_selected = TRUE;
715 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n";
717 if (!$got_selected && strlen($currvalue) > 0)
719 //Check 'ethrace' list if the entry does not exist in the list_id of the given list(Race or Ethnicity).
720 $list_id='ethrace';
721 $lrow = sqlQuery("SELECT title FROM list_options " .
722 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
723 if ($lrow > 0)
725 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
726 echo "<option value='$currvalue' selected> $s </option>";
727 echo "</select>";
729 else
731 echo "<option value='$currescaped' selected>* $currescaped *</option>";
732 echo "</select>";
733 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES);
734 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
735 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
738 else {
739 echo "</select>";
744 function generate_print_field($frow, $currvalue) {
745 global $rootdir, $date_init;
747 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
749 $data_type = $frow['data_type'];
750 $field_id = $frow['field_id'];
751 $list_id = $frow['list_id'];
752 $fld_length = $frow['fld_length'];
754 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
756 // Can pass $frow['empty_title'] with this variable, otherwise
757 // will default to 'Unassigned'.
758 // If it is 'SKIP' then an empty text title is completely skipped.
759 $showEmpty = true;
760 if (isset($frow['empty_title'])) {
761 if ($frow['empty_title'] == "SKIP") {
762 //do not display an 'empty' choice
763 $showEmpty = false;
764 $empty_title = "Unassigned";
766 else {
767 $empty_title = $frow['empty_title'];
770 else {
771 $empty_title = "Unassigned";
774 // generic single-selection list
775 if ($data_type == 1 || $data_type == 26 || $data_type == 33) {
776 if (empty($fld_length)) {
777 if ($list_id == 'titles') {
778 $fld_length = 3;
779 } else {
780 $fld_length = 10;
783 $tmp = '';
784 if ($currvalue) {
785 $lrow = sqlQuery("SELECT title FROM list_options " .
786 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
787 $tmp = xl_list_label($lrow['title']);
788 if (empty($tmp)) $tmp = "($currvalue)";
790 /*****************************************************************
791 echo "<input type='text'" .
792 " size='$fld_length'" .
793 " value='$tmp'" .
794 " class='under'" .
795 " />";
796 *****************************************************************/
797 if ($tmp === '') { $tmp = '&nbsp;'; }
798 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
799 echo $tmp;
802 // simple text field
803 else if ($data_type == 2 || $data_type == 15) {
804 /*****************************************************************
805 echo "<input type='text'" .
806 " size='$fld_length'" .
807 " value='$currescaped'" .
808 " class='under'" .
809 " />";
810 *****************************************************************/
811 if ($currescaped === '') $currescaped = '&nbsp;';
812 echo $currescaped;
815 // long or multi-line text field
816 else if ($data_type == 3) {
817 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
818 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
819 echo "<textarea" .
820 " cols='$fldlength'" .
821 " rows='$maxlength'>" .
822 $currescaped . "</textarea>";
825 // date
826 else if ($data_type == 4) {
827 /*****************************************************************
828 echo "<input type='text' size='10'" .
829 " value='$currescaped'" .
830 " title='$description'" .
831 " class='under'" .
832 " />";
833 *****************************************************************/
834 if ($currvalue === '') { $tmp = oeFormatShortDate('&nbsp;'); }
835 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES); }
836 echo $tmp;
839 // provider list
840 else if ($data_type == 10 || $data_type == 11) {
841 $tmp = '';
842 if ($currvalue) {
843 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
844 "WHERE id = ?", array($currvalue) );
845 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
846 if (empty($tmp)) $tmp = "($currvalue)";
848 /*****************************************************************
849 echo "<input type='text'" .
850 " size='$fld_length'" .
851 " value='$tmp'" .
852 " class='under'" .
853 " />";
854 *****************************************************************/
855 if ($tmp === '') { $tmp = '&nbsp;'; }
856 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
857 echo $tmp;
860 // pharmacy list
861 else if ($data_type == 12) {
862 $tmp = '';
863 if ($currvalue) {
864 $pres = get_pharmacies();
865 while ($prow = sqlFetchArray($pres)) {
866 $key = $prow['id'];
867 if ($currvalue == $key) {
868 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
869 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
870 $prow['line1'] . ' / ' . $prow['city'];
873 if (empty($tmp)) $tmp = "($currvalue)";
875 /*****************************************************************
876 echo "<input type='text'" .
877 " size='$fld_length'" .
878 " value='$tmp'" .
879 " class='under'" .
880 " />";
881 *****************************************************************/
882 if ($tmp === '') { $tmp = '&nbsp;'; }
883 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
884 echo $tmp;
887 // squads
888 else if ($data_type == 13) {
889 $tmp = '';
890 if ($currvalue) {
891 $squads = acl_get_squads();
892 if ($squads) {
893 foreach ($squads as $key => $value) {
894 if ($currvalue == $key) {
895 $tmp = $value[3];
899 if (empty($tmp)) $tmp = "($currvalue)";
901 /*****************************************************************
902 echo "<input type='text'" .
903 " size='$fld_length'" .
904 " value='$tmp'" .
905 " class='under'" .
906 " />";
907 *****************************************************************/
908 if ($tmp === '') { $tmp = '&nbsp;'; }
909 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
910 echo $tmp;
913 // Address book.
914 else if ($data_type == 14) {
915 $tmp = '';
916 if ($currvalue) {
917 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
918 "WHERE id = ?", array($currvalue) );
919 $uname = $urow['lname'];
920 if ($urow['fname']) $uname .= ", " . $urow['fname'];
921 $tmp = $uname;
922 if (empty($tmp)) $tmp = "($currvalue)";
924 /*****************************************************************
925 echo "<input type='text'" .
926 " size='$fld_length'" .
927 " value='$tmp'" .
928 " class='under'" .
929 " />";
930 *****************************************************************/
931 if ($tmp === '') { $tmp = '&nbsp;'; }
932 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
933 echo $tmp;
936 // a set of labeled checkboxes
937 else if ($data_type == 21) {
938 // In this special case, fld_length is the number of columns generated.
939 $cols = max(1, $fld_length);
940 $avalue = explode('|', $currvalue);
941 $lres = sqlStatement("SELECT * FROM list_options " .
942 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
943 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
944 $tdpct = (int) (100 / $cols);
945 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
946 $option_id = $lrow['option_id'];
947 if ($count % $cols == 0) {
948 if ($count) echo "</tr>";
949 echo "<tr>";
951 echo "<td width='$tdpct%'>";
952 echo "<input type='checkbox'";
953 if (in_array($option_id, $avalue)) echo " checked";
954 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
955 echo "</td>";
957 if ($count) {
958 echo "</tr>";
959 if ($count > $cols) {
960 // Add some space after multiple rows of checkboxes.
961 $cols = htmlspecialchars( $cols, ENT_QUOTES);
962 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
965 echo "</table>";
968 // a set of labeled text input fields
969 else if ($data_type == 22) {
970 $tmp = explode('|', $currvalue);
971 $avalue = array();
972 foreach ($tmp as $value) {
973 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
974 $avalue[$matches[1]] = $matches[2];
977 $lres = sqlStatement("SELECT * FROM list_options " .
978 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
979 echo "<table cellpadding='0' cellspacing='0'>";
980 while ($lrow = sqlFetchArray($lres)) {
981 $option_id = $lrow['option_id'];
982 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
983 $fldlength = empty($fld_length) ? 20 : $fld_length;
984 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
985 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
986 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
987 echo "<td><input type='text'" .
988 " size='$fldlength'" .
989 " value='$inputValue'" .
990 " class='under'" .
991 " /></td></tr>";
993 echo "</table>";
996 // a set of exam results; 3 radio buttons and a text field:
997 else if ($data_type == 23) {
998 $tmp = explode('|', $currvalue);
999 $avalue = array();
1000 foreach ($tmp as $value) {
1001 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1002 $avalue[$matches[1]] = $matches[2];
1005 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1006 $fldlength = empty($fld_length) ? 20 : $fld_length;
1007 $lres = sqlStatement("SELECT * FROM list_options " .
1008 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1009 echo "<table cellpadding='0' cellspacing='0'>";
1010 echo "<tr><td>&nbsp;</td><td class='bold'>" .
1011 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
1012 "&nbsp;</td><td class='bold'>" .
1013 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
1014 "<td class='bold'>" .
1015 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
1016 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
1017 while ($lrow = sqlFetchArray($lres)) {
1018 $option_id = $lrow['option_id'];
1019 $restype = substr($avalue[$option_id], 0, 1);
1020 $resnote = substr($avalue[$option_id], 2);
1021 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1022 for ($i = 0; $i < 3; ++$i) {
1023 echo "<td><input type='radio'";
1024 if ($restype === "$i") echo " checked";
1025 echo " /></td>";
1027 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1028 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1029 echo "<td><input type='text'" .
1030 " size='$fldlength'" .
1031 " value='$resnote'" .
1032 " class='under' /></td>" .
1033 "</tr>";
1035 echo "</table>";
1038 // the list of active allergies for the current patient
1039 // this is read-only!
1040 else if ($data_type == 24) {
1041 $query = "SELECT title, comments FROM lists WHERE " .
1042 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1043 "ORDER BY begdate";
1044 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1045 $count = 0;
1046 while ($lrow = sqlFetchArray($lres)) {
1047 if ($count++) echo "<br />";
1048 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
1049 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1053 // a set of labeled checkboxes, each with a text field:
1054 else if ($data_type == 25) {
1055 $tmp = explode('|', $currvalue);
1056 $avalue = array();
1057 foreach ($tmp as $value) {
1058 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1059 $avalue[$matches[1]] = $matches[2];
1062 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1063 $fldlength = empty($fld_length) ? 20 : $fld_length;
1064 $lres = sqlStatement("SELECT * FROM list_options " .
1065 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1066 echo "<table cellpadding='0' cellspacing='0'>";
1067 while ($lrow = sqlFetchArray($lres)) {
1068 $option_id = $lrow['option_id'];
1069 $restype = substr($avalue[$option_id], 0, 1);
1070 $resnote = substr($avalue[$option_id], 2);
1071 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1072 echo "<td><input type='checkbox'";
1073 if ($restype) echo " checked";
1074 echo " />&nbsp;</td>";
1075 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1076 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1077 echo "<td><input type='text'" .
1078 " size='$fldlength'" .
1079 " value='$resnote'" .
1080 " class='under'" .
1081 " /></td>" .
1082 "</tr>";
1084 echo "</table>";
1087 // a set of labeled radio buttons
1088 else if ($data_type == 27) {
1089 // In this special case, fld_length is the number of columns generated.
1090 $cols = max(1, $frow['fld_length']);
1091 $lres = sqlStatement("SELECT * FROM list_options " .
1092 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1093 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1094 $tdpct = (int) (100 / $cols);
1095 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1096 $option_id = $lrow['option_id'];
1097 if ($count % $cols == 0) {
1098 if ($count) echo "</tr>";
1099 echo "<tr>";
1101 echo "<td width='$tdpct%'>";
1102 echo "<input type='radio'";
1103 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1104 (strlen($currvalue) > 0 && $option_id == $currvalue))
1106 echo " checked";
1108 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1109 echo "</td>";
1111 if ($count) {
1112 echo "</tr>";
1113 if ($count > $cols) {
1114 // Add some space after multiple rows of radio buttons.
1115 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1116 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1119 echo "</table>";
1122 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1123 else if ($data_type == 28 || $data_type == 32) {
1124 $tmp = explode('|', $currvalue);
1125 switch(count($tmp)) {
1126 case "4": {
1127 $resnote = $tmp[0];
1128 $restype = $tmp[1];
1129 $resdate = $tmp[2];
1130 $reslist = $tmp[3];
1131 } break;
1132 case "3": {
1133 $resnote = $tmp[0];
1134 $restype = $tmp[1];
1135 $resdate = $tmp[2];
1136 } break;
1137 case "2": {
1138 $resnote = $tmp[0];
1139 $restype = $tmp[1];
1140 $resdate = "";
1141 } break;
1142 case "1": {
1143 $resnote = $tmp[0];
1144 $resdate = $restype = "";
1145 } break;
1146 default: {
1147 $restype = $resdate = $resnote = "";
1148 } break;
1150 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1151 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1152 echo "<table cellpadding='0' cellspacing='0'>";
1153 echo "<tr>";
1154 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1155 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1156 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1157 if($data_type == 28)
1159 echo "<td><input type='text'" .
1160 " size='$fldlength'" .
1161 " class='under'" .
1162 " value='$resnote' /></td>";
1163 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1164 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1165 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1167 else if($data_type == 32)
1169 echo "<tr><td><input type='text'" .
1170 " size='$fldlength'" .
1171 " class='under'" .
1172 " value='$resnote' /></td></tr>";
1173 $fldlength = 30;
1174 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1175 echo "<td><input type='text'" .
1176 " size='$fldlength'" .
1177 " class='under'" .
1178 " value='$smoking_status_title' /></td>";
1179 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1181 echo "<td><input type='radio'";
1182 if ($restype == "current".$field_id) echo " checked";
1183 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1185 echo "<td><input type='radio'";
1186 if ($restype == "current".$field_id) echo " checked";
1187 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1189 echo "<td><input type='text' size='6'" .
1190 " value='$resdate'" .
1191 " class='under'" .
1192 " /></td>";
1194 echo "<td><input type='radio'";
1195 if ($restype == "current".$field_id) echo " checked";
1196 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1198 echo "<td><input type='radio'";
1199 if ($restype == "not_applicable".$field_id) echo " checked";
1200 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1201 echo "</tr>";
1202 echo "</table>";
1205 // static text. read-only, of course.
1206 else if ($data_type == 31) {
1207 echo nl2br($frow['description']);
1212 function generate_display_field($frow, $currvalue) {
1213 $data_type = $frow['data_type'];
1214 $field_id = $frow['field_id'];
1215 $list_id = $frow['list_id'];
1216 $s = '';
1218 // generic selection list or the generic selection list with add on the fly
1219 // feature, or radio buttons
1220 if ($data_type == 1 || $data_type == 26 || $data_type == 27 || $data_type == 33) {
1221 $lrow = sqlQuery("SELECT title FROM list_options " .
1222 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1223 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1224 //For lists Race and Ethnicity if there is no matching value in the corresponding lists check ethrace list
1225 if ($lrow == 0 && $data_type == 33)
1227 $list_id='ethrace';
1228 $lrow_ethrace = sqlQuery("SELECT title FROM list_options " .
1229 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1230 $s = htmlspecialchars(xl_list_label($lrow_ethrace['title']),ENT_NOQUOTES);
1234 // simple text field
1235 else if ($data_type == 2) {
1236 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1239 // long or multi-line text field
1240 else if ($data_type == 3) {
1241 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1244 // date
1245 else if ($data_type == 4) {
1246 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES);
1249 // provider
1250 else if ($data_type == 10 || $data_type == 11) {
1251 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1252 "WHERE id = ?", array($currvalue) );
1253 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1256 // pharmacy list
1257 else if ($data_type == 12) {
1258 $pres = get_pharmacies();
1259 while ($prow = sqlFetchArray($pres)) {
1260 $key = $prow['id'];
1261 if ($currvalue == $key) {
1262 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1263 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1264 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1269 // squads
1270 else if ($data_type == 13) {
1271 $squads = acl_get_squads();
1272 if ($squads) {
1273 foreach ($squads as $key => $value) {
1274 if ($currvalue == $key) {
1275 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1281 // address book
1282 else if ($data_type == 14) {
1283 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1284 "WHERE id = ?", array($currvalue));
1285 $uname = $urow['lname'];
1286 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1287 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1290 // billing code
1291 else if ($data_type == 15) {
1292 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1295 // a set of labeled checkboxes
1296 else if ($data_type == 21) {
1297 $avalue = explode('|', $currvalue);
1298 $lres = sqlStatement("SELECT * FROM list_options " .
1299 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1300 $count = 0;
1301 while ($lrow = sqlFetchArray($lres)) {
1302 $option_id = $lrow['option_id'];
1303 if (in_array($option_id, $avalue)) {
1304 if ($count++) $s .= "<br />";
1306 // Added 5-09 by BM - Translate label if applicable
1307 $s .= htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1313 // a set of labeled text input fields
1314 else if ($data_type == 22) {
1315 $tmp = explode('|', $currvalue);
1316 $avalue = array();
1317 foreach ($tmp as $value) {
1318 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1319 $avalue[$matches[1]] = $matches[2];
1322 $lres = sqlStatement("SELECT * FROM list_options " .
1323 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1324 $s .= "<table cellpadding='0' cellspacing='0'>";
1325 while ($lrow = sqlFetchArray($lres)) {
1326 $option_id = $lrow['option_id'];
1327 if (empty($avalue[$option_id])) continue;
1329 // Added 5-09 by BM - Translate label if applicable
1330 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1332 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1334 $s .= "</table>";
1337 // a set of exam results; 3 radio buttons and a text field:
1338 else if ($data_type == 23) {
1339 $tmp = explode('|', $currvalue);
1340 $avalue = array();
1341 foreach ($tmp as $value) {
1342 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1343 $avalue[$matches[1]] = $matches[2];
1346 $lres = sqlStatement("SELECT * FROM list_options " .
1347 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1348 $s .= "<table cellpadding='0' cellspacing='0'>";
1349 while ($lrow = sqlFetchArray($lres)) {
1350 $option_id = $lrow['option_id'];
1351 $restype = substr($avalue[$option_id], 0, 1);
1352 $resnote = substr($avalue[$option_id], 2);
1353 if (empty($restype) && empty($resnote)) continue;
1355 // Added 5-09 by BM - Translate label if applicable
1356 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1358 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1359 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1360 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1361 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1362 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1363 $s .= "</tr>";
1365 $s .= "</table>";
1368 // the list of active allergies for the current patient
1369 else if ($data_type == 24) {
1370 $query = "SELECT title, comments FROM lists WHERE " .
1371 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1372 "ORDER BY begdate";
1373 // echo "<!-- $query -->\n"; // debugging
1374 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1375 $count = 0;
1376 while ($lrow = sqlFetchArray($lres)) {
1377 if ($count++) $s .= "<br />";
1378 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1379 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1383 // a set of labeled checkboxes, each with a text field:
1384 else if ($data_type == 25) {
1385 $tmp = explode('|', $currvalue);
1386 $avalue = array();
1387 foreach ($tmp as $value) {
1388 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1389 $avalue[$matches[1]] = $matches[2];
1392 $lres = sqlStatement("SELECT * FROM list_options " .
1393 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1394 $s .= "<table cellpadding='0' cellspacing='0'>";
1395 while ($lrow = sqlFetchArray($lres)) {
1396 $option_id = $lrow['option_id'];
1397 $restype = substr($avalue[$option_id], 0, 1);
1398 $resnote = substr($avalue[$option_id], 2);
1399 if (empty($restype) && empty($resnote)) continue;
1401 // Added 5-09 by BM - Translate label if applicable
1402 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1404 $restype = $restype ? xl('Yes') : xl('No');
1405 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1406 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1407 $s .= "</tr>";
1409 $s .= "</table>";
1412 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1413 // VicarePlus :: A selection list for smoking status.
1414 else if ($data_type == 28 || $data_type == 32) {
1415 $tmp = explode('|', $currvalue);
1416 switch(count($tmp)) {
1417 case "4": {
1418 $resnote = $tmp[0];
1419 $restype = $tmp[1];
1420 $resdate = $tmp[2];
1421 $reslist = $tmp[3];
1422 } break;
1423 case "3": {
1424 $resnote = $tmp[0];
1425 $restype = $tmp[1];
1426 $resdate = $tmp[2];
1427 } break;
1428 case "2": {
1429 $resnote = $tmp[0];
1430 $restype = $tmp[1];
1431 $resdate = "";
1432 } break;
1433 case "1": {
1434 $resnote = $tmp[0];
1435 $resdate = $restype = "";
1436 } break;
1437 default: {
1438 $restype = $resdate = $resnote = "";
1439 } break;
1441 $s .= "<table cellpadding='0' cellspacing='0'>";
1443 $s .= "<tr>";
1444 $res = "";
1445 if ($restype == "current".$field_id) $res = xl('Current');
1446 if ($restype == "quit".$field_id) $res = xl('Quit');
1447 if ($restype == "never".$field_id) $res = xl('Never');
1448 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1449 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1450 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1451 if ($data_type == 28)
1453 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1455 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1456 else if ($data_type == 32)
1458 if (!empty($reslist)) $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1459 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
1462 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1463 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1464 $s .= "</tr>";
1465 $s .= "</table>";
1468 // static text. read-only, of course.
1469 else if ($data_type == 31) {
1470 $s .= nl2br($frow['description']);
1473 return $s;
1476 $CPR = 4; // cells per row of generic data
1477 $last_group = '';
1478 $cell_count = 0;
1479 $item_count = 0;
1481 function disp_end_cell() {
1482 global $item_count, $cell_count;
1483 if ($item_count > 0) {
1484 echo "</td>";
1485 $item_count = 0;
1489 function disp_end_row() {
1490 global $cell_count, $CPR;
1491 disp_end_cell();
1492 if ($cell_count > 0) {
1493 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
1494 echo "</tr>\n";
1495 $cell_count = 0;
1499 function disp_end_group() {
1500 global $last_group;
1501 if (strlen($last_group) > 0) {
1502 disp_end_row();
1506 function display_layout_rows($formtype, $result1, $result2='') {
1507 global $item_count, $cell_count, $last_group, $CPR;
1509 $fres = sqlStatement("SELECT * FROM layout_options " .
1510 "WHERE form_id = ? AND uor > 0 " .
1511 "ORDER BY group_name, seq", array($formtype) );
1513 while ($frow = sqlFetchArray($fres)) {
1514 $this_group = $frow['group_name'];
1515 $titlecols = $frow['titlecols'];
1516 $datacols = $frow['datacols'];
1517 $data_type = $frow['data_type'];
1518 $field_id = $frow['field_id'];
1519 $list_id = $frow['list_id'];
1520 $currvalue = '';
1522 if ($formtype == 'DEM') {
1523 if ($GLOBALS['athletic_team']) {
1524 // Skip fitness level and return-to-play date because those appear
1525 // in a special display/update form on this page.
1526 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1528 if (strpos($field_id, 'em_') === 0) {
1529 // Skip employer related fields, if it's disabled.
1530 if ($GLOBALS['omit_employers']) continue;
1531 $tmp = substr($field_id, 3);
1532 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1534 else {
1535 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1538 else {
1539 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1542 // Handle a data category (group) change.
1543 if (strcmp($this_group, $last_group) != 0) {
1544 $group_name = substr($this_group, 1);
1545 // totally skip generating the employer category, if it's disabled.
1546 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1547 disp_end_group();
1548 $last_group = $this_group;
1551 // Handle starting of a new row.
1552 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1553 disp_end_row();
1554 echo "<tr>";
1555 if ($group_name) {
1556 echo "<td class='groupname'>";
1557 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1558 //echo "<font color='#008800'>$group_name</font>";
1560 // Added 5-09 by BM - Translate label if applicable
1561 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
1563 $group_name = '';
1564 } else {
1565 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1566 echo "<td valign='top'>&nbsp;";
1568 echo "</td>";
1571 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1573 // Handle starting of a new label cell.
1574 if ($titlecols > 0) {
1575 disp_end_cell();
1576 //echo "<td class='label' colspan='$titlecols' valign='top'";
1577 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1578 echo "<td class='label' colspan='$titlecols_esc' ";
1579 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1580 echo ">";
1581 $cell_count += $titlecols;
1583 ++$item_count;
1585 // Added 5-09 by BM - Translate label if applicable
1586 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1588 // Handle starting of a new data cell.
1589 if ($datacols > 0) {
1590 disp_end_cell();
1591 //echo "<td class='text data' colspan='$datacols' valign='top'";
1592 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1593 echo "<td class='text data' colspan='$datacols_esc'";
1594 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1595 echo ">";
1596 $cell_count += $datacols;
1599 ++$item_count;
1600 echo generate_display_field($frow, $currvalue);
1603 disp_end_group();
1606 function display_layout_tabs($formtype, $result1, $result2='') {
1607 global $item_count, $cell_count, $last_group, $CPR;
1609 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1610 "WHERE form_id = ? AND uor > 0 " .
1611 "ORDER BY group_name, seq", array($formtype) );
1613 $first = true;
1614 while ($frow = sqlFetchArray($fres)) {
1615 $this_group = $frow['group_name'];
1616 $group_name = substr($this_group, 1);
1618 <li <?php echo $first ? 'class="current"' : '' ?>>
1619 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES)."?>">
1620 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
1621 </li>
1622 <?php
1623 $first = false;
1627 function display_layout_tabs_data($formtype, $result1, $result2='') {
1628 global $item_count, $cell_count, $last_group, $CPR;
1630 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1631 "WHERE form_id = ? AND uor > 0 " .
1632 "ORDER BY group_name, seq", array($formtype));
1634 $first = true;
1635 while ($frow = sqlFetchArray($fres)) {
1636 $this_group = $frow['group_name'];
1637 $titlecols = $frow['titlecols'];
1638 $datacols = $frow['datacols'];
1639 $data_type = $frow['data_type'];
1640 $field_id = $frow['field_id'];
1641 $list_id = $frow['list_id'];
1642 $currvalue = '';
1644 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1645 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1646 "ORDER BY seq", array($formtype, $this_group) );
1649 <div class="tab <?php echo $first ? 'current' : '' ?>">
1650 <table border='0' cellpadding='0'>
1652 <?php
1653 while ($group_fields = sqlFetchArray($group_fields_query)) {
1655 $titlecols = $group_fields['titlecols'];
1656 $datacols = $group_fields['datacols'];
1657 $data_type = $group_fields['data_type'];
1658 $field_id = $group_fields['field_id'];
1659 $list_id = $group_fields['list_id'];
1660 $currvalue = '';
1662 if ($formtype == 'DEM') {
1663 if ($GLOBALS['athletic_team']) {
1664 // Skip fitness level and return-to-play date because those appear
1665 // in a special display/update form on this page.
1666 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1668 if (strpos($field_id, 'em_') === 0) {
1669 // Skip employer related fields, if it's disabled.
1670 if ($GLOBALS['omit_employers']) continue;
1671 $tmp = substr($field_id, 3);
1672 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1674 else {
1675 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1678 else {
1679 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1682 // Handle a data category (group) change.
1683 if (strcmp($this_group, $last_group) != 0) {
1684 $group_name = substr($this_group, 1);
1685 // totally skip generating the employer category, if it's disabled.
1686 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1687 $last_group = $this_group;
1690 // Handle starting of a new row.
1691 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1692 disp_end_row();
1693 echo "<tr>";
1696 if ($item_count == 0 && $titlecols == 0) {
1697 $titlecols = 1;
1700 // Handle starting of a new label cell.
1701 if ($titlecols > 0) {
1702 disp_end_cell();
1703 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1704 echo "<td class='label' colspan='$titlecols_esc' ";
1705 echo ">";
1706 $cell_count += $titlecols;
1708 ++$item_count;
1710 // Added 5-09 by BM - Translate label if applicable
1711 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1713 // Handle starting of a new data cell.
1714 if ($datacols > 0) {
1715 disp_end_cell();
1716 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1717 echo "<td class='text data' colspan='$datacols_esc'";
1718 echo ">";
1719 $cell_count += $datacols;
1722 ++$item_count;
1723 echo generate_display_field($group_fields, $currvalue);
1726 disp_end_row();
1729 </table>
1730 </div>
1732 <?php
1734 $first = false;
1740 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1741 global $item_count, $cell_count, $last_group, $CPR;
1743 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1744 "WHERE form_id = ? AND uor > 0 " .
1745 "ORDER BY group_name, seq", array($formtype) );
1747 $first = true;
1748 while ($frow = sqlFetchArray($fres)) {
1749 $this_group = $frow['group_name'];
1750 $group_name = substr($this_group, 1);
1751 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
1752 $titlecols = $frow['titlecols'];
1753 $datacols = $frow['datacols'];
1754 $data_type = $frow['data_type'];
1755 $field_id = $frow['field_id'];
1756 $list_id = $frow['list_id'];
1757 $currvalue = '';
1759 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1760 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1761 "ORDER BY seq", array($formtype,$this_group) );
1764 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name_esc?>" >
1765 <table border='0' cellpadding='0'>
1767 <?php
1768 while ($group_fields = sqlFetchArray($group_fields_query)) {
1770 $titlecols = $group_fields['titlecols'];
1771 $datacols = $group_fields['datacols'];
1772 $data_type = $group_fields['data_type'];
1773 $field_id = $group_fields['field_id'];
1774 $list_id = $group_fields['list_id'];
1775 $currvalue = '';
1777 if ($formtype == 'DEM') {
1778 if ($GLOBALS['athletic_team']) {
1779 // Skip fitness level and return-to-play date because those appear
1780 // in a special display/update form on this page.
1781 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1783 if (strpos($field_id, 'em_') === 0) {
1784 // Skip employer related fields, if it's disabled.
1785 if ($GLOBALS['omit_employers']) continue;
1786 $tmp = substr($field_id, 3);
1787 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1789 else {
1790 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1793 else {
1794 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1797 // Handle a data category (group) change.
1798 if (strcmp($this_group, $last_group) != 0) {
1799 $group_name = substr($this_group, 1);
1800 // totally skip generating the employer category, if it's disabled.
1801 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1802 $last_group = $this_group;
1805 // Handle starting of a new row.
1806 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1807 disp_end_row();
1808 echo "<tr>";
1811 if ($item_count == 0 && $titlecols == 0) {
1812 $titlecols = 1;
1815 // Handle starting of a new label cell.
1816 if ($titlecols > 0) {
1817 disp_end_cell();
1818 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1819 echo "<td class='label' colspan='$titlecols_esc' ";
1820 echo ">";
1821 $cell_count += $titlecols;
1823 ++$item_count;
1825 // Added 5-09 by BM - Translate label if applicable
1826 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
1828 // Handle starting of a new data cell.
1829 if ($datacols > 0) {
1830 disp_end_cell();
1831 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1832 echo "<td class='text data' colspan='$datacols_esc'";
1833 echo ">";
1834 $cell_count += $datacols;
1837 ++$item_count;
1838 echo generate_form_field($group_fields, $currvalue);
1842 </table>
1843 </div>
1845 <?php
1847 $first = false;
1852 // From the currently posted HTML form, this gets the value of the
1853 // field corresponding to the provided layout_options table row.
1855 function get_layout_form_value($frow, $maxlength=255) {
1856 // Bring in $sanitize_all_escapes variable, which will decide
1857 // the variable escaping method.
1858 global $sanitize_all_escapes;
1860 $data_type = $frow['data_type'];
1861 $field_id = $frow['field_id'];
1862 $value = '';
1863 if (isset($_POST["form_$field_id"])) {
1864 if ($data_type == 21) {
1865 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1866 // must be concatenated into a |-separated string.
1867 foreach ($_POST["form_$field_id"] as $key => $val) {
1868 if (strlen($value)) $value .= '|';
1869 $value .= $key;
1872 else if ($data_type == 22) {
1873 // $_POST["form_$field_id"] is an array of text fields to be imploded
1874 // into "key:value|key:value|...".
1875 foreach ($_POST["form_$field_id"] as $key => $val) {
1876 $val = str_replace('|', ' ', $val);
1877 if (strlen($value)) $value .= '|';
1878 $value .= "$key:$val";
1881 else if ($data_type == 23) {
1882 // $_POST["form_$field_id"] is an array of text fields with companion
1883 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1884 foreach ($_POST["form_$field_id"] as $key => $val) {
1885 $restype = $_POST["radio_{$field_id}"][$key];
1886 if (empty($restype)) $restype = '0';
1887 $val = str_replace('|', ' ', $val);
1888 if (strlen($value)) $value .= '|';
1889 $value .= "$key:$restype:$val";
1892 else if ($data_type == 25) {
1893 // $_POST["form_$field_id"] is an array of text fields with companion
1894 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1895 foreach ($_POST["form_$field_id"] as $key => $val) {
1896 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
1897 $val = str_replace('|', ' ', $val);
1898 if (strlen($value)) $value .= '|';
1899 $value .= "$key:$restype:$val";
1902 else if ($data_type == 28 || $data_type == 32) {
1903 // $_POST["form_$field_id"] is an date text fields with companion
1904 // radio buttons to be imploded into "notes|type|date".
1905 $restype = $_POST["radio_{$field_id}"];
1906 if (empty($restype)) $restype = '0';
1907 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1908 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1909 if ($data_type == 32)
1911 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
1912 $reslist = str_replace('|', ' ', $_POST["form_$field_id"]);
1913 $res_text_note = str_replace('|', ' ', $_POST["form_text_$field_id"]);
1914 $value = "$res_text_note|$restype|$resdate|$reslist";
1916 else
1917 $value = "$resnote|$restype|$resdate";
1919 else {
1920 $value = $_POST["form_$field_id"];
1924 // Better to die than to silently truncate data!
1925 if ($maxlength && $data_type != 3 && strlen($value) > $maxlength)
1926 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
1927 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
1929 // Make sure the return value is quote-safe.
1930 if ($sanitize_all_escapes) {
1931 //escapes already removed and using binding/placemarks in sql calls
1932 // so only need to trim value
1933 return trim($value);
1935 else {
1936 //need to explicitly prepare value
1937 return formTrim($value);
1941 // Generate JavaScript validation logic for the required fields.
1943 function generate_layout_validation($form_id) {
1944 $fres = sqlStatement("SELECT * FROM layout_options " .
1945 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
1946 "ORDER BY group_name, seq", array($form_id) );
1948 while ($frow = sqlFetchArray($fres)) {
1949 if ($frow['uor'] < 2) continue;
1950 $data_type = $frow['data_type'];
1951 $field_id = $frow['field_id'];
1952 $fldtitle = $frow['title'];
1953 if (!$fldtitle) $fldtitle = $frow['description'];
1954 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES);
1955 switch($data_type) {
1956 case 1:
1957 case 11:
1958 case 12:
1959 case 13:
1960 case 14:
1961 case 26:
1962 case 33:
1963 echo
1964 " if (f.$fldname.selectedIndex <= 0) {\n" .
1965 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1966 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1967 " }\n";
1968 break;
1969 case 27: // radio buttons
1970 echo
1971 " var i = 0;\n" .
1972 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
1973 " if (i >= f.$fldname.length) {\n" .
1974 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1975 " }\n";
1976 break;
1977 case 2:
1978 case 3:
1979 case 4:
1980 case 15:
1981 echo
1982 " if (trimlen(f.$fldname.value) == 0) {\n" .
1983 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1984 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
1985 " $('#" . $fldname . "').attr('style','background:red'); \n" .
1986 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1987 " } else { " .
1988 " $('#" . $fldname . "').attr('style',''); " .
1989 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
1990 " } \n";
1991 break;
1997 * DROPDOWN FOR FACILITIES
1999 * build a dropdown with all facilities
2001 * @param string $selected - name of the currently selected facility
2002 * use '0' for "unspecified facility"
2003 * use '' for "All facilities" (the default)
2004 * @param string $name - the name/id for select form (defaults to "form_facility")
2005 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2006 * defaults to true
2007 * @return void - just echo the html encoded string
2009 * Note: This should become a data-type at some point, according to Brady
2011 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true) {
2012 $have_selected = false;
2013 $query = "SELECT id, name FROM facility ORDER BY name";
2014 $fres = sqlStatement($query);
2016 $name = htmlspecialchars($name, ENT_QUOTES);
2017 echo " <select name=\"$name\">\n";
2019 $option_value = '';
2020 $option_selected_attr = '';
2021 if ($selected == '') {
2022 $option_selected_attr = ' selected="selected"';
2023 $have_selected = true;
2025 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
2026 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2028 while ($frow = sqlFetchArray($fres)) {
2029 $facility_id = $frow['id'];
2030 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
2031 $option_selected_attr = '';
2032 if ($selected == $facility_id) {
2033 $option_selected_attr = ' selected="selected"';
2034 $have_selected = true;
2036 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
2037 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2040 if ($allow_unspecified) {
2041 $option_value = '0';
2042 $option_selected_attr = '';
2043 if ( $selected == '0' ) {
2044 $option_selected_attr = ' selected="selected"';
2045 $have_selected = true;
2047 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
2048 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2051 if (!$have_selected) {
2052 $option_value = htmlspecialchars($selected, ENT_QUOTES);
2053 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
2054 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
2055 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2057 echo " </select>\n";
2060 // Expand Collapse Widget
2061 // This forms the header and functionality component of the widget. The information that is displayed
2062 // then follows this function followed by a closing div tag
2064 // $title is the title of the section (already translated)
2065 // $label is identifier used in the tag id's and sql columns
2066 // $buttonLabel is the button label text (already translated)
2067 // $buttonLink is the button link information
2068 // $buttonClass is any additional needed class elements for the button tag
2069 // $linkMethod is the button link method ('javascript' vs 'html')
2070 // $bodyClass is to set class(es) of the body
2071 // $auth is a flag to decide whether to show the button
2072 // $fixedWidth is to flag whether width is fixed
2073 // $forceExpandAlways is a flag to force the widget to always be expanded
2075 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2076 if ($fixedWidth) {
2077 echo "<div class='section-header'>";
2079 else {
2080 echo "<div class='section-header-dynamic'>";
2082 echo "<table><tr>";
2083 if ($auth) {
2084 // show button, since authorized
2085 // first prepare class string
2086 if ($buttonClass) {
2087 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
2089 else {
2090 $class_string = "css_button_small";
2092 // next, create the link
2093 if ($linkMethod == "javascript") {
2094 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2096 else {
2097 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'" .
2098 " onclick='top.restoreSession()'";
2100 if (!$GLOBALS['concurrent_layout']) {
2101 echo " target='Main'";
2103 echo "><span>" .
2104 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
2106 if ($forceExpandAlways){
2107 // Special case to force the widget to always be expanded
2108 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2109 $indicatorTag ="style='display:none'";
2111 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2112 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
2113 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2114 if (getUserSetting($label."_ps_expand")) {
2115 $text = xl('collapse');
2117 else {
2118 $text = xl('expand');
2120 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
2121 "</span>)</a></td>";
2122 echo "</tr></table>";
2123 echo "</div>";
2124 if ($forceExpandAlways) {
2125 // Special case to force the widget to always be expanded
2126 $styling = "";
2128 else if (getUserSetting($label."_ps_expand")) {
2129 $styling = "";
2131 else {
2132 $styling = "style='display:none'";
2134 if ($bodyClass) {
2135 $styling .= " class='" . $bodyClass . "'";
2137 //next, create the first div tag to hold the information
2138 // note the code that calls this function will then place the ending div tag after the data
2139 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";