commit c9a2daa18b9ea453666bfd7ffce7ee60bbe2603d
parent 5a4d1e009c99a49b92d706ae0f599c3a0c5dd60e
Author: Friedel Schön <[email protected]>
Date: Sun, 25 Jun 2023 17:16:25 +0200
Merge branch 'master' of https://github.com/friedelschoen/lollipop
Diffstat:
30 files changed, 652 insertions(+), 576 deletions(-)
diff --git a/Controller/Templates.php b/Controller/Templates.php
@@ -47,18 +47,28 @@ namespace Controller{
}
function form_v2(string $action, array $values = [], array $extra = [], array $response = []): string{
-
/*auto-increment fields are automatically hidden*/
- $form = '<h1>Add '. $this->table->get_table() .'</h1>
+ if(sizeof($values) == 0){
+ $form_type = "Add";
+ }else{
+ $form_type = "Update";
+ }
+ $form = '<h1>'. $form_type .' '. $this->table->get_table() .'</h1>
<a href="/'. $this->table->get_table() .'">New</a>';
$form .= '<form method="POST" action="'. $action . '">';
foreach($this->table->get_col_info() as $col => $info){
- if($info["extra"] == "auto_increment"){
- $form .= '<input type="hidden" name="' . $col . '" placeholder="' . $col . '" value="' . $values[$col] . '">';
- }elseif($info["extra"] == "password"){
+ if(isset($info["extra"]) && $info["extra"] == "auto_increment"){
+ $form .= '<input type="hidden" name="' . $col . '" placeholder="' . $col . '" value="';
+ if(isset($values[$col]))
+ $form .= $values[$col];
+ $form .= '">';
+ }elseif(isset($info["extra"]) && $info["extra"] == "password"){
$form .= '<input type="password" name="' . $col . '" placeholder="' . $col . '">';
- }else{
- $form .= '<input type="'. $info["input_type"] .'" name="' . $col . '" placeholder="' . $col . '" value="' . $values[$col] . '">';
+ }elseif(isset($info["input_type"])){
+ $form .= '<input type="'. $info["input_type"] .'" name="' . $col . '" placeholder="' . $col . '" value="';
+ if(isset($values[$col]))
+ $form .= $values[$col];
+ $form .= '">';
}
$miss_key = 'missing_'.$col;
if(array_key_exists($miss_key, $response)){
@@ -68,11 +78,6 @@ namespace Controller{
foreach($extra as $html){
$form.= $html;
}
- if(sizeof($values) == 0){
- $form_type = "Add";
- }else{
- $form_type = "Update";
- }
$form .= '<input type="hidden" name="form_type" " value="' . $form_type . '">';
$form .='
<input type="submit" value="'. $form_type .'">
@@ -89,14 +94,18 @@ namespace Controller{
}
public function crud_table(string $action, string $search = "", string $search_key, \Model\PermissionUser $permissionUser = null):string{
- $search = '%' . $search . '%';
+ if($search == ""){
+ $search = "%";
+ }else{
+ $search = '%' . $search . '%';
+ }
$table = "<table> <thead> <tr>";
foreach($this->table->get_column_names() as $column){
$table .= "<th>$column</th>";
}
$table .= "<th>Alter</th> <th>Delete</th>";
if($permissionUser != null){
- $table .= "<th>Permissions</th>";
+ $table .= "<th>user permissions</th>";
}
$table .= "</tr> </thead>";
@@ -116,7 +125,11 @@ namespace Controller{
<a class="delete" href="' . $action . '/'. $obj->{$this->table->get_primary()} .'/delete/">Delete</a>
</td>
<td>';
-
+ if($permissionUser != null){
+ foreach($this->db->all_where(\Model\PermissionUser::class, [$permissionUser->get_primary() => $obj->{$this->table->get_primary()}]) as $perm){
+ $table .= $perm->id . ' ';
+ }
+ }
$table .= '</td> </tr>';
}
@@ -125,5 +138,34 @@ namespace Controller{
</table>";
return $table;
}
+
+ function links():string{
+ $links = '<div class ="links">';
+ if(isset($_SESSION['user_permissions'])){
+ if(in_array(1, $_SESSION['user_permissions']) || in_array(2, $_SESSION['user_permissions'])|| in_array(3, $_SESSION['user_permissions'])){
+ $links .= '<a href="/userpage/'.$_SESSION["email"].'/page">My info</a>';
+ }
+ if(in_array(2, $_SESSION['user_permissions']) || in_array(3, $_SESSION['user_permissions'])){
+ $links .= '<a href="/course">Courses</a>';
+ $links .= '<a href="/exam">Exams</a>';
+ $links .= '<a href="/grade">Grades</a>';
+ }
+ if(in_array(3, $_SESSION['user_permissions'])){
+ $links .= '<a href="/user">Users</a>';
+ }
+ }
+ $links .= "</div>";
+ return $links;
+ }
+
+ function header():string{
+ $header = "";
+ $header .= "<div class='header'>
+ <h1>Lollipop</h1>";
+ if(isset($_SESSION['user_permissions']))
+ $header .= '<a href="/logout">logout</a>';
+ $header .= "</div>";
+ return $header;
+ }
}
}
\ No newline at end of file
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;
@@ -172,7 +171,7 @@ namespace Lollipop {
public function notNullable(){
//non-auto-increment not-nullable collumn names query
$col_names = [];
- $sql = " SELECT column_name, is_nullable
+ $sql = " SELECT column_name, is_nullable, extra
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = '{$this->table}'
AND TABLE_SCHEMA = '{$this->schema}'";
@@ -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/Lollipop/Utils.php b/Lollipop/Utils.php
@@ -19,5 +19,17 @@ namespace Lollipop{
}
return $missing;
}
+ static function missing_fields_sans_pw($not_nullable){
+ $missing = [];
+ foreach($not_nullable as $column){
+ if($_POST[$column] == NULL || $_POST[$column] == ""){
+ if($column != "password"){
+ $key = 'missing_' . $column;
+ $missing[$key] = "This field cannot be empty!";
+ }
+ }
+ }
+ return $missing;
+ }
}
}
\ No newline at end of file
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/Model/PermissionUser.php b/Model/PermissionUser.php
@@ -9,7 +9,7 @@ namespace Model {
static function get_primary(): string
{
- return 'id';
+ return 'email';
}
static function get_schema(): string
{
@@ -26,10 +26,19 @@ namespace Model {
}
return false;
}
- public function update_permissions(User $user):array{
-
-
- return $this->db->all_where($this->get_table(), ["email", $_POST["email"]]);
+ public function update_permissions(User $user):bool{
+ foreach($this->db->all_where(PermissionUser::class, [$this->get_primary() => $_POST[$this->get_primary()]]) as $permission){
+ $permission->delete();
+ }
+ if(array_key_exists('permissions', $_POST)){
+ foreach($_POST['permissions'] as $permission){
+ $this->{$user->get_primary()} = $user->{$user->get_primary()};
+ $this->id = $permission;
+ $this->add();
+ }
+ return true;
+ }
+ return false;
}
}
}
\ No newline at end of file
diff --git a/Model/User.php b/Model/User.php
@@ -82,7 +82,7 @@ namespace Model {
}
}
//get permissions form db and set sessions_permissions
- $p = $this->db->all_where(PermissionUser::class, [$this->get_primary(), $this->{$this->get_primary()}]);
+ $p = $this->db->all_where(PermissionUser::class, [$this->get_primary() => $this->{$this->get_primary()}]);
foreach($p as $permission){
$user_permissions[] = $permission->id;
}
@@ -127,5 +127,21 @@ namespace Model {
}
}
}
+ public function update_user():bool{
+ $missing_fields = \Lollipop\Utils::missing_fields_sans_pw($this->notNullable());
+ if(sizeof($missing_fields) == 0){
+ foreach($_POST as $key => $post){
+ if(in_array($key, $this->get_column_names())){
+ if($key == $this->get_password_field()){
+ $this->{$key} = password_hash($_POST[$key], PASSWORD_DEFAULT);
+ }else{
+ $this->{$key} = $post;
+ }
+ }
+ }
+ return $this->save();
+ }
+ return false;
+ }
}
}
\ No newline at end of file
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);
@@ -16,7 +18,12 @@ session_start();
echo $tmp;
}
}*/
-
+$router->addRoute(["GET"], "/views/css/add_user.css", "views/css/add_user.css");
+$router->addRoute(["GET"], "/views/css/course.css", "views/css/course.css");
+$router->addRoute(["GET"], "/views/css/exam.css", "views/css/exam.css");
+$router->addRoute(["GET"], "/views/css/form_template.css", "views/css/form_template.css");
+$router->addRoute(["GET"], "/views/css/login.css", "views/css/login.css");
+$router->addRoute(["GET"], "/views/css/theme.css", "views/css/theme.css");
$router->addRoute(["GET"], "/", $index_get);
@@ -38,7 +45,7 @@ $router->addRoute(["GET"], "/user/:primary_key/delete", $user_delete);
$router->addRoute(["GET"], "/user/:primary_key/page", $user_page);
-$router->addRoute(["POST"], "/logout", $logout);
+$router->addRoute(["GET"], "/logout", $logout);
$router->addRoute(["GET"], "/course", $course_get);
@@ -52,4 +59,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/routing/index.php b/routing/index.php
@@ -2,6 +2,8 @@
$index_get = function(&$vars){
global $db;
+ $templates = new Controller\Templates($db, $db->get(\Model\User::class));
+ $vars["header"] = $templates->header();
$vars["login-fields"] = $db->get(Model\User::class)->login_fields();
return "views/login.html";
};
@@ -23,8 +25,10 @@ $dashboard = function(&$vars){
global $db;
$vars += $_SESSION;
$templates = new Controller\Templates($db, $db->get(\Model\Course::class));
+ $vars["header"] = $templates->header();
$course = $db->get(Model\Course::class);
+ $vars['links'] = $templates->links();
$enrolled = [];
foreach($db->all_where(Model\CourseUser::class, [ "email" => $_SESSION['email'] ]) as $data) {
@@ -35,7 +39,7 @@ $dashboard = function(&$vars){
foreach($course->get_column_names() as $column){
$table .= "<th>$column</th>";
}
- $table .= "</tr> </thead>";
+ $table .= "<th>registered</tr> </thead>";
$objs = $db->all(Model\Course::class);
$table .= "<tbody>";
diff --git a/routing/user.php b/routing/user.php
@@ -3,7 +3,7 @@ $user_get = function(&$vars){
global $db;
$user = $db->get(Model\User::class);
$permissions = $db->get(Model\Permission::class);
- $permissionUser = $db->get(Model\PermissionUser::class);
+ $permission_user = $db->get(Model\PermissionUser::class);
$templates = new controller\templates($db, $user);
if(isset($_POST["search"])){
@@ -12,7 +12,7 @@ $user_get = function(&$vars){
}
$vars["form"] = $templates->form_v2("/user", [], ["checkboxes" => $permissions->get_checkboxes()]);
$vars["search"] = $templates->search_form("/user/search");
- $vars["table"] = $templates->crud_table("/user", "" ,"email", $permissionUser);
+ $vars["table"] = $templates->crud_table("/user", "" ,"email", $permission_user);
return "views/user.html";
};
@@ -29,17 +29,19 @@ $user_post = function(&$vars){
if($user->add_user() && $permission_user->add_permissions($user)){
$vars["response"] = 'succesfully added: ' . $_POST["email"];
}
- } elseif($_POST["form_type"] == 'Update'){
- if($user->update_user()){
+ }elseif($_POST["form_type"] == 'Update'){
+ if($user->update_user() && $permission_user->update_permissions($user)){
$vars["response"] = 'succesfully updated: ' . $_POST["email"];
+ }else{
+ echo"something went wrong";
+ var_dump(\Lollipop\Utils::missing_fields($user->notNullable()));
}
}
- }
-
+ }
$vars["form"] = $templates->form_v2("/user", $data, ["checkboxes" => $permissions->get_checkboxes()]);
$vars["search"] = $templates->search_form("/user");
- $vars["table"] = $templates->crud_table("/user", "", "email");
+ $vars["table"] = $templates->crud_table("/user", "", "email", $permission_user);
return "views/user.html";
};
@@ -47,10 +49,11 @@ $user_query = function(&$vars){
global $db;
$user = $db->get(Model\User::class);
$permissions = $db->get(Model\Permission::class);
+ $permission_user = $db->get(Model\PermissionUser::class);
$templates = new controller\templates($db, $user);
$vars["form"] = $templates->form_v2("/user", [], ["checkboxes" => $permissions->get_checkboxes()]);
$vars["search"] = $templates->search_form("/user/search");
- $vars["table"] = $templates->crud_table("/user", $vars["search_query"], "email");
+ $vars["table"] = $templates->crud_table("/user", $vars["search_query"], "email", $permission_user);
return "views/user.html";
};
@@ -73,6 +76,7 @@ $user_edit = function(&$vars){
global $db;
$user = $db->get(Model\User::class);
$permissions = $db->get(Model\Permission::class);
+ $permission_user = $db->get(Model\PermissionUser::class);
$templates = new controller\templates($db, $user);
$data = [];
$user->load($vars["primary_key"]);
@@ -81,7 +85,7 @@ $user_edit = function(&$vars){
}
$vars["form"] = $templates->form_v2("/user", $data, ["checkboxes" => $permissions->get_checkboxes()]);
$vars["search"] = $templates->search_form("/user/search");
- $vars["table"] = $templates->crud_table("/user", "", "email");
+ $vars["table"] = $templates->crud_table("/user", "", "email", $permission_user);
return "views/user.html";
};
@@ -90,11 +94,12 @@ $user_delete = function(&$vars){
$user = $db->get(Model\User::class);
$permissions = $db->get(Model\Permission::class);
$templates = new controller\templates($db, $user);
+ $permission_user = $db->get(Model\PermissionUser::class);
$user->load($vars["primary_key"]);
$user->delete();
$vars["form"] = $templates->form_v2("/user", [], ["checkboxes" => $permissions->get_checkboxes()]);
$vars["search"] = $templates->search_form("/user");
- $vars["table"] = $templates->crud_table("/user" ,"", "email");
+ $vars["table"] = $templates->crud_table("/user" ,"", "email", $permission_user);
return "views/user.html";
};
diff --git a/views/alter_user.php b/views/alter_user.php
@@ -1,170 +0,0 @@
-<!DOCTYPE html>
-<html lang="eng">
-
-<head>
- <title>User toevoegen</title>
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
-</head>
-<?php
-
-include "navbar.php";
-include "utils/autoloader.php";
-if (!in_array(0, $_SESSION['permissions'])) {
- header('Location: /dashboard');
- exit;
-}
-$db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "lollipop");
-
-//select the available permissions from the database
-$all_p = $db->all(Model\Permission::class);
-$available_permissions = [];
-foreach ($all_p as $tmp) {
- $available_permissions[] = ['id' => $tmp->id, 'name' => $tmp->name];
-}
-//if not found set to empty if not GET
-$fname = "";
-$lname = "";
-$email = "";
-$user_permissions = [];
-
-if ($_SERVER["REQUEST_METHOD"] == "GET") {
- //if the get var isset and user is found in the database load data into forms
- $get_email = $_PARAM['email'];
- $u = $db->get(Model\User::class);
- if ($u->load($get_email)) {
- $fname = $u->fname;
- $lname = $u->lname;
- $email = $u->email;
- $p = $db->where(Model\PermissionUser::class, array('email' => $email));
- foreach ($p as $permission) {
- $user_permissions[] = $permission->id;
- }
- }
-}
-if ($_SERVER["REQUEST_METHOD"] == "POST") {
- $errors = array(); // initialize an empty array to store errors
-
- // Check if voornaam is set and not empty
- if (isset($_POST['voornaam']) && !empty($_POST['voornaam'])) {
- $fname = $_POST['voornaam'];
- } else {
- $errors[] = "Voornaam is required";
- }
-
- // Check if achternaam is set and not empty
- if (isset($_POST['achternaam']) && !empty($_POST['achternaam'])) {
- $lname = $_POST['achternaam'];
- } else {
- $errors[] = "Achternaam is required";
- }
-
- // Check if email is set and not empty
- if (isset($_POST['email']) && !empty($_POST['email'])) {
- $email = $_POST['email'];
- } else {
- $errors[] = "E-mail is required";
- }
-
- // Check if permissions is set
- if (isset($_POST['permissions'])) {
- $permissions = $_POST['permissions'];
- } else {
- $errors[] = "Permissies zijn vereist";
- }
-
- // Check if there are any errors
- if (count($errors) > 0) {
- // Print out the errors
- foreach ($errors as $error) {
- echo $error . "<br>";
- }
- } else {
- //create a database object with table user
- $u = $db->get(Model\User::class);
-
- //check if email already exists
- if (!$u->load($email)) {
- echo "this user does not exist " . $email;
- } else {
- $succes = false;
- //set new user data
- $u->email = $email;
- $u->fname = $fname;
- $u->lname = $lname;
- echo $u->save();
- //add user with the add function
- if (true) {
- $succes = true;
- }
-
- $p = $db->get(Model\PermissionUser::class);
- //delete all permissions
- foreach ($available_permissions as $available) {
- $p->email = $email;
- $p->id = $available['id'];
- $p->delete();
- }
-
- //add permissions
- foreach ($permissions as $keep) {
- $p->email = $email;
- $p->id = (int) $keep;
- $p->insert();
- }
- if ($succes) {
- echo "succes!";
- }
- }
- }
- //if the get var isset and user is found in the database load data into forms
-
- $get_email = $_PARAMS['email'];
- $u = $db->get(Model\User::class);
- if ($u->load($get_email)) {
- $fname = $u->fname;
- $lname = $u->lname;
- $email = $u->email;
- $p = $db->where(Model\PermissionUser::class, array('email' => $email));
- foreach ($p as $permission) {
- $user_permissions[] = $permission->id;
- }
- }
-}
-?>
-
-<body>
- <div class="container">
- <h1>Alter user</h1>
- <form action="/user/<?= $email ?>/update" method="post">
- <div class="mb-3">
- <label for="voornaam" class="form-label"><b>Voornaam:</b></label>
- <input type="text" class="form-control" name="voornaam" id="voornaam" placeholder="Voornaam" value=<?php echo $fname ?>>
- </div>
- <div class="mb-3">
- <label for="achternaam" class="form-label"><b>Achternaam:</b></label>
- <input type="text" class="form-control" name="achternaam" id="achternaam" placeholder="Achternaam"
- value=<?php echo $lname ?>>
- </div>
- <div class="mb-3">
- <label for="email" class="form-label"><b>Email:</b></label>
- <input type="text" class="form-control" name="email" id="email" placeholder="Email" value=<?php echo $email ?>>
- </div>
- <p>Please select the user permissions:</p>
- <?php
- foreach ($available_permissions as $db_permission) {
- echo "<div class=\"mb-3 form-check\">" .
- "<input type=\"checkbox\" class=\"form-check-input\" name=\"permissions[]\" value=" . $db_permission['id'] . "\"";
- if ($user_permissions != null && in_array($db_permission['id'], $user_permissions)) {
- echo " checked";
- }
- echo "><label class=\"form-check-label\" for=" . $db_permission['name'] . ">" . $db_permission['name'] . "</label>" .
- "</div>";
- }
- ?>
- <button type="submit" class="btn btn-primary" name="submit">Alter user</button>
- </form>
- </div>
-</body>
-
-</html>
-\ No newline at end of file
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/crud_user.php b/views/crud_user.php
@@ -1,122 +0,0 @@
-<!DOCTYPE html>
-<html lang="nl">
-
-<head>
- <title>User toevoegen</title>
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
-</head>
-<?php
-include "navbar.php";
-include 'utils/autoloader.php';
-
-$permissions = $_SESSION['permissions'];
-if (!isset($_SESSION['email'])) {
- if (!in_array(0, $permissions)) {
- header('Location: /dashboard');
- exit;
- }
-}
-?>
-
-<body>
- <div class="container">
- <h1>User toevoegen</h1>
-
- <form action="/user/:/crud" method="post">
- <div class="mb-3">
- <label for="voornaam" class="form-label"><b>Voornaam:</b></label>
- <input type="text" class="form-control" name="voornaam" id="voornaam" placeholder="Voornaam">
- </div>
- <div class="mb-3">
- <label for="achternaam" class="form-label"><b>Achternaam:</b></label>
- <input type="text" class="form-control" name="achternaam" id="achternaam" placeholder="Achternaam">
- </div>
- <div class="mb-3">
- <label for="email" class="form-label"><b>Email:</b></label>
- <input type="text" class="form-control" name="email" id="email" placeholder="Email">
- </div>
- <div class="mb-3">
- <label for="password" class="form-label"><b>Wachtwoord:</b></label>
- <input type="password" class="form-control" name="password" id="password" placeholder="******">
- </div>
- <p>Please select the user permissions:</p>
- <div class="mb-3 form-check">
- <input type="checkbox" class="form-check-input" id="Admin" name="permissions[]" value="1">
- <label class="form-check-label" for="Admin">Admin</label>
- </div>
- <div class="mb-3 form-check">
- <input type="checkbox" class="form-check-input" id="Administratief medewerker" name="permissions[]"
- value="2">
- <label class="form-check-label" for="Administratief medewerker">Administratief medewerker</label>
- </div>
- <div class="mb-3 form-check">
- <input type="checkbox" class="form-check-input" id="Wetenschappelijk medewerker" name="permissions[]"
- value="3">
- <label class="form-check-label" for="Wetenschappelijk medewerker">Wetenschappelijk medewerker</label>
- </div>
- <button type="submit" class="btn btn-primary" name="submit">Voeg toe</button>
- </form>
- </div>
- <?php
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
-
- $errors = array(); // initialize an empty array to store errors
-
- // Check if voornaam is set and not empty
- if (isset($_POST['voornaam']) && !empty($_POST['voornaam'])) {
- $fname = $_POST['voornaam'];
- } else {
- $errors[] = "Voornaam is required";
- }
-
- // Check if achternaam is set and not empty
- if (isset($_POST['achternaam']) && !empty($_POST['achternaam'])) {
- $lname = $_POST['achternaam'];
- } else {
- $errors[] = "Achternaam is required";
- }
-
- // Check if email is set and not empty
- if (isset($_POST['email']) && !empty($_POST['email'])) {
- $email = $_POST['email'];
- } else {
- $errors[] = "E-mail is required";
- }
-
- // Check if password is set and not empty
- if (isset($_POST['password']) && !empty($_POST['password'])) {
- $pwd = $_POST['password'];
- } else {
- $errors[] = "Wachtwoord is required";
- }
-
- // Check if permissions is set
- if (isset($_POST['permissions'])) {
- $permissions = $_POST['permissions'];
- } else {
- $errors[] = "Permissies zijn vereist";
- }
-
- // Check if there are any errors
- if (count($errors) > 0) {
- // Print out the errors
- foreach ($errors as $error) {
- echo $error . "<br>";
- }
- } else {
- // Pass the password through a hashing function
- $hashed_pwd = password_hash($pwd, PASSWORD_DEFAULT);
-
- // Making a sql statement to add user to the database, preparing it and excuting
- $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "lollipop");
-
- $u = $db->get(Model\User::class);
-
-
- }
- }
- ?>
-</body>
-
-</html>
-\ No newline at end of file
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
@@ -1,19 +1,5 @@
-* {
- box-sizing: border-box;
- font-family: Verdana,sans-serif;
- font-size: 15px;
- line-height: 1.5;
-
-}
-
-.header{
- padding: 40px;
- background: #1abc9c;
- color: white;
- text-align: center;
-}
-
.flex-row{
+ margin-top:150px;
display: flex;
align-items: stretch;
}
@@ -24,7 +10,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
@@ -4,8 +4,30 @@
font-size: 15px;
line-height: 1.5;
}
+
body{
padding: 0;
margin: 0;
- background: #1abc9c;
+ background: #52dff2;
}
+
+.header{
+ display: flex;
+ padding: 40px;
+ background: #33b3b6;
+ color: white;
+ text-align: center;
+}
+
+.header h1{
+ font-size: 40px;
+}
+
+.header a{
+ align-items: center;
+ align-self: center;
+ margin-left: auto;
+ height: 40px;
+ padding-top: 9px;
+ width: 140px;
+}
+\ No newline at end of file
diff --git a/views/dashboard.html b/views/dashboard.html
@@ -7,16 +7,20 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
+ {{ $header }}
<div class="flex_container">
<div class ="side_bar">
- <div class ="form_add">
+ <div class ="form_card">
<h1>Dashboard</h1>
Welcome {{ $first_name }}!
+ {{ $links }}
</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,25 +3,26 @@
<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>
- <div class="header">
- <h1>Lollipop</h1>
- </div>
+ {{ $header }}
<div class="flex-row">
<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/search_course.php b/views/search_course.php
@@ -1,97 +0,0 @@
-<?php
-include "utils/autoloader.php";
-
-session_start();
-
-$db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "lollipop");
-// if (!isset($_SESSION['permissions']) || !in_array(1, $_SESSION['permissions'])) {
-// header('Location: /dashboard');
-// exit;
-// }
-
-if (isset($_PARAM['enroll'])) {
- $c = $db->get(Model\CourseUser::class);
- $c->email = $_SESSION['email'];
- $c->id = $_PARAM['enroll'];
- $c->insert();
-} else if (isset($_PARAM['unsubscribe'])) {
- $c = $db->get(Model\CourseUser::class);
- $c->email = $_SESSION['email'];
- $c->id = $_PARAM['unsubscribe'];
- $c->delete();
-}
-
-$query = '';
-if (isset($_GET['query'])) {
- $query = $_GET['query'];
- $results = $db->where(Model\Course::class, ['name' => "%$query%"], true);
-} else {
- $results = $db->all(Model\Course::class);
-}
-
-$enrolled = [];
-foreach ($db->where(Model\CourseUser::class, ['email' => $_SESSION['email']]) as $r) {
- $enrolled[] = $r->id;
-}
-
-?>
-
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
- <meta charset="UTF-8">
- <title>Course Search</title>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
-</head>
-
-<body>
- <?= include "navbar.php"; ?>
- <form class="d-flex" action="/course/search" method="get">
- <input class="form-control me-2" type="search" name="query" placeholder="Email" aria-label="Search">
- <button class="btn btn-outline-success" type="submit">Search</button>
- </form>
- <?php
- if (!empty($results)) {
- ?>
- <table class='table table-striped'>
- <thead>
- <tr>
- <th>Cursus</th>
- <th>Year</th>
- <th>Semester</th>
- <th>Lecturer</th>
- </tr>
- </thead>
- <tbody>
- <?php
- foreach ($results as $data) { ?>
- <tr>
- <td>
- <?= $data->name ?>
- </td>
- <td>
- <?= $data->year ?>
- </td>
- <td>
- <?= $data->semester ?>
- </td>
- <td>
- <?= $data->lecturer ?>
- </td>
- <?php if (!in_array($data->id, $enrolled)) { ?>
- <td><a href='/course/<?= $data->id ?>/enroll'>Enroll</a></td>
- <?php } else { ?>
- <td><a href='/course/<?= $data->id ?>/unsubscribe'>Unsubscribe</a></td>
- <?php } ?>
- </tr>
- <?php
- }
- echo "</tbody></table>";
- } else {
- echo "No courses found.";
- }
- ?>
-</body>
-
-</html>
-\ No newline at end of file
diff --git a/views/search_user.php b/views/search_user.php
@@ -1,85 +0,0 @@
-<?php
-include "utils/autoloader.php";
-
-session_start();
-
-$db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "lollipop");
-if (!isset($_SESSION['permissions']) || !in_array(0, $_SESSION['permissions'])) {
- header('Location: /dashboard');
- exit;
-}
-
-if (isset($_GET['delete'])) {
- $u = $db->get(Model\User::class);
- $u->load($_GET['delete']);
- $u->delete();
-}
-
-$query = '';
-if (isset($_GET['query'])) {
- $query = $_GET['query'];
- $results = $db->where(Model\User::class, ['email' => "%$query%"], true);
-} else {
- $results = $db->all(Model\User::class);
-}
-
-?>
-
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
- <meta charset="UTF-8">
- <title>User Search</title>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
-</head>
-
-<body>
- <?= include "navbar.php"; ?>
- <form class="d-flex" action="/user/search" method="get">
- <input class="form-control me-2" type="search" name="query" placeholder="Email" aria-label="Search">
- <button class="btn btn-outline-success" type="submit">Search</button>
- </form>
- <?php
- if (!empty($results)) {
- ?>
- <table class='table table-striped'>
- <thead>
- <tr>
- <th>Email</th>
- <th>First Name</th>
- <th>Last Name</th>
-
- </tr>
- </thead>
- <tbody>
- <?php
- foreach ($results as $data) { ?>
- <tr>
- <td>
- <?= $data->email ?>
- </td>
- <td>
- <?= $data->fname ?>
- </td>
- <td>
- <?= $data->lname ?>
- </td>
- <td><a href='/user/<?= $data->email ?>/update'>Edit</a></td>
- <td>
- <form method='get' action='/user/search'>
- <input type='hidden' name='query' value='<?= $query ?>'>
- <button type='submit' name='delete' value='<?= $data->email ?>' class='btn btn-primary'>Delete</button>
- </form>
- </td>
- </tr>
- <?php
- }
- echo "</tbody></table>";
- } else {
- echo "No users with this email address were found.";
- }
- ?>
-</body>
-
-</html>
-\ No newline at end of file
diff --git a/views/user.html b/views/user.html
@@ -9,18 +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