Address Book Module Updates:
[openemr.git] / interface / usergroup / addrbook_edit.php
blob73658e3fa11ef2c75c8a938be7f3233e1ac77266
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 person centric)
84 // 2 = Person Centric
85 // 3 = Company Centric
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:
97 // 1) Hide the person Name entries
98 // 2) Hide the Specialty entry
99 // 3) Show the director Name entries
100 document.getElementById("nameRow").style.display = "none";
101 document.getElementById("specialtyRow").style.display = "none";
102 document.getElementById("nameDirectorRow").style.display = "";
104 else {
105 // Person centric:
106 // 1) Hide the director Name entries
107 // 2) Show the person Name entries
108 // 3) Show the Specialty entry
109 document.getElementById("nameDirectorRow").style.display = "none";
110 document.getElementById("nameRow").style.display = "";
111 document.getElementById("specialtyRow").style.display = "";
114 </script>
116 </head>
118 <body class="body_top">
119 <?php
120 // If we are saving, then save and close the window.
122 if ($_POST['form_save']) {
124 // Collect the form_abook_type option value
125 // (ie. patient vs company centric)
126 $type_sql_row = sqlQuery("SELECT `option_value` FROM `list_options` WHERE `list_id` = 'abook_type' AND `option_id` = " . invalue('form_abook_type') . "");
127 $option_abook_type = $type_sql_row['option_value'];
128 // Set up any abook_type specific settings
129 if ($option_abook_type == 3) {
130 // Company centric
131 $form_title = invalue('form_director_title');
132 $form_fname = invalue('form_director_fname');
133 $form_lname = invalue('form_director_lname');
134 $form_mname = invalue('form_director_mname');
136 else {
137 // Person centric
138 $form_title = invalue('form_title');
139 $form_fname = invalue('form_fname');
140 $form_lname = invalue('form_lname');
141 $form_mname = invalue('form_mname');
144 if ($userid) {
146 $query = "UPDATE users SET " .
147 "abook_type = " . invalue('form_abook_type') . ", " .
148 "title = " . $form_title . ", " .
149 "fname = " . $form_fname . ", " .
150 "lname = " . $form_lname . ", " .
151 "mname = " . $form_mname . ", " .
152 "specialty = " . invalue('form_specialty') . ", " .
153 "organization = " . invalue('form_organization') . ", " .
154 "valedictory = " . invalue('form_valedictory') . ", " .
155 "assistant = " . invalue('form_assistant') . ", " .
156 "federaltaxid = " . invalue('form_federaltaxid') . ", " .
157 "upin = " . invalue('form_upin') . ", " .
158 "npi = " . invalue('form_npi') . ", " .
159 "taxonomy = " . invalue('form_taxonomy') . ", " .
160 "email = " . invalue('form_email') . ", " .
161 "url = " . invalue('form_url') . ", " .
162 "street = " . invalue('form_street') . ", " .
163 "streetb = " . invalue('form_streetb') . ", " .
164 "city = " . invalue('form_city') . ", " .
165 "state = " . invalue('form_state') . ", " .
166 "zip = " . invalue('form_zip') . ", " .
167 "street2 = " . invalue('form_street2') . ", " .
168 "streetb2 = " . invalue('form_streetb2') . ", " .
169 "city2 = " . invalue('form_city2') . ", " .
170 "state2 = " . invalue('form_state2') . ", " .
171 "zip2 = " . invalue('form_zip2') . ", " .
172 "phone = " . invalue('form_phone') . ", " .
173 "phonew1 = " . invalue('form_phonew1') . ", " .
174 "phonew2 = " . invalue('form_phonew2') . ", " .
175 "phonecell = " . invalue('form_phonecell') . ", " .
176 "fax = " . invalue('form_fax') . ", " .
177 "notes = " . invalue('form_notes') . " " .
178 "WHERE id = '$userid'";
179 sqlStatement($query);
181 } else {
183 $userid = sqlInsert("INSERT INTO users ( " .
184 "username, password, authorized, info, source, " .
185 "title, fname, lname, mname, " .
186 "federaltaxid, federaldrugid, upin, facility, see_auth, active, npi, taxonomy, " .
187 "specialty, organization, valedictory, assistant, billname, email, url, " .
188 "street, streetb, city, state, zip, " .
189 "street2, streetb2, city2, state2, zip2, " .
190 "phone, phonew1, phonew2, phonecell, fax, notes, abook_type " .
191 ") VALUES ( " .
192 "'', " . // username
193 "'', " . // password
194 "0, " . // authorized
195 "'', " . // info
196 "NULL, " . // source
197 $form_title . ", " .
198 $form_fname . ", " .
199 $form_lname . ", " .
200 $form_mname . ", " .
201 invalue('form_federaltaxid') . ", " .
202 "'', " . // federaldrugid
203 invalue('form_upin') . ", " .
204 "'', " . // facility
205 "0, " . // see_auth
206 "1, " . // active
207 invalue('form_npi') . ", " .
208 invalue('form_taxonomy') . ", " .
209 invalue('form_specialty') . ", " .
210 invalue('form_organization') . ", " .
211 invalue('form_valedictory') . ", " .
212 invalue('form_assistant') . ", " .
213 "'', " . // billname
214 invalue('form_email') . ", " .
215 invalue('form_url') . ", " .
216 invalue('form_street') . ", " .
217 invalue('form_streetb') . ", " .
218 invalue('form_city') . ", " .
219 invalue('form_state') . ", " .
220 invalue('form_zip') . ", " .
221 invalue('form_street2') . ", " .
222 invalue('form_streetb2') . ", " .
223 invalue('form_city2') . ", " .
224 invalue('form_state2') . ", " .
225 invalue('form_zip2') . ", " .
226 invalue('form_phone') . ", " .
227 invalue('form_phonew1') . ", " .
228 invalue('form_phonew2') . ", " .
229 invalue('form_phonecell') . ", " .
230 invalue('form_fax') . ", " .
231 invalue('form_notes') . ", " .
232 invalue('form_abook_type') . " " .
233 ")");
238 else if ($_POST['form_delete']) {
240 if ($userid) {
241 // Be careful not to delete internal users.
242 sqlStatement("DELETE FROM users WHERE id = '$userid' AND username = ''");
247 if ($_POST['form_save'] || $_POST['form_delete']) {
248 // Close this window and redisplay the updated list.
249 echo "<script language='JavaScript'>\n";
250 if ($info_msg) echo " alert('$info_msg');\n";
251 echo " window.close();\n";
252 echo " if (opener.refreshme) opener.refreshme();\n";
253 echo "</script></body></html>\n";
254 exit();
257 if ($userid) {
258 $row = sqlQuery("SELECT * FROM users WHERE id = '$userid'");
261 if ($type) { // note this only happens when its new
262 // Set up type
263 $row['abook_type'] = strip_escape_custom($type);
268 <script language="JavaScript">
269 $(document).ready(function() {
270 // customize the form via the type options
271 typeSelect("<?php echo $row['abook_type']; ?>");
273 </script>
275 <form method='post' name='theform' action='addrbook_edit.php?userid=<?php echo $userid ?>'>
276 <center>
278 <table border='0' width='100%'>
280 <?php if (acl_check('admin', 'practice' )) { // allow choose type option if have admin access ?>
281 <tr>
282 <td width='1%' nowrap><b><?php xl('Type','e'); ?>:</b></td>
283 <td>
284 <?php
285 echo generate_select_list('form_abook_type', 'abook_type', $row['abook_type'], '', 'Unassigned', '', 'typeSelect(this.value)');
287 </td>
288 </tr>
289 <?php } // end of if has admin access ?>
291 <tr id="nameRow">
292 <td width='1%' nowrap><b><?php xl('Name','e'); ?>:</b></td>
293 <td>
294 <?php
295 generate_form_field(array('data_type'=>1,'field_id'=>'title','list_id'=>'titles','empty_title'=>' '), $row['title']);
297 <b><?php xl('Last','e'); ?>:</b><input type='text' size='10' name='form_lname' class='inputtext'
298 maxlength='50' value='<?php echo htmlspecialchars($row['lname'], ENT_QUOTES); ?>'/>&nbsp;
299 <b><?php xl('First','e'); ?>:</b> <input type='text' size='10' name='form_fname' class='inputtext'
300 maxlength='50' value='<?php echo htmlspecialchars($row['fname'], ENT_QUOTES); ?>' />&nbsp;
301 <b><?php xl('Middle','e'); ?>:</b> <input type='text' size='4' name='form_mname' class='inputtext'
302 maxlength='50' value='<?php echo htmlspecialchars($row['mname'], ENT_QUOTES); ?>' />
303 </td>
304 </tr>
306 <tr id="specialtyRow">
307 <td nowrap><b><?php xl('Specialty','e'); ?>:</b></td>
308 <td>
309 <input type='text' size='40' name='form_specialty' maxlength='250'
310 value='<?php echo htmlspecialchars($row['specialty'], ENT_QUOTES); ?>'
311 style='width:100%' class='inputtext' />
312 </td>
313 </tr>
315 <tr>
316 <td nowrap><b><?php xl('Organization','e'); ?>:</b></td>
317 <td>
318 <input type='text' size='40' name='form_organization' maxlength='250'
319 value='<?php echo htmlspecialchars($row['organization'], ENT_QUOTES); ?>'
320 style='width:100%' class='inputtext' />
321 </td>
322 </tr>
324 <tr id="nameDirectorRow">
325 <td width='1%' nowrap><b><?php xl('Director Name','e'); ?>:</b></td>
326 <td>
327 <?php
328 generate_form_field(array('data_type'=>1,'field_id'=>'director_title','list_id'=>'titles','empty_title'=>' '), $row['title']);
330 <b><?php xl('Last','e'); ?>:</b><input type='text' size='10' name='form_director_lname' class='inputtext'
331 maxlength='50' value='<?php echo htmlspecialchars($row['lname'], ENT_QUOTES); ?>'/>&nbsp;
332 <b><?php xl('First','e'); ?>:</b> <input type='text' size='10' name='form_director_fname' class='inputtext'
333 maxlength='50' value='<?php echo htmlspecialchars($row['fname'], ENT_QUOTES); ?>' />&nbsp;
334 <b><?php xl('Middle','e'); ?>:</b> <input type='text' size='4' name='form_director_mname' class='inputtext'
335 maxlength='50' value='<?php echo htmlspecialchars($row['mname'], ENT_QUOTES); ?>' />
336 </td>
337 </tr>
339 <tr>
340 <td nowrap><b><?php xl('Valedictory','e'); ?>:</b></td>
341 <td>
342 <input type='text' size='40' name='form_valedictory' maxlength='250'
343 value='<?php echo htmlspecialchars($row['valedictory'], ENT_QUOTES); ?>'
344 style='width:100%' class='inputtext' />
345 </td>
346 </tr>
348 <tr>
349 <td nowrap><b><?php xl('Home Phone','e'); ?>:</b></td>
350 <td>
351 <input type='text' size='11' name='form_phone' value='<?php echo htmlspecialchars($row['phone'], ENT_QUOTES); ?>'
352 maxlength='30' class='inputtext' />&nbsp;
353 <b><?php xl('Mobile','e'); ?>:</b><input type='text' size='11' name='form_phonecell'
354 maxlength='30' value='<?php echo htmlspecialchars($row['phonecell'], ENT_QUOTES); ?>' class='inputtext' />
355 </td>
356 </tr>
358 <tr>
359 <td nowrap><b><?php xl('Work Phone','e'); ?>:</b></td>
360 <td>
361 <input type='text' size='11' name='form_phonew1' value='<?php echo htmlspecialchars($row['phonew1'], ENT_QUOTES); ?>'
362 maxlength='30' class='inputtext' />&nbsp;
363 <b><?php xl('2nd','e'); ?>:</b><input type='text' size='11' name='form_phonew2' value='<?php echo htmlspecialchars($row['phonew2'], ENT_QUOTES); ?>'
364 maxlength='30' class='inputtext' />&nbsp;
365 <b><?php xl('Fax','e'); ?>:</b> <input type='text' size='11' name='form_fax' value='<?php echo htmlspecialchars($row['fax'], ENT_QUOTES); ?>'
366 maxlength='30' class='inputtext' />
367 </td>
368 </tr>
370 <tr>
371 <td nowrap><b><?php xl('Assistant','e'); ?>:</b></td>
372 <td>
373 <input type='text' size='40' name='form_assistant' maxlength='250'
374 value='<?php echo htmlspecialchars($row['assistant'], ENT_QUOTES); ?>'
375 style='width:100%' class='inputtext' />
376 </td>
377 </tr>
379 <tr>
380 <td nowrap><b><?php xl('Email','e'); ?>:</b></td>
381 <td>
382 <input type='text' size='40' name='form_email' maxlength='250'
383 value='<?php echo htmlspecialchars($row['email'], ENT_QUOTES); ?>'
384 style='width:100%' class='inputtext' />
385 </td>
386 </tr>
388 <tr>
389 <td nowrap><b><?php xl('Website','e'); ?>:</b></td>
390 <td>
391 <input type='text' size='40' name='form_url' maxlength='250'
392 value='<?php echo htmlspecialchars($row['url'], ENT_QUOTES); ?>'
393 style='width:100%' class='inputtext' />
394 </td>
395 </tr>
397 <tr>
398 <td nowrap><b><?php xl('Main Address','e'); ?>:</b></td>
399 <td>
400 <input type='text' size='40' name='form_street' maxlength='60'
401 value='<?php echo htmlspecialchars($row['street'], ENT_QUOTES); ?>'
402 style='width:100%' class='inputtext' />
403 </td>
404 </tr>
406 <tr>
407 <td nowrap>&nbsp;</td>
408 <td>
409 <input type='text' size='40' name='form_streetb' maxlength='60'
410 value='<?php echo htmlspecialchars($row['streetb'], ENT_QUOTES); ?>'
411 style='width:100%' class='inputtext' />
412 </td>
413 </tr>
415 <tr>
416 <td nowrap><b><?php xl('City','e'); ?>:</b></td>
417 <td>
418 <input type='text' size='10' name='form_city' maxlength='30'
419 value='<?php echo htmlspecialchars($row['city'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
420 <b><?php echo xl('State')."/".xl('county'); ?>:</b> <input type='text' size='10' name='form_state' maxlength='30'
421 value='<?php echo htmlspecialchars($row['state'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
422 <b><?php xl('Postal code','e'); ?>:</b> <input type='text' size='10' name='form_zip' maxlength='20'
423 value='<?php echo htmlspecialchars($row['zip'], ENT_QUOTES); ?>' class='inputtext' />
424 </td>
425 </tr>
427 <tr>
428 <td nowrap><b><?php xl('Alt Address','e'); ?>:</b></td>
429 <td>
430 <input type='text' size='40' name='form_street2' maxlength='60'
431 value='<?php echo htmlspecialchars($row['street2'], ENT_QUOTES); ?>'
432 style='width:100%' class='inputtext' />
433 </td>
434 </tr>
436 <tr>
437 <td nowrap>&nbsp;</td>
438 <td>
439 <input type='text' size='40' name='form_streetb2' maxlength='60'
440 value='<?php echo htmlspecialchars($row['streetb2'], ENT_QUOTES); ?>'
441 style='width:100%' class='inputtext' />
442 </td>
443 </tr>
445 <tr>
446 <td nowrap><b><?php xl('City','e'); ?>:</b></td>
447 <td>
448 <input type='text' size='10' name='form_city2' maxlength='30'
449 value='<?php echo htmlspecialchars($row['city2'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
450 <b><?php echo xl('State')."/".xl('county'); ?>:</b> <input type='text' size='10' name='form_state2' maxlength='30'
451 value='<?php echo htmlspecialchars($row['state2'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
452 <b><?php xl('Postal code','e'); ?>:</b> <input type='text' size='10' name='form_zip2' maxlength='20'
453 value='<?php echo htmlspecialchars($row['zip2'], ENT_QUOTES); ?>' class='inputtext' />
454 </td>
455 </tr>
457 <tr>
458 <td nowrap><b><?php xl('UPIN','e'); ?>:</b></td>
459 <td>
460 <input type='text' size='6' name='form_upin' maxlength='6'
461 value='<?php echo htmlspecialchars($row['upin'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
462 <b><?php xl('NPI','e'); ?>:</b> <input type='text' size='10' name='form_npi' maxlength='10'
463 value='<?php echo htmlspecialchars($row['npi'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
464 <b><?php xl('TIN','e'); ?>:</b> <input type='text' size='10' name='form_federaltaxid' maxlength='10'
465 value='<?php echo htmlspecialchars($row['federaltaxid'], ENT_QUOTES); ?>' class='inputtext' />&nbsp;
466 <b><?php xl('Taxonomy','e'); ?>:</b> <input type='text' size='10' name='form_taxonomy' maxlength='10'
467 value='<?php echo htmlspecialchars($row['taxonomy'], ENT_QUOTES); ?>' class='inputtext' />
468 </td>
469 </tr>
471 <tr>
472 <td nowrap><b><?php xl('Notes','e'); ?>:</b></td>
473 <td>
474 <textarea rows='3' cols='40' name='form_notes' style='width:100%'
475 wrap='virtual' class='inputtext' /><?php echo $row['notes'] ?></textarea>
476 </td>
477 </tr>
479 </table>
481 <br />
483 <input type='submit' name='form_save' value=<?php xl('Save','e','\'','\''); ?> />
485 <?php if ($userid && !$row['username']) { ?>
486 &nbsp;
487 <input type='submit' name='form_delete' value=<?php xl('Delete','e','\'','\''); ?> style='color:red' />
488 <?php } ?>
490 &nbsp;
491 <input type='button' value=<?php xl('Cancel','e','\'','\''); ?> onclick='window.close()' />
492 </p>
494 </center>
495 </form>
496 </body>
497 </html>