commit 1caf86a203188f4e13dbf5ea51f696ce254ff724
parent 294b50809b4783c9a62ab922e319040ae7ac1334
Author: Friedel Schön <[email protected]>
Date: Sun, 25 Jun 2023 22:01:15 +0200
adding disenroll/enroll
Diffstat:
5 files changed, 56 insertions(+), 9 deletions(-)
diff --git a/Lollipop/Router.php b/Lollipop/Router.php
@@ -94,9 +94,10 @@ namespace Lollipop {
if ($this->match($route["match"], $vars)) {
if (is_callable($route["func"])) {
$fil = $route["func"]($vars);
- if (!is_null($fil)) {
- $this->set_mime($fil);
+ if (is_null($fil)) {
+ return;
}
+ $this->set_mime($fil);
echo $this->temp->template($fil, $vars);
return;
} else {
@@ -108,6 +109,7 @@ namespace Lollipop {
}
echo "404 '$this->path' not found!";
+ header("Location: /");
return null;
}
}
diff --git a/index.php b/index.php
@@ -34,6 +34,10 @@ if(isset($_SESSION['user_permissions'])) {
$router->addRoute(["GET"], "/user/:primary_key", $user_page);
$router->addRoute(["GET"], "/dashboard", $dashboard);
+
+ $router->addRoute(["GET"], "/course/:primary_key/enroll", $course_enroll);
+
+ $router->addRoute(["GET"], "/course/:primary_key/disenroll", $course_disenroll);
}
if(in_array(2, $_SESSION['user_permissions']) || in_array(3, $_SESSION['user_permissions'])) {
@@ -50,7 +54,7 @@ if(isset($_SESSION['user_permissions'])) {
$router->addRoute(["GET"], "/course/:primary_key/edit", $course_edit);
$router->addRoute(["GET"], "/course/:primary_key/delete", $course_delete);
-
+
$router->addRoute(["GET"], "/exam", $exam_get);
$router->addRoute(["GET"], "/exam/:exam", $exam_data);
@@ -96,4 +100,4 @@ if(isset($_SESSION['user_permissions'])) {
}
}
-$router->route()
-\ No newline at end of file
+$router->route();
+\ No newline at end of file
diff --git a/readme.md b/readme.md
@@ -0,0 +1,17 @@
+Er zijn 3 test-accounts:
+
+| Username | Wachtwoord | Function |
+| ---------------- | ---------- | -------- |
+| [email protected] | test | admin |
+| [email protected] | test | student |
+| [email protected] | test | docent |
+
+Endpoints zijn gedefineerd in index.php
+
+Het makkelijks is, om alles te bekijken om een locale server te draaien met:
+
+```shell
+$ php -S localhost:9000 index.php
+```
+
+> :warning: Je moet de index.php achter zetten, anders doet het de rewrite (routing) niet goed!
+\ No newline at end of file
diff --git a/routing/course.php b/routing/course.php
@@ -107,3 +107,25 @@ $course_data = function (&$vars) {
$vars['table'] = $table;
return "views/parent_child.html";
};
+
+$course_enroll = function(&$vars) {
+ global $db;
+
+ $courseuser = $db->get(Model\CourseUser::class);
+ $courseuser->id = $vars['primary_key'];
+ $courseuser->email = $_SESSION['email'];
+ $courseuser->add();
+
+ header('Location: /dashboard');
+};
+
+$course_disenroll = function(&$vars) {
+ global $db;
+
+ $courseuser = $db->get(Model\CourseUser::class);
+ $courseuser->id = $vars['primary_key'];
+ $courseuser->email = $_SESSION['email'];
+ $courseuser->delete();
+
+ header('Location: /dashboard');
+};
+\ No newline at end of file
diff --git a/routing/index.php b/routing/index.php
@@ -50,11 +50,11 @@ $dashboard = function (&$vars) {
$table .= "<tbody>";
foreach($objs as $obj) {
if (in_array($obj->id, $enrolled)) {
- $enroll_btn = 'Enroll';
- $enroll_action = 'enroll';
- } else {
$enroll_btn = 'Disenroll';
$enroll_action = 'disenroll';
+ } else {
+ $enroll_btn = 'Enroll';
+ $enroll_action = 'enroll';
}
$table .= "<tr>";
@@ -64,7 +64,7 @@ $dashboard = function (&$vars) {
}
$table .= '
<td>
- <a class="edit" href="/user/'. $_SESSION['email'] . '/course/' . $obj->id . '/' . $enroll_action . '/";>' . $enroll_btn . '</a>
+ <a class="edit" href="/course/' . $obj->id . '/' . $enroll_action . '/";>' . $enroll_btn . '</a>
</td>';
$table .= '</tr>';