Commit 092297a1 authored by Rémy Huet's avatar Rémy Huet 💻

Separate database management from views

parent 9c4e11c1
......@@ -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']);
?>
......@@ -13,59 +13,26 @@ 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) {
function subList(string $utclogin) : array {
$sql = "SELECT *
FROM vsubscription
WHERE utclogin='".$utclogin."'";
$st = $this->conn->prepare($sql);
$st->execute();
$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) {
function apiList(string $semester, int $year) : array {
$sql = "SELECT *
FROM vApi
WHERE semester='".$semester."' AND year=".$year;
$st = $this->conn->prepare($sql);
$st->execute();
$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) {
......
<?php
class Views {
public static function printHtmlBegin() : void {
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>';
}
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