Some fixes in phpgacl to work with php 5.4
[openemr.git] / interface / usergroup / addrbook_edit.php
blobb7ca9ce29cce9cca77a12e08e9f4e2abe35c937a
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 //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 $fld = add_escape_custom(trim($_POST[$name]));
33 return "'$fld'";
37 <html>
38 <head>
39 <title><?php echo $userid ? xlt('Edit') : xlt('Add New') ?> <?php echo xlt('Person'); ?></title>
40 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
41 <script type="text/javascript" src="../../library/js/jquery.1.3.2.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'");
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` = ?", 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');
122 else {
123 // Person centric
124 $form_title = invalue('form_title');
125 $form_fname = invalue('form_fname');
126 $form_lname = invalue('form_lname');
127 $form_mname = invalue('form_mname');
130 if ($userid) {
132 $query = "UPDATE users SET " .
133 "abook_type = " . invalue('form_abook_type') . ", " .
134 "title = " . $form_title . ", " .
135 "fname = " . $form_fname . ", " .
136 "lname = " . $form_lname . ", " .
137 "mname = " . $form_mname . ", " .
138 "specialty = " . invalue('form_specialty') . ", " .
139 "organization = " . invalue('form_organization') . ", " .
140 "valedictory = " . invalue('form_valedictory') . ", " .
141 "assistant = " . invalue('form_assistant') . ", " .
142 "federaltaxid = " . invalue('form_federaltaxid') . ", " .
143 "upin = " . invalue('form_upin') . ", " .
144 "npi = " . invalue('form_npi') . ", " .
145 "taxonomy = " . invalue('form_taxonomy') . ", " .
146 "cpoe = " . invalue('form_cpoe') . ", " .
147 "email = " . invalue('form_email') . ", " .
148 "email_direct = " . invalue('form_email_direct') . ", " .
149 "url = " . invalue('form_url') . ", " .
150 "street = " . invalue('form_street') . ", " .
151 "streetb = " . invalue('form_streetb') . ", " .
152 "city = " . invalue('form_city') . ", " .
153 "state = " . invalue('form_state') . ", " .
154 "zip = " . invalue('form_zip') . ", " .
155 "street2 = " . invalue('form_street2') . ", " .
156 "streetb2 = " . invalue('form_streetb2') . ", " .
157 "city2 = " . invalue('form_city2') . ", " .
158 "state2 = " . invalue('form_state2') . ", " .
159 "zip2 = " . invalue('form_zip2') . ", " .
160 "phone = " . invalue('form_phone') . ", " .
161 "phonew1 = " . invalue('form_phonew1') . ", " .
162 "phonew2 = " . invalue('form_phonew2') . ", " .
163 "phonecell = " . invalue('form_phonecell') . ", " .
164 "fax = " . invalue('form_fax') . ", " .
165 "notes = " . invalue('form_notes') . " " .
166 "WHERE id = '" . add_escape_custom($userid) . "'";
167 sqlStatement($query);
169 } else {
171 $userid = sqlInsert("INSERT INTO users ( " .
172 "username, password, authorized, info, source, " .
173 "title, fname, lname, mname, " .
174 "federaltaxid, federaldrugid, upin, facility, see_auth, active, npi, taxonomy, cpoe, " .
175 "specialty, organization, valedictory, assistant, billname, email, email_direct, url, " .
176 "street, streetb, city, state, zip, " .
177 "street2, streetb2, city2, state2, zip2, " .
178 "phone, phonew1, phonew2, phonecell, fax, notes, abook_type " .
179 ") VALUES ( " .
180 "'', " . // username
181 "'', " . // password
182 "0, " . // authorized
183 "'', " . // info
184 "NULL, " . // source
185 $form_title . ", " .
186 $form_fname . ", " .
187 $form_lname . ", " .
188 $form_mname . ", " .
189 invalue('form_federaltaxid') . ", " .
190 "'', " . // federaldrugid
191 invalue('form_upin') . ", " .
192 "'', " . // facility
193 "0, " . // see_auth
194 "1, " . // active
195 invalue('form_npi') . ", " .
196 invalue('form_taxonomy') . ", " .
197 invalue('form_cpoe') . ", " .
198 invalue('form_specialty') . ", " .
199 invalue('form_organization') . ", " .
200 invalue('form_valedictory') . ", " .
201 invalue('form_assistant') . ", " .
202 "'', " . // billname
203 invalue('form_email') . ", " .
204 invalue('form_email_direct') . ", " .
205 invalue('form_url') . ", " .
206 invalue('form_street') . ", " .
207 invalue('form_streetb') . ", " .
208 invalue('form_city') . ", " .
209 invalue('form_state') . ", " .
210 invalue('form_zip') . ", " .
211 invalue('form_street2') . ", " .
212 invalue('form_streetb2') . ", " .
213 invalue('form_city2') . ", " .
214 invalue('form_state2') . ", " .
215 invalue('form_zip2') . ", " .
216 invalue('form_phone') . ", " .
217 invalue('form_phonew1') . ", " .
218 invalue('form_phonew2') . ", " .
219 invalue('form_phonecell') . ", " .
220 invalue('form_fax') . ", " .
221 invalue('form_notes') . ", " .
222 invalue('form_abook_type') . " " .
223 ")");
228 else if ($_POST['form_delete']) {
230 if ($userid) {
231 // Be careful not to delete internal users.
232 sqlStatement("DELETE FROM users WHERE id = ? AND username = ''", array($userid));
237 if ($_POST['form_save'] || $_POST['form_delete']) {
238 // Close this window and redisplay the updated list.
239 echo "<script language='JavaScript'>\n";
240 if ($info_msg) echo " alert('".addslashes($info_msg)."');\n";
241 echo " window.close();\n";
242 echo " if (opener.refreshme) opener.refreshme();\n";
243 echo "</script></body></html>\n";
244 exit();
247 if ($userid) {
248 $row = sqlQuery("SELECT * FROM users WHERE id = ?", array($userid));
251 if ($type) { // note this only happens when its new
252 // Set up type
253 $row['abook_type'] = $type;
258 <script language="JavaScript">
259 $(document).ready(function() {
260 // customize the form via the type options
261 typeSelect("<?php echo attr($row['abook_type']); ?>");
262 if(abook_type == 'ord_lab') {
263 $('#cpoe_span').css('display','inline');
266 </script>
268 <form method='post' name='theform' action='addrbook_edit.php?userid=<?php echo attr($userid) ?>'>
269 <center>
271 <table border='0' width='100%'>
273 <?php if (acl_check('admin', 'practice' )) { // allow choose type option if have admin access ?>
274 <tr>
275 <td width='1%' nowrap><b><?php echo xlt('Type'); ?>:</b></td>
276 <td>
277 <?php
278 echo generate_select_list('form_abook_type', 'abook_type', $row['abook_type'], '', 'Unassigned', '', 'typeSelect(this.value)');
280 </td>
281 </tr>
282 <?php } // end of if has admin access ?>
284 <tr id="nameRow">
285 <td width='1%' nowrap><b><?php echo xlt('Name'); ?>:</b></td>
286 <td>
287 <?php
288 generate_form_field(array('data_type'=>1,'field_id'=>'title','list_id'=>'titles','empty_title'=>' '), $row['title']);
290 <b><?php echo xlt('Last'); ?>:</b><input type='text' size='10' name='form_lname' class='inputtext'
291 maxlength='50' value='<?php echo attr($row['lname']); ?>'/>&nbsp;
292 <b><?php echo xlt('First'); ?>:</b> <input type='text' size='10' name='form_fname' class='inputtext'
293 maxlength='50' value='<?php echo attr($row['fname']); ?>' />&nbsp;
294 <b><?php echo xlt('Middle'); ?>:</b> <input type='text' size='4' name='form_mname' class='inputtext'
295 maxlength='50' value='<?php echo attr($row['mname']); ?>' />
296 </td>
297 </tr>
299 <tr id="specialtyRow">
300 <td nowrap><b><?php echo xlt('Specialty'); ?>:</b></td>
301 <td>
302 <input type='text' size='40' name='form_specialty' maxlength='250'
303 value='<?php echo attr($row['specialty']); ?>'
304 style='width:100%' class='inputtext' />
305 </td>
306 </tr>
308 <tr>
309 <td nowrap><b><?php echo xlt('Organization'); ?>:</b></td>
310 <td>
311 <input type='text' size='40' name='form_organization' maxlength='250'
312 value='<?php echo attr($row['organization']); ?>'
313 style='width:100%' class='inputtext' />
314 <span id='cpoe_span' style="display:none;">
315 <input type='checkbox' title="<?php echo xla('CPOE'); ?>" name='form_cpoe' id='form_cpoe' value='1' <?php if($row['cpoe']=='1') echo "CHECKED"; ?>/>
316 <label for='form_cpoe'><b><?php echo xlt('CPOE'); ?></b></label>
317 </span>
318 </td>
319 </tr>
321 <tr id="nameDirectorRow">
322 <td width='1%' nowrap><b><?php echo xlt('Director Name'); ?>:</b></td>
323 <td>
324 <?php
325 generate_form_field(array('data_type'=>1,'field_id'=>'director_title','list_id'=>'titles','empty_title'=>' '), $row['title']);
327 <b><?php echo xlt('Last'); ?>:</b><input type='text' size='10' name='form_director_lname' class='inputtext'
328 maxlength='50' value='<?php echo attr($row['lname']); ?>'/>&nbsp;
329 <b><?php echo xlt('First'); ?>:</b> <input type='text' size='10' name='form_director_fname' class='inputtext'
330 maxlength='50' value='<?php echo attr($row['fname']); ?>' />&nbsp;
331 <b><?php echo xlt('Middle'); ?>:</b> <input type='text' size='4' name='form_director_mname' class='inputtext'
332 maxlength='50' value='<?php echo attr($row['mname']); ?>' />
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>
500 </center>
501 </form>
502 </body>
503 </html>