prepare("SELECT userrole, username FROM app_users WHERE username = ?"); $queryprm->bind_param("s", $username); $queryprm->execute(); $queryprmres = $queryprm->get_result()->fetch_assoc(); $cruserrole = $queryprmres["userrole"]; if ($cruserrole == 'superadmin') { $queryup = $mysqli->prepare("UPDATE `banned_users` SET `banned_until`=? WHERE `banned_sipusername`=? AND `conf_extension`=?"); $queryup->bind_param("sss", $newBanDate, $bannedExtension, $vconfExtension); if ($queryup->execute()) { $messagetosend = 'success'; } else { $messagetosend = 'An error occurred while attempting to save the ban date to the database!'; } } elseif ($cruserrole == 'admin') { // Check if the banned user has been banned by the current admin $querychck = $mysqli->prepare("SELECT ban_creator, banned_sipusername, conf_extension FROM banned_users WHERE banned_sipusername = ? AND conf_extension = ?"); $querychck->bind_param("ss", $bannedExtension, $vconfExtension); $querychck->execute(); $querychckres = $querychck->get_result()->fetch_assoc(); $banCreator = $querychckres['ban_creator']; if ($banCreator == $username) { $queryupadm = $mysqli->prepare("UPDATE `banned_users` SET `banned_until`=? WHERE `banned_sipusername`=? AND `conf_extension`=?"); $queryupadm->bind_param("sss", $newBanDate, $bannedExtension, $vconfExtension); if ($queryupadm->execute()) { $messagetosend = 'success'; } else { $messagetosend = 'An error occurred while attempting to save the ban date to the database!'; } } else { $messagetosend = 'You can change the ban time only for the users that were banned by you.'; } } elseif ($cruserrole == 'regular_user') { $messagetosend = 'Only Admins and Superadmins can unban users.'; } $response = array('result' => $messagetosend); echo json_encode($response); } else { header("Location: ../login.php"); } ?>