Improvements mostly concerning inventory.
[openemr.git] / interface / usergroup / usergroup_admin_add.php
blobae2594de8d7c154462edef050fe5f6caa3c1910c
1 <?php
3 /**
4 * Add new user.
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @author Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 require_once("../globals.php");
15 require_once("$srcdir/calendar.inc");
16 require_once("$srcdir/options.inc.php");
17 require_once("$srcdir/erx_javascript.inc.php");
19 use OpenEMR\Common\Acl\AclExtended;
20 use OpenEMR\Common\Acl\AclMain;
21 use OpenEMR\Common\Csrf\CsrfUtils;
22 use OpenEMR\Core\Header;
23 use OpenEMR\Menu\MainMenuRole;
24 use OpenEMR\Menu\PatientMenuRole;
25 use OpenEMR\Services\FacilityService;
26 use OpenEMR\Services\UserService;
28 $facilityService = new FacilityService();
30 if (!AclMain::aclCheckCore('admin', 'users')) {
31 exit();
34 $alertmsg = '';
37 <html>
38 <head>
40 <?php Header::setupHeader(['common','opener']); ?>
42 <script src="checkpwd_validation.js"></script>
44 <!-- validation library -->
45 <!--//Not lbf forms use the new validation, please make sure you have the corresponding values in the list Page validation-->
46 <?php $use_validate_js = 1;?>
47 <?php require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php"); ?>
48 <?php
49 //Gets validation rules from Page Validation list.
50 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
51 $collectthis = collectValidationPageRules("/interface/usergroup/usergroup_admin_add.php");
52 if (empty($collectthis)) {
53 $collectthis = "undefined";
54 } else {
55 $collectthis = json_sanitize($collectthis["new_user"]["rules"]);
58 <script>
61 * validation on the form with new client side validation (using validate.js).
62 * this enable to add new rules for this form in the pageValidation list.
63 * */
64 var collectvalidation = <?php echo $collectthis; ?>;
66 function trimAll(sString)
68 while (sString.substring(0,1) == ' ')
70 sString = sString.substring(1, sString.length);
72 while (sString.substring(sString.length-1, sString.length) == ' ')
74 sString = sString.substring(0,sString.length-1);
76 return sString;
79 function submitform() {
81 var valid = submitme(1, undefined, 'new_user', collectvalidation);
82 if (!valid) return;
84 top.restoreSession();
86 //Checking if secure password is enabled or disabled.
87 //If it is enabled and entered password is a weak password, alert the user to enter strong password.
88 if(document.new_user.secure_pwd.value == 1){
89 var password = trim(document.new_user.stiltskin.value);
90 if(password != "") {
91 var pwdresult = passwordvalidate(password);
92 if(pwdresult === 0){
93 alert(
94 <?php echo xlj('The password must be at least eight characters, and should'); ?> +
95 '\n' +
96 <?php echo xlj('contain at least three of the four following items:'); ?> +
97 '\n' +
98 <?php echo xlj('A number'); ?> +
99 '\n' +
100 <?php echo xlj('A lowercase letter'); ?> +
101 '\n' +
102 <?php echo xlj('An uppercase letter'); ?> +
103 '\n' +
104 <?php echo xlj('A special character'); ?> +
105 '\n' +
106 '(' +
107 <?php echo xlj('not a letter or number'); ?> +
108 ').' +
109 '\n' +
110 <?php echo xlj('For example:'); ?> +
111 ' healthCare@09'
113 return false;
116 } //secure_pwd if ends here
118 <?php if ($GLOBALS['erx_enable']) { ?>
119 alertMsg='';
120 f=document.forms[0];
121 for(i=0;i<f.length;i++){
122 if(f[i].type=='text' && f[i].value)
124 if(f[i].name == 'rumple')
126 alertMsg += checkLength(f[i].name,f[i].value,35);
127 alertMsg += checkUsername(f[i].name,f[i].value);
129 else if(f[i].name == 'fname' || f[i].name == 'mname' || f[i].name == 'lname')
131 alertMsg += checkLength(f[i].name,f[i].value,35);
132 alertMsg += checkUsername(f[i].name,f[i].value);
134 else if(f[i].name == 'federaltaxid')
136 alertMsg += checkLength(f[i].name,f[i].value,10);
137 alertMsg += checkFederalEin(f[i].name,f[i].value);
139 else if(f[i].name == 'state_license_number')
141 alertMsg += checkLength(f[i].name,f[i].value,10);
142 alertMsg += checkStateLicenseNumber(f[i].name,f[i].value);
144 else if(f[i].name == 'npi')
146 alertMsg += checkLength(f[i].name,f[i].value,35);
147 alertMsg += checkTaxNpiDea(f[i].name,f[i].value);
149 else if(f[i].name == 'federaldrugid')
151 alertMsg += checkLength(f[i].name,f[i].value,30);
152 alertMsg += checkAlphaNumeric(f[i].name,f[i].value);
156 if(alertMsg)
158 alert(alertMsg);
159 return false;
161 <?php } // End erx_enable only include block?>
163 let post_url = $("#new_user").attr("action");
164 let request_method = $("#new_user").attr("method");
165 let form_data = $("#new_user").serialize();
167 $.ajax({
168 url: post_url,
169 type: request_method,
170 data: form_data
171 }).done(function (r) {
172 if (r) {
173 alert(r);
174 } else {
175 dlgclose('reload', false);
179 return false;
181 function authorized_clicked() {
182 var f = document.forms[0];
183 f.calendar.disabled = !f.authorized.checked;
184 f.calendar.checked = f.authorized.checked;
187 </script>
188 <style>
189 .physician_type_class {
190 width: 120px !important;
192 #main_menu_role {
193 width: 120px !important;
195 </style>
196 </head>
197 <body class="body_top">
199 <div class="container">
201 <table><tr><td>
202 <span class="title"><?php echo xlt('Add User'); ?></span>&nbsp;</td>
203 <td>
204 <a class="btn btn-secondary btn-save" name='form_save' id='form_save' href='#' onclick="return submitform()">
205 <span><?php echo xlt('Save'); ?></span></a>
206 <a class="btn btn-link btn-cancel" id='cancel' href='#'>
207 <span><?php echo xlt('Cancel');?></span>
208 </a>
209 </td></tr></table>
210 <br /><br />
212 <table border='0'>
214 <tr>
215 <td valign='top'>
216 <form name='new_user' id="new_user" method='post' action="usergroup_admin.php">
217 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
219 <input type='hidden' name='mode' value='new_user'>
220 <input type='hidden' name='secure_pwd' value="<?php echo attr($GLOBALS['secure_password']); ?>">
222 <span class="font-weight-bold">&nbsp;</span>
223 <table class="border-0" cellpadding='0' cellspacing='0' style="width:600px;">
224 <tr>
225 <td style="width:150px;"><span class="text"><?php echo xlt('Username'); ?>: </span></td><td style="width:220px;"><input type="text" name="rumple" style="width:120px;" class="form-control"><span class="mandatory"></span></td>
226 <?php if (empty($GLOBALS['gbl_ldap_enabled']) || empty($GLOBALS['gbl_ldap_exclusions'])) { ?>
227 <td style="width:150px;"><span class="text"><?php echo xlt('Password'); ?>: </span></td><td style="width:250px;"><input type="password" style="width:120px;" name="stiltskin" class="form-control"><span class="mandatory"></span></td>
228 <?php } else { ?>
229 <td><input type="hidden" value="124" name="stiltskin" /></td>
230 <?php } ?>
231 </tr>
232 <tr>
233 <td style="width:150px;"></td><td style="width:220px;"></td>
234 <td style="width:200px;"><span class='text'><?php echo xlt('Your Password'); ?>: </span></td>
235 <td class='text' style="width:280px;"><input type='password' name=adminPass style="width:120px;" value="" autocomplete='off' class="form-control"><font class="mandatory"></font></td>
237 </tr>
238 <tr>
239 <td><span class="text"<?php echo ($GLOBALS['disable_non_default_groups']) ? " style='display: none'" : ""; ?>><?php echo xlt('Groupname'); ?>: </span></td>
240 <td>
241 <select name="groupname" class="form-control"<?php echo ($GLOBALS['disable_non_default_groups']) ? " style='display:none'" : ""; ?>>
242 <?php
243 $res = sqlStatement("select distinct name from `groups`");
244 $result2 = array();
245 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
246 $result2[$iter] = $row;
249 foreach ($result2 as $iter) {
250 print "<option value='" . attr($iter["name"]) . "'>" . text($iter["name"]) . "</option>\n";
253 </select></td>
254 <td colspan="2"><span class="text"><?php echo xlt('Provider'); ?>: </span>
255 <input type='checkbox' name='authorized' value='1' onclick='authorized_clicked()' />
256 <span class='text'><?php echo xlt('Calendar'); ?>:
257 <input type='checkbox' name='calendar' disabled /></span>
258 <span class=text><?php echo xlt('Portal'); ?>:
259 <input type="checkbox" name="portal_user" /></span>
260 </td>
261 </tr>
262 <tr>
263 <td><span class="text"><?php echo xlt('First Name'); ?>: </span></td><td><input type="text" name='fname' id='fname' style="width:120px;" class="form-control"><span class="mandatory"></span></td>
264 <td><span class="text"><?php echo xlt('Middle Name'); ?>: </span></td><td><input type="text" name='mname' style="width:120px;" class="form-control"></td>
265 </tr>
266 <tr>
267 <td><span class="text"><?php echo xlt('Last Name'); ?>: </span></td><td><input type="text" name='lname' id='lname' style="width:120px;" class="form-control"><span class="mandatory"></span></td>
268 <td><span class="text"><?php echo xlt('Default Facility'); ?>: </span></td>
269 <td>
270 <select style="width:120px;" name=facility_id class="form-control">
271 <?php
272 $fres = $facilityService->getAllServiceLocations();
273 if ($fres) {
274 for ($iter = 0; $iter < sizeof($fres); $iter++) {
275 $result[$iter] = $fres[$iter];
278 foreach ($result as $iter) {
280 <option value="<?php echo attr($iter['id']); ?>"><?php echo text($iter['name']); ?></option>
281 <?php
285 </select></td>
286 </tr>
287 <tr>
288 <td><span class="text"><?php echo xlt('Federal Tax ID'); ?>: </span></td><td><input type="text" name='federaltaxid' style="width:120px;" class="form-control"></td>
289 <td><span class="text"><?php echo xlt('DEA number'); ?>: </span></td><td><input type="text" name='federaldrugid' style="width:120px;" class="form-control"></td>
290 </tr>
291 <tr>
292 <td><span class="text"><?php echo xlt('UPIN'); ?>: </span></td><td><input type="text" name="upin" style="width:120px;" class="form-control"></td>
293 <td class='text'><?php echo xlt('See Authorizations'); ?>: </td>
294 <td><select name="see_auth" style="width:120px;" class="form-control">
295 <?php
296 foreach (array(1 => xl('None{{Authorization}}'), 2 => xl('Only Mine'), 3 => xl('All')) as $key => $value) {
297 echo " <option value='" . attr($key) . "'";
298 echo ">" . text($value) . "</option>\n";
301 </select></td>
303 <tr>
304 <td><span class="text"><?php echo xlt('NPI'); ?>: </span></td><td><input type="text" name="npi" style="width:120px;" class="form-control"></td>
305 <td><span class="text"><?php echo xlt('Job Description'); ?>: </span></td><td><input type="text" name="specialty" style="width:120px;" class="form-control"></td>
306 </tr>
308 <tr>
309 <td>
310 <span class="text"><?php echo xlt('Provider Type'); ?>: </span>
311 </td>
312 <td>
313 <?php echo generate_select_list("physician_type", "physician_type", '', '', xl('Select Type'), 'physician_type_class', '', '', ''); ?>
314 </td>
315 </tr>
316 <tr>
317 <td>
318 <span class="text"><?php echo xlt('Main Menu Role'); ?>: </span>
319 </td>
320 <td>
321 <?php
322 $menuMain = new MainMenuRole($GLOBALS['kernel']->getEventDispatcher());
323 echo $menuMain->displayMenuRoleSelector();
325 </td>
326 <td>
327 <span class="text"><?php echo xlt('Patient Menu Role'); ?>: </span>
328 </td>
329 <td>
330 <?php
331 $menuPatient = new PatientMenuRole();
332 echo $menuPatient->displayMenuRoleSelector();
334 </td>
335 </tr>
337 <tr>
338 <td><span class="text"><?php echo xlt('Taxonomy'); ?>: </span></td>
339 <td><input type="text" name="taxonomy" style="width:120px;" class="form-control" value="207Q00000X"></td>
340 <td><span class="text"><?php echo xlt('Supervisor'); ?>: </span></td>
341 <td>
342 <select name="supervisor_id" style="width:150px;" class="form-control">
343 <option value=""><?php echo xlt("Select Supervisor") ?></option>
344 <?php
345 $userService = new UserService();
346 $users = $userService->getActiveUsers();
347 foreach ($users as $activeUser) {
348 $p_id = (int)$activeUser['id'];
349 if ($activeUser['authorized'] != 1) {
350 continue;
352 echo "<option value='" . attr($p_id) . "'";
353 if ((int)($iter["supervisor_id"] ?? null) === $p_id) {
354 echo "selected";
356 echo ">" . text($activeUser['lname']) . ' ' .
357 text($activeUser['fname']) . ' ' . text($activeUser['mname']) . "</option>\n";
360 </select>
361 </td>
362 <tr>
363 <td><span class="text"><?php echo xlt('State License Number'); ?>: </span></td>
364 <td><input type="text" name="state_license_number" style="width:120px;" class="form-control"></td>
365 <td class='text'><?php echo xlt('NewCrop eRX Role'); ?>:</td>
366 <td>
367 <?php echo generate_select_list("erxrole", "newcrop_erx_role", '', '', '--Select Role--', '', '', '', array('style' => 'width:120px')); ?>
368 </td>
369 </tr>
370 <tr>
371 <td><span class="text"><?php echo xlt('Weno Provider ID'); ?>: </span></td><td><input type="text" name="erxprid" style="width:120px;" class="form-control" value="<?php echo attr($iter["weno_prov_id"] ?? ''); ?>"></td>
372 <td><span class="text"><?php echo xlt('Google Email for Login'); ?>: </span></td><td><input type="text" name="google_signin_email" style="width:150px;" class="form-control" value="<?php echo attr($iter["google_signin_email"]); ?>"></td>
373 </tr>
374 <?php if ($GLOBALS['inhouse_pharmacy']) { ?>
375 <tr>
376 <td class="text"><?php echo xlt('Default Warehouse'); ?>: </td>
377 <td class='text'>
378 <?php
379 echo generate_select_list(
380 'default_warehouse',
381 'warehouse',
386 </td>
387 <td class="text"><?php echo xlt('Invoice Refno Pool'); ?>: </td>
388 <td class='text'>
389 <?php
390 echo generate_select_list(
391 'irnpool',
392 'irnpool',
394 xl('Invoice reference number pool, if used')
397 </td>
398 </tr>
399 <?php } ?>
401 <!-- facility and warehouse restrictions, optional -->
402 <?php if (!empty($GLOBALS['gbl_fac_warehouse_restrictions']) || !empty($GLOBALS['restrict_user_facility'])) { ?>
403 <tr title="<?php echo xla('If nothing is selected here then all are permitted.'); ?>">
404 <td class="text"><?php echo !empty($GLOBALS['gbl_fac_warehouse_restrictions']) ?
405 xlt('Facility and warehouse permissions') : xlt('Facility permissions'); ?>:</td>
406 <td colspan="3">
407 <select name="schedule_facility[]" multiple style="width:490px;">
408 <?php
409 $user_id = 0; // in user_admin.php this is intval($_GET["id"]).
410 $userFacilities = getUserFacilities($user_id, 'id', $GLOBALS['gbl_fac_warehouse_restrictions']);
411 $ufid = array();
412 foreach ($userFacilities as $uf) {
413 $ufid[] = $uf['id'];
415 $fres = sqlStatement("select * from facility order by name");
416 if ($fres) {
417 while ($frow = sqlFetchArray($fres)) {
418 // Get the warehouses that are linked to this user and facility.
419 $whids = getUserFacWH($user_id, $frow['id']); // from calendar.inc
420 // Generate an option for just the facility with no warehouse restriction.
421 echo " <option";
422 if (empty($whids) && in_array($frow['id'], $ufid)) {
423 echo ' selected';
425 echo " value='" . attr($frow['id']) . "'>" . text($frow['name']) . "</option>\n";
426 // Then generate an option for each of the facility's warehouses.
427 // Does not apply if the site does not use warehouse restrictions.
428 if (!empty($GLOBALS['gbl_fac_warehouse_restrictions'])) {
429 $lres = sqlStatement(
430 "SELECT option_id, title FROM list_options WHERE " .
431 "list_id = ? AND option_value = ? ORDER BY seq, title",
432 array('warehouse', $frow['id'])
434 while ($lrow = sqlFetchArray($lres)) {
435 echo " <option";
436 if (in_array($lrow['option_id'], $whids)) {
437 echo ' selected';
439 echo " value='" . attr($frow['id']) . "/" . attr($lrow['option_id']) . "'>&nbsp;&nbsp;&nbsp;" .
440 text(xl_list_label($lrow['title'])) . "</option>\n";
446 </select>
447 </td>
448 </tr>
449 <?php } ?>
451 <tr>
452 <td class='text'><?php echo xlt('Access Control'); ?>:</td>
453 <td><select name="access_group[]" multiple style="width:120px;" class="form-control">
454 <?php
455 // List the access control groups
456 $is_super_user = AclMain::aclCheckCore('admin', 'super');
457 $list_acl_groups = AclExtended::aclGetGroupTitleList($is_super_user ? true : false);
458 $default_acl_group = 'Administrators';
459 foreach ($list_acl_groups as $value) {
460 if ($is_super_user && $default_acl_group == $value) {
461 // Modified 6-2009 by BM - Translate group name if applicable
462 echo " <option value='" . attr($value) . "' selected>" . text(xl_gacl_group($value)) . "</option>\n";
463 } else {
464 // Modified 6-2009 by BM - Translate group name if applicable
465 echo " <option value='" . attr($value) . "'>" . text(xl_gacl_group($value)) . "</option>\n";
469 </select></td>
470 <td><span class="text"><?php echo xlt('Additional Info'); ?>: </span></td>
471 <td><textarea name=info style="width:120px;" cols='27' rows='4' wrap='auto' class="form-control"></textarea></td>
473 </tr>
474 <tr height="25"><td colspan="4">&nbsp;</td></tr>
476 </table>
478 <br />
479 <input type="hidden" name="newauthPass">
480 </form>
481 </td>
483 </tr>
485 <tr<?php echo ($GLOBALS['disable_non_default_groups']) ? " style='display:none'" : ""; ?>>
487 <td valign='top'>
488 <form name='new_group' method='post' action="usergroup_admin.php"
489 onsubmit='return top.restoreSession()'>
490 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
491 <br />
492 <input type='hidden' name='mode' value='new_group' />
493 <span class="bold"><?php echo xlt('New Group'); ?>:</span>
494 </td>
495 <td>
496 <span class="text"><?php echo xlt('Groupname'); ?>: </span><input type="text" name='groupname' size='10'>
497 &nbsp;&nbsp;&nbsp;
498 <span class="text"><?php echo xlt('Initial User'); ?>: </span>
499 <select name='rumple'>
500 <?php
501 $res = sqlStatement("select distinct username from users where username != ''");
502 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
503 $result[$iter] = $row;
506 foreach ($result as $iter) {
507 print "<option value='" . attr($iter["username"]) . "'>" . text($iter["username"]) . "</option>\n";
510 </select>
511 &nbsp;&nbsp;&nbsp;
512 <input type="submit" value="<?php echo xla('Save'); ?>" />
513 </form>
514 </td>
516 </tr>
518 <tr<?php echo ($GLOBALS['disable_non_default_groups']) ? " style='display:none'" : ""; ?>>
520 <td valign='top'>
521 <form name='new_group' method='post' action="usergroup_admin.php"
522 onsubmit='return top.restoreSession()'>
523 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
524 <input type='hidden' name='mode' value='new_group' />
525 <span class="bold"><?php echo xlt('Add User To Group'); ?>:</span>
526 </td>
527 <td>
528 <span class="text">
529 <?php echo xlt('User'); ?>
530 : </span>
531 <select name='rumple'>
532 <?php
533 $res = sqlStatement("select distinct username from users where username != ''");
534 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
535 $result3[$iter] = $row;
538 foreach ($result3 as $iter) {
539 print "<option value='" . attr($iter["username"]) . "'>" . text($iter["username"]) . "</option>\n";
542 </select>
543 &nbsp;&nbsp;&nbsp;
544 <span class="text"><?php echo xlt('Groupname'); ?>: </span>
545 <select name='groupname'>
546 <?php
547 $res = sqlStatement("select distinct name from `groups`");
548 $result2 = array();
549 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
550 $result2[$iter] = $row;
553 foreach ($result2 as $iter) {
554 print "<option value='" . attr($iter["name"]) . "'>" . text($iter["name"]) . "</option>\n";
557 </select>
558 &nbsp;&nbsp;&nbsp;
559 <input type="submit" value="<?php echo xla('Add User To Group'); ?>" />
560 </form>
561 </td>
562 </tr>
564 </table>
566 <?php
567 if (empty($GLOBALS['disable_non_default_groups'])) {
568 $res = sqlStatement("select * from `groups` order by name");
569 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
570 $result5[$iter] = $row;
573 foreach ($result5 as $iter) {
574 $grouplist[$iter["name"]] .= $iter["user"] .
575 "(<a class='link_submit' href='usergroup_admin.php?mode=delete_group&id=" .
576 attr_url($iter["id"]) . "&csrf_token_form=" . attr_url(CsrfUtils::collectCsrfToken()) . "' onclick='top.restoreSession()'>" . xlt("Remove") . "</a>), ";
579 foreach ($grouplist as $groupname => $list) {
580 print "<span class='font-weight-bold'>" . text($groupname) . "</span><br />\n<span class='text'>" .
581 text(substr($list, 0, strlen($list) - 2)) . "</span><br />\n";
586 <script>
587 <?php
588 if ($alertmsg = trim($alertmsg)) {
589 echo "alert('" . js_escape($alertmsg) . "');\n";
592 $(function () {
593 $("#cancel").click(function() {
594 dlgclose();
598 </script>
599 <table>
601 </table>
603 </div>
605 </body>
606 </html>