commit 35c29a1f65db120ec54f0874d714fb02deb27990
parent 4ca069a831bc926120c6007345d38d72ac57dbc8
Author: MoiBaguette <[email protected]>
Date: Sun, 25 Jun 2023 16:27:50 +0200
pages + routes for course, user, exam and grade. Databases foreign key updated. Foreign key contstraints added to post
Diffstat:
20 files changed, 501 insertions(+), 46 deletions(-)
diff --git a/Lollipop/DatabaseObject.php b/Lollipop/DatabaseObject.php
@@ -25,7 +25,6 @@ namespace Lollipop {
abstract static function get_primary(): string;
abstract static function get_table(): string;
abstract static function get_schema():string;
-
public function setData($data)
{
$this->data = $data;
@@ -267,6 +266,8 @@ namespace Lollipop {
$column_names[$tmp["column_name"]]["input_type"] = "date";
}elseif(str_contains($tmp['data_type'], "int")){
$column_names[$tmp["column_name"]]["input_type"] = "number";
+ }elseif(str_contains($tmp['data_type'], "double")){
+ $column_names[$tmp["column_name"]]["input_type"] = "number";
}
if(str_contains($tmp['extra'], "auto_increment")){
$column_names[$tmp["column_name"]]['extra'] = "auto_increment";
diff --git a/Model/Course.php b/Model/Course.php
@@ -43,6 +43,5 @@ use Lollipop\Utils;
}
return false;
}
-
}
}
\ No newline at end of file
diff --git a/Model/Exam.php b/Model/Exam.php
@@ -1,7 +1,7 @@
<?php
-
namespace Model {
- class User extends \Lollipop\DatabaseObject
+ use Lollipop\Utils;
+ class Exam extends \Lollipop\DatabaseObject
{
static function get_table(): string
{
@@ -16,5 +16,29 @@ namespace Model {
{
return "lollipop";
}
+ public function add_exam():bool{
+ $missing_fields = Utils::missing_fields($this->notNullable());
+ if(sizeof($missing_fields) == 0){
+ foreach($_POST as $key => $post){
+ if(in_array($key, $this->get_col_names_no_ai())){
+ $this->{$key} = $post;
+ }
+ }
+ return $this->add();
+ }
+ return false;
+ }
+ public function update_exam():bool{
+ $missing_fields = Utils::missing_fields($this->notNullable());
+ if(sizeof($missing_fields) == 0){
+ foreach($_POST as $key => $post){
+ if(in_array($key, $this->get_column_names())){
+ $this->{$key} = $post;
+ }
+ }
+ return $this->save();
+ }
+ return false;
+ }
}
}
\ No newline at end of file
diff --git a/Model/Grade.php b/Model/Grade.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Model {
+
+use Lollipop\Utils;
+ class Grade extends \Lollipop\DatabaseObject
+ {
+ static function get_table(): string
+ {
+ return "grade";
+ }
+
+ static function get_primary(): string
+ {
+ return "id";
+ }
+
+ static function get_schema(): string
+ {
+ return "lollipop";
+ }
+
+ public function add_grade():bool{
+ $missing_fields = Utils::missing_fields($this->notNullable());
+ if(sizeof($missing_fields) == 0){
+ foreach($_POST as $key => $post){
+ if(in_array($key, $this->get_col_names_no_ai())){
+ $this->{$key} = $post;
+ }
+ }
+ return $this->add();
+ }
+ return false;
+ }
+ public function update_grade():bool{
+ $missing_fields = Utils::missing_fields($this->notNullable());
+ if(sizeof($missing_fields) == 0){
+ foreach($_POST as $key => $post){
+ if(in_array($key, $this->get_column_names())){
+ $this->{$key} = $post;
+ }
+ }
+ return $this->save();
+ }
+ return false;
+ }
+
+ }
+}
+\ No newline at end of file
diff --git a/Model/Permission.php b/Model/Permission.php
@@ -18,7 +18,7 @@ namespace Model {
}
function get_checkboxes(): string{
$all_permissions = $this->db->all($this::class);
- $html = "";
+ $html = "<div class='check_this_box'>";
foreach($all_permissions as $permission){
$html .= '<input type="checkbox" id="'. $permission->name .'" name="permissions[]" value="'. $permission->id .'"';
if($permission->id == 0){
@@ -27,6 +27,7 @@ namespace Model {
$html .= '>';
$html .= '<label for="'. $permission->name .'">'. $permission->name .'</label>';
}
+ $html .= "</div>";
return $html;
}
}
diff --git a/index.php b/index.php
@@ -3,6 +3,8 @@ require_once "utils/autoloader.php";
require_once "routing/index.php";
require_once "routing/user.php";
require_once "routing/course.php";
+require_once "routing/exam.php";
+require_once "routing/grade.php";
$templater = new Lollipop\Template(new Lollipop\TemplateMethods());
$router = new Lollipop\Router($templater);
@@ -52,4 +54,28 @@ $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(["POST"], "/exam", $exam_post);
+
+$router->addRoute(["GET"], "/exam/search/:search_query", $exam_query);
+
+$router->addRoute(["POST"], "/exam/search", $exam_search);
+
+$router->addRoute(["GET"], "/exam/:primary_key/edit", $exam_edit);
+
+$router->addRoute(["GET"], "/exam/:primary_key/delete", $exam_delete);
+
+$router->addRoute(["GET"], "/grade", $grade_get);
+
+$router->addRoute(["POST"], "/grade", $grade_post);
+
+$router->addRoute(["GET"], "/grade/search/:search_query", $grade_query);
+
+$router->addRoute(["POST"], "/grade/search", $grade_search);
+
+$router->addRoute(["GET"], "/grade/:primary_key/edit", $grade_edit);
+
+$router->addRoute(["GET"], "/grade/:primary_key/delete", $grade_delete);
+
$router->route();
diff --git a/routing/course.php b/routing/course.php
@@ -17,18 +17,23 @@ $course_get = function(&$vars){
$course_post = function(&$vars){
global $db;
$course = $db->get(Model\Course::class);
+ $user = $db->get(Model\User::class);
$templates = new Controller\Templates($db, $course);
$data = [];
if(isset($_POST["form_type"])){
- if($_POST["form_type"] == 'Add'){
- if($course->add_course()){
- $vars["response"] = 'succesfully added: ' . $_POST["name"];
- }
- } elseif($_POST["form_type"] == 'Update'){
- if($course->update_course()){
- $vars["response"] = 'succesfully updated: ' . $_POST["name"];
+ if($user->load($_POST['lecturer'])){
+ if($_POST["form_type"] == 'Add'){
+ if($course->add_course()){
+ $vars["response"] = 'succesfully added: ' . $_POST["name"];
+ }
+ } elseif($_POST["form_type"] == 'Update'){
+ if($course->update_course()){
+ $vars["response"] = 'succesfully updated: ' . $_POST["name"];
+ }
}
+ }else{
+ $vars["response"] = 'foreign_key constraint on lecturer';
}
}
diff --git a/routing/exam.php b/routing/exam.php
@@ -0,0 +1,96 @@
+<?php
+$exam_get = function(&$vars){
+ global $db;
+ $exam = $db->get(Model\Exam::class);
+ $templates = new Controller\Templates($db, $exam);
+
+ if(isset($_POST["search"])){
+ $exam->load($_POST["search"]);
+ $data = $exam->getData();
+ }
+ $vars["form"] = $templates->form_v2("/exam");
+ $vars["search"] = $templates->search_form("/exam/search");
+ $vars["table"] = $templates->crud_table("/exam", "" ,"name");
+ return "views/exam.html";
+};
+
+$exam_post = function(&$vars){
+ global $db;
+ $exam = $db->get(Model\Exam::class);
+ $templates = new Controller\Templates($db, $exam);
+ $course = $db->get(Model\Course::class);
+ $data = [];
+ if(isset($_POST["form_type"])){
+ if($course->load($_POST['course'])){
+ if($_POST["form_type"] == 'Add'){
+ if($exam->add_exam()){
+ $vars["response"] = 'succesfully added: ' . $_POST["name"];
+ }
+ } elseif($_POST["form_type"] == 'Update'){
+ if($exam->update_exam()){
+ $vars["response"] = 'succesfully updated: ' . $_POST["name"];
+ }
+ }
+ }else{
+ $vars["response"] = 'foreign_key constraint on course';
+ }
+ }
+
+
+ $vars["form"] = $templates->form_v2("/exam", $data);
+ $vars["search"] = $templates->search_form("/exam");
+ $vars["table"] = $templates->crud_table("/exam", "", "name");
+ return "views/exam.html";
+};
+
+$exam_query = function(&$vars){
+ global $db;
+ $exam = $db->get(Model\Exam::class);
+ $templates = new controller\templates($db, $exam);
+ $vars["form"] = $templates->form_v2("/exam");
+ $vars["search"] = $templates->search_form("/exam/search");
+ $vars["table"] = $templates->crud_table("/exam", $vars["search_query"], "name");
+ return "views/exam.html";
+};
+
+$exam_search = function(&$vars){
+ if(isset($_POST['search'])){
+ if($_POST['search'] == ""){
+ $search = "%";
+ }else{
+ $search = $_POST['search'];
+ }
+ $header = '/exam/search/' . $search;
+ header('Location: ' . $header);
+ }else{
+ echo "wtF?";
+ var_dump($_POST);
+ }
+};
+
+$exam_edit = function(&$vars){
+ global $db;
+ $exam = $db->get(Model\Exam::class);
+ $templates = new Controller\Templates($db, $exam);
+ $data = [];
+ $exam->load($vars["primary_key"]);
+ foreach($exam->getData() as $key => $col){
+ $data[$key] = $col;
+ }
+ $vars["form"] = $templates->form_v2("/exam", $data);
+ $vars["search"] = $templates->search_form("/exam/search");
+ $vars["table"] = $templates->crud_table("/exam", "", "name");
+ return "views/exam.html";
+};
+
+$exam_delete = function(&$vars){
+ global $db;
+ $exam = $db->get(Model\Exam::class);
+ $templates = new Controller\Templates($db, $exam);
+ $exam->load($vars["primary_key"]);
+ $exam->delete();
+ $vars["form"] = $templates->form_v2("/exam");
+ $vars["search"] = $templates->search_form("/exam");
+ $vars["table"] = $templates->crud_table("/exam" ,"", "name");
+ return "views/exam.html";
+};
diff --git a/routing/grade.php b/routing/grade.php
@@ -0,0 +1,101 @@
+<?php
+$grade_get = function(&$vars){
+ global $db;
+ $grade = $db->get(Model\Grade::class);
+ $templates = new Controller\Templates($db, $grade);
+
+ if(isset($_POST["search"])){
+ $grade->load($_POST["search"]);
+ $data = $grade->getData();
+ }
+ $vars["form"] = $templates->form_v2("/grade");
+ $vars["search"] = $templates->search_form("/grade/search");
+ $vars["table"] = $templates->crud_table("/grade", "" ,"email");
+ return "views/grade.html";
+};
+
+$grade_post = function(&$vars){
+ global $db;
+ $grade = $db->get(Model\Grade::class);
+ $user = $db->get(Model\User::class);
+ $exam = $db->get(Model\Exam::class);
+ $templates = new Controller\Templates($db, $grade);
+ $data = [];
+
+ if($exam->load($_POST['exam'])){
+ if($user->load($_POST['email'])){
+ if(isset($_POST["form_type"])){
+ if($_POST["form_type"] == 'Add'){
+ if($grade->add_grade()){
+ $vars["response"] = 'succesfully added: ' . $_POST["email"];
+ }
+ } elseif($_POST["form_type"] == 'Update'){
+ if($grade->update_grade()){
+ $vars["response"] = 'succesfully updated: ' . $_POST["email"];
+ }
+ }
+ }
+ }else{
+ $vars["response"] = 'foreign_key constraint on email';
+ }
+ }else{
+ $vars["response"] = 'foreign_key constraint on exam';
+ }
+
+ $vars["form"] = $templates->form_v2("/grade", $data);
+ $vars["search"] = $templates->search_form("/grade");
+ $vars["table"] = $templates->crud_table("/grade", "", "email");
+ return "views/grade.html";
+};
+
+$grade_query = function(&$vars){
+ global $db;
+ $grade = $db->get(Model\Grade::class);
+ $templates = new controller\templates($db, $grade);
+ $vars["form"] = $templates->form_v2("/grade");
+ $vars["search"] = $templates->search_form("/grade/search");
+ $vars["table"] = $templates->crud_table("/grade", $vars["search_query"], "email");
+ return "views/grade.html";
+};
+
+$grade_search = function(&$vars){
+ if(isset($_POST['search'])){
+ if($_POST['search'] == ""){
+ $search = "%";
+ }else{
+ $search = $_POST['search'];
+ }
+ $header = '/grade/search/' . $search;
+ header('Location: ' . $header);
+ }else{
+ echo "wtF?";
+ var_dump($_POST);
+ }
+};
+
+$grade_edit = function(&$vars){
+ global $db;
+ $grade = $db->get(Model\Grade::class);
+ $templates = new Controller\Templates($db, $grade);
+ $data = [];
+ $grade->load($vars["primary_key"]);
+ foreach($grade->getData() as $key => $col){
+ $data[$key] = $col;
+ }
+ $vars["form"] = $templates->form_v2("/grade", $data);
+ $vars["search"] = $templates->search_form("/grade/search");
+ $vars["table"] = $templates->crud_table("/grade", "", "email");
+ return "views/grade.html";
+};
+
+$grade_delete = function(&$vars){
+ global $db;
+ $grade = $db->get(Model\Grade::class);
+ $templates = new Controller\Templates($db, $grade);
+ $grade->load($vars["primary_key"]);
+ $grade->delete();
+ $vars["form"] = $templates->form_v2("/grade");
+ $vars["search"] = $templates->search_form("/grade");
+ $vars["table"] = $templates->crud_table("/grade" ,"", "email");
+ return "views/grade.html";
+};
diff --git a/views/course.html b/views/course.html
@@ -9,17 +9,21 @@
<body>
<div class="flex_container">
<div class ="side_bar">
- <div class ="form_add">
+ <div class ="form_card">
{{$form}}
{{$response}}
</div>
</div>
<div class = "courses">
- <div class="search">
- {{$search}}
+ <div class ="form_card">
+ <div class="search">
+ {{$search}}
+ </div>
</div>
- <div class ="table">
- {{$table}}
+ <div class ="form_card">
+ <div class ="table">
+ {{$table}}
+ </div>
</div>
</div>
diff --git a/views/css/course.css b/views/css/course.css
@@ -8,14 +8,12 @@
padding: 25px;
flex-grow: 1;
border-radius: 35px;
- background-color: #f1f1f1;
}
.side_bar{
flex-grow: 1;
max-width:350px;
margin: 25px;
border-radius: 35px;
- background-color: #f1f1f1;
}
.form_add{
padding: 25px;
@@ -27,6 +25,5 @@
margin-right: 5px;
}
.search form input[type=submit]{
-
width: fit-content;
- }
-\ No newline at end of file
+}
+\ No newline at end of file
diff --git a/views/css/exam.css b/views/css/exam.css
@@ -0,0 +1,29 @@
+.flex_container{
+ display: flex;
+ align-items: stretch;
+}
+.exams{
+ flex-grow: 8;
+ margin: 25px;
+ padding: 25px;
+ flex-grow: 1;
+ border-radius: 35px;
+}
+.side_bar{
+ flex-grow: 1;
+ max-width:350px;
+ margin: 25px;
+}
+.form_add{
+ padding: 25px;
+}
+.search form{
+ display:flex;
+}
+.search form input[type=text]{
+ margin-right: 5px;
+}
+.search form input[type=submit]{
+
+ width: fit-content;
+ }
+\ No newline at end of file
diff --git a/views/css/form_template.css b/views/css/form_template.css
@@ -2,32 +2,55 @@
margin:1em;
padding: 25px;
border-radius: 35px;
- background-color: #f1f1f1;
+ background-color: #33b3b6;
+ border: 3px solid #ccc;
}
.form_card h1{
font-size: 25px;
width: 100%;
text-align: center;
+ color:white;
}
-input[type=text], input[type=password]{
+form{
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+}
+a{
+ width: 75%;
+ padding-left: 10px;
+ padding-right: 10px;
+ background-color: #66ffff;
+ border-radius: 8px;
+ text-decoration:none
+}
+
+input[type=text], input[type=password], input[type=date], input[type=number]{
width: 100%;
padding: 6px 12px;
margin: 8px 0;
- border-radius: 4px;
+ border-radius: 15px;
border: 3px solid #ccc;
outline: none;
}
+.check_this_box{
+ display:block;
+}
+
input[type=password]:focus, input[type=text]:focus{
border: 3px solid #555;
+ border-radius: 15px;
}
input[type=button], input[type=submit], input[type=reset]{
- width: 80%;
+ width: 75%;
padding: 6px 12px;
- margin: 8px 0;
+ background-color: #66ffff;
+ border-radius: 15px;
+ border: 3px solid #ccc;
}
.form-response{
@@ -36,3 +59,20 @@ input[type=button], input[type=submit], input[type=reset]{
margin-bottom: 5px;
}
+table {
+ border-collapse: collapse;
+ text-align: left;
+ width: 100%;
+}
+
+tr{
+
+}
+th, td {
+ border-bottom: 1px solid #ddd;
+}
+
+tr:hover{
+ background-color:#52dff2;
+}
+
diff --git a/views/css/login.css b/views/css/login.css
@@ -8,12 +8,16 @@
.header{
padding: 40px;
- background: #1abc9c;
+ background: #33b3b6;
color: white;
text-align: center;
}
+.header h1{
+ font-size: 40px;
+}
.flex-row{
+ margin-top:150px;
display: flex;
align-items: stretch;
}
@@ -24,7 +28,6 @@
flex-grow: 8;
max-width:350px;
border-radius: 35px;
- background-color: #f1f1f1;
}
.flex-side{
diff --git a/views/css/theme.css b/views/css/theme.css
@@ -7,5 +7,5 @@
body{
padding: 0;
margin: 0;
- background: #1abc9c;
+ background: #52dff2;
}
diff --git a/views/dashboard.html b/views/dashboard.html
@@ -9,14 +9,16 @@
<body>
<div class="flex_container">
<div class ="side_bar">
- <div class ="form_add">
+ <div class ="form_card">
<h1>Dashboard</h1>
Welcome {{ $first_name }}!
</div>
</div>
<div class = "courses">
<div class="table">
- {{ $in_course }}
+ <div class="form_card">
+ {{ $in_course }}
+ </div>
</div>
</div>
</div>
diff --git a/views/exam.html b/views/exam.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html lang="eng">
+ <title>Add User</title>
+ <link rel="stylesheet" href="/views/css/theme.css">
+ <link rel="stylesheet" href="/views/css/form_template.css">
+ <link rel="stylesheet" href="/views/css/course.css">
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+</head>
+</head>
+<body>
+ <div class="flex_container">
+ <div class ="side_bar">
+ <div class ="form_card">
+ {{$form}}
+ {{$response}}
+ </div>
+ </div>
+ <div class = "courses">
+ <div class ="form_card">
+ <div class="search">
+ {{$search}}
+ </div>
+ </div>
+ <div class ="form_card">
+ <div class ="table">
+ {{$table}}
+ </div>
+ </div>
+ </div>
+
+ </div>
+</body>
+</html>
+\ No newline at end of file
diff --git a/views/grade.html b/views/grade.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html lang="eng">
+ <title>Add User</title>
+ <link rel="stylesheet" href="/views/css/theme.css">
+ <link rel="stylesheet" href="/views/css/form_template.css">
+ <link rel="stylesheet" href="/views/css/course.css">
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+</head>
+</head>
+<body>
+ <div class="flex_container">
+ <div class ="side_bar">
+ <div class ="form_card">
+ {{$form}}
+ {{$response}}
+ </div>
+ </div>
+ <div class = "courses">
+ <div class ="form_card">
+ <div class="search">
+ {{$search}}
+ </div>
+ </div>
+ <div class ="form_card">
+ <div class ="table">
+ {{$table}}
+ </div>
+ </div>
+ </div>
+
+ </div>
+</body>
+</html>
+\ No newline at end of file
diff --git a/views/login.html b/views/login.html
@@ -3,7 +3,8 @@
<head>
<title>Login Page</title>
<link rel="stylesheet" href="views/css/login.css">
- <link rel="stylesheet" href="views/css/input.css">
+ <link rel="stylesheet" href="views/css/theme.css">
+ <link rel="stylesheet" href="views/css/form_template.css">
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
@@ -14,14 +15,16 @@
<div class="flex-side"></div>
<div class="flex-middle">
- <div class="form-title"><h2>Enter credentials:</h1></div>
- <form method="POST" action="/">
- {{$login-fields}}
-
- <div class="form-response"><p style="color:red;">{{$response}}</p></div>
-
- <input type="submit" value="Login">
- </form>
+ <div class="form_card">
+ <div class="form-title"><h2>Enter credentials:</h1></div>
+ <form method="POST" action="/">
+ {{$login-fields}}
+
+ <div class="form-response"><p style="color:red;">{{$response}}</p></div>
+
+ <input type="submit" value="Login">
+ </form>
+ </div>
</div>
<div class="flex-side"></div>
diff --git a/views/user.html b/views/user.html
@@ -9,19 +9,24 @@
<body>
<div class="flex_container">
<div class ="side_bar">
- <div class ="form_add">
+ <div class ="form_card">
{{$form}}
{{$response}}
</div>
</div>
<div class = "courses">
- <div class="search">
- {{$search}}
+ <div class ="form_card">
+ <div class="search">
+ {{$search}}
+ </div>
</div>
- <div class ="table">
- {{$table}}
+ <div class ="form_card">
+ <div class ="table">
+ {{$table}}
+ </div>
</div>
</div>
+
</div>
</body>
</html>
\ No newline at end of file