CAMOS bug fix continued. See previous commit message for details.
[openemr.git] / library / options.inc.php
blob04733938b7a5b2d324f9d644e03aa271d9571518
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 // H = Read-only field copied from static history
24 // N = Show in New Patient form
25 // O = Procedure Order ("pro_*") types only (address book)
26 // U = Capitalize all letters (text fields)
27 // V = Vendor types only (address book)
28 // R = Distributor types only (address book)
29 // 1 = Write Once (not editable when not empty) (text fields)
31 require_once("formdata.inc.php");
32 require_once("formatting.inc.php");
33 require_once("user.inc");
35 $date_init = "";
37 function get_pharmacies() {
38 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
39 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
40 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
41 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
42 "AND p.type = 2 " .
43 "ORDER BY name, area_code, prefix, number");
46 // Function to generate a drop-list.
48 function generate_select_list($tag_name, $list_id, $currvalue, $title,
49 $empty_name=' ', $class='', $onchange='')
51 $s = '';
52 $tag_name_esc = htmlspecialchars( $tag_name, ENT_QUOTES);
53 $s .= "<select name='$tag_name_esc' id='$tag_name_esc'";
54 if ($class) $s .= " class='$class'";
55 if ($onchange) $s .= " onchange='$onchange'";
56 $selectTitle = htmlspecialchars( $title, ENT_QUOTES);
57 $s .= " title='$selectTitle'>";
58 $selectEmptyName = htmlspecialchars( xl($empty_name), ENT_NOQUOTES);
59 if ($empty_name) $s .= "<option value=''>" . $selectEmptyName . "</option>";
60 $lres = sqlStatement("SELECT * FROM list_options " .
61 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
62 $got_selected = FALSE;
63 while ($lrow = sqlFetchArray($lres)) {
64 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
65 $s .= "<option value='$optionValue'";
66 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
67 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
69 $s .= " selected";
70 $got_selected = TRUE;
72 $optionLabel = htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
73 $s .= ">$optionLabel</option>\n";
75 if (!$got_selected && strlen($currvalue) > 0) {
76 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
77 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
78 $s .= "</select>";
79 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_QUOTES);
80 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
81 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
83 else {
84 $s .= "</select>";
86 return $s;
89 // $frow is a row from the layout_options table.
90 // $currvalue is the current value, if any, of the associated item.
92 function generate_form_field($frow, $currvalue) {
93 global $rootdir, $date_init;
95 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
97 $data_type = $frow['data_type'];
98 $field_id = $frow['field_id'];
99 $list_id = $frow['list_id'];
100 // escaped variables to use in html
101 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
102 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
104 // Added 5-09 by BM - Translate description if applicable
105 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
107 // added 5-2009 by BM to allow modification of the 'empty' text title field.
108 // Can pass $frow['empty_title'] with this variable, otherwise
109 // will default to 'Unassigned'.
110 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
111 // if make $frow['empty_title'] equal to 'SKIP'
112 $showEmpty = true;
113 if (isset($frow['empty_title'])) {
114 if ($frow['empty_title'] == "SKIP") {
115 //do not display an 'empty' choice
116 $showEmpty = false;
117 $empty_title = "Unassigned";
119 else {
120 $empty_title = $frow['empty_title'];
123 else {
124 $empty_title = "Unassigned";
127 // generic single-selection list
128 if ($data_type == 1) {
129 echo generate_select_list("form_$field_id", $list_id, $currvalue,
130 $description, $showEmpty ? $empty_title : '');
133 // simple text field
134 else if ($data_type == 2) {
135 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
136 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
137 echo "<input type='text'" .
138 " name='form_$field_id_esc'" .
139 " id='form_$field_id_esc'" .
140 " size='$fldlength'" .
141 " maxlength='$maxlength'" .
142 " title='$description'" .
143 " value='$currescaped'";
144 if (strpos($frow['edit_options'], 'C') !== FALSE)
145 echo " onchange='capitalizeMe(this)'";
146 else if (strpos($frow['edit_options'], 'U') !== FALSE)
147 echo " onchange='this.value = this.value.toUpperCase()'";
148 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
149 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
150 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
151 echo " onblur='maskblur(this,\"$tmp\")'";
153 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0)
154 echo " readonly";
155 echo " />";
158 // long or multi-line text field
159 else if ($data_type == 3) {
160 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
161 $textRows = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
162 echo "<textarea" .
163 " name='form_$field_id_esc'" .
164 " id='form_$field_id_esc'" .
165 " title='$description'" .
166 " cols='$textCols'" .
167 " rows='$textRows'>" .
168 $currescaped . "</textarea>";
171 // date
172 else if ($data_type == 4) {
173 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
174 " value='$currescaped'" .
175 " title='$description'" .
176 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
177 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
178 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
179 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
180 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
183 // provider list, local providers only
184 else if ($data_type == 10) {
185 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
186 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
187 "AND authorized = 1 " .
188 "ORDER BY lname, fname");
189 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
190 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
191 while ($urow = sqlFetchArray($ures)) {
192 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
193 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
194 echo "<option value='$optionId'";
195 if ($urow['id'] == $currvalue) echo " selected";
196 echo ">$uname</option>";
198 echo "</select>";
201 // provider list, including address book entries with an NPI number
202 else if ($data_type == 11) {
203 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
204 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
205 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
206 "ORDER BY lname, fname");
207 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
208 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
209 while ($urow = sqlFetchArray($ures)) {
210 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
211 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
212 echo "<option value='$optionId'";
213 if ($urow['id'] == $currvalue) echo " selected";
214 echo ">$uname</option>";
216 echo "</select>";
219 // pharmacy list
220 else if ($data_type == 12) {
221 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
222 echo "<option value='0'></option>";
223 $pres = get_pharmacies();
224 while ($prow = sqlFetchArray($pres)) {
225 $key = $prow['id'];
226 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
227 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
228 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
229 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
230 echo "<option value='$optionValue'";
231 if ($currvalue == $key) echo " selected";
232 echo ">$optionLabel</option>";
234 echo "</select>";
237 // squads
238 else if ($data_type == 13) {
239 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
240 echo "<option value=''>&nbsp;</option>";
241 $squads = acl_get_squads();
242 if ($squads) {
243 foreach ($squads as $key => $value) {
244 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
245 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
246 echo "<option value='$optionValue'";
247 if ($currvalue == $key) echo " selected";
248 echo ">$optionLabel</option>\n";
251 echo "</select>";
254 // Address book, preferring organization name if it exists and is not in
255 // parentheses, and excluding local users who are not providers.
256 // Supports "referred to" practitioners and facilities.
257 // Alternatively the letter O in edit_options means that abook_type
258 // must begin with "ord_", indicating types used with the procedure
259 // ordering system.
260 // Alternatively the letter V in edit_options means that abook_type
261 // must be "vendor", indicating the Vendor type.
262 // Alternatively the letter R in edit_options means that abook_type
263 // must be "dist", indicating the Distributor type.
264 else if ($data_type == 14) {
265 if (strpos($frow['edit_options'], 'O') !== FALSE)
266 $tmp = "abook_type LIKE 'ord\\_%'";
267 else if (strpos($frow['edit_options'], 'V') !== FALSE)
268 $tmp = "abook_type LIKE 'vendor%'";
269 else if (strpos($frow['edit_options'], 'R') !== FALSE)
270 $tmp = "abook_type LIKE 'dist'";
271 else
272 $tmp = "( username = '' OR authorized = 1 )";
273 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
274 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
275 "AND $tmp " .
276 "ORDER BY organization, lname, fname");
277 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
278 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
279 while ($urow = sqlFetchArray($ures)) {
280 $uname = $urow['organization'];
281 if (empty($uname) || substr($uname, 0, 1) == '(') {
282 $uname = $urow['lname'];
283 if ($urow['fname']) $uname .= ", " . $urow['fname'];
285 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
286 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
287 echo "<option value='$optionValue'";
288 $title = $urow['username'] ? xl('Local') : xl('External');
289 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
290 echo " title='$optionTitle'";
291 if ($urow['id'] == $currvalue) echo " selected";
292 echo ">$optionLabel</option>";
294 echo "</select>";
297 // a billing code
298 else if ($data_type == 15) {
299 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
300 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
301 echo "<input type='text'" .
302 " name='form_$field_id_esc'" .
303 " id='form_related_code'" .
304 " size='$fldlength'" .
305 " maxlength='$maxlength'" .
306 " title='$description'" .
307 " value='$currescaped'" .
308 " onclick='sel_related(this)' readonly" .
309 " />";
312 // a set of labeled checkboxes
313 else if ($data_type == 21) {
314 // In this special case, fld_length is the number of columns generated.
315 $cols = max(1, $frow['fld_length']);
316 $avalue = explode('|', $currvalue);
317 $lres = sqlStatement("SELECT * FROM list_options " .
318 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
319 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
320 $tdpct = (int) (100 / $cols);
321 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
322 $option_id = $lrow['option_id'];
323 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
324 // if ($count) echo "<br />";
325 if ($count % $cols == 0) {
326 if ($count) echo "</tr>";
327 echo "<tr>";
329 echo "<td width='$tdpct%'>";
330 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]' id='form_{$field_id_esc}[$option_id_esc]' value='1'";
331 if (in_array($option_id, $avalue)) echo " checked";
333 // Added 5-09 by BM - Translate label if applicable
334 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
336 echo "</td>";
338 if ($count) {
339 echo "</tr>";
340 if ($count > $cols) {
341 // Add some space after multiple rows of checkboxes.
342 $cols = htmlspecialchars( $cols, ENT_QUOTES);
343 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
346 echo "</table>";
349 // a set of labeled text input fields
350 else if ($data_type == 22) {
351 $tmp = explode('|', $currvalue);
352 $avalue = array();
353 foreach ($tmp as $value) {
354 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
355 $avalue[$matches[1]] = $matches[2];
358 $lres = sqlStatement("SELECT * FROM list_options " .
359 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
360 echo "<table cellpadding='0' cellspacing='0'>";
361 while ($lrow = sqlFetchArray($lres)) {
362 $option_id = $lrow['option_id'];
363 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
364 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
365 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
367 // Added 5-09 by BM - Translate label if applicable
368 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
369 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
370 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
371 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
372 echo "<td><input type='text'" .
373 " name='form_{$field_id_esc}[$option_id_esc]'" .
374 " id='form_{$field_id_esc}[$option_id_esc]'" .
375 " size='$fldlength'" .
376 " maxlength='$maxlength'" .
377 " value='$optionValue'";
378 echo " /></td></tr>";
380 echo "</table>";
383 // a set of exam results; 3 radio buttons and a text field:
384 else if ($data_type == 23) {
385 $tmp = explode('|', $currvalue);
386 $avalue = array();
387 foreach ($tmp as $value) {
388 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
389 $avalue[$matches[1]] = $matches[2];
392 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
393 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
394 $lres = sqlStatement("SELECT * FROM list_options " .
395 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
396 echo "<table cellpadding='0' cellspacing='0'>";
397 echo "<tr><td>&nbsp;</td><td class='bold'>" .
398 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
399 "&nbsp;</td><td class='bold'>" .
400 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
401 "<td class='bold'>" .
402 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
403 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
404 while ($lrow = sqlFetchArray($lres)) {
405 $option_id = $lrow['option_id'];
406 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
407 $restype = substr($avalue[$option_id], 0, 1);
408 $resnote = substr($avalue[$option_id], 2);
410 // Added 5-09 by BM - Translate label if applicable
411 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
413 for ($i = 0; $i < 3; ++$i) {
414 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
415 echo "<td><input type='radio'" .
416 " name='radio_{$field_id_esc}[$option_id_esc]'" .
417 " id='radio_{$field_id_esc}[$option_id_esc]'" .
418 " value='$inputValue'";
419 if ($restype === "$i") echo " checked";
420 echo " /></td>";
422 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
423 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
424 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
425 echo "<td><input type='text'" .
426 " name='form_{$field_id_esc}[$option_id_esc]'" .
427 " id='form_{$field_id_esc}[$option_id_esc]'" .
428 " size='$fldlength'" .
429 " maxlength='$maxlength'" .
430 " value='$resnote' /></td>";
431 echo "</tr>";
433 echo "</table>";
436 // the list of active allergies for the current patient
437 // this is read-only!
438 else if ($data_type == 24) {
439 $query = "SELECT title, comments FROM lists WHERE " .
440 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
441 "ORDER BY begdate";
442 // echo "<!-- $query -->\n"; // debugging
443 $lres = sqlStatement($query, array($GLOBALS['pid']));
444 $count = 0;
445 while ($lrow = sqlFetchArray($lres)) {
446 if ($count++) echo "<br />";
447 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
448 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
452 // a set of labeled checkboxes, each with a text field:
453 else if ($data_type == 25) {
454 $tmp = explode('|', $currvalue);
455 $avalue = array();
456 foreach ($tmp as $value) {
457 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
458 $avalue[$matches[1]] = $matches[2];
461 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
462 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
463 $lres = sqlStatement("SELECT * FROM list_options " .
464 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
465 echo "<table cellpadding='0' cellspacing='0'>";
466 while ($lrow = sqlFetchArray($lres)) {
467 $option_id = $lrow['option_id'];
468 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
469 $restype = substr($avalue[$option_id], 0, 1);
470 $resnote = substr($avalue[$option_id], 2);
472 // Added 5-09 by BM - Translate label if applicable
473 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
475 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
476 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]' id='check_{$field_id_esc}[$option_id_esc]' value='1'";
477 if ($restype) echo " checked";
478 echo " />&nbsp;</td>";
479 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
480 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
481 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
482 echo "<td><input type='text'" .
483 " name='form_{$field_id_esc}[$option_id_esc]'" .
484 " id='form_{$field_id_esc}[$option_id_esc]'" .
485 " size='$fldlength'" .
486 " maxlength='$maxlength'" .
487 " value='$resnote' /></td>";
488 echo "</tr>";
490 echo "</table>";
493 // single-selection list with ability to add to it
494 else if ($data_type == 26) {
495 echo "<select class='addtolistclass_$list_id_esc' name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
496 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES) . "</option>";
497 $lres = sqlStatement("SELECT * FROM list_options " .
498 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
499 $got_selected = FALSE;
500 while ($lrow = sqlFetchArray($lres)) {
501 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
502 echo "<option value='$optionValue'";
503 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
504 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
506 echo " selected";
507 $got_selected = TRUE;
509 // Added 5-09 by BM - Translate label if applicable
510 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n";
512 if (!$got_selected && strlen($currvalue) > 0) {
513 echo "<option value='$currescaped' selected>* $currescaped *</option>";
514 echo "</select>";
515 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES);
516 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
517 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
519 else {
520 echo "</select>";
522 // show the add button if user has access to correct list
523 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
524 $outputAddButton = "<input type='button' id='addtolistid_".$list_id_esc."' fieldid='form_".$field_id_esc."' class='addtolist' value='$inputValue'>";
525 if (aco_exist('lists', $list_id)) {
526 // a specific aco exist for this list, so ensure access
527 if (acl_check('lists', $list_id)) echo $outputAddButton;
529 else {
530 // no specific aco exist for this list, so check for access to 'default' list
531 if (acl_check('lists', 'default')) echo $outputAddButton;
535 // a set of labeled radio buttons
536 else if ($data_type == 27) {
537 // In this special case, fld_length is the number of columns generated.
538 $cols = max(1, $frow['fld_length']);
539 $lres = sqlStatement("SELECT * FROM list_options " .
540 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
541 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
542 $tdpct = (int) (100 / $cols);
543 $got_selected = FALSE;
544 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
545 $option_id = $lrow['option_id'];
546 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
547 if ($count % $cols == 0) {
548 if ($count) echo "</tr>";
549 echo "<tr>";
551 echo "<td width='$tdpct%'>";
552 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]' value='$option_id_esc'";
553 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
554 (strlen($currvalue) > 0 && $option_id == $currvalue))
556 echo " checked";
557 $got_selected = TRUE;
559 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
560 echo "</td>";
562 if ($count) {
563 echo "</tr>";
564 if ($count > $cols) {
565 // Add some space after multiple rows of radio buttons.
566 $cols = htmlspecialchars( $cols, ENT_QUOTES);
567 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
570 echo "</table>";
571 if (!$got_selected && strlen($currvalue) > 0) {
572 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
573 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
574 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
578 // special case for history of lifestyle status; 3 radio buttons and a date text field:
579 // VicarePlus :: A selection list box for smoking status:
580 else if ($data_type == 28 || $data_type == 32) {
581 $tmp = explode('|', $currvalue);
582 switch(count($tmp)) {
583 case "4": {
584 $resnote = $tmp[0];
585 $restype = $tmp[1];
586 $resdate = $tmp[2];
587 $reslist = $tmp[3];
588 } break;
589 case "3": {
590 $resnote = $tmp[0];
591 $restype = $tmp[1];
592 $resdate = $tmp[2];
593 } break;
594 case "2": {
595 $resnote = $tmp[0];
596 $restype = $tmp[1];
597 $resdate = "";
598 } break;
599 case "1": {
600 $resnote = $tmp[0];
601 $resdate = $restype = "";
602 } break;
603 default: {
604 $restype = $resdate = $resnote = "";
605 } break;
607 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
608 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
610 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
611 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
612 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
613 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
614 echo "<table cellpadding='0' cellspacing='0'>";
615 echo "<tr>";
616 if ($data_type == 28)
618 // input text
619 echo "<td><input type='text'" .
620 " name='form_$field_id_esc'" .
621 " id='form_$field_id_esc'" .
622 " size='$fldlength'" .
623 " maxlength='$maxlength'" .
624 " value='$resnote' />&nbsp;</td>";
625 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
626 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
627 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
629 else if($data_type == 32)
631 // input text
632 echo "<tr><td><input type='text'" .
633 " name='form_text_$field_id_esc'" .
634 " id='form_text_$field_id_esc'" .
635 " size='$fldlength'" .
636 " maxlength='$maxlength'" .
637 " value='$resnote' />&nbsp;</td></tr>";
638 echo "<td>";
639 //Selection list for smoking status
640 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
641 echo generate_select_list("form_$field_id", $list_id, $reslist,
642 $description, $showEmpty ? $empty_title : '', '', $onchange)."</td>";
643 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
645 // current
646 echo "<td><input type='radio'" .
647 " name='radio_{$field_id_esc}'" .
648 " id='radio_{$field_id_esc}[current]'" .
649 " value='current".$field_id_esc."'";
650 if ($restype == "current".$field_id) echo " checked";
651 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
652 // quit
653 echo "<td><input type='radio'" .
654 " name='radio_{$field_id_esc}'" .
655 " id='radio_{$field_id_esc}[quit]'" .
656 " value='quit".$field_id_esc."'";
657 if ($restype == "quit".$field_id) echo " checked";
658 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
659 // quit date
660 echo "<td><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
661 " value='$resdate'" .
662 " title='$description'" .
663 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
664 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
665 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
666 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />&nbsp;</td>";
667 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
668 // never
669 echo "<td><input type='radio'" .
670 " name='radio_{$field_id_esc}'" .
671 " id='radio_{$field_id_esc}[never]'" .
672 " value='never".$field_id_esc."'";
673 if ($restype == "never".$field_id) echo " checked";
674 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."&nbsp;</td>";
675 // Not Applicable
676 echo "<td><input type='radio'" .
677 " name='radio_{$field_id}'" .
678 " id='radio_{$field_id}[not_applicable]'" .
679 " value='not_applicable".$field_id."'";
680 if ($restype == "not_applicable".$field_id) echo " checked";
681 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('N/A'), ENT_QUOTES)."&nbsp;</td>";
682 echo "</tr>";
683 echo "</table>";
686 // static text. read-only, of course.
687 else if ($data_type == 31) {
688 echo nl2br($frow['description']);
693 function generate_print_field($frow, $currvalue) {
694 global $rootdir, $date_init;
696 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
698 $data_type = $frow['data_type'];
699 $field_id = $frow['field_id'];
700 $list_id = $frow['list_id'];
701 $fld_length = $frow['fld_length'];
703 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
705 // Can pass $frow['empty_title'] with this variable, otherwise
706 // will default to 'Unassigned'.
707 // If it is 'SKIP' then an empty text title is completely skipped.
708 $showEmpty = true;
709 if (isset($frow['empty_title'])) {
710 if ($frow['empty_title'] == "SKIP") {
711 //do not display an 'empty' choice
712 $showEmpty = false;
713 $empty_title = "Unassigned";
715 else {
716 $empty_title = $frow['empty_title'];
719 else {
720 $empty_title = "Unassigned";
723 // generic single-selection list
724 if ($data_type == 1 || $data_type == 26) {
725 if (empty($fld_length)) {
726 if ($list_id == 'titles') {
727 $fld_length = 3;
728 } else {
729 $fld_length = 10;
732 $tmp = '';
733 if ($currvalue) {
734 $lrow = sqlQuery("SELECT title FROM list_options " .
735 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
736 $tmp = xl_list_label($lrow['title']);
737 if (empty($tmp)) $tmp = "($currvalue)";
739 /*****************************************************************
740 echo "<input type='text'" .
741 " size='$fld_length'" .
742 " value='$tmp'" .
743 " class='under'" .
744 " />";
745 *****************************************************************/
746 if ($tmp === '') { $tmp = '&nbsp;'; }
747 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
748 echo $tmp;
751 // simple text field
752 else if ($data_type == 2 || $data_type == 15) {
753 /*****************************************************************
754 echo "<input type='text'" .
755 " size='$fld_length'" .
756 " value='$currescaped'" .
757 " class='under'" .
758 " />";
759 *****************************************************************/
760 if ($currescaped === '') $currescaped = '&nbsp;';
761 echo $currescaped;
764 // long or multi-line text field
765 else if ($data_type == 3) {
766 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
767 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
768 echo "<textarea" .
769 " cols='$fldlength'" .
770 " rows='$maxlength'>" .
771 $currescaped . "</textarea>";
774 // date
775 else if ($data_type == 4) {
776 /*****************************************************************
777 echo "<input type='text' size='10'" .
778 " value='$currescaped'" .
779 " title='$description'" .
780 " class='under'" .
781 " />";
782 *****************************************************************/
783 if ($currvalue === '') { $tmp = oeFormatShortDate('&nbsp;'); }
784 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES); }
785 echo $tmp;
788 // provider list
789 else if ($data_type == 10 || $data_type == 11) {
790 $tmp = '';
791 if ($currvalue) {
792 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
793 "WHERE id = ?", array($currvalue) );
794 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
795 if (empty($tmp)) $tmp = "($currvalue)";
797 /*****************************************************************
798 echo "<input type='text'" .
799 " size='$fld_length'" .
800 " value='$tmp'" .
801 " class='under'" .
802 " />";
803 *****************************************************************/
804 if ($tmp === '') { $tmp = '&nbsp;'; }
805 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
806 echo $tmp;
809 // pharmacy list
810 else if ($data_type == 12) {
811 $tmp = '';
812 if ($currvalue) {
813 $pres = get_pharmacies();
814 while ($prow = sqlFetchArray($pres)) {
815 $key = $prow['id'];
816 if ($currvalue == $key) {
817 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
818 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
819 $prow['line1'] . ' / ' . $prow['city'];
822 if (empty($tmp)) $tmp = "($currvalue)";
824 /*****************************************************************
825 echo "<input type='text'" .
826 " size='$fld_length'" .
827 " value='$tmp'" .
828 " class='under'" .
829 " />";
830 *****************************************************************/
831 if ($tmp === '') { $tmp = '&nbsp;'; }
832 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
833 echo $tmp;
836 // squads
837 else if ($data_type == 13) {
838 $tmp = '';
839 if ($currvalue) {
840 $squads = acl_get_squads();
841 if ($squads) {
842 foreach ($squads as $key => $value) {
843 if ($currvalue == $key) {
844 $tmp = $value[3];
848 if (empty($tmp)) $tmp = "($currvalue)";
850 /*****************************************************************
851 echo "<input type='text'" .
852 " size='$fld_length'" .
853 " value='$tmp'" .
854 " class='under'" .
855 " />";
856 *****************************************************************/
857 if ($tmp === '') { $tmp = '&nbsp;'; }
858 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
859 echo $tmp;
862 // Address book.
863 else if ($data_type == 14) {
864 $tmp = '';
865 if ($currvalue) {
866 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
867 "WHERE id = ?", array($currvalue) );
868 $uname = $urow['lname'];
869 if ($urow['fname']) $uname .= ", " . $urow['fname'];
870 $tmp = $uname;
871 if (empty($tmp)) $tmp = "($currvalue)";
873 /*****************************************************************
874 echo "<input type='text'" .
875 " size='$fld_length'" .
876 " value='$tmp'" .
877 " class='under'" .
878 " />";
879 *****************************************************************/
880 if ($tmp === '') { $tmp = '&nbsp;'; }
881 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
882 echo $tmp;
885 // a set of labeled checkboxes
886 else if ($data_type == 21) {
887 // In this special case, fld_length is the number of columns generated.
888 $cols = max(1, $fld_length);
889 $avalue = explode('|', $currvalue);
890 $lres = sqlStatement("SELECT * FROM list_options " .
891 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
892 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
893 $tdpct = (int) (100 / $cols);
894 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
895 $option_id = $lrow['option_id'];
896 if ($count % $cols == 0) {
897 if ($count) echo "</tr>";
898 echo "<tr>";
900 echo "<td width='$tdpct%'>";
901 echo "<input type='checkbox'";
902 if (in_array($option_id, $avalue)) echo " checked";
903 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
904 echo "</td>";
906 if ($count) {
907 echo "</tr>";
908 if ($count > $cols) {
909 // Add some space after multiple rows of checkboxes.
910 $cols = htmlspecialchars( $cols, ENT_QUOTES);
911 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
914 echo "</table>";
917 // a set of labeled text input fields
918 else if ($data_type == 22) {
919 $tmp = explode('|', $currvalue);
920 $avalue = array();
921 foreach ($tmp as $value) {
922 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
923 $avalue[$matches[1]] = $matches[2];
926 $lres = sqlStatement("SELECT * FROM list_options " .
927 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
928 echo "<table cellpadding='0' cellspacing='0'>";
929 while ($lrow = sqlFetchArray($lres)) {
930 $option_id = $lrow['option_id'];
931 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
932 $fldlength = empty($fld_length) ? 20 : $fld_length;
933 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
934 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
935 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
936 echo "<td><input type='text'" .
937 " size='$fldlength'" .
938 " value='$inputValue'" .
939 " class='under'" .
940 " /></td></tr>";
942 echo "</table>";
945 // a set of exam results; 3 radio buttons and a text field:
946 else if ($data_type == 23) {
947 $tmp = explode('|', $currvalue);
948 $avalue = array();
949 foreach ($tmp as $value) {
950 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
951 $avalue[$matches[1]] = $matches[2];
954 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
955 $fldlength = empty($fld_length) ? 20 : $fld_length;
956 $lres = sqlStatement("SELECT * FROM list_options " .
957 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
958 echo "<table cellpadding='0' cellspacing='0'>";
959 echo "<tr><td>&nbsp;</td><td class='bold'>" .
960 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
961 "&nbsp;</td><td class='bold'>" .
962 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
963 "<td class='bold'>" .
964 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
965 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
966 while ($lrow = sqlFetchArray($lres)) {
967 $option_id = $lrow['option_id'];
968 $restype = substr($avalue[$option_id], 0, 1);
969 $resnote = substr($avalue[$option_id], 2);
970 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
971 for ($i = 0; $i < 3; ++$i) {
972 echo "<td><input type='radio'";
973 if ($restype === "$i") echo " checked";
974 echo " /></td>";
976 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
977 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
978 echo "<td><input type='text'" .
979 " size='$fldlength'" .
980 " value='$resnote'" .
981 " class='under' /></td>" .
982 "</tr>";
984 echo "</table>";
987 // the list of active allergies for the current patient
988 // this is read-only!
989 else if ($data_type == 24) {
990 $query = "SELECT title, comments FROM lists WHERE " .
991 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
992 "ORDER BY begdate";
993 $lres = sqlStatement($query, array($GLOBALS['pid']) );
994 $count = 0;
995 while ($lrow = sqlFetchArray($lres)) {
996 if ($count++) echo "<br />";
997 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
998 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
1002 // a set of labeled checkboxes, each with a text field:
1003 else if ($data_type == 25) {
1004 $tmp = explode('|', $currvalue);
1005 $avalue = array();
1006 foreach ($tmp as $value) {
1007 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1008 $avalue[$matches[1]] = $matches[2];
1011 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1012 $fldlength = empty($fld_length) ? 20 : $fld_length;
1013 $lres = sqlStatement("SELECT * FROM list_options " .
1014 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1015 echo "<table cellpadding='0' cellspacing='0'>";
1016 while ($lrow = sqlFetchArray($lres)) {
1017 $option_id = $lrow['option_id'];
1018 $restype = substr($avalue[$option_id], 0, 1);
1019 $resnote = substr($avalue[$option_id], 2);
1020 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
1021 echo "<td><input type='checkbox'";
1022 if ($restype) echo " checked";
1023 echo " />&nbsp;</td>";
1024 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1025 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1026 echo "<td><input type='text'" .
1027 " size='$fldlength'" .
1028 " value='$resnote'" .
1029 " class='under'" .
1030 " /></td>" .
1031 "</tr>";
1033 echo "</table>";
1036 // a set of labeled radio buttons
1037 else if ($data_type == 27) {
1038 // In this special case, fld_length is the number of columns generated.
1039 $cols = max(1, $frow['fld_length']);
1040 $lres = sqlStatement("SELECT * FROM list_options " .
1041 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1042 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1043 $tdpct = (int) (100 / $cols);
1044 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1045 $option_id = $lrow['option_id'];
1046 if ($count % $cols == 0) {
1047 if ($count) echo "</tr>";
1048 echo "<tr>";
1050 echo "<td width='$tdpct%'>";
1051 echo "<input type='radio'";
1052 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1053 (strlen($currvalue) > 0 && $option_id == $currvalue))
1055 echo " checked";
1057 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1058 echo "</td>";
1060 if ($count) {
1061 echo "</tr>";
1062 if ($count > $cols) {
1063 // Add some space after multiple rows of radio buttons.
1064 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1065 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1068 echo "</table>";
1071 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1072 else if ($data_type == 28 || $data_type == 32) {
1073 $tmp = explode('|', $currvalue);
1074 switch(count($tmp)) {
1075 case "4": {
1076 $resnote = $tmp[0];
1077 $restype = $tmp[1];
1078 $resdate = $tmp[2];
1079 $reslist = $tmp[3];
1080 } break;
1081 case "3": {
1082 $resnote = $tmp[0];
1083 $restype = $tmp[1];
1084 $resdate = $tmp[2];
1085 } break;
1086 case "2": {
1087 $resnote = $tmp[0];
1088 $restype = $tmp[1];
1089 $resdate = "";
1090 } break;
1091 case "1": {
1092 $resnote = $tmp[0];
1093 $resdate = $restype = "";
1094 } break;
1095 default: {
1096 $restype = $resdate = $resnote = "";
1097 } break;
1099 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1100 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1101 echo "<table cellpadding='0' cellspacing='0'>";
1102 echo "<tr>";
1103 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1104 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1105 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1106 if($data_type == 28)
1108 echo "<td><input type='text'" .
1109 " size='$fldlength'" .
1110 " class='under'" .
1111 " value='$resnote' /></td>";
1112 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1113 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
1114 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1116 else if($data_type == 32)
1118 echo "<tr><td><input type='text'" .
1119 " size='$fldlength'" .
1120 " class='under'" .
1121 " value='$resnote' /></td></tr>";
1122 $fldlength = 30;
1123 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1124 echo "<td><input type='text'" .
1125 " size='$fldlength'" .
1126 " class='under'" .
1127 " value='$smoking_status_title' /></td>";
1128 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
1130 echo "<td><input type='radio'";
1131 if ($restype == "current".$field_id) echo " checked";
1132 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1134 echo "<td><input type='radio'";
1135 if ($restype == "current".$field_id) echo " checked";
1136 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1138 echo "<td><input type='text' size='6'" .
1139 " value='$resdate'" .
1140 " class='under'" .
1141 " /></td>";
1143 echo "<td><input type='radio'";
1144 if ($restype == "current".$field_id) echo " checked";
1145 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1147 echo "<td><input type='radio'";
1148 if ($restype == "not_applicable".$field_id) echo " checked";
1149 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1150 echo "</tr>";
1151 echo "</table>";
1154 // static text. read-only, of course.
1155 else if ($data_type == 31) {
1156 echo nl2br($frow['description']);
1161 function generate_display_field($frow, $currvalue) {
1162 $data_type = $frow['data_type'];
1163 $field_id = $frow['field_id'];
1164 $list_id = $frow['list_id'];
1165 $s = '';
1167 // generic selection list or the generic selection list with add on the fly
1168 // feature, or radio buttons
1169 if ($data_type == 1 || $data_type == 26 || $data_type == 27) {
1170 $lrow = sqlQuery("SELECT title FROM list_options " .
1171 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1172 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1175 // simple text field
1176 else if ($data_type == 2) {
1177 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1180 // long or multi-line text field
1181 else if ($data_type == 3) {
1182 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1185 // date
1186 else if ($data_type == 4) {
1187 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES);
1190 // provider
1191 else if ($data_type == 10 || $data_type == 11) {
1192 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1193 "WHERE id = ?", array($currvalue) );
1194 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1197 // pharmacy list
1198 else if ($data_type == 12) {
1199 $pres = get_pharmacies();
1200 while ($prow = sqlFetchArray($pres)) {
1201 $key = $prow['id'];
1202 if ($currvalue == $key) {
1203 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1204 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1205 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1210 // squads
1211 else if ($data_type == 13) {
1212 $squads = acl_get_squads();
1213 if ($squads) {
1214 foreach ($squads as $key => $value) {
1215 if ($currvalue == $key) {
1216 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1222 // address book
1223 else if ($data_type == 14) {
1224 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1225 "WHERE id = ?", array($currvalue));
1226 $uname = $urow['lname'];
1227 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1228 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1231 // billing code
1232 else if ($data_type == 15) {
1233 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1236 // a set of labeled checkboxes
1237 else if ($data_type == 21) {
1238 $avalue = explode('|', $currvalue);
1239 $lres = sqlStatement("SELECT * FROM list_options " .
1240 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1241 $count = 0;
1242 while ($lrow = sqlFetchArray($lres)) {
1243 $option_id = $lrow['option_id'];
1244 if (in_array($option_id, $avalue)) {
1245 if ($count++) $s .= "<br />";
1247 // Added 5-09 by BM - Translate label if applicable
1248 $s .= htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1254 // a set of labeled text input fields
1255 else if ($data_type == 22) {
1256 $tmp = explode('|', $currvalue);
1257 $avalue = array();
1258 foreach ($tmp as $value) {
1259 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1260 $avalue[$matches[1]] = $matches[2];
1263 $lres = sqlStatement("SELECT * FROM list_options " .
1264 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1265 $s .= "<table cellpadding='0' cellspacing='0'>";
1266 while ($lrow = sqlFetchArray($lres)) {
1267 $option_id = $lrow['option_id'];
1268 if (empty($avalue[$option_id])) continue;
1270 // Added 5-09 by BM - Translate label if applicable
1271 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1273 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1275 $s .= "</table>";
1278 // a set of exam results; 3 radio buttons and a text field:
1279 else if ($data_type == 23) {
1280 $tmp = explode('|', $currvalue);
1281 $avalue = array();
1282 foreach ($tmp as $value) {
1283 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1284 $avalue[$matches[1]] = $matches[2];
1287 $lres = sqlStatement("SELECT * FROM list_options " .
1288 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1289 $s .= "<table cellpadding='0' cellspacing='0'>";
1290 while ($lrow = sqlFetchArray($lres)) {
1291 $option_id = $lrow['option_id'];
1292 $restype = substr($avalue[$option_id], 0, 1);
1293 $resnote = substr($avalue[$option_id], 2);
1294 if (empty($restype) && empty($resnote)) continue;
1296 // Added 5-09 by BM - Translate label if applicable
1297 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1299 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1300 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1301 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1302 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1303 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1304 $s .= "</tr>";
1306 $s .= "</table>";
1309 // the list of active allergies for the current patient
1310 else if ($data_type == 24) {
1311 $query = "SELECT title, comments FROM lists WHERE " .
1312 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1313 "ORDER BY begdate";
1314 // echo "<!-- $query -->\n"; // debugging
1315 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1316 $count = 0;
1317 while ($lrow = sqlFetchArray($lres)) {
1318 if ($count++) $s .= "<br />";
1319 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1320 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1324 // a set of labeled checkboxes, each with a text field:
1325 else if ($data_type == 25) {
1326 $tmp = explode('|', $currvalue);
1327 $avalue = array();
1328 foreach ($tmp as $value) {
1329 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1330 $avalue[$matches[1]] = $matches[2];
1333 $lres = sqlStatement("SELECT * FROM list_options " .
1334 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1335 $s .= "<table cellpadding='0' cellspacing='0'>";
1336 while ($lrow = sqlFetchArray($lres)) {
1337 $option_id = $lrow['option_id'];
1338 $restype = substr($avalue[$option_id], 0, 1);
1339 $resnote = substr($avalue[$option_id], 2);
1340 if (empty($restype) && empty($resnote)) continue;
1342 // Added 5-09 by BM - Translate label if applicable
1343 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1345 $restype = $restype ? xl('Yes') : xl('No');
1346 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1347 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1348 $s .= "</tr>";
1350 $s .= "</table>";
1353 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1354 // VicarePlus :: A selection list for smoking status.
1355 else if ($data_type == 28 || $data_type == 32) {
1356 $tmp = explode('|', $currvalue);
1357 switch(count($tmp)) {
1358 case "4": {
1359 $resnote = $tmp[0];
1360 $restype = $tmp[1];
1361 $resdate = $tmp[2];
1362 $reslist = $tmp[3];
1363 } break;
1364 case "3": {
1365 $resnote = $tmp[0];
1366 $restype = $tmp[1];
1367 $resdate = $tmp[2];
1368 } break;
1369 case "2": {
1370 $resnote = $tmp[0];
1371 $restype = $tmp[1];
1372 $resdate = "";
1373 } break;
1374 case "1": {
1375 $resnote = $tmp[0];
1376 $resdate = $restype = "";
1377 } break;
1378 default: {
1379 $restype = $resdate = $resnote = "";
1380 } break;
1382 $s .= "<table cellpadding='0' cellspacing='0'>";
1384 $s .= "<tr>";
1385 $res = "";
1386 if ($restype == "current".$field_id) $res = xl('Current');
1387 if ($restype == "quit".$field_id) $res = xl('Quit');
1388 if ($restype == "never".$field_id) $res = xl('Never');
1389 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1390 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1391 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1392 if ($data_type == 28)
1394 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1396 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1397 else if ($data_type == 32)
1399 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>";
1400 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;</td>";
1403 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1404 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1405 $s .= "</tr>";
1406 $s .= "</table>";
1409 // static text. read-only, of course.
1410 else if ($data_type == 31) {
1411 $s .= nl2br($frow['description']);
1414 return $s;
1417 $CPR = 4; // cells per row of generic data
1418 $last_group = '';
1419 $cell_count = 0;
1420 $item_count = 0;
1422 function disp_end_cell() {
1423 global $item_count, $cell_count;
1424 if ($item_count > 0) {
1425 echo "</td>";
1426 $item_count = 0;
1430 function disp_end_row() {
1431 global $cell_count, $CPR;
1432 disp_end_cell();
1433 if ($cell_count > 0) {
1434 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
1435 echo "</tr>\n";
1436 $cell_count = 0;
1440 function disp_end_group() {
1441 global $last_group;
1442 if (strlen($last_group) > 0) {
1443 disp_end_row();
1447 function display_layout_rows($formtype, $result1, $result2='') {
1448 global $item_count, $cell_count, $last_group, $CPR;
1450 $fres = sqlStatement("SELECT * FROM layout_options " .
1451 "WHERE form_id = ? AND uor > 0 " .
1452 "ORDER BY group_name, seq", array($formtype) );
1454 while ($frow = sqlFetchArray($fres)) {
1455 $this_group = $frow['group_name'];
1456 $titlecols = $frow['titlecols'];
1457 $datacols = $frow['datacols'];
1458 $data_type = $frow['data_type'];
1459 $field_id = $frow['field_id'];
1460 $list_id = $frow['list_id'];
1461 $currvalue = '';
1463 if ($formtype == 'DEM') {
1464 if ($GLOBALS['athletic_team']) {
1465 // Skip fitness level and return-to-play date because those appear
1466 // in a special display/update form on this page.
1467 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1469 if (strpos($field_id, 'em_') === 0) {
1470 // Skip employer related fields, if it's disabled.
1471 if ($GLOBALS['omit_employers']) continue;
1472 $tmp = substr($field_id, 3);
1473 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1475 else {
1476 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1479 else {
1480 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1483 // Handle a data category (group) change.
1484 if (strcmp($this_group, $last_group) != 0) {
1485 $group_name = substr($this_group, 1);
1486 // totally skip generating the employer category, if it's disabled.
1487 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1488 disp_end_group();
1489 $last_group = $this_group;
1492 // Handle starting of a new row.
1493 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1494 disp_end_row();
1495 echo "<tr>";
1496 if ($group_name) {
1497 echo "<td class='groupname'>";
1498 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1499 //echo "<font color='#008800'>$group_name</font>";
1501 // Added 5-09 by BM - Translate label if applicable
1502 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
1504 $group_name = '';
1505 } else {
1506 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1507 echo "<td valign='top'>&nbsp;";
1509 echo "</td>";
1512 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1514 // Handle starting of a new label cell.
1515 if ($titlecols > 0) {
1516 disp_end_cell();
1517 //echo "<td class='label' colspan='$titlecols' valign='top'";
1518 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1519 echo "<td class='label' colspan='$titlecols_esc' ";
1520 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1521 echo ">";
1522 $cell_count += $titlecols;
1524 ++$item_count;
1526 // Added 5-09 by BM - Translate label if applicable
1527 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1529 // Handle starting of a new data cell.
1530 if ($datacols > 0) {
1531 disp_end_cell();
1532 //echo "<td class='text data' colspan='$datacols' valign='top'";
1533 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1534 echo "<td class='text data' colspan='$datacols_esc'";
1535 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1536 echo ">";
1537 $cell_count += $datacols;
1540 ++$item_count;
1541 echo generate_display_field($frow, $currvalue);
1544 disp_end_group();
1547 function display_layout_tabs($formtype, $result1, $result2='') {
1548 global $item_count, $cell_count, $last_group, $CPR;
1550 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1551 "WHERE form_id = ? AND uor > 0 " .
1552 "ORDER BY group_name, seq", array($formtype) );
1554 $first = true;
1555 while ($frow = sqlFetchArray($fres)) {
1556 $this_group = $frow['group_name'];
1557 $group_name = substr($this_group, 1);
1559 <li <?php echo $first ? 'class="current"' : '' ?>>
1560 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES)."?>">
1561 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
1562 </li>
1563 <?php
1564 $first = false;
1568 function display_layout_tabs_data($formtype, $result1, $result2='') {
1569 global $item_count, $cell_count, $last_group, $CPR;
1571 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1572 "WHERE form_id = ? AND uor > 0 " .
1573 "ORDER BY group_name, seq", array($formtype));
1575 $first = true;
1576 while ($frow = sqlFetchArray($fres)) {
1577 $this_group = $frow['group_name'];
1578 $titlecols = $frow['titlecols'];
1579 $datacols = $frow['datacols'];
1580 $data_type = $frow['data_type'];
1581 $field_id = $frow['field_id'];
1582 $list_id = $frow['list_id'];
1583 $currvalue = '';
1585 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1586 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1587 "ORDER BY seq", array($formtype, $this_group) );
1590 <div class="tab <?php echo $first ? 'current' : '' ?>">
1591 <table border='0' cellpadding='0'>
1593 <?php
1594 while ($group_fields = sqlFetchArray($group_fields_query)) {
1596 $titlecols = $group_fields['titlecols'];
1597 $datacols = $group_fields['datacols'];
1598 $data_type = $group_fields['data_type'];
1599 $field_id = $group_fields['field_id'];
1600 $list_id = $group_fields['list_id'];
1601 $currvalue = '';
1603 if ($formtype == 'DEM') {
1604 if ($GLOBALS['athletic_team']) {
1605 // Skip fitness level and return-to-play date because those appear
1606 // in a special display/update form on this page.
1607 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1609 if (strpos($field_id, 'em_') === 0) {
1610 // Skip employer related fields, if it's disabled.
1611 if ($GLOBALS['omit_employers']) continue;
1612 $tmp = substr($field_id, 3);
1613 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1615 else {
1616 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1619 else {
1620 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1623 // Handle a data category (group) change.
1624 if (strcmp($this_group, $last_group) != 0) {
1625 $group_name = substr($this_group, 1);
1626 // totally skip generating the employer category, if it's disabled.
1627 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1628 $last_group = $this_group;
1631 // Handle starting of a new row.
1632 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1633 disp_end_row();
1634 echo "<tr>";
1637 if ($item_count == 0 && $titlecols == 0) {
1638 $titlecols = 1;
1641 // Handle starting of a new label cell.
1642 if ($titlecols > 0) {
1643 disp_end_cell();
1644 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1645 echo "<td class='label' colspan='$titlecols_esc' ";
1646 echo ">";
1647 $cell_count += $titlecols;
1649 ++$item_count;
1651 // Added 5-09 by BM - Translate label if applicable
1652 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1654 // Handle starting of a new data cell.
1655 if ($datacols > 0) {
1656 disp_end_cell();
1657 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1658 echo "<td class='text data' colspan='$datacols_esc'";
1659 echo ">";
1660 $cell_count += $datacols;
1663 ++$item_count;
1664 echo generate_display_field($group_fields, $currvalue);
1668 </table>
1669 </div>
1671 <?php
1673 $first = false;
1679 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1680 global $item_count, $cell_count, $last_group, $CPR;
1682 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1683 "WHERE form_id = ? AND uor > 0 " .
1684 "ORDER BY group_name, seq", array($formtype) );
1686 $first = true;
1687 while ($frow = sqlFetchArray($fres)) {
1688 $this_group = $frow['group_name'];
1689 $group_name = substr($this_group, 1);
1690 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
1691 $titlecols = $frow['titlecols'];
1692 $datacols = $frow['datacols'];
1693 $data_type = $frow['data_type'];
1694 $field_id = $frow['field_id'];
1695 $list_id = $frow['list_id'];
1696 $currvalue = '';
1698 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1699 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1700 "ORDER BY seq", array($formtype,$this_group) );
1703 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name_esc?>" >
1704 <table border='0' cellpadding='0'>
1706 <?php
1707 while ($group_fields = sqlFetchArray($group_fields_query)) {
1709 $titlecols = $group_fields['titlecols'];
1710 $datacols = $group_fields['datacols'];
1711 $data_type = $group_fields['data_type'];
1712 $field_id = $group_fields['field_id'];
1713 $list_id = $group_fields['list_id'];
1714 $currvalue = '';
1716 if ($formtype == 'DEM') {
1717 if ($GLOBALS['athletic_team']) {
1718 // Skip fitness level and return-to-play date because those appear
1719 // in a special display/update form on this page.
1720 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1722 if (strpos($field_id, 'em_') === 0) {
1723 // Skip employer related fields, if it's disabled.
1724 if ($GLOBALS['omit_employers']) continue;
1725 $tmp = substr($field_id, 3);
1726 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1728 else {
1729 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1732 else {
1733 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1736 // Handle a data category (group) change.
1737 if (strcmp($this_group, $last_group) != 0) {
1738 $group_name = substr($this_group, 1);
1739 // totally skip generating the employer category, if it's disabled.
1740 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1741 $last_group = $this_group;
1744 // Handle starting of a new row.
1745 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1746 disp_end_row();
1747 echo "<tr>";
1750 if ($item_count == 0 && $titlecols == 0) {
1751 $titlecols = 1;
1754 // Handle starting of a new label cell.
1755 if ($titlecols > 0) {
1756 disp_end_cell();
1757 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1758 echo "<td class='label' colspan='$titlecols_esc' ";
1759 echo ">";
1760 $cell_count += $titlecols;
1762 ++$item_count;
1764 // Added 5-09 by BM - Translate label if applicable
1765 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
1767 // Handle starting of a new data cell.
1768 if ($datacols > 0) {
1769 disp_end_cell();
1770 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1771 echo "<td class='text data' colspan='$datacols_esc'";
1772 echo ">";
1773 $cell_count += $datacols;
1776 ++$item_count;
1777 echo generate_form_field($group_fields, $currvalue);
1781 </table>
1782 </div>
1784 <?php
1786 $first = false;
1791 // From the currently posted HTML form, this gets the value of the
1792 // field corresponding to the provided layout_options table row.
1794 function get_layout_form_value($frow, $maxlength=255) {
1795 // Bring in $sanitize_all_escapes variable, which will decide
1796 // the variable escaping method.
1797 global $sanitize_all_escapes;
1799 $data_type = $frow['data_type'];
1800 $field_id = $frow['field_id'];
1801 $value = '';
1802 if (isset($_POST["form_$field_id"])) {
1803 if ($data_type == 21) {
1804 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1805 // must be concatenated into a |-separated string.
1806 foreach ($_POST["form_$field_id"] as $key => $val) {
1807 if (strlen($value)) $value .= '|';
1808 $value .= $key;
1811 else if ($data_type == 22) {
1812 // $_POST["form_$field_id"] is an array of text fields to be imploded
1813 // into "key:value|key:value|...".
1814 foreach ($_POST["form_$field_id"] as $key => $val) {
1815 $val = str_replace('|', ' ', $val);
1816 if (strlen($value)) $value .= '|';
1817 $value .= "$key:$val";
1820 else if ($data_type == 23) {
1821 // $_POST["form_$field_id"] is an array of text fields with companion
1822 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1823 foreach ($_POST["form_$field_id"] as $key => $val) {
1824 $restype = $_POST["radio_{$field_id}"][$key];
1825 if (empty($restype)) $restype = '0';
1826 $val = str_replace('|', ' ', $val);
1827 if (strlen($value)) $value .= '|';
1828 $value .= "$key:$restype:$val";
1831 else if ($data_type == 25) {
1832 // $_POST["form_$field_id"] is an array of text fields with companion
1833 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1834 foreach ($_POST["form_$field_id"] as $key => $val) {
1835 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
1836 $val = str_replace('|', ' ', $val);
1837 if (strlen($value)) $value .= '|';
1838 $value .= "$key:$restype:$val";
1841 else if ($data_type == 28 || $data_type == 32) {
1842 // $_POST["form_$field_id"] is an date text fields with companion
1843 // radio buttons to be imploded into "notes|type|date".
1844 $restype = $_POST["radio_{$field_id}"];
1845 if (empty($restype)) $restype = '0';
1846 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1847 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1848 if ($data_type == 32)
1850 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
1851 $reslist = str_replace('|', ' ', $_POST["form_$field_id"]);
1852 $res_text_note = str_replace('|', ' ', $_POST["form_text_$field_id"]);
1853 $value = "$res_text_note|$restype|$resdate|$reslist";
1855 else
1856 $value = "$resnote|$restype|$resdate";
1858 else {
1859 $value = $_POST["form_$field_id"];
1863 // Better to die than to silently truncate data!
1864 if ($maxlength && $data_type != 3 && strlen($value) > $maxlength)
1865 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
1866 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
1868 // Make sure the return value is quote-safe.
1869 if ($sanitize_all_escapes) {
1870 //escapes already removed and using binding/placemarks in sql calls
1871 // so only need to trim value
1872 return trim($value);
1874 else {
1875 //need to explicitly prepare value
1876 return formTrim($value);
1880 // Generate JavaScript validation logic for the required fields.
1882 function generate_layout_validation($form_id) {
1883 $fres = sqlStatement("SELECT * FROM layout_options " .
1884 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
1885 "ORDER BY group_name, seq", array($form_id) );
1887 while ($frow = sqlFetchArray($fres)) {
1888 if ($frow['uor'] < 2) continue;
1889 $data_type = $frow['data_type'];
1890 $field_id = $frow['field_id'];
1891 $fldtitle = $frow['title'];
1892 if (!$fldtitle) $fldtitle = $frow['description'];
1893 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES);
1894 switch($data_type) {
1895 case 1:
1896 case 11:
1897 case 12:
1898 case 13:
1899 case 14:
1900 case 26:
1901 echo
1902 " if (f.$fldname.selectedIndex <= 0) {\n" .
1903 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1904 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1905 " }\n";
1906 break;
1907 case 27: // radio buttons
1908 echo
1909 " var i = 0;\n" .
1910 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
1911 " if (i >= f.$fldname.length) {\n" .
1912 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1913 " }\n";
1914 break;
1915 case 2:
1916 case 3:
1917 case 4:
1918 case 15:
1919 echo
1920 " if (trimlen(f.$fldname.value) == 0) {\n" .
1921 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1922 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
1923 " $('#" . $fldname . "').attr('style','background:red'); \n" .
1924 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1925 " } else { " .
1926 " $('#" . $fldname . "').attr('style',''); " .
1927 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
1928 " } \n";
1929 break;
1935 * DROPDOWN FOR FACILITIES
1937 * build a dropdown with all facilities
1939 * @param string $selected - name of the currently selected facility
1940 * use '0' for "unspecified facility"
1941 * use '' for "All facilities" (the default)
1942 * @param string $name - the name/id for select form (defaults to "form_facility")
1943 * @param boolean $allow_unspecified - include an option for "unspecified" facility
1944 * defaults to true
1945 * @return void - just echo the html encoded string
1947 * Note: This should become a data-type at some point, according to Brady
1949 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true) {
1950 $have_selected = false;
1951 $query = "SELECT id, name FROM facility ORDER BY name";
1952 $fres = sqlStatement($query);
1954 $name = htmlspecialchars($name, ENT_QUOTES);
1955 echo " <select name=\"$name\">\n";
1957 $option_value = '';
1958 $option_selected_attr = '';
1959 if ($selected == '') {
1960 $option_selected_attr = ' selected="selected"';
1961 $have_selected = true;
1963 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
1964 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1966 while ($frow = sqlFetchArray($fres)) {
1967 $facility_id = $frow['id'];
1968 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
1969 $option_selected_attr = '';
1970 if ($selected == $facility_id) {
1971 $option_selected_attr = ' selected="selected"';
1972 $have_selected = true;
1974 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
1975 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1978 if ($allow_unspecified) {
1979 $option_value = '0';
1980 $option_selected_attr = '';
1981 if ( $selected == '0' ) {
1982 $option_selected_attr = ' selected="selected"';
1983 $have_selected = true;
1985 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
1986 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1989 if (!$have_selected) {
1990 $option_value = htmlspecialchars($selected, ENT_QUOTES);
1991 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
1992 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
1993 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
1995 echo " </select>\n";
1998 // Expand Collapse Widget
1999 // This forms the header and functionality component of the widget. The information that is displayed
2000 // then follows this function followed by a closing div tag
2002 // $title is the title of the section (already translated)
2003 // $label is identifier used in the tag id's and sql columns
2004 // $buttonLabel is the button label text (already translated)
2005 // $buttonLink is the button link information
2006 // $buttonClass is any additional needed class elements for the button tag
2007 // $linkMethod is the button link method ('javascript' vs 'html')
2008 // $bodyClass is to set class(es) of the body
2009 // $auth is a flag to decide whether to show the button
2010 // $fixedWidth is to flag whether width is fixed
2011 // $forceExpandAlways is a flag to force the widget to always be expanded
2013 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2014 if ($fixedWidth) {
2015 echo "<div class='section-header'>";
2017 else {
2018 echo "<div class='section-header-dynamic'>";
2020 echo "<table><tr>";
2021 if ($auth) {
2022 // show button, since authorized
2023 // first prepare class string
2024 if ($buttonClass) {
2025 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
2027 else {
2028 $class_string = "css_button_small";
2030 // next, create the link
2031 if ($linkMethod == "javascript") {
2032 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2034 else {
2035 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'" .
2036 " onclick='top.restoreSession()'";
2038 if (!$GLOBALS['concurrent_layout']) {
2039 echo " target='Main'";
2041 echo "><span>" .
2042 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
2044 if ($forceExpandAlways){
2045 // Special case to force the widget to always be expanded
2046 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2047 $indicatorTag ="style='display:none'";
2049 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2050 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
2051 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
2052 if (getUserSetting($label."_ps_expand")) {
2053 $text = xl('collapse');
2055 else {
2056 $text = xl('expand');
2058 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
2059 "</span>)</a></td>";
2060 echo "</tr></table>";
2061 echo "</div>";
2062 if ($forceExpandAlways) {
2063 // Special case to force the widget to always be expanded
2064 $styling = "";
2066 else if (getUserSetting($label."_ps_expand")) {
2067 $styling = "";
2069 else {
2070 $styling = "style='display:none'";
2072 if ($bodyClass) {
2073 $styling .= " class='" . $bodyClass . "'";
2075 //next, create the first div tag to hold the information
2076 // note the code that calls this function will then place the ending div tag after the data
2077 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";