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