Adjusts fileroot for document paths at the moment that the document is to be displayed.
[openemr.git] / library / options.inc.php
blob0a0a5bfa11cfd282feb8f1afbb28039250f00eba
1 <?php
3 $date_init = "";
5 function get_pharmacies() {
6 return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
7 "p.area_code, p.prefix, p.number FROM pharmacies AS d " .
8 "LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
9 "LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
10 "AND p.type = 2 " .
11 "ORDER BY name, area_code, prefix, number");
14 function generate_form_field($frow, $currvalue) {
15 global $rootdir, $date_init;
17 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
19 $data_type = $frow['data_type'];
20 $field_id = $frow['field_id'];
21 $list_id = $frow['list_id'];
22 $description = htmlspecialchars($frow['description'], ENT_QUOTES);
24 // generic selection list
25 if ($data_type == 1) {
26 echo "<select name='form_$field_id' title='$description'>";
27 echo "<option value=''>" . xl('Unassigned') . "</option>";
28 $lres = sqlStatement("SELECT * FROM list_options " .
29 "WHERE list_id = '$list_id' ORDER BY seq");
30 $got_selected = FALSE;
31 while ($lrow = sqlFetchArray($lres)) {
32 echo "<option value='" . $lrow['option_id'] . "'";
33 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
34 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue))
36 echo " selected";
37 $got_selected = TRUE;
39 echo ">" . $lrow['title'] . "</option>\n";
41 if (!$got_selected && strlen($currvalue) > 0) {
42 echo "<option value='$currescaped' selected>* $currescaped *</option>";
43 echo "</select>";
44 echo " <font color='red' title='Please choose a valid selection " .
45 "from the list'>Fix this!</font>";
47 else {
48 echo "</select>";
52 // simple text field
53 else if ($data_type == 2) {
54 echo "<input type='text'" .
55 " name='form_$field_id'" .
56 " size='" . $frow['fld_length'] . "'" .
57 " maxlength='" . $frow['max_length'] . "'" .
58 " title='$description'" .
59 " value='$currescaped'";
60 if (strpos($frow['edit_options'], 'C') !== FALSE)
61 echo " onchange='capitalizeMe(this)'";
62 echo " />";
65 // long or multi-line text field
66 else if ($data_type == 3) {
67 echo "<textarea" .
68 " name='form_$field_id'" .
69 " title='$description'" .
70 " cols='" . $frow['fld_length'] . "'" .
71 " rows='" . $frow['max_length'] . "'>" .
72 $currescaped . "</textarea>";
75 // date
76 else if ($data_type == 4) {
77 echo "<input type='text' size='10' name='form_$field_id' id='form_$field_id'" .
78 " value='$currescaped'" .
79 " title='$description'" .
80 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />" .
81 "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
82 " id='img_$field_id' border='0' alt='[?]' style='cursor:pointer'" .
83 " title='" . xl('Click here to choose a date') . "' />";
84 $date_init .= " Calendar.setup({inputField:'form_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
87 // local provider list
88 else if ($data_type == 11) {
89 echo "<select name='form_$field_id' title='$description'>";
90 echo "<option value=''>" . xl('Unassigned') . "</option>";
91 $provideri = getProviderInfo();
92 foreach ($provideri as $s) {
93 echo "<option value='" . $s['id'] . "'";
94 if ($s['id'] == $currvalue) echo " selected";
95 echo ">" . ucwords($s['fname'] . " " . $s['lname']) . "</option>";
97 echo "</select>";
100 // pharmacy list
101 else if ($data_type == 12) {
102 echo "<select name='form_$field_id' title='$description'>";
103 echo "<option value='0'></option>";
104 $pres = get_pharmacies();
105 while ($prow = sqlFetchArray($pres)) {
106 $key = $prow['id'];
107 echo "<option value='$key'";
108 if ($currvalue == $key) echo " selected";
109 echo '>' . $prow['name'] . ' ' . $prow['area_code'] . '-' .
110 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
111 $prow['line1'] . ' / ' . $prow['city'] . "</option>";
113 echo "</select>";
116 // squads
117 else if ($data_type == 13) {
118 echo "<select name='form_$field_id' title='$description'>";
119 echo "<option value=''>&nbsp;</option>";
120 $squads = acl_get_squads();
121 if ($squads) {
122 foreach ($squads as $key => $value) {
123 echo "<option value='$key'";
124 if ($currvalue == $key) echo " selected";
125 echo ">" . $value[3] . "</option>\n";
128 echo "</select>";
131 // address book
132 else if ($data_type == 14) {
133 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
134 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
135 "ORDER BY lname, fname");
136 echo "<select name='form_$field_id' title='$description'>";
137 echo "<option value='0'>&nbsp;</option>";
138 while ($urow = sqlFetchArray($ures)) {
139 $uname = $urow['lname'];
140 if ($urow['fname']) $uname .= ", " . $urow['fname'];
141 echo "<option value='" . $urow['id'] . "'";
142 if ($urow['id'] == $currvalue) echo " selected";
143 echo ">$uname</option>";
145 echo "</select>";
150 function generate_display_field($frow, $currvalue) {
151 $data_type = $frow['data_type'];
152 $field_id = $frow['field_id'];
153 $list_id = $frow['list_id'];
154 $s = '';
156 // generic selection list
157 if ($data_type == 1) {
158 $lrow = sqlQuery("SELECT title FROM list_options " .
159 "WHERE list_id = '$list_id' AND option_id = '$currvalue'");
160 $s = $lrow['title'];
163 // simple text field
164 else if ($data_type == 2) {
165 $s = $currvalue;
168 // long or multi-line text field
169 else if ($data_type == 3) {
170 $s = nl2br($currvalue);
173 // date
174 else if ($data_type == 4) {
175 $s = $currvalue;
178 // provider list
179 else if ($data_type == 11) {
180 $provideri = getProviderInfo();
181 foreach ($provideri as $p) {
182 if ($p['id'] == $currvalue) {
183 $s .= ucwords($p['fname'] . " " . $p['lname']);
188 // pharmacy list
189 else if ($data_type == 12) {
190 $pres = get_pharmacies();
191 while ($prow = sqlFetchArray($pres)) {
192 $key = $prow['id'];
193 if ($currvalue == $key) {
194 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
195 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
196 $prow['line1'] . ' / ' . $prow['city'];
201 // squads
202 else if ($data_type == 13) {
203 $squads = acl_get_squads();
204 if ($squads) {
205 foreach ($squads as $key => $value) {
206 if ($currvalue == $key) {
207 $s .= $value[3];
213 // address book
214 else if ($data_type == 14) {
215 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
216 "WHERE id = '$currvalue'");
217 $uname = $urow['lname'];
218 if ($urow['fname']) $uname .= ", " . $urow['fname'];
219 $s = $uname;
222 return $s;