summaryrefslogtreecommitdiff
path: root/public/app/routes
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-04-27 03:47:30 +0300
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-04-27 03:47:30 +0300
commit059e0d95d0c28bc5060e87e146eaf7411f51bf90 (patch)
tree7c21ac432f16dde2329a0d5954d70711eceb48e6 /public/app/routes
parent26cd8ee99659ef1926c96a049c93645ffc9b169d (diff)
downloadgyraf1gov-059e0d95d0c28bc5060e87e146eaf7411f51bf90.tar.gz
gyraf1gov-059e0d95d0c28bc5060e87e146eaf7411f51bf90.tar.bz2
gyraf1gov-059e0d95d0c28bc5060e87e146eaf7411f51bf90.zip
skeleton commit; based on an anom project
Diffstat (limited to 'public/app/routes')
-rw-r--r--public/app/routes/.gitkeep0
-rw-r--r--public/app/routes/api.php81
-rw-r--r--public/app/routes/backend.php221
-rw-r--r--public/app/routes/frontend.php169
-rw-r--r--public/app/routes/user.php84
5 files changed, 555 insertions, 0 deletions
diff --git a/public/app/routes/.gitkeep b/public/app/routes/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/public/app/routes/.gitkeep
diff --git a/public/app/routes/api.php b/public/app/routes/api.php
new file mode 100644
index 0000000..61e485b
--- /dev/null
+++ b/public/app/routes/api.php
@@ -0,0 +1,81 @@
+<?php
+
+use app\controllers\Auth;
+use app\controllers\api\Common_api;
+use app\controllers\api\Doc_api;
+
+
+/** API CALLS
+ * -----------------------------------------------------------------------------
+ *
+ * these calls return json responses
+ */
+
+
+// api: tree of product-categories
+Route::add('/api/tree',
+ function() { Doc_api::tree(); },
+ 'get'
+);
+
+// api: database documentation
+Route::add('/api/doc',
+ function() { Doc_api::dbDoc(); },
+ 'get'
+);
+
+Route::add('/api/url/([0-9a-zA-Z-_\/]*)',
+ function($url) { Common_api::category_by_url($url); }
+);
+
+// route: /api/table
+Route::add('/api/([0-9a-zA-Z-_]*)',
+ function($table) { Common_api::table($table); },
+ 'get'
+);
+
+// route: /api/table/{id}
+Route::add('/api/([0-9a-zA-Z-_]*)/([0-9]*)',
+ function($table, $id) { Common_api::record($table, $id); },
+ 'get'
+);
+
+
+
+/** XML CALLS
+ * -----------------------------------------------------------------------------
+ *
+ * These calls are like `/api`, except...
+ * they return xml/html as part of the responses;
+ *
+ * example: { success: true, message: html }
+ *
+ * Used when an html message needs to be passed in some div
+ *
+ */
+
+
+
+
+/** TEST CALLS
+ * -----------------------------------------------------------------------------
+ *
+ * direct calls to simple tests
+ *
+ */
+
+
+// route for testing...
+// ---
+Route::add('/test/([0-9a-zA-Z-_\/]*)', function($test) {
+
+ // TODO:
+ // hide tests from production
+
+ if (file_exists(TESTS_DIRECTORY . $test .'.php')) {
+ if (!Benchmark::exist('start')) Benchmark::add_spot('start');
+ require(TESTS_DIRECTORY . $test .'.php');
+ } else { echo "Test {$test} not exist";
+ } die();
+
+});
diff --git a/public/app/routes/backend.php b/public/app/routes/backend.php
new file mode 100644
index 0000000..2bbd056
--- /dev/null
+++ b/public/app/routes/backend.php
@@ -0,0 +1,221 @@
+<?php
+
+use app\controllers\Auth;
+use app\controllers\admin\Course_admin;
+use app\models\admin\Privilege_model;
+use app\extends\Cache_service;
+
+
+/** admin pages
+ * -----------------------------------------------------------------------------
+ * NOTE:
+ * All adminitration routes MUST INCLUDE an Auth::allowRoles() check
+ */
+
+// admin panel
+////////////////////////////////////////////////////////////////////////////////
+
+Route::add('/admin', function () { // admin panel
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Render::view('admin/skeleton', [
+ 'title' => 'Διαχείριση Classroom',
+ 'action' => 'panel',
+ ]);
+});
+Route::add('/admin/panel', function () { // admin panel #2
+ Auth::allowRoles([1, 2, 3]);
+ Render::view('admin/skeleton', [
+ 'title' => 'Διαχείριση Classroom',
+ 'action' => 'panel',
+ ]);
+});
+
+
+// admin categories (=courses)
+////////////////////////////////////////////////////////////////////////////////
+
+
+Route::add('/admin/categories', function () { // manage categories page
+ Auth::allowRoles([1, 2, 3]);
+ Render::view('admin/skeleton', [
+ 'title' => 'Διαχείριση Κεφαλαίων',
+ 'action' => 'categories',
+ ]);
+});
+
+Route::add('/admin/api/categories', function () { // ajax: get all courses; with breadcrumbs
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Course_admin::breadcrumbs();
+});
+
+Route::add('/admin/api/categories/add', function () { // ajax: add new category (course)
+ Auth::allowRoles([1, 2, 3]);
+ Course_admin::add_course();
+}, 'post');
+
+Route::add('/admin/api/categories/update', function () { // ajax: edit category (course)
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Course_admin::update_course();
+},
+'post');
+
+
+// admin privileges
+////////////////////////////////////////////////////////////////////////////////
+
+
+Route::add('/admin/privileges', function () { // manage privileges page
+ Auth::allowRoles([1, 2, 3]);
+ 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( Cache_service::privileges_hierarchy() );
+});
+
+// add privilege
+
+// update privilege
+
+
+
+// admin lessons
+////////////////////////////////////////////////////////////////////////////////
+
+Route::add('/admin/lessons', function () { // request admin-lessons page
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Render::view('admin/skeleton', [
+ 'title' => 'Διαχείριση Μαθημάτων',
+ 'action' => 'lessons',
+ ]);
+});
+
+Route::add('/admin/edit_lesson', function () { // new lesson form
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Render::view('admin/skeleton', [
+ 'title' => 'Νέο Μάθημα',
+ 'action' => 'edit_lesson',
+ ]);
+});
+
+Route::add('/admin/edit_lesson/([0-9]*)', function ($id) { // edit lesson form
+ Auth::allowRoles([1, 2, 3]);
+ Render::view('admin/skeleton', [
+ 'title' => 'Επεξεργασία Μαθήματος',
+ 'action' => 'edit_lesson',
+ 'id' => intval($id)
+ ]);
+});
+
+
+Route::add('/admin/api/lesson/([0-9]*)', function ($id) { // ajax: get lesson
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Course_admin::get_lesson($id);
+});
+
+
+Route::add('/admin/api/lesson/add', function () { // ajax: add lesson
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Render::json(['success' => Course_admin::add_lesson()]);
+}, 'post');
+
+
+Route::add('/admin/api/lesson/update', function () { // ajax: update lesson
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Render::json(['success' => Course_admin::update_lesson()]);
+}, 'post');
+
+
+Route::add('/admin/api/lessons', function () { // ajax: get all lessons
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Course_admin::all_lessons();
+});
+
+
+
+// admin files
+////////////////////////////////////////////////////////////////////////////////
+
+Route::add('/admin/files', function () { // admin-files panel
+ Auth::allowRoles([1, 2, 3]);
+ Render::view('admin/skeleton', [
+ 'title' => 'Διαχείριση Μέσων (media)',
+ 'action' => 'files',
+ ]);
+});
+
+
+Route::add('/admin/api/files', function () { // ajax: get lesson
+ Auth::allowRoles([1, 2, 3]);
+ Render::json(Course_admin::files());
+});
+
+// ajax: file-upload
+// ---
+Route::add('/admin/api/file_upload', function () {
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Render::json(Course_admin::upload_file());
+}, 'post');
+
+
+
+
+// admin page
+////////////////////////////////////////////////////////////////////////////////
+
+Route::add('/admin/pages', function () { // request admin-lessons page
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Render::view('admin/skeleton', [
+ 'title' => 'Διαχείριση Σελίδων',
+ 'action' => 'pages',
+ ]);
+});
+
+
+Route::add('/admin/edit_page', function () { // new page form
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Render::view('admin/skeleton', [
+ 'title' => 'Νέα Σελίδα',
+ 'action' => 'edit_page',
+ ]);
+});
+
+Route::add('/admin/edit_page/([0-9]*)', function ($id) { // edit page form
+ Auth::allowRoles([1, 2, 3]);
+ Render::view('admin/skeleton', [
+ 'title' => 'Επεξεργασία Σελίδας',
+ 'action' => 'edit_page',
+ 'id' => intval($id)
+ ]);
+});
+
+
+Route::add('/admin/api/page/([0-9]*)', function ($id) { // ajax: get page
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Course_admin::get_page($id);
+});
+
+
+Route::add('/admin/api/page/add', function () { // ajax: add page
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Render::json(['success' => Course_admin::add_page()]);
+}, 'post');
+
+
+Route::add('/admin/api/page/update', function () { // ajax: update page
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Render::json(['success' => Course_admin::update_page()]);
+}, 'post');
+
+
+Route::add('/admin/api/pages', function () { // ajax: get all pages
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Course_admin::all_pages();
+});
+
diff --git a/public/app/routes/frontend.php b/public/app/routes/frontend.php
new file mode 100644
index 0000000..be06b1c
--- /dev/null
+++ b/public/app/routes/frontend.php
@@ -0,0 +1,169 @@
+<?php
+
+use app\controllers\Auth;
+use app\controllers\Classroom_user;
+use app\controllers\cms\Course;
+use app\models\cms\Course_model;
+use app\extends\Cache_service;
+
+
+// Home/Welcome
+////////////////////////////////////////////////////////////////////////////////
+
+Route::add('/', function() {
+ Render::view('welcome', [
+ 'categories' => Cache_service::courses_struct()['tree'],
+ 'entity' => Cache_service::pages_list()
+ ]);
+ // need redirect?... header('Location: /some/default/url', true, 302);
+});
+
+
+// Error pages
+////////////////////////////////////////////////////////////////////////////////
+
+Route::notFound( function() { // 404 error page
+ header("HTTP/1.0 404 Not Found");
+ Render::view('error/404', ['message' => 'nobody knows it (but you got a secret smile;)']);
+});
+
+
+
+// Common content
+////////////////////////////////////////////////////////////////////////////////
+
+
+Route::add('/course/([0-9]*)', // request course by course-id
+ function($id) { Course::course($id); }
+);
+
+Route::add('/lesson/([0-9]*)', // request lesson by lesson-id
+ function($id) { Course::lesson($id); }
+);
+
+Route::add('/page/([0-9]*)', // request lesson by lesson-id
+ function($id) { Course::page($id); }
+);
+
+Route::add('/serve/file/([0-9a-zA-Z-_\.\/]*)', // serve file by path
+ function ($path) { Course::serve_file($path); } // (also ?type= is sent)
+);
+
+
+
+
+
+// Account
+///////////////////////////////////////////////////////////////////////////////////////////////
+
+// [ok] login
+// [ok] register
+// [ok] activate
+// [..] ask-reset
+// [..] reset
+// [..] profile
+// [..] edit-profile
+// [..] subscriptions
+// [..] payments
+// [..] pay
+// [..] order
+
+
+
+
+/** URL-format Proposals and common Route regex solutions
+ * -----------------------------------------------------------------------------
+ *
+ * Page (almost-static content):
+ * /about/{url}
+# Route::add('/about/([0-9a-zA-Z-_\/]*)', function($url) { Page::fromUrl($url); });
+ *
+ * Product:
+ * /{level-1}/{level-2}/{level-3}/{friendly-url}-{id}
+# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)',
+# function($category, $subcategory, $group, $label, $id) {
+# Product::fromID([$$category, $subcategory, $group, $label], $id);
+# }
+# );
+ *
+ * Category
+ * /{category}/[ {subcategory}[ /{group}]]
+# Route::add('/([0-9a-zA-Z-_]*)', function($a) { Category::url([$a]); };
+# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b) { Category::url([$a, $b]); });
+# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b, $c) { Category::url([$a, $b, $c]); });
+ *
+ * othet routes used in some user-cases
+
+# Route::add('/lesson/([0-9a-f]*)/([0-9a-zA-Z-_]*)',
+# function($ticket, $lesson) { Lesson::show([$lesson, $ticket]); }
+# );
+#
+# Route::add('/media/([0-9a-f]*)/([0-9a-zA-Z-_]*)/([0-9]*)/',
+# function($ticket, $type, $id) { Media::serve([$type, $id, $ticket]); }
+# );
+ *
+ * 4-th level paths belong to products
+# Route::add('/about/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)',
+# function($a, $b, $c) { Page::show([$a, $b, $c]); }
+# );
+ *
+ *
+ * OTHER EXAMPLES (use it for brainsrtorming)
+ * -----------------------------------------------------------------------------
+ *
+ *
+# // Typical Use
+# // ---
+# Route::add('/art', function() { Art::blah(); });
+# Route::add('/art/db', function() { Art::fromDatabase(); });
+# Route::add('/art/([0-9]*)', function($id) { Art::getInfo($id); });
+ *
+ * Get-Post route example
+# Route::add('/contact-form', function() {
+# echo '<form method="post"><input type="text" name="test" /><input type="submit" value="send" /></form>';
+# }, 'get');
+
+ Route::add('/contact-form', function() {
+ echo 'Hey! The form has been sent:<br/>'; print_r($_POST);
+ }, 'post');
+ *
+ * Accept number as parameter
+# Route::add('/foo/([0-9]*)/bar', function($var1) {
+# // echo $var1.' is a number!';
+ echo "{$var1} is a number!";
+# });
+ *
+ * About pages
+# Route::add('/about/([0-9a-zA-Z-_]*)', function($page) {
+# InfoPage::render('about/'.page);
+# });
+ *
+ * handle a request like: /foo/123/bar/3254-lefki-zaxari-marata-1kg
+ * where first-numeric-part of last-uri-section (3254) is the product number
+# Route::add('/foo/([0-9]*)/bar/([0-9]*)-([0-9a-zA-Z-_]*)', function($num, $id, $name) {
+# echo $num .' is some nomber, id = '. $id .' and label = '. $name;
+# });
+ *
+ * handle a request like: /zaxares-glykantika/lefki-zaxari-year-2022-45678
+ * where last-numeric-part of last-uri-section (45678) is the product number
+# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)',
+# function($category, $subcategory, $group, $label, $id) {
+# Shop::product([$$category, $subcategory, $group, $label], $id);
+# });
+ *
+ * last chance to resolve (some friendly url)
+# Route::add('/([0-9a-zA-Z-_]*)', function($a) { Resolve::uri([$a]); });
+# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b) { Resolve::uri([$a, $b]); });
+# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b, $c) { Resolve::uri([$a, $b, $c]); });
+ *
+ *
+ * Product page
+ * handle a request like: /pantopoleio/zaxares/lefki-zaxari/lefki-zaxari-year-2022-45678
+ * where last-numeric-part of last-uri-section (45678) is the product number
+# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)',
+# function($category, $subcategory, $group, $label, $id) {
+# Shop::product([$$category, $subcategory, $group, $label], $id);
+# });
+ *
+ * ------------------------------------------------------------------------------
+ */
diff --git a/public/app/routes/user.php b/public/app/routes/user.php
new file mode 100644
index 0000000..7ad0fa6
--- /dev/null
+++ b/public/app/routes/user.php
@@ -0,0 +1,84 @@
+<?php
+
+use app\controllers\Auth;
+use app\controllers\Classroom_user;
+
+/** User Connection Management Routes
+ * -----------------------------------------------------------------------------
+ */
+
+// common requests (GET method)
+// --- -- -- - - -
+
+// request login ... -> then sends to POST:/account/check-login
+Route::add('/login', function() { Render::view('user/login'); });
+
+// request registration ... -> then sends to POST:/account/register
+Route::add('/registration', function() { Render::view('user/registration'); });
+
+// request logout
+Route::add('/logout', function() {
+ Auth::logout();
+ header('Location: /'); die();
+});
+
+// request activation
+Route::add('/account/activate', function() { Auth::activate(); } );
+
+// request password reset
+Route::add('/account/reset_password', function() { Auth::reset_password(); } );
+
+
+
+// Replies to common requests (POST method)
+// --- -- -- - - -
+
+// user sends login form
+Route::add('/account/check-login', function() {
+ $response = Auth::login();
+ Render::json(['status' => $response]);
+ },
+ 'post'
+);
+
+// user sends a registration form
+Route::add('/account/register', function() {
+ $response = Auth::register();
+ Render::json($response);
+ },
+ 'post'
+);
+
+
+// Account Management
+// --- -- -- - - -
+
+// user profile
+Route::add('/account/profile', function() {
+ $user = Auth::is_connected();
+ if ($user === false) {
+ Render::view('error/general',
+ [
+ 'title' => 'Nope!',
+ 'message' => "<h2>No profile</h2>User is not connected"
+ ]
+ );
+
+ } else {
+ Render::json(['success' => true, 'status' => 'user is connected']);
+ }
+ }
+);
+
+
+// temporary (on development)
+// --- -- -- - --
+// NOTE: these is only for testing purposes
+
+// test connection
+if (!PRODUCTION) {
+ Route::add('/check/connection', function() { Auth::is_connected(); });
+}
+
+
+