lollipop

A PHP-framework
Log | Files | Refs

commit 4d0742b42436cd0ce26d979376f9804f65d920be
parent 5ea97dd0ca04b95e3ab8c9a7e47935904cb36351
Author: Friedel Schön <[email protected]>
Date:   Sat, 24 Jun 2023 15:56:14 +0200

add dashboard

Diffstat:
Mrouting/index.php | 45+++++++++++++++++++++++++++++++++++++++++++++
Mviews/dashboard.html | 38+++++++++++++++++++++++---------------
2 files changed, 68 insertions(+), 15 deletions(-)

diff --git a/routing/index.php b/routing/index.php @@ -20,7 +20,52 @@ $index_post = function(&$vars){ }; $dashboard = function(&$vars){ + global $db; $vars += $_SESSION; + $templates = new Controller\Templates($db, $db->get(\Model\Course::class)); + $course = $db->get(Model\Course::class); + + $enrolled = []; + + foreach($db->all_where(Model\CourseUser::class, [ "email" => $_SESSION['email'] ]) as $data) { + $enrolled[] = $data->id; + } + + $table = "<table> <thead> <tr>"; + foreach($course->get_column_names() as $column){ + $table .= "<th>$column</th>"; + } + $table .= "</tr> </thead>"; + + $objs = $db->all(Model\Course::class); + $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'; + } + + $table .= "<tr>"; + $col_names = $obj->get_column_names(); + foreach($col_names as $col){ + $table .= '<td>' . $obj->{$col} . '</td>'; + } + $table .= ' + <td> + <a class="edit" href="/user/'. $_SESSION['email'] . '/course/' . $obj->id . '/' . $enroll_action . '/";>' . $enroll_btn . '</a> + </td>'; + + $table .= '</tr>'; + } + + $table .= " + </tbody></table>"; + + $vars['in_course'] = $table; + return "views/dashboard.html"; }; diff --git a/views/dashboard.html b/views/dashboard.html @@ -1,16 +1,24 @@ -<html> - <head> - <link rel="stylesheet" href="views/css/input.css"> - </head> - <body> - <div class="header"> - <div></div> - <h1>Lollipop</h1> - <form method="post" action="/logout"> - <input type="submit" value="Logout"> - </form> - </div> - - {{$email}} - </body> +<!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> +<body> + <div class="flex_container"> + <div class ="side_bar"> + <div class ="form_add"> + <h1>Dashboard</h1> + Welcome {{ $first_name }}! + </div> + </div> + <div class = "courses"> + <div class="table"> + {{ $in_course }} + </div> + </div> + </div> +</body> </html> \ No newline at end of file