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

Remise en fonctionnement de l'appli sur le nouveau schéma

parent 09fb5e6e
# Create user and db
DROP USER apisub;
CREATE USER apisub WITH ENCRYPTED PASSWORD 'password';
DROP DATABASE apisub;
CREATE DATABASE apisub WITH OWNER apisub;
sql/db_init.sh (edit password first)
# Connect
psql -h localhost -U apisub -d apisub
......
......@@ -52,13 +52,7 @@ if (isset($_GET['api']) && $admin->isActive()) {
}
}
/** Explanation management **/
if (isset($_GET['explanation'])) {
$db->setExplanation($_SESSION['utclogin'],$_GET['explanation']);
}
$view->printSubList($db->subList($_SESSION['utclogin']));
$view->printExplanation($db->getExplanation($_SESSION['utclogin']), $_SESSION['utclogin']);
$view->printApiList($db->apiList('H', 2019), $_SESSION['utclogin']);
$view->printApiList($db->apiList('E', 2019), $_SESSION['utclogin']);
?>
......@@ -24,28 +24,6 @@ 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
......@@ -121,7 +99,7 @@ class DB {
public function isAdmin ($utclogin) {
$sql = 'SELECT utclogin FROM admins WHERE utclogin=:utclogin';
$st = $this->conn->prepare($sql);
$st->bindValue(':utclogin',$utclogin,PDO::PARAM_STR);
$st->bindValue(':utclogin',$utclogin,PDO::PARAM_STR);
$st->execute();
$res = $st->fetch(PDO::FETCH_ASSOC);
return $res['utclogin'];
......
......@@ -47,7 +47,7 @@ class Views {
}
private function printApi($row) {
return "$row[normcode] - $row[name] (du $row[dbegin] au $row[dend]) [Inscriptions : $row[nbsub]/$row[size]]";
return "$row[normcode] - $row[name] (du $row[normdbegin] au $row[normdend]) [Inscriptions : $row[nbsub]/$row[size]]";
}
public function printSubList($list) {
......@@ -56,7 +56,7 @@ class Views {
foreach ($list as $row) {
echo '<p>';
if ($this->isActive()) {
echo "<a href='index.php?action=unsub&api=$row[code]'>[désinscription]</a> ";
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'].']';
......@@ -89,7 +89,7 @@ class Views {
foreach ($list as $row) {
echo '<p>';
if ($this->isActive()) {
echo "<a href='index.php?action=sub&api=$row[code]'>[inscription]</a> ";
echo "<a href='index.php?action=sub&api=$row[id]'>[inscription]</a> ";
}
echo $this->printApi($row);
echo '</p>';
......
/** Test dataset **/
BEGIN;
DELETE FROM api;
DELETE FROM localuser;
INSERT INTO localuser (utclogin) VALUES ('crozatst');
INSERT INTO localuser (utclogin) VALUES ('prof1');
INSERT INTO localuser (utclogin) VALUES ('student1');
INSERT INTO localuser (utclogin) VALUES ('student2');
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'
);
INSERT INTO api VALUES (
TO_DATE('20190125','yyyymmdd'),2,'Cloud big data blockchain IA','At vero eos et accusamus',3,12,1,'crozatst'
'2afa8472-2178-11e9-b2b0-07511495b3b2',
TO_DATE('20190128','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',
TO_DATE('20190121','yyyymmdd'),3,'La TRM et la G1','Duis rhoncus turpis non libero auctor posuere.',5,50,2,'prof1'
);
SELECT * FROM vapi;
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')
);
INSERT INTO subscribe (utclogin,api,subdate) VALUES (
'student1','4352b3a0-217d-11e9-aabc-037b6e1a6a16',TO_DATE('20190121','yyyymmdd')
);
INSERT INTO subscribe (utclogin,api,subdate) VALUES (
'student2','1e06e8dc-2178-11e9-8edb-4bc5e8f8599c',TO_DATE('20190121','yyyymmdd')
);
SELECT id, normcode, name FROM vapi;
SELECT * FROM vlocaluser;
SELECT * FROM vsubscription;
SELECT * FROM vsubscription_anonymous;
SELECT utclogin, id, normcode FROM vsubscription;
SELECT * FROM vapi_count;
COMMIT;
......@@ -15,6 +15,7 @@ CREATE TABLE localuser (
);
CREATE TABLE api (
id UUID PRIMARY KEY,
dbegin DATE NOT NULL,
code INTEGER NOT NULL,
name TEXT NOT NULL,
......@@ -28,20 +29,19 @@ CREATE TABLE api (
CHECK (size>0),
CHECK (ects BETWEEN 1 AND 3),
FOREIGN KEY (resplogin) REFERENCES localuser (utclogin),
PRIMARY KEY (dbegin, code),
UNIQUE (dbegin, code),
UNIQUE (dbegin, name),
UNIQUE (dbegin, description)
);
CREATE TABLE subscribe (
utclogin TEXT NOT NULL,
dbegin DATE NOT NULL,
code INTEGER NOT NULL,
api UUID NOT NULL,
subdate DATE NOT NULL,
confirmed BOOLEAN NOT NULL DEFAULT FALSE,
FOREIGN KEY (utclogin) REFERENCES localuser(utclogin),
FOREIGN KEY (dbegin,code) REFERENCES api(dbegin,code),
PRIMARY KEY (utclogin,dbegin,code)
FOREIGN KEY (api) REFERENCES api(id),
PRIMARY KEY (utclogin,api)
);
/* Table created to retrieve CSV info from DFP (À supprimer) */
......
BEGIN;
CREATE OR REPLACE VIEW vapi_count AS
SELECT
api AS countid,
COUNT(utclogin) AS nbsub
FROM subscribe
GROUP BY api;
CREATE OR REPLACE VIEW vapi AS
SELECT
*,
......@@ -9,7 +16,7 @@ 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
FROM api LEFT JOIN vapi_count ON id=countid
ORDER BY dbegin, code;
CREATE OR REPLACE VIEW vlocaluser AS
......@@ -26,7 +33,7 @@ TO_CHAR(su.subdate,'DD/MM/YYYY') AS subdate,
su.utclogin AS sublogin,
lo.*
FROM subscribe su
JOIN vapi ap ON ap.dbegin=su.dbegin AND ap.code=su.code
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;
......@@ -34,12 +41,4 @@ CREATE OR REPLACE VIEW vsubscription_anonymous AS
SELECT normcode, name, normdbegin, normdend, size, speciality, level
FROM vsubscription;
CREATE OR REPLACE VIEW vapi_count AS
SELECT
dbegin,
code,
COUNT(utclogin) AS nbsub
FROM vsubscription
GROUP BY dbegin, code;
COMMIT;
#!/bin/bash
sqlfiles='/media/stc/data/git/apisub/sql'
psql -f "$sqlfiles/apisub_functions.sql"
psql -f "$sqlfiles/apisub_admin.sql"
psql -f "$sqlfiles/apisub_tables.sql"
psql -f "$sqlfiles/apisub_views.sql"
psql -f "$sqlfiles/apisub_dataset.sql"
psql -c "DROP DATABASE apisub"
psql -c "DROP USER apisub"
psql -c "CREATE USER apisub WITH ENCRYPTED PASSWORD 'password'"
psql -c "CREATE DATABASE apisub WITH OWNER apisub"
psql -d apisub -f "$sqlfiles/apisub_functions.sql"
psql -d apisub -f "$sqlfiles/apisub_admin.sql"
psql -d apisub -f "$sqlfiles/apisub_tables.sql"
psql -d apisub -f "$sqlfiles/apisub_views.sql"
psql -d apisub -f "$sqlfiles/apisub_dataset.sql"
psql -d apisub -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO apisub"
<?php
phpinfo();
?>
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