Commit 74c47d7b authored by stph's avatar stph
Browse files

Add #28

parent 4ad0ce19
...@@ -30,18 +30,18 @@ hr { ...@@ -30,18 +30,18 @@ hr {
font-size:150%; font-size:150%;
} }
.sub { .sub, .valid {
text-decoration:none; text-decoration:none;
font-weight:bold; font-weight:bold;
color:#00612b; color:#175e0c;
} }
.unsub { .unsub, .decline {
text-decoration:none; text-decoration:none;
font-weight:bold; font-weight:bold;
color:#8e3c00; color:#8e3c00;
} }
.valid {
text-decoration:none; .impossible {
font-weight:bold; text-decoration:line-through;
color:#790600; cursor: help;
} }
...@@ -22,7 +22,10 @@ if (isset($_GET['mode'])) { ...@@ -22,7 +22,10 @@ if (isset($_GET['mode'])) {
if ($_GET['mode']=='resp') { if ($_GET['mode']=='resp') {
if (isset($_GET['action']) && isset($_GET['api']) && isset($_GET['login'])) { if (isset($_GET['action']) && isset($_GET['api']) && isset($_GET['login'])) {
if ($_GET['action']=='validate') { if ($_GET['action']=='validate') {
$db->validate($_SESSION['utclogin'], $_GET['api'], $_GET['login']); $db->validate($_SESSION['utclogin'], $_GET['api'], $_GET['login'], 'TRUE');
}
elseif ($_GET['action']=='decline') {
$db->validate($_SESSION['utclogin'], $_GET['api'], $_GET['login'], 'FALSE');
} }
} }
$view->respValidation($db->apiListResp($admin, $_SESSION['utclogin'])); $view->respValidation($db->apiListResp($admin, $_SESSION['utclogin']));
......
document.querySelectorAll('.impossible').forEach(item => {
item.addEventListener('click', event => {
alert('Vous ne pouvez pas vous inscrire à cette Api : \n— le responsable de l\'Api a déjà décliné votre demande, \n— ou vous avez une autre Api validée la même semaine.')
})
})
function download_csv(students) { function download_csv(students) {
var csv = ''; var csv = '';
students.forEach(function(row) { students.forEach(function(row) {
......
...@@ -26,8 +26,17 @@ class DB { ...@@ -26,8 +26,17 @@ class DB {
} }
public function apiList($admin, $utclogin) { public function apiList($admin, $utclogin) {
$sql = 'SELECT *, is_available(:utclogin, week, year) AS is_available $sql = 'SELECT
FROM vapi a.*,
is_available(:utclogin, week, year) AS is_available,
CASE
WHEN s.api IS NULL THEN 0 /* student has not yet subscribed */
WHEN s.validation IS NULL THEN 0.5 /* student has subscribed and wait for valdiation */
WHEN s.validation THEN 1 /* student subscription has been validated */
ELSE -1 END AS validation /* student subscription has been declined or other subscription has been accepted the same week */
FROM vapi a
LEFT JOIN subscribe s
ON a.id = s.api
WHERE semester=:semester AND year=:year'; WHERE semester=:semester AND year=:year';
$st = $this->conn->prepare($sql); $st = $this->conn->prepare($sql);
$st->bindValue(':semester',$admin->activeSemester(),PDO::PARAM_STR); $st->bindValue(':semester',$admin->activeSemester(),PDO::PARAM_STR);
...@@ -148,17 +157,32 @@ class DB { ...@@ -148,17 +157,32 @@ class DB {
return $res; return $res;
} }
public function validate($resp, $api, $student) {
$today = date('Ymd');
// Validation that $resp is resp of $api // Validation that $resp is resp of $api
private function validateResp($resp, $api) {
$sql = 'SELECT COUNT(*) AS c FROM vapi WHERE resplogin=:resp AND id=:api'; $sql = 'SELECT COUNT(*) AS c FROM vapi WHERE resplogin=:resp AND id=:api';
$st = $this->conn->prepare($sql); $st = $this->conn->prepare($sql);
$st->bindValue(':resp',$resp,PDO::PARAM_STR); $st->bindValue(':resp',$resp,PDO::PARAM_STR);
$st->bindValue(':api',$api,PDO::PARAM_STR); $st->bindValue(':api',$api,PDO::PARAM_STR);
$st->execute(); $st->execute();
$res = $st->fetch(PDO::FETCH_ASSOC); $res = $st->fetch(PDO::FETCH_ASSOC);
if ($res['c']==1)
return true;
else
return false;
}
/** This function either validate or decline a student participation to an Api.
** If $validation is true : student participation is unvalidated
** Else : student participation is declined
**/
public function validate($resp, $api, $student, $validation) {
$today = date('Ymd');
if ($res['c']==1) { // Check user is Api responsible
if ($this->validateResp($resp, $api) == false) {
echo "<p>Erreur : le responsable $resp n'est pas autorisé à valider l'inscription de $student à l'Api $api</p>" ;
return -1;
}
// Year and week calculation for Api // Year and week calculation for Api
$sql = "SELECT year, week FROM vapi WHERE id=:api"; $sql = "SELECT year, week FROM vapi WHERE id=:api";
...@@ -175,15 +199,17 @@ class DB { ...@@ -175,15 +199,17 @@ class DB {
$st = $this->conn->prepare($sql); $st = $this->conn->prepare($sql);
$st->execute(); $st->execute();
$sql = "UPDATE subscribe $sql = "UPDATE subscribe
SET validation='TRUE', validationdate=:today SET validation=:validation, validationdate=:today
WHERE api=:api AND utclogin=:utclogin"; WHERE api=:api AND utclogin=:utclogin";
$st = $this->conn->prepare($sql); $st = $this->conn->prepare($sql);
$st->bindValue(':utclogin',$student,PDO::PARAM_STR); $st->bindValue(':utclogin',$student,PDO::PARAM_STR);
$st->bindValue(':api',$api,PDO::PARAM_STR); $st->bindValue(':api',$api,PDO::PARAM_STR);
$st->bindValue(':today',$today,PDO::PARAM_STR); $st->bindValue(':today',$today,PDO::PARAM_STR);
$st->bindValue(':validation',$validation,PDO::PARAM_STR);
$res = $st->execute(); $res = $st->execute();
// Cancel other subscriptions the same week // Cancel other subscriptions the same week (if validation only)
if ($validation == 'TRUE') {
$sql = "UPDATE subscribe $sql = "UPDATE subscribe
SET validation='FALSE', validationdate=:today SET validation='FALSE', validationdate=:today
WHERE api<>:api AND utclogin=:utclogin WHERE api<>:api AND utclogin=:utclogin
...@@ -195,16 +221,12 @@ class DB { ...@@ -195,16 +221,12 @@ class DB {
$st->bindValue(':year',$year,PDO::PARAM_STR); $st->bindValue(':year',$year,PDO::PARAM_STR);
$st->bindValue(':week',$week,PDO::PARAM_STR); $st->bindValue(':week',$week,PDO::PARAM_STR);
$res = $st->execute(); $res = $st->execute();
}
$sql = "COMMIT"; $sql = "COMMIT";
$st = $this->conn->prepare($sql); $st = $this->conn->prepare($sql);
$st->execute(); $st->execute();
return $res; return true;
}
else {
echo "<p>Erreur : le responsable $resp n'est pas autorisé à valider l'inscription de $student</p>" ;
// ajouter le nom de l'Api
return -1;
}
} }
public function apiStudents($utclogin, $api) { public function apiStudents($utclogin, $api) {
......
...@@ -24,6 +24,7 @@ class Views { ...@@ -24,6 +24,7 @@ class Views {
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>'; echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>';
echo '<title>Api Sub</title>'; echo '<title>Api Sub</title>';
echo '<link href="css/main.css" type="text/css" rel="stylesheet"/>'; echo '<link href="css/main.css" type="text/css" rel="stylesheet"/>';
echo '<script src="js/main.js" defer></script>';
echo '</head>'; echo '</head>';
echo '<body>'; echo '<body>';
echo '<h1>Foire aux Api '.$admin->activeSemester().$admin->activeYear().'</h1>'; echo '<h1>Foire aux Api '.$admin->activeSemester().$admin->activeYear().'</h1>';
...@@ -117,24 +118,30 @@ class Views { ...@@ -117,24 +118,30 @@ class Views {
if ($list) { if ($list) {
echo '<h2>Liste des Api</h2>'; echo '<h2>Liste des Api</h2>';
$week = ''; $week = '';
foreach ($list as $row) { foreach ($list as $api) {
if ($row['week'] != $week) { if ($api['week'] != $week) {
$week = $row['week']; $week = $api['week'];
echo "<h3>".$this->printWeek($row)."</h3>"; echo "<h3>".$this->printWeek($api)."</h3>";
} }
echo '<p>'; echo '<p>';
if ($this->isActive()) { if ($this->isActive()) {
if ($row['open'] && $row['is_available']) { if ($api['validation'] == 1) {
echo "<a href='index.php?action=sub&api=$row[id]' class='sub'>[inscription]</a> "; echo "[validé] ";
} }
elseif (! $row['is_available']) { elseif ($api['validation'] == 0.5) {
echo "[indisponible] "; echo "[en attente] ";
}
elseif ($api['validation'] == -1 || ! $api['is_available']) {
echo "[<span class='impossible'>indisponible</span>] ";
}
elseif (! $api['open']) {
echo "[<span class='impossible'>complet</span>] ";
} }
else { else {
echo '[complet] '; echo "<a href='index.php?action=sub&api=$api[id]' class='sub'>[inscription]</a> ";
} }
} }
echo $this->printApi($row); echo $this->printApi($api);
echo '</p>'; echo '</p>';
} }
} }
...@@ -151,7 +158,7 @@ class Views { ...@@ -151,7 +158,7 @@ class Views {
echo '<h2>Rappel</h2>'; echo '<h2>Rappel</h2>';
echo '<ul>'; echo '<ul>';
echo '<li>La validation d\'une inscription entraîne la confirmation de l\'ouverture de l\'Api.</li>'; echo '<li>La validation d\'une inscription entraîne la confirmation de l\'ouverture de l\'Api.</li>';
echo '<li>Toute inscription validée est irréversible.</li>'; echo '<li>Toute inscription validée ou déclinée est irréversible.</li>';
echo '</ul>'; echo '</ul>';
if ($listsub) { if ($listsub) {
$api = ''; $api = '';
...@@ -168,7 +175,12 @@ class Views { ...@@ -168,7 +175,12 @@ class Views {
} }
else if (is_null($sub['validation'])) { else if (is_null($sub['validation'])) {
// At least one waiting subscription // At least one waiting subscription
echo "<p> <a href='index.php?action=validate&api=$sub[id]&login=$sub[utclogin]&mode=resp' class='valid'>[valider]</a> ".$this->printStudent($sub)." <span>Exclusivité : $sub[indicator]%</span></p>"; echo "<p>
<a href='index.php?action=validate&api=$sub[id]&login=$sub[utclogin]&mode=resp' class='valid'>[valider]</a> "
.$this->printStudent($sub).
" <span>Exclusivité : $sub[indicator]%</span>
<a href='index.php?action=decline&api=$sub[id]&login=$sub[utclogin]&mode=resp' class='decline'>[décliner]</a>
</p>";
} }
else { else {
// validation = FALSE lignes ignored // validation = FALSE lignes ignored
...@@ -196,7 +208,6 @@ class Views { ...@@ -196,7 +208,6 @@ class Views {
$mailinglist = $mailinglist."$s[email],"; $mailinglist = $mailinglist."$s[email],";
} }
// Api CSV data (for JavaScript function) // Api CSV data (for JavaScript function)
echo '<script src="js/main.js"></script>';
echo "<script>var csvstudents = [['Nom','Prénom','Niveau','Mail','Login'],"; echo "<script>var csvstudents = [['Nom','Prénom','Niveau','Mail','Login'],";
foreach ($students as $s) { foreach ($students as $s) {
echo "['$s[surname]','$s[firstname]','$s[level]','$s[email]','$s[utclogin]'],"; echo "['$s[surname]','$s[firstname]','$s[level]','$s[email]','$s[utclogin]'],";
......
...@@ -29,7 +29,7 @@ INSERT INTO api (id,dbegin,code,name,description,duration,size,ects,resplogin) V ...@@ -29,7 +29,7 @@ INSERT INTO api (id,dbegin,code,name,description,duration,size,ects,resplogin) V
gen_random_uuid(), gen_random_uuid(),
TO_DATE('01/01/2020','DD/MM/YYYY'), TO_DATE('01/01/2020','DD/MM/YYYY'),
code, code,
'title, 'title',
'longtitle', 'longtitle',
duration, duration,
size, size,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment