Further modification of address book:
[openemr.git] / interface / usergroup / addrbook_edit.php
blob222323fdcc2ef2547ff808a4a22a5adac1907e53
1 <?php
2 // Copyright (C) 2006-2010 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 include_once("../globals.php");
10 include_once("$srcdir/acl.inc");
11 require_once("$srcdir/options.inc.php");
12 require_once("$srcdir/formdata.inc.php");
14 // Collect user id if editing entry
15 $userid = $_REQUEST['userid'];
17 // Collect type if creating a new entry
18 $type = $_REQUEST['type'];
20 $info_msg = "";
22 function QuotedOrNull($fld) {
23 $fld = formDataCore($fld,true);
24 if ($fld) return "'$fld'";
25 return "NULL";
28 function invalue($name) {
29 $fld = formData($name,"P",true);
30 return "'$fld'";
33 function rbinput($name, $value, $desc, $colname) {
34 global $row;
35 $ret = "<input type='radio' name='$name' value='$value'";
36 if ($row[$colname] == $value) $ret .= " checked";
37 $ret .= " />$desc";
38 return $ret;
41 function rbvalue($rbname) {
42 $tmp = $_POST[$rbname];
43 if (! $tmp) $tmp = '0';
44 return "'$tmp'";
48 <html>
49 <head>
50 <title><?php echo $userid ? xl('Edit') : xl('Add New') ?> <?php xl('Person','e'); ?></title>
51 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
52 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
54 <style>
55 td { font-size:10pt; }
57 .inputtext {
59 font-family:monospace;
60 font-size:10pt;
61 font-weight:normal;
62 border-style:solid;
63 border-width:1px;
64 border-color: #000000;
65 background-color:transparent;
67 padding-left:2px;
68 padding-right:2px;
71 .button {
72 font-family:sans-serif;
73 font-size:9pt;
74 font-weight:bold;
76 </style>
78 <script language="JavaScript">
80 var type_options_js = Array();
81 <?php
82 // Collect the type options. Possible values are:
83 // 1 = Unassigned (default to patient centric)
84 // 2 = Person Centric
85 // 3 = Company Centric (Basically, do not show the Name fields)
86 $sql = sqlStatement("SELECT option_id, option_value FROM list_options WHERE " .
87 "list_id = 'abook_type'");
88 while ($row_query = sqlFetchArray($sql)) {
89 echo "type_options_js"."['" . htmlspecialchars($row_query['option_id'],ENT_QUOTES) . "']=" . htmlspecialchars($row_query['option_value'],ENT_QUOTES) . ";\n";
93 // Process to customize the form by type
94 function typeSelect(a) {
95 if (type_options_js[a] == 3) {
96 // Company centric, so hide the Name entries
97 document.getElementById("nameRow").style.display = "none";
99 else {
100 // show the name row
101 document.getElementById("nameRow").style.display = "";
104 </script>
106 </head>
108 <body class="body_top">
109 <?php
110 // If we are saving, then save and close the window.
112 if ($_POST['form_save']) {
114 if ($userid) {
116 $query = "UPDATE users SET " .
117 "abook_type = " . invalue('form_abook_type') . ", " .
118 "title = " . invalue('form_title') . ", " .
119 "fname = " . invalue('form_fname') . ", " .
120 "lname = " . invalue('form_lname') . ", " .
121 "mname = " . invalue('form_mname') . ", " .
122 "specialty = " . invalue('form_specialty') . ", " .
123 "organization = " . invalue('form_organization') . ", " .
124 "valedictory = " . invalue('form_valedictory') . ", " .
125 "assistant = " . invalue('form_assistant') . ", " .
126 "federaltaxid = " . invalue('form_federaltaxid') . ", " .
127 "upin = " . invalue('form_upin') . ", " .
128 "npi = " . invalue('form_npi') . ", " .
129 "taxonomy = " . invalue('form_taxonomy') . ", " .
130 "email = " . invalue('form_email') . ", " .
131 "url = " . invalue('form_url') . ", " .
132 "street = " . invalue('form_street') . ", " .
133 "streetb = " . invalue('form_streetb') . ", " .
134 "city = " . invalue('form_city') . ", " .
135 "state = " . invalue('form_state') . ", " .
136 "zip = " . invalue('form_zip') . ", " .
137 "street2 = " . invalue('form_street2') . ", " .
138 "streetb2 = " . invalue('form_streetb2') . ", " .
139 "city2 = " . invalue('form_city2') . ", " .
140 "state2 = " . invalue('form_state2') . ", " .
141 "zip2 = " . invalue('form_zip2') . ", " .
142 "phone = " . invalue('form_phone') . ", " .
143 "phonew1 = " . invalue('form_phonew1') . ", " .
144 "phonew2 = " . invalue('form_phonew2') . ", " .
145 "phonecell = " . invalue('form_phonecell') . ", " .
146 "fax = " . invalue('form_fax') . ", " .
147 "notes = " . invalue('form_notes') . " " .
148 "WHERE id = '$userid'";
149 sqlStatement($query);
151 } else {
153 $userid = sqlInsert("INSERT INTO users ( " .
154 "username, password, authorized, info, source, " .
155 "title, fname, lname, mname, " .
156 "federaltaxid, federaldrugid, upin, facility, see_auth, active, npi, taxonomy, " .
157 "specialty, organization, valedictory, assistant, billname, email, url, " .
158 "street, streetb, city, state, zip, " .
159 "street2, streetb2, city2, state2, zip2, " .
160 "phone, phonew1, phonew2, phonecell, fax, notes, abook_type " .
161 ") VALUES ( " .
162 "'', " . // username
163 "'', " . // password
164 "0, " . // authorized
165 "'', " . // info
166 "NULL, " . // source
167 invalue('form_title') . ", " .
168 invalue('form_fname') . ", " .
169 invalue('form_lname') . ", " .
170 invalue('form_mname') . ", " .
171 invalue('form_federaltaxid') . ", " .
172 "'', " . // federaldrugid
173 invalue('form_upin') . ", " .
174 "'', " . // facility
175 "0, " . // see_auth
176 "1, " . // active
177 invalue('form_npi') . ", " .
178 invalue('form_taxonomy') . ", " .
179 invalue('form_specialty') . ", " .
180 invalue('form_organization') . ", " .
181 invalue('form_valedictory') . ", " .
182 invalue('form_assistant') . ", " .
183 "'', " . // billname
184 invalue('form_email') . ", " .
185 invalue('form_url') . ", " .
186 invalue('form_street') . ", " .
187 invalue('form_streetb') . ", " .
188 invalue('form_city') . ", " .
189 invalue('form_state') . ", " .
190 invalue('form_zip') . ", " .
191 invalue('form_street2') . ", " .
192 invalue('form_streetb2') . ", " .
193 invalue('form_city2') . ", " .
194 invalue('form_state2') . ", " .
195 invalue('form_zip2') . ", " .
196 invalue('form_phone') . ", " .
197 invalue('form_phonew1') . ", " .
198 invalue('form_phonew2') . ", " .
199 invalue('form_phonecell') . ", " .
200 invalue('form_fax') . ", " .
201 invalue('form_notes') . ", " .
202 invalue('form_abook_type') . " " .
203 ")");
208 else if ($_POST['form_delete']) {
210 if ($userid) {
211 // Be careful not to delete internal users.
212 sqlStatement("DELETE FROM users WHERE id = '$userid' AND username = ''");
217 if ($_POST['form_save'] || $_POST['form_delete']) {
218 // Close this window and redisplay the updated list.
219 echo "<script language='JavaScript'>\n";
220 if ($info_msg) echo " alert('$info_msg');\n";
221 echo " window.close();\n";
222 echo " if (opener.refreshme) opener.refreshme();\n";
223 echo "</script></body></html>\n";
224 exit();
227 if ($userid) {
228 $row = sqlQuery("SELECT * FROM users WHERE id = '$userid'");
231 if ($type) { // note this only happens when its new
232 // Set up type
233 $row['abook_type'] = strip_escape_custom($type);
238 <script language="JavaScript">
239 $(document).ready(function() {
240 // customize the form via the type options
241 typeSelect("<?php echo $row['abook_type']; ?>");
243 </script>
245 <form method='post' name='theform' action='addrbook_edit.php?userid=<?php echo $userid ?>'>
246 <center>
248 <table border='0' width='100%'>
250 <?php if (acl_check('admin', 'practice' )) { // allow choose type option if have admin access ?>
251 <tr>
252 <td width='1%' nowrap><b><?php xl('Type','e'); ?>:</b></td>
253 <td>
254 <?php
255 echo generate_select_list('form_abook_type', 'abook_type', $row['abook_type'], '', 'Unassigned', '', 'typeSelect(this.value)');
257 </td>
258 </tr>
259 <?php } // end of if has admin access ?>
261 <tr id="nameRow">
262 <td width='1%' nowrap><b><?php xl('Name','e'); ?>:</b></td>
263 <td>
264 <?php
265 generate_form_field(array('data_type'=>1,'field_id'=>'title','list_id'=>'titles','empty_title'=>' '), $row['title']);
267 <b><?php xl('Last','e'); ?>:</b><input type='text' size='10' name='form_lname' class='inputtext'
268 maxlength='50' value='<?php echo htmlspecialchars($row['lname'], ENT_QUOTES); ?>'/>&nbsp;
269 <b><?php xl('First','e'); ?>:</b> <input type='text' size='10' name='form_fname' class='inputtext'
270 maxlength='50' value='<?php echo htmlspecialchars($row['fname'], ENT_QUOTES); ?>' />&nbsp;
271 <b><?php xl('Middle','e'); ?>:</b> <input type='text' size='4' name='form_mname' class='inputtext'
272 maxlength='50' value='<?php echo htmlspecialchars($row['mname'], ENT_QUOTES); ?>' />
273 </td>
274 </tr>
276 <tr>
277 <td nowrap><b><?php xl('Specialty','e'); ?>:</b></td>
278 <td>
279 <input type='text' size='40' name='form_specialty' maxlength='250'
280 value='<?php echo htmlspecialchars($row['specialty'], ENT_QUOTES); ?>'
281 style='width:100%' class='inputtext' />
282 </td>
283 </tr>
285 <tr>
286 <td nowrap><b><?php xl('Organization','e'); ?>:</b></td>
287 <td>
288 <input type='text' size='40' name='form_organization' maxlength='250'
289 value='<?php echo htmlspecialchars($row['organization'], ENT_QUOTES); ?>'
290 style='width:100%' class='inputtext' />
291 </td>
292 </tr>
294 <tr>
295 <td nowrap><b><?php xl('Valedictory','e'); ?>:</b></td>
296 <td>
297 <input type='text' size='40' name='form_valedictory' maxlength='250'
298 value='<?php echo htmlspecialchars($row['valedictory'], ENT_QUOTES); ?>'
299 style='width:100%' class='inputtext' />
300 </td>
301 </tr>
303 <tr>
304 <td nowrap><b><?php xl('Home Phone','e'); ?>:</b></td>
305 <td>
306 <input type='text' size='11' name='form_phone' value='<?php echo htmlspecialchars($row['phone'], ENT_QUOTES); ?>'
307 maxlength='30' class='inputtext' />&nbsp;
308 <b><?php xl('Mobile','e'); ?>:</b><input type='text' size='11' name='form_phonecell'
309 maxlength='30' value='<?php echo htmlspecialchars($row['phonecell'], ENT_QUOTES); ?>' class='inputtext' />
310 </td>
311 </tr>
313 <tr>
314 <td nowrap><b><?php xl('Work Phone','e'); ?>:</b></td>
315 <td>
316 <input type='text' size='11' name='form_phonew1' value='<?php echo htmlspecialchars($row['phonew1'], ENT_QUOTES); ?>'
317 maxlength='30' class='inputtext' />&nbsp;
318 <b><?php xl('2nd','e'); ?>:</b><input type='text' size='11' name='form_phonew2' value='<?php echo htmlspecialchars($row['phonew2'], ENT_QUOTES); ?>'
319 maxlength='30' class='inputtext' />&nbsp;
320 <b><?php xl('Fax','e'); ?>:</b> <input type='text' size='11' name='form_fax' value='<?php echo htmlspecialchars($row['fax'], ENT_QUOTES); ?>'
321 maxlength='30' class='inputtext' />
322 </td>
323 </tr>
325 <tr>
326 <td nowrap><b><?php xl('Assistant','e'); ?>:</b></td>
327 <td>
328 <input type='text' size='40' name='form_assistant' maxlength='250'
329 value='<?php echo htmlspecialchars($row['assistant'], ENT_QUOTES); ?>'
330 style='width:100%' class='inputtext' />
331 </td>
332 </tr>
334 <tr>
335 <td nowrap><b><?php xl('Email','e'); ?>:</b></td>
336 <td>
337 <input type='text' size='40' name='form_email' maxlength='250'
338 value='<?php echo htmlspecialchars($row['email'], ENT_QUOTES); ?>'
339 style='width:100%' class='inputtext' />
340 </td>
341 </tr>
343 <tr>
344 <td nowrap><b><?php xl('Website','e'); ?>:</b></td>
345 <td>
346 <input type='text' size='40' name='form_url' maxlength='250'
347 value='<?php echo htmlspecialchars($row['url'], ENT_QUOTES); ?>'
348 style='width:100%' class='inputtext' />
349 </td>
350 </tr>
352 <tr>
353 <td nowrap><b><?php xl('Main Address','e'); ?>:</b></td>
354 <td>
355 <input type='text' size='40' name='form_street' maxlength='60'
356 value='<?php echo htmlspecialchars($row['street'], ENT_QUOTES); ?>'
357 style='width:100%' class='inputtext' />
358 </td>
359 </tr>
361 <tr>
362 <td nowrap>&nbsp;</td>
363 <td>
364 <input type='text' size='40' name='form_streetb' maxlength='60'
365 value='<?php echo htmlspecialchars($row['streetb'], ENT_QUOTES); ?>'
366 style='width:100%' class='inputtext' />
367 </td>
368 </tr>
370 <tr>
371 <td nowrap><b><?php xl('City','e'); ?>:</b></td>
372 <td>
373 <input type='text' size='10' name='form_city' maxlength='30'
374 value='<?php echo htmlspecialchars($row['city'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
375 <b><?php echo xl('State')."/".xl('county'); ?>:</b> <input type='text' size='10' name='form_state' maxlength='30'
376 value='<?php echo htmlspecialchars($row['state'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
377 <b><?php xl('Postal code','e'); ?>:</b> <input type='text' size='10' name='form_zip' maxlength='20'
378 value='<?php echo htmlspecialchars($row['zip'], ENT_QUOTES); ?>' class='inputtext' />
379 </td>
380 </tr>
382 <tr>
383 <td nowrap><b><?php xl('Alt Address','e'); ?>:</b></td>
384 <td>
385 <input type='text' size='40' name='form_street2' maxlength='60'
386 value='<?php echo htmlspecialchars($row['street2'], ENT_QUOTES); ?>'
387 style='width:100%' class='inputtext' />
388 </td>
389 </tr>
391 <tr>
392 <td nowrap>&nbsp;</td>
393 <td>
394 <input type='text' size='40' name='form_streetb2' maxlength='60'
395 value='<?php echo htmlspecialchars($row['streetb2'], ENT_QUOTES); ?>'
396 style='width:100%' class='inputtext' />
397 </td>
398 </tr>
400 <tr>
401 <td nowrap><b><?php xl('City','e'); ?>:</b></td>
402 <td>
403 <input type='text' size='10' name='form_city2' maxlength='30'
404 value='<?php echo htmlspecialchars($row['city2'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
405 <b><?php echo xl('State')."/".xl('county'); ?>:</b> <input type='text' size='10' name='form_state2' maxlength='30'
406 value='<?php echo htmlspecialchars($row['state2'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
407 <b><?php xl('Postal code','e'); ?>:</b> <input type='text' size='10' name='form_zip2' maxlength='20'
408 value='<?php echo htmlspecialchars($row['zip2'], ENT_QUOTES); ?>' class='inputtext' />
409 </td>
410 </tr>
412 <tr>
413 <td nowrap><b><?php xl('UPIN','e'); ?>:</b></td>
414 <td>
415 <input type='text' size='6' name='form_upin' maxlength='6'
416 value='<?php echo htmlspecialchars($row['upin'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
417 <b><?php xl('NPI','e'); ?>:</b> <input type='text' size='10' name='form_npi' maxlength='10'
418 value='<?php echo htmlspecialchars($row['npi'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
419 <b><?php xl('TIN','e'); ?>:</b> <input type='text' size='10' name='form_federaltaxid' maxlength='10'
420 value='<?php echo htmlspecialchars($row['federaltaxid'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
421 <b><?php xl('Taxonomy','e'); ?>:</b> <input type='text' size='10' name='form_taxonomy' maxlength='10'
422 value='<?php echo htmlspecialchars($row['taxonomy'], ENT_QUOTES); ?>' class='inputtext' />
423 </td>
424 </tr>
426 <tr>
427 <td nowrap><b><?php xl('Notes','e'); ?>:</b></td>
428 <td>
429 <textarea rows='3' cols='40' name='form_notes' style='width:100%'
430 wrap='virtual' class='inputtext' /><?php echo $row['notes'] ?></textarea>
431 </td>
432 </tr>
434 </table>
436 <br />
438 <input type='submit' name='form_save' value=<?php xl('Save','e','\'','\''); ?> />
440 <?php if ($userid && !$row['username']) { ?>
441 &nbsp;
442 <input type='submit' name='form_delete' value=<?php xl('Delete','e','\'','\''); ?> style='color:red' />
443 <?php } ?>
445 &nbsp;
446 <input type='button' value=<?php xl('Cancel','e','\'','\''); ?> onclick='window.close()' />
447 </p>
449 </center>
450 </form>
451 </body>
452 </html>