6 $dontRunGroupSearch =
true;
7 require_once(
"userSearch.i");
8 require_once(
"aGroupSupport.i");
9 require_once(
"$sharedLibrary/hcuTranslate.i");
11 $parameters = array(
"a" => array(
"operation" =>
""));
12 $string = array(
"filter" => FILTER_DEFAULT);
13 HCU_ImportVars($parameters,
"a", array(
"operation" => $string));
15 switch($parameters[
"a"][
"operation"]) {
17 $returnArray = addUser($dbh, $Cu, $Cn);
19 header(
'Content-type: application/json');
20 print HCU_JsonEncode($returnArray);
22 case "validateUsername":
23 $parameters = array(
"a" => array(
"username" =>
""));
24 HCU_ImportVars($parameters,
"a", array(
"username" => $string));
25 $username = HCU_array_key_exists(
"username", $parameters[
"a"]) ? trim($parameters[
"a"][
"username"]) :
"";
26 $returnArray = validateUsername($dbh, $Cu, $username);
28 header(
'Content-type: application/json');
29 print HCU_JsonEncode($returnArray);
43 function validateUsername($dbh, $Cu, $username) {
48 if (!ctype_digit(strval(trim($username)))) {
50 if ( strlen( $username ) >= 0 && strlen( $username ) < 6 ) {
51 throw new exception ($MC->msg(
'Username too short', HCU_DISPLAY_AS_JS), 1);
54 if ( strlen( $username ) > 5 && !check_alias_format( $username ) ) {
56 throw new exception ($MC->msg(
'Username appears invalid', HCU_DISPLAY_AS_JS), 2);
60 $sql =
"select 'FOUND' from ${Cu}user where lower(trim(user_name)) = '" . prep_save(strtolower(trim($username)), 50) .
"'";
61 $sth = db_query($sql, $dbh);
62 if (!$sth || db_num_rows($sth) > 0) {
63 throw new exception($MC->msg(
"Username not available" , HCU_DISPLAY_AS_JS), 3);
66 $returnArray = array(
"status" =>
"000",
"error" =>
"");
67 }
catch(exception $e) {
68 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
83 function readForAddUser($dbh, $Cu) {
85 $sql =
"select profile_id as value, trim(description) as text from cu_profile where cu = '$Cu' order by trim(description)";
86 $sth = db_query($sql, $dbh);
88 throw new exception(
"profile id query failed.", 1);
90 $ddl = array(array(
"value" =>
"",
"text" =>
"(None)"));
91 for($i = 0; $row = db_fetch_assoc($sth, $i); $i++) {
95 $sql =
"select profile_id from cu_profile p left join cuadmin a on p.profile_code = a.settings::json->>'profile' where a.cu = '$Cu'";
96 $sth = db_query($sql, $dbh);
98 throw new Exception(
"default profile query failed.", 2);
100 $dftprofile = db_fetch_row($sth, 0)[0];
102 $sql =
"select pwdconfig from cuadmin where cu = '$Cu'";
103 $sth = db_query($sql, $dbh);
105 throw new exception(
"pwdconfig query failed.", 4);
107 $pwdconfig = db_fetch_row($sth, 0)[0];
108 $pwdconfig = HCU_JsonDecode($pwdconfig);
109 if (!is_array($pwdconfig)) {
110 throw new exception(
"Password array is malformed.", 5);
113 return array(
"code" => 0,
"error" => array(),
"profileDDL" => $ddl,
"profileDefault" => $dftprofile,
"passwordRules" => $pwdconfig,
114 "usePhonesInsteadOfMFA" => getUsePhonesInsteadOfMFA($dbh, $Cu));
115 }
catch(exception $e) {
116 return array(
"code" => $e->getCode(),
"error" => array($e->getMessage()),
"profileDDL" => array(),
"profileDefault"=>
"",
"passwordRules" => array(),
117 "usePhonesInsteadOfMFA" =>
false);
133 function addUser($dbh, $Cu, $Cn) {
134 $parameters = array(
"a" => array(
"username" =>
"",
"email" =>
"",
"password" =>
"",
"phone" =>
"",
"groupId" =>
"",
"profileId" =>
"",
"confirm" =>
""));
135 $encryption = array(
"message" =>
"",
"hash" =>
"");
137 $string = array(
"filter" => HCUFILTER_INPUT_STRING);
138 HCU_ImportVars($parameters,
"a", array(
"username" => $string,
"email" => $string,
"password" => $string,
"phones" => $string,
"groupId" => $string,
139 "profileId" => $string,
"confirm" => $string));
140 extract($parameters[
"a"]);
142 $username = isset($username) ? trim($username) :
"";
143 $email = isset($email) ? trim($email) :
"";
144 $password = isset($password) ? trim($password) :
"";
145 $phones = isset($phones) ? trim($phones) :
"";
146 $groupId = isset($groupId) ? trim($groupId) :
"";
147 $profileId = isset($profileId) ? trim($profileId) :
"";
148 $confirm = isset($confirm) ? trim($confirm) :
"";
150 if ($username ==
"") {
151 throw new exception(
"Username is required.", 1);
154 throw new exception(
"Email is required.", 2);
156 if ($password ==
"") {
157 throw new exception(
"Password is required.", 3);
159 if ($password != $confirm) {
160 throw new exception(
"Passwords must match.", 31);
162 if ($profileId ==
"") {
163 if ($groupId ==
"") {
164 throw new exception(
"Group id or profile id needs to be set (not both).", 7);
166 if (!is_numeric($groupId)) {
167 throw new exception(
"Group id needs to be numeric.", 10);
170 if ($groupId !=
"") {
171 throw new exception(
"Group id or profile id needs to be set (not both).", 8);
173 if (!is_numeric($profileId)) {
174 throw new exception(
"Profile id needs to be numeric.", 11);
178 $userValidate = validateUsername($dbh, $Cu, $username);
179 if ($userValidate[
"status"] !==
"000") {
180 throw new exception($userValidate[
"error"], 28);
183 $phoneRecord = array();
185 if ($phones !=
"" && $phones !=
"[]") {
186 $phones = HCU_JsonDecode($phones);
187 if (!is_array($phones)) {
188 throw new exception(
"Phones are malformed.", 22);
190 $phoneArray = array(
"mobile" => array());
191 foreach($phones as $phone) {
192 $value = trim($phone);
194 if (!is_numeric($value) || $value <= 0 || strlen($value) != 10) {
195 throw new exception(
"Phones are malformed.", 25);
197 $value = substr($value, 0, 3) .
"-" . substr($value, 3, 3) .
"-" . substr($value, 6);
198 $phoneArray[
"mobile"][] = $value;
202 $sql =
"select nextval('${Cu}usercontact_contact_id_seq'::regclass)";
203 $sth = db_query($sql, $dbh);
206 throw new exception(
"Nextval query failed.", 26);
208 $contactId = intval(db_fetch_row($sth, 0)[0]);
210 $phoneRecord = array(
"_action" =>
"create",
"contact_id" => $contactId,
"phones" => HCU_JsonEncode($phoneArray));
213 if (!validateEmail($email)) {
214 throw new exception(
"Email is not valid.", 5);
217 $userRecord = array(
"_action" =>
"create",
"user_name" => $username,
"email" => $email);
218 $groupRecord = array();
220 if ($groupId !=
"") {
222 $sql =
"select 'FOUND' from ${Cu}group where group_id = " . intval($groupId);
223 $sth = db_query($sql, $dbh);
225 throw new exception(
"Validate group query failed.", 15);
228 $userRecord[
"group_id"] = $groupId;
229 $userRecord[
"is_group_primary"] =
false;
230 $openAccessControl =
false;
233 $sql =
"select profile_id, cu from cu_profile where profile_id = " . intval($profileId);
234 $sth = db_query($sql, $dbh);
236 throw new exception(
"Validate query failed.", 12);
238 if (db_num_rows($sth) == 0) {
239 throw new exception(
"Profile id not found.", 13);
241 if (strtolower(trim($Cu)) != strtolower(trim(db_fetch_row($sth, 0)[1]))) {
242 throw new exception(
"Profile id belongs to another CU.", 14);
245 $sql =
"select nextval('${Cu}group_group_id_seq'::regclass)";
246 $sth = db_query($sql, $dbh);
249 throw new exception(
"Nextval query failed.", 9);
251 $groupId = intval(db_fetch_row($sth, 0)[0]);
252 $userRecord[
"group_id"] = $groupId;
253 $userRecord[
"is_group_primary"] =
true;
255 $groupRecord = array(
"_action" =>
"create",
"group_id" => $groupId,
"group_name" => $username,
"profile_id" => $profileId,
"contact" => $contactId);
256 $openAccessControl =
true;
260 if (strlen($password) < 4) {
261 throw new exception(
"Password needs to be four characters or greater.", 34);
264 $hash = password_hash($password, PASSWORD_DEFAULT);
265 $userRecord[
"passwd"] =
"$hash";
267 $envVars = array(
"cu" => $Cu);
270 $script =
"addUser.i";
272 $sql =
"select email from cuadminusers where user_name = '$Cn' and cu = '$Cu'";
273 $sth = db_query($sql, $dbh);
275 throw new exception(
"email query failed.", 16);
277 $email = db_fetch_row($sth)[0];
279 $sql =
"select coalesce(ca.retrylimit,5) as retry, coalesce(ca.gracelimit,5) as grace from cuadmin ca where ca.cu = '$Cu'";
280 $sth = db_query($sql, $dbh);
282 throw new exception(
"retry query failed.", 30);
284 $row = db_fetch_assoc($sth, 0);
286 $userRecord[
"failedremain"] = intval($row[
"retry"]);
287 $userRecord[
"forceremain"] = intval($row[
"grace"]);
288 $userRecord[
"userflags"] = 2;
290 $sql =
"select nextval('" . strtolower(trim($Cu)) .
"user_id_seq'::regclass)";
291 $sth = db_query($sql, $dbh);
293 throw new exception(
"Nextval query failed.", 19);
295 $userId = intval(db_fetch_row($sth, 0)[0]);
296 $userRecord[
"user_id"] = $userId;
297 $userRecord[
"contact"] = $contactId;
299 if (!db_work ($dbh, HOMECU_WORK_BEGIN)) {
300 throw new exception(
"begin query failed.", 32);
303 if (count($phoneRecord) > 0) {
304 $phoneRecord = array(
"usercontact" => array($phoneRecord));
305 if (DataUserTableUpdate($dbh, $envVars,
null, $phoneRecord, $userId,
"P_ADD", $context, $script,
"A",
"Phone Add", $Cn, $email, trim($_SERVER[
"REMOTE_ADDR"])) ===
false) {
306 throw new exception(
"Add contact failed.", 127);
310 if (count($groupRecord) > 0) {
311 $groupRecord = array(
"group" => array($groupRecord));
312 if (DataUserTableUpdate($dbh, $envVars,
null, $groupRecord, $userId,
"G_ADD", $context, $script,
"A",
"Group Add", $Cn, $email, trim($_SERVER[
"REMOTE_ADDR"])) ===
false) {
313 throw new exception(
"Add group failed.", 117);
317 $userRecord = array(
"user" => array($userRecord));
318 if (DataUserTableUpdate($dbh, $envVars,
null, $userRecord, $userId,
"U_ADD", $context, $script,
"A",
"User Add", $Cn, $email, trim($_SERVER[
"REMOTE_ADDR"])) ===
false) {
319 throw new exception(
"Add user failed.", 118);
322 if (!db_work($dbh, HOMECU_WORK_COMMIT)) {
323 throw new exception(
"commit work failed.", 133);
326 $sql =
"select u.user_id, u.user_name, u.email, u.name, array_to_string(ss.cellnumbers, ',') as cellnumber, g.group_name, g.group_id, p.profile_code, p.profile_id, 327 p.description as profile_desc 329 left join (select uc.user_id, array_agg(distinct s.cellnumber::text) as cellnumbers from ${Cu}useraccounts uc 330 left join cusms s on trim(uc.accountnumber) = trim(s.accountnumber) and s.cu = '${Cu}' group by uc.user_id 331 ) ss on u.user_id = ss.user_id 332 left join ${Cu}group g on u.group_id = g.group_id 333 left join cu_profile p on g.profile_id = p.profile_id where u.user_id = $userId";
334 $sth = db_query($sql, $dbh);
336 throw new exception(
"Query query failed.", 20);
338 if (db_num_rows($sth) == 0) {
339 throw new exception(
"Query query didn't return anything.", 21);
341 $thisUser = db_fetch_assoc($sth, 0);
342 $encryption = encryptUser($Cu, $thisUser,
false);
343 $counts = getUserHubCounts($dbh, $Cu, intval($thisUser[
"user_id"]));
345 $groupEncryption = encryptGroup($dbh, $Cu, $thisUser);
347 return array(
"code" => 0,
"error" => array(),
"encryption" => $encryption,
"data" => array($thisUser),
"counts" => $counts,
"groupEncryption" => $groupEncryption,
348 "openAccessControl" => $openAccessControl);
349 }
catch(exception $e) {
350 if ($e->getCode() >= 100) {
351 db_work($dbh, HOMECU_WORK_ROLLBACK);
354 return array(
"code" => $e->getCode(),
"error" => array($e->getMessage()),
"data" => array());
369 function printDoAddUser($self, $callbackName, $formName, $itIsKnownKhaleesi, $knownGroupId, $closeDialog, $usePhonesInsteadOfMFA) { ?>
370 $.homecuValidator.doValidateUsername =
false;
371 if ($.homecuValidator.validate()) {
372 var parameters = {username: $(
"#<?php echo $formName; ?> [name='username']").val().trim(), email: $(
"#<?php echo $formName; ?> [name='email']").val().trim(),
373 password: $(
"#<?php echo $formName; ?> [name='passwordi']").val().trim(), confirm: $(
"#<?php echo $formName; ?> [name='confirmi']").val().trim()};
375 <?php
if ($usePhonesInsteadOfMFA) { ?>
376 var phoneData = $(
"#<?php echo $formName; ?> #phoneGrid").data(
"kendoGrid").dataSource.data();
378 for(var i = 0; i != phoneData.length; i++) {
379 if (!phoneData[i].isAdd) {
380 phoneArray.push(phoneData[i].value.trim().replace(/\D+/g,
""));
383 parameters.phones = kendo.stringify(phoneArray);
386 <?php
if ($itIsKnownKhaleesi) { ?>
387 parameters.groupId = <?php echo intval($knownGroupId); ?>;
389 switch($(
"#<?php echo $formName; ?> [name='group']:checked").data(
"val"))
391 case "addToGroup": parameters.groupId = $(
"#userAddDialog [name='groupPopup']").data(
"id").trim();
break;
392 case "newGroup": parameters.profileId = profileDDL.value();
break;
397 $.post(
"<?php echo $self; ?>&operation=addUser", parameters,
function(data) {
399 if (data.error.length > 0) {
400 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
402 <?php
if ($closeDialog) { ?>
403 if (typeof(<?php echo $callbackName; ?>) ==
"function") {
404 <?php echo $callbackName; ?>(
"successfulOneRecord", data.encryption, data.data[0], data.counts, data.groupEncryption, data.openAccessControl);
408 $(
"#userAddDialog").data(
"invalid",
false);
409 $(
"#userAddDialog").data(
"kendoDialog").close();
411 window.location.href =
"main.prg?ft=22&payload=" + encodeURIComponent(encodeURI(data.encryption));
416 $.homecuValidator.doValidateUsername =
true;
427 function printAddUserInit($selectGroupOrProfile, $profileDDL, $profileDefault, $formName, $usePhonesInsteadOfMFA)
430 <?php
if ($selectGroupOrProfile) { ?>
431 $(
"#userAddDialog [name='groupPopup']").click(
function() {
434 if (groupSearch !=
null) {
439 $(
"#groupSearchModule").empty();
440 $(
"#groupSearchModule").load(
"main.prg?ft=102102",
function(response) {
442 groupSearch.Data([]);
443 groupSearch.Init(groupCallback,
this);
444 groupSearch.Open(window.activeWindows);
448 profileDDL = $(
"#<?php echo $formName; ?> #profileDDL").kendoDropDownList({
449 dataTextField:
"text",
450 dataValueField:
"value",
452 data: <?php echo HCU_JsonEncode($profileDDL); ?>
454 filter:
"startswith",
455 value: <?php echo HCU_JsonEncode($profileDefault); ?>
456 }).data(
"kendoDropDownList");
459 <?php
if ($usePhonesInsteadOfMFA)
460 printInitPhoneGrid($formName);
463 function printInitPhoneGrid($formName, $data =
"")
465 var data = [{kendoId: 1, value: 0, isAdd:
true}];
467 <?php
if ($data !=
"") { ?>
468 var predata = <?php echo $data; ?>;
470 if (Array.isArray(predata)) {
471 for (var i = 0, iLength = predata.length; i <= iLength; i++) {
472 if (typeof(predata[i]) ==
"string") {
473 value = predata[i].replace(/\D+/g,
"");
474 value =
"(" + value.substring(0,3) +
") " + value.substring(3,6) +
"-" + value.substring(6);
475 data.push({kendoId: kendoId++, value: value, isAdd:
false});
481 var inPhoneSave =
false;
482 var phoneGrid = $(
"#<?php echo $formName; ?> #phoneGrid").kendoGrid({
489 kendoId: {type:
"number"},
490 value: {type:
"string"},
491 isAdd: {type:
"boolean"}
495 sort: [{field:
"isAdd", dir:
"asc"}, {field:
"kendoId", dir:
"asc"}]
502 {
template:
'<span class="fa fa-minus-circle"></span>', width: 30},
503 {field:
"value",
template:
"<div class='validateable'># if (value == null) { # # } else { # #: value # # } #</div>", editor:
function(container, options) {
504 var mtb = $(
"<input class='validatePhone' name='" + options.field +
"'>").appendTo(container).kendoMaskedTextBox({
505 mask:
"(000) 000-0000" 506 }).data(
"kendoMaskedTextBox");
508 rowTemplate:
"# if (isAdd) { # <tr class='addRow'><td class='addBtn'><span class='fa fa-plus-circle'></span></td><td>Add phone</td></tr> # } else { #" 509 +
" <tr data-uid='#: uid #'><td class='removeBtn'><span class='fa fa-minus-circle'></span></td>" 510 +
"<td class='phoneValueTD'><div class='validateable'># if (value == null) { # # } else { # #: value # # } #</div></td></tr> # } #",
512 $(
"#<?php echo $formName; ?> #phoneGrid").data(
"phonesChanged",
true);
513 window.setTimeout(
function() { $(
"#<?php echo $formName; ?> [name='validatePhonesHidden']").blur(); <?php ?>}, 100);
515 }).data(
"kendoGrid");
517 $(
"#<?php echo $formName; ?> #phoneGrid").data(
"phonesChanged",
false);
519 $(
"#<?php echo $formName; ?> #phoneGrid").css({height:
"auto"});
520 $(
"#<?php echo $formName; ?> #phoneGrid .k-grid-header").
remove();
522 $(
"#<?php echo $formName; ?> #phoneGrid").on(
"mousedown",
".removeBtn",
function() {
523 $(
"#<?php echo $formName; ?> #phoneGrid").data(
"phonesChanged",
true);
524 $(
"#<?php echo $formName; ?> #phoneGrid .validatePhone:visible").blur();
525 window.setTimeout(
function() { $(
"#<?php echo $formName; ?> [name='validatePhonesHidden']").blur(); <?php ?>}, 100);
527 phoneGrid.removeRow($(
this).closest(
"tr"));
531 $(
"#<?php echo $formName; ?> #phoneGrid").on(
"mousedown",
".addRow",
function() {
532 $(
"#<?php echo $formName; ?> #phoneGrid").data(
"phonesChanged",
true);
533 $(
"#<?php echo $formName; ?> #phoneGrid .validatePhone:visible").blur();
534 window.setTimeout(
function() { $(
"#<?php echo $formName; ?> [name='validatePhonesHidden']").blur(); <?php ?>}, 100);
540 var toolTipProps = homecuTooltip.defaults;
541 toolTipProps.filter =
".validatePhone";
542 toolTipProps.content =
"Mobile Number";
544 $(
"#<?php echo $formName; ?> #phoneGrid").kendoTooltip(toolTipProps);
558 function printAddUserValidationSetup($self, $passwordRules, $formValidate, $formStatusField, $doValidateGroup, $usePhonesInsteadOfMFA) {
561 $.homecuValidator.settings.homecuCustomRules.validateGroup = undefined;
563 $.homecuValidator.setup({formValidate:
'<?php echo $formValidate; ?>', formStatusField:
'<?php echo $formStatusField; ?>', homecuCustomRules: {
564 confirmA:
function(input) {
565 if ($(input).is(
"#<?php echo $formValidate; ?> [name='confirmi']"))
567 var password = $(
"#<?php echo $formValidate; ?> [name='passwordi']").val().trim();
568 if (password ==
"") {
571 if (password != $(input).val().trim()) {
572 $(input).attr(
"data-confirmA-msg",
"Passwords must match.");
578 validateUsername1:
function(input) {
579 if ($(input).is(
"#<?php echo $formValidate; ?> [name='username']")) {
580 var theHidden = $(
"#<?php echo $formValidate; ?> [name='usernameHidden']");
581 if ($(input).val().trim() ==
"") {
582 $(input).attr(
"data-validateUsername1-msg",
"Username is required.");
583 $(theHidden).attr(
"data-validateUsername2-msg",
"");
584 $(
"#<?php echo $formValidate; ?> .k-invalid-msg[data-for='usernameHidden']").empty();
586 }
else if ($.homecuValidator.doValidateUsername) {
587 $(theHidden).attr(
"data-validateUsername2-msg",
"");
588 $.post(
"<?php echo $self; ?>&operation=validateUsername", {username: $(input).val().trim()},
function(data) {
589 if (data.status ===
"000") {
590 $(input).removeClass(
"k-invalid");
592 $(theHidden).attr(
"data-validateUsername2-msg", data.error);
593 $(input).addClass(
"k-invalid");
601 validateUsername2:
function(input) {
602 if ($(input).is(
"#<?php echo $formValidate; ?> [name='usernameHidden']")) {
603 if ($(input).attr(
"data-validateUsername2-msg") !=
null && $(input).attr(
"data-validateUsername2-msg") !=
"") {
604 $(
"#<?php echo $formValidate; ?> [name='username']").addClass(
"k-invalid");
605 $.homecuValidator.showErrorMessage =
true;
611 <?php
if ($usePhonesInsteadOfMFA) {
612 echo
","; printValidatePhones($formValidate);
614 , validatepassword:
function(input) {
615 if (!input.is(
"[name='passwordi']")) {
618 var password = $(input).val();
619 if (password.length < 4) {
620 $(input).attr(
"data-validatepassword-msg",
"Password must be four or more characters.");
623 var invalidMatches = password.match(/[
'"\s]/g); 624 if (invalidMatches != null && invalidMatches.length > 0) { 625 $(input).attr("data-validatepassword-msg", "Password has illegal characters."); 630 <?php if ($doValidateGroup) { ?>, 631 validateGroup: function(input) { 632 if ($(input).is("[name='validateGroup
']")) { 633 switch($("#<?php echo $formValidate; ?> [name='group
']:checked").data("val")) { 635 if ($("#<?php echo $formValidate; ?> [name='groupPopup
']").text().trim() == "(none selected)") { 636 $(input).attr("data-validateGroup-msg", "Group must be selected."); 641 if ($("#<?php echo $formValidate; ?> #profileDDL").data("kendoDropDownList").value() == "") { 642 $(input).attr("data-validateGroup-msg", "Profile must be selected."); 647 $(input).attr("data-validateGroup-msg", "Please specify new group or add to group."); 655 $.homecuValidator.doValidateUsername = true; 656 $.homecuValidator.passwordRules = <?php echo HCU_JsonEncode($passwordRules); ?>; 659 function printValidatePhones($formValidate) { ?> 660 validatePhones: function(input) { 661 if ($(input).is("[name='validatePhonesHidden
']")) { 664 $("#<?php echo $formValidate; ?> #phoneGrid .phoneValueTD").removeClass("k-invalid"); 665 $("#<?php echo $formValidate; ?> #phoneGrid .phoneValueTD .validateable").removeClass("k-invalid"); 666 var numPhones = 0, phoneMap = {}; 667 $("#<?php echo $formValidate; ?> #phoneGrid .phoneValueTD .validateable").each(function() { 668 if ($(this).text().trim() != "") { 670 var value = $(this).text().trim(); 672 if (value.match(/^\(\d{3}\) \d{3}-\d{4}$/) == null) { 674 $(input).attr("data-validatePhones-msg", "One or more phones are invalid."); 675 } else if (numPhones > 5) { 677 $(input).attr("data-validatePhones-msg", "You cannot have over 5 phone numbers."); 678 } else if (phoneMap[value] != null) { 680 $(input).attr("data-validatePhones-msg", "You have duplicate phone numbers."); 683 phoneMap[value] = true; 685 $(this).addClass("k-invalid"); 686 $(this).closest(".phoneValueTD").remove("k-invalid"); 707 function printAddNewUser($self, $callbackName, $dbh, $Cu) {
708 $record = readForAddUser($dbh, $Cu);
709 $formName = "addNewUserForm";
710 $formValidateDiv = "userNewValidation";
719 function openAddNewUser(fromSearchUser, autoFill) {
720 var userAddDialog = $("#userAddDialog").data("kendoDialog");
721 var groupSearch = null;
722 var profileDDL = null;
723 if (userAddDialog == null) {
724 var phoneGridIndex = 2;
725 var content = '<div
class=
"userSearchTop container hcu-all-100"><div
class=
"row">
' 726 + '<div
id=
"<?php echo $formValidateDiv; ?>"></div></div></div><br>
' 727 + '<div
class=
"userSearchContents container hcu-all-100"><form
id=
"<?php echo $formName; ?>">
' 728 + '<div
class=
"row hcuSpacer"><div
class=
"col-xs-4 hcu-no-padding"><label>Username*</label></div>
' 729 + '<div
class=
"col-xs-8 hcu-no-padding"><input name=
"username" type=
"text" maxlength=
"50" class=
"hcu-all-100 k-input k-textbox">
' 730 + '<span data-
for=
"usernameHidden" class=
"k-invalid-msg"></span></div></div>
' 731 <?php dialogPrintInputLine("Email*", "", "email", 255, " required data-required-msg=\"Email is required.\"", "email", false); ?> 732 + '<div
class=
"row hcuSpacer"><div
class=
"col-xs-4 hcu-no-padding"><label>Password*</label></div><div
class=
"col-xs-8 hcu-no-padding">
' 733 + '<input name=
"passwordi" type=
"password" maxlength=
"255" class=
"hcu-all-100 k-input k-textbox"></div></div>
' 734 <?php dialogPrintInputLine("Confirm*", "", "confirmi", 255, false, "password", false); ?> 735 + '<div
class=
"row hcuSpacer"><div
class=
"radio"><label
class=
"col-xs-4 hcu-no-padding"><input type=
"radio" name=
"group" data-val=
"addToGroup" checked>Add To Group</label></div>
' 736 + '<div
class=
"col-xs-8 hcu-no-padding"><a href=
"#" name=
"groupPopup" data-
id=
"">(none selected)</a></div></div>
' 737 + '<div
class=
"row hcuSpacer"><div
class=
"radio"><label
class=
"col-xs-4 hcu-no-padding"><input type=
"radio" name=
"group" data-val=
"newGroup">Add To Profile</label></div>
' 738 + '<div
class=
"col-xs-8 hcu-no-padding"><div
id=
"profileDDL" class=
"hcu-all-100"></div></div></div>
' 739 <?php if ($record["usePhonesInsteadOfMFA"]) { ?> 740 + '<div
class=
"row hcuSpacer"><span
class=
"h3">Phones</span></div>
' 741 + '<div
class=
"row hcuSpacer"><div
id=
"phoneGrid"></div></div>
' 743 + '<input type=
"hidden" name=
"usernameHidden"><input type=
"hidden" name=
"validatePhonesHidden"><input type=
"hidden" name=
"validatePhoneTypesHidden">
' 744 + '<input type=
"hidden" name=
"validateGroup">
' 746 userAddDialog = $("<div id='userAddDialog
' class='searchDialog
'></div>").appendTo("body").kendoDialog({ 749 actions: [{text: "Cancel"}, 750 {text: "Add User", primary: true, action: function() { 751 var fromSearchUser = $("#userAddDialog").data("fromSearchUser"); 752 <?php printDoAddUser($self, $callbackName, $formName, false, null, true, $record["usePhonesInsteadOfMFA"]); ?> 756 if (window.activeWindows != null) { 757 window.activeWindows.push(this); 759 $("#userAddDialog").data("invalid", true); 762 <?php printAddUserValidationSetup($self, $record["passwordRules"], $formName, $formValidateDiv, true, $record["usePhonesInsteadOfMFA"]); ?> 763 <?php if ($record["code"] != 0) { ?> 764 $.homecuValidator.displayMessage(<?php echo HCU_JsonEncode($record["error"]); ?>, $.homecuValidator.settings.statusError ); 768 if (window.activeWindows != null) { 769 window.activeWindows.pop(); 771 var fromSearchUser = $("#userAddDialog").data("fromSearchUser"); 772 var invalid = $("#userAddDialog").data("invalid"); 773 if (fromSearchUser && invalid) { 774 $("#userSearchDialog").data("kendoDialog").open(); 782 }).data("kendoDialog"); 784 <?php printAddUserInit(true, $record["profileDDL"], $record['profileDefault
'], $formName, $record["usePhonesInsteadOfMFA"]); ?> 786 else <?php // Clear all inputs ?> 788 $("#<?php echo $formName; ?> [name='username
']").val(null); 789 $("#<?php echo $formName; ?> [name='email
']").val(null); 790 $("#<?php echo $formName; ?> [name='passwordi
']").val(null); 791 $("#<?php echo $formName; ?> [name='confirmi
']").val(null); 792 $("#<?php echo $formName; ?> [name='group
']:eq(0)").click(); 793 <?php if ($record["usePhonesInsteadOfMFA"]) { ?> 794 $("#<?php echo $formName; ?> #phoneGrid").data("kendoGrid").dataSource.data([{kendoId: 1, type: "", value: 0, isAdd: true}]); 796 $("#<?php echo $formName; ?> [name='groupPopup
']").attr("data-id", "").text("(none selected)"); 797 $("#<?php echo $formName; ?> #profileDDL").data("kendoDropDownList").value(""); 798 $("#<?php echo $formName; ?> .k-invalid").removeClass("k-invalid"); 801 if (autoFill != null) { 802 $("#<?php echo $formName; ?> [name='username
']").val(autoFill); 805 if (fromSearchUser) { 806 $("#userSearchDialog").data("kendoDialog").close(); 808 userAddDialog.open(); 809 $("#userAddDialog").data("fromSearchUser", fromSearchUser); 821 function groupCallback(apparentlyItActuallyIsUsed, groupInfo) {
822 if (apparentlyItActuallyIsUsed == "updateGroupInfo") {
823 $("#<?php echo $formName; ?> [name='groupPopup
']").data("id", groupInfo.group.g_id); 824 $("#<?php echo $formName; ?> [name='groupPopup
']").text(groupInfo.group.g_name);