diff --git a/Assets/functions.php b/Assets/functions.php index 2d4d724..1a06a11 100644 --- a/Assets/functions.php +++ b/Assets/functions.php @@ -66,22 +66,20 @@ function getHashPwd($bdd, $username) return $user; // retourne un tableau ou null } -function getEvenements($bdd, $site) +function getEvenements($bdd, $site, $allSites = false) { - $results = mysqli_query( - $bdd, - "SELECT * FROM evenements - WHERE site_id = '" . $site . "' - OR public = 1 - ORDER BY date DESC" - ); - + if ($allSites) { + $query = "SELECT * FROM evenements ORDER BY date DESC"; + } else { + $query = "SELECT * FROM evenements + WHERE site_id = '$site' OR public = 1 + ORDER BY date DESC"; + } + $results = mysqli_query($bdd, $query); $evenements = []; - while ($row = mysqli_fetch_assoc($results)) { $evenements[] = $row; } - return $evenements; } @@ -453,13 +451,13 @@ function createValidationCode($bdd, $user, $ttlMinutes = 60) while ($exists) { $code = bin2hex(random_bytes(16)); - + $checkStmt = mysqli_prepare($bdd, "SELECT id FROM `$table` WHERE `$colCode` = ? LIMIT 1"); if ($checkStmt) { mysqli_stmt_bind_param($checkStmt, "s", $code); mysqli_stmt_execute($checkStmt); mysqli_stmt_store_result($checkStmt); - + if (mysqli_stmt_num_rows($checkStmt) == 0) { $exists = false; } @@ -473,7 +471,7 @@ function createValidationCode($bdd, $user, $ttlMinutes = 60) $insertSql = "INSERT INTO `$table` (`$colCode`, `$colUser`, `$colExpire`) VALUES (?, ?, ?)"; $insertStmt = mysqli_prepare($bdd, $insertSql); - + if ($insertStmt) { mysqli_stmt_bind_param($insertStmt, "sss", $code, $user, $expiresAt); $success = mysqli_stmt_execute($insertStmt); @@ -525,4 +523,104 @@ function getUserFromCode($bdd, $code) mysqli_stmt_close($stmt); return $row ? $row['utilisateur'] : null; +} + +function getEventSite($bdd, $event) +{ + $stmt = mysqli_prepare( + $bdd, + "SELECT site_id FROM evenements WHERE id = ? LIMIT 1" + ); + + mysqli_stmt_bind_param($stmt, "s", $event); + mysqli_stmt_execute($stmt); + + $result = mysqli_stmt_get_result($stmt); + $row = mysqli_fetch_assoc($result); + + mysqli_stmt_close($stmt); + + return $row ? $row['site_id'] : null; +} + +function updateEventSite($bdd, $eventid, $site) +{ + $stmt = mysqli_prepare( + $bdd, + "UPDATE evenements SET site_id = ? WHERE id = ?" + ); + + mysqli_stmt_bind_param($stmt, "ii", $site, $eventid); + mysqli_stmt_execute($stmt); + + $success = mysqli_stmt_affected_rows($stmt) >= 0; + + mysqli_stmt_close($stmt); + + return $success; +} + +function userExists($bdd, $username){ + $stmt = $bdd->prepare("SELECT id FROM utilisateurs WHERE username = ? LIMIT 1"); + $stmt->bind_param("s", $username); + $stmt->execute(); + $result = $stmt->get_result(); + return $result->num_rows > 0; +} + +function createUser($bdd, $username, $password, $permissions, $site_id) +{ + + $sql = "INSERT INTO utilisateurs (username, password, permissions, site_id) VALUES (?, ?, ?, ?)"; + $req = $bdd->prepare($sql); + $req->bind_param("sssi", $username, $password, $permissions, $site_id); + $req->execute(); + return $bdd->insert_id; +} + +function getAllPermissions($bdd) +{ + $results = mysqli_query($bdd, "SELECT * FROM `permissions`"); + + $return = []; + + while ($row = mysqli_fetch_assoc($results)) { + $return[] = $row; + } + + return $return; +} + +function updateUserSite($bdd, $user, $site) +{ + $stmt = mysqli_prepare( + $bdd, + "UPDATE utilisateurs SET site_id = ? WHERE username = ?" + ); + + mysqli_stmt_bind_param($stmt, "is", $site, $user); + mysqli_stmt_execute($stmt); + + $success = mysqli_stmt_affected_rows($stmt) >= 0; + + mysqli_stmt_close($stmt); + + return $success; +} + +function updateUserPermissions($bdd, $user, $permissions) +{ + $stmt = mysqli_prepare( + $bdd, + "UPDATE utilisateurs SET permissions = ? WHERE username = ?" + ); + + mysqli_stmt_bind_param($stmt, "ss", $permissions, $user); + mysqli_stmt_execute($stmt); + + $success = mysqli_stmt_affected_rows($stmt) >= 0; + + mysqli_stmt_close($stmt); + + return $success; } \ No newline at end of file diff --git a/Assets/sendMail.php b/Assets/sendMail.php index 9e94ba9..f9e34ce 100644 --- a/Assets/sendMail.php +++ b/Assets/sendMail.php @@ -68,7 +68,7 @@ try { $mail->setFrom('intranet-apei@apeimbge.fr', 'Demande de connexion'); $mail->addAddress($sendto); - $mail->addAddress('erwann.philippe2@gmail.com'); + //$mail->addAddress('erwann.philippe2@gmail.com'); $mail->Subject = $objet[$type]; $mail->Body = $message[$type]; diff --git a/admin/admin.php b/admin/admin.php index dfb46bd..6b77a07 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -9,7 +9,12 @@ if (!isset($_SESSION['connected']) || $_SESSION['connected'] == false) { header('location: ../login.php?redirect_to=./admin/'); } -$events = getEvenements($bdd, $_SESSION['site']); +$permission = $_SESSION["permission"]; +if ($permission == "admin") { + $evenements = getEvenements($bdd, $_SESSION['site'], true); +} else { + $evenements = getEvenements($bdd, $_SESSION['site']); +} /* Récupération des infos */ $permissions = $_SESSION['permission']; @@ -24,7 +29,6 @@ if (!verifyPoids($bdd, $_SESSION['username'], $minPoids)) { $uploadDir = "../Photos/INTRANET/"; - if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!empty($_POST['nom']) && !empty($_POST['url']) && !empty($_POST['image'])) { @@ -40,8 +44,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { exit; } } - - ?> @@ -49,9 +51,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { Gestion Intranet + + + +

Gestion de l'intranet

+ - -
-

Création de raccourcis

+
+ + + + +
+ + +
+ +

Création de raccourcis

+ +
+ + + + + +
+ + " + style="width:40px;height:40px;margin-right:10px;cursor:pointer;"> + +
+ + + +
+ + + +
+ +
+ + -
- - -
- " - style="width:40px;height:40px;margin-right:10px;cursor:pointer;"> -
- - -
- - - -
- + + + +
+ +
+ + +
+ + + +

Modification d'un utilisateur

+ +
+ +
+ +
+ +
+ +
+ +
+
+
- -
- + \ No newline at end of file diff --git a/admin/gestionUser.php b/admin/gestionUser.php new file mode 100644 index 0000000..f631344 --- /dev/null +++ b/admin/gestionUser.php @@ -0,0 +1,18 @@ +Date de l'évènement
+ +
+ + +
+ - + - + Supprimer + +
- +