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>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // Functions for managing the lists and layouts
13 // Note: there are translation wrappers for the lists and layout labels
14 // at library/translation.inc.php. The functions are titled
15 // xl_list_label() and xl_layout_label() and are controlled by the
16 // $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
17 // flags in globals.php
19 // Documentation for layout_options.edit_options:
21 // C = Capitalize first letter of each word (text fields)
22 // D = Check for duplicates in New Patient form
23 // G = Graphable (for numeric fields in forms supporting historical data)
24 // H = Read-only field copied from static history
25 // L = Lab Order ("ord_lab") types only (address book)
26 // N = Show in New Patient form
27 // O = Procedure Order ("ord_*") types only (address book)
28 // R = Distributor types only (address book)
29 // U = Capitalize all letters (text fields)
30 // V = Vendor types only (address book)
31 // 1 = Write Once (not editable when not empty) (text fields)
33 require_once("formdata.inc.php");
34 require_once("formatting.inc.php");
35 require_once("user.inc");
39 function get_pharmacies() {
40 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
41 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
42 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
43 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
45 "ORDER BY name, area_code, prefix, number");
48 // Function to generate a drop-list.
50 function generate_select_list($tag_name, $list_id, $currvalue, $title,
51 $empty_name=' ', $class='', $onchange='', $tag_id = '', $custom_attributes = null )
54 $tag_name_esc = htmlspecialchars( $tag_name, ENT_QUOTES
);
55 $s .= "<select name='$tag_name_esc'";
56 $tag_id_esc = $tag_name_esc;
57 if ( $tag_id != '' ) {
58 $tag_id_esc = htmlspecialchars( $tag_id, ENT_QUOTES
);
60 $s .= " id='$tag_id_esc'";
61 if ($class) $s .= " class='$class'";
62 if ($onchange) $s .= " onchange='$onchange'";
63 if ( $custom_attributes != null && is_array($custom_attributes) ) {
64 foreach ( $custom_attributes as $attr => $val ) {
65 if ( isset($custom_attributes[$attr] ) ) {
66 $s .= " ".htmlspecialchars( $attr, ENT_QUOTES
)."='".htmlspecialchars( $val, ENT_QUOTES
)."'";
70 $selectTitle = htmlspecialchars( $title, ENT_QUOTES
);
71 $s .= " title='$selectTitle'>";
72 $selectEmptyName = htmlspecialchars( xl($empty_name), ENT_NOQUOTES
);
73 if ($empty_name) $s .= "<option value=''>" . $selectEmptyName . "</option>";
74 $lres = sqlStatement("SELECT * FROM list_options " .
75 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
76 $got_selected = FALSE;
77 while ($lrow = sqlFetchArray($lres)) {
78 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES
);
79 $s .= "<option value='$optionValue'";
80 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
81 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
86 $optionLabel = htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
87 $s .= ">$optionLabel</option>\n";
89 if (!$got_selected && strlen($currvalue) > 0) {
90 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
91 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
93 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_QUOTES
);
94 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
95 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
103 // $frow is a row from the layout_options table.
104 // $currvalue is the current value, if any, of the associated item.
106 function generate_form_field($frow, $currvalue) {
107 global $rootdir, $date_init;
109 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
111 $data_type = $frow['data_type'];
112 $field_id = $frow['field_id'];
113 $list_id = $frow['list_id'];
114 // escaped variables to use in html
115 $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES
);
116 $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES
);
118 // Added 5-09 by BM - Translate description if applicable
119 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
121 // added 5-2009 by BM to allow modification of the 'empty' text title field.
122 // Can pass $frow['empty_title'] with this variable, otherwise
123 // will default to 'Unassigned'.
124 // modified 6-2009 by BM to allow complete skipping of the 'empty' text title
125 // if make $frow['empty_title'] equal to 'SKIP'
127 if (isset($frow['empty_title'])) {
128 if ($frow['empty_title'] == "SKIP") {
129 //do not display an 'empty' choice
131 $empty_title = "Unassigned";
134 $empty_title = $frow['empty_title'];
138 $empty_title = "Unassigned";
141 // generic single-selection list
142 if ($data_type == 1) {
143 echo generate_select_list("form_$field_id", $list_id, $currvalue,
144 $description, $showEmpty ?
$empty_title : '');
148 else if ($data_type == 2) {
149 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
150 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
151 echo "<input type='text'" .
152 " name='form_$field_id_esc'" .
153 " id='form_$field_id_esc'" .
154 " size='$fldlength'" .
155 " maxlength='$maxlength'" .
156 " title='$description'" .
157 " value='$currescaped'";
158 if (strpos($frow['edit_options'], 'C') !== FALSE)
159 echo " onchange='capitalizeMe(this)'";
160 else if (strpos($frow['edit_options'], 'U') !== FALSE)
161 echo " onchange='this.value = this.value.toUpperCase()'";
162 $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES
);
163 if ($field_id == 'pubpid' && strlen($tmp) > 0) {
164 echo " onkeyup='maskkeyup(this,\"$tmp\")'";
165 echo " onblur='maskblur(this,\"$tmp\")'";
167 if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0)
172 // long or multi-line text field
173 else if ($data_type == 3) {
174 $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
175 $textRows = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
177 " name='form_$field_id_esc'" .
178 " id='form_$field_id_esc'" .
179 " title='$description'" .
180 " cols='$textCols'" .
181 " rows='$textRows'>" .
182 $currescaped . "</textarea>";
186 else if ($data_type == 4) {
187 echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
188 " value='$currescaped'" .
189 " title='$description'" .
190 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
191 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
192 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
193 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES
) . "' />";
194 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
197 // provider list, local providers only
198 else if ($data_type == 10) {
199 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
200 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
201 "AND authorized = 1 " .
202 "ORDER BY lname, fname");
203 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
204 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
205 while ($urow = sqlFetchArray($ures)) {
206 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES
);
207 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES
);
208 echo "<option value='$optionId'";
209 if ($urow['id'] == $currvalue) echo " selected";
210 echo ">$uname</option>";
215 // provider list, including address book entries with an NPI number
216 else if ($data_type == 11) {
217 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
218 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
219 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
220 "ORDER BY lname, fname");
221 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
222 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
223 while ($urow = sqlFetchArray($ures)) {
224 $uname = htmlspecialchars( $urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES
);
225 $optionId = htmlspecialchars( $urow['id'], ENT_QUOTES
);
226 echo "<option value='$optionId'";
227 if ($urow['id'] == $currvalue) echo " selected";
228 echo ">$uname</option>";
234 else if ($data_type == 12) {
235 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
236 echo "<option value='0'></option>";
237 $pres = get_pharmacies();
238 while ($prow = sqlFetchArray($pres)) {
240 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
241 $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
242 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
243 $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES
);
244 echo "<option value='$optionValue'";
245 if ($currvalue == $key) echo " selected";
246 echo ">$optionLabel</option>";
252 else if ($data_type == 13) {
253 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
254 echo "<option value=''> </option>";
255 $squads = acl_get_squads();
257 foreach ($squads as $key => $value) {
258 $optionValue = htmlspecialchars( $key, ENT_QUOTES
);
259 $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES
);
260 echo "<option value='$optionValue'";
261 if ($currvalue == $key) echo " selected";
262 echo ">$optionLabel</option>\n";
268 // Address book, preferring organization name if it exists and is not in
269 // parentheses, and excluding local users who are not providers.
270 // Supports "referred to" practitioners and facilities.
271 // Alternatively the letter L in edit_options means that abook_type
272 // must be "ord_lab", indicating types used with the procedure
273 // lab ordering system.
274 // Alternatively the letter O in edit_options means that abook_type
275 // must begin with "ord_", indicating types used with the procedure
277 // Alternatively the letter V in edit_options means that abook_type
278 // must be "vendor", indicating the Vendor type.
279 // Alternatively the letter R in edit_options means that abook_type
280 // must be "dist", indicating the Distributor type.
281 else if ($data_type == 14) {
282 if (strpos($frow['edit_options'], 'L') !== FALSE)
283 $tmp = "abook_type = 'ord_lab'";
284 else if (strpos($frow['edit_options'], 'O') !== FALSE)
285 $tmp = "abook_type LIKE 'ord\\_%'";
286 else if (strpos($frow['edit_options'], 'V') !== FALSE)
287 $tmp = "abook_type LIKE 'vendor%'";
288 else if (strpos($frow['edit_options'], 'R') !== FALSE)
289 $tmp = "abook_type LIKE 'dist'";
291 $tmp = "( username = '' OR authorized = 1 )";
292 $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
293 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
295 "ORDER BY organization, lname, fname");
296 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
297 echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES
) . "</option>";
298 while ($urow = sqlFetchArray($ures)) {
299 $uname = $urow['organization'];
300 if (empty($uname) ||
substr($uname, 0, 1) == '(') {
301 $uname = $urow['lname'];
302 if ($urow['fname']) $uname .= ", " . $urow['fname'];
304 $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES
);
305 $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES
);
306 echo "<option value='$optionValue'";
307 $title = $urow['username'] ?
xl('Local') : xl('External');
308 $optionTitle = htmlspecialchars( $title, ENT_QUOTES
);
309 echo " title='$optionTitle'";
310 if ($urow['id'] == $currvalue) echo " selected";
311 echo ">$optionLabel</option>";
317 else if ($data_type == 15) {
318 $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES
);
319 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
320 echo "<input type='text'" .
321 " name='form_$field_id_esc'" .
322 " id='form_related_code'" .
323 " size='$fldlength'" .
324 " maxlength='$maxlength'" .
325 " title='$description'" .
326 " value='$currescaped'" .
327 " onclick='sel_related(this)' readonly" .
331 // a set of labeled checkboxes
332 else if ($data_type == 21) {
333 // In this special case, fld_length is the number of columns generated.
334 $cols = max(1, $frow['fld_length']);
335 $avalue = explode('|', $currvalue);
336 $lres = sqlStatement("SELECT * FROM list_options " .
337 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
338 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
339 $tdpct = (int) (100 / $cols);
340 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
341 $option_id = $lrow['option_id'];
342 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
343 // if ($count) echo "<br />";
344 if ($count %
$cols == 0) {
345 if ($count) echo "</tr>";
348 echo "<td width='$tdpct%'>";
349 echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]' id='form_{$field_id_esc}[$option_id_esc]' value='1'";
350 if (in_array($option_id, $avalue)) echo " checked";
352 // Added 5-09 by BM - Translate label if applicable
353 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
359 if ($count > $cols) {
360 // Add some space after multiple rows of checkboxes.
361 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
362 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
368 // a set of labeled text input fields
369 else if ($data_type == 22) {
370 $tmp = explode('|', $currvalue);
372 foreach ($tmp as $value) {
373 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
374 $avalue[$matches[1]] = $matches[2];
377 $lres = sqlStatement("SELECT * FROM list_options " .
378 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
379 echo "<table cellpadding='0' cellspacing='0'>";
380 while ($lrow = sqlFetchArray($lres)) {
381 $option_id = $lrow['option_id'];
382 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
383 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
384 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
386 // Added 5-09 by BM - Translate label if applicable
387 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
388 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
389 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
390 $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
391 echo "<td><input type='text'" .
392 " name='form_{$field_id_esc}[$option_id_esc]'" .
393 " id='form_{$field_id_esc}[$option_id_esc]'" .
394 " size='$fldlength'" .
395 " maxlength='$maxlength'" .
396 " value='$optionValue'";
397 echo " /></td></tr>";
402 // a set of exam results; 3 radio buttons and a text field:
403 else if ($data_type == 23) {
404 $tmp = explode('|', $currvalue);
406 foreach ($tmp as $value) {
407 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
408 $avalue[$matches[1]] = $matches[2];
411 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
412 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
413 $lres = sqlStatement("SELECT * FROM list_options " .
414 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
415 echo "<table cellpadding='0' cellspacing='0'>";
416 echo "<tr><td> </td><td class='bold'>" .
417 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
418 " </td><td class='bold'>" .
419 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
420 "<td class='bold'>" .
421 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
422 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
423 while ($lrow = sqlFetchArray($lres)) {
424 $option_id = $lrow['option_id'];
425 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
426 $restype = substr($avalue[$option_id], 0, 1);
427 $resnote = substr($avalue[$option_id], 2);
429 // Added 5-09 by BM - Translate label if applicable
430 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
432 for ($i = 0; $i < 3; ++
$i) {
433 $inputValue = htmlspecialchars( $i, ENT_QUOTES
);
434 echo "<td><input type='radio'" .
435 " name='radio_{$field_id_esc}[$option_id_esc]'" .
436 " id='radio_{$field_id_esc}[$option_id_esc]'" .
437 " value='$inputValue'";
438 if ($restype === "$i") echo " checked";
441 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
442 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
443 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
444 echo "<td><input type='text'" .
445 " name='form_{$field_id_esc}[$option_id_esc]'" .
446 " id='form_{$field_id_esc}[$option_id_esc]'" .
447 " size='$fldlength'" .
448 " maxlength='$maxlength'" .
449 " value='$resnote' /></td>";
455 // the list of active allergies for the current patient
456 // this is read-only!
457 else if ($data_type == 24) {
458 $query = "SELECT title, comments FROM lists WHERE " .
459 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
461 // echo "<!-- $query -->\n"; // debugging
462 $lres = sqlStatement($query, array($GLOBALS['pid']));
464 while ($lrow = sqlFetchArray($lres)) {
465 if ($count++
) echo "<br />";
466 echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES
);
467 if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES
) . ')';
471 // a set of labeled checkboxes, each with a text field:
472 else if ($data_type == 25) {
473 $tmp = explode('|', $currvalue);
475 foreach ($tmp as $value) {
476 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
477 $avalue[$matches[1]] = $matches[2];
480 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
481 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
482 $lres = sqlStatement("SELECT * FROM list_options " .
483 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
484 echo "<table cellpadding='0' cellspacing='0'>";
485 while ($lrow = sqlFetchArray($lres)) {
486 $option_id = $lrow['option_id'];
487 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
488 $restype = substr($avalue[$option_id], 0, 1);
489 $resnote = substr($avalue[$option_id], 2);
491 // Added 5-09 by BM - Translate label if applicable
492 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
494 $option_id = htmlspecialchars( $option_id, ENT_QUOTES
);
495 echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]' id='check_{$field_id_esc}[$option_id_esc]' value='1'";
496 if ($restype) echo " checked";
497 echo " /> </td>";
498 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
499 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
500 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
501 echo "<td><input type='text'" .
502 " name='form_{$field_id_esc}[$option_id_esc]'" .
503 " id='form_{$field_id_esc}[$option_id_esc]'" .
504 " size='$fldlength'" .
505 " maxlength='$maxlength'" .
506 " value='$resnote' /></td>";
512 // single-selection list with ability to add to it
513 else if ($data_type == 26) {
514 echo "<select class='addtolistclass_$list_id_esc' name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
515 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES
) . "</option>";
516 $lres = sqlStatement("SELECT * FROM list_options " .
517 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
518 $got_selected = FALSE;
519 while ($lrow = sqlFetchArray($lres)) {
520 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES
);
521 echo "<option value='$optionValue'";
522 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
523 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
526 $got_selected = TRUE;
528 // Added 5-09 by BM - Translate label if applicable
529 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . "</option>\n";
531 if (!$got_selected && strlen($currvalue) > 0) {
532 echo "<option value='$currescaped' selected>* $currescaped *</option>";
534 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES
);
535 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
536 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
541 // show the add button if user has access to correct list
542 $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES
);
543 $outputAddButton = "<input type='button' id='addtolistid_".$list_id_esc."' fieldid='form_".$field_id_esc."' class='addtolist' value='$inputValue'>";
544 if (aco_exist('lists', $list_id)) {
545 // a specific aco exist for this list, so ensure access
546 if (acl_check('lists', $list_id)) echo $outputAddButton;
549 // no specific aco exist for this list, so check for access to 'default' list
550 if (acl_check('lists', 'default')) echo $outputAddButton;
554 // a set of labeled radio buttons
555 else if ($data_type == 27) {
556 // In this special case, fld_length is the number of columns generated.
557 $cols = max(1, $frow['fld_length']);
558 $lres = sqlStatement("SELECT * FROM list_options " .
559 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
560 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
561 $tdpct = (int) (100 / $cols);
562 $got_selected = FALSE;
563 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
564 $option_id = $lrow['option_id'];
565 $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES
);
566 if ($count %
$cols == 0) {
567 if ($count) echo "</tr>";
570 echo "<td width='$tdpct%'>";
571 echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]' value='$option_id_esc'";
572 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
573 (strlen($currvalue) > 0 && $option_id == $currvalue))
576 $got_selected = TRUE;
578 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
583 if ($count > $cols) {
584 // Add some space after multiple rows of radio buttons.
585 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
586 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
590 if (!$got_selected && strlen($currvalue) > 0) {
591 $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES
);
592 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
593 echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
597 // special case for history of lifestyle status; 3 radio buttons and a date text field:
598 // VicarePlus :: A selection list box for smoking status:
599 else if ($data_type == 28 ||
$data_type == 32) {
600 $tmp = explode('|', $currvalue);
601 switch(count($tmp)) {
620 $resdate = $restype = "";
623 $restype = $resdate = $resnote = "";
626 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
627 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
629 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
630 $maxlength = htmlspecialchars( $maxlength, ENT_QUOTES
);
631 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
632 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
633 echo "<table cellpadding='0' cellspacing='0'>";
635 if ($data_type == 28)
638 echo "<td><input type='text'" .
639 " name='form_$field_id_esc'" .
640 " id='form_$field_id_esc'" .
641 " size='$fldlength'" .
642 " maxlength='$maxlength'" .
643 " value='$resnote' /> </td>";
644 echo "<td class='bold'> ".
645 " ".
646 htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
648 else if($data_type == 32)
651 echo "<tr><td><input type='text'" .
652 " name='form_text_$field_id_esc'" .
653 " id='form_text_$field_id_esc'" .
654 " size='$fldlength'" .
655 " maxlength='$maxlength'" .
656 " value='$resnote' /> </td></tr>";
658 //Selection list for smoking status
659 $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
660 echo generate_select_list("form_$field_id", $list_id, $reslist,
661 $description, $showEmpty ?
$empty_title : '', '', $onchange)."</td>";
662 echo "<td class='bold'> ".htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
665 echo "<td><input type='radio'" .
666 " name='radio_{$field_id_esc}'" .
667 " id='radio_{$field_id_esc}[current]'" .
668 " value='current".$field_id_esc."'";
669 if ($restype == "current".$field_id) echo " checked";
670 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Current'), ENT_NOQUOTES
)." </td>";
672 echo "<td><input type='radio'" .
673 " name='radio_{$field_id_esc}'" .
674 " id='radio_{$field_id_esc}[quit]'" .
675 " value='quit".$field_id_esc."'";
676 if ($restype == "quit".$field_id) echo " checked";
677 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Quit'), ENT_NOQUOTES
)." </td>";
679 echo "<td><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
680 " value='$resdate'" .
681 " title='$description'" .
682 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
683 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
684 " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
685 " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES
) . "' /> </td>";
686 $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
688 echo "<td><input type='radio'" .
689 " name='radio_{$field_id_esc}'" .
690 " id='radio_{$field_id_esc}[never]'" .
691 " value='never".$field_id_esc."'";
692 if ($restype == "never".$field_id) echo " checked";
693 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('Never'), ENT_NOQUOTES
)." </td>";
695 echo "<td><input type='radio'" .
696 " name='radio_{$field_id}'" .
697 " id='radio_{$field_id}[not_applicable]'" .
698 " value='not_applicable".$field_id."'";
699 if ($restype == "not_applicable".$field_id) echo " checked";
700 echo " if($data_type == 32) { onClick='smoking_statusClicked(this)' } />".htmlspecialchars( xl('N/A'), ENT_QUOTES
)." </td>";
705 // static text. read-only, of course.
706 else if ($data_type == 31) {
707 echo nl2br($frow['description']);
710 //VicarePlus :: A single selection list for Race and Ethnicity, which is specialized to check the 'ethrace' list if the entry does not exist in the list_id of the given list. At some point in the future (when able to input two lists via the layouts engine), this function could be expanded to allow using any list as a backup entry.
711 else if ($data_type == 33) {
712 echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
713 if ($showEmpty) echo "<option value=''>" . htmlspecialchars( xl($empty_title), ENT_QUOTES
) . "</option>";
714 $lres = sqlStatement("SELECT * FROM list_options " .
715 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
716 $got_selected = FALSE;
717 while ($lrow = sqlFetchArray($lres)) {
718 $optionValue = htmlspecialchars( $lrow['option_id'], ENT_QUOTES
);
719 echo "<option value='$optionValue'";
720 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
721 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
724 $got_selected = TRUE;
727 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . "</option>\n";
729 if (!$got_selected && strlen($currvalue) > 0)
731 //Check 'ethrace' list if the entry does not exist in the list_id of the given list(Race or Ethnicity).
733 $lrow = sqlQuery("SELECT title FROM list_options " .
734 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
737 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
738 echo "<option value='$currvalue' selected> $s </option>";
743 echo "<option value='$currescaped' selected>* $currescaped *</option>";
745 $fontTitle = htmlspecialchars( xl('Please choose a valid selection from the list.'), ENT_NOQUOTES
);
746 $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES
);
747 echo " <font color='red' title='$fontTitle'>$fontText!</font>";
754 else if($data_type == 34){
755 $arr = explode("|*|*|*|",$currvalue);
756 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc,ENT_QUOTES
)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
757 echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES
)."</div>";
758 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'>".$currvalue."</textarea></div>";
762 //facilities drop-down list
763 else if ($data_type == 35) {
764 if (empty($currvalue)){
767 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
772 function generate_print_field($frow, $currvalue) {
773 global $rootdir, $date_init;
775 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
777 $data_type = $frow['data_type'];
778 $field_id = $frow['field_id'];
779 $list_id = $frow['list_id'];
780 $fld_length = $frow['fld_length'];
782 $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES
);
784 // Can pass $frow['empty_title'] with this variable, otherwise
785 // will default to 'Unassigned'.
786 // If it is 'SKIP' then an empty text title is completely skipped.
788 if (isset($frow['empty_title'])) {
789 if ($frow['empty_title'] == "SKIP") {
790 //do not display an 'empty' choice
792 $empty_title = "Unassigned";
795 $empty_title = $frow['empty_title'];
799 $empty_title = "Unassigned";
802 // generic single-selection list
803 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 33) {
804 if (empty($fld_length)) {
805 if ($list_id == 'titles') {
813 $lrow = sqlQuery("SELECT title FROM list_options " .
814 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
815 $tmp = xl_list_label($lrow['title']);
816 if (empty($tmp)) $tmp = "($currvalue)";
818 /*****************************************************************
819 echo "<input type='text'" .
820 " size='$fld_length'" .
824 *****************************************************************/
825 if ($tmp === '') { $tmp = ' '; }
826 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
831 else if ($data_type == 2 ||
$data_type == 15) {
832 /*****************************************************************
833 echo "<input type='text'" .
834 " size='$fld_length'" .
835 " value='$currescaped'" .
838 *****************************************************************/
839 if ($currescaped === '') $currescaped = ' ';
843 // long or multi-line text field
844 else if ($data_type == 3) {
845 $fldlength = htmlspecialchars( $fld_length, ENT_QUOTES
);
846 $maxlength = htmlspecialchars( $frow['max_length'], ENT_QUOTES
);
848 " cols='$fldlength'" .
849 " rows='$maxlength'>" .
850 $currescaped . "</textarea>";
854 else if ($data_type == 4) {
855 /*****************************************************************
856 echo "<input type='text' size='10'" .
857 " value='$currescaped'" .
858 " title='$description'" .
861 *****************************************************************/
862 if ($currvalue === '') { $tmp = oeFormatShortDate(' '); }
863 else { $tmp = htmlspecialchars( oeFormatShortDate($currvalue), ENT_QUOTES
); }
868 else if ($data_type == 10 ||
$data_type == 11) {
871 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
872 "WHERE id = ?", array($currvalue) );
873 $tmp = ucwords($urow['fname'] . " " . $urow['lname']);
874 if (empty($tmp)) $tmp = "($currvalue)";
876 /*****************************************************************
877 echo "<input type='text'" .
878 " size='$fld_length'" .
882 *****************************************************************/
883 if ($tmp === '') { $tmp = ' '; }
884 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
889 else if ($data_type == 12) {
892 $pres = get_pharmacies();
893 while ($prow = sqlFetchArray($pres)) {
895 if ($currvalue == $key) {
896 $tmp = $prow['name'] . ' ' . $prow['area_code'] . '-' .
897 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
898 $prow['line1'] . ' / ' . $prow['city'];
901 if (empty($tmp)) $tmp = "($currvalue)";
903 /*****************************************************************
904 echo "<input type='text'" .
905 " size='$fld_length'" .
909 *****************************************************************/
910 if ($tmp === '') { $tmp = ' '; }
911 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
916 else if ($data_type == 13) {
919 $squads = acl_get_squads();
921 foreach ($squads as $key => $value) {
922 if ($currvalue == $key) {
927 if (empty($tmp)) $tmp = "($currvalue)";
929 /*****************************************************************
930 echo "<input type='text'" .
931 " size='$fld_length'" .
935 *****************************************************************/
936 if ($tmp === '') { $tmp = ' '; }
937 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
942 else if ($data_type == 14) {
945 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
946 "WHERE id = ?", array($currvalue) );
947 $uname = $urow['lname'];
948 if ($urow['fname']) $uname .= ", " . $urow['fname'];
950 if (empty($tmp)) $tmp = "($currvalue)";
952 /*****************************************************************
953 echo "<input type='text'" .
954 " size='$fld_length'" .
958 *****************************************************************/
959 if ($tmp === '') { $tmp = ' '; }
960 else { $tmp = htmlspecialchars( $tmp, ENT_QUOTES
); }
964 // a set of labeled checkboxes
965 else if ($data_type == 21) {
966 // In this special case, fld_length is the number of columns generated.
967 $cols = max(1, $fld_length);
968 $avalue = explode('|', $currvalue);
969 $lres = sqlStatement("SELECT * FROM list_options " .
970 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
971 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
972 $tdpct = (int) (100 / $cols);
973 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
974 $option_id = $lrow['option_id'];
975 if ($count %
$cols == 0) {
976 if ($count) echo "</tr>";
979 echo "<td width='$tdpct%'>";
980 echo "<input type='checkbox'";
981 if (in_array($option_id, $avalue)) echo " checked";
982 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
987 if ($count > $cols) {
988 // Add some space after multiple rows of checkboxes.
989 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
990 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
996 // a set of labeled text input fields
997 else if ($data_type == 22) {
998 $tmp = explode('|', $currvalue);
1000 foreach ($tmp as $value) {
1001 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1002 $avalue[$matches[1]] = $matches[2];
1005 $lres = sqlStatement("SELECT * FROM list_options " .
1006 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1007 echo "<table cellpadding='0' cellspacing='0'>";
1008 while ($lrow = sqlFetchArray($lres)) {
1009 $option_id = $lrow['option_id'];
1010 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
1011 $fldlength = empty($fld_length) ?
20 : $fld_length;
1012 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1013 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1014 $inputValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES
);
1015 echo "<td><input type='text'" .
1016 " size='$fldlength'" .
1017 " value='$inputValue'" .
1024 // a set of exam results; 3 radio buttons and a text field:
1025 else if ($data_type == 23) {
1026 $tmp = explode('|', $currvalue);
1028 foreach ($tmp as $value) {
1029 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1030 $avalue[$matches[1]] = $matches[2];
1033 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
1034 $fldlength = empty($fld_length) ?
20 : $fld_length;
1035 $lres = sqlStatement("SELECT * FROM list_options " .
1036 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1037 echo "<table cellpadding='0' cellspacing='0'>";
1038 echo "<tr><td> </td><td class='bold'>" .
1039 htmlspecialchars( xl('N/A'), ENT_NOQUOTES
) .
1040 " </td><td class='bold'>" .
1041 htmlspecialchars( xl('Nor'), ENT_NOQUOTES
) . " </td>" .
1042 "<td class='bold'>" .
1043 htmlspecialchars( xl('Abn'), ENT_NOQUOTES
) . " </td><td class='bold'>" .
1044 htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES
) . "</td></tr>";
1045 while ($lrow = sqlFetchArray($lres)) {
1046 $option_id = $lrow['option_id'];
1047 $restype = substr($avalue[$option_id], 0, 1);
1048 $resnote = substr($avalue[$option_id], 2);
1049 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1050 for ($i = 0; $i < 3; ++
$i) {
1051 echo "<td><input type='radio'";
1052 if ($restype === "$i") echo " checked";
1055 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1056 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1057 echo "<td><input type='text'" .
1058 " size='$fldlength'" .
1059 " value='$resnote'" .
1060 " class='under' /></td>" .
1066 // the list of active allergies for the current patient
1067 // this is read-only!
1068 else if ($data_type == 24) {
1069 $query = "SELECT title, comments FROM lists WHERE " .
1070 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1072 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1074 while ($lrow = sqlFetchArray($lres)) {
1075 if ($count++
) echo "<br />";
1076 echo htmlspecialchars( $lrow['title'], ENT_QUOTES
);
1077 if ($lrow['comments']) echo htmlspecialchars( ' (' . $lrow['comments'] . ')', ENT_QUOTES
);
1081 // a set of labeled checkboxes, each with a text field:
1082 else if ($data_type == 25) {
1083 $tmp = explode('|', $currvalue);
1085 foreach ($tmp as $value) {
1086 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1087 $avalue[$matches[1]] = $matches[2];
1090 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
1091 $fldlength = empty($fld_length) ?
20 : $fld_length;
1092 $lres = sqlStatement("SELECT * FROM list_options " .
1093 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1094 echo "<table cellpadding='0' cellspacing='0'>";
1095 while ($lrow = sqlFetchArray($lres)) {
1096 $option_id = $lrow['option_id'];
1097 $restype = substr($avalue[$option_id], 0, 1);
1098 $resnote = substr($avalue[$option_id], 2);
1099 echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
) . " </td>";
1100 echo "<td><input type='checkbox'";
1101 if ($restype) echo " checked";
1102 echo " /> </td>";
1103 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1104 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1105 echo "<td><input type='text'" .
1106 " size='$fldlength'" .
1107 " value='$resnote'" .
1115 // a set of labeled radio buttons
1116 else if ($data_type == 27) {
1117 // In this special case, fld_length is the number of columns generated.
1118 $cols = max(1, $frow['fld_length']);
1119 $lres = sqlStatement("SELECT * FROM list_options " .
1120 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1121 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
1122 $tdpct = (int) (100 / $cols);
1123 for ($count = 0; $lrow = sqlFetchArray($lres); ++
$count) {
1124 $option_id = $lrow['option_id'];
1125 if ($count %
$cols == 0) {
1126 if ($count) echo "</tr>";
1129 echo "<td width='$tdpct%'>";
1130 echo "<input type='radio'";
1131 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
1132 (strlen($currvalue) > 0 && $option_id == $currvalue))
1136 echo ">" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES
);
1141 if ($count > $cols) {
1142 // Add some space after multiple rows of radio buttons.
1143 $cols = htmlspecialchars( $cols, ENT_QUOTES
);
1144 echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
1150 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1151 else if ($data_type == 28 ||
$data_type == 32) {
1152 $tmp = explode('|', $currvalue);
1153 switch(count($tmp)) {
1172 $resdate = $restype = "";
1175 $restype = $resdate = $resnote = "";
1178 $maxlength = empty($frow['max_length']) ?
255 : $frow['max_length'];
1179 $fldlength = empty($frow['fld_length']) ?
20 : $frow['fld_length'];
1180 echo "<table cellpadding='0' cellspacing='0'>";
1182 $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES
);
1183 $resnote = htmlspecialchars( $resnote, ENT_QUOTES
);
1184 $resdate = htmlspecialchars( $resdate, ENT_QUOTES
);
1185 if($data_type == 28)
1187 echo "<td><input type='text'" .
1188 " size='$fldlength'" .
1190 " value='$resnote' /></td>";
1191 echo "<td class='bold'> ".
1192 " ".
1193 htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
1195 else if($data_type == 32)
1197 echo "<tr><td><input type='text'" .
1198 " size='$fldlength'" .
1200 " value='$resnote' /></td></tr>";
1202 $smoking_status_title = generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist);
1203 echo "<td><input type='text'" .
1204 " size='$fldlength'" .
1206 " value='$smoking_status_title' /></td>";
1207 echo "<td class='bold'> ".htmlspecialchars( xl('Status'), ENT_NOQUOTES
).": </td>";
1209 echo "<td><input type='radio'";
1210 if ($restype == "current".$field_id) echo " checked";
1211 echo "/>".htmlspecialchars( xl('Current'), ENT_NOQUOTES
)." </td>";
1213 echo "<td><input type='radio'";
1214 if ($restype == "current".$field_id) echo " checked";
1215 echo "/>".htmlspecialchars( xl('Quit'), ENT_NOQUOTES
)." </td>";
1217 echo "<td><input type='text' size='6'" .
1218 " value='$resdate'" .
1222 echo "<td><input type='radio'";
1223 if ($restype == "current".$field_id) echo " checked";
1224 echo " />".htmlspecialchars( xl('Never'), ENT_NOQUOTES
)."</td>";
1226 echo "<td><input type='radio'";
1227 if ($restype == "not_applicable".$field_id) echo " checked";
1228 echo " />".htmlspecialchars( xl('N/A'), ENT_NOQUOTES
)." </td>";
1233 // static text. read-only, of course.
1234 else if ($data_type == 31) {
1235 echo nl2br($frow['description']);
1238 else if($data_type == 34){
1239 echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc,ENT_QUOTES
)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
1240 echo "<div id='form_{$field_id}_div' class='text-area'></div>";
1241 echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' stye='display:none'></textarea></div>";
1245 //facilities drop-down list
1246 else if ($data_type == 35) {
1247 if (empty($currvalue)){
1250 dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false);
1255 function generate_display_field($frow, $currvalue) {
1256 $data_type = $frow['data_type'];
1257 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : null;
1258 $list_id = $frow['list_id'];
1261 // generic selection list or the generic selection list with add on the fly
1262 // feature, or radio buttons
1263 if ($data_type == 1 ||
$data_type == 26 ||
$data_type == 27 ||
$data_type == 33) {
1264 $lrow = sqlQuery("SELECT title FROM list_options " .
1265 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1266 $s = htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1267 //For lists Race and Ethnicity if there is no matching value in the corresponding lists check ethrace list
1268 if ($lrow == 0 && $data_type == 33)
1271 $lrow_ethrace = sqlQuery("SELECT title FROM list_options " .
1272 "WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue) );
1273 $s = htmlspecialchars(xl_list_label($lrow_ethrace['title']),ENT_NOQUOTES
);
1277 // simple text field
1278 else if ($data_type == 2) {
1279 $s = htmlspecialchars($currvalue,ENT_NOQUOTES
);
1282 // long or multi-line text field
1283 else if ($data_type == 3) {
1284 $s = nl2br(htmlspecialchars($currvalue,ENT_NOQUOTES
));
1288 else if ($data_type == 4) {
1289 $s = htmlspecialchars(oeFormatShortDate($currvalue),ENT_NOQUOTES
);
1293 else if ($data_type == 10 ||
$data_type == 11) {
1294 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1295 "WHERE id = ?", array($currvalue) );
1296 $s = htmlspecialchars(ucwords($urow['fname'] . " " . $urow['lname']),ENT_NOQUOTES
);
1300 else if ($data_type == 12) {
1301 $pres = get_pharmacies();
1302 while ($prow = sqlFetchArray($pres)) {
1304 if ($currvalue == $key) {
1305 $s .= htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' .
1306 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
1307 $prow['line1'] . ' / ' . $prow['city'],ENT_NOQUOTES
);
1313 else if ($data_type == 13) {
1314 $squads = acl_get_squads();
1316 foreach ($squads as $key => $value) {
1317 if ($currvalue == $key) {
1318 $s .= htmlspecialchars($value[3],ENT_NOQUOTES
);
1325 else if ($data_type == 14) {
1326 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
1327 "WHERE id = ?", array($currvalue));
1328 $uname = $urow['lname'];
1329 if ($urow['fname']) $uname .= ", " . $urow['fname'];
1330 $s = htmlspecialchars($uname,ENT_NOQUOTES
);
1334 else if ($data_type == 15) {
1335 $s = htmlspecialchars($currvalue,ENT_NOQUOTES
);
1338 // a set of labeled checkboxes
1339 else if ($data_type == 21) {
1340 $avalue = explode('|', $currvalue);
1341 $lres = sqlStatement("SELECT * FROM list_options " .
1342 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1344 while ($lrow = sqlFetchArray($lres)) {
1345 $option_id = $lrow['option_id'];
1346 if (in_array($option_id, $avalue)) {
1347 if ($count++
) $s .= "<br />";
1349 // Added 5-09 by BM - Translate label if applicable
1350 $s .= htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
);
1356 // a set of labeled text input fields
1357 else if ($data_type == 22) {
1358 $tmp = explode('|', $currvalue);
1360 foreach ($tmp as $value) {
1361 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1362 $avalue[$matches[1]] = $matches[2];
1365 $lres = sqlStatement("SELECT * FROM list_options " .
1366 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1367 $s .= "<table cellpadding='0' cellspacing='0'>";
1368 while ($lrow = sqlFetchArray($lres)) {
1369 $option_id = $lrow['option_id'];
1370 if (empty($avalue[$option_id])) continue;
1372 // Added 5-09 by BM - Translate label if applicable
1373 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . ": </td>";
1375 $s .= "<td class='text' valign='top'>" . htmlspecialchars($avalue[$option_id],ENT_NOQUOTES
) . "</td></tr>";
1380 // a set of exam results; 3 radio buttons and a text field:
1381 else if ($data_type == 23) {
1382 $tmp = explode('|', $currvalue);
1384 foreach ($tmp as $value) {
1385 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1386 $avalue[$matches[1]] = $matches[2];
1389 $lres = sqlStatement("SELECT * FROM list_options " .
1390 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1391 $s .= "<table cellpadding='0' cellspacing='0'>";
1392 while ($lrow = sqlFetchArray($lres)) {
1393 $option_id = $lrow['option_id'];
1394 $restype = substr($avalue[$option_id], 0, 1);
1395 $resnote = substr($avalue[$option_id], 2);
1396 if (empty($restype) && empty($resnote)) continue;
1398 // Added 5-09 by BM - Translate label if applicable
1399 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1401 $restype = ($restype == '1') ?
xl('Normal') : (($restype == '2') ?
xl('Abnormal') : xl('N/A'));
1402 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1403 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1404 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . " </td>";
1405 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td>";
1411 // the list of active allergies for the current patient
1412 else if ($data_type == 24) {
1413 $query = "SELECT title, comments FROM lists WHERE " .
1414 "pid = ? AND type = 'allergy' AND enddate IS NULL " .
1416 // echo "<!-- $query -->\n"; // debugging
1417 $lres = sqlStatement($query, array($GLOBALS['pid']) );
1419 while ($lrow = sqlFetchArray($lres)) {
1420 if ($count++
) $s .= "<br />";
1421 $s .= htmlspecialchars($lrow['title'],ENT_NOQUOTES
);
1422 if ($lrow['comments']) $s .= ' (' . htmlspecialchars($lrow['comments'],ENT_NOQUOTES
) . ')';
1426 // a set of labeled checkboxes, each with a text field:
1427 else if ($data_type == 25) {
1428 $tmp = explode('|', $currvalue);
1430 foreach ($tmp as $value) {
1431 if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
1432 $avalue[$matches[1]] = $matches[2];
1435 $lres = sqlStatement("SELECT * FROM list_options " .
1436 "WHERE list_id = ? ORDER BY seq, title", array($list_id) );
1437 $s .= "<table cellpadding='0' cellspacing='0'>";
1438 while ($lrow = sqlFetchArray($lres)) {
1439 $option_id = $lrow['option_id'];
1440 $restype = substr($avalue[$option_id], 0, 1);
1441 $resnote = substr($avalue[$option_id], 2);
1442 if (empty($restype) && empty($resnote)) continue;
1444 // Added 5-09 by BM - Translate label if applicable
1445 $s .= "<tr><td class='bold' valign='top'>" . htmlspecialchars(xl_list_label($lrow['title']),ENT_NOQUOTES
) . " </td>";
1447 $restype = $restype ?
xl('Yes') : xl('No');
1448 $s .= "<td class='text' valign='top'>" . htmlspecialchars($restype,ENT_NOQUOTES
) . "</td></tr>";
1449 $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . "</td></tr>";
1455 // special case for history of lifestyle status; 3 radio buttons and a date text field:
1456 // VicarePlus :: A selection list for smoking status.
1457 else if ($data_type == 28 ||
$data_type == 32) {
1458 $tmp = explode('|', $currvalue);
1459 switch(count($tmp)) {
1478 $resdate = $restype = "";
1481 $restype = $resdate = $resnote = "";
1484 $s .= "<table cellpadding='0' cellspacing='0'>";
1488 if ($restype == "current".$field_id) $res = xl('Current');
1489 if ($restype == "quit".$field_id) $res = xl('Quit');
1490 if ($restype == "never".$field_id) $res = xl('Never');
1491 if ($restype == "not_applicable".$field_id) $res = xl('N/A');
1492 // $s .= "<td class='text' valign='top'>$restype</td></tr>";
1493 // $s .= "<td class='text' valign='top'>$resnote</td></tr>";
1494 if ($data_type == 28)
1496 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . " </td>";
1498 //VicarePlus :: Tobacco field has a listbox, text box, date field and 3 radio buttons.
1499 else if ($data_type == 32)
1501 if (!empty($reslist)) $s .= "<td class='text' valign='top'>" . generate_display_field(array('data_type'=>'1','list_id'=>$list_id),$reslist) . " </td>";
1502 if (!empty($resnote)) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resnote,ENT_NOQUOTES
) . " </td>";
1505 if (!empty($res)) $s .= "<td class='text' valign='top'><b>" . htmlspecialchars(xl('Status'),ENT_NOQUOTES
) . "</b>: " . htmlspecialchars($res,ENT_NOQUOTES
) . " </td>";
1506 if ($restype == "quit".$field_id) $s .= "<td class='text' valign='top'>" . htmlspecialchars($resdate,ENT_NOQUOTES
) . " </td>";
1511 // static text. read-only, of course.
1512 else if ($data_type == 31) {
1513 $s .= nl2br($frow['description']);
1516 else if($data_type == 34){
1517 $arr = explode("|*|*|*|",$currvalue);
1518 for($i=0;$i<sizeof($arr);$i++
){
1524 else if ($data_type == 35) {
1525 $urow = sqlQuery("SELECT id, name FROM facility ".
1526 "WHERE id = ?", array($currvalue) );
1527 $s = htmlspecialchars($urow['name'],ENT_NOQUOTES
);
1533 $CPR = 4; // cells per row of generic data
1538 function disp_end_cell() {
1539 global $item_count, $cell_count;
1540 if ($item_count > 0) {
1546 function disp_end_row() {
1547 global $cell_count, $CPR;
1549 if ($cell_count > 0) {
1550 for (; $cell_count < $CPR; ++
$cell_count) echo "<td></td>";
1556 function disp_end_group() {
1558 if (strlen($last_group) > 0) {
1563 function display_layout_rows($formtype, $result1, $result2='') {
1564 global $item_count, $cell_count, $last_group, $CPR;
1566 $fres = sqlStatement("SELECT * FROM layout_options " .
1567 "WHERE form_id = ? AND uor > 0 " .
1568 "ORDER BY group_name, seq", array($formtype) );
1570 while ($frow = sqlFetchArray($fres)) {
1571 $this_group = $frow['group_name'];
1572 $titlecols = $frow['titlecols'];
1573 $datacols = $frow['datacols'];
1574 $data_type = $frow['data_type'];
1575 $field_id = $frow['field_id'];
1576 $list_id = $frow['list_id'];
1579 if ($formtype == 'DEM') {
1580 if ($GLOBALS['athletic_team']) {
1581 // Skip fitness level and return-to-play date because those appear
1582 // in a special display/update form on this page.
1583 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
1585 if (strpos($field_id, 'em_') === 0) {
1586 // Skip employer related fields, if it's disabled.
1587 if ($GLOBALS['omit_employers']) continue;
1588 $tmp = substr($field_id, 3);
1589 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1592 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1596 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1599 // Handle a data category (group) change.
1600 if (strcmp($this_group, $last_group) != 0) {
1601 $group_name = substr($this_group, 1);
1602 // totally skip generating the employer category, if it's disabled.
1603 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1605 $last_group = $this_group;
1608 // Handle starting of a new row.
1609 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
1613 echo "<td class='groupname'>";
1614 //echo "<td class='groupname' style='padding-right:5pt' valign='top'>";
1615 //echo "<font color='#008800'>$group_name</font>";
1617 // Added 5-09 by BM - Translate label if applicable
1618 echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
);
1622 //echo "<td class='' style='padding-right:5pt' valign='top'>";
1623 echo "<td valign='top'> ";
1628 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
1630 // Handle starting of a new label cell.
1631 if ($titlecols > 0) {
1633 //echo "<td class='label' colspan='$titlecols' valign='top'";
1634 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
1635 echo "<td class='label' colspan='$titlecols_esc' ";
1636 //if ($cell_count == 2) echo " style='padding-left:10pt'";
1638 $cell_count +
= $titlecols;
1642 // Added 5-09 by BM - Translate label if applicable
1643 if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']).":",ENT_NOQUOTES
); else echo " ";
1645 // Handle starting of a new data cell.
1646 if ($datacols > 0) {
1648 //echo "<td class='text data' colspan='$datacols' valign='top'";
1649 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
1650 echo "<td class='text data' colspan='$datacols_esc'";
1651 //if ($cell_count > 0) echo " style='padding-left:5pt'";
1653 $cell_count +
= $datacols;
1657 echo generate_display_field($frow, $currvalue);
1663 function display_layout_tabs($formtype, $result1, $result2='') {
1664 global $item_count, $cell_count, $last_group, $CPR;
1666 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1667 "WHERE form_id = ? AND uor > 0 " .
1668 "ORDER BY group_name, seq", array($formtype) );
1671 while ($frow = sqlFetchArray($fres)) {
1672 $this_group = $frow['group_name'];
1673 $group_name = substr($this_group, 1);
1675 <li
<?php
echo $first ?
'class="current"' : '' ?
>>
1676 <a href
="/play/javascript-tabbed-navigation/" id
="header_tab_<?php echo ".htmlspecialchars($group_name,ENT_QUOTES
)."?>">
1677 <?php
echo htmlspecialchars(xl_layout_label($group_name),ENT_NOQUOTES
); ?
></a
>
1684 function display_layout_tabs_data($formtype, $result1, $result2='') {
1685 global $item_count, $cell_count, $last_group, $CPR;
1687 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1688 "WHERE form_id = ? AND uor > 0 " .
1689 "ORDER BY group_name, seq", array($formtype));
1692 while ($frow = sqlFetchArray($fres)) {
1693 $this_group = isset($frow['group_name']) ?
$frow['group_name'] : "" ;
1694 $titlecols = isset($frow['titlecols']) ?
$frow['titlecols'] : "";
1695 $datacols = isset($frow['datacols']) ?
$frow['datacols'] : "";
1696 $data_type = isset($frow['data_type']) ?
$frow['data_type'] : "";
1697 $field_id = isset($frow['field_id']) ?
$frow['field_id'] : "";
1698 $list_id = isset($frow['list_id']) ?
$frow['list_id'] : "";
1701 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1702 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1703 "ORDER BY seq", array($formtype, $this_group) );
1706 <div
class="tab <?php echo $first ? 'current' : '' ?>">
1707 <table border
='0' cellpadding
='0'>
1710 while ($group_fields = sqlFetchArray($group_fields_query)) {
1712 $titlecols = $group_fields['titlecols'];
1713 $datacols = $group_fields['datacols'];
1714 $data_type = $group_fields['data_type'];
1715 $field_id = $group_fields['field_id'];
1716 $list_id = $group_fields['list_id'];
1719 if ($formtype == 'DEM') {
1720 if ($GLOBALS['athletic_team']) {
1721 // Skip fitness level and return-to-play date because those appear
1722 // in a special display/update form on this page.
1723 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
1725 if (strpos($field_id, 'em_') === 0) {
1726 // Skip employer related fields, if it's disabled.
1727 if ($GLOBALS['omit_employers']) continue;
1728 $tmp = substr($field_id, 3);
1729 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1732 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1736 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1739 // Handle a data category (group) change.
1740 if (strcmp($this_group, $last_group) != 0) {
1741 $group_name = substr($this_group, 1);
1742 // totally skip generating the employer category, if it's disabled.
1743 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1744 $last_group = $this_group;
1747 // Handle starting of a new row.
1748 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
1753 if ($item_count == 0 && $titlecols == 0) {
1757 // Handle starting of a new label cell.
1758 if ($titlecols > 0) {
1760 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
1761 echo "<td class='label' colspan='$titlecols_esc' ";
1763 $cell_count +
= $titlecols;
1767 // Added 5-09 by BM - Translate label if applicable
1768 if ($group_fields['title']) echo htmlspecialchars(xl_layout_label($group_fields['title']).":",ENT_NOQUOTES
); else echo " ";
1770 // Handle starting of a new data cell.
1771 if ($datacols > 0) {
1773 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
1774 echo "<td class='text data' colspan='$datacols_esc'";
1776 $cell_count +
= $datacols;
1780 echo generate_display_field($group_fields, $currvalue);
1797 function display_layout_tabs_data_editable($formtype, $result1, $result2='') {
1798 global $item_count, $cell_count, $last_group, $CPR;
1800 $fres = sqlStatement("SELECT distinct group_name FROM layout_options " .
1801 "WHERE form_id = ? AND uor > 0 " .
1802 "ORDER BY group_name, seq", array($formtype) );
1805 while ($frow = sqlFetchArray($fres)) {
1806 $this_group = $frow['group_name'];
1807 $group_name = substr($this_group, 1);
1808 $group_name_esc = htmlspecialchars( $group_name, ENT_QUOTES
);
1809 $titlecols = $frow['titlecols'];
1810 $datacols = $frow['datacols'];
1811 $data_type = $frow['data_type'];
1812 $field_id = $frow['field_id'];
1813 $list_id = $frow['list_id'];
1816 $group_fields_query = sqlStatement("SELECT * FROM layout_options " .
1817 "WHERE form_id = ? AND uor > 0 AND group_name = ? " .
1818 "ORDER BY seq", array($formtype,$this_group) );
1821 <div
class="tab <?php echo $first ? 'current' : '' ?>" id
="tab_<?php echo $group_name_esc?>" >
1822 <table border
='0' cellpadding
='0'>
1825 while ($group_fields = sqlFetchArray($group_fields_query)) {
1827 $titlecols = $group_fields['titlecols'];
1828 $datacols = $group_fields['datacols'];
1829 $data_type = $group_fields['data_type'];
1830 $field_id = $group_fields['field_id'];
1831 $list_id = $group_fields['list_id'];
1834 if ($formtype == 'DEM') {
1835 if ($GLOBALS['athletic_team']) {
1836 // Skip fitness level and return-to-play date because those appear
1837 // in a special display/update form on this page.
1838 if ($field_id === 'fitness' ||
$field_id === 'userdate1') continue;
1840 if (strpos($field_id, 'em_') === 0) {
1841 // Skip employer related fields, if it's disabled.
1842 if ($GLOBALS['omit_employers']) continue;
1843 $tmp = substr($field_id, 3);
1844 if (isset($result2[$tmp])) $currvalue = $result2[$tmp];
1847 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1851 if (isset($result1[$field_id])) $currvalue = $result1[$field_id];
1854 // Handle a data category (group) change.
1855 if (strcmp($this_group, $last_group) != 0) {
1856 $group_name = substr($this_group, 1);
1857 // totally skip generating the employer category, if it's disabled.
1858 if ($group_name === 'Employer' && $GLOBALS['omit_employers']) continue;
1859 $last_group = $this_group;
1862 // Handle starting of a new row.
1863 if (($titlecols > 0 && $cell_count >= $CPR) ||
$cell_count == 0) {
1868 if ($item_count == 0 && $titlecols == 0) {
1872 // Handle starting of a new label cell.
1873 if ($titlecols > 0) {
1875 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES
);
1876 echo "<td class='label' colspan='$titlecols_esc' ";
1878 $cell_count +
= $titlecols;
1882 // Added 5-09 by BM - Translate label if applicable
1883 if ($group_fields['title']) echo (htmlspecialchars( xl_layout_label($group_fields['title']), ENT_NOQUOTES
).":"); else echo " ";
1885 // Handle starting of a new data cell.
1886 if ($datacols > 0) {
1888 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES
);
1889 echo "<td class='text data' colspan='$datacols_esc'";
1891 $cell_count +
= $datacols;
1895 echo generate_form_field($group_fields, $currvalue);
1909 // From the currently posted HTML form, this gets the value of the
1910 // field corresponding to the provided layout_options table row.
1912 function get_layout_form_value($frow, $maxlength=255) {
1913 // Bring in $sanitize_all_escapes variable, which will decide
1914 // the variable escaping method.
1915 global $sanitize_all_escapes;
1917 $data_type = $frow['data_type'];
1918 $field_id = $frow['field_id'];
1920 if (isset($_POST["form_$field_id"])) {
1921 if ($data_type == 21) {
1922 // $_POST["form_$field_id"] is an array of checkboxes and its keys
1923 // must be concatenated into a |-separated string.
1924 foreach ($_POST["form_$field_id"] as $key => $val) {
1925 if (strlen($value)) $value .= '|';
1929 else if ($data_type == 22) {
1930 // $_POST["form_$field_id"] is an array of text fields to be imploded
1931 // into "key:value|key:value|...".
1932 foreach ($_POST["form_$field_id"] as $key => $val) {
1933 $val = str_replace('|', ' ', $val);
1934 if (strlen($value)) $value .= '|';
1935 $value .= "$key:$val";
1938 else if ($data_type == 23) {
1939 // $_POST["form_$field_id"] is an array of text fields with companion
1940 // radio buttons to be imploded into "key:n:notes|key:n:notes|...".
1941 foreach ($_POST["form_$field_id"] as $key => $val) {
1942 $restype = $_POST["radio_{$field_id}"][$key];
1943 if (empty($restype)) $restype = '0';
1944 $val = str_replace('|', ' ', $val);
1945 if (strlen($value)) $value .= '|';
1946 $value .= "$key:$restype:$val";
1949 else if ($data_type == 25) {
1950 // $_POST["form_$field_id"] is an array of text fields with companion
1951 // checkboxes to be imploded into "key:n:notes|key:n:notes|...".
1952 foreach ($_POST["form_$field_id"] as $key => $val) {
1953 $restype = empty($_POST["check_{$field_id}"][$key]) ?
'0' : '1';
1954 $val = str_replace('|', ' ', $val);
1955 if (strlen($value)) $value .= '|';
1956 $value .= "$key:$restype:$val";
1959 else if ($data_type == 28 ||
$data_type == 32) {
1960 // $_POST["form_$field_id"] is an date text fields with companion
1961 // radio buttons to be imploded into "notes|type|date".
1962 $restype = $_POST["radio_{$field_id}"];
1963 if (empty($restype)) $restype = '0';
1964 $resdate = str_replace('|', ' ', $_POST["date_$field_id"]);
1965 $resnote = str_replace('|', ' ', $_POST["form_$field_id"]);
1966 if ($data_type == 32)
1968 //VicarePlus :: Smoking status data is imploded into "note|type|date|list".
1969 $reslist = str_replace('|', ' ', $_POST["form_$field_id"]);
1970 $res_text_note = str_replace('|', ' ', $_POST["form_text_$field_id"]);
1971 $value = "$res_text_note|$restype|$resdate|$reslist";
1974 $value = "$resnote|$restype|$resdate";
1977 $value = $_POST["form_$field_id"];
1981 // Better to die than to silently truncate data!
1982 if ($maxlength && ($data_type != 3 && $data_type != 34) && strlen($value) > $maxlength)
1983 die(htmlspecialchars( xl('ERROR: Field') . " '$field_id' " . xl('is too long'), ENT_NOQUOTES
) .
1984 ":<br /> <br />".htmlspecialchars( $value, ENT_NOQUOTES
));
1986 // Make sure the return value is quote-safe.
1987 if ($sanitize_all_escapes) {
1988 //escapes already removed and using binding/placemarks in sql calls
1989 // so only need to trim value
1990 return trim($value);
1993 //need to explicitly prepare value
1994 return formTrim($value);
1998 // Generate JavaScript validation logic for the required fields.
2000 function generate_layout_validation($form_id) {
2001 $fres = sqlStatement("SELECT * FROM layout_options " .
2002 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
2003 "ORDER BY group_name, seq", array($form_id) );
2005 while ($frow = sqlFetchArray($fres)) {
2006 if ($frow['uor'] < 2) continue;
2007 $data_type = $frow['data_type'];
2008 $field_id = $frow['field_id'];
2009 $fldtitle = $frow['title'];
2010 if (!$fldtitle) $fldtitle = $frow['description'];
2011 $fldname = htmlspecialchars( "form_$field_id", ENT_QUOTES
);
2012 switch($data_type) {
2021 " if (f.$fldname.selectedIndex <= 0) {\n" .
2022 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2023 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
2026 case 27: // radio buttons
2029 " for (; i < f.$fldname.length; ++i) if (f.$fldname[i].checked) break;\n" .
2030 " if (i >= f.$fldname.length) {\n" .
2031 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
2039 " if (trimlen(f.$fldname.value) == 0) {\n" .
2040 " if (f.$fldname.focus) f.$fldname.focus();\n" .
2041 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color','red'); } ); " .
2042 " $('#" . $fldname . "').attr('style','background:red'); \n" .
2043 " errMsgs[errMsgs.length] = '" . htmlspecialchars( (xl_layout_label($fldtitle)), ENT_QUOTES
) . "'; \n" .
2045 " $('#" . $fldname . "').attr('style',''); " .
2046 " $('#" . $fldname . "').parents('div.tab').each( function(){ var tabHeader = $('#header_' + $(this).attr('id') ); tabHeader.css('color',''); } ); " .
2054 * DROPDOWN FOR FACILITIES
2056 * build a dropdown with all facilities
2058 * @param string $selected - name of the currently selected facility
2059 * use '0' for "unspecified facility"
2060 * use '' for "All facilities" (the default)
2061 * @param string $name - the name/id for select form (defaults to "form_facility")
2062 * @param boolean $allow_unspecified - include an option for "unspecified" facility
2064 * @return void - just echo the html encoded string
2066 * Note: This should become a data-type at some point, according to Brady
2068 function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = true, $allow_allfacilities = true) {
2069 $have_selected = false;
2070 $query = "SELECT id, name FROM facility ORDER BY name";
2071 $fres = sqlStatement($query);
2073 $name = htmlspecialchars($name, ENT_QUOTES
);
2074 echo " <select name=\"$name\" id=\"$name\">\n";
2076 if ($allow_allfacilities) {
2078 $option_selected_attr = '';
2079 if ($selected == '') {
2080 $option_selected_attr = ' selected="selected"';
2081 $have_selected = true;
2083 $option_content = htmlspecialchars('-- ' . xl('All Facilities') . ' --', ENT_NOQUOTES
);
2084 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2085 } elseif ($allow_unspecified) {
2086 $option_value = '0';
2087 $option_selected_attr = '';
2088 if ( $selected == '0' ) {
2089 $option_selected_attr = ' selected="selected"';
2090 $have_selected = true;
2092 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
2093 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2096 while ($frow = sqlFetchArray($fres)) {
2097 $facility_id = $frow['id'];
2098 $option_value = htmlspecialchars($facility_id, ENT_QUOTES
);
2099 $option_selected_attr = '';
2100 if ($selected == $facility_id) {
2101 $option_selected_attr = ' selected="selected"';
2102 $have_selected = true;
2104 $option_content = htmlspecialchars($frow['name'], ENT_NOQUOTES
);
2105 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2108 if ($allow_unspecified && $allow_allfacilities) {
2109 $option_value = '0';
2110 $option_selected_attr = '';
2111 if ( $selected == '0' ) {
2112 $option_selected_attr = ' selected="selected"';
2113 $have_selected = true;
2115 $option_content = htmlspecialchars('-- ' . xl('Unspecified') . ' --', ENT_NOQUOTES
);
2116 echo " <option value=\"$option_value\" $option_selected_attr>$option_content</option>\n";
2119 if (!$have_selected) {
2120 $option_value = htmlspecialchars($selected, ENT_QUOTES
);
2121 $option_label = htmlspecialchars('(' . xl('Do not change') . ')', ENT_QUOTES
);
2122 $option_content = htmlspecialchars(xl('Missing or Invalid'), ENT_NOQUOTES
);
2123 echo " <option value='$option_value' label='$option_label' selected='selected'>$option_content</option>\n";
2125 echo " </select>\n";
2128 // Expand Collapse Widget
2129 // This forms the header and functionality component of the widget. The information that is displayed
2130 // then follows this function followed by a closing div tag
2132 // $title is the title of the section (already translated)
2133 // $label is identifier used in the tag id's and sql columns
2134 // $buttonLabel is the button label text (already translated)
2135 // $buttonLink is the button link information
2136 // $buttonClass is any additional needed class elements for the button tag
2137 // $linkMethod is the button link method ('javascript' vs 'html')
2138 // $bodyClass is to set class(es) of the body
2139 // $auth is a flag to decide whether to show the button
2140 // $fixedWidth is to flag whether width is fixed
2141 // $forceExpandAlways is a flag to force the widget to always be expanded
2143 function expand_collapse_widget($title, $label, $buttonLabel, $buttonLink, $buttonClass, $linkMethod, $bodyClass, $auth, $fixedWidth, $forceExpandAlways=false) {
2145 echo "<div class='section-header'>";
2148 echo "<div class='section-header-dynamic'>";
2152 // show button, since authorized
2153 // first prepare class string
2155 $class_string = "css_button_small ".htmlspecialchars( $buttonClass, ENT_NOQUOTES
);
2158 $class_string = "css_button_small";
2160 // next, create the link
2161 if ($linkMethod == "javascript") {
2162 echo "<td><a class='" . $class_string . "' href='javascript:;' onclick='" . $buttonLink . "'";
2165 echo "<td><a class='" . $class_string . "' href='" . $buttonLink . "'";
2166 if (!isset($_SESSION['patient_portal_onsite'])) {
2167 // prevent an error from occuring when calling the function from the patient portal
2168 echo " onclick='top.restoreSession()'";
2171 if (!$GLOBALS['concurrent_layout']) {
2172 echo " target='Main'";
2175 htmlspecialchars( $buttonLabel, ENT_NOQUOTES
) . "</span></a></td>";
2177 if ($forceExpandAlways){
2178 // Special case to force the widget to always be expanded
2179 echo "<td><span class='text'><b>" . htmlspecialchars( $title, ENT_NOQUOTES
) . "</b></span>";
2180 $indicatorTag ="style='display:none'";
2182 $indicatorTag = isset($indicatorTag) ?
$indicatorTag : "";
2183 echo "<td><a " . $indicatorTag . " href='javascript:;' class='small' onclick='toggleIndicator(this,\"" .
2184 htmlspecialchars( $label, ENT_QUOTES
) . "_ps_expand\")'><span class='text'><b>";
2185 echo htmlspecialchars( $title, ENT_NOQUOTES
) . "</b></span>";
2187 if (isset($_SESSION['patient_portal_onsite'])) {
2188 // collapse all entries in the patient portal
2189 $text = xl('expand');
2191 else if (getUserSetting($label."_ps_expand")) {
2192 $text = xl('collapse');
2195 $text = xl('expand');
2197 echo " (<span class='indicator'>" . htmlspecialchars($text, ENT_QUOTES
) .
2198 "</span>)</a></td>";
2199 echo "</tr></table>";
2201 if ($forceExpandAlways) {
2202 // Special case to force the widget to always be expanded
2205 else if (isset($_SESSION['patient_portal_onsite'])) {
2206 // collapse all entries in the patient portal
2207 $styling = "style='display:none'";
2209 else if (getUserSetting($label."_ps_expand")) {
2213 $styling = "style='display:none'";
2216 $styling .= " class='" . $bodyClass . "'";
2218 //next, create the first div tag to hold the information
2219 // note the code that calls this function will then place the ending div tag after the data
2220 echo "<div id='" . htmlspecialchars( $label, ENT_QUOTES
) . "_ps_expand' " . $styling . ">";
2223 //billing_facility fuction will give the dropdown list which contain billing faciliies.
2224 function billing_facility($name,$select){
2225 $qsql = sqlStatement("SELECT id, name FROM facility WHERE billing_location = 1");
2226 echo " <select id='".htmlspecialchars($name, ENT_QUOTES
)."' name='".htmlspecialchars($name, ENT_QUOTES
)."'>";
2227 while ($facrow = sqlFetchArray($qsql)) {
2228 $selected = ( $facrow['id'] == $select ) ?
'selected="selected"' : '' ;
2229 echo "<option value=".htmlspecialchars($facrow['id'],ENT_QUOTES
)." $selected>".htmlspecialchars($facrow['name'], ENT_QUOTES
)."</option>";