summaryrefslogtreecommitdiff
path: root/public/app
diff options
context:
space:
mode:
Diffstat (limited to 'public/app')
-rw-r--r--public/app/controllers/admin/Course_admin.php93
-rw-r--r--public/app/controllers/admin/Users_admin.php42
-rw-r--r--public/app/models/admin/Privilege_model.php42
-rw-r--r--public/app/models/cms/Course_model.php3
-rw-r--r--public/app/routes/backend.php81
-rw-r--r--public/app/views/admin/admin-menu.php4
-rw-r--r--public/app/views/admin/categories.php16
-rw-r--r--public/app/views/admin/new_lesson.php144
-rw-r--r--public/app/views/admin/privileges.php93
9 files changed, 492 insertions, 26 deletions
diff --git a/public/app/controllers/admin/Course_admin.php b/public/app/controllers/admin/Course_admin.php
new file mode 100644
index 0000000..0e34e00
--- /dev/null
+++ b/public/app/controllers/admin/Course_admin.php
@@ -0,0 +1,93 @@
+<?php
+
+namespace app\controllers\admin;
+
+use Registry;
+use Render;
+use app\models\cms\Course_model;
+
+class Course_admin {
+
+
+ /** breadcrumbs
+ * ---
+ * responds to ajax GET: /admin/api/categories
+ */
+ public static function breadcrumbs()
+ {
+ $tree = proxy( // cache-get categories
+ [\app\models\cms\Course_model::class, 'category_tree'],
+ [], CACHE_ROOT_TTL
+ );
+ $breadcrumbs = proxy( // cache-get breadcrumbs
+ [\app\models\cms\Course_model::class, 'breadcrumbs'],
+ [$tree], CACHE_ROOT_TTL
+ );
+ Render::json($breadcrumbs); // send as json
+ }
+
+ /** add course
+ * ---
+ * @param void (get data from POST)
+ */
+ public static function add_course()
+ {
+ // insert new category; id = new category id
+ $id = Registry::use('database')->query(
+ "INSERT INTO course (parent_id, label) VALUES (:parent, :label)",
+ [
+ ':parent' => Registry::get('REQUEST')->POST['parent_id'],
+ ':label' => Registry::get('REQUEST')->POST['label']
+ ]
+ )->lastInsertID();
+
+ $cache = self::update_courses_cache(); // update category caches
+ return $cache['breadcrumbs']; // return
+ }
+
+
+ /** update course
+ * ---
+ * @param void (get data from POST)
+ */
+ public static function update_course()
+ {
+ Registry::use('database')->query(
+ "UPDATE course SET parent_id = :parent, label = :label
+ WHERE id = :id",
+ [
+ ':id' => Registry::get('REQUEST')->POST['id'],
+ ':parent' => Registry::get('REQUEST')->POST['parent_id'],
+ ':label' => Registry::get('REQUEST')->POST['label']
+ ]
+ );
+ $cache = self::update_courses_cache();
+ return $cache['breadcrumbs'];
+ }
+
+
+ /** update courses cache
+ * --- -- -- - - -
+ * Shall run if anything changes to courses
+ *
+ * @param void
+ * @return (array): the two course caches
+ */
+ public static function update_courses_cache()
+ {
+ $tree = proxy( // cache-get categories
+ [\app\models\cms\Course_model::class, 'category_tree'],
+ [], CACHE_ROOT_TTL, PROXY_IGNORE_CACHE
+ );
+ $breadcrumbs = proxy( // cache-get breadcrumbs
+ [\app\models\cms\Course_model::class, 'breadcrumbs'],
+ [$tree], CACHE_ROOT_TTL, PROXY_IGNORE_CACHE
+ );
+
+ return [
+ 'tree' => $tree,
+ 'breadcrumbs' => $breadcrumbs
+ ];
+ }
+
+} \ No newline at end of file
diff --git a/public/app/controllers/admin/Users_admin.php b/public/app/controllers/admin/Users_admin.php
new file mode 100644
index 0000000..4e335c1
--- /dev/null
+++ b/public/app/controllers/admin/Users_admin.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace app\controllers\admin;
+
+use Registry;
+use Render;
+
+
+class Users_admin {
+
+ /** privileges
+ * ---
+ * get all privileges
+ *
+ * @param void
+ * @return privileges (array)
+ */
+ public static function privileges()
+ {
+ return Registry::use('database')->runQuery(
+ "SELECT * FROM privilege",[]
+ );
+ }
+
+ /** edit privileges
+ * ---
+ */
+ public static function edit_privileges()
+ {
+ // TODO: ...
+ }
+
+
+ /** update course
+ * ---
+ */
+ public static function update_course()
+ {
+ // TODO: ...
+ }
+
+} \ No newline at end of file
diff --git a/public/app/models/admin/Privilege_model.php b/public/app/models/admin/Privilege_model.php
new file mode 100644
index 0000000..c385484
--- /dev/null
+++ b/public/app/models/admin/Privilege_model.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace app\models\admin;
+
+use Registry;
+use Render;
+
+
+class Privilege_model {
+
+ /** privileges
+ * ---
+ * get all privileges
+ *
+ * @param void
+ * @return privileges (array)
+ */
+ public static function privileges()
+ {
+ return Registry::use('database')->runQuery(
+ "SELECT * FROM privilege",[]
+ );
+ }
+
+ /** edit privileges
+ * ---
+ */
+ public static function edit_privileges()
+ {
+ // TODO: ...
+ }
+
+
+ /** update course
+ * ---
+ */
+ public static function update_course()
+ {
+ // TODO: ...
+ }
+
+} \ No newline at end of file
diff --git a/public/app/models/cms/Course_model.php b/public/app/models/cms/Course_model.php
index 4fb49c0..4740a4f 100644
--- a/public/app/models/cms/Course_model.php
+++ b/public/app/models/cms/Course_model.php
@@ -14,7 +14,7 @@ class Course_model {
public static function get_categories()
{
return Registry::use('database')->runQuery(
- "SELECT * FROM course",
+ "SELECT * FROM course ORDER BY `order`",
[]
);
}
@@ -74,6 +74,7 @@ class Course_model {
'rec' => [
'id' => $rec['id'],
'label' => $rec['label'],
+ 'order' => $rec['order'],
'parent' => $rec['parent_id']
],
'childs' => self::to_tree($dataset, $child) // recursively
diff --git a/public/app/routes/backend.php b/public/app/routes/backend.php
index 700fa14..5356407 100644
--- a/public/app/routes/backend.php
+++ b/public/app/routes/backend.php
@@ -1,7 +1,8 @@
<?php
use app\controllers\Auth;
-use app\models\cms\Course_model;
+use app\controllers\admin\Course_admin;
+use app\models\admin\Privilege_model;
// admin lessons
// ---
@@ -15,6 +16,9 @@ Route::add('/admin/lessons', function () {
// admin cateogies
+// -----------------------------------------------------------------------------
+
+// manage categories page
// ---
Route::add('/admin/categories', function () {
Auth::allowRoles([1, 2, 3]);
@@ -25,17 +29,70 @@ Route::add('/admin/categories', function () {
});
+// ajax: get all categories (courses; with breadcrumbs)
+// ---
Route::add('/admin/api/categories', function () {
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Course_admin::breadcrumbs();
+});
+
+
+// ajax: add new category (course)
+// ---
+Route::add('/admin/api/category/add', function () {
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Course_admin::add_course();
+ },
+ 'post'
+);
+
+// ajax: edit category (course)
+// ---
+Route::add('/admin/api/category/update', function () {
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Course_admin::update_course();
+ },
+ 'post'
+);
+
+
+// admin privileges
+// -----------------------------------------------------------------------------
+
+// manage privileges page
+// ---
+Route::add('/admin/privileges', function () {
Auth::allowRoles([1, 2, 3]);
- $tree = proxy(
- [\app\models\cms\Course_model::class, 'category_tree'],
+ Render::view('admin/skeleton', [
+ 'title' => 'Διαχείριση Δικαιωμάτων Πρόσβασης',
+ 'action' => 'privileges',
+ ]);
+});
+
+// ajax: get all privileges (courses; with breadcrumbs)
+// use proxy (cache results); send as json
+// ---
+Route::add('/admin/api/privileges', function () {
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Render::json( proxy(
+ [\app\models\admin\Privilege_model::class, 'privileges'],
[], CACHE_ROOT_TTL
- );
-
- $breadcrumbs = proxy(
- [\app\models\cms\Course_model::class, 'breadcrumbs'],
- [$tree], CACHE_ROOT_TTL
- );
- // $breadcrumbs = Course_model::breadcrumbs($tree);
- Render::json($breadcrumbs);
-}); \ No newline at end of file
+ ));
+});
+
+// add privilege
+
+// update privilege
+
+
+
+// new lesson
+// -----------------------------------------------------------------------------
+Route::add('/admin/new_lesson', function () {
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Render::view('admin/skeleton', [
+ 'title' => 'Νέο Μάθημα',
+ 'action' => 'new_lesson'
+ ]);
+});
+
diff --git a/public/app/views/admin/admin-menu.php b/public/app/views/admin/admin-menu.php
index 813420d..d7e7b09 100644
--- a/public/app/views/admin/admin-menu.php
+++ b/public/app/views/admin/admin-menu.php
@@ -16,11 +16,11 @@
$admin_options = [
- 'new' => 'Νέο Μάθημα',
+ 'new_lesson' => 'Νέο Μάθημα',
'lessons' => 'Μαθήματα',
'categories' => 'Κατηγορίες',
'pages' => 'Σελίδες',
- 'privileges' => 'Δικαιώματα',
+ 'privileges' => 'Πρόσβαση',
'users' => 'Χρήστες'
];
diff --git a/public/app/views/admin/categories.php b/public/app/views/admin/categories.php
index e33d9b0..91acec1 100644
--- a/public/app/views/admin/categories.php
+++ b/public/app/views/admin/categories.php
@@ -1,9 +1,9 @@
<!-- title bar -->
<div class="title-bar">
- <div>Διαχείριση Κατηγοριών</div>
+ <div><h5>Διαχείριση Κατηγοριών</h5></div>
<div>
<!-- Button trigger modal -->
- <button type="button" class="btn btn-success pull-right"
+ <button type="button" class="btn pull-right"
data-bs-toggle="modal" data-bs-target="#manageCategory" data-id="0">
<i class="fas fa-plus"></i> &nbsp; Νέα Κατηγορία
</button>
@@ -16,7 +16,7 @@
<div id="categories-tree">
- <table id="dt-categories" class="table table-responsive dt-table">
+ <table id="dt-categories" class="table table-responsive dt-table" style="width:100%">
<thead>
<th class="dt-breadcrumb">Κατηγορία</th>
<th class="dt-actions"></th>
@@ -48,25 +48,19 @@
<!-- modal-body -->
<div class="modal-body">
- <!-- loader
- <div class="modal-loader">
- <img src="/img/ajax-loader.gif">
- </div>
- -->
-
<!-- form fields -->
<div class="row form-group">
<label class="control-label col-sm-12" for="label">Όνομα κατηγορίας</label>
<div class="col-sm-12">
- <input class="form-control" type="text" name="label" value="" required="">
+ <input class="form-control form-control-sm" type="text" name="label" value="" required="">
</div>
</div>
<div class="row form-group">
<label class="control-label col-sm-12" for="parent_id">Γονική Κατηγορία</label>
<div class="col-sm-12">
- <select class="form-control" id="parent_id" name="parent_id" required /></select>
+ <select class="form-control form-control-sm form-select form-select-sm" id="parent_id" name="parent_id" required></select>
</div>
</div>
diff --git a/public/app/views/admin/new_lesson.php b/public/app/views/admin/new_lesson.php
new file mode 100644
index 0000000..c48fc82
--- /dev/null
+++ b/public/app/views/admin/new_lesson.php
@@ -0,0 +1,144 @@
+<?php
+// if no (lesson-)id is specified, then id=0 (new lesson)
+if (!isset($id)) $id=0;
+?>
+
+<!-- title bar -->
+<div class="title-bar">
+ <div><h5>Επεξεργασία Μαθήματος</h5></div>
+ <div>
+ <button type="button" class="btn pull-right"
+ data-toggle="modal" data-target="#editorModal" data-action="preview">
+ <i class="fas fa-search"></i> &nbsp; Προεπισκόπηση
+ </button>
+ </div>
+</div>
+
+<!-- manage -->
+<div class="manage edit-post">
+ <form>
+ <div class="row">
+
+
+ <div class="col col-8">
+
+ <!-- id (hidden) -->
+ <input type="hidden" name="id" value="0"><!-- action = (0) ? 'new' : 'edit' -->
+
+ <!--
+ <div class="row form-group">
+ <input type="date" name="date" value="" readonly="">
+ </div>
+ -->
+
+ <div class="row form-group">
+ <label class="control-label col-sm-12" for="title">Τίτλος</label>
+ <div class="col-sm-12">
+ <input class="form-control form-control-sm" type="text" name="title" value="" required="">
+ </div>
+ </div>
+
+ <div class="row form-group">
+ <label class="control-label col-sm-12" for="category_id">Κατηγορία</label>
+ <div class="col-sm-12">
+ <select class="form-control form-control-sm" id="category_id" name="category_id" required></select>
+ </div>
+ </div>
+
+ <!-- Post body -->
+ <div class="row form-group">
+ <label class="control-label col-sm-12" for="body">Κείμενο</label>
+ <div class="col-sm-12">
+ <textarea class="form-control form-control-sm" type="text" name="body" value="" required=""></textarea>
+ </div>
+ </div>
+
+ </div>
+
+ <div class="col">
+
+ <div class="row form-group">
+ <label class="control-label col-sm-12" for="status">Κατάσταση</label>
+ <div class="col-sm-12">
+ <select class="form-control form-control-sm form-select form-select-sm" name="status" onchange="this.dataset.chosen = this.value;">
+ <option value="0">Αδημοσίευτο</option>
+ <option value="one">ΔΗΜΟΣΙΕΥΜΕΝΟ</option>
+ </select>
+ </div>
+ </div>
+
+ <div class="row form-group">
+ <label class="control-label col-sm-12" for="privilege_id">Επίπεδο Πρόσβασης</label>
+ <div class="col-sm-12">
+ <select class="form-control form-control-sm form-select form-select-sm" name="privilege_id">
+ <option>one</option>
+ <option>two</option>
+ <option>three</option>
+ </select>
+ </div>
+ </div>
+
+ <div class="row form-group">
+ <label class="control-label col-sm-12" for="intro">Σύντομη Περιγραφή</label>
+ <div class="col-sm-12">
+ <textarea class="form-control form-control-sm" type="text" name="intro" value=""></textarea>
+ </div>
+ </div>
+
+ <div class="row form-group">
+ <label class="control-label col-sm-12" for="media">Αρχεία</label>
+ <div class="col-sm-12 post-media">
+
+ <!-- Button trigger modal -->
+ <button type="button" class="btn btn-sm btn-success pull-right over-bar"
+ data-toggle="modal" data-target="#editorModal" data-action="upload_file">
+ <i class="fas fa-plus"></i> &nbsp; Προσθήκη
+ </button>
+
+ <ul id="files_list">
+ </ul>
+
+ </div>
+ </div>
+
+ <?php if ($id != 0) : ?>
+ <div class="row form-group">
+ <label class="control-label col-sm-12">Πληροφορίες</label>
+ <div class="col-sm-12" id="post-info">
+ </div>
+ </div>
+ <?php endif; ?>
+
+ </div>
+
+ </div>
+
+ <div class="row">
+
+ <div class="col">
+ <hr/>
+ <!-- close | submit buttons -->
+
+ <div class="form-actions row justify-content-md-center">
+
+ <div class="col-3">
+ <button type="button" id="go-back" class="btn btn-light col-sm-12">
+ Επιστροφή
+ </button>
+ </div>
+
+ <div class="col-4">
+ <button class="btn btn-primary col-sm-12" type="submit">
+ Καταχώριση
+ </button>
+ </div>
+
+ </div>
+
+ </div>
+
+ </form>
+
+ </div>
+</div><!-- /manage -->
+
diff --git a/public/app/views/admin/privileges.php b/public/app/views/admin/privileges.php
new file mode 100644
index 0000000..587c363
--- /dev/null
+++ b/public/app/views/admin/privileges.php
@@ -0,0 +1,93 @@
+ <!-- title bar -->
+ <div class="title-bar">
+ <div><h5>Διαχείριση Επιπέδων Πρόσβασης</h5></div>
+ <div>
+ <!-- Button trigger modal -->
+ <button type="button" class="btn pull-right"
+ data-bs-toggle="modal" data-bs-target="#managePrivileges" data-id="0">
+ <i class="fas fa-plus"></i> &nbsp; Νέο Επίπεδο
+ </button>
+ </div>
+</div>
+
+<div class="manage">
+ <div class="row">
+ <div class="col-md-12">
+
+ <div id="categories-tree">
+
+ <table id="dt-privileges" class="table table-responsive dt-table" style="width:100%">
+ <thead>
+ <th class="dt-id">Κωδικός</th>
+ <th class="dt-privilege">Επίπεδο Πρόσβασης</th>
+ <th class="dt-includes">Περιλαμβάνει</th>
+ <th class="dt-actions"></th>
+ </thead>
+ </table>
+
+ </div>
+
+
+ </div>
+ </div>
+</div><!-- /manage -->
+
+
+
+<!-- MODAL for new/edit category -->
+<!-- NOTE: tabindex="-1" removed, ref:https://github.com/select2/select2-bootstrap-theme/issues/41 -->
+<div class="modal fade" id="managePrivileges" aria-labelledby="myModalLabel" aria-hidden="true">
+ <div class="modal-dialog modal-lg" role="document">
+ <div class="modal-content">
+
+ <form method="post" action="">
+
+ <div class="modal-header">
+ <h4 class="modal-title" id="myModalLabel">Modal title</h4>
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
+ </div><!-- /modal-header -->
+
+ <!-- modal-body -->
+ <div class="modal-body">
+
+ <!-- form fields -->
+
+ <div class="row form-group">
+ <label class="control-label col-sm-12" for="label">Όνομα Επιπέδου Πρόσβασης</label>
+ <div class="col-sm-12">
+ <input class="form-control form-control-sm" type="text" name="label" value="" required="">
+ </div>
+ </div>
+
+ <div class="row form-group">
+ <label class="control-label col-sm-12" for="included_id">Περιλαμβάνει μέχρι και το Επίπεδο</label>
+ <div class="col-sm-12">
+ <select class="form-control form-control-sm form-select form-select-sm" id="included_id" name="included_id" required></select>
+ </div>
+ </div>
+
+ <div class="row form-group">
+ <input type="hidden" name="id" value="0"><!-- action = (0) ? 'new' : 'edit' -->
+ </div>
+
+
+ </div><!-- /modal body -->
+
+ <div class="modal-footer">
+ <div class="row form-actions">
+
+ <div class="col">
+ <button type="button" class="btn btn-default js-modal-close col-sm-12" data-bs-dismiss="modal">Κλείσιμο</button>
+ </div>
+ <div class="col">
+ <button class="btn btn-success col-sm-12" type="submit">Καταχώριση</button>
+ </div>
+
+ </div>
+ </div><!-- /modal-footer -->
+
+ </form><!-- /form -->
+
+ </div>
+ </div>
+</div>