Matancy

Untitled

Oct 26th, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. <?php
  2.  
  3. // Fonction pour générer un code aléatoire de 60 caractères
  4.  
  5. function str_random($length) {
  6. $alphabet = "0123456789azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN";
  7. return substr(str_shuffle(str_repeat($alphabet, $length)), 0, $length);
  8. }
  9.  
  10. function OnlyStaff()
  11. {
  12. $allowedgrades = [1];
  13. $grade = $_SESSION['user']['grade'];
  14. foreach ($allowedgrades as $allowed) {
  15. if ($grade === $allowed) {
  16. $_SESSION['error'] = "Vous n'avez pas la permission d'accéder à cette page";
  17. header("Location: index.php");
  18. exit();
  19. }
  20. }
  21. }
  22.  
  23. function OnlyStaffButton($button)
  24. {
  25. $allowedgrades = [1];
  26. $grade = $_SESSION['user']['grade'];
  27. foreach ($allowedgrades as $allowed) {
  28. if ($grade !== $allowed) {
  29. echo $button;
  30. break;
  31. }
  32. }
  33. }
  34.  
  35. function dateDiff($date1, $date2){
  36. $diff = abs($date1 - $date2); // abs pour avoir la valeur absolute, ainsi éviter d'avoir une différence négative
  37. $retour = array();
  38.  
  39. $tmp = $diff;
  40. $retour['second'] = $tmp % 60;
  41.  
  42. $tmp = floor( ($tmp - $retour['second']) /60 );
  43. $retour['minute'] = $tmp % 60;
  44.  
  45. $tmp = floor( ($tmp - $retour['minute'])/60 );
  46. $retour['hour'] = $tmp % 24;
  47.  
  48. $tmp = floor( ($tmp - $retour['hour']) /24 );
  49. $retour['day'] = $tmp;
  50.  
  51. return $retour;
  52. }
  53.  
  54. function Permission($name, $button, $bdd_cpm){
  55. include('bdd.php');
  56. $req = $bdd_cpm->prepare('SELECT * FROM role_perm WHERE name = :name AND grade = :grade');
  57. $req->execute(['name' => $name, 'grade' => $_SESSION['user']['grade']]);
  58. $result = $req->fetch();
  59.  
  60. if ($result['value'] == "TRUE") {
  61. echo $button;
  62. }
  63.  
  64. }
  65.  
  66. function AllowedPage($name, $bdd_cpm){
  67. include('bdd.php');
  68. $req = $bdd_cpm->prepare('SELECT * FROM role_perm WHERE name = :name AND grade = :grade');
  69. $req->execute(['name' => $name, 'grade' => $_SESSION['user']['grade']]);
  70. $result = $req->fetch();
  71.  
  72. if ($result['value'] =! "TRUE") {
  73. $_SESSION['error'] = "Vous n'avez pas la permission d'accéder à cette page !";
  74. header("Location: index.php");
  75. exit();
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment