Skip to content

Commit

Permalink
Update usermanag.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Lydoche authored Dec 8, 2021
1 parent a5913fb commit aec6cdb
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions Web/usermanag.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
<?php
session_start();
if (isset($_SESSION['Email'])){
if ($_SESSION['Status'] != 'Admin'){
header("HTTP/1.0 404 Not Found");
echo "<h1>404 Not Found</h1>";
echo "The page that you have requested is not accessible for you.";
echo "<a href='search_page.php'>Go back to search page</a>";
exit();
}
}else {
header("Location: LoginPage.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> User management </title>
<link rel="stylesheet" type="text/css" href="website.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <!--CSS for log out button-->
</head>
<style>
table{
width: 100%;
}
tr>td{
padding-bottom: 1em;
}
</style>
<body>
<header>
<h1>CALI</h1>
</header>

<div class="topnav">
<?php require_once 'libphp/Menu.php';
echo Menu($_SESSION['Status'],"usermanag.php")?>
<a href="menu.html">Home</a>
<a href="AnnotatorArea.php"> Annotator area</a>
<a href="ValidatorArea.php"> Validator area</a>
<a class="active" href="usermanag.php"> User management</a> <!--Page active-->
<a href="Add_genome.php"> Add genome</a>
<button type="button" class="LogOut" onclick="window.location.href = 'LoginPage.html'">Log out</button>
</div>
<div class="center">
<div class="container">
Expand All @@ -38,27 +35,29 @@
connect_db();


$q_name_status = "SELECT email, status FROM website.users WHERE status != 'Admin' AND Access = TRUE";
$q_name_status = "SELECT email, status, lastconnection FROM website.users WHERE status != 'Admin' AND Access = TRUE";


$res_name_status = pg_query($db_conn, $q_name_status) or die (pg_last_error());
$res_user_array = pg_fetch_all_columns($res_name_status);
$res_status_user = pg_fetch_all_columns($res_name_status, 1);
$res_last_co = pg_fetch_all_columns($res_name_status, 2); // récupère date de dernière connexion


while ($id = pg_fetch_assoc($res_name_status)) {
$id_email = $id['email'];
$id_user_name = explode(".", $id_email)[0];

if (isset($_POST["del" . $id_user_name])) {
$id_email = $id['email']; // adresse mail
$id_user_name = explode(".", $id_email)[0]; // id_user_name : tout ce qu'il y a avant '.com' ou '.fr' de l'adresse mail
$id_last_co = $id['lastconnection']; // date de dernière connection

if (isset($_POST["del" . $id_user_name])) { // si on supprime un utilisateur
// celui-ci perd l'accès au site (mais n'est pas supprimé de la base de données)
$del_user = "UPDATE website.users
SET Access = FALSE
WHERE email = '$id_email'";
echo $del_user;

$res_delete_role = pg_query($db_conn, $del_user) or die(pg_last_error());

} else {
if (isset($_POST["submit" . $id_user_name])) {
if (isset($_POST["submit" . $id_user_name])) { // Change le rôle d'un utilisateur
if ($_POST["sel" . $id_user_name] == 'Reader') {
$alter_role = "UPDATE website.users SET status = 'Reader' WHERE users.email = '$id_email'";
} else if ($_POST["sel" . $id_user_name] == 'Annotator') {
Expand All @@ -83,6 +82,7 @@
</select>
<button class='little_submit_button' type='submit' name = 'submit" . $id_user_name . "'> Change role</button> </td>";
echo "<td><button class='little_submit_button' type='submit' name = 'del" . $id_user_name . "'> Delete user</button></td></tr>";
echo '<td>' . $id_last_co . '</td>';

}
}
Expand Down

0 comments on commit aec6cdb

Please sign in to comment.