Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Fonction pour générer un code aléatoire de 60 caractères
- function str_random($length) {
- $alphabet = "0123456789azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN";
- return substr(str_shuffle(str_repeat($alphabet, $length)), 0, $length);
- }
- function OnlyStaff()
- {
- $allowedgrades = [1];
- $grade = $_SESSION['user']['grade'];
- foreach ($allowedgrades as $allowed) {
- if ($grade === $allowed) {
- $_SESSION['error'] = "Vous n'avez pas la permission d'accéder à cette page";
- header("Location: index.php");
- exit();
- }
- }
- }
- function OnlyStaffButton($button)
- {
- $allowedgrades = [1];
- $grade = $_SESSION['user']['grade'];
- foreach ($allowedgrades as $allowed) {
- if ($grade !== $allowed) {
- echo $button;
- break;
- }
- }
- }
- function dateDiff($date1, $date2){
- $diff = abs($date1 - $date2); // abs pour avoir la valeur absolute, ainsi éviter d'avoir une différence négative
- $retour = array();
- $tmp = $diff;
- $retour['second'] = $tmp % 60;
- $tmp = floor( ($tmp - $retour['second']) /60 );
- $retour['minute'] = $tmp % 60;
- $tmp = floor( ($tmp - $retour['minute'])/60 );
- $retour['hour'] = $tmp % 24;
- $tmp = floor( ($tmp - $retour['hour']) /24 );
- $retour['day'] = $tmp;
- return $retour;
- }
- function Permission($name, $button, $bdd_cpm){
- include('bdd.php');
- $req = $bdd_cpm->prepare('SELECT * FROM role_perm WHERE name = :name AND grade = :grade');
- $req->execute(['name' => $name, 'grade' => $_SESSION['user']['grade']]);
- $result = $req->fetch();
- if ($result['value'] == "TRUE") {
- echo $button;
- }
- }
- function AllowedPage($name, $bdd_cpm){
- include('bdd.php');
- $req = $bdd_cpm->prepare('SELECT * FROM role_perm WHERE name = :name AND grade = :grade');
- $req->execute(['name' => $name, 'grade' => $_SESSION['user']['grade']]);
- $result = $req->fetch();
- if ($result['value'] =! "TRUE") {
- $_SESSION['error'] = "Vous n'avez pas la permission d'accéder à cette page !";
- header("Location: index.php");
- exit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment