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