function generate_form_field($frow, $currvalue) { global $rootdir, $date_init, $ISSUE_TYPES, $code_types; $currescaped = htmlspecialchars($currvalue, ENT_QUOTES); $data_type = $frow['data_type']; $field_id = $frow['field_id']; $list_id = $frow['list_id']; $backup_list = $frow['list_backup_id']; // escaped variables to use in html $field_id_esc = htmlspecialchars($field_id, ENT_QUOTES); $list_id_esc = htmlspecialchars($list_id, ENT_QUOTES); // Added 5-09 by BM - Translate description if applicable $description = isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : ''; // Support edit option T which assigns the (possibly very long) description as // the default value. if (strpos($frow['edit_options'], 'T') !== FALSE) { if (strlen($currescaped) == 0) { $currescaped = $description; } // Description used in this way is not suitable as a title. $description = ''; } // added 5-2009 by BM to allow modification of the 'empty' text title field. // Can pass $frow['empty_title'] with this variable, otherwise // will default to 'Unassigned'. // modified 6-2009 by BM to allow complete skipping of the 'empty' text title // if make $frow['empty_title'] equal to 'SKIP' $showEmpty = true; if (isset($frow['empty_title'])) { if ($frow['empty_title'] == "SKIP") { //do not display an 'empty' choice $showEmpty = false; $empty_title = "Unassigned"; } else { $empty_title = $frow['empty_title']; } } else { $empty_title = "Unassigned"; } $disabled = strpos($frow['edit_options'], '0') === FALSE ? '' : 'disabled'; $lbfchange = strpos($frow['form_id'], 'LBF') === 0 ? "checkSkipConditions();" : ""; $lbfonchange = $lbfchange ? "onchange='{$lbfchange}'" : ""; // generic single-selection list or Race and Ethnicity. // These data types support backup lists. if ($data_type == 1 || $data_type == 33) { echo generate_select_list("form_{$field_id}", $list_id, $currvalue, $description, $showEmpty ? $empty_title : '', '', $lbfchange, '', $disabled ? array('disabled' => 'disabled') : null, false, $backup_list); } else { if ($data_type == 2) { $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES); $maxlength = $frow['max_length']; $string_maxlength = ""; // if max_length is set to zero, then do not set a maxlength if ($maxlength) { $string_maxlength = "maxlength='" . attr($maxlength) . "'"; } echo "<input type='text'" . " name='form_{$field_id_esc}'" . " id='form_{$field_id_esc}'" . " size='{$fldlength}'" . " {$string_maxlength}" . " title='{$description}'" . " value='{$currescaped}'"; $tmp = $lbfchange; if (strpos($frow['edit_options'], 'C') !== FALSE) { $tmp .= "capitalizeMe(this);"; } else { if (strpos($frow['edit_options'], 'U') !== FALSE) { $tmp .= "this.value = this.value.toUpperCase();"; } } if ($tmp) { echo " onchange='{$tmp}'"; } $tmp = htmlspecialchars($GLOBALS['gbl_mask_patient_id'], ENT_QUOTES); if ($field_id == 'pubpid' && strlen($tmp) > 0) { echo " onkeyup='maskkeyup(this,\"{$tmp}\")'"; echo " onblur='maskblur(this,\"{$tmp}\")'"; } if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) { echo " readonly"; } if ($disabled) { echo ' disabled'; } echo " />"; } else { if ($data_type == 3) { $textCols = htmlspecialchars($frow['fld_length'], ENT_QUOTES); $textRows = htmlspecialchars($frow['fld_rows'], ENT_QUOTES); echo "<textarea" . " name='form_{$field_id_esc}'" . " id='form_{$field_id_esc}'" . " title='{$description}'" . " cols='{$textCols}'" . " rows='{$textRows}' {$lbfonchange} {$disabled}" . ">" . $currescaped . "</textarea>"; } else { if ($data_type == 4) { $age_asof_date = ''; // optionalAge() sets this $age_format = strpos($frow['edit_options'], 'A') === FALSE ? 3 : 0; $agestr = optionalAge($frow, $currvalue, $age_asof_date); if ($agestr) { echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>"; } echo "<input type='text' size='10' name='form_{$field_id_esc}' id='form_{$field_id_esc}'" . " value='" . substr($currescaped, 0, 10) . "'"; if (!$agestr) { echo " title='{$description}'"; } echo " {$lbfonchange} onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' {$disabled} />"; if (!$disabled) { echo "<img src='{$rootdir}/pic/show_calendar.gif' align='absbottom' width='24' height='22'" . " id='img_{$field_id_esc}' border='0' alt='[?]' style='cursor:pointer'" . " title='" . htmlspecialchars(xl('Click here to choose a date'), ENT_QUOTES) . "' />"; $date_init .= " Calendar.setup({" . "inputField:'form_{$field_id}', " . "ifFormat:'%Y-%m-%d', "; if ($agestr) { $date_init .= "onUpdate: function() {" . "if (typeof(updateAgeString) == 'function') updateAgeString('{$field_id}','{$age_asof_date}', {$age_format});" . "}, "; } $date_init .= "button:'img_{$field_id}'})\n"; } // Optional display of age or gestational age. if ($agestr) { echo "</td></tr><tr><td id='span_{$field_id}' class='text'>" . text($agestr) . "</td></tr></table>"; } } else { if ($data_type == 10) { $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " . "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " . "AND authorized = 1 " . "ORDER BY lname, fname"); echo "<select name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}' {$lbfonchange} {$disabled}>"; echo "<option value=''>" . xlt($empty_title) . "</option>"; $got_selected = false; while ($urow = sqlFetchArray($ures)) { $uname = text($urow['fname'] . ' ' . $urow['lname']); $optionId = attr($urow['id']); echo "<option value='{$optionId}'"; if ($urow['id'] == $currvalue) { echo " selected"; $got_selected = true; } echo ">{$uname}</option>"; } if (!$got_selected && $currvalue) { echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>"; echo "</select>"; echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>"; } else { echo "</select>"; } } else { if ($data_type == 11) { $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " . "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " . "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " . "ORDER BY lname, fname"); echo "<select name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}'"; echo " {$lbfonchange} {$disabled}>"; echo "<option value=''>" . xlt('Unassigned') . "</option>"; $got_selected = false; while ($urow = sqlFetchArray($ures)) { $uname = text($urow['fname'] . ' ' . $urow['lname']); $optionId = attr($urow['id']); echo "<option value='{$optionId}'"; if ($urow['id'] == $currvalue) { echo " selected"; $got_selected = true; } echo ">{$uname}</option>"; } if (!$got_selected && $currvalue) { echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>"; echo "</select>"; echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>"; } else { echo "</select>"; } } else { if ($data_type == 12) { echo "<select name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}'"; echo " {$lbfonchange} {$disabled}>"; echo "<option value='0'></option>"; $pres = get_pharmacies(); $got_selected = false; while ($prow = sqlFetchArray($pres)) { $key = $prow['id']; $optionValue = htmlspecialchars($key, ENT_QUOTES); $optionLabel = htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' . $prow['prefix'] . '-' . $prow['number'] . ' / ' . $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES); echo "<option value='{$optionValue}'"; if ($currvalue == $key) { echo " selected"; $got_selected = true; } echo ">{$optionLabel}</option>"; } if (!$got_selected && $currvalue) { echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>"; echo "</select>"; echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>"; } else { echo "</select>"; } } else { if ($data_type == 13) { echo "<select name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}'"; echo " {$lbfonchange} {$disabled}>"; echo "<option value=''> </option>"; $squads = acl_get_squads(); if ($squads) { foreach ($squads as $key => $value) { $optionValue = htmlspecialchars($key, ENT_QUOTES); $optionLabel = htmlspecialchars($value[3], ENT_NOQUOTES); echo "<option value='{$optionValue}'"; if ($currvalue == $key) { echo " selected"; } echo ">{$optionLabel}</option>\n"; } } echo "</select>"; } else { if ($data_type == 14) { if (strpos($frow['edit_options'], 'L') !== FALSE) { $tmp = "abook_type = 'ord_lab'"; } else { if (strpos($frow['edit_options'], 'O') !== FALSE) { $tmp = "abook_type LIKE 'ord\\_%'"; } else { if (strpos($frow['edit_options'], 'V') !== FALSE) { $tmp = "abook_type LIKE 'vendor%'"; } else { if (strpos($frow['edit_options'], 'R') !== FALSE) { $tmp = "abook_type LIKE 'dist'"; } else { $tmp = "( username = '' OR authorized = 1 )"; } } } } $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " . "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " . "AND {$tmp} " . "ORDER BY organization, lname, fname"); echo "<select name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}'"; echo " {$lbfonchange} {$disabled}>"; echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES) . "</option>"; while ($urow = sqlFetchArray($ures)) { $uname = $urow['organization']; if (empty($uname) || substr($uname, 0, 1) == '(') { $uname = $urow['lname']; if ($urow['fname']) { $uname .= ", " . $urow['fname']; } } $optionValue = htmlspecialchars($urow['id'], ENT_QUOTES); $optionLabel = htmlspecialchars($uname, ENT_NOQUOTES); echo "<option value='{$optionValue}'"; $title = $urow['username'] ? xl('Local') : xl('External'); $optionTitle = htmlspecialchars($title, ENT_QUOTES); echo " title='{$optionTitle}'"; if ($urow['id'] == $currvalue) { echo " selected"; } echo ">{$optionLabel}</option>"; } echo "</select>"; } else { if ($data_type == 15) { $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES); $maxlength = $frow['max_length']; $string_maxlength = ""; // if max_length is set to zero, then do not set a maxlength if ($maxlength) { $string_maxlength = "maxlength='" . attr($maxlength) . "'"; } // if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') { // Option "2" generates a hidden input for the codes, and a matching visible field // displaying their descriptions. First step is computing the description string. $currdescstring = ''; if (!empty($currvalue)) { $relcodes = explode(';', $currvalue); foreach ($relcodes as $codestring) { if ($codestring === '') { continue; } $code_text = lookup_code_descriptions($codestring); if ($currdescstring !== '') { $currdescstring .= '; '; } if (!empty($code_text)) { $currdescstring .= $code_text; } else { $currdescstring .= $codestring; } } } $currdescstring = attr($currdescstring); // echo "<input type='text'" . " name='form_{$field_id_esc}'" . " id='form_related_code'" . " size='{$fldlength}'" . " value='{$currescaped}'" . " style='display:none'" . " {$lbfonchange} readonly {$disabled} />"; // Extra readonly input field for optional display of code description(s). echo "<input type='text'" . " name='form_{$field_id_esc}" . "__desc'" . " size='{$fldlength}'" . " title='{$description}'" . " value='{$currdescstring}'"; if (!$disabled) { echo " onclick='sel_related(this,\"{$codetype}\")'"; } echo " readonly {$disabled} />"; } else { echo "<input type='text'" . " name='form_{$field_id_esc}'" . " id='form_related_code'" . " size='{$fldlength}'" . " {$string_maxlength}" . " title='{$description}'" . " value='{$currescaped}'"; if (!$disabled) { echo " onclick='sel_related(this,\"{$codetype}\")'"; } echo " {$lbfonchange} readonly {$disabled} />"; } } else { if ($data_type == 16) { echo "<select name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}'>"; echo "<option value='0'></option>"; $insprovs = getInsuranceProviders(); $got_selected = false; foreach ($insprovs as $key => $ipname) { $optionValue = htmlspecialchars($key, ENT_QUOTES); $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES); echo "<option value='{$optionValue}'"; if ($currvalue == $key) { echo " selected"; $got_selected = true; } echo ">{$optionLabel}</option>"; } if (!$got_selected && $currvalue) { echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>"; echo "</select>"; echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>"; } else { echo "</select>"; } } else { if ($data_type == 17) { echo "<select name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}'>"; echo "<option value='0'></option>"; $got_selected = false; foreach ($ISSUE_TYPES as $key => $value) { $optionValue = htmlspecialchars($key, ENT_QUOTES); $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES); echo "<option value='{$optionValue}'"; if ($currvalue == $key) { echo " selected"; $got_selected = true; } echo ">{$optionLabel}</option>"; } if (!$got_selected && strlen($currvalue) > 0) { echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>"; echo "</select>"; echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>"; } else { echo "</select>"; } } else { if ($data_type == 18) { $cres = sqlStatement("SELECT pc_catid, pc_catname " . "FROM openemr_postcalendar_categories ORDER BY pc_catname"); echo "<select name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}'" . " {$lbfonchange} {$disabled}>"; echo "<option value=''>" . xlt($empty_title) . "</option>"; $got_selected = false; while ($crow = sqlFetchArray($cres)) { $catid = $crow['pc_catid']; if ($catid < 9 && $catid != 5 || $catid == 11) { continue; } echo "<option value='" . attr($catid) . "'"; if ($catid == $currvalue) { echo " selected"; $got_selected = true; } echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>"; } if (!$got_selected && $currvalue) { echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>"; echo "</select>"; echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>"; } else { echo "</select>"; } } else { if ($data_type == 21) { // In this special case, fld_length is the number of columns generated. $cols = max(1, $frow['fld_length']); $avalue = explode('|', $currvalue); $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? ORDER BY seq, title", array($list_id)); echo "<table cellpadding='0' cellspacing='0' width='100%'>"; $tdpct = (int) (100 / $cols); for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES); // if ($count) echo "<br />"; if ($count % $cols == 0) { if ($count) { echo "</tr>"; } echo "<tr>"; } echo "<td width='{$tdpct}%'>"; echo "<input type='checkbox' name='form_{$field_id_esc}[{$option_id_esc}]'" . "id='form_{$field_id_esc}[{$option_id_esc}]' value='1' {$lbfonchange}"; if (in_array($option_id, $avalue)) { echo " checked"; } // Added 5-09 by BM - Translate label if applicable echo " {$disabled} />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES); echo "</td>"; } if ($count) { echo "</tr>"; if ($count > $cols) { // Add some space after multiple rows of checkboxes. $cols = htmlspecialchars($cols, ENT_QUOTES); echo "<tr><td colspan='{$cols}' style='height:0.7em'></td></tr>"; } } echo "</table>"; } else { if ($data_type == 22) { $tmp = explode('|', $currvalue); $avalue = array(); foreach ($tmp as $value) { if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) { $avalue[$matches[1]] = $matches[2]; } } $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? ORDER BY seq, title", array($list_id)); echo "<table cellpadding='0' cellspacing='0'>"; while ($lrow = sqlFetchArray($lres)) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES); $maxlength = $frow['max_length']; $string_maxlength = ""; // if max_length is set to zero, then do not set a maxlength if ($maxlength) { $string_maxlength = "maxlength='" . attr($maxlength) . "'"; } $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length']; // Added 5-09 by BM - Translate label if applicable echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . " </td>"; $fldlength = htmlspecialchars($fldlength, ENT_QUOTES); $optionValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES); echo "<td><input type='text'" . " name='form_{$field_id_esc}[{$option_id_esc}]'" . " id='form_{$field_id_esc}[{$option_id_esc}]'" . " size='{$fldlength}'" . " {$string_maxlength}" . " value='{$optionValue}'"; echo " {$lbfonchange} {$disabled} /></td></tr>"; } echo "</table>"; } else { if ($data_type == 23) { $tmp = explode('|', $currvalue); $avalue = array(); foreach ($tmp as $value) { if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) { $avalue[$matches[1]] = $matches[2]; } } $maxlength = $frow['max_length']; $string_maxlength = ""; // if max_length is set to zero, then do not set a maxlength if ($maxlength) { $string_maxlength = "maxlength='" . attr($maxlength) . "'"; } $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length']; $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? ORDER BY seq, title", array($list_id)); echo "<table cellpadding='0' cellspacing='0'>"; echo "<tr><td> </td><td class='bold'>" . htmlspecialchars(xl('N/A'), ENT_NOQUOTES) . " </td><td class='bold'>" . htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . " </td>" . "<td class='bold'>" . htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . " </td><td class='bold'>" . htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>"; while ($lrow = sqlFetchArray($lres)) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES); $restype = substr($avalue[$option_id], 0, 1); $resnote = substr($avalue[$option_id], 2); // Added 5-09 by BM - Translate label if applicable echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . " </td>"; for ($i = 0; $i < 3; ++$i) { $inputValue = htmlspecialchars($i, ENT_QUOTES); echo "<td><input type='radio'" . " name='radio_{$field_id_esc}[{$option_id_esc}]'" . " id='radio_{$field_id_esc}[{$option_id_esc}]'" . " value='{$inputValue}' {$lbfonchange}"; if ($restype === "{$i}") { echo " checked"; } echo " {$disabled} /></td>"; } $fldlength = htmlspecialchars($fldlength, ENT_QUOTES); $resnote = htmlspecialchars($resnote, ENT_QUOTES); echo "<td><input type='text'" . " name='form_{$field_id_esc}[{$option_id_esc}]'" . " id='form_{$field_id_esc}[{$option_id_esc}]'" . " size='{$fldlength}'" . " {$string_maxlength}" . " value='{$resnote}' {$disabled} /></td>"; echo "</tr>"; } echo "</table>"; } else { if ($data_type == 24) { $query = "SELECT title, comments FROM lists WHERE " . "pid = ? AND type = 'allergy' AND enddate IS NULL " . "ORDER BY begdate"; // echo "<!-- $query -->\n"; // debugging $lres = sqlStatement($query, array($GLOBALS['pid'])); $count = 0; while ($lrow = sqlFetchArray($lres)) { if ($count++) { echo "<br />"; } echo htmlspecialchars($lrow['title'], ENT_NOQUOTES); if ($lrow['comments']) { echo ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')'; } } } else { if ($data_type == 25) { $tmp = explode('|', $currvalue); $avalue = array(); foreach ($tmp as $value) { if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) { $avalue[$matches[1]] = $matches[2]; } } $maxlength = $frow['max_length']; $string_maxlength = ""; // if max_length is set to zero, then do not set a maxlength if ($maxlength) { $string_maxlength = "maxlength='" . attr($maxlength) . "'"; } $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length']; $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? ORDER BY seq, title", array($list_id)); echo "<table cellpadding='0' cellspacing='0'>"; while ($lrow = sqlFetchArray($lres)) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES); $restype = substr($avalue[$option_id], 0, 1); $resnote = substr($avalue[$option_id], 2); // Added 5-09 by BM - Translate label if applicable echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . " </td>"; $option_id = htmlspecialchars($option_id, ENT_QUOTES); echo "<td><input type='checkbox' name='check_{$field_id_esc}[{$option_id_esc}]'" . " id='check_{$field_id_esc}[{$option_id_esc}]' value='1' {$lbfonchange}"; if ($restype) { echo " checked"; } echo " {$disabled} /> </td>"; $fldlength = htmlspecialchars($fldlength, ENT_QUOTES); $resnote = htmlspecialchars($resnote, ENT_QUOTES); echo "<td><input type='text'" . " name='form_{$field_id_esc}[{$option_id_esc}]'" . " id='form_{$field_id_esc}[{$option_id_esc}]'" . " size='{$fldlength}'" . " {$string_maxlength}" . " value='{$resnote}' {$disabled} /></td>"; echo "</tr>"; } echo "</table>"; } else { if ($data_type == 26) { echo generate_select_list("form_{$field_id}", $list_id, $currvalue, $description, $showEmpty ? $empty_title : '', 'addtolistclass_' . $list_id, $lbfchange, '', $disabled ? array('disabled' => 'disabled') : null, false, $backup_list); // show the add button if user has access to correct list $inputValue = htmlspecialchars(xl('Add'), ENT_QUOTES); $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" . $field_id_esc . "' class='addtolist' value='{$inputValue}' {$disabled} />"; if (aco_exist('lists', $list_id)) { // a specific aco exist for this list, so ensure access if (acl_check('lists', $list_id)) { echo $outputAddButton; } } else { // no specific aco exist for this list, so check for access to 'default' list if (acl_check('lists', 'default')) { echo $outputAddButton; } } } else { if ($data_type == 27) { // In this special case, fld_length is the number of columns generated. $cols = max(1, $frow['fld_length']); $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? ORDER BY seq, title", array($list_id)); echo "<table cellpadding='0' cellspacing='0' width='100%'>"; $tdpct = (int) (100 / $cols); $got_selected = FALSE; for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES); if ($count % $cols == 0) { if ($count) { echo "</tr>"; } echo "<tr>"; } echo "<td width='{$tdpct}%'>"; echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[{$option_id_esc}]'" . " value='{$option_id_esc}' {$lbfonchange}"; if (strlen($currvalue) == 0 && $lrow['is_default'] || strlen($currvalue) > 0 && $option_id == $currvalue) { echo " checked"; $got_selected = TRUE; } echo " {$disabled} />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES); echo "</td>"; } if ($count) { echo "</tr>"; if ($count > $cols) { // Add some space after multiple rows of radio buttons. $cols = htmlspecialchars($cols, ENT_QUOTES); echo "<tr><td colspan='{$cols}' style='height:0.7em'></td></tr>"; } } echo "</table>"; if (!$got_selected && strlen($currvalue) > 0) { $fontTitle = htmlspecialchars(xl('Please choose a valid selection.'), ENT_QUOTES); $fontText = htmlspecialchars(xl('Fix this'), ENT_NOQUOTES); echo "{$currescaped} <font color='red' title='{$fontTitle}'>{$fontText}!</font>"; } } else { if ($data_type == 28 || $data_type == 32) { $tmp = explode('|', $currvalue); switch (count($tmp)) { case "4": $resnote = $tmp[0]; $restype = $tmp[1]; $resdate = $tmp[2]; $reslist = $tmp[3]; break; case "3": $resnote = $tmp[0]; $restype = $tmp[1]; $resdate = $tmp[2]; break; case "2": $resnote = $tmp[0]; $restype = $tmp[1]; $resdate = ""; break; case "1": $resnote = $tmp[0]; $resdate = $restype = ""; break; default: $restype = $resdate = $resnote = ""; break; } $maxlength = $frow['max_length']; $string_maxlength = ""; // if max_length is set to zero, then do not set a maxlength if ($maxlength) { $string_maxlength = "maxlength='" . attr($maxlength) . "'"; } $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length']; $fldlength = htmlspecialchars($fldlength, ENT_QUOTES); $resnote = htmlspecialchars($resnote, ENT_QUOTES); $resdate = htmlspecialchars($resdate, ENT_QUOTES); echo "<table cellpadding='0' cellspacing='0'>"; echo "<tr>"; if ($data_type == 28) { // input text echo "<td><input type='text'" . " name='form_{$field_id_esc}'" . " id='form_{$field_id_esc}'" . " size='{$fldlength}'" . " {$string_maxlength}" . " value='{$resnote}' {$disabled} /> </td>"; echo "<td class='bold'> " . " " . htmlspecialchars(xl('Status'), ENT_NOQUOTES) . ": </td>"; } else { if ($data_type == 32) { // input text echo "<tr><td><input type='text'" . " name='form_text_{$field_id_esc}'" . " id='form_text_{$field_id_esc}'" . " size='{$fldlength}'" . " {$string_maxlength}" . " value='{$resnote}' {$disabled} /> </td></tr>"; echo "<td>"; //Selection list for smoking status $onchange = 'radioChange(this.options[this.selectedIndex].value)'; //VicarePlus :: The javascript function for selection list. echo generate_select_list("form_{$field_id}", $list_id, $reslist, $description, $showEmpty ? $empty_title : '', '', $onchange, '', $disabled ? array('disabled' => 'disabled') : null); echo "</td>"; echo "<td class='bold'> " . xlt('Status') . ": </td>"; } } // current echo "<td class='text' ><input type='radio'" . " name='radio_{$field_id_esc}'" . " id='radio_{$field_id_esc}[current]'" . " value='current" . $field_id_esc . "' {$lbfonchange}"; if ($restype == "current" . $field_id) { echo " checked"; } if ($data_type == 32) { echo " onClick='smoking_statusClicked(this)'"; } echo " />" . xlt('Current') . " </td>"; // quit echo "<td class='text'><input type='radio'" . " name='radio_{$field_id_esc}'" . " id='radio_{$field_id_esc}[quit]'" . " value='quit" . $field_id_esc . "' {$lbfonchange}"; if ($restype == "quit" . $field_id) { echo " checked"; } if ($data_type == 32) { echo " onClick='smoking_statusClicked(this)'"; } echo " {$disabled} />" . xlt('Quit') . " </td>"; // quit date echo "<td class='text'><input type='text' size='6' name='date_{$field_id_esc}' id='date_{$field_id_esc}'" . " value='{$resdate}'" . " title='{$description}'" . " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' {$disabled} />"; if (!$disabled) { echo "<img src='{$rootdir}/pic/show_calendar.gif' align='absbottom' width='24' height='22'" . " id='img_{$field_id_esc}' border='0' alt='[?]' style='cursor:pointer'" . " title='" . htmlspecialchars(xl('Click here to choose a date'), ENT_QUOTES) . "' />"; $date_init .= " Calendar.setup({inputField:'date_{$field_id}', ifFormat:'%Y-%m-%d', button:'img_{$field_id}'});\n"; } echo " </td>"; // never echo "<td class='text'><input type='radio'" . " name='radio_{$field_id_esc}'" . " id='radio_{$field_id_esc}[never]'" . " value='never" . $field_id_esc . "' {$lbfonchange}"; if ($restype == "never" . $field_id) { echo " checked"; } if ($data_type == 32) { echo " onClick='smoking_statusClicked(this)'"; } echo " />" . xlt('Never') . " </td>"; // Not Applicable echo "<td class='text'><input type='radio'" . " name='radio_{$field_id}'" . " id='radio_{$field_id}[not_applicable]'" . " value='not_applicable" . $field_id . "' {$lbfonchange}"; if ($restype == "not_applicable" . $field_id) { echo " checked"; } if ($data_type == 32) { echo " onClick='smoking_statusClicked(this)'"; } echo " {$disabled} />" . xlt('N/A') . " </td>"; // //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description') echo "<td class='text' ><div id='smoke_code'></div></td>"; echo "</tr>"; echo "</table>"; } else { if ($data_type == 31) { echo nl2br($frow['description']); } else { if ($data_type == 34) { $arr = explode("|*|*|*|", $currvalue); 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;'>"; echo "<div id='form_{$field_id}_div' class='text-area'>" . htmlspecialchars($arr[0], ENT_QUOTES) . "</div>"; echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' {$lbfonchange} {$disabled}>" . $currvalue . "</textarea></div>"; echo "</a>"; } else { if ($data_type == 35) { if (empty($currvalue)) { $currvalue = 0; } dropdown_facility($selected = $currvalue, $name = "form_{$field_id_esc}", $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange); } else { if ($data_type == 36) { echo generate_select_list("form_{$field_id}", $list_id, $currvalue, $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list); } } } } } } } } } } } } } } } } } } } } } } } } } }
function generate_form_field($frow, $currvalue) { global $rootdir, $date_init; $currescaped = htmlspecialchars($currvalue, ENT_QUOTES); $data_type = $frow['data_type']; $field_id = $frow['field_id']; $list_id = $frow['list_id']; // escaped variables to use in html $field_id_esc = htmlspecialchars($field_id, ENT_QUOTES); $list_id_esc = htmlspecialchars($list_id, ENT_QUOTES); // Added 5-09 by BM - Translate description if applicable $description = htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES); // added 5-2009 by BM to allow modification of the 'empty' text title field. // Can pass $frow['empty_title'] with this variable, otherwise // will default to 'Unassigned'. // modified 6-2009 by BM to allow complete skipping of the 'empty' text title // if make $frow['empty_title'] equal to 'SKIP' $showEmpty = true; if (isset($frow['empty_title'])) { if ($frow['empty_title'] == "SKIP") { //do not display an 'empty' choice $showEmpty = false; $empty_title = "Unassigned"; } else { $empty_title = $frow['empty_title']; } } else { $empty_title = "Unassigned"; } // generic single-selection list if ($data_type == 1) { echo generate_select_list("form_{$field_id}", $list_id, $currvalue, $description, $showEmpty ? $empty_title : ''); } else { if ($data_type == 2) { $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES); $maxlength = htmlspecialchars($frow['max_length'], ENT_QUOTES); echo "<input type='text'" . " name='form_{$field_id_esc}'" . " id='form_{$field_id_esc}'" . " size='{$fldlength}'" . " maxlength='{$maxlength}'" . " title='{$description}'" . " value='{$currescaped}'"; if (strpos($frow['edit_options'], 'C') !== FALSE) { echo " onchange='capitalizeMe(this)'"; } $tmp = htmlspecialchars($GLOBALS['gbl_mask_patient_id'], ENT_QUOTES); if ($field_id == 'pubpid' && strlen($tmp) > 0) { echo " onkeyup='maskkeyup(this,\"{$tmp}\")'"; echo " onblur='maskblur(this,\"{$tmp}\")'"; } echo " />"; } else { if ($data_type == 3) { $textCols = htmlspecialchars($frow['fld_length'], ENT_QUOTES); $textRows = htmlspecialchars($frow['max_length'], ENT_QUOTES); echo "<textarea" . " name='form_{$field_id_esc}'" . " id='form_{$field_id_esc}'" . " title='{$description}'" . " cols='{$textCols}'" . " rows='{$textRows}'>" . $currescaped . "</textarea>"; } else { if ($data_type == 4) { echo "<input type='text' size='10' name='form_{$field_id_esc}' id='form_{$field_id_esc}'" . " value='{$currescaped}'" . " title='{$description}'" . " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" . "<img src='{$rootdir}/pic/show_calendar.gif' align='absbottom' width='24' height='22'" . " id='img_{$field_id_esc}' border='0' alt='[?]' style='cursor:pointer'" . " title='" . htmlspecialchars(xl('Click here to choose a date'), ENT_QUOTES) . "' />"; $date_init .= " Calendar.setup({inputField:'form_{$field_id}', ifFormat:'%Y-%m-%d', button:'img_{$field_id}'});\n"; } else { if ($data_type == 10) { $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " . "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " . "AND authorized = 1 " . "ORDER BY lname, fname"); echo "<select name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}'>"; echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES) . "</option>"; while ($urow = sqlFetchArray($ures)) { $uname = htmlspecialchars($urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES); $optionId = htmlspecialchars($urow['id'], ENT_QUOTES); echo "<option value='{$optionId}'"; if ($urow['id'] == $currvalue) { echo " selected"; } echo ">{$uname}</option>"; } echo "</select>"; } else { if ($data_type == 11) { $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " . "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " . "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " . "ORDER BY lname, fname"); echo "<select name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}'>"; echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES) . "</option>"; while ($urow = sqlFetchArray($ures)) { $uname = htmlspecialchars($urow['fname'] . ' ' . $urow['lname'], ENT_NOQUOTES); $optionId = htmlspecialchars($urow['id'], ENT_QUOTES); echo "<option value='{$optionId}'"; if ($urow['id'] == $currvalue) { echo " selected"; } echo ">{$uname}</option>"; } echo "</select>"; } else { if ($data_type == 12) { echo "<select name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}'>"; echo "<option value='0'></option>"; $pres = get_pharmacies(); while ($prow = sqlFetchArray($pres)) { $key = $prow['id']; $optionValue = htmlspecialchars($key, ENT_QUOTES); $optionLabel = htmlspecialchars($prow['name'] . ' ' . $prow['area_code'] . '-' . $prow['prefix'] . '-' . $prow['number'] . ' / ' . $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES); echo "<option value='{$optionValue}'"; if ($currvalue == $key) { echo " selected"; } echo ">{$optionLabel}</option>"; } echo "</select>"; } else { if ($data_type == 13) { echo "<select name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}'>"; echo "<option value=''> </option>"; $squads = acl_get_squads(); if ($squads) { foreach ($squads as $key => $value) { $optionValue = htmlspecialchars($key, ENT_QUOTES); $optionLabel = htmlspecialchars($value[3], ENT_NOQUOTES); echo "<option value='{$optionValue}'"; if ($currvalue == $key) { echo " selected"; } echo ">{$optionLabel}</option>\n"; } } echo "</select>"; } else { if ($data_type == 14) { if (strpos($frow['edit_options'], 'O') !== FALSE) { $tmp = "abook_type LIKE 'ord\\_%'"; } else { if (strpos($frow['edit_options'], 'V') !== FALSE) { $tmp = "abook_type LIKE 'vendor%'"; } else { $tmp = "( username = '' OR authorized = 1 )"; } } $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " . "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " . "AND {$tmp} " . "ORDER BY organization, lname, fname"); echo "<select name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}'>"; echo "<option value=''>" . htmlspecialchars(xl('Unassigned'), ENT_NOQUOTES) . "</option>"; while ($urow = sqlFetchArray($ures)) { $uname = $urow['organization']; if (empty($uname) || substr($uname, 0, 1) == '(') { $uname = $urow['lname']; if ($urow['fname']) { $uname .= ", " . $urow['fname']; } } $optionValue = htmlspecialchars($urow['id'], ENT_QUOTES); $optionLabel = htmlspecialchars($uname, ENT_NOQUOTES); echo "<option value='{$optionValue}'"; $title = $urow['username'] ? xl('Local') : xl('External'); $optionTitle = htmlspecialchars($title, ENT_QUOTES); echo " title='{$optionTitle}'"; if ($urow['id'] == $currvalue) { echo " selected"; } echo ">{$optionLabel}</option>"; } echo "</select>"; } else { if ($data_type == 15) { $fldlength = htmlspecialchars($frow['fld_length'], ENT_QUOTES); $maxlength = htmlspecialchars($frow['max_length'], ENT_QUOTES); echo "<input type='text'" . " name='form_{$field_id_esc}'" . " id='form_related_code'" . " size='{$fldlength}'" . " maxlength='{$maxlength}'" . " title='{$description}'" . " value='{$currescaped}'" . " onclick='sel_related(this)' readonly" . " />"; } else { if ($data_type == 21) { // In this special case, fld_length is the number of columns generated. $cols = max(1, $frow['fld_length']); $avalue = explode('|', $currvalue); $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? ORDER BY seq, title", array($list_id)); echo "<table cellpadding='0' cellspacing='0' width='100%'>"; $tdpct = (int) (100 / $cols); for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES); // if ($count) echo "<br />"; if ($count % $cols == 0) { if ($count) { echo "</tr>"; } echo "<tr>"; } echo "<td width='{$tdpct}%'>"; echo "<input type='checkbox' name='form_{$field_id_esc}[{$option_id_esc}]' id='form_{$field_id_esc}[{$option_id_esc}]' value='1'"; if (in_array($option_id, $avalue)) { echo " checked"; } // Added 5-09 by BM - Translate label if applicable echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES); echo "</td>"; } if ($count) { echo "</tr>"; if ($count > $cols) { // Add some space after multiple rows of checkboxes. $cols = htmlspecialchars($cols, ENT_QUOTES); echo "<tr><td colspan='{$cols}' style='height:0.7em'></td></tr>"; } } echo "</table>"; } else { if ($data_type == 22) { $tmp = explode('|', $currvalue); $avalue = array(); foreach ($tmp as $value) { if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) { $avalue[$matches[1]] = $matches[2]; } } $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? ORDER BY seq, title", array($list_id)); echo "<table cellpadding='0' cellspacing='0'>"; while ($lrow = sqlFetchArray($lres)) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES); $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length']; $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length']; // Added 5-09 by BM - Translate label if applicable echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . " </td>"; $fldlength = htmlspecialchars($fldlength, ENT_QUOTES); $maxlength = htmlspecialchars($maxlength, ENT_QUOTES); $optionValue = htmlspecialchars($avalue[$option_id], ENT_QUOTES); echo "<td><input type='text'" . " name='form_{$field_id_esc}[{$option_id_esc}]'" . " id='form_{$field_id_esc}[{$option_id_esc}]'" . " size='{$fldlength}'" . " maxlength='{$maxlength}'" . " value='{$optionValue}'"; echo " /></td></tr>"; } echo "</table>"; } else { if ($data_type == 23) { $tmp = explode('|', $currvalue); $avalue = array(); foreach ($tmp as $value) { if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) { $avalue[$matches[1]] = $matches[2]; } } $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length']; $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length']; $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? ORDER BY seq, title", array($list_id)); echo "<table cellpadding='0' cellspacing='0'>"; echo "<tr><td> </td><td class='bold'>" . htmlspecialchars(xl('N/A'), ENT_NOQUOTES) . " </td><td class='bold'>" . htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . " </td>" . "<td class='bold'>" . htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . " </td><td class='bold'>" . htmlspecialchars(xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>"; while ($lrow = sqlFetchArray($lres)) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES); $restype = substr($avalue[$option_id], 0, 1); $resnote = substr($avalue[$option_id], 2); // Added 5-09 by BM - Translate label if applicable echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . " </td>"; for ($i = 0; $i < 3; ++$i) { $inputValue = htmlspecialchars($i, ENT_QUOTES); echo "<td><input type='radio'" . " name='radio_{$field_id_esc}[{$option_id_esc}]'" . " id='radio_{$field_id_esc}[{$option_id_esc}]'" . " value='{$inputValue}'"; if ($restype === "{$i}") { echo " checked"; } echo " /></td>"; } $fldlength = htmlspecialchars($fldlength, ENT_QUOTES); $maxlength = htmlspecialchars($maxlength, ENT_QUOTES); $resnote = htmlspecialchars($resnote, ENT_QUOTES); echo "<td><input type='text'" . " name='form_{$field_id_esc}[{$option_id_esc}]'" . " id='form_{$field_id_esc}[{$option_id_esc}]'" . " size='{$fldlength}'" . " maxlength='{$maxlength}'" . " value='{$resnote}' /></td>"; echo "</tr>"; } echo "</table>"; } else { if ($data_type == 24) { $query = "SELECT title, comments FROM lists WHERE " . "pid = ? AND type = 'allergy' AND enddate IS NULL " . "ORDER BY begdate"; // echo "<!-- $query -->\n"; // debugging $lres = sqlStatement($query, array($GLOBALS['pid'])); $count = 0; while ($lrow = sqlFetchArray($lres)) { if ($count++) { echo "<br />"; } echo htmlspecialchars($lrow['title'], ENT_NOQUOTES); if ($lrow['comments']) { echo ' (' . htmlspecialchars($lrow['comments'], ENT_NOQUOTES) . ')'; } } } else { if ($data_type == 25) { $tmp = explode('|', $currvalue); $avalue = array(); foreach ($tmp as $value) { if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) { $avalue[$matches[1]] = $matches[2]; } } $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length']; $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length']; $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? ORDER BY seq, title", array($list_id)); echo "<table cellpadding='0' cellspacing='0'>"; while ($lrow = sqlFetchArray($lres)) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES); $restype = substr($avalue[$option_id], 0, 1); $resnote = substr($avalue[$option_id], 2); // Added 5-09 by BM - Translate label if applicable echo "<tr><td>" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . " </td>"; $option_id = htmlspecialchars($option_id, ENT_QUOTES); echo "<td><input type='checkbox' name='check_{$field_id_esc}[{$option_id_esc}]' id='check_{$field_id_esc}[{$option_id_esc}]' value='1'"; if ($restype) { echo " checked"; } echo " /> </td>"; $fldlength = htmlspecialchars($fldlength, ENT_QUOTES); $maxlength = htmlspecialchars($maxlength, ENT_QUOTES); $resnote = htmlspecialchars($resnote, ENT_QUOTES); echo "<td><input type='text'" . " name='form_{$field_id_esc}[{$option_id_esc}]'" . " id='form_{$field_id_esc}[{$option_id_esc}]'" . " size='{$fldlength}'" . " maxlength='{$maxlength}'" . " value='{$resnote}' /></td>"; echo "</tr>"; } echo "</table>"; } else { if ($data_type == 26) { echo "<select class='addtolistclass_{$list_id_esc}' name='form_{$field_id_esc}' id='form_{$field_id_esc}' title='{$description}'>"; if ($showEmpty) { echo "<option value=''>" . htmlspecialchars(xl($empty_title), ENT_QUOTES) . "</option>"; } $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? ORDER BY seq, title", array($list_id)); $got_selected = FALSE; while ($lrow = sqlFetchArray($lres)) { $optionValue = htmlspecialchars($lrow['option_id'], ENT_QUOTES); echo "<option value='{$optionValue}'"; if (strlen($currvalue) == 0 && $lrow['is_default'] || strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue) { echo " selected"; $got_selected = TRUE; } // Added 5-09 by BM - Translate label if applicable echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES) . "</option>\n"; } if (!$got_selected && strlen($currvalue) > 0) { echo "<option value='{$currescaped}' selected>* {$currescaped} *</option>"; echo "</select>"; $fontTitle = htmlspecialchars(xl('Please choose a valid selection from the list.'), ENT_NOQUOTES); $fontText = htmlspecialchars(xl('Fix this'), ENT_NOQUOTES); echo " <font color='red' title='{$fontTitle}'>{$fontText}!</font>"; } else { echo "</select>"; } // show the add button if user has access to correct list $inputValue = htmlspecialchars(xl('Add'), ENT_QUOTES); $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" . $field_id_esc . "' class='addtolist' value='{$inputValue}'>"; if (aco_exist('lists', $list_id)) { // a specific aco exist for this list, so ensure access if (acl_check('lists', $list_id)) { echo $outputAddButton; } } else { // no specific aco exist for this list, so check for access to 'default' list if (acl_check('lists', 'default')) { echo $outputAddButton; } } } else { if ($data_type == 27) { // In this special case, fld_length is the number of columns generated. $cols = max(1, $frow['fld_length']); $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? ORDER BY seq, title", array($list_id)); echo "<table cellpadding='0' cellspacing='0' width='100%'>"; $tdpct = (int) (100 / $cols); $got_selected = FALSE; for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars($option_id, ENT_QUOTES); if ($count % $cols == 0) { if ($count) { echo "</tr>"; } echo "<tr>"; } echo "<td width='{$tdpct}%'>"; echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[{$option_id_esc}]' value='{$option_id_esc}'"; if (strlen($currvalue) == 0 && $lrow['is_default'] || strlen($currvalue) > 0 && $option_id == $currvalue) { echo " checked"; $got_selected = TRUE; } echo ">" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES); echo "</td>"; } if ($count) { echo "</tr>"; if ($count > $cols) { // Add some space after multiple rows of radio buttons. $cols = htmlspecialchars($cols, ENT_QUOTES); echo "<tr><td colspan='{$cols}' style='height:0.7em'></td></tr>"; } } echo "</table>"; if (!$got_selected && strlen($currvalue) > 0) { $fontTitle = htmlspecialchars(xl('Please choose a valid selection.'), ENT_QUOTES); $fontText = htmlspecialchars(xl('Fix this'), ENT_NOQUOTES); echo "{$currescaped} <font color='red' title='{$fontTitle}'>{$fontText}!</font>"; } } else { if ($data_type == 28) { $tmp = explode('|', $currvalue); switch (count($tmp)) { case "3": $resnote = $tmp[0]; $restype = $tmp[1]; $resdate = $tmp[2]; break; case "2": $resnote = $tmp[0]; $restype = $tmp[1]; $resdate = ""; break; case "1": $resnote = $tmp[0]; $resdate = $restype = ""; break; default: $restype = $resdate = $resnote = ""; break; } $maxlength = empty($frow['max_length']) ? 255 : $frow['max_length']; $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length']; $fldlength = htmlspecialchars($fldlength, ENT_QUOTES); $maxlength = htmlspecialchars($maxlength, ENT_QUOTES); $resnote = htmlspecialchars($resnote, ENT_QUOTES); $resdate = htmlspecialchars($resdate, ENT_QUOTES); echo "<table cellpadding='0' cellspacing='0'>"; echo "<tr>"; // input text echo "<td><input type='text'" . " name='form_{$field_id_esc}'" . " id='form_{$field_id_esc}'" . " size='{$fldlength}'" . " maxlength='{$maxlength}'" . " value='{$resnote}' /> </td>"; echo "<td class='bold'> " . htmlspecialchars(xl('Status'), ENT_NOQUOTES) . ": </td>"; // current echo "<td><input type='radio'" . " name='radio_{$field_id_esc}'" . " id='radio_{$field_id_esc}[current]'" . " value='current" . $field_id_esc . "'"; if ($restype == "current" . $field_id) { echo " checked"; } echo "/>" . htmlspecialchars(xl('Current'), ENT_NOQUOTES) . " </td>"; // quit echo "<td><input type='radio'" . " name='radio_{$field_id_esc}'" . " id='radio_{$field_id_esc}[quit]'" . " value='quit" . $field_id_esc . "'"; if ($restype == "quit" . $field_id) { echo " checked"; } echo "/>" . htmlspecialchars(xl('Quit'), ENT_NOQUOTES) . " </td>"; // quit date echo "<td><input type='text' size='6' name='date_{$field_id_esc}' id='date_{$field_id_esc}'" . " value='{$resdate}'" . " title='{$description}'" . " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" . "<img src='{$rootdir}/pic/show_calendar.gif' align='absbottom' width='24' height='22'" . " id='img_{$field_id_esc}' border='0' alt='[?]' style='cursor:pointer'" . " title='" . htmlspecialchars(xl('Click here to choose a date'), ENT_QUOTES) . "' /> </td>"; $date_init .= " Calendar.setup({inputField:'date_{$field_id}', ifFormat:'%Y-%m-%d', button:'img_{$field_id}'});\n"; // never echo "<td><input type='radio'" . " name='radio_{$field_id_esc}'" . " id='radio_{$field_id_esc}[never]'" . " value='never" . $field_id_esc . "'"; if ($restype == "never" . $field_id) { echo " checked"; } echo " />" . htmlspecialchars(xl('Never'), ENT_NOQUOTES) . " </td>"; // Not Applicable echo "<td><input type='radio'" . " name='radio_{$field_id}'" . " id='radio_{$field_id}[not_applicable]'" . " value='not_applicable" . $field_id . "'"; if ($restype == "not_applicable" . $field_id) { echo " checked"; } echo " />" . htmlspecialchars(xl('N/A'), ENT_QUOTES) . " </td>"; echo "</tr>"; echo "</table>"; } else { if ($data_type == 31) { echo nl2br($frow['description']); } } } } } } } } } } } } } } } } } } } }
function generate_form_field($frow, $currvalue) { global $rootdir, $date_init, $ISSUE_TYPES, $code_types,$condition_str; $currescaped = htmlspecialchars($currvalue, ENT_QUOTES); $data_type = $frow['data_type']; $field_id = $frow['field_id']; $list_id = $frow['list_id']; $backup_list = $frow['list_backup_id']; $condition_str = get_conditions_str($condition_str,$frow); // escaped variables to use in html $field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES); $list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES); // Added 5-09 by BM - Translate description if applicable $description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : ''); // Support edit option T which assigns the (possibly very long) description as // the default value. if (strpos($frow['edit_options'], 'T') !== FALSE) { if (strlen($currescaped) == 0) $currescaped = $description; // Description used in this way is not suitable as a title. $description = ''; } // added 5-2009 by BM to allow modification of the 'empty' text title field. // Can pass $frow['empty_title'] with this variable, otherwise // will default to 'Unassigned'. // modified 6-2009 by BM to allow complete skipping of the 'empty' text title // if make $frow['empty_title'] equal to 'SKIP' $showEmpty = true; if (isset($frow['empty_title'])) { if ($frow['empty_title'] == "SKIP") { //do not display an 'empty' choice $showEmpty = false; $empty_title = "Unassigned"; } else { $empty_title = $frow['empty_title']; } } else { $empty_title = "Unassigned"; } $disabled = strpos($frow['edit_options'], '0') === FALSE ? '' : 'disabled'; $lbfchange = (strpos($frow['form_id'], 'LBF') === 0 || strpos($frow['form_id'], 'LBT') === 0) ? "checkSkipConditions();" : ""; $lbfonchange = $lbfchange ? "onchange='$lbfchange'" : ""; // generic single-selection list or Race and Ethnicity. // These data types support backup lists. if ($data_type == 1 || $data_type == 33) { echo generate_select_list("form_$field_id", $list_id, $currvalue, $description, ($showEmpty ? $empty_title : ''), '', $lbfchange, '', ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list); } // simple text field else if ($data_type == 2) { $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES); $maxlength = $frow['max_length']; $string_maxlength = ""; // if max_length is set to zero, then do not set a maxlength if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'"; echo "<input type='text'" . " name='form_$field_id_esc'" . " id='form_$field_id_esc'" . " size='$fldlength'" . " $string_maxlength" . " title='$description'" . " value='$currescaped'"; $tmp = $lbfchange; if (strpos($frow['edit_options'], 'C') !== FALSE) $tmp .= "capitalizeMe(this);"; else if (strpos($frow['edit_options'], 'U') !== FALSE) $tmp .= "this.value = this.value.toUpperCase();"; if ($tmp) echo " onchange='$tmp'"; $tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES); if ($field_id == 'pubpid' && strlen($tmp) > 0) { echo " onkeyup='maskkeyup(this,\"$tmp\")'"; echo " onblur='maskblur(this,\"$tmp\")'"; } if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) { echo " readonly"; } if ($disabled) echo ' disabled'; echo " />"; } // long or multi-line text field else if ($data_type == 3) { $textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES); $textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES); echo "<textarea" . " name='form_$field_id_esc'" . " id='form_$field_id_esc'" . " title='$description'" . " cols='$textCols'" . " rows='$textRows' $lbfonchange $disabled" . ">" . $currescaped . "</textarea>"; } // date else if ($data_type == 4) { $age_asof_date = ''; // optionalAge() sets this $age_format = strpos($frow['edit_options'], 'A') === FALSE ? 3 : 0; $agestr = optionalAge($frow, $currvalue, $age_asof_date); if ($agestr) { echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>"; } echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" . " value='" . substr($currescaped, 0, 10) . "'"; if (!$agestr) echo " title='$description'"; echo " $lbfonchange onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />"; if (!$disabled) { echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" . " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" . " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />"; $date_init .= " Calendar.setup({" . "inputField:'form_$field_id', " . "ifFormat:'%Y-%m-%d', "; if ($agestr) { $date_init .= "onUpdate: function() {" . "if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format);" . "}, "; } $date_init .= "button:'img_$field_id'})\n"; } // Optional display of age or gestational age. if ($agestr) { echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>"; } } // provider list, local providers only else if ($data_type == 10) { $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " . "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " . "AND authorized = 1 " . "ORDER BY lname, fname"); echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled>"; echo "<option value=''>" . xlt($empty_title) . "</option>"; $got_selected = false; while ($urow = sqlFetchArray($ures)) { $uname = text($urow['fname'] . ' ' . $urow['lname']); $optionId = attr($urow['id']); echo "<option value='$optionId'"; if ($urow['id'] == $currvalue) { echo " selected"; $got_selected = true; } echo ">$uname</option>"; } if (!$got_selected && $currvalue) { echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>"; echo "</select>"; echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>"; } else { echo "</select>"; } } // provider list, including address book entries with an NPI number else if ($data_type == 11) { $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " . "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " . "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " . "ORDER BY lname, fname"); echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'"; echo " $lbfonchange $disabled>"; echo "<option value=''>" . xlt('Unassigned') . "</option>"; $got_selected = false; while ($urow = sqlFetchArray($ures)) { $uname = text($urow['fname'] . ' ' . $urow['lname']); $optionId = attr($urow['id']); echo "<option value='$optionId'"; if ($urow['id'] == $currvalue) { echo " selected"; $got_selected = true; } echo ">$uname</option>"; } if (!$got_selected && $currvalue) { echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>"; echo "</select>"; echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>"; } else { echo "</select>"; } } // pharmacy list else if ($data_type == 12) { echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'"; echo " $lbfonchange $disabled>"; echo "<option value='0'></option>"; $pres = get_pharmacies(); $got_selected = false; while ($prow = sqlFetchArray($pres)) { $key = $prow['id']; $optionValue = htmlspecialchars( $key, ENT_QUOTES); $optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' . $prow['prefix'] . '-' . $prow['number'] . ' / ' . $prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES); echo "<option value='$optionValue'"; if ($currvalue == $key) { echo " selected"; $got_selected = true; } echo ">$optionLabel</option>"; } if (!$got_selected && $currvalue) { echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>"; echo "</select>"; echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>"; } else { echo "</select>"; } } // squads else if ($data_type == 13) { echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'"; echo " $lbfonchange $disabled>"; echo "<option value=''> </option>"; $squads = acl_get_squads(); if ($squads) { foreach ($squads as $key => $value) { $optionValue = htmlspecialchars( $key, ENT_QUOTES); $optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES); echo "<option value='$optionValue'"; if ($currvalue == $key) echo " selected"; echo ">$optionLabel</option>\n"; } } echo "</select>"; } // Address book, preferring organization name if it exists and is not in // parentheses, and excluding local users who are not providers. // Supports "referred to" practitioners and facilities. // Alternatively the letter L in edit_options means that abook_type // must be "ord_lab", indicating types used with the procedure // lab ordering system. // Alternatively the letter O in edit_options means that abook_type // must begin with "ord_", indicating types used with the procedure // ordering system. // Alternatively the letter V in edit_options means that abook_type // must be "vendor", indicating the Vendor type. // Alternatively the letter R in edit_options means that abook_type // must be "dist", indicating the Distributor type. else if ($data_type == 14) { if (strpos($frow['edit_options'], 'L') !== FALSE) $tmp = "abook_type = 'ord_lab'"; else if (strpos($frow['edit_options'], 'O') !== FALSE) $tmp = "abook_type LIKE 'ord\\_%'"; else if (strpos($frow['edit_options'], 'V') !== FALSE) $tmp = "abook_type LIKE 'vendor%'"; else if (strpos($frow['edit_options'], 'R') !== FALSE) $tmp = "abook_type LIKE 'dist'"; else $tmp = "( username = '' OR authorized = 1 )"; $ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " . "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " . "AND $tmp " . "ORDER BY organization, lname, fname"); echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'"; echo " $lbfonchange $disabled>"; echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>"; while ($urow = sqlFetchArray($ures)) { $uname = $urow['organization']; if (empty($uname) || substr($uname, 0, 1) == '(') { $uname = $urow['lname']; if ($urow['fname']) $uname .= ", " . $urow['fname']; } $optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES); $optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES); echo "<option value='$optionValue'"; $title = $urow['username'] ? xl('Local') : xl('External'); $optionTitle = htmlspecialchars( $title, ENT_QUOTES); echo " title='$optionTitle'"; if ($urow['id'] == $currvalue) echo " selected"; echo ">$optionLabel</option>"; } echo "</select>"; } // A billing code. If description matches an existing code type then that type is used. else if ($data_type == 15) { $fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES); $maxlength = $frow['max_length']; $string_maxlength = ""; // if max_length is set to zero, then do not set a maxlength if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'"; // if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') { // Option "2" generates a hidden input for the codes, and a matching visible field // displaying their descriptions. First step is computing the description string. $currdescstring = ''; if (!empty($currvalue)) { $relcodes = explode(';', $currvalue); foreach ($relcodes as $codestring) { if ($codestring === '') continue; $code_text = lookup_code_descriptions($codestring); if ($currdescstring !== '') $currdescstring .= '; '; if (!empty($code_text)) { $currdescstring .= $code_text; } else { $currdescstring .= $codestring; } } } $currdescstring = attr($currdescstring); // echo "<input type='text'" . " name='form_$field_id_esc'" . " id='form_related_code'" . " size='$fldlength'" . " value='$currescaped'" . " style='display:none'" . " $lbfonchange readonly $disabled />"; // Extra readonly input field for optional display of code description(s). echo "<input type='text'" . " name='form_$field_id_esc" . "__desc'" . " size='$fldlength'" . " title='$description'" . " value='$currdescstring'"; if (!$disabled) { echo " onclick='sel_related(this,\"$codetype\")'"; } echo " readonly $disabled />"; } else { echo "<input type='text'" . " name='form_$field_id_esc'" . " id='form_related_code'" . " size='$fldlength'" . " $string_maxlength" . " title='$description'" . " value='$currescaped'"; if (!$disabled) { echo " onclick='sel_related(this,\"$codetype\")'"; } echo " $lbfonchange readonly $disabled />"; } } // insurance company list else if ($data_type == 16) { echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>"; echo "<option value='0'></option>"; $insprovs = getInsuranceProviders(); $got_selected = false; foreach ($insprovs as $key => $ipname) { $optionValue = htmlspecialchars($key, ENT_QUOTES); $optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES); echo "<option value='$optionValue'"; if ($currvalue == $key) { echo " selected"; $got_selected = true; } echo ">$optionLabel</option>"; } if (!$got_selected && $currvalue) { echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>"; echo "</select>"; echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>"; } else { echo "</select>"; } } // issue types else if ($data_type == 17) { echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>"; echo "<option value='0'></option>"; $got_selected = false; foreach ($ISSUE_TYPES as $key => $value) { $optionValue = htmlspecialchars($key, ENT_QUOTES); $optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES); echo "<option value='$optionValue'"; if ($currvalue == $key) { echo " selected"; $got_selected = true; } echo ">$optionLabel</option>"; } if (!$got_selected && strlen($currvalue) > 0) { echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>"; echo "</select>"; echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>"; } else { echo "</select>"; } } // Visit categories. else if ($data_type == 18) { $cres = sqlStatement("SELECT pc_catid, pc_catname " . "FROM openemr_postcalendar_categories ORDER BY pc_catname"); echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'" . " $lbfonchange $disabled>"; echo "<option value=''>" . xlt($empty_title) . "</option>"; $got_selected = false; while ($crow = sqlFetchArray($cres)) { $catid = $crow['pc_catid']; if (($catid < 9 && $catid != 5) || $catid == 11) continue; echo "<option value='" . attr($catid) . "'"; if ($catid == $currvalue) { echo " selected"; $got_selected = true; } echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>"; } if (!$got_selected && $currvalue) { echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>"; echo "</select>"; echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>"; } else { echo "</select>"; } } // a set of labeled checkboxes else if ($data_type == 21) { // In this special case, fld_length is the number of columns generated. $cols = max(1, $frow['fld_length']); $avalue = explode('|', $currvalue); $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) ); echo "<table cellpadding='0' cellspacing='0' width='100%'>"; $tdpct = (int) (100 / $cols); for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES); // if ($count) echo "<br />"; if ($count % $cols == 0) { if ($count) echo "</tr>"; echo "<tr>"; } echo "<td width='$tdpct%'>"; echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" . "id='form_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange"; if (in_array($option_id, $avalue)) echo " checked"; // Added 5-09 by BM - Translate label if applicable echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES); echo "</td>"; } if ($count) { echo "</tr>"; if ($count > $cols) { // Add some space after multiple rows of checkboxes. $cols = htmlspecialchars( $cols, ENT_QUOTES); echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>"; } } echo "</table>"; } // a set of labeled text input fields else if ($data_type == 22) { $tmp = explode('|', $currvalue); $avalue = array(); foreach ($tmp as $value) { if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) { $avalue[$matches[1]] = $matches[2]; } } $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) ); echo "<table cellpadding='0' cellspacing='0'>"; while ($lrow = sqlFetchArray($lres)) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES); $maxlength = $frow['max_length']; $string_maxlength = ""; // if max_length is set to zero, then do not set a maxlength if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'"; $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length']; // Added 5-09 by BM - Translate label if applicable echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . " </td>"; $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES); $optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES); echo "<td><input type='text'" . " name='form_{$field_id_esc}[$option_id_esc]'" . " id='form_{$field_id_esc}[$option_id_esc]'" . " size='$fldlength'" . " $string_maxlength" . " value='$optionValue'"; echo " $lbfonchange $disabled /></td></tr>"; } echo "</table>"; } // a set of exam results; 3 radio buttons and a text field: else if ($data_type == 23) { $tmp = explode('|', $currvalue); $avalue = array(); foreach ($tmp as $value) { if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) { $avalue[$matches[1]] = $matches[2]; } } $maxlength = $frow['max_length']; $string_maxlength = ""; // if max_length is set to zero, then do not set a maxlength if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'"; $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length']; $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) ); echo "<table cellpadding='0' cellspacing='0'>"; echo "<tr><td> </td><td class='bold'>" . htmlspecialchars( xl('N/A'), ENT_NOQUOTES) . " </td><td class='bold'>" . htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . " </td>" . "<td class='bold'>" . htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . " </td><td class='bold'>" . htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>"; while ($lrow = sqlFetchArray($lres)) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES); $restype = substr($avalue[$option_id], 0, 1); $resnote = substr($avalue[$option_id], 2); // Added 5-09 by BM - Translate label if applicable echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . " </td>"; for ($i = 0; $i < 3; ++$i) { $inputValue = htmlspecialchars( $i, ENT_QUOTES); echo "<td><input type='radio'" . " name='radio_{$field_id_esc}[$option_id_esc]'" . " id='radio_{$field_id_esc}[$option_id_esc]'" . " value='$inputValue' $lbfonchange"; if ($restype === "$i") echo " checked"; echo " $disabled /></td>"; } $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES); $resnote = htmlspecialchars( $resnote, ENT_QUOTES); echo "<td><input type='text'" . " name='form_{$field_id_esc}[$option_id_esc]'" . " id='form_{$field_id_esc}[$option_id_esc]'" . " size='$fldlength'" . " $string_maxlength" . " value='$resnote' $disabled /></td>"; echo "</tr>"; } echo "</table>"; } // the list of active allergies for the current patient // this is read-only! else if ($data_type == 24) { $query = "SELECT title, comments FROM lists WHERE " . "pid = ? AND type = 'allergy' AND enddate IS NULL " . "ORDER BY begdate"; // echo "<!-- $query -->\n"; // debugging $lres = sqlStatement($query, array($GLOBALS['pid'])); $count = 0; while ($lrow = sqlFetchArray($lres)) { if ($count++) echo "<br />"; echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES); if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')'; } } // a set of labeled checkboxes, each with a text field: else if ($data_type == 25) { $tmp = explode('|', $currvalue); $avalue = array(); foreach ($tmp as $value) { if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) { $avalue[$matches[1]] = $matches[2]; } } $maxlength = $frow['max_length']; $string_maxlength = ""; // if max_length is set to zero, then do not set a maxlength if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'"; $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length']; $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) ); echo "<table cellpadding='0' cellspacing='0'>"; while ($lrow = sqlFetchArray($lres)) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES); $restype = substr($avalue[$option_id], 0, 1); $resnote = substr($avalue[$option_id], 2); // Added 5-09 by BM - Translate label if applicable echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . " </td>"; $option_id = htmlspecialchars( $option_id, ENT_QUOTES); echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" . " id='check_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange"; if ($restype) echo " checked"; echo " $disabled /> </td>"; $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES); $resnote = htmlspecialchars( $resnote, ENT_QUOTES); echo "<td><input type='text'" . " name='form_{$field_id_esc}[$option_id_esc]'" . " id='form_{$field_id_esc}[$option_id_esc]'" . " size='$fldlength'" . " $string_maxlength" . " value='$resnote' $disabled /></td>"; echo "</tr>"; } echo "</table>"; } // single-selection list with ability to add to it else if ($data_type == 26) { echo generate_select_list("form_$field_id", $list_id, $currvalue, $description, ($showEmpty ? $empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '', ($disabled ? array('disabled' => 'disabled') : null), false, $backup_list); // show the add button if user has access to correct list $inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES); $outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" . $field_id_esc . "' class='addtolist' value='$inputValue' $disabled />"; if (aco_exist('lists', $list_id)) { // a specific aco exist for this list, so ensure access if (acl_check('lists', $list_id)) echo $outputAddButton; } else { // no specific aco exist for this list, so check for access to 'default' list if (acl_check('lists', 'default')) echo $outputAddButton; } } // a set of labeled radio buttons else if ($data_type == 27) { // In this special case, fld_length is the number of columns generated. $cols = max(1, $frow['fld_length']); $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id) ); echo "<table cellpadding='0' cellspacing='0' width='100%'>"; $tdpct = (int) (100 / $cols); $got_selected = FALSE; for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) { $option_id = $lrow['option_id']; $option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES); if ($count % $cols == 0) { if ($count) echo "</tr>"; echo "<tr>"; } echo "<td width='$tdpct%'>"; echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" . " value='$option_id_esc' $lbfonchange"; if ((strlen($currvalue) == 0 && $lrow['is_default']) || (strlen($currvalue) > 0 && $option_id == $currvalue)) { echo " checked"; $got_selected = TRUE; } echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES); echo "</td>"; } if ($count) { echo "</tr>"; if ($count > $cols) { // Add some space after multiple rows of radio buttons. $cols = htmlspecialchars($cols, ENT_QUOTES); echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>"; } } echo "</table>"; if (!$got_selected && strlen($currvalue) > 0) { $fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES); $fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES); echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>"; } } // special case for history of lifestyle status; 3 radio buttons and a date text field: // VicarePlus :: A selection list box for smoking status: else if ($data_type == 28 || $data_type == 32) { $tmp = explode('|', $currvalue); switch(count($tmp)) { case "4": { $resnote = $tmp[0]; $restype = $tmp[1]; $resdate = $tmp[2]; $reslist = $tmp[3]; } break; case "3": { $resnote = $tmp[0]; $restype = $tmp[1]; $resdate = $tmp[2]; } break; case "2": { $resnote = $tmp[0]; $restype = $tmp[1]; $resdate = ""; } break; case "1": { $resnote = $tmp[0]; $resdate = $restype = ""; } break; default: { $restype = $resdate = $resnote = ""; } break; } $maxlength = $frow['max_length']; $string_maxlength = ""; // if max_length is set to zero, then do not set a maxlength if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'"; $fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length']; $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES); $resnote = htmlspecialchars( $resnote, ENT_QUOTES); $resdate = htmlspecialchars( $resdate, ENT_QUOTES); echo "<table cellpadding='0' cellspacing='0'>"; echo "<tr>"; if ($data_type == 28) { // input text echo "<td><input type='text'" . " name='form_$field_id_esc'" . " id='form_$field_id_esc'" . " size='$fldlength'" . " $string_maxlength" . " value='$resnote' $disabled /> </td>"; echo "<td class='bold'> ". " ". htmlspecialchars( xl('Status'), ENT_NOQUOTES).": </td>"; } else if($data_type == 32) { // input text echo "<tr><td><input type='text'" . " name='form_text_$field_id_esc'" . " id='form_text_$field_id_esc'" . " size='$fldlength'" . " $string_maxlength" . " value='$resnote' $disabled /> </td></tr>"; echo "<td>"; //Selection list for smoking status $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list. echo generate_select_list("form_$field_id", $list_id, $reslist, $description, ($showEmpty ? $empty_title : ''), '', $onchange, '', ($disabled ? array('disabled' => 'disabled') : null)); echo "</td>"; echo "<td class='bold'> " . xlt('Status') . ": </td>"; } // current echo "<td class='text' ><input type='radio'" . " name='radio_{$field_id_esc}'" . " id='radio_{$field_id_esc}[current]'" . " value='current" . $field_id_esc . "' $lbfonchange"; if ($restype == "current" . $field_id) echo " checked"; if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'"; echo " />" . xlt('Current') . " </td>"; // quit echo "<td class='text'><input type='radio'" . " name='radio_{$field_id_esc}'" . " id='radio_{$field_id_esc}[quit]'" . " value='quit".$field_id_esc."' $lbfonchange"; if ($restype == "quit" . $field_id) echo " checked"; if($data_type == 32) echo " onClick='smoking_statusClicked(this)'"; echo " $disabled />" . xlt('Quit') . " </td>"; // quit date echo "<td class='text'><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" . " value='$resdate'" . " title='$description'" . " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />"; if (!$disabled) { echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" . " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" . " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />"; $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n"; } echo " </td>"; // never echo "<td class='text'><input type='radio'" . " name='radio_{$field_id_esc}'" . " id='radio_{$field_id_esc}[never]'" . " value='never" . $field_id_esc . "' $lbfonchange"; if ($restype == "never" . $field_id) echo " checked"; if($data_type == 32) echo " onClick='smoking_statusClicked(this)'"; echo " />" . xlt('Never') . " </td>"; // Not Applicable echo "<td class='text'><input type='radio'" . " name='radio_{$field_id}'" . " id='radio_{$field_id}[not_applicable]'" . " value='not_applicable" . $field_id . "' $lbfonchange"; if ($restype == "not_applicable" . $field_id) echo " checked"; if($data_type == 32) echo " onClick='smoking_statusClicked(this)'"; echo " $disabled />" . xlt('N/A') . " </td>"; // //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description') echo "<td class='text' ><div id='smoke_code'></div></td>"; echo "</tr>"; echo "</table>"; } // static text. read-only, of course. else if ($data_type == 31) { echo nl2br($frow['description']); } //$data_type == 33 // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there. //$data_type == 33 else if($data_type == 34){ $arr = explode("|*|*|*|",$currvalue); 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;'>"; echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>"; echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>"; echo "</a>"; } //facilities drop-down list else if ($data_type == 35) { if (empty($currvalue)){ $currvalue = 0; } dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc", $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange); } //multiple select // supports backup list else if ($data_type == 36) { echo generate_select_list("form_$field_id", $list_id, $currvalue, $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list); } // Canvas and related elements for browser-side image drawing. // Note you must invoke lbf_canvas_head() (below) to use this field type in a form. else if ($data_type == 40) { // Unlike other field types, width and height are in pixels. $canWidth = intval($frow['fld_length']); $canHeight = intval($frow['fld_rows']); if (empty($currvalue)) { if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) { // If defined this is the filename of the default starting image. $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1]; } } echo "<div id='form_$field_id_esc'></div>"; // Hidden form field exists to send updated data to the server at submit time. echo "<input type='hidden' name='form_$field_id_esc' value='' />"; // Hidden image exists to support initialization of the canvas. echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>"; // $date_init is a misnomer but it's the place for browser-side setup logic. $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n"; } }