commit 9adb7e510bb607b0301d552fd479cbdd5d60f014
parent 021ead60bfa23b1ba7e3b12c6b65817fc9c54f67
Author: MoiBaguette <[email protected]>
Date: Sat, 24 Jun 2023 13:49:19 +0200
Merge branch 'master' of https://github.com/friedelschoen/lollipop
Diffstat:
M | index.php | | | 238 | ++++++++++++------------------------------------------------------------------- |
A | routing/course.php | | | 88 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | routing/index.php | | | 32 | ++++++++++++++++++++++++++++++++ |
A | routing/user.php | | | 88 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 files changed, 242 insertions(+), 204 deletions(-)
diff --git a/index.php b/index.php
@@ -1,223 +1,53 @@
<?php
require_once "utils/autoloader.php";
+require_once "routing/index.php";
+require_once "routing/user.php";
+require_once "routing/course.php";
+
$templater = new Lollipop\Template();
$router = new Lollipop\Router($templater);
$db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "lollipop");
-$router->addRoute(["GET"], "/", function(&$vars){
- global $db;
- $vars["login-fields"] = $db->get(Model\User::class)->login_fields();
- return "views/login.html";
-});
-
-$router->addRoute(["POST"], "/", function(&$vars){
- global $db;
- $res = $db->get(Model\User::class)->login();
- if($res == []){
- header("Location: dashboard");
- exit();
- }else{
- $vars["login-fields"] = $db->get(Model\User::class)->login_fields();
- $vars["response"] = $res["response"] ;
- return "views/login.html";
- }
-});
-
session_start();
-if(isset($_SESSION['user_permissions']) && in_array(1, $_SESSION['user_permissions'])){
+/*if(isset($_SESSION['user_permissions']) && in_array(1, $_SESSION['user_permissions'])){
echo "permission dingen";
foreach($_SESSION as $tmp){
echo $tmp;
}
-}
-
-$router->addRoute(["GET"], "/dashboard", function(&$vars){
- $vars += $_SESSION;
- return "views/dashboard.html";
-});
-
-$router->addRoute(["GET"], "/user", function(&$vars){
- global $db;
- $user = $db->get(Model\User::class);
- $templates = new controller\templates($db, $user);
-
- if(isset($_POST["search"])){
- $user->load($_POST["search"]);
- $data = $user->getData();
- }
- $vars["form"] = $templates->form("/user");
- $vars["search"] = $templates->search_form("/user/search");
- $vars["table"] = $templates->crud_table("/user", "" ,"email");
- return "views/user.html";
-});
-
-$router->addRoute(["GET"], "/user/search/:search_query", function(&$vars){
- global $db;
- $user = $db->get(Model\User::class);
- $templates = new controller\templates($db, $user);
- $vars["form"] = $templates->form("/user");
- $vars["search"] = $templates->search_form("/user/search");
- $vars["table"] = $templates->crud_table("/user", $vars["search_query"], "email");
- return "views/user.html";
-});
-
-$router->addRoute(["POST"], "/user/search", function(&$vars){
- if(isset($_POST['search'])){
- if($_POST['search'] == ""){
- $search = "%";
- }else{
- $search = $_POST['search'];
- }
- $header = '/user/search/' . $search;
- header('Location: ' . $header);
- }else{
- echo "wtF?";
- var_dump($_POST);
- }
-});
-
-$router->addRoute(["GET"], "/user/:primary_key/edit", function(&$vars){
- global $db;
- $user = $db->get(Model\User::class);
- $templates = new controller\templates($db, $user);
- $data = [];
- $user->load($vars["primary_key"]);
- foreach($user->getData() as $key => $col){
- $data[$key] = $col;
- }
- $vars["form"] = $templates->form("/user", $data);
- $vars["search"] = $templates->search_form("/user/search");
- $vars["table"] = $templates->crud_table("/user", "", "email");
- return "views/user.html";
-});
-
-$router->addRoute(["GET"], "/user/:primary_key/delete", function(&$vars){
- global $db;
- $user = $db->get(Model\User::class);
- $templates = new controller\templates($db, $user);
- $user->load($vars["primary_key"]);
- $user->delete();
- $vars["form"] = $templates->form("/user");
- $vars["search"] = $templates->search_form("/user");
- $vars["table"] = $templates->crud_table("/user" ,"", "email");
- return "views/user.html";
-});
-
-$router->addRoute(["POST"], "/user", function(&$vars){
- global $db;
- $user = $db->get(Model\User::class);
- $templates = new controller\templates($db, $user);
- $data = [];
-
- if(isset($_POST["form_type"])){
- if($_POST["form_type"] == 'Add')
- $user->add_user();
- elseif($_POST["form_type"] == 'Update'){
- $user->update_user();
- }
- }
+}*/
- $vars["form"] = $templates->form("/user", $data);
- $vars["search"] = $templates->search_form("/user");
- $vars["table"] = $templates->crud_table("/user", "", "email");
- return "views/user.html";
-});
-
-
-$router->addRoute(["POST"], "/logout", function(&$vars){
- session_unset();
- session_destroy();
- header("Location: /");
-});
-
-$router->addRoute(["GET"], "/course", function(&$vars){
- global $db;
- $course = $db->get(Model\Course::class);
- $templates = new controller\templates($db, $course);
- var_dump($course->get_col_info());
-
- $vars["form"] = $templates->form_v2("/course");
- $vars["search"] = $templates->search_form("/course/search");
- $vars["table"] = $templates->crud_table("/course", "" ,"name");
- return "views/course.html";
-});
-
-$router->addRoute(["GET"], "/course/search/:search_query", function(&$vars){
- global $db;
- $course = $db->get(Model\Course::class);
- $templates = new controller\templates($db, $course);
- $vars["form"] = $templates->form_v2("/course");
- $vars["search"] = $templates->search_form("/course/search");
- $vars["table"] = $templates->crud_table("/course", $vars["search_query"], "name");
- return "views/course.html";
-});
-
-$router->addRoute(["POST"], "/course/search", function(&$vars){
- if(isset($_POST['search'])){
- if($_POST['search'] == ""){
- $search = "%";
- }else{
- $search = $_POST['search'];
- }
- $header = '/course/search/' . $search;
- header('Location: ' . $header);
- }else{
- echo "wtF?";
- var_dump($_POST);
- }
-});
-$router->addRoute(["GET"], "/course/:primary_key/edit", function(&$vars){
- global $db;
- $course = $db->get(Model\Course::class);
- $templates = new controller\templates($db, $course);
- $data = [];
+$router->addRoute(["GET"], "/", $index_get);
- $course->load($vars["primary_key"]);
- foreach($course->getData() as $key => $col){
- $data[$key] = $col;
- }
- $vars["form"] = $templates->form_v2("/course", $data);
- $vars["search"] = $templates->search_form("/course/search");
- $vars["table"] = $templates->crud_table("/course", "", "name");
- return "views/course.html";
-});
-
-$router->addRoute(["GET"], "/course/:primary_key/delete", function(&$vars){
- global $db;
- $course = $db->get(Model\Course::class);
- $templates = new controller\templates($db, $course);
- $course->load($vars["primary_key"]);
- $course->delete();
-
- $vars["form"] = $templates->form_v2("/course");
- $vars["search"] = $templates->search_form("/course");
- $vars["table"] = $templates->crud_table("/course" ,"", "name");
- return "views/course.html";
-});
-
-$router->addRoute(["POST"], "/course", function(&$vars){
- global $db;
- $course = $db->get(Model\Course::class);
- $templates = new controller\templates($db, $course);
- $data = [];
- if(isset($_POST["form_type"])){
- if($_POST["form_type"] == 'Add'){
- $course->add_course();
- echo "add 'em";
- }
- elseif($_POST["form_type"] == 'Update'){
- echo "update 'em";
- $course->update_course();
- }
- }
+$router->addRoute(["POST"], "/", $index_post);
+
+$router->addRoute(["GET"], "/dashboard", $dashboard);
+
+$router->addRoute(["GET"], "/user", $user_get);
+
+$router->addRoute(["POST"], "/user", $user_post);
+
+$router->addRoute(["GET"], "/user/search/:search_query", $user_query);
+
+$router->addRoute(["POST"], "/user/search", $user_search);
+
+$router->addRoute(["GET"], "/user/:primary_key/edit", $user_edit);
+
+$router->addRoute(["GET"], "/user/:primary_key/delete", $user_delete);
+
+$router->addRoute(["POST"], "/logout", $logout);
+
+$router->addRoute(["GET"], "/course", $course_get);
+
+$router->addRoute(["POST"], "/course", $course_post);
+
+$router->addRoute(["GET"], "/course/search/:search_query", $course_query);
+
+$router->addRoute(["POST"], "/course/search", $course_search);
- $vars["form"] = $templates->form_v2("/course", $data);
- $vars["search"] = $templates->search_form("/course");
- $vars["table"] = $templates->crud_table("/course", "", "name");
- return "views/course.html";
-});
+$router->addRoute(["GET"], "/course/:primary_key/edit", $course_edit);
+$router->addRoute(["GET"], "/course/:primary_key/delete", $course_delete);
$router->route();
diff --git a/routing/course.php b/routing/course.php
@@ -0,0 +1,88 @@
+<?php
+
+$course_get = function(&$vars){
+ global $db;
+ $course = $db->get(Model\Course::class);
+ $templates = new controller\templates($db, $course);
+
+ if(isset($_POST["search"])){
+ $course->load($_POST["search"]);
+ $data = $course->getData();
+ }
+ $vars["form"] = $templates->form("/course");
+ $vars["search"] = $templates->search_form("/course/search");
+ $vars["table"] = $templates->crud_table("/course", "" ,"name");
+ return "views/course.html";
+};
+
+$course_post = function(&$vars){
+ global $db;
+ $course = $db->get(Model\Course::class);
+ $templates = new controller\templates($db, $course);
+ $data = [];
+
+ if(isset($_POST["form_type"])){
+ if($_POST["form_type"] == 'Add')
+ $course->add_course();
+ elseif($_POST["form_type"] == 'Update'){
+ $course->update_course();
+ }
+ }
+
+ $vars["form"] = $templates->form("/course", $data);
+ $vars["search"] = $templates->search_form("/course");
+ $vars["table"] = $templates->crud_table("/course", "", "name");
+ return "views/course.html";
+};
+
+$course_query = function(&$vars){
+ global $db;
+ $course = $db->get(Model\Course::class);
+ $templates = new controller\templates($db, $course);
+ $vars["form"] = $templates->form("/course");
+ $vars["search"] = $templates->search_form("/course/search");
+ $vars["table"] = $templates->crud_table("/course", $vars["search_query"], "name");
+ return "views/course.html";
+};
+
+$course_search = function(&$vars){
+ if(isset($_POST['search'])){
+ if($_POST['search'] == ""){
+ $search = "%";
+ }else{
+ $search = $_POST['search'];
+ }
+ $header = '/course/search/' . $search;
+ header('Location: ' . $header);
+ }else{
+ echo "wtF?";
+ var_dump($_POST);
+ }
+};
+
+$course_edit = function(&$vars){
+ global $db;
+ $course = $db->get(Model\Course::class);
+ $templates = new controller\templates($db, $course);
+ $data = [];
+ $course->load($vars["primary_key"]);
+ foreach($course->getData() as $key => $col){
+ $data[$key] = $col;
+ }
+ $vars["form"] = $templates->form("/course", $data);
+ $vars["search"] = $templates->search_form("/course/search");
+ $vars["table"] = $templates->crud_table("/course", "", "name");
+ return "views/course.html";
+};
+
+$course_delete = function(&$vars){
+ global $db;
+ $course = $db->get(Model\Course::class);
+ $templates = new controller\templates($db, $course);
+ $course->load($vars["primary_key"]);
+ $course->delete();
+ $vars["form"] = $templates->form("/course");
+ $vars["search"] = $templates->search_form("/course");
+ $vars["table"] = $templates->crud_table("/course" ,"", "name");
+ return "views/course.html";
+};
diff --git a/routing/index.php b/routing/index.php
@@ -0,0 +1,31 @@
+<?php
+
+$index_get = function(&$vars){
+ global $db;
+ $vars["login-fields"] = $db->get(Model\User::class)->login_fields();
+ return "views/login.html";
+};
+
+$index_post = function(&$vars){
+ global $db;
+ $res = $db->get(Model\User::class)->login();
+ if($res == []){
+ header("Location: dashboard");
+ exit();
+ }else{
+ $vars["login-fields"] = $db->get(Model\User::class)->login_fields();
+ $vars["response"] = $res["response"] ;
+ return "views/login.html";
+ }
+};
+
+$dashboard = function(&$vars){
+ $vars += $_SESSION;
+ return "views/dashboard.html";
+};
+
+$logout = function(&$vars){
+ session_unset();
+ session_destroy();
+ header("Location: /");
+};
+\ No newline at end of file
diff --git a/routing/user.php b/routing/user.php
@@ -0,0 +1,88 @@
+<?php
+
+$user_get = function(&$vars){
+ global $db;
+ $user = $db->get(Model\User::class);
+ $templates = new controller\templates($db, $user);
+
+ if(isset($_POST["search"])){
+ $user->load($_POST["search"]);
+ $data = $user->getData();
+ }
+ $vars["form"] = $templates->form("/user");
+ $vars["search"] = $templates->search_form("/user/search");
+ $vars["table"] = $templates->crud_table("/user", "" ,"email");
+ return "views/user.html";
+};
+
+$user_post = function(&$vars){
+ global $db;
+ $user = $db->get(Model\User::class);
+ $templates = new controller\templates($db, $user);
+ $data = [];
+
+ if(isset($_POST["form_type"])){
+ if($_POST["form_type"] == 'Add')
+ $user->add_user();
+ elseif($_POST["form_type"] == 'Update'){
+ $user->update_user();
+ }
+ }
+
+ $vars["form"] = $templates->form("/user", $data);
+ $vars["search"] = $templates->search_form("/user");
+ $vars["table"] = $templates->crud_table("/user", "", "email");
+ return "views/user.html";
+};
+
+$user_query = function(&$vars){
+ global $db;
+ $user = $db->get(Model\User::class);
+ $templates = new controller\templates($db, $user);
+ $vars["form"] = $templates->form("/user");
+ $vars["search"] = $templates->search_form("/user/search");
+ $vars["table"] = $templates->crud_table("/user", $vars["search_query"], "email");
+ return "views/user.html";
+};
+
+$user_search = function(&$vars){
+ if(isset($_POST['search'])){
+ if($_POST['search'] == ""){
+ $search = "%";
+ }else{
+ $search = $_POST['search'];
+ }
+ $header = '/user/search/' . $search;
+ header('Location: ' . $header);
+ }else{
+ echo "wtF?";
+ var_dump($_POST);
+ }
+};
+
+$user_edit = function(&$vars){
+ global $db;
+ $user = $db->get(Model\User::class);
+ $templates = new controller\templates($db, $user);
+ $data = [];
+ $user->load($vars["primary_key"]);
+ foreach($user->getData() as $key => $col){
+ $data[$key] = $col;
+ }
+ $vars["form"] = $templates->form("/user", $data);
+ $vars["search"] = $templates->search_form("/user/search");
+ $vars["table"] = $templates->crud_table("/user", "", "email");
+ return "views/user.html";
+};
+
+$user_delete = function(&$vars){
+ global $db;
+ $user = $db->get(Model\User::class);
+ $templates = new controller\templates($db, $user);
+ $user->load($vars["primary_key"]);
+ $user->delete();
+ $vars["form"] = $templates->form("/user");
+ $vars["search"] = $templates->search_form("/user");
+ $vars["table"] = $templates->crud_table("/user" ,"", "email");
+ return "views/user.html";
+};