Commit 7a1cbc6f authored by Stephane Crozat's avatar Stephane Crozat
Browse files

Adding localcopy of users surname and lastname when then CAS login, in order to join CSV files'

parent ccd05b52
...@@ -18,14 +18,20 @@ if (!isset($_SESSION['ticket'])) { ...@@ -18,14 +18,20 @@ if (!isset($_SESSION['ticket'])) {
$_SESSION['surname'] = strtoupper($info['cas:attributes']['cas:sn']); $_SESSION['surname'] = strtoupper($info['cas:attributes']['cas:sn']);
$_SESSION['firstname'] = $info['cas:attributes']['cas:givenName']; $_SESSION['firstname'] = $info['cas:attributes']['cas:givenName'];
} }
else else {
$cas->login(); $cas->login();
}
$_SESSION['localcopy'] = true; //call localcopy once per session
} }
include $_SERVER['DOCUMENT_ROOT'].'/apisub/lib/db.php'; include $_SERVER['DOCUMENT_ROOT'].'/apisub/lib/db.php';
include 'lib/views.php'; include 'lib/views.php';
$db = new DB(); $db = new DB();
if ($_SESSION['localcopy']) {
$db->copyUser($_SESSION['utclogin'], $_SESSION['surname'], $_SESSION['firstname']);
$_SESSION['localcopy']=false;
}
Views::printHtmlBegin(); Views::printHtmlBegin();
Views::printUser($_SESSION['utclogin'], $_SESSION['surname'], $_SESSION['firstname']); Views::printUser($_SESSION['utclogin'], $_SESSION['surname'], $_SESSION['firstname']);
Views::printInstructions(); Views::printInstructions();
......
...@@ -55,4 +55,27 @@ class DB { ...@@ -55,4 +55,27 @@ class DB {
$res = $st->execute(); $res = $st->execute();
return $res; return $res;
} }
public function copyUser($utclogin, $surname, $firstname) {
// Function used to create a local copy of surname and firstname of each user, in order to link to DFP files without utclogin
$sql = 'SELECT utclogin FROM localuser WHERE utclogin=:utclogin';
$st1 = $this->conn->prepare($sql);
$st1->bindValue(':utclogin',$utclogin,PDO::PARAM_STR);
$st1->execute();
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);
$st2->bindValue(':utclogin',$utclogin,PDO::PARAM_STR);
$st2->bindValue(':firstname',$firstname,PDO::PARAM_STR);
$st2->bindValue(':surname',$surname,PDO::PARAM_STR);
$res = $st2->execute();
return $res;
}
else {
return 0;
};
}
} }
...@@ -28,6 +28,12 @@ CREATE TABLE subscribe ( ...@@ -28,6 +28,12 @@ CREATE TABLE subscribe (
PRIMARY KEY (utclogin,api) PRIMARY KEY (utclogin,api)
); );
CREATE TABLE localuser (
utclogin TEXT PRIMARY KEY,
surname TEXT,
firstname TEXT
);
/** Test dataset /** Test dataset
INSERT INTO api VALUES ( 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' 1,'Poésie et ingénierie',2019,'H',TO_DATE('20190121','yyyymmdd'),TO_DATE('20190125','yyyymmdd'),24,2,'stc@utc.fr'
...@@ -40,17 +46,19 @@ INSERT INTO subscribe VALUES ( ...@@ -40,17 +46,19 @@ INSERT INTO subscribe VALUES (
); );
**/ **/
CREATE OR REPLACE VIEW vApi AS CREATE OR REPLACE VIEW vapi AS
SELECT SELECT
ap.code, ap.code,
CASE WHEN ap.code<10 THEN '000'||ap.code WHEN ap.code>=10 THEN '00'||ap.code END AS normcode, CASE WHEN ap.code<10 THEN '000'||ap.code WHEN ap.code>=10 THEN '00'||ap.code END AS normcode,
ap.name, ap.year, ap.semester, ap.name, ap.year, ap.semester,
TO_CHAR(ap.dbegin,'TMday FMDD TMmonth') AS dbegin, TO_CHAR(ap.dend,'TMday FMDD TMmonth') AS dend, TO_CHAR(ap.dbegin,'TMday FMDD TMmonth') AS dbegin, TO_CHAR(ap.dend,'TMday FMDD TMmonth') AS dend,
ap.size, ap.ects, ap.mail ap.size, ap.ects, ap.mail,
FROM api ap COUNT(su.utclogin) AS nbsub
FROM api ap LEFT JOIN subscribe su ON ap.code=su.api
GROUP BY ap.code, normcode, ap.name, ap.year, ap.semester, dbegin, dend, ap.size, ap.ects, ap.mail
ORDER BY ap.year, ap.semester, ap.dbegin, ap.dend, ap.code; ORDER BY ap.year, ap.semester, ap.dbegin, ap.dend, ap.code;
CREATE OR REPLACE VIEW vSubscription AS CREATE OR REPLACE VIEW vsubscription AS
SELECT ap.*, TO_CHAR(su.subdate,'DD/MM/YYYY') AS subdate, su.utclogin SELECT ap.*, TO_CHAR(su.subdate,'DD/MM/YYYY') AS subdate, su.utclogin
FROM subscribe su JOIN vApi ap ON ap.code=su.api FROM subscribe su JOIN vApi ap ON ap.code=su.api
ORDER BY ap.year, ap.semester, ap.dbegin, ap.dend, ap.code, su.utclogin; ORDER BY ap.year, ap.semester, ap.dbegin, ap.dend, ap.code, su.utclogin;
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