Commit 9412b72b authored by Stephane Crozat's avatar Stephane Crozat

Fix #9

parent f63c4eaa
......@@ -3,3 +3,7 @@ CREATE USER apisub WITH ENCRYPTED PASSWORD 'password';
DROP DATABASE apisub;
CREATE DATABASE apisub;
GRANT ALL PRIVILEGES ON DATABASE apisub TO apisub;
# PHP
On Ubuntu, add XML lib to PHP
apt install php-xml
......@@ -36,6 +36,7 @@ Views::printHtmlBegin();
Views::printUser($_SESSION['utclogin'], $_SESSION['surname'], $_SESSION['firstname']);
Views::printInstructions();
/** Subscription and unsubscription management **/
if (isset($_GET['api']) && isset($_GET['utclogin'])) {
if (isset($_GET['action'])) {
if ($_GET['action']=='sub') {
......@@ -47,7 +48,13 @@ if (isset($_GET['api']) && isset($_GET['utclogin'])) {
}
}
/** Explanation management **/
if (isset($_GET['explanation'])) {
$db->setExplanation($_SESSION['utclogin'],$_GET['explanation']);
}
Views::printSubList($db->subList($_SESSION['utclogin']), $_SESSION['utclogin']);
Views::printExplanation($db->getExplanation($_SESSION['utclogin']), $_SESSION['utclogin']);
Views::printApiList($db->apiList('H', 2019), $_SESSION['utclogin']);
?>
......@@ -24,6 +24,30 @@ class DB {
return $res;
}
public function getExplanation($utclogin) {
$sql = 'SELECT explanation
FROM localuser
WHERE utclogin=:utclogin';
$st = $this->conn->prepare($sql);
$st->bindValue(':utclogin',$utclogin,PDO::PARAM_STR);
$st->execute();
$res = $st->fetch(PDO::FETCH_ASSOC);
return $res['explanation'];
}
public function setExplanation($utclogin,$explanation) {
$sql = 'UPDATE localuser
SET explanation=:explanation
WHERE utclogin=:utclogin';
$st = $this->conn->prepare($sql);
$st->bindValue(':explanation',$explanation,PDO::PARAM_STR);
$st->bindValue(':utclogin',$utclogin,PDO::PARAM_STR);
$res = $st->execute();
return $res;
}
public function apiList($semester, $year) {
$sql = 'SELECT *
FROM vapi
......@@ -62,7 +86,7 @@ class DB {
$st1 = $this->conn->prepare($sql);
$st1->bindValue(':utclogin',$utclogin,PDO::PARAM_STR);
$st1->execute();
if (!$st1->fetch(PDO::FETCH_ASSOC)) {
if (!$st1->fetch(PDO::FETCH_ASSOC)) {
// If user has never logged in yet, he is added to local copy
$sql = 'INSERT INTO localuser(utclogin, firstname, surname) VALUES (:utclogin, :firstname, :surname)';
$st2 = $this->conn->prepare($sql);
......
......@@ -16,9 +16,8 @@ class Views {
public static function printInstructions() {
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...).</p>';
echo '<p>Vous pouvez vous inscrire et vous désinscrire librement jusqu\'au 4 décembre 2018.</p>';
echo '<p>Veillez à <b>ne pas</b> choisir deux Api qui se chevauchent (sauf pour le cas particulier de l\'Api <i>Animer une Api</i>).</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 jusqu\'au 4 décembre 2018.</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>';
}
public static function printUser($utclogin, $surname, $firstname) {
......@@ -45,6 +44,15 @@ class Views {
}
}
public static function printExplanation($comment, $utclogin) {
echo '<h2>Commentaire</h2>';
echo '<form method="get" action="index.php">';
echo '<textarea name="explanation" cols="100" rows="5">'.$comment.'</textarea>';
echo '<br/>';
echo '<input type="submit" value="Enregistrer le commentaire"/>';
echo '</form>';
}
public static function printApiList($list, $utclogin) {
if ($list) {
echo '<h2>Liste des Api</h2>';
......@@ -60,6 +68,4 @@ class Views {
}
}
}
BEGIN;
DROP TABLE IF EXISTS subscribe CASCADE;
DROP TABLE IF EXISTS api CASCADE;
DROP TABLE IF EXISTS localuser CASCADE;
DROP TABLE IF EXISTS utcstudent;
CREATE TABLE api (
code INTEGER PRIMARY KEY,
......@@ -21,19 +25,26 @@ CREATE TABLE api (
UNIQUE (name,year,semester)
);
CREATE TABLE subscribe (
utclogin TEXT NOT NULL,
api INTEGER REFERENCES api(code),
subdate DATE NOT NULL,
PRIMARY KEY (utclogin,api)
);
/* Table created to collect CAS user surname and firstname */
CREATE TABLE localuser (
utclogin TEXT PRIMARY KEY,
surname TEXT,
firstname TEXT
firstname TEXT,
explanation TEXT
);
/* MAJ Apisub H19
ALTER TABLE localuser ADD explanation TEXT;
*/
CREATE TABLE subscribe (
utclogin TEXT NOT NULL REFERENCES localuser(utclogin),
api INTEGER REFERENCES api(code),
subdate DATE NOT NULL,
PRIMARY KEY (utclogin,api)
);
/* MAJ Apisub H19
ALTER TABLE subscribe ADD FOREIGN KEY (utclogin) REFERENCES localuser(utclogin);
*/
/* Table created to retrieve CSV info from DFP */
CREATE TABLE utcstudent (
......@@ -68,18 +79,6 @@ FROM localuser l
LEFT JOIN utcstudent u ON l.surname=u.surname AND l.firstname=unaccent_string(u.firstname)
GROUP BY l.utclogin, u.surname, u.firstname;
/** Test dataset
INSERT INTO api VALUES (
1,'Poésie et ingénierie',2019,'H',TO_DATE('20190121','yyyymmdd'),TO_DATE('20190125','yyyymmdd'),24,2,'stc@utc.fr'
);
INSERT INTO api VALUES (
2,'Cloud big data blockchain IA',2019,'H',TO_DATE('20190125','yyyymmdd'),TO_DATE('20190131','yyyymmdd'),12,3,'stc@utc.fr'
);
INSERT INTO subscribe VALUES (
'crozatst',1,TO_DATE('20181018','YYYYMMDD')
);
**/
CREATE OR REPLACE VIEW vapi AS
SELECT
ap.code,
......@@ -98,3 +97,5 @@ FROM subscribe su
JOIN vapi ap ON ap.code=su.api
LEFT JOIN vlocaluser lo ON su.utclogin=lo.utclogin
ORDER BY ap.year, ap.semester, ap.dbegin, ap.dend, ap.code, lo.firstname, lo.surname, su.utclogin;
COMMIT;
/** Test dataset **/
DELETE FROM api;
INSERT INTO api VALUES (
1,'Poésie et ingénierie','Lorem ipsum dolor sit amet',2019,'H',TO_DATE('20190121','yyyymmdd'),TO_DATE('20190125','yyyymmdd'),24,2,'stc@utc.fr'
);
INSERT INTO api VALUES (
2,'Cloud big data blockchain IA','At vero eos et accusamus',2019,'H',TO_DATE('20190125','yyyymmdd'),TO_DATE('20190131','yyyymmdd'),12,3,'stc@utc.fr'
);
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