Commit 0d9b16c2 authored by Stephane Crozat's avatar Stephane Crozat

Processus d'inscription et de validation fonctionnel

parent 57460f59
......@@ -41,12 +41,12 @@ $view->printUser($db->isResp($_SESSION['utclogin']), $db->isAdmin($_SESSION['utc
if (isset($_GET['mode'])) {
if ($_GET['mode']=='resp') {
$view->respValidation($db->apiListResp($admin, $_SESSION['utclogin']));
if (isset($_GET['action']) && isset($_GET['api']) && isset($_GET['login'])) {
if ($_GET['action']=='validate') {
$db->validate($_SESSION['utclogin'], $_GET['api'], $_GET['login']);
$db->validate($_SESSION['utclogin'], $_GET['api'], $_GET['login']);
}
}
$view->respValidation($db->apiListResp($admin, $_SESSION['utclogin']));
}
if ($_GET['mode']=='admin') {
$view->adminFunction($_SESSION['utclogin']);
......@@ -66,6 +66,6 @@ else {
}
$view->printInstructions($db->config());
$view->printSubList($db->subList($_SESSION['utclogin']));
$view->printApiList($db->apiList($admin));
$view->printApiList($db->apiList($admin, $_SESSION['utclogin']));
}
?>
......@@ -16,7 +16,8 @@ class DB {
public function subList($utclogin) {
$sql = 'SELECT *
FROM vsubscription
WHERE utclogin=:utclogin';
WHERE utclogin=:utclogin
AND (validation OR validation IS NULL)';
$st = $this->conn->prepare($sql);
$st->bindValue(':utclogin',$utclogin,PDO::PARAM_STR);
$st->execute();
......@@ -24,13 +25,14 @@ class DB {
return $res;
}
public function apiList($admin) {
$sql = 'SELECT *
public function apiList($admin, $utclogin) {
$sql = 'SELECT *, is_available(:utclogin, week, year) AS is_available
FROM vapi
WHERE semester=:semester AND year=:year';
$st = $this->conn->prepare($sql);
$st->bindValue(':semester',$admin->activeSemester(),PDO::PARAM_STR);
$st->bindValue(':year',$admin->activeYear(),PDO::PARAM_INT);
$st->bindValue(':utclogin',$utclogin,PDO::PARAM_STR);
$st->execute();
$res = $st->fetchAll(PDO::FETCH_ASSOC);
return $res;
......@@ -108,7 +110,7 @@ class DB {
public function apiListResp($admin, $utclogin) {
$sql = 'SELECT *
FROM vsubscription
WHERE semester=:semester AND year=:year AND resplogin=:resp' ;
WHERE semester=:semester AND year=:year AND resplogin=:resp' ;
$st = $this->conn->prepare($sql);
$st->bindValue(':semester',$admin->activeSemester(),PDO::PARAM_STR);
$st->bindValue(':year',$admin->activeYear(),PDO::PARAM_INT);
......@@ -144,7 +146,9 @@ class DB {
$sql = "BEGIN";
$st = $this->conn->prepare($sql);
$st->execute();
$sql = "UPDATE subscribe SET validation='TRUE', validationdate=:today WHERE api=:api AND utclogin=:utclogin";
$sql = "UPDATE subscribe
SET validation='TRUE', validationdate=:today
WHERE api=:api AND utclogin=:utclogin";
$st = $this->conn->prepare($sql);
$st->bindValue(':utclogin',$student,PDO::PARAM_STR);
$st->bindValue(':api',$api,PDO::PARAM_STR);
......@@ -152,9 +156,10 @@ class DB {
$res = $st->execute();
// Cancel other subscriptions the same week
$sql = "UPDATE subscribe SET validation='FALSE', validationdate=:today
WHERE api<>:api AND utclogin=:utclogin
AND api IN (SELECT id FROM vapi WHERE week=:week AND year=:year)";
$sql = "UPDATE subscribe
SET validation='FALSE', validationdate=:today
WHERE api<>:api AND utclogin=:utclogin
AND api IN (SELECT id FROM vapi WHERE week=:week AND year=:year)";
$st = $this->conn->prepare($sql);
$st->bindValue(':utclogin',$student,PDO::PARAM_STR);
$st->bindValue(':api',$api,PDO::PARAM_STR);
......
......@@ -26,14 +26,15 @@ class Views {
echo '<link href="css/main.css" type="text/css" rel="stylesheet"/>';
echo '</head>';
echo '<body>';
echo '<h1>Inscriptions Api</h1>';
echo '<h1>Inscriptions aux Api</h1>';
}
public function printInstructions($row) {
echo '<h2>Instructions</h2>';
echo '<p>Les Api sont décrites ici : <b><a href="https://apint.utc.fr/cat">https://apint.utc.fr/cat</a></b></p>';
echo "<p>Veillez à avoir bien lu la fiche avant de vous inscrire (pré-requis, dates...). Vous pouvez vous inscrire et vous désinscrire librement entre le $row[openbegin] et le $row[openend].</p>";
echo '<p>Vous ne <b>pouvez pas</b> suivre deux Api qui se chevauchent (sauf pour le cas particulier de l\'Api <i>Animer une Api</i>). Si vous choisissez deux Api qui se chevauchent, indiquez vos préférences dans la zone de commentaire.</p>';
echo "<p>Veillez à avoir bien lu la fiche avant de vous inscrire (pré-requis, dates...). Vous pouvez vous inscrire et vous désinscrire <b>tant que votre inscription n'est pas validée</b>.</p>";
echo "<p>La présence à une Api validée est obligatoire.<p>";
echo '<p>Vous ne <b>pouvez pas</b> suivre deux Api qui se déroulent lors de la même semaine (sauf pour le cas particulier de l\'Api <i>Animer une Api</i>). Si vous choisissez deux Api la même semaine, vous serez inscrit à la première qui sera validée.</p>';
}
public function printUser($isResp, $isAdmin) {
......@@ -50,16 +51,31 @@ class Views {
}
private function printApi($row) {
return "$row[normcode] - $row[name] (du $row[normdbegin] au $row[normdend]) [Inscriptions : $row[nbsub]/$row[size]]";
return "$row[normcode] - $row[name] (du $row[normdbegin] au $row[normdend]) [Demandes $row[nbask] | Inscriptions $row[nbval]/$row[size]]";
}
private function printWeek($row) {
return "$row[year] Semaine $row[week]";
}
public function printSubList($list) {
#KNOWN_BUB #TODO Il est possible de ses déinscrire en utilisant directement l'URL
if ($list) {
echo '<h2>Vos inscriptions</h2>';
$week = '';
foreach ($list as $row) {
if ($row['week'] != $week) {
$week = $row['week'];
echo "<h3>".$this->printWeek($row)."</h3>";
}
echo '<p>';
if ($this->isActive()) {
echo "<a href='index.php?action=unsub&api=$row[id]'>[désinscription]</a> ";
if ($row['validation']) {
echo "<span class='validation'>[validé]</span> ";
}
else {
echo "<a href='index.php?action=unsub&api=$row[id]'>[désinscription]</a> ";
}
}
echo $this->printApi($row);
echo ' ['.$row['semester'].$row['year'].', inscrit le '.$row['subdate'].']';
......@@ -74,10 +90,23 @@ class Views {
public function printApiList($list) {
if ($list) {
echo '<h2>Liste des Api</h2>';
$week = '';
foreach ($list as $row) {
if ($row['week'] != $week) {
$week = $row['week'];
echo "<h3>".$this->printWeek($row)."</h3>";
}
echo '<p>';
if ($this->isActive()) {
echo "<a href='index.php?action=sub&api=$row[id]'>[inscription]</a> ";
if ($row['open'] && $row['is_available']) {
echo "<a href='index.php?action=sub&api=$row[id]'>[inscription]</a> ";
}
elseif (! $row['is_available']) {
echo "[-] ";
}
else {
echo '[complet] ';
}
}
echo $this->printApi($row);
echo '</p>';
......@@ -89,6 +118,7 @@ class Views {
}
public function respValidation ($listsub) {
// #KNOWN_BUG Si un resp a plusieurs Api, il peut changer un inscrit entre ses deux Api en modifiant l'URL (pas via l'interface)
echo '<h1>Interface Responsable d\'Api</h2>';
if ($listsub) {
$api = '';
......@@ -97,7 +127,23 @@ class Views {
$api = $sub['id'];
echo "<h2>$sub[normcode] $sub[name] (Semaine $sub[week])</h2>";
}
echo "<p>$sub[utclogin] <a href='index.php?action=validate&api=$sub[id]&login=$sub[utclogin]&mode=resp'>[valider]</a></p>";
if ($sub['utclogin']) {
if ($sub['validation']) {
// Subscription already validated
echo "<p><b>[validé]</b> $sub[utclogin]</p>";
}
else if (is_null($sub['validation'])) {
// At least one waiting subscription
echo "<p> <a href='index.php?action=validate&api=$sub[id]&login=$sub[utclogin]&mode=resp'>[valider]</a> $sub[utclogin]</p>";
}
else {
// validation = FALSE lignes ignored
}
}
else {
// Not yet any subscription for this Api (LEFT JOIN might have add null student line)
echo "<p>Aucune inscription à gérer</p>";
}
}
}
else {
......@@ -106,6 +152,6 @@ class Views {
}
public function adminFunction ($utclogin) {
echo "<p>Je dois vérifier que $utclogin a vraiment des super-pouvoirs ?</p>";
echo "<p>Je dois vérifier que $utclogin a vraiment des super-pouvoirs...</p>";
}
}
......@@ -15,6 +15,10 @@ class Api {
week() : [1..53]
year() : int(4)
semester() : H|E|A|P
nbsub() : int
nbval() : int
isActive() : boolean
isOpen() : boolean
}
note left of Api : (dbeging,code) key\n(dbegin,name) key\nduration in days
......
......@@ -12,33 +12,40 @@ INSERT INTO localuser (utclogin) VALUES ('student3');
INSERT INTO api VALUES (
'1e06e8dc-2178-11e9-8edb-4bc5e8f8599c',
TO_DATE('20190121','yyyymmdd'),1,'Poésie et ingénierie','Lorem ipsum dolor sit amet',5,24,2,'crozatst'
TO_DATE('20190121','yyyymmdd'),1,'Poésie et ingénierie','Lorem ipsum dolor sit amet',5,3,2,'crozatst'
);
INSERT INTO api VALUES (
'2afa8472-2178-11e9-b2b0-07511495b3b2',
TO_DATE('20190121','yyyymmdd'),2,'Cloud big data blockchain IA','At vero eos et accusamus',3,12,1,'crozatst'
);
INSERT INTO api VALUES (
'4352b3a0-217d-11e9-aabc-037b6e1a6a16',
'3352b3a0-217d-11e9-aabc-037b6e1a6a33',
TO_DATE('20190128','yyyymmdd'),3,'La TRM et la G1','Duis rhoncus turpis non libero auctor posuere.',5,50,2,'crozatst'
);
INSERT INTO api VALUES (
'4352b3a0-217d-11e9-aabc-037b6e1a6a16',
TO_DATE('20190128','yyyymmdd'),4,'Initiation au Picard','Vivamus porttitor arcu non dui mollis.',1,1,1,'crozatst'
);
INSERT INTO subscribe (utclogin,api,subdate) VALUES (
'student1','1e06e8dc-2178-11e9-8edb-4bc5e8f8599c',TO_DATE('20190121','yyyymmdd')
);
INSERT INTO subscribe (utclogin,api,subdate) VALUES (
'student1','2afa8472-2178-11e9-b2b0-07511495b3b2',TO_DATE('20190121','yyyymmdd')
'student2','1e06e8dc-2178-11e9-8edb-4bc5e8f8599c',TO_DATE('20190121','yyyymmdd')
);
INSERT INTO subscribe (utclogin,api,subdate) VALUES (
'student1','4352b3a0-217d-11e9-aabc-037b6e1a6a16',TO_DATE('20190121','yyyymmdd')
'student3','1e06e8dc-2178-11e9-8edb-4bc5e8f8599c',TO_DATE('20190121','yyyymmdd')
);
INSERT INTO subscribe (utclogin,api,subdate) VALUES (
'student2','1e06e8dc-2178-11e9-8edb-4bc5e8f8599c',TO_DATE('20190121','yyyymmdd')
'student1','2afa8472-2178-11e9-b2b0-07511495b3b2',TO_DATE('20190121','yyyymmdd')
);
INSERT INTO subscribe (utclogin,api,subdate) VALUES (
'student1','4352b3a0-217d-11e9-aabc-037b6e1a6a16',TO_DATE('20190121','yyyymmdd')
);
SELECT id, normcode, name FROM vapi;
SELECT normcode, name, size, nbval, nbask, nbsub, open FROM vapi;
SELECT * FROM vlocaluser;
SELECT utclogin, id, normcode FROM vsubscription;
SELECT * FROM vapi_count;
SELECT utclogin, id, normcode, validation FROM vsubscription;
COMMIT;
CREATE OR REPLACE FUNCTION unaccent_string(TEXT)
RETURNS TEXT
AS $$
CREATE OR REPLACE FUNCTION unaccent_string(TEXT) RETURNS TEXT AS $$
SELECT translate(
$1,
'âãäåÁÂÃÄÅèééêëÈÉÉÊËìíîïìÌÍÎÏÌóôõöÒÓÔÕÖùúûüÙÚÛÜ',
......@@ -8,11 +6,26 @@ AS $$
);
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION is_available(TEXT, TEXT, TEXT) RETURNS BOOLEAN AS $$
DECLARE
student ALIAS FOR $1;
w ALIAS FOR $2;
y ALIAS FOR $3;
c INTEGER;
BEGIN
SELECT COUNT(*) INTO c
FROM vsubscription
WHERE utclogin=student AND week=w AND year=y AND validation;
IF c = 0 THEN
RETURN 'TRUE';
ELSE
RETURN 'FALSE';
END IF;
END;
$$ LANGUAGE PLPGSQL;
/** TODO **/
CREATE OR REPLACE FUNCTION
semester(DATE)
RETURNS CHAR(1)
AS $$
CREATE OR REPLACE FUNCTION semester(DATE) RETURNS CHAR(1) AS $$
BEGIN
RETURN 'E';
END;
......
BEGIN;
CREATE OR REPLACE VIEW vapi_count AS
CREATE OR REPLACE VIEW vapi_subcount AS
SELECT
api AS countid,
COUNT(utclogin) AS nbsub
api AS subcountid,
COUNT(utclogin) AS countsub
FROM subscribe
GROUP BY api;
CREATE OR REPLACE VIEW vapi_valcount AS
SELECT
api AS valcountid,
COUNT(utclogin) AS countval
FROM subscribe
WHERE validation
GROUP BY api;
CREATE OR REPLACE VIEW vapi AS
SELECT
*,
......@@ -15,9 +23,13 @@ CASE WHEN code<10 THEN '000'||code WHEN code>=10 THEN '00'||code END AS normcode
TO_CHAR(dbegin + duration-1,'TMday FMDD TMmonth') AS normdend,
TO_CHAR(dbegin, 'ww') AS week,
TO_CHAR(dbegin, 'yyyy') AS year,
semester(dbegin) AS semester
FROM api LEFT JOIN vapi_count ON id=countid
ORDER BY dbegin, code;
semester(dbegin) AS semester,
COALESCE(countsub,0) AS nbsub,
COALESCE(countval,0) AS nbval,
COALESCE(countsub,0)-COALESCE(countval,0) AS nbask,
CASE WHEN countval >= size THEN 0 ELSE 1 END AS open
FROM api LEFT JOIN vapi_subcount ON id=subcountid LEFT JOIN vapi_valcount ON id=valcountid
ORDER BY year, week, code;
CREATE OR REPLACE VIEW vlocaluser AS
SELECT l.utclogin, u.surname, u.firstname, l.email, MAX(u.speciality) AS speciality, MAX(u.level) AS level,
......@@ -34,9 +46,9 @@ su.subdate,
su.validation,
su.validationdate
FROM subscribe su
JOIN vapi ap ON ap.id=su.api
RIGHT JOIN vapi ap ON ap.id=su.api
LEFT JOIN vlocaluser lo ON su.utclogin=lo.utclogin
ORDER BY ap.dbegin, ap.code, lo.firstname, lo.surname, lo.utclogin;
ORDER BY ap.year, ap.week, ap.code, su.validation, lo.firstname, lo.surname, lo.utclogin;
CREATE OR REPLACE VIEW vsubscription_anonymous AS
SELECT normcode, name, normdbegin, normdend, size, speciality, level
......
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