Fix for issue #291
[openemr.git] / interface / usergroup / addrbook_edit.php
blob1b95093c126300f7363f3b1304db3af56bbf2f1f
1 <?php
2 // Copyright (C) 2006-2010, 2016 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 //SANITIZE ALL ESCAPES
10 $sanitize_all_escapes=true;
13 //STOP FAKE REGISTER GLOBALS
14 $fake_register_globals=false;
17 include_once("../globals.php");
18 include_once("$srcdir/acl.inc");
19 require_once("$srcdir/options.inc.php");
20 require_once("$srcdir/formdata.inc.php");
21 require_once("$srcdir/htmlspecialchars.inc.php");
23 // Collect user id if editing entry
24 $userid = $_REQUEST['userid'];
26 // Collect type if creating a new entry
27 $type = $_REQUEST['type'];
29 $info_msg = "";
31 function invalue($name) {
32 if (!$_POST[$name]) return "''";
33 $fld = add_escape_custom(trim($_POST[$name]));
34 return "'$fld'";
38 <html>
39 <head>
40 <title><?php echo $userid ? xlt('Edit') : xlt('Add New') ?> <?php echo xlt('Person'); ?></title>
41 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
42 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
43 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script>
45 <style>
46 td { font-size:10pt; }
48 .inputtext {
49 padding-left:2px;
50 padding-right:2px;
53 .button {
54 font-family:sans-serif;
55 font-size:9pt;
56 font-weight:bold;
58 </style>
60 <script language="JavaScript">
62 var type_options_js = Array();
63 <?php
64 // Collect the type options. Possible values are:
65 // 1 = Unassigned (default to person centric)
66 // 2 = Person Centric
67 // 3 = Company Centric
68 $sql = sqlStatement("SELECT option_id, option_value FROM list_options WHERE " .
69 "list_id = 'abook_type' AND activity = 1");
70 while ($row_query = sqlFetchArray($sql)) {
71 echo "type_options_js"."['" . attr($row_query['option_id']) . "']=" . attr($row_query['option_value']) . ";\n";
75 // Process to customize the form by type
76 function typeSelect(a) {
77 if(a=='ord_lab'){
78 $('#cpoe_span').css('display','inline');
79 } else {
80 $('#cpoe_span').css('display','none');
81 $('#form_cpoe').removeAttr('checked');
83 if (type_options_js[a] == 3) {
84 // Company centric:
85 // 1) Hide the person Name entries
86 // 2) Hide the Specialty entry
87 // 3) Show the director Name entries
88 document.getElementById("nameRow").style.display = "none";
89 document.getElementById("specialtyRow").style.display = "none";
90 document.getElementById("nameDirectorRow").style.display = "";
92 else {
93 // Person centric:
94 // 1) Hide the director Name entries
95 // 2) Show the person Name entries
96 // 3) Show the Specialty entry
97 document.getElementById("nameDirectorRow").style.display = "none";
98 document.getElementById("nameRow").style.display = "";
99 document.getElementById("specialtyRow").style.display = "";
102 </script>
104 </head>
106 <body class="body_top">
107 <?php
108 // If we are saving, then save and close the window.
110 if ($_POST['form_save']) {
112 // Collect the form_abook_type option value
113 // (ie. patient vs company centric)
114 $type_sql_row = sqlQuery("SELECT `option_value` FROM `list_options` WHERE `list_id` = 'abook_type' AND `option_id` = ? AND activity = 1", array(trim($_POST['form_abook_type'])));
115 $option_abook_type = $type_sql_row['option_value'];
116 // Set up any abook_type specific settings
117 if ($option_abook_type == 3) {
118 // Company centric
119 $form_title = invalue('form_director_title');
120 $form_fname = invalue('form_director_fname');
121 $form_lname = invalue('form_director_lname');
122 $form_mname = invalue('form_director_mname');
123 $form_suffix = invalue('form_director_suffix');
125 else {
126 // Person centric
127 $form_title = invalue('form_title');
128 $form_fname = invalue('form_fname');
129 $form_lname = invalue('form_lname');
130 $form_mname = invalue('form_mname');
131 $form_suffix = invalue('form_suffix');
134 if ($userid) {
136 $query = "UPDATE users SET " .
137 "abook_type = " . invalue('form_abook_type') . ", " .
138 "title = " . $form_title . ", " .
139 "fname = " . $form_fname . ", " .
140 "lname = " . $form_lname . ", " .
141 "mname = " . $form_mname . ", " .
142 "suffix = " . $form_suffix . ", " .
143 "specialty = " . invalue('form_specialty') . ", " .
144 "organization = " . invalue('form_organization') . ", " .
145 "valedictory = " . invalue('form_valedictory') . ", " .
146 "assistant = " . invalue('form_assistant') . ", " .
147 "federaltaxid = " . invalue('form_federaltaxid') . ", " .
148 "upin = " . invalue('form_upin') . ", " .
149 "npi = " . invalue('form_npi') . ", " .
150 "taxonomy = " . invalue('form_taxonomy') . ", " .
151 "cpoe = " . invalue('form_cpoe') . ", " .
152 "email = " . invalue('form_email') . ", " .
153 "email_direct = " . invalue('form_email_direct') . ", " .
154 "url = " . invalue('form_url') . ", " .
155 "street = " . invalue('form_street') . ", " .
156 "streetb = " . invalue('form_streetb') . ", " .
157 "city = " . invalue('form_city') . ", " .
158 "state = " . invalue('form_state') . ", " .
159 "zip = " . invalue('form_zip') . ", " .
160 "street2 = " . invalue('form_street2') . ", " .
161 "streetb2 = " . invalue('form_streetb2') . ", " .
162 "city2 = " . invalue('form_city2') . ", " .
163 "state2 = " . invalue('form_state2') . ", " .
164 "zip2 = " . invalue('form_zip2') . ", " .
165 "phone = " . invalue('form_phone') . ", " .
166 "phonew1 = " . invalue('form_phonew1') . ", " .
167 "phonew2 = " . invalue('form_phonew2') . ", " .
168 "phonecell = " . invalue('form_phonecell') . ", " .
169 "fax = " . invalue('form_fax') . ", " .
170 "notes = " . invalue('form_notes') . " " .
171 "WHERE id = '" . add_escape_custom($userid) . "'";
172 sqlStatement($query);
174 } else {
176 $userid = sqlInsert("INSERT INTO users ( " .
177 "username, password, authorized, info, source, " .
178 "title, fname, lname, mname, suffix, " .
179 "federaltaxid, federaldrugid, upin, facility, see_auth, active, npi, taxonomy, cpoe, " .
180 "specialty, organization, valedictory, assistant, billname, email, email_direct, url, " .
181 "street, streetb, city, state, zip, " .
182 "street2, streetb2, city2, state2, zip2, " .
183 "phone, phonew1, phonew2, phonecell, fax, notes, abook_type " .
184 ") VALUES ( " .
185 "'', " . // username
186 "'', " . // password
187 "0, " . // authorized
188 "'', " . // info
189 "NULL, " . // source
190 $form_title . ", " .
191 $form_fname . ", " .
192 $form_lname . ", " .
193 $form_mname . ", " .
194 $form_suffix . ", " .
195 invalue('form_federaltaxid') . ", " .
196 "'', " . // federaldrugid
197 invalue('form_upin') . ", " .
198 "'', " . // facility
199 "0, " . // see_auth
200 "1, " . // active
201 invalue('form_npi') . ", " .
202 invalue('form_taxonomy') . ", " .
203 invalue('form_cpoe') . ", " .
204 invalue('form_specialty') . ", " .
205 invalue('form_organization') . ", " .
206 invalue('form_valedictory') . ", " .
207 invalue('form_assistant') . ", " .
208 "'', " . // billname
209 invalue('form_email') . ", " .
210 invalue('form_email_direct') . ", " .
211 invalue('form_url') . ", " .
212 invalue('form_street') . ", " .
213 invalue('form_streetb') . ", " .
214 invalue('form_city') . ", " .
215 invalue('form_state') . ", " .
216 invalue('form_zip') . ", " .
217 invalue('form_street2') . ", " .
218 invalue('form_streetb2') . ", " .
219 invalue('form_city2') . ", " .
220 invalue('form_state2') . ", " .
221 invalue('form_zip2') . ", " .
222 invalue('form_phone') . ", " .
223 invalue('form_phonew1') . ", " .
224 invalue('form_phonew2') . ", " .
225 invalue('form_phonecell') . ", " .
226 invalue('form_fax') . ", " .
227 invalue('form_notes') . ", " .
228 invalue('form_abook_type') . " " .
229 ")");
234 else if ($_POST['form_delete']) {
236 if ($userid) {
237 // Be careful not to delete internal users.
238 sqlStatement("DELETE FROM users WHERE id = ? AND username = ''", array($userid));
243 if ($_POST['form_save'] || $_POST['form_delete']) {
244 // Close this window and redisplay the updated list.
245 echo "<script language='JavaScript'>\n";
246 if ($info_msg) echo " alert('".addslashes($info_msg)."');\n";
247 echo " window.close();\n";
248 echo " if (opener.refreshme) opener.refreshme();\n";
249 echo "</script></body></html>\n";
250 exit();
253 if ($userid) {
254 $row = sqlQuery("SELECT * FROM users WHERE id = ?", array($userid));
257 if ($type) { // note this only happens when its new
258 // Set up type
259 $row['abook_type'] = $type;
264 <script language="JavaScript">
265 $(document).ready(function() {
266 // customize the form via the type options
267 typeSelect("<?php echo attr($row['abook_type']); ?>");
268 if(abook_type == 'ord_lab') {
269 $('#cpoe_span').css('display','inline');
272 </script>
274 <form method='post' name='theform' action='addrbook_edit.php?userid=<?php echo attr($userid) ?>'>
275 <center>
277 <table border='0' width='100%'>
279 <?php if (acl_check('admin', 'practice' )) { // allow choose type option if have admin access ?>
280 <tr>
281 <td width='1%' nowrap><b><?php echo xlt('Type'); ?>:</b></td>
282 <td>
283 <?php
284 echo generate_select_list('form_abook_type', 'abook_type', $row['abook_type'], '', 'Unassigned', '', 'typeSelect(this.value)');
286 </td>
287 </tr>
288 <?php } // end of if has admin access ?>
290 <tr id="nameRow">
291 <td width='1%' nowrap><b><?php echo xlt('Name'); ?>:</b></td>
292 <td>
293 <?php
294 generate_form_field(array('data_type'=>1,'field_id'=>'title','list_id'=>'titles','empty_title'=>' '), $row['title']);
296 <b><?php echo xlt('Last'); ?>:</b><input type='text' size='10' name='form_lname' class='inputtext'
297 maxlength='50' value='<?php echo attr($row['lname']); ?>'/>&nbsp;
298 <b><?php echo xlt('First'); ?>:</b> <input type='text' size='10' name='form_fname' class='inputtext'
299 maxlength='50' value='<?php echo attr($row['fname']); ?>' />&nbsp;
300 <b><?php echo xlt('Middle'); ?>:</b> <input type='text' size='4' name='form_mname' class='inputtext'
301 maxlength='50' value='<?php echo attr($row['mname']); ?>' />
302 <b><?php echo xlt('Suffix'); ?>:</b> <input type='text' size='4' name='form_suffix' class='inputtext'
303 maxlength='50' value='<?php echo attr($row['suffix']); ?>' />
304 </td>
305 </tr>
307 <tr id="specialtyRow">
308 <td nowrap><b><?php echo xlt('Specialty'); ?>:</b></td>
309 <td>
310 <input type='text' size='40' name='form_specialty' maxlength='250'
311 value='<?php echo attr($row['specialty']); ?>'
312 style='width:100%' class='inputtext' />
313 </td>
314 </tr>
316 <tr>
317 <td nowrap><b><?php echo xlt('Organization'); ?>:</b></td>
318 <td>
319 <input type='text' size='40' name='form_organization' maxlength='250'
320 value='<?php echo attr($row['organization']); ?>'
321 style='width:100%' class='inputtext' />
322 <span id='cpoe_span' style="display:none;">
323 <input type='checkbox' title="<?php echo xla('CPOE'); ?>" name='form_cpoe' id='form_cpoe' value='1' <?php if($row['cpoe']=='1') echo "CHECKED"; ?>/>
324 <label for='form_cpoe'><b><?php echo xlt('CPOE'); ?></b></label>
325 </span>
326 </td>
327 </tr>
329 <tr id="nameDirectorRow">
330 <td width='1%' nowrap><b><?php echo xlt('Director Name'); ?>:</b></td>
331 <td>
332 <?php
333 generate_form_field(array('data_type'=>1,'field_id'=>'director_title','list_id'=>'titles','empty_title'=>' '), $row['title']);
335 <b><?php echo xlt('Last'); ?>:</b><input type='text' size='10' name='form_director_lname' class='inputtext'
336 maxlength='50' value='<?php echo attr($row['lname']); ?>'/>&nbsp;
337 <b><?php echo xlt('First'); ?>:</b> <input type='text' size='10' name='form_director_fname' class='inputtext'
338 maxlength='50' value='<?php echo attr($row['fname']); ?>' />&nbsp;
339 <b><?php echo xlt('Middle'); ?>:</b> <input type='text' size='4' name='form_director_mname' class='inputtext'
340 maxlength='50' value='<?php echo attr($row['mname']); ?>' />
341 <b><?php echo xlt('Suffix'); ?>:</b> <input type='text' size='4' name='form_director_suffix' class='inputtext'
342 maxlength='50' value='<?php echo attr($row['suffix']); ?>' />
343 </td>
344 </tr>
346 <tr>
347 <td nowrap><b><?php echo xlt('Valedictory'); ?>:</b></td>
348 <td>
349 <input type='text' size='40' name='form_valedictory' maxlength='250'
350 value='<?php echo attr($row['valedictory']); ?>'
351 style='width:100%' class='inputtext' />
352 </td>
353 </tr>
355 <tr>
356 <td nowrap><b><?php echo xlt('Home Phone'); ?>:</b></td>
357 <td>
358 <input type='text' size='11' name='form_phone' value='<?php echo attr($row['phone']); ?>'
359 maxlength='30' class='inputtext' />&nbsp;
360 <b><?php echo xlt('Mobile'); ?>:</b><input type='text' size='11' name='form_phonecell'
361 maxlength='30' value='<?php echo attr($row['phonecell']); ?>' class='inputtext' />
362 </td>
363 </tr>
365 <tr>
366 <td nowrap><b><?php echo xlt('Work Phone'); ?>:</b></td>
367 <td>
368 <input type='text' size='11' name='form_phonew1' value='<?php echo attr($row['phonew1']); ?>'
369 maxlength='30' class='inputtext' />&nbsp;
370 <b><?php echo xlt('2nd'); ?>:</b><input type='text' size='11' name='form_phonew2' value='<?php echo attr($row['phonew2']); ?>'
371 maxlength='30' class='inputtext' />&nbsp;
372 <b><?php echo xlt('Fax'); ?>:</b> <input type='text' size='11' name='form_fax' value='<?php echo attr($row['fax']); ?>'
373 maxlength='30' class='inputtext' />
374 </td>
375 </tr>
377 <tr>
378 <td nowrap><b><?php echo xlt('Assistant'); ?>:</b></td>
379 <td>
380 <input type='text' size='40' name='form_assistant' maxlength='250'
381 value='<?php echo attr($row['assistant']); ?>'
382 style='width:100%' class='inputtext' />
383 </td>
384 </tr>
386 <tr>
387 <td nowrap><b><?php echo xlt('Email'); ?>:</b></td>
388 <td>
389 <input type='text' size='40' name='form_email' maxlength='250'
390 value='<?php echo attr($row['email']); ?>'
391 style='width:100%' class='inputtext' />
392 </td>
393 </tr>
395 <tr>
396 <td nowrap><b><?php echo xlt('Trusted Email'); ?>:</b></td>
397 <td>
398 <input type='text' size='40' name='form_email_direct' maxlength='250'
399 value='<?php echo attr($row['email_direct']); ?>'
400 style='width:100%' class='inputtext' />
401 </td>
402 </tr>
404 <tr>
405 <td nowrap><b><?php echo xlt('Website'); ?>:</b></td>
406 <td>
407 <input type='text' size='40' name='form_url' maxlength='250'
408 value='<?php echo attr($row['url']); ?>'
409 style='width:100%' class='inputtext' />
410 </td>
411 </tr>
413 <tr>
414 <td nowrap><b><?php echo xlt('Main Address'); ?>:</b></td>
415 <td>
416 <input type='text' size='40' name='form_street' maxlength='60'
417 value='<?php echo attr($row['street']); ?>'
418 style='width:100%' class='inputtext' />
419 </td>
420 </tr>
422 <tr>
423 <td nowrap>&nbsp;</td>
424 <td>
425 <input type='text' size='40' name='form_streetb' maxlength='60'
426 value='<?php echo attr($row['streetb']); ?>'
427 style='width:100%' class='inputtext' />
428 </td>
429 </tr>
431 <tr>
432 <td nowrap><b><?php echo xlt('City'); ?>:</b></td>
433 <td>
434 <input type='text' size='10' name='form_city' maxlength='30'
435 value='<?php echo attr($row['city']); ?>' class='inputtext' />&nbsp;
436 <b><?php echo xlt('State')."/".xlt('county'); ?>:</b> <input type='text' size='10' name='form_state' maxlength='30'
437 value='<?php echo attr($row['state']); ?>' class='inputtext' />&nbsp;
438 <b><?php echo xlt('Postal code'); ?>:</b> <input type='text' size='10' name='form_zip' maxlength='20'
439 value='<?php echo attr($row['zip']); ?>' class='inputtext' />
440 </td>
441 </tr>
443 <tr>
444 <td nowrap><b><?php echo xlt('Alt Address'); ?>:</b></td>
445 <td>
446 <input type='text' size='40' name='form_street2' maxlength='60'
447 value='<?php echo attr($row['street2']); ?>'
448 style='width:100%' class='inputtext' />
449 </td>
450 </tr>
452 <tr>
453 <td nowrap>&nbsp;</td>
454 <td>
455 <input type='text' size='40' name='form_streetb2' maxlength='60'
456 value='<?php echo attr($row['streetb2']); ?>'
457 style='width:100%' class='inputtext' />
458 </td>
459 </tr>
461 <tr>
462 <td nowrap><b><?php echo xlt('City'); ?>:</b></td>
463 <td>
464 <input type='text' size='10' name='form_city2' maxlength='30'
465 value='<?php echo attr($row['city2']); ?>' class='inputtext' />&nbsp;
466 <b><?php echo xlt('State')."/".xlt('county'); ?>:</b> <input type='text' size='10' name='form_state2' maxlength='30'
467 value='<?php echo attr($row['state2']); ?>' class='inputtext' />&nbsp;
468 <b><?php echo xlt('Postal code'); ?>:</b> <input type='text' size='10' name='form_zip2' maxlength='20'
469 value='<?php echo attr($row['zip2']); ?>' class='inputtext' />
470 </td>
471 </tr>
473 <tr>
474 <td nowrap><b><?php echo xlt('UPIN'); ?>:</b></td>
475 <td>
476 <input type='text' size='6' name='form_upin' maxlength='6'
477 value='<?php echo attr($row['upin']); ?>' class='inputtext' />&nbsp;
478 <b><?php echo xlt('NPI'); ?>:</b> <input type='text' size='10' name='form_npi' maxlength='10'
479 value='<?php echo attr($row['npi']); ?>' class='inputtext' />&nbsp;
480 <b><?php echo xlt('TIN'); ?>:</b> <input type='text' size='10' name='form_federaltaxid' maxlength='10'
481 value='<?php echo attr($row['federaltaxid']); ?>' class='inputtext' />&nbsp;
482 <b><?php echo xlt('Taxonomy'); ?>:</b> <input type='text' size='10' name='form_taxonomy' maxlength='10'
483 value='<?php echo attr($row['taxonomy']); ?>' class='inputtext' />
484 </td>
485 </tr>
487 <tr>
488 <td nowrap><b><?php echo xlt('Notes'); ?>:</b></td>
489 <td>
490 <textarea rows='3' cols='40' name='form_notes' style='width:100%'
491 wrap='virtual' class='inputtext' /><?php echo text($row['notes']) ?></textarea>
492 </td>
493 </tr>
495 </table>
497 <br />
499 <input type='submit' name='form_save' value='<?php echo xla('Save'); ?>' />
501 <?php if ($userid && !$row['username']) { ?>
502 &nbsp;
503 <input type='submit' name='form_delete' value='<?php echo xla('Delete'); ?>' style='color:red' />
504 <?php } ?>
506 &nbsp;
507 <input type='button' value='<?php echo xla('Cancel'); ?>' onclick='window.close()' />
508 </p>
510 </center>
511 </form>
512 </body>
513 </html>