$email = $user['email']; $user_title = $user['title']; $user_active = $user['active']; $user_enabled = $user['enabled']; $primary_group_id = $user['primary_group_id']; if ($user['last_sign_in_stamp'] == '0') { $last_sign_in_date = "Brand new!"; } else { $last_sign_in_date_obj = new DateTime(); $last_sign_in_date_obj->setTimestamp($user['last_sign_in_stamp']); $last_sign_in_date = $last_sign_in_date_obj->format('l, F j Y'); } $sign_up_date_obj = new DateTime(); $sign_up_date_obj->setTimestamp($user['sign_up_stamp']); $sign_up_date = $sign_up_date_obj->format('l, F j Y'); $user_permissions = loadUserGroups($user_id); if ($render_mode == "panel") { $box_title = $display_name; } } $response = ""; if ($render_mode == "modal") { $response .= "<div id='{$box_id}' class='modal fade'>\n <div class='modal-dialog'>\n <div class='modal-content'>\n <div class='modal-header'>\n <button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>\n <h4 class='modal-title'>{$box_title}</h4>\n </div>\n <div class='modal-body'>\n <form method='post' action='{$target}'>"; } else { if ($render_mode == "panel") { $response .= "<div class='panel panel-primary'>\n <div class='panel-heading'>\n <h2 class='panel-title pull-left'>{$box_title}</h2>\n <div class='clearfix'></div>\n </div>\n <div class='panel-body'>\n <form method='post' action='{$target}'>"; } else { echo "Invalid render mode."; exit; } }
$user_id = $validator->optionalGetVar('user_id'); $group_id = $validator->optionalGetVar('group_id'); // Add alerts for any failed input validation foreach ($validator->errors as $error) { addAlert("danger", $error); } if (count($validator->errors) > 0) { apiReturnError($ajax, getReferralPage()); } if ($user_id) { // Special case to load groups for the logged in user if ($user_id == "0") { $user_id = $loggedInUser->user_id; } // Attempt to load group information for the specified user. if (!($results = loadUserGroups($user_id))) { apiReturnError($ajax, getReferralPage()); } } else { if ($group_id) { // Attempt to load information for the specified group. if (!($results = loadGroup($group_id))) { apiReturnError($ajax, getReferralPage()); } } else { // Attempt to load information for all groups if (!($results = loadGroups())) { apiReturnError($ajax, getReferralPage()); } } }
if ($get['user_id']) { $populate_fields = true; $button_submit_text = "Update user"; $target = "update_user.php"; $box_title = "Update User"; } else { $populate_fields = false; $button_submit_text = "Create user"; $target = "create_user.php"; $box_title = "New User"; } // If we're in update mode, load user data if ($populate_fields) { $user = loadUser($get['user_id']); $deleteLabel = $user['user_name']; $user_groups = loadUserGroups($get['user_id']); if ($get['render_mode'] == "panel") { $box_title = $user['display_name']; } } else { $user = array(); $deleteLabel = ""; } $fields_default = ['user_name' => ['type' => 'text', 'label' => 'Username', 'display' => 'disabled', 'validator' => ['minLength' => 1, 'maxLength' => 25, 'label' => 'Username'], 'placeholder' => 'Please enter the user name'], 'display_name' => ['type' => 'text', 'label' => 'Display Name', 'display' => 'disabled', 'validator' => ['minLength' => 1, 'maxLength' => 50, 'label' => 'Display name'], 'placeholder' => 'Please enter the display name'], 'email' => ['type' => 'text', 'label' => 'Email', 'display' => 'disabled', 'icon' => 'fa fa-envelope', 'icon_link' => 'mailto: {{value}}', 'validator' => ['minLength' => 1, 'maxLength' => 150, 'email' => true, 'label' => 'Email'], 'placeholder' => 'Email goes here'], 'title' => ['type' => 'text', 'label' => 'Title', 'display' => 'disabled', 'validator' => ['minLength' => 1, 'maxLength' => 100, 'label' => 'Title'], 'default' => 'New User'], 'sign_up_stamp' => ['type' => 'text', 'label' => 'Registered Since', 'display' => 'disabled', 'icon' => 'fa fa-calendar', 'preprocess' => 'formatSignInDate'], 'last_sign_in_stamp' => ['type' => 'text', 'label' => 'Last Sign-in', 'display' => 'disabled', 'icon' => 'fa fa-calendar', 'preprocess' => 'formatSignInDate', 'default' => 0], 'password' => ['type' => 'password', 'label' => 'Password', 'display' => 'hidden', 'icon' => 'fa fa-key', 'validator' => ['minLength' => 8, 'maxLength' => 50, 'label' => 'Password', 'passwordMatch' => 'passwordc']], 'passwordc' => ['type' => 'password', 'label' => 'Confirm password', 'display' => 'hidden', 'icon' => 'fa fa-key', 'validator' => ['minLength' => 8, 'maxLength' => 50, 'label' => 'Password']], 'groups' => ['display' => 'disabled']]; $fields = array_merge_recursive_distinct($fields_default, $get['fields']); // Buttons (optional) // submit: display the submission button for this form. // edit: display the edit button for panel mode. // disable: display the enable/disable button. // delete: display the deletion button. // activate: display the activate button for inactive users.