-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkNumEtu.php
57 lines (51 loc) · 1.96 KB
/
checkNumEtu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
session_start();
// Dépendances
require "vendor/autoload.php";
// Récupération des variables d'environnement
$dotenv = Dotenv\Dotenv::createImmutable($_SERVER['DOCUMENT_ROOT']);
$dotenv->load();
$hostname = $_ENV['BDD_HOST'];
$dbname = $_ENV['BDD_NAME'];
$username = $_ENV['BDD_LOGIN'];
$password = $_ENV['BDD_PASSWD'];
// Connexion bdd
try {
$bdd = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
exit();
}
$id_etu_sent = $_GET["num_etu"] ?? 1;
$id_etu_sent = empty($id_etu_sent) ? exit("Please provide a valid student ID.") : $id_etu_sent;
$force_login = isset($_GET["login"]) ? $_GET["login"] : false;
// Force next semester if date > february
$semestre = date("m") > 2 ? 0 : 1;
$num_etu = "SELECT promo, enabled FROM data_etu where id_etu = $id_etu_sent";
$data_etu = $bdd->query($num_etu);
$data_etu = $data_etu->fetch();
if ($data_etu) {
// If the student allowed NoteUniv to display his marks
if ($data_etu['enabled']) {
// Set cookie semester
if ($data_etu['promo'] === 'MMI1') {
setcookie('semestre', 's' . 1 * 2 - $semestre, strtotime('+360 days'));
setcookie('promo', 'MMI', strtotime('+360 days'));
} else if ($data_etu['promo'] === 'MMI2') {
setcookie('semestre', 's' . 2 * 2 - $semestre, strtotime('+360 days'));
setcookie('promo', 'MMI', strtotime('+360 days'));
} else {
setcookie('semestre', $data_etu['promo'], strtotime('+360 days'));
setcookie('promo', $data_etu['promo'], strtotime('+360 days'));
}
echo $id_etu_sent . ' authorized';
if ($force_login == true) {
$_SESSION['id_etu'] = $id_etu_sent;
header('Location: last.php');
}
// Else return an error
} else {
echo $id_etu_sent . ' disabled';
}
}