Commit ad91ebfb authored by Stephane Crozat's avatar Stephane Crozat

Affichage des noms des inscrits pour le Respapi

parent 33b364a7
<?php
session_start();
$DEVMODE = True;
if (!$DEVMODE && !isset($_SESSION['ticket'])) {
if (!isset($_SESSION['ticket'])) {
/* If session is already open for current PHP file, user is already logged in, do nothing
If session is not open on current PHP file, check if it is open on CAS server
If it is open on CAS server retrieve session informations
......@@ -25,23 +23,16 @@ if (!$DEVMODE && !isset($_SESSION['ticket'])) {
}
$_SESSION['localcopy'] = true; //call localcopy once per session
}
else {
$_SESSION['ticket'] = '-1';
$_SESSION['utclogin'] = 'crozatst';
$_SESSION['mail'] = 'dev@mail.fr';
$_SESSION['surname'] = 'Crozat/dev';
$_SESSION['firstname'] = 'Stéphane/dev';
}
include 'lib/db.php';
include 'lib/views.php';
include 'lib/admin.php';
$db = new DB();
if ($_SESSION['localcopy']) {
//if ($_SESSION['localcopy']) {
$db->copyUser($_SESSION['utclogin'], $_SESSION['surname'], $_SESSION['firstname'], $_SESSION['mail']);
$_SESSION['localcopy']=false;
}
//}
$admin = new Admin($db);
$view = new Views($admin, $_SESSION['utclogin'], $_SESSION['surname'], $_SESSION['firstname']);
......
......@@ -79,25 +79,29 @@ class DB {
}
public function copyUser($utclogin, $surname, $firstname, $email) {
// Function used to create a local copy of surname and firstname of each user, in order to link to DFP files without utclogin
// Function used to create a local copy of each user, in order to use data directly in database
$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, email) VALUES (:utclogin, :firstname, :surname, :email)';
$sql = 'INSERT INTO localuser(utclogin) VALUES (:utclogin)';
$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);
$st2->bindValue(':email',$email,PDO::PARAM_STR);
$res = $st2->execute();
return $res;
}
else {
return 0;
}
// Update data in any case
$sql = 'UPDATE localuser
SET firstname=:firstname, surname=:surname, email=:email
WHERE utclogin=:utclogin';
$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);
$st2->bindValue(':email',$email,PDO::PARAM_STR);
$res = $st2->execute();
return $res;
}
/** Returns T is subscriptions and unsubscription are allowed **/
......
......@@ -58,6 +58,15 @@ class Views {
return "$row[year] Semaine $row[week]";
}
private function printStudent($row) {
if (!$row['surname']) {
return "$row[utclogin]";
}
else {
return "$row[firstname] $row[surname] ($row[email])";
}
}
public function printSubList($list) {
#KNOWN_BUB #TODO Il est possible de ses déinscrire en utilisant directement l'URL
if ($list) {
......@@ -125,16 +134,17 @@ class Views {
foreach ($listsub as $sub) {
if ($api != $sub['id']) {
$api = $sub['id'];
echo "<h2>$sub[normcode] $sub[name] (Semaine $sub[week])</h2>";
echo '<h2>'.$this->printWeek($sub).'</h2>';
echo '<h3>'.$this->printApi($sub).'</h3>';
}
if ($sub['utclogin']) {
if ($sub['validation']) {
// Subscription already validated
echo "<p><b>[validé]</b> $sub[utclogin]</p>";
echo '<p><b>[validé] </b>'.$this->printStudent($sub).'</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>";
echo "<p> <a href='index.php?action=validate&api=$sub[id]&login=$sub[utclogin]&mode=resp'>[valider]</a> ".$this->printStudent($sub)."</p>";
}
else {
// validation = FALSE lignes ignored
......
......@@ -32,11 +32,8 @@ FROM api LEFT JOIN vapi_subcount ON id=subcountid LEFT JOIN vapi_valcount ON id=
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,
CASE WHEN COUNT(*)>1 THEN 'duplication' END AS warning
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;
SELECT *
FROM localuser;
CREATE OR REPLACE VIEW vsubscription AS
SELECT
......
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