Commit 6e4ec8e4 authored by Stephane Crozat's avatar Stephane Crozat

Merge remote-tracking branch 'origin/dev-remy'

parents 8734afdc 743643e1
......@@ -23,9 +23,11 @@ if (!isset($_SESSION['ticket'])) {
}
include $_SERVER['DOCUMENT_ROOT'].'/apisub/lib/db.php';
include 'lib/views.php';
$db = new DB();
$db->printHtmlBegin();
$db->printUser($_SESSION['utclogin'], $_SESSION['surname'], $_SESSION['firstname']);
Views::printHtmlBegin();
Views::printUser($_SESSION['utclogin'], $_SESSION['surname'], $_SESSION['firstname']);
if (isset($_GET['api']) && isset($_GET['utclogin'])) {
if (isset($_GET['action'])) {
......@@ -38,7 +40,7 @@ if (isset($_GET['api']) && isset($_GET['utclogin'])) {
}
}
$db->subList($_SESSION['utclogin']);
$db->apiList($_SESSION['utclogin'], 'H', 2019);
Views::printSubList($db->subList($_SESSION['utclogin']), $_SESSION['utclogin']);
Views::printApiList($db->apiList('H', 2019), $_SESSION['utclogin']);
?>
......@@ -4,7 +4,7 @@ class DB {
private $conn;
function __construct () {
public function __construct () {
include 'connexion.php';
try {
$this->conn = new PDO('pgsql:host=localhost;port=5432;dbname=apisub', $db_user, $db_pass);
......@@ -13,71 +13,54 @@ class DB {
}
}
public function printHtmlBegin () {
echo '<html>';
echo '<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head>';
echo '<title>Api Sub</title>';
echo '<link href="css/main.css" type="text/css" rel="stylesheet"/>';
echo '<body>';
echo '<h1>Inscriptions Api</h1>';
}
function printUser($utclogin, $surname, $firstname) {
echo '<p><i>'.$firstname.' '. $surname.'</i> (<b>'.$utclogin.'</b>)</p>';
}
function subList($utclogin) {
$sql = "SELECT *
public function subList(string $utclogin) : array {
$sql = 'SELECT *
FROM vsubscription
WHERE utclogin='".$utclogin."'";
WHERE utclogin=:utclogin';
$st = $this->conn->prepare($sql);
$st->execute();
$st->execute([
'utclogin' => $utclogin,
]);
$res = $st->fetchAll(PDO::FETCH_ASSOC);
if ($res) {
echo '<h2>Vos inscriptions</h2>';
foreach ($res as $row) {
echo '<p>';
echo ' <a href="index.php?action=unsub&api='.$row['code'].'&utclogin='.$utclogin.'">[désinscription]</a> ';
echo $row['code']."-".$row['name']." (".$row['semester'].$row['year'].", du ".$row['dbegin']." au ".$row['dend'].") [inscrit le ".$row['subdate']."]";
echo '</p>';
}
}
else {
echo '<h2>Aucune inscription</h2>';
}
return $res;
}
function apiList($utclogin, $semester, $year) {
$sql = "SELECT *
public function apiList(string $semester, int $year) : array {
$sql = 'SELECT *
FROM vApi
WHERE semester='".$semester."' AND year=".$year;
WHERE semester=:semester AND year=:year';
$st = $this->conn->prepare($sql);
$st->execute();
$st->execute([
'semester' => $semester,
'year' => $year,
]);
$res = $st->fetchAll(PDO::FETCH_ASSOC);
if ($res) {
echo '<h2>Liste des Api '.$semester.$year.'</h2>';
foreach ($res as $row) {
echo '<p>';
echo '<a href="index.php?action=sub&api='.$row['code'].'&utclogin='.$utclogin.'">[inscription]</a> ';
echo $row['code']."-".$row['name'];
echo '</p>';
}
}
else {
echo '<h2>Aucune Api</h2>';
}
return $res;
}
function subToApi($utclogin, $api) {
$today = date("Ymd");
$sql = "INSERT INTO subscribe VALUES ('".$utclogin."',".$api.",TO_DATE('".$today."','YYYYMMDD'))";
$res=$this->conn->exec($sql);
}
public function subToApi(string $utclogin, int $api) : bool {
$today = date('Ymd');
$sql = 'INSERT INTO subscribe(utclogin, api, subdate) VALUES (:utclogin, :api, :today)';
$st = $this->conn->prepare($sql);
$res = $st->execute([
'utclogin' => $utclogin,
'api' => $api,
'today' => $today,
]);
function unsubToApi($utclogin, $api) {
$sql = "DELETE FROM subscribe WHERE utclogin='".$utclogin."' AND api=".$api;
$res=$this->conn->exec($sql);
return $res;
}
public function unsubToApi(string $utclogin, int $api) : bool {
$sql = 'DELETE FROM subscribe WHERE utclogin=:utclogin AND api=:api';
$st = $this->conn->prepare($sql);
$res = $st->execute([
'utclogin' => $utclogin,
'api' => $api,
]);
return $res;
}
}
<?php
class Views {
public static function printHtmlBegin() : void {
echo '<html>';
echo '<head>';
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>';
echo '<title>Api Sub</title>';
echo '<link href="css/main.css" type="text/css" rel="stylesheet"/>';
echo '</head>';
echo '<body>';
echo '<h1>Inscriptions Api</h1>';
}
public static function printUser(string $utclogin, string $surname, string $firstname) : void {
echo '<p><i>'.$firstname.' '. $surname.'</i> (<b>'.$utclogin.'</b>)</p>';
}
public static function printSubList(array $list, string $utclogin) : void {
if ($list) {
echo '<h2>Vos inscriptions</h2>';
foreach ($list as $row) {
echo '<p>';
echo ' <a href="index.php?action=unsub&api='.$row['code'].'&utclogin='.$utclogin.'">[désinscription]</a> ';
echo $row['code'].'-'.$row['name'].' ('.$row['semester'].$row['year'].', du '.$row['dbegin'].' au '.$row['dend'].') [inscrit le '.$row['subdate'].']';
echo '</p>';
}
}
else {
echo '<h2>Aucune inscription</h2>';
}
}
public static function printApiList(array $list, string $utclogin) : void {
if ($list) {
echo '<h2>Liste des Api '.$semester.$year.'</h2>';
foreach ($list as $row) {
echo '<p>';
echo '<a href="index.php?action=sub&api='.$row['code'].'&utclogin='.$utclogin.'">[inscription]</a> ';
echo $row['code'].'-'.$row['name'];
echo '</p>';
}
}
else {
echo '<h2>Aucune Api</h2>';
}
}
}
\ No newline at end of file
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