Stay on the same tab after creating a new TA account

Hui-Organize
Lan Hui 2024-10-04 09:07:40 +08:00
parent aa82e9b5db
commit 545915b8be
2 changed files with 17 additions and 7 deletions

View File

@ -66,7 +66,7 @@ if ($_SESSION['user_type'] != "Lecturer" && $_SESSION['user_type'] != "Admin") {
?> ?>
<form method="post" action="Script.php" id="create_account_form"> <form method="post" action="Script.php" id="create_account_form">
<input type="hidden" name="form_createlecturrer" value="true" required="" /> <input type="hidden" name="form_createlecturer" value="true" required="" />
Full name Full name
<input type="text" name="fullname" placeholder="Full Name" class="form-control" required=""> <br> <input type="text" name="fullname" placeholder="Full Name" class="form-control" required=""> <br>
Email Email
@ -93,10 +93,6 @@ if ($_SESSION['user_type'] != "Lecturer" && $_SESSION['user_type'] != "Admin") {
echo '<hr><div class="alert alert-warning" role="alert">' . $_SESSION['info_Admin_Users'] . '</div>'; echo '<hr><div class="alert alert-warning" role="alert">' . $_SESSION['info_Admin_Users'] . '</div>';
$_SESSION['info_Admin_Users'] = null; $_SESSION['info_Admin_Users'] = null;
} }
if (isset($_SESSION['info_Admin_Users'])) {
echo '<hr><div class="alert alert-warning" role="alert">' . $_SESSION['info_Admin_Users'] . '</div>';
$_SESSION['info_Admin_Users'] = null;
}
?> ?>
</form> </form>
@ -227,8 +223,22 @@ if ($_SESSION['user_type'] != "Lecturer" && $_SESSION['user_type'] != "Admin") {
</div> </div>
<?php include 'Footer.php';?> <?php include 'Footer.php';?>
<script>
/** After creating a TA account, stay on the same tab "Create instructor account"
Side effect: ?tacreated will be appended on the URL
*/
document.addEventListener("DOMContentLoaded", () => {
const url = new URL(window.location.href);
if (url.searchParams.has('tacreated')) {
const elem = document.querySelector('#tab_ins_accounts');
elem.click();
}
});
</script>
<script> <script>
function updatePassword(id, pass) { function updatePassword(id, pass) {
if (!confirm('Are you sure to reset user password?')) { if (!confirm('Are you sure to reset user password?')) {

View File

@ -336,7 +336,7 @@ if (!empty($_POST["form_reset_password"])) {
} }
// ############################### CREATE Lecturer/TA USER ################################## // ############################### CREATE Lecturer/TA USER ##################################
if (!empty($_POST["form_createlecturrer"])){ if (!empty($_POST["form_createlecturer"])){
$email = mysqli_real_escape_string($con, $_POST["email"]); $email = mysqli_real_escape_string($con, $_POST["email"]);
$fullname = mysqli_real_escape_string($con, $_POST["fullname"]); $fullname = mysqli_real_escape_string($con, $_POST["fullname"]);
$type = mysqli_real_escape_string($con, $_POST["type"]); $type = mysqli_real_escape_string($con, $_POST["type"]);
@ -361,7 +361,7 @@ if (!empty($_POST["form_createlecturrer"])){
try { try {
$result = mysqli_query($con, $sql); $result = mysqli_query($con, $sql);
$_SESSION["info_Admin_Users"] = $type . " user created successfully. Use email " . $email . " as account name and ". $password ." as password."; $_SESSION["info_Admin_Users"] = $type . " user created successfully. Use email " . $email . " as account name and ". $password ." as password.";
header("Location: Admin.php"); header("Location: Admin.php?tacreated");
} catch (Exception $ex) { } catch (Exception $ex) {
echo "$ex"; echo "$ex";
} }