diff --git a/index.php b/index.php index f46553f2dd4326e89192cae101c3f560cc016414..b2ea5be8254d25584c4853a1e390647a12349629 100644 --- a/index.php +++ b/index.php @@ -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']); ?> diff --git a/lib/db.php b/lib/db.php index e5bce0c4ea819a43eee3e37e115b4c6acec02234..09dceb0e966cc8a7089ebabaf5be8c39b0ec78e7 100644 --- a/lib/db.php +++ b/lib/db.php @@ -13,59 +13,26 @@ class DB { } } - public function printHtmlBegin () { - echo ''; - echo ''; - echo 'Api Sub'; - echo ''; - echo ''; - echo '

Inscriptions Api

'; - } - - function printUser($utclogin, $surname, $firstname) { - echo '

'.$firstname.' '. $surname.' ('.$utclogin.')

'; - } - - 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 '

Vos inscriptions

'; - foreach ($res as $row) { - echo '

'; - echo ' [désinscription] '; - echo $row['code']."-".$row['name']." (".$row['semester'].$row['year'].", du ".$row['dbegin']." au ".$row['dend'].") [inscrit le ".$row['subdate']."]"; - echo '

'; - } - } - else { - echo '

Aucune inscription

'; - } + + 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 '

Liste des Api '.$semester.$year.'

'; - foreach ($res as $row) { - echo '

'; - echo '[inscription] '; - echo $row['code']."-".$row['name']; - echo '

'; - } - } - else { - echo '

Aucune Api

'; - } + + return $res; } function subToApi($utclogin, $api) { diff --git a/lib/views.php b/lib/views.php new file mode 100644 index 0000000000000000000000000000000000000000..7f3c6494fde07b487379a71aa0c4940e7cb825bb --- /dev/null +++ b/lib/views.php @@ -0,0 +1,47 @@ +'; + echo ''; + echo 'Api Sub'; + echo ''; + echo ''; + echo '

Inscriptions Api

'; + } + + public static function printUser(string $utclogin, string $surname, string $firstname) : void { + echo '

'.$firstname.' '. $surname.' ('.$utclogin.')

'; + } + + public static function printSubList(array $list, string $utclogin) : void { + if ($list) { + echo '

Vos inscriptions

'; + foreach ($list as $row) { + echo '

'; + echo ' [désinscription] '; + echo $row['code']."-".$row['name']." (".$row['semester'].$row['year'].", du ".$row['dbegin']." au ".$row['dend'].") [inscrit le ".$row['subdate']."]"; + echo '

'; + } + } + else { + echo '

Aucune inscription

'; + } + } + + public static function printApiList(array $list, string $utclogin) : void { + if ($list) { + echo '

Liste des Api '.$semester.$year.'

'; + foreach ($list as $row) { + echo '

'; + echo '[inscription] '; + echo $row['code']."-".$row['name']; + echo '

'; + } + } + else { + echo '

Aucune Api

'; + } + } +} \ No newline at end of file