Fixed errors in two regular expressions due to the lack of the /s modifier.
[openemr.git] / library / options.inc.php
blob1e91b3f34bad5f29b2a7f61ede3900c32bb7eb2f
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 // provider list, including address book entries with an NPI number
88 else if ($data_type == 11) {
89 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
90 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
91 "AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
92 "ORDER BY lname, fname");
93 echo "<select name='form_$field_id' title='$description'>";
94 echo "<option value=''>" . xl('Unassigned') . "</option>";
95 while ($urow = sqlFetchArray($ures)) {
96 $uname = $urow['fname'] . ' ' . $urow['lname'];
97 echo "<option value='" . $urow['id'] . "'";
98 if ($urow['id'] == $currvalue) echo " selected";
99 echo ">$uname</option>";
101 echo "</select>";
104 // pharmacy list
105 else if ($data_type == 12) {
106 echo "<select name='form_$field_id' title='$description'>";
107 echo "<option value='0'></option>";
108 $pres = get_pharmacies();
109 while ($prow = sqlFetchArray($pres)) {
110 $key = $prow['id'];
111 echo "<option value='$key'";
112 if ($currvalue == $key) echo " selected";
113 echo '>' . $prow['name'] . ' ' . $prow['area_code'] . '-' .
114 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
115 $prow['line1'] . ' / ' . $prow['city'] . "</option>";
117 echo "</select>";
120 // squads
121 else if ($data_type == 13) {
122 echo "<select name='form_$field_id' title='$description'>";
123 echo "<option value=''>&nbsp;</option>";
124 $squads = acl_get_squads();
125 if ($squads) {
126 foreach ($squads as $key => $value) {
127 echo "<option value='$key'";
128 if ($currvalue == $key) echo " selected";
129 echo ">" . $value[3] . "</option>\n";
132 echo "</select>";
135 // address book
136 else if ($data_type == 14) {
137 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
138 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
139 "ORDER BY lname, fname");
140 echo "<select name='form_$field_id' title='$description'>";
141 echo "<option value='0'>&nbsp;</option>";
142 while ($urow = sqlFetchArray($ures)) {
143 $uname = $urow['lname'];
144 if ($urow['fname']) $uname .= ", " . $urow['fname'];
145 echo "<option value='" . $urow['id'] . "'";
146 if ($urow['id'] == $currvalue) echo " selected";
147 echo ">$uname</option>";
149 echo "</select>";
154 function generate_display_field($frow, $currvalue) {
155 $data_type = $frow['data_type'];
156 $field_id = $frow['field_id'];
157 $list_id = $frow['list_id'];
158 $s = '';
160 // generic selection list
161 if ($data_type == 1) {
162 $lrow = sqlQuery("SELECT title FROM list_options " .
163 "WHERE list_id = '$list_id' AND option_id = '$currvalue'");
164 $s = $lrow['title'];
167 // simple text field
168 else if ($data_type == 2) {
169 $s = $currvalue;
172 // long or multi-line text field
173 else if ($data_type == 3) {
174 $s = nl2br($currvalue);
177 // date
178 else if ($data_type == 4) {
179 $s = $currvalue;
182 // provider
183 else if ($data_type == 11) {
184 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
185 "WHERE id = '$currvalue'");
186 $s = ucwords($urow['fname'] . " " . $urow['lname']);
189 // pharmacy list
190 else if ($data_type == 12) {
191 $pres = get_pharmacies();
192 while ($prow = sqlFetchArray($pres)) {
193 $key = $prow['id'];
194 if ($currvalue == $key) {
195 $s .= $prow['name'] . ' ' . $prow['area_code'] . '-' .
196 $prow['prefix'] . '-' . $prow['number'] . ' / ' .
197 $prow['line1'] . ' / ' . $prow['city'];
202 // squads
203 else if ($data_type == 13) {
204 $squads = acl_get_squads();
205 if ($squads) {
206 foreach ($squads as $key => $value) {
207 if ($currvalue == $key) {
208 $s .= $value[3];
214 // address book
215 else if ($data_type == 14) {
216 $urow = sqlQuery("SELECT fname, lname, specialty FROM users " .
217 "WHERE id = '$currvalue'");
218 $uname = $urow['lname'];
219 if ($urow['fname']) $uname .= ", " . $urow['fname'];
220 $s = $uname;
223 return $s;