Merge branch 'master' of git://github.com/openemr/openemr
[openemr.git] / library / options.inc.php
blob6b607737e0c25f477f49b6ee5662d9faf86081c4
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 // 1 = Write Once (not editable when not empty) (text fields)
30 require_once("formdata.inc.php");
31 require_once("formatting.inc.php");
32 require_once("user.inc");
34 $date_init = "";
36 function get_pharmacies() {
37 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
38 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
39 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
40 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
41 "AND p.type = 2 " .
42 "ORDER BY name, area_code, prefix, number");
45 // Function to generate a drop-list.
47 function generate_select_list($tag_name, $list_id, $currvalue, $title,
48 $empty_name=' ', $class='', $onchange='')
50 $s = '';
51 $tag_name_esc = htmlspecialchars( $tag_name, ENT_QUOTES);
52 $s .= "<select name='$tag_name_esc' id='$tag_name_esc'";
53 if ($class) $s .= " class='$class'";
54 if ($onchange) $s .= " onchange='$onchange'";
55 $selectTitle = htmlspecialchars( $title, ENT_QUOTES);
56 $s .= " title='$selectTitle'>";
57 $selectEmptyName = htmlspecialchars( xl($empty_name), ENT_NOQUOTES);
58 if ($empty_name) $s .= "<option value=''>" . $selectEmptyName . "</option>";
59 $lres = sqlStatement("SELECT * FROM list_options " .
60 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
61 $got_selected = FALSE;
62 while ($lrow = sqlFetchArray($lres)) {
63 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
64 $s .= "<option value='$optionValue'";
65 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
66 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
68 $s .= " selected";
69 $got_selected = TRUE;
71 $optionLabel = htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
72 $s .= ">$optionLabel</option>\n";
74 if (!$got_selected && strlen($currvalue) > 0) {
75 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
76 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
77 $s .= "</select>";
78 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_QUOTES);
79 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
80 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
82 else {
83 $s .= "</select>";
85 return $s;
88 // $frow is a row from the layout_options table.
89 // $currvalue is the current value, if any, of the associated item.
91 function generate_form_field($frow, $currvalue) {
92 global $rootdir, $date_init;
94 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
96 $data_type = $frow['data_type'];
97 $field_id = $frow['field_id'];
98 $list_id = $frow['list_id'];
99 // escaped variables to use in html
100 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
101 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
103 // Added 5-09 by BM - Translate description if applicable
104 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
106 // added 5-2009 by BM to allow modification of the 'empty' text title field.
107 // Can pass $frow['empty_title'] with this variable, otherwise
108 // will default to 'Unassigned'.
109 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
110 // if make $frow['empty_title'] equal to 'SKIP'
111 $showEmpty = true;
112 if (isset($frow['empty_title'])) {
113 if ($frow['empty_title'] == "SKIP") {
114 //do not display an 'empty' choice
115 $showEmpty = false;
116 $empty_title = "Unassigned";
118 else {
119 $empty_title = $frow['empty_title'];
122 else {
123 $empty_title = "Unassigned";
126 // generic single-selection list
127 if ($data_type == 1) {
128 echo generate_select_list("form_$field_id", $list_id, $currvalue,
129 $description, $showEmpty ? $empty_title : '');
132 // simple text field
133 else if ($data_type == 2) {
134 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
135 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
136 echo "<input type='text'" .
137 " name='form_$field_id_esc'" .
138 " id='form_$field_id_esc'" .
139 " size='$fldlength'" .
140 " maxlength='$maxlength'" .
141 " title='$description'" .
142 " value='$currescaped'";
143 if (strpos($frow['edit_options'], 'C') !== FALSE)
144 echo " onchange='capitalizeMe(this)'";
145 else if (strpos($frow['edit_options'], 'U') !== FALSE)
146 echo " onchange='this.value = this.value.toUpperCase()'";
147 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
148 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
149 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
150 echo " onblur='maskblur(this,\"$tmp\")'";
152 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0)
153 echo " readonly";
154 echo " />";
157 // long or multi-line text field
158 else if ($data_type == 3) {
159 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
160 $textRows = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
161 echo "<textarea" .
162 " name='form_$field_id_esc'" .
163 " id='form_$field_id_esc'" .
164 " title='$description'" .
165 " cols='$textCols'" .
166 " rows='$textRows'>" .
167 $currescaped . "</textarea>";
170 // date
171 else if ($data_type == 4) {
172 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
173 " value='$currescaped'" .
174 " title='$description'" .
175 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
176 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
177 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
178 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
179 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
182 // provider list, local providers only
183 else if ($data_type == 10) {
184 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
185 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
186 "AND authorized = 1 " .
187 "ORDER BY lname, fname");
188 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
189 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
190 while ($urow = sqlFetchArray($ures)) {
191 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
192 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
193 echo "<option value='$optionId'";
194 if ($urow['id'] == $currvalue) echo " selected";
195 echo ">$uname</option>";
197 echo "</select>";
200 // provider list, including address book entries with an NPI number
201 else if ($data_type == 11) {
202 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
203 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
204 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
205 "ORDER BY lname, fname");
206 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
207 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
208 while ($urow = sqlFetchArray($ures)) {
209 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES);
210 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES);
211 echo "<option value='$optionId'";
212 if ($urow['id'] == $currvalue) echo " selected";
213 echo ">$uname</option>";
215 echo "</select>";
218 // pharmacy list
219 else if ($data_type == 12) {
220 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
221 echo "<option value='0'></option>";
222 $pres = get_pharmacies();
223 while ($prow = sqlFetchArray($pres)) {
224 $key = $prow['id'];
225 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
226 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
227 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
228 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
229 echo "<option value='$optionValue'";
230 if ($currvalue == $key) echo " selected";
231 echo ">$optionLabel</option>";
233 echo "</select>";
236 // squads
237 else if ($data_type == 13) {
238 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
239 echo "<option value=''>&nbsp;</option>";
240 $squads = acl_get_squads();
241 if ($squads) {
242 foreach ($squads as $key => $value) {
243 $optionValue = htmlspecialchars( $key, ENT_QUOTES);
244 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
245 echo "<option value='$optionValue'";
246 if ($currvalue == $key) echo " selected";
247 echo ">$optionLabel</option>\n";
250 echo "</select>";
253 // Address book, preferring organization name if it exists and is not in
254 // parentheses, and excluding local users who are not providers.
255 // Supports "referred to" practitioners and facilities.
256 // Alternatively the letter O in edit_options means that abook_type
257 // must begin with "ord_", indicating types used with the procedure
258 // ordering system.
259 // Alternatively the letter V in edit_options means that abook_type
260 // must be "vendor", indicating the Vendor type.
261 else if ($data_type == 14) {
262 if (strpos($frow['edit_options'], 'O') !== FALSE)
263 $tmp = "abook_type LIKE 'ord\\_%'";
264 else if (strpos($frow['edit_options'], 'V') !== FALSE)
265 $tmp = "abook_type LIKE 'vendor%'";
266 else
267 $tmp = "( username = '' OR authorized = 1 )";
268 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
269 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
270 "AND $tmp " .
271 "ORDER BY organization, lname, fname");
272 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
273 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
274 while ($urow = sqlFetchArray($ures)) {
275 $uname = $urow['organization'];
276 if (empty($uname) || substr($uname, 0, 1) == '(') {
277 $uname = $urow['lname'];
278 if ($urow['fname']) $uname .= ", " . $urow['fname'];
280 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
281 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
282 echo "<option value='$optionValue'";
283 $title = $urow['username'] ? xl('Local') : xl('External');
284 $optionTitle = htmlspecialchars( $title, ENT_QUOTES);
285 echo " title='$optionTitle'";
286 if ($urow['id'] == $currvalue) echo " selected";
287 echo ">$optionLabel</option>";
289 echo "</select>";
292 // a billing code
293 else if ($data_type == 15) {
294 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
295 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
296 echo "<input type='text'" .
297 " name='form_$field_id_esc'" .
298 " id='form_related_code'" .
299 " size='$fldlength'" .
300 " maxlength='$maxlength'" .
301 " title='$description'" .
302 " value='$currescaped'" .
303 " onclick='sel_related(this)' readonly" .
304 " />";
307 // a set of labeled checkboxes
308 else if ($data_type == 21) {
309 // In this special case, fld_length is the number of columns generated.
310 $cols = max(1, $frow['fld_length']);
311 $avalue = explode('|', $currvalue);
312 $lres = sqlStatement("SELECT * FROM list_options " .
313 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
314 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
315 $tdpct = (int) (100 / $cols);
316 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
317 $option_id = $lrow['option_id'];
318 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
319 // if ($count) echo "<br />";
320 if ($count % $cols == 0) {
321 if ($count) echo "</tr>";
322 echo "<tr>";
324 echo "<td width='$tdpct%'>";
325 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]' id='form_{$field_id_esc}[$option_id_esc]' value='1'";
326 if (in_array($option_id, $avalue)) echo " checked";
328 // Added 5-09 by BM - Translate label if applicable
329 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
331 echo "</td>";
333 if ($count) {
334 echo "</tr>";
335 if ($count > $cols) {
336 // Add some space after multiple rows of checkboxes.
337 $cols = htmlspecialchars( $cols, ENT_QUOTES);
338 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
341 echo "</table>";
344 // a set of labeled text input fields
345 else if ($data_type == 22) {
346 $tmp = explode('|', $currvalue);
347 $avalue = array();
348 foreach ($tmp as $value) {
349 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
350 $avalue[$matches[1]] = $matches[2];
353 $lres = sqlStatement("SELECT * FROM list_options " .
354 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
355 echo "<table cellpadding='0' cellspacing='0'>";
356 while ($lrow = sqlFetchArray($lres)) {
357 $option_id = $lrow['option_id'];
358 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
359 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
360 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
362 // Added 5-09 by BM - Translate label if applicable
363 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
364 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
365 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
366 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
367 echo "<td><input type='text'" .
368 " name='form_{$field_id_esc}[$option_id_esc]'" .
369 " id='form_{$field_id_esc}[$option_id_esc]'" .
370 " size='$fldlength'" .
371 " maxlength='$maxlength'" .
372 " value='$optionValue'";
373 echo " /></td></tr>";
375 echo "</table>";
378 // a set of exam results; 3 radio buttons and a text field:
379 else if ($data_type == 23) {
380 $tmp = explode('|', $currvalue);
381 $avalue = array();
382 foreach ($tmp as $value) {
383 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
384 $avalue[$matches[1]] = $matches[2];
387 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
388 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
389 $lres = sqlStatement("SELECT * FROM list_options " .
390 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
391 echo "<table cellpadding='0' cellspacing='0'>";
392 echo "<tr><td>&nbsp;</td><td class='bold'>" .
393 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
394 "&nbsp;</td><td class='bold'>" .
395 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
396 "<td class='bold'>" .
397 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
398 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
399 while ($lrow = sqlFetchArray($lres)) {
400 $option_id = $lrow['option_id'];
401 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
402 $restype = substr($avalue[$option_id], 0, 1);
403 $resnote = substr($avalue[$option_id], 2);
405 // Added 5-09 by BM - Translate label if applicable
406 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
408 for ($i = 0; $i < 3; ++$i) {
409 $inputValue = htmlspecialchars( $i, ENT_QUOTES);
410 echo "<td><input type='radio'" .
411 " name='radio_{$field_id_esc}[$option_id_esc]'" .
412 " id='radio_{$field_id_esc}[$option_id_esc]'" .
413 " value='$inputValue'";
414 if ($restype === "$i") echo " checked";
415 echo " /></td>";
417 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
418 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
419 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
420 echo "<td><input type='text'" .
421 " name='form_{$field_id_esc}[$option_id_esc]'" .
422 " id='form_{$field_id_esc}[$option_id_esc]'" .
423 " size='$fldlength'" .
424 " maxlength='$maxlength'" .
425 " value='$resnote' /></td>";
426 echo "</tr>";
428 echo "</table>";
431 // the list of active allergies for the current patient
432 // this is read-only!
433 else if ($data_type == 24) {
434 $query = "SELECT title, comments FROM lists WHERE " .
435 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
436 "ORDER BY begdate";
437 // echo "<!-- $query -->\n"; // debugging
438 $lres = sqlStatement($query, array($GLOBALS['pid']));
439 $count = 0;
440 while ($lrow = sqlFetchArray($lres)) {
441 if ($count++) echo "<br />";
442 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
443 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
447 // a set of labeled checkboxes, each with a text field:
448 else if ($data_type == 25) {
449 $tmp = explode('|', $currvalue);
450 $avalue = array();
451 foreach ($tmp as $value) {
452 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
453 $avalue[$matches[1]] = $matches[2];
456 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
457 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
458 $lres = sqlStatement("SELECT * FROM list_options " .
459 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
460 echo "<table cellpadding='0' cellspacing='0'>";
461 while ($lrow = sqlFetchArray($lres)) {
462 $option_id = $lrow['option_id'];
463 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
464 $restype = substr($avalue[$option_id], 0, 1);
465 $resnote = substr($avalue[$option_id], 2);
467 // Added 5-09 by BM - Translate label if applicable
468 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
470 $option_id = htmlspecialchars( $option_id, ENT_QUOTES);
471 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]' id='check_{$field_id_esc}[$option_id_esc]' value='1'";
472 if ($restype) echo " checked";
473 echo " />&nbsp;</td>";
474 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
475 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
476 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
477 echo "<td><input type='text'" .
478 " name='form_{$field_id_esc}[$option_id_esc]'" .
479 " id='form_{$field_id_esc}[$option_id_esc]'" .
480 " size='$fldlength'" .
481 " maxlength='$maxlength'" .
482 " value='$resnote' /></td>";
483 echo "</tr>";
485 echo "</table>";
488 // single-selection list with ability to add to it
489 else if ($data_type == 26) {
490 echo "<select class='addtolistclass_$list_id_esc' name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
491 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES) . "</option>";
492 $lres = sqlStatement("SELECT * FROM list_options " .
493 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
494 $got_selected = FALSE;
495 while ($lrow = sqlFetchArray($lres)) {
496 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES);
497 echo "<option value='$optionValue'";
498 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
499 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
501 echo " selected";
502 $got_selected = TRUE;
504 // Added 5-09 by BM - Translate label if applicable
505 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n";
507 if (!$got_selected && strlen($currvalue) > 0) {
508 echo "<option value='$currescaped' selected>* $currescaped *</option>";
509 echo "</select>";
510 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES);
511 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
512 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
514 else {
515 echo "</select>";
517 // show the add button if user has access to correct list
518 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
519 $outputAddButton = "<input type='button' id='addtolistid_".$list_id_esc."' fieldid='form_".$field_id_esc."' class='addtolist' value='$inputValue'>";
520 if (aco_exist('lists', $list_id)) {
521 // a specific aco exist for this list, so ensure access
522 if (acl_check('lists', $list_id)) echo $outputAddButton;
524 else {
525 // no specific aco exist for this list, so check for access to 'default' list
526 if (acl_check('lists', 'default')) echo $outputAddButton;
530 // a set of labeled radio buttons
531 else if ($data_type == 27) {
532 // In this special case, fld_length is the number of columns generated.
533 $cols = max(1, $frow['fld_length']);
534 $lres = sqlStatement("SELECT * FROM list_options " .
535 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
536 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
537 $tdpct = (int) (100 / $cols);
538 $got_selected = FALSE;
539 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
540 $option_id = $lrow['option_id'];
541 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
542 if ($count % $cols == 0) {
543 if ($count) echo "</tr>";
544 echo "<tr>";
546 echo "<td width='$tdpct%'>";
547 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]' value='$option_id_esc'";
548 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
549 (strlen($currvalue) > 0 && $option_id == $currvalue))
551 echo " checked";
552 $got_selected = TRUE;
554 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
555 echo "</td>";
557 if ($count) {
558 echo "</tr>";
559 if ($count > $cols) {
560 // Add some space after multiple rows of radio buttons.
561 $cols = htmlspecialchars( $cols, ENT_QUOTES);
562 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
565 echo "</table>";
566 if (!$got_selected && strlen($currvalue) > 0) {
567 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
568 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
569 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
573 // special case for history of lifestyle status; 3 radio buttons and a date text field:
574 else if ($data_type == 28) {
575 $tmp = explode('|', $currvalue);
576 switch(count($tmp)) {
577 case "3": {
578 $resnote = $tmp[0];
579 $restype = $tmp[1];
580 $resdate = $tmp[2];
581 } break;
582 case "2": {
583 $resnote = $tmp[0];
584 $restype = $tmp[1];
585 $resdate = "";
586 } break;
587 case "1": {
588 $resnote = $tmp[0];
589 $resdate = $restype = "";
590 } break;
591 default: {
592 $restype = $resdate = $resnote = "";
593 } break;
595 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
596 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
598 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
599 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES);
600 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
601 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
602 echo "<table cellpadding='0' cellspacing='0'>";
603 echo "<tr>";
604 // input text
605 echo "<td><input type='text'" .
606 " name='form_$field_id_esc'" .
607 " id='form_$field_id_esc'" .
608 " size='$fldlength'" .
609 " maxlength='$maxlength'" .
610 " value='$resnote' />&nbsp;</td>";
611 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;".htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
612 // current
613 echo "<td><input type='radio'" .
614 " name='radio_{$field_id_esc}'" .
615 " id='radio_{$field_id_esc}[current]'" .
616 " value='current".$field_id_esc."'";
617 if ($restype == "current".$field_id) echo " checked";
618 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
619 // quit
620 echo "<td><input type='radio'" .
621 " name='radio_{$field_id_esc}'" .
622 " id='radio_{$field_id_esc}[quit]'" .
623 " value='quit".$field_id_esc."'";
624 if ($restype == "quit".$field_id) echo " checked";
625 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
626 // quit date
627 echo "<td><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
628 " value='$resdate'" .
629 " title='$description'" .
630 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
631 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
632 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
633 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />&nbsp;</td>";
634 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
635 // never
636 echo "<td><input type='radio'" .
637 " name='radio_{$field_id_esc}'" .
638 " id='radio_{$field_id_esc}[never]'" .
639 " value='never".$field_id_esc."'";
640 if ($restype == "never".$field_id) echo " checked";
641 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."&nbsp;</td>";
642 // Not Applicable
643 echo "<td><input type='radio'" .
644 " name='radio_{$field_id}'" .
645 " id='radio_{$field_id}[not_applicable]'" .
646 " value='not_applicable".$field_id."'";
647 if ($restype == "not_applicable".$field_id) echo " checked";
648 echo " />".htmlspecialchars( xl('N/A'), ENT_QUOTES)."&nbsp;</td>";
649 echo "</tr>";
650 echo "</table>";
653 // static text. read-only, of course.
654 else if ($data_type == 31) {
655 echo nl2br($frow['description']);
660 function generate_print_field($frow, $currvalue) {
661 global $rootdir, $date_init;
663 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
665 $data_type = $frow['data_type'];
666 $field_id = $frow['field_id'];
667 $list_id = $frow['list_id'];
668 $fld_length = $frow['fld_length'];
670 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES);
672 // Can pass $frow['empty_title'] with this variable, otherwise
673 // will default to 'Unassigned'.
674 // If it is 'SKIP' then an empty text title is completely skipped.
675 $showEmpty = true;
676 if (isset($frow['empty_title'])) {
677 if ($frow['empty_title'] == "SKIP") {
678 //do not display an 'empty' choice
679 $showEmpty = false;
680 $empty_title = "Unassigned";
682 else {
683 $empty_title = $frow['empty_title'];
686 else {
687 $empty_title = "Unassigned";
690 // generic single-selection list
691 if ($data_type == 1 || $data_type == 26) {
692 if (empty($fld_length)) {
693 if ($list_id == 'titles') {
694 $fld_length = 3;
695 } else {
696 $fld_length = 10;
699 $tmp = '';
700 if ($currvalue) {
701 $lrow = sqlQuery("SELECT title FROM list_options " .
702 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
703 $tmp = xl_list_label($lrow['title']);
704 if (empty($tmp)) $tmp = "($currvalue)";
706 /*****************************************************************
707 echo "<input type='text'" .
708 " size='$fld_length'" .
709 " value='$tmp'" .
710 " class='under'" .
711 " />";
712 *****************************************************************/
713 if ($tmp === '') { $tmp = '&nbsp;'; }
714 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
715 echo $tmp;
718 // simple text field
719 else if ($data_type == 2 || $data_type == 15) {
720 /*****************************************************************
721 echo "<input type='text'" .
722 " size='$fld_length'" .
723 " value='$currescaped'" .
724 " class='under'" .
725 " />";
726 *****************************************************************/
727 if ($currescaped === '') $currescaped = '&nbsp;';
728 echo $currescaped;
731 // long or multi-line text field
732 else if ($data_type == 3) {
733 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES);
734 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES);
735 echo "<textarea" .
736 " cols='$fldlength'" .
737 " rows='$maxlength'>" .
738 $currescaped . "</textarea>";
741 // date
742 else if ($data_type == 4) {
743 /*****************************************************************
744 echo "<input type='text' size='10'" .
745 " value='$currescaped'" .
746 " title='$description'" .
747 " class='under'" .
748 " />";
749 *****************************************************************/
750 if ($currvalue === '') { $tmp = oeFormatShortDate('&nbsp;'); }
751 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES); }
752 echo $tmp;
755 // provider list
756 else if ($data_type == 10 || $data_type == 11) {
757 $tmp = '';
758 if ($currvalue) {
759 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
760 "WHERE id = ?", array($currvalue) );
761 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
762 if (empty($tmp)) $tmp = "($currvalue)";
764 /*****************************************************************
765 echo "<input type='text'" .
766 " size='$fld_length'" .
767 " value='$tmp'" .
768 " class='under'" .
769 " />";
770 *****************************************************************/
771 if ($tmp === '') { $tmp = '&nbsp;'; }
772 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
773 echo $tmp;
776 // pharmacy list
777 else if ($data_type == 12) {
778 $tmp = '';
779 if ($currvalue) {
780 $pres = get_pharmacies();
781 while ($prow = sqlFetchArray($pres)) {
782 $key = $prow['id'];
783 if ($currvalue == $key) {
784 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
785 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
786 $prow['line1'] . ' / ' . $prow['city'];
789 if (empty($tmp)) $tmp = "($currvalue)";
791 /*****************************************************************
792 echo "<input type='text'" .
793 " size='$fld_length'" .
794 " value='$tmp'" .
795 " class='under'" .
796 " />";
797 *****************************************************************/
798 if ($tmp === '') { $tmp = '&nbsp;'; }
799 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
800 echo $tmp;
803 // squads
804 else if ($data_type == 13) {
805 $tmp = '';
806 if ($currvalue) {
807 $squads = acl_get_squads();
808 if ($squads) {
809 foreach ($squads as $key => $value) {
810 if ($currvalue == $key) {
811 $tmp = $value[3];
815 if (empty($tmp)) $tmp = "($currvalue)";
817 /*****************************************************************
818 echo "<input type='text'" .
819 " size='$fld_length'" .
820 " value='$tmp'" .
821 " class='under'" .
822 " />";
823 *****************************************************************/
824 if ($tmp === '') { $tmp = '&nbsp;'; }
825 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
826 echo $tmp;
829 // Address book.
830 else if ($data_type == 14) {
831 $tmp = '';
832 if ($currvalue) {
833 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
834 "WHERE id = ?", array($currvalue) );
835 $uname = $urow['lname'];
836 if ($urow['fname']) $uname .= ", " . $urow['fname'];
837 $tmp = $uname;
838 if (empty($tmp)) $tmp = "($currvalue)";
840 /*****************************************************************
841 echo "<input type='text'" .
842 " size='$fld_length'" .
843 " value='$tmp'" .
844 " class='under'" .
845 " />";
846 *****************************************************************/
847 if ($tmp === '') { $tmp = '&nbsp;'; }
848 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES); }
849 echo $tmp;
852 // a set of labeled checkboxes
853 else if ($data_type == 21) {
854 // In this special case, fld_length is the number of columns generated.
855 $cols = max(1, $fld_length);
856 $avalue = explode('|', $currvalue);
857 $lres = sqlStatement("SELECT * FROM list_options " .
858 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
859 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
860 $tdpct = (int) (100 / $cols);
861 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
862 $option_id = $lrow['option_id'];
863 if ($count % $cols == 0) {
864 if ($count) echo "</tr>";
865 echo "<tr>";
867 echo "<td width='$tdpct%'>";
868 echo "<input type='checkbox'";
869 if (in_array($option_id, $avalue)) echo " checked";
870 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
871 echo "</td>";
873 if ($count) {
874 echo "</tr>";
875 if ($count > $cols) {
876 // Add some space after multiple rows of checkboxes.
877 $cols = htmlspecialchars( $cols, ENT_QUOTES);
878 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
881 echo "</table>";
884 // a set of labeled text input fields
885 else if ($data_type == 22) {
886 $tmp = explode('|', $currvalue);
887 $avalue = array();
888 foreach ($tmp as $value) {
889 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
890 $avalue[$matches[1]] = $matches[2];
893 $lres = sqlStatement("SELECT * FROM list_options " .
894 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
895 echo "<table cellpadding='0' cellspacing='0'>";
896 while ($lrow = sqlFetchArray($lres)) {
897 $option_id = $lrow['option_id'];
898 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
899 $fldlength = empty($fld_length) ? 20 : $fld_length;
900 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
901 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
902 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
903 echo "<td><input type='text'" .
904 " size='$fldlength'" .
905 " value='$inputValue'" .
906 " class='under'" .
907 " /></td></tr>";
909 echo "</table>";
912 // a set of exam results; 3 radio buttons and a text field:
913 else if ($data_type == 23) {
914 $tmp = explode('|', $currvalue);
915 $avalue = array();
916 foreach ($tmp as $value) {
917 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
918 $avalue[$matches[1]] = $matches[2];
921 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
922 $fldlength = empty($fld_length) ? 20 : $fld_length;
923 $lres = sqlStatement("SELECT * FROM list_options " .
924 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
925 echo "<table cellpadding='0' cellspacing='0'>";
926 echo "<tr><td>&nbsp;</td><td class='bold'>" .
927 htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
928 "&nbsp;</td><td class='bold'>" .
929 htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
930 "<td class='bold'>" .
931 htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" .
932 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
933 while ($lrow = sqlFetchArray($lres)) {
934 $option_id = $lrow['option_id'];
935 $restype = substr($avalue[$option_id], 0, 1);
936 $resnote = substr($avalue[$option_id], 2);
937 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
938 for ($i = 0; $i < 3; ++$i) {
939 echo "<td><input type='radio'";
940 if ($restype === "$i") echo " checked";
941 echo " /></td>";
943 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
944 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
945 echo "<td><input type='text'" .
946 " size='$fldlength'" .
947 " value='$resnote'" .
948 " class='under' /></td>" .
949 "</tr>";
951 echo "</table>";
954 // the list of active allergies for the current patient
955 // this is read-only!
956 else if ($data_type == 24) {
957 $query = "SELECT title, comments FROM lists WHERE " .
958 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
959 "ORDER BY begdate";
960 $lres = sqlStatement($query, array($GLOBALS['pid']) );
961 $count = 0;
962 while ($lrow = sqlFetchArray($lres)) {
963 if ($count++) echo "<br />";
964 echo htmlspecialchars( $lrow['title'], ENT_QUOTES);
965 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES);
969 // a set of labeled checkboxes, each with a text field:
970 else if ($data_type == 25) {
971 $tmp = explode('|', $currvalue);
972 $avalue = array();
973 foreach ($tmp as $value) {
974 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
975 $avalue[$matches[1]] = $matches[2];
978 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
979 $fldlength = empty($fld_length) ? 20 : $fld_length;
980 $lres = sqlStatement("SELECT * FROM list_options " .
981 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
982 echo "<table cellpadding='0' cellspacing='0'>";
983 while ($lrow = sqlFetchArray($lres)) {
984 $option_id = $lrow['option_id'];
985 $restype = substr($avalue[$option_id], 0, 1);
986 $resnote = substr($avalue[$option_id], 2);
987 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . "&nbsp;</td>";
988 echo "<td><input type='checkbox'";
989 if ($restype) echo " checked";
990 echo " />&nbsp;</td>";
991 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
992 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
993 echo "<td><input type='text'" .
994 " size='$fldlength'" .
995 " value='$resnote'" .
996 " class='under'" .
997 " /></td>" .
998 "</tr>";
1000 echo "</table>";
1003 // a set of labeled radio buttons
1004 else if ($data_type == 27) {
1005 // In this special case, fld_length is the number of columns generated.
1006 $cols = max(1, $frow['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' width='100%'>";
1010 $tdpct = (int) (100 / $cols);
1011 for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
1012 $option_id = $lrow['option_id'];
1013 if ($count % $cols == 0) {
1014 if ($count) echo "</tr>";
1015 echo "<tr>";
1017 echo "<td width='$tdpct%'>";
1018 echo "<input type='radio'";
1019 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1020 (strlen($currvalue) > 0 && $option_id == $currvalue))
1022 echo " checked";
1024 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
1025 echo "</td>";
1027 if ($count) {
1028 echo "</tr>";
1029 if ($count > $cols) {
1030 // Add some space after multiple rows of radio buttons.
1031 $cols = htmlspecialchars( $cols, ENT_QUOTES);
1032 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1035 echo "</table>";
1038 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1039 else if ($data_type == 28) {
1040 $tmp = explode('|', $currvalue);
1041 switch(count($tmp)) {
1042 case "3": {
1043 $resnote = $tmp[0];
1044 $restype = $tmp[1];
1045 $resdate = $tmp[2];
1046 } break;
1047 case "2": {
1048 $resnote = $tmp[0];
1049 $restype = $tmp[1];
1050 $resdate = "";
1051 } break;
1052 case "1": {
1053 $resnote = $tmp[0];
1054 $resdate = $restype = "";
1055 } break;
1056 default: {
1057 $restype = $resdate = $resnote = "";
1058 } break;
1060 $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length'];
1061 $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
1062 echo "<table cellpadding='0' cellspacing='0'>";
1063 echo "<tr>";
1064 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
1065 $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
1066 $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
1067 echo "<td><input type='text'" .
1068 " size='$fldlength'" .
1069 " class='under'" .
1070 " value='$resnote' /></td>";
1071 echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;".
1072 htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;</td>";
1073 echo "<td><input type='radio'";
1074 if ($restype == "current".$field_id) echo " checked";
1075 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES)."&nbsp;</td>";
1077 echo "<td><input type='radio'";
1078 if ($restype == "current".$field_id) echo " checked";
1079 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES)."&nbsp;</td>";
1081 echo "<td><input type='text' size='6'" .
1082 " value='$resdate'" .
1083 " class='under'" .
1084 " /></td>";
1086 echo "<td><input type='radio'";
1087 if ($restype == "current".$field_id) echo " checked";
1088 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES)."</td>";
1090 echo "<td><input type='radio'";
1091 if ($restype == "not_applicable".$field_id) echo " checked";
1092 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES)."&nbsp;</td>";
1093 echo "</tr>";
1094 echo "</table>";
1097 // static text. read-only, of course.
1098 else if ($data_type == 31) {
1099 echo nl2br($frow['description']);
1104 function generate_display_field($frow, $currvalue) {
1105 $data_type = $frow['data_type'];
1106 $field_id = $frow['field_id'];
1107 $list_id = $frow['list_id'];
1108 $s = '';
1110 // generic selection list or the generic selection list with add on the fly
1111 // feature, or radio buttons
1112 if ($data_type == 1 || $data_type == 26 || $data_type == 27) {
1113 $lrow = sqlQuery("SELECT title FROM list_options " .
1114 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1115 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1118 // simple text field
1119 else if ($data_type == 2) {
1120 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1123 // long or multi-line text field
1124 else if ($data_type == 3) {
1125 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES));
1128 // date
1129 else if ($data_type == 4) {
1130 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES);
1133 // provider
1134 else if ($data_type == 10 || $data_type == 11) {
1135 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1136 "WHERE id = ?", array($currvalue) );
1137 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES);
1140 // pharmacy list
1141 else if ($data_type == 12) {
1142 $pres = get_pharmacies();
1143 while ($prow = sqlFetchArray($pres)) {
1144 $key = $prow['id'];
1145 if ($currvalue == $key) {
1146 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1147 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1148 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES);
1153 // squads
1154 else if ($data_type == 13) {
1155 $squads = acl_get_squads();
1156 if ($squads) {
1157 foreach ($squads as $key => $value) {
1158 if ($currvalue == $key) {
1159 $s .= htmlspecialchars($value[3],ENT_NOQUOTES);
1165 // address book
1166 else if ($data_type == 14) {
1167 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1168 "WHERE id = ?", array($currvalue));
1169 $uname = $urow['lname'];
1170 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1171 $s = htmlspecialchars($uname,ENT_NOQUOTES);
1174 // billing code
1175 else if ($data_type == 15) {
1176 $s = htmlspecialchars($currvalue,ENT_NOQUOTES);
1179 // a set of labeled checkboxes
1180 else if ($data_type == 21) {
1181 $avalue = explode('|', $currvalue);
1182 $lres = sqlStatement("SELECT * FROM list_options " .
1183 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1184 $count = 0;
1185 while ($lrow = sqlFetchArray($lres)) {
1186 $option_id = $lrow['option_id'];
1187 if (in_array($option_id, $avalue)) {
1188 if ($count++) $s .= "<br />";
1190 // Added 5-09 by BM - Translate label if applicable
1191 $s .= htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES);
1197 // a set of labeled text input fields
1198 else if ($data_type == 22) {
1199 $tmp = explode('|', $currvalue);
1200 $avalue = array();
1201 foreach ($tmp as $value) {
1202 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1203 $avalue[$matches[1]] = $matches[2];
1206 $lres = sqlStatement("SELECT * FROM list_options " .
1207 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1208 $s .= "<table cellpadding='0' cellspacing='0'>";
1209 while ($lrow = sqlFetchArray($lres)) {
1210 $option_id = $lrow['option_id'];
1211 if (empty($avalue[$option_id])) continue;
1213 // Added 5-09 by BM - Translate label if applicable
1214 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . ":&nbsp;</td>";
1216 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES) . "</td></tr>";
1218 $s .= "</table>";
1221 // a set of exam results; 3 radio buttons and a text field:
1222 else if ($data_type == 23) {
1223 $tmp = explode('|', $currvalue);
1224 $avalue = array();
1225 foreach ($tmp as $value) {
1226 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1227 $avalue[$matches[1]] = $matches[2];
1230 $lres = sqlStatement("SELECT * FROM list_options " .
1231 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1232 $s .= "<table cellpadding='0' cellspacing='0'>";
1233 while ($lrow = sqlFetchArray($lres)) {
1234 $option_id = $lrow['option_id'];
1235 $restype = substr($avalue[$option_id], 0, 1);
1236 $resnote = substr($avalue[$option_id], 2);
1237 if (empty($restype) && empty($resnote)) continue;
1239 // Added 5-09 by BM - Translate label if applicable
1240 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1242 $restype = ($restype == '1') ? xl('Normal') : (($restype == '2') ? xl('Abnormal') : xl('N/A'));
1243 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1244 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1245 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "&nbsp;</td>";
1246 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td>";
1247 $s .= "</tr>";
1249 $s .= "</table>";
1252 // the list of active allergies for the current patient
1253 else if ($data_type == 24) {
1254 $query = "SELECT title, comments FROM lists WHERE " .
1255 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1256 "ORDER BY begdate";
1257 // echo "<!-- $query -->\n"; // debugging
1258 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1259 $count = 0;
1260 while ($lrow = sqlFetchArray($lres)) {
1261 if ($count++) $s .= "<br />";
1262 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES);
1263 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES) . ')';
1267 // a set of labeled checkboxes, each with a text field:
1268 else if ($data_type == 25) {
1269 $tmp = explode('|', $currvalue);
1270 $avalue = array();
1271 foreach ($tmp as $value) {
1272 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1273 $avalue[$matches[1]] = $matches[2];
1276 $lres = sqlStatement("SELECT * FROM list_options " .
1277 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1278 $s .= "<table cellpadding='0' cellspacing='0'>";
1279 while ($lrow = sqlFetchArray($lres)) {
1280 $option_id = $lrow['option_id'];
1281 $restype = substr($avalue[$option_id], 0, 1);
1282 $resnote = substr($avalue[$option_id], 2);
1283 if (empty($restype) && empty($resnote)) continue;
1285 // Added 5-09 by BM - Translate label if applicable
1286 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES) . "&nbsp;</td>";
1288 $restype = $restype ? xl('Yes') : xl('No');
1289 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES) . "</td></tr>";
1290 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "</td></tr>";
1291 $s .= "</tr>";
1293 $s .= "</table>";
1296 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1297 else if ($data_type == 28) {
1298 $tmp = explode('|', $currvalue);
1299 switch(count($tmp)) {
1300 case "3": {
1301 $resnote = $tmp[0];
1302 $restype = $tmp[1];
1303 $resdate = $tmp[2];
1304 } break;
1305 case "2": {
1306 $resnote = $tmp[0];
1307 $restype = $tmp[1];
1308 $resdate = "";
1309 } break;
1310 case "1": {
1311 $resnote = $tmp[0];
1312 $resdate = $restype = "";
1313 } break;
1314 default: {
1315 $restype = $resdate = $resnote = "";
1316 } break;
1318 $s .= "<table cellpadding='0' cellspacing='0'>";
1320 $s .= "<tr>";
1321 $res = "";
1322 if ($restype == "current".$field_id) $res = xl('Current');
1323 if ($restype == "quit".$field_id) $res = xl('Quit');
1324 if ($restype == "never".$field_id) $res = xl('Never');
1325 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1326 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1327 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1328 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
1329 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES) . "</b>:&nbsp;" . htmlspecialchars($res,ENT_NOQUOTES) . "&nbsp;</td>";
1330 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES) . "&nbsp;</td>";
1331 $s .= "</tr>";
1332 $s .= "</table>";
1335 // static text. read-only, of course.
1336 else if ($data_type == 31) {
1337 $s .= nl2br($frow['description']);
1340 return $s;
1343 $CPR = 4; // cells per row of generic data
1344 $last_group = '';
1345 $cell_count = 0;
1346 $item_count = 0;
1348 function disp_end_cell() {
1349 global $item_count, $cell_count;
1350 if ($item_count > 0) {
1351 echo "</td>";
1352 $item_count = 0;
1356 function disp_end_row() {
1357 global $cell_count, $CPR;
1358 disp_end_cell();
1359 if ($cell_count > 0) {
1360 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
1361 echo "</tr>\n";
1362 $cell_count = 0;
1366 function disp_end_group() {
1367 global $last_group;
1368 if (strlen($last_group) > 0) {
1369 disp_end_row();
1373 function display_layout_rows($formtype, $result1, $result2='') {
1374 global $item_count, $cell_count, $last_group, $CPR;
1376 $fres = sqlStatement("SELECT * FROM layout_options " .
1377 "WHERE form_id = ? AND uor > 0 " .
1378 "ORDER BY group_name, seq", array($formtype) );
1380 while ($frow = sqlFetchArray($fres)) {
1381 $this_group = $frow['group_name'];
1382 $titlecols = $frow['titlecols'];
1383 $datacols = $frow['datacols'];
1384 $data_type = $frow['data_type'];
1385 $field_id = $frow['field_id'];
1386 $list_id = $frow['list_id'];
1387 $currvalue = '';
1389 if ($formtype == 'DEM') {
1390 if ($GLOBALS['athletic_team']) {
1391 // Skip fitness level and return-to-play date because those appear
1392 // in a special display/update form on this page.
1393 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1395 if (strpos($field_id, 'em_') === 0) {
1396 // Skip employer related fields, if it's disabled.
1397 if ($GLOBALS['omit_employers']) continue;
1398 $tmp = substr($field_id, 3);
1399 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1401 else {
1402 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1405 else {
1406 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1409 // Handle a data category (group) change.
1410 if (strcmp($this_group, $last_group) != 0) {
1411 $group_name = substr($this_group, 1);
1412 // totally skip generating the employer category, if it's disabled.
1413 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1414 disp_end_group();
1415 $last_group = $this_group;
1418 // Handle starting of a new row.
1419 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1420 disp_end_row();
1421 echo "<tr>";
1422 if ($group_name) {
1423 echo "<td class='groupname'>";
1424 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1425 //echo "<font color='#008800'>$group_name</font>";
1427 // Added 5-09 by BM - Translate label if applicable
1428 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES);
1430 $group_name = '';
1431 } else {
1432 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1433 echo "<td valign='top'>&nbsp;";
1435 echo "</td>";
1438 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1440 // Handle starting of a new label cell.
1441 if ($titlecols > 0) {
1442 disp_end_cell();
1443 //echo "<td class='label' colspan='$titlecols' valign='top'";
1444 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1445 echo "<td class='label' colspan='$titlecols_esc' ";
1446 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1447 echo ">";
1448 $cell_count += $titlecols;
1450 ++$item_count;
1452 // Added 5-09 by BM - Translate label if applicable
1453 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1455 // Handle starting of a new data cell.
1456 if ($datacols > 0) {
1457 disp_end_cell();
1458 //echo "<td class='text data' colspan='$datacols' valign='top'";
1459 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1460 echo "<td class='text data' colspan='$datacols_esc'";
1461 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1462 echo ">";
1463 $cell_count += $datacols;
1466 ++$item_count;
1467 echo generate_display_field($frow, $currvalue);
1470 disp_end_group();
1473 function display_layout_tabs($formtype, $result1, $result2='') {
1474 global $item_count, $cell_count, $last_group, $CPR;
1476 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1477 "WHERE form_id = ? AND uor > 0 " .
1478 "ORDER BY group_name, seq", array($formtype) );
1480 $first = true;
1481 while ($frow = sqlFetchArray($fres)) {
1482 $this_group = $frow['group_name'];
1483 $group_name = substr($this_group, 1);
1485 <li <?php echo $first ? 'class="current"' : '' ?>>
1486 <a href="/play/javascript-tabbed-navigation/" id="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES)."?>">
1487 <?php echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES); ?></a>
1488 </li>
1489 <?php
1490 $first = false;
1494 function display_layout_tabs_data($formtype, $result1, $result2='') {
1495 global $item_count, $cell_count, $last_group, $CPR;
1497 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1498 "WHERE form_id = ? AND uor > 0 " .
1499 "ORDER BY group_name, seq", array($formtype));
1501 $first = true;
1502 while ($frow = sqlFetchArray($fres)) {
1503 $this_group = $frow['group_name'];
1504 $titlecols = $frow['titlecols'];
1505 $datacols = $frow['datacols'];
1506 $data_type = $frow['data_type'];
1507 $field_id = $frow['field_id'];
1508 $list_id = $frow['list_id'];
1509 $currvalue = '';
1511 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1512 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1513 "ORDER BY seq", array($formtype, $this_group) );
1516 <div class="tab <?php echo $first ? 'current' : '' ?>">
1517 <table border='0' cellpadding='0'>
1519 <?php
1520 while ($group_fields = sqlFetchArray($group_fields_query)) {
1522 $titlecols = $group_fields['titlecols'];
1523 $datacols = $group_fields['datacols'];
1524 $data_type = $group_fields['data_type'];
1525 $field_id = $group_fields['field_id'];
1526 $list_id = $group_fields['list_id'];
1527 $currvalue = '';
1529 if ($formtype == 'DEM') {
1530 if ($GLOBALS['athletic_team']) {
1531 // Skip fitness level and return-to-play date because those appear
1532 // in a special display/update form on this page.
1533 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1535 if (strpos($field_id, 'em_') === 0) {
1536 // Skip employer related fields, if it's disabled.
1537 if ($GLOBALS['omit_employers']) continue;
1538 $tmp = substr($field_id, 3);
1539 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1541 else {
1542 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1545 else {
1546 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1549 // Handle a data category (group) change.
1550 if (strcmp($this_group, $last_group) != 0) {
1551 $group_name = substr($this_group, 1);
1552 // totally skip generating the employer category, if it's disabled.
1553 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1554 $last_group = $this_group;
1557 // Handle starting of a new row.
1558 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1559 disp_end_row();
1560 echo "<tr>";
1563 if ($item_count == 0 && $titlecols == 0) {
1564 $titlecols = 1;
1567 // Handle starting of a new label cell.
1568 if ($titlecols > 0) {
1569 disp_end_cell();
1570 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1571 echo "<td class='label' colspan='$titlecols_esc' ";
1572 echo ">";
1573 $cell_count += $titlecols;
1575 ++$item_count;
1577 // Added 5-09 by BM - Translate label if applicable
1578 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES); else echo "&nbsp;";
1580 // Handle starting of a new data cell.
1581 if ($datacols > 0) {
1582 disp_end_cell();
1583 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1584 echo "<td class='text data' colspan='$datacols_esc'";
1585 echo ">";
1586 $cell_count += $datacols;
1589 ++$item_count;
1590 echo generate_display_field($group_fields, $currvalue);
1594 </table>
1595 </div>
1597 <?php
1599 $first = false;
1605 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1606 global $item_count, $cell_count, $last_group, $CPR;
1608 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1609 "WHERE form_id = ? AND uor > 0 " .
1610 "ORDER BY group_name, seq", array($formtype) );
1612 $first = true;
1613 while ($frow = sqlFetchArray($fres)) {
1614 $this_group = $frow['group_name'];
1615 $group_name = substr($this_group, 1);
1616 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES);
1617 $titlecols = $frow['titlecols'];
1618 $datacols = $frow['datacols'];
1619 $data_type = $frow['data_type'];
1620 $field_id = $frow['field_id'];
1621 $list_id = $frow['list_id'];
1622 $currvalue = '';
1624 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1625 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1626 "ORDER BY seq", array($formtype,$this_group) );
1629 <div class="tab <?php echo $first ? 'current' : '' ?>" id="tab_<?php echo $group_name_esc?>" >
1630 <table border='0' cellpadding='0'>
1632 <?php
1633 while ($group_fields = sqlFetchArray($group_fields_query)) {
1635 $titlecols = $group_fields['titlecols'];
1636 $datacols = $group_fields['datacols'];
1637 $data_type = $group_fields['data_type'];
1638 $field_id = $group_fields['field_id'];
1639 $list_id = $group_fields['list_id'];
1640 $currvalue = '';
1642 if ($formtype == 'DEM') {
1643 if ($GLOBALS['athletic_team']) {
1644 // Skip fitness level and return-to-play date because those appear
1645 // in a special display/update form on this page.
1646 if ($field_id === 'fitness' || $field_id === 'userdate1') continue;
1648 if (strpos($field_id, 'em_') === 0) {
1649 // Skip employer related fields, if it's disabled.
1650 if ($GLOBALS['omit_employers']) continue;
1651 $tmp = substr($field_id, 3);
1652 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1654 else {
1655 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1658 else {
1659 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1662 // Handle a data category (group) change.
1663 if (strcmp($this_group, $last_group) != 0) {
1664 $group_name = substr($this_group, 1);
1665 // totally skip generating the employer category, if it's disabled.
1666 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1667 $last_group = $this_group;
1670 // Handle starting of a new row.
1671 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
1672 disp_end_row();
1673 echo "<tr>";
1676 if ($item_count == 0 && $titlecols == 0) {
1677 $titlecols = 1;
1680 // Handle starting of a new label cell.
1681 if ($titlecols > 0) {
1682 disp_end_cell();
1683 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
1684 echo "<td class='label' colspan='$titlecols_esc' ";
1685 echo ">";
1686 $cell_count += $titlecols;
1688 ++$item_count;
1690 // Added 5-09 by BM - Translate label if applicable
1691 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES).":"); else echo "&nbsp;";
1693 // Handle starting of a new data cell.
1694 if ($datacols > 0) {
1695 disp_end_cell();
1696 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
1697 echo "<td class='text data' colspan='$datacols_esc'";
1698 echo ">";
1699 $cell_count += $datacols;
1702 ++$item_count;
1703 echo generate_form_field($group_fields, $currvalue);
1707 </table>
1708 </div>
1710 <?php
1712 $first = false;
1717 // From the currently posted HTML form, this gets the value of the
1718 // field corresponding to the provided layout_options table row.
1720 function get_layout_form_value($frow, $maxlength=255) {
1721 // Bring in $sanitize_all_escapes variable, which will decide
1722 // the variable escaping method.
1723 global $sanitize_all_escapes;
1725 $data_type = $frow['data_type'];
1726 $field_id = $frow['field_id'];
1727 $value = '';
1728 if (isset($_POST["form_$field_id"])) {
1729 if ($data_type == 21) {
1730 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1731 // must be concatenated into a |-separated string.
1732 foreach ($_POST["form_$field_id"] as $key => $val) {
1733 if (strlen($value)) $value .= '|';
1734 $value .= $key;
1737 else if ($data_type == 22) {
1738 // $_POST["form_$field_id"] is an array of text fields to be imploded
1739 // into "key:value|key:value|...".
1740 foreach ($_POST["form_$field_id"] as $key => $val) {
1741 $val = str_replace('|', ' ', $val);
1742 if (strlen($value)) $value .= '|';
1743 $value .= "$key:$val";
1746 else if ($data_type == 23) {
1747 // $_POST["form_$field_id"] is an array of text fields with companion
1748 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1749 foreach ($_POST["form_$field_id"] as $key => $val) {
1750 $restype = $_POST["radio_{$field_id}"][$key];
1751 if (empty($restype)) $restype = '0';
1752 $val = str_replace('|', ' ', $val);
1753 if (strlen($value)) $value .= '|';
1754 $value .= "$key:$restype:$val";
1757 else if ($data_type == 25) {
1758 // $_POST["form_$field_id"] is an array of text fields with companion
1759 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1760 foreach ($_POST["form_$field_id"] as $key => $val) {
1761 $restype = empty($_POST["check_{$field_id}"][$key]) ? '0' : '1';
1762 $val = str_replace('|', ' ', $val);
1763 if (strlen($value)) $value .= '|';
1764 $value .= "$key:$restype:$val";
1767 else if ($data_type == 28) {
1768 // $_POST["form_$field_id"] is an date text fields with companion
1769 // radio buttons to be imploded into "notes|type|date".
1770 $restype = $_POST["radio_{$field_id}"];
1771 if (empty($restype)) $restype = '0';
1772 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1773 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1774 $value = "$resnote|$restype|$resdate";
1776 else {
1777 $value = $_POST["form_$field_id"];
1781 // Better to die than to silently truncate data!
1782 if ($maxlength && $data_type != 3 && strlen($value) > $maxlength)
1783 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES) .
1784 ":<br />&nbsp;<br />".htmlspecialchars( $value, ENT_NOQUOTES));
1786 // Make sure the return value is quote-safe.
1787 if ($sanitize_all_escapes) {
1788 //escapes already removed and using binding/placemarks in sql calls
1789 // so only need to trim value
1790 return trim($value);
1792 else {
1793 //need to explicitly prepare value
1794 return formTrim($value);
1798 // Generate JavaScript validation logic for the required fields.
1800 function generate_layout_validation($form_id) {
1801 $fres = sqlStatement("SELECT * FROM layout_options " .
1802 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
1803 "ORDER BY group_name, seq", array($form_id) );
1805 while ($frow = sqlFetchArray($fres)) {
1806 if ($frow['uor'] < 2) continue;
1807 $data_type = $frow['data_type'];
1808 $field_id = $frow['field_id'];
1809 $fldtitle = $frow['title'];
1810 if (!$fldtitle) $fldtitle = $frow['description'];
1811 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES);
1812 switch($data_type) {
1813 case 1:
1814 case 11:
1815 case 12:
1816 case 13:
1817 case 14:
1818 case 26:
1819 echo
1820 " if (f.$fldname.selectedIndex <= 0) {\n" .
1821 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1822 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1823 " }\n";
1824 break;
1825 case 27: // radio buttons
1826 echo
1827 " var i = 0;\n" .
1828 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
1829 " if (i >= f.$fldname.length) {\n" .
1830 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1831 " }\n";
1832 break;
1833 case 2:
1834 case 3:
1835 case 4:
1836 case 15:
1837 echo
1838 " if (trimlen(f.$fldname.value) == 0) {\n" .
1839 " if (f.$fldname.focus) f.$fldname.focus();\n" .
1840 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
1841 " $('#" . $fldname . "').attr('style','background:red'); \n" .
1842 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES) . "'; \n" .
1843 " } else { " .
1844 " $('#" . $fldname . "').attr('style',''); " .
1845 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
1846 " } \n";
1847 break;
1853 * DROPDOWN FOR FACILITIES
1855 * build a dropdown with all facilities
1857 * @param string $selected - name of the currently selected facility
1858 * use '0' for "unspecified facility"
1859 * use '' for "All facilities" (the default)
1860 * @param string $name - the name/id for select form (defaults to "form_facility")
1861 * @param boolean $allow_unspecified - include an option for "unspecified" facility
1862 * defaults to true
1863 * @return void - just echo the html encoded string
1865 * Note: This should become a data-type at some point, according to Brady
1867 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true) {
1868 $have_selected = false;
1869 $query = "SELECT id, name FROM facility ORDER BY name";
1870 $fres = sqlStatement($query);
1872 $name = htmlspecialchars($name, ENT_QUOTES);
1873 echo " <select name=\"$name\">\n";
1875 $option_value = '';
1876 $option_selected_attr = '';
1877 if ($selected == '') {
1878 $option_selected_attr = ' selected="selected"';
1879 $have_selected = true;
1881 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES);
1882 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1884 while ($frow = sqlFetchArray($fres)) {
1885 $facility_id = $frow['id'];
1886 $option_value = htmlspecialchars($facility_id, ENT_QUOTES);
1887 $option_selected_attr = '';
1888 if ($selected == $facility_id) {
1889 $option_selected_attr = ' selected="selected"';
1890 $have_selected = true;
1892 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES);
1893 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1896 if ($allow_unspecified) {
1897 $option_value = '0';
1898 $option_selected_attr = '';
1899 if ( $selected == '0' ) {
1900 $option_selected_attr = ' selected="selected"';
1901 $have_selected = true;
1903 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES);
1904 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
1907 if (!$have_selected) {
1908 $option_value = htmlspecialchars($selected, ENT_QUOTES);
1909 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES);
1910 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES);
1911 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
1913 echo " </select>\n";
1916 // Expand Collapse Widget
1917 // This forms the header and functionality component of the widget. The information that is displayed
1918 // then follows this function followed by a closing div tag
1920 // $title is the title of the section (already translated)
1921 // $label is identifier used in the tag id's and sql columns
1922 // $buttonLabel is the button label text (already translated)
1923 // $buttonLink is the button link information
1924 // $buttonClass is any additional needed class elements for the button tag
1925 // $linkMethod is the button link method ('javascript' vs 'html')
1926 // $bodyClass is to set class(es) of the body
1927 // $auth is a flag to decide whether to show the button
1928 // $fixedWidth is to flag whether width is fixed
1930 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth) {
1931 if ($fixedWidth) {
1932 echo "<div class='section-header'>";
1934 else {
1935 echo "<div class='section-header-dynamic'>";
1937 echo "<table><tr>";
1938 if ($auth) {
1939 // show button, since authorized
1940 // first prepare class string
1941 if ($buttonClass) {
1942 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES);
1944 else {
1945 $class_string = "css_button_small";
1947 // next, create the link
1948 if ($linkMethod == "javascript") {
1949 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
1951 else {
1952 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'" .
1953 " onclick='top.restoreSession()'";
1955 if (!$GLOBALS['concurrent_layout']) {
1956 echo " target='Main'";
1958 echo "><span>" .
1959 htmlspecialchars( $buttonLabel, ENT_NOQUOTES) . "</span></a></td>";
1961 echo "<td><a href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
1962 htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand\")'><span class='text'><b>";
1963 echo htmlspecialchars( $title, ENT_NOQUOTES) . "</b></span>";
1964 if (getUserSetting($label."_ps_expand")) {
1965 $text = xl('collapse');
1967 else {
1968 $text = xl('expand');
1970 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES) .
1971 "</span>)</a></td>";
1972 echo "</tr></table>";
1973 echo "</div>";
1974 if (getUserSetting($label."_ps_expand")) {
1975 $styling = "";
1977 else {
1978 $styling = "style='display:none'";
1980 if ($bodyClass) {
1981 $styling .= " class='" . $bodyClass . "'";
1983 //next, create the first div tag to hold the information
1984 // note the code that calls this function will then place the ending div tag after the data
1985 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES) . "_ps_expand' " . $styling . ">";