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

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

parent 09fb5e6e
# Create user and db # Create user and db
DROP USER apisub; sql/db_init.sh (edit password first)
CREATE USER apisub WITH ENCRYPTED PASSWORD 'password';
DROP DATABASE apisub;
CREATE DATABASE apisub WITH OWNER apisub;
# Connect # Connect
psql -h localhost -U apisub -d apisub psql -h localhost -U apisub -d apisub
......
...@@ -52,13 +52,7 @@ if (isset($_GET['api']) && $admin->isActive()) { ...@@ -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->printSubList($db->subList($_SESSION['utclogin']));
$view->printExplanation($db->getExplanation($_SESSION['utclogin']), $_SESSION['utclogin']); $view->printApiList($db->apiList('E', 2019), $_SESSION['utclogin']);
$view->printApiList($db->apiList('H', 2019), $_SESSION['utclogin']);
?> ?>
...@@ -24,28 +24,6 @@ class DB { ...@@ -24,28 +24,6 @@ class DB {
return $res; 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) { public function apiList($semester, $year) {
$sql = 'SELECT * $sql = 'SELECT *
FROM vapi FROM vapi
......
...@@ -47,7 +47,7 @@ class Views { ...@@ -47,7 +47,7 @@ class Views {
} }
private function printApi($row) { 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) { public function printSubList($list) {
...@@ -56,7 +56,7 @@ class Views { ...@@ -56,7 +56,7 @@ class Views {
foreach ($list as $row) { foreach ($list as $row) {
echo '<p>'; echo '<p>';
if ($this->isActive()) { 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 $this->printApi($row);
echo ' ['.$row['semester'].$row['year'].', inscrit le '.$row['subdate'].']'; echo ' ['.$row['semester'].$row['year'].', inscrit le '.$row['subdate'].']';
...@@ -89,7 +89,7 @@ class Views { ...@@ -89,7 +89,7 @@ class Views {
foreach ($list as $row) { foreach ($list as $row) {
echo '<p>'; echo '<p>';
if ($this->isActive()) { 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 $this->printApi($row);
echo '</p>'; echo '</p>';
......
/** Test dataset **/ /** Test dataset **/
BEGIN;
DELETE FROM api; DELETE FROM api;
DELETE FROM localuser; DELETE FROM localuser;
INSERT INTO localuser (utclogin) VALUES ('crozatst'); 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 ( 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,24,2,'crozatst'
); );
INSERT INTO api VALUES ( 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 vlocaluser;
SELECT * FROM vsubscription; SELECT utclogin, id, normcode FROM vsubscription;
SELECT * FROM vsubscription_anonymous;
SELECT * FROM vapi_count; SELECT * FROM vapi_count;
COMMIT;
...@@ -15,6 +15,7 @@ CREATE TABLE localuser ( ...@@ -15,6 +15,7 @@ CREATE TABLE localuser (
); );
CREATE TABLE api ( CREATE TABLE api (
id UUID PRIMARY KEY,
dbegin DATE NOT NULL, dbegin DATE NOT NULL,
code INTEGER NOT NULL, code INTEGER NOT NULL,
name TEXT NOT NULL, name TEXT NOT NULL,
...@@ -28,20 +29,19 @@ CREATE TABLE api ( ...@@ -28,20 +29,19 @@ CREATE TABLE api (
CHECK (size>0), CHECK (size>0),
CHECK (ects BETWEEN 1 AND 3), CHECK (ects BETWEEN 1 AND 3),
FOREIGN KEY (resplogin) REFERENCES localuser (utclogin), FOREIGN KEY (resplogin) REFERENCES localuser (utclogin),
PRIMARY KEY (dbegin, code), UNIQUE (dbegin, code),
UNIQUE (dbegin, name), UNIQUE (dbegin, name),
UNIQUE (dbegin, description) UNIQUE (dbegin, description)
); );
CREATE TABLE subscribe ( CREATE TABLE subscribe (
utclogin TEXT NOT NULL, utclogin TEXT NOT NULL,
dbegin DATE NOT NULL, api UUID NOT NULL,
code INTEGER NOT NULL,
subdate DATE NOT NULL, subdate DATE NOT NULL,
confirmed BOOLEAN NOT NULL DEFAULT FALSE, confirmed BOOLEAN NOT NULL DEFAULT FALSE,
FOREIGN KEY (utclogin) REFERENCES localuser(utclogin), FOREIGN KEY (utclogin) REFERENCES localuser(utclogin),
FOREIGN KEY (dbegin,code) REFERENCES api(dbegin,code), FOREIGN KEY (api) REFERENCES api(id),
PRIMARY KEY (utclogin,dbegin,code) PRIMARY KEY (utclogin,api)
); );
/* Table created to retrieve CSV info from DFP (À supprimer) */ /* Table created to retrieve CSV info from DFP (À supprimer) */
......
BEGIN; 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 CREATE OR REPLACE VIEW vapi AS
SELECT SELECT
*, *,
...@@ -9,7 +16,7 @@ TO_CHAR(dbegin + duration-1,'TMday FMDD TMmonth') AS normdend, ...@@ -9,7 +16,7 @@ TO_CHAR(dbegin + duration-1,'TMday FMDD TMmonth') AS normdend,
TO_CHAR(dbegin, 'ww') AS week, TO_CHAR(dbegin, 'ww') AS week,
TO_CHAR(dbegin, 'yyyy') AS year, TO_CHAR(dbegin, 'yyyy') AS year,
semester(dbegin) AS semester semester(dbegin) AS semester
FROM api FROM api LEFT JOIN vapi_count ON id=countid
ORDER BY dbegin, code; ORDER BY dbegin, code;
CREATE OR REPLACE VIEW vlocaluser AS CREATE OR REPLACE VIEW vlocaluser AS
...@@ -26,7 +33,7 @@ TO_CHAR(su.subdate,'DD/MM/YYYY') AS subdate, ...@@ -26,7 +33,7 @@ TO_CHAR(su.subdate,'DD/MM/YYYY') AS subdate,
su.utclogin AS sublogin, su.utclogin AS sublogin,
lo.* lo.*
FROM subscribe su 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 LEFT JOIN vlocaluser lo ON su.utclogin=lo.utclogin
ORDER BY ap.dbegin, ap.code, lo.firstname, lo.surname, 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 ...@@ -34,12 +41,4 @@ CREATE OR REPLACE VIEW vsubscription_anonymous AS
SELECT normcode, name, normdbegin, normdend, size, speciality, level SELECT normcode, name, normdbegin, normdend, size, speciality, level
FROM vsubscription; FROM vsubscription;
CREATE OR REPLACE VIEW vapi_count AS
SELECT
dbegin,
code,
COUNT(utclogin) AS nbsub
FROM vsubscription
GROUP BY dbegin, code;
COMMIT; COMMIT;
#!/bin/bash #!/bin/bash
sqlfiles='/media/stc/data/git/apisub/sql' sqlfiles='/media/stc/data/git/apisub/sql'
psql -f "$sqlfiles/apisub_functions.sql" psql -c "DROP DATABASE apisub"
psql -f "$sqlfiles/apisub_admin.sql" psql -c "DROP USER apisub"
psql -f "$sqlfiles/apisub_tables.sql" psql -c "CREATE USER apisub WITH ENCRYPTED PASSWORD 'password'"
psql -f "$sqlfiles/apisub_views.sql" psql -c "CREATE DATABASE apisub WITH OWNER apisub"
psql -f "$sqlfiles/apisub_dataset.sql" 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