From 1388a64651f1c61a6aafc32f8e3e60f7a6ffd339 Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Tue, 6 Jun 2023 00:46:19 +0300 Subject: admin petition ready --- public/app/config/setup_application.php | 34 +++++ public/app/controllers/Auth.php | 77 +++++++++- public/app/controllers/Office.php | 26 +++- public/app/models/Access_model.php | 37 ++++- public/app/models/Content_model.php | 5 +- public/app/routes/user.php | 43 +++++- public/app/views/admin/admin-menu.php | 47 ------ public/app/views/admin/categories.php | 91 ----------- public/app/views/admin/edit_lesson.php | 159 -------------------- public/app/views/admin/edit_page.php | 139 ----------------- public/app/views/admin/files.php | 96 ------------ public/app/views/admin/lessons.php | 126 ---------------- public/app/views/admin/pages.php | 109 -------------- public/app/views/admin/panel.php | 4 - public/app/views/admin/privileges.php | 93 ------------ public/app/views/admin/skeleton.php | 45 ------ public/app/views/components/menu.php | 2 +- public/app/views/js/submit/update-password.php | 61 ++++++++ public/app/views/js/submit/update-properties.php | 16 +- public/app/views/templates/admin_petitions.php | 135 +++++++++++++++++ public/app/views/user/new-password.php | 65 -------- public/app/views/user/update_password.php | 73 +++++++++ public/app/views/user/update_properties.php | 7 +- public/app/views/xx--admin/admin-menu.php | 47 ++++++ public/app/views/xx--admin/categories.php | 91 +++++++++++ public/app/views/xx--admin/edit_lesson.php | 159 ++++++++++++++++++++ public/app/views/xx--admin/edit_page.php | 139 +++++++++++++++++ public/app/views/xx--admin/files.php | 96 ++++++++++++ public/app/views/xx--admin/lessons.php | 126 ++++++++++++++++ public/app/views/xx--admin/pages.php | 109 ++++++++++++++ public/app/views/xx--admin/panel.php | 4 + public/app/views/xx--admin/privileges.php | 93 ++++++++++++ public/app/views/xx--admin/skeleton.php | 45 ++++++ public/assets/css/class.css | 3 +- public/assets/js/panel/admin_petitions.js | 184 +++++++++++++++++++++++ 35 files changed, 1592 insertions(+), 994 deletions(-) delete mode 100644 public/app/views/admin/admin-menu.php delete mode 100644 public/app/views/admin/categories.php delete mode 100644 public/app/views/admin/edit_lesson.php delete mode 100644 public/app/views/admin/edit_page.php delete mode 100644 public/app/views/admin/files.php delete mode 100644 public/app/views/admin/lessons.php delete mode 100644 public/app/views/admin/pages.php delete mode 100644 public/app/views/admin/panel.php delete mode 100644 public/app/views/admin/privileges.php delete mode 100644 public/app/views/admin/skeleton.php create mode 100644 public/app/views/js/submit/update-password.php create mode 100644 public/app/views/templates/admin_petitions.php delete mode 100644 public/app/views/user/new-password.php create mode 100644 public/app/views/user/update_password.php create mode 100644 public/app/views/xx--admin/admin-menu.php create mode 100644 public/app/views/xx--admin/categories.php create mode 100644 public/app/views/xx--admin/edit_lesson.php create mode 100644 public/app/views/xx--admin/edit_page.php create mode 100644 public/app/views/xx--admin/files.php create mode 100644 public/app/views/xx--admin/lessons.php create mode 100644 public/app/views/xx--admin/pages.php create mode 100644 public/app/views/xx--admin/panel.php create mode 100644 public/app/views/xx--admin/privileges.php create mode 100644 public/app/views/xx--admin/skeleton.php create mode 100644 public/assets/js/panel/admin_petitions.js diff --git a/public/app/config/setup_application.php b/public/app/config/setup_application.php index e7d2ca4..2c8b756 100644 --- a/public/app/config/setup_application.php +++ b/public/app/config/setup_application.php @@ -130,6 +130,8 @@ define('NOT_VALID_ACTIVATION_MESSAGE', 'Ο λογαριασμός δεν έχε define('ACCOUNT_UPDATED_TITLE','Ο λογαριασμός σας ενημερώθηκε!'); define('ACCOUNT_UPDATED_MESSAGE','Τώρα μπορείτε να επιστρέψετε στον πίνακα ελέγχου.'); +define('RETRY_SET_PASSWORD', 'Μπορείτε να ξαναδοκιμάσετε ή +
ή να επιστρέψετε στον πίνακα ελέγψου.'); @@ -204,6 +206,7 @@ define('GENDERED_ARTICLE',[ // gendered (grammar) articles + // the forms /////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- @@ -361,6 +364,37 @@ define('USER_PROPERTIES_FORM', [ ] ]); + + +define('SET_PASSWORD_FORM', [ + 'defaults' => [ + 'outer_class' => 'col-12', + 'inner_class' => 'form-control', + 'type' => 'text', + 'source' => '\app\controllers\User::current' + ], + 'form' => [ + [ + 'name' => 'oldpass', + 'label' => 'Τρέχον κωδικός πρόσβασης', + 'type' => 'password', + 'attributes' => ['required'] + ], + [ + 'name' => 'password', + 'label' => 'Νέος Κωδικός πρόσβασης', + 'type' => 'password', + 'attributes' => ['required'] + ], + [ + 'name' => 'confirm_password', + 'label' => 'Επαλήθευση νέου κωδικού πρόσβασης', + 'type' => 'password', + 'attributes' => ['required'] + ] + ] +]); + // Application (common request) form // --- define('APPLICATION_FORM', [ diff --git a/public/app/controllers/Auth.php b/public/app/controllers/Auth.php index 02a059f..f356dfe 100644 --- a/public/app/controllers/Auth.php +++ b/public/app/controllers/Auth.php @@ -23,7 +23,7 @@ class Auth { ## handle user's record / token / session ## ------------------------------------------------------------------------- - /** user from record + /** User from Record * * create and return a user based on the record of properties * @@ -94,7 +94,12 @@ class Auth { /** update session token + * ... for user by user-id * + * This method perfomes + * a new READ User's data from DataBase + * + * @param int $uid: user-id */ private static function reset_user_token($uid) { @@ -178,10 +183,9 @@ class Auth { } - /** AJAX POST: update_user * - * resolves call POST:/user/update_properties; + * resolves call POST:/user/update/properties; * updates user's proiperties with POSTed data * * @param void : all parametres passed via request->POST @@ -209,6 +213,46 @@ class Auth { } + /** AJAX POST: update_password + * + * resolves call POST:/user/update/password; + * updates user's proiperties with POSTed data + * + * @param void : all parametres passed via request->POST + */ + public static function update_password() + { + $req = Registry::get('REQUEST'); + $manager = new App_manager(); + $user = $manager->getUserToken()->getUser(); + + $record = Access_model::checkUser($user->get('email')); + + // confirm old-password + if ($manager->isPasswordValid($user, $req->POST['oldpass'])) { + + $check = Access_model::update_password( // then update pass + $user->getID(), + $manager->cryptPassword($req->POST['password']) + ); + + // user properties changed, so update user's session token + self::reset_user_token($user->getID()); + + Render::json([ + 'title' => ACCOUNT_UPDATED_TITLE, + 'message' => ACCOUNT_UPDATED_MESSAGE . ' (msg code: '. $check .')' + ]); + + } else { + Render::json([ + 'title' => 'Error', + 'message' => 'Λάθος Password
(msg code: 2)

'. RETRY_SET_PASSWORD + ]); + } + } + + ## serve user management forms ## ------------------------------------------------------------------------- @@ -311,6 +355,33 @@ class Auth { } + /** SERVE FORM: password_form + * + * renders a form for user to change password + * + * NOTE: + * after form is submited, client shall call Auth::update_user() + * + */ + public static function password_form() + { + $user = json_decode(json_encode(self::user_data(), JSON_UNESCAPED_UNICODE)); + + // format form_setup to a json array + $form_setup = json_decode(json_encode(SET_PASSWORD_FORM, JSON_UNESCAPED_UNICODE)); + + // get Form's HTML and Jsvascript + $form = JsonToForm::json_form($form_setup, [ + // pass invitation identity for security + ['name' => 'id', 'value' => $user->id] + ]); // print_r($form_setup); die(); + + Render::view('user/update_password', [ + 'form' => $form + ]); + } + + ## suplamentary methods ## ------------------------------------------------------------------------- diff --git a/public/app/controllers/Office.php b/public/app/controllers/Office.php index f57cf08..c67249a 100644 --- a/public/app/controllers/Office.php +++ b/public/app/controllers/Office.php @@ -327,9 +327,21 @@ class Office { + public static function all_petitions() + { + if (Auth::in_admin_group()) { + Render::json([ + 'success' => true, + 'data' => Content_model::all_petitions() + ]); + } + } + + + public static function petition_copy($sign) { - if (false) { //(Auth::in_admin_group()) { + if (Auth::in_admin_group()) { $petition = Content_model::get_petition(['signature' => $sign]); } else { @@ -407,7 +419,19 @@ class Office { ## ADMIN METHODS (insert, updated etc.) ## ------------------------------------------------------------------------- + /** set_protocol + * --- + */ + public static function set_protocol() + { + if (Auth::in_admin_group()) { + $post = Registry::get('REQUEST')->POST; + Content_model::set_protocol( $post['id'], $post['protocol'] ); + } + Render::json(['success' => true]); + } + /** files * echo all files * diff --git a/public/app/models/Access_model.php b/public/app/models/Access_model.php index 2d36285..c98b6c4 100644 --- a/public/app/models/Access_model.php +++ b/public/app/models/Access_model.php @@ -12,7 +12,7 @@ class Access_model ## User methods ## ------------------------------------------------------------------------- - /** check user (by index key) + /** check user (by index key = Email) * * @param $indexKey (string) : key for user identification * @param $value (string) @@ -135,8 +135,8 @@ class Access_model * * activate user and set password * - * @param $ticket (hex/MD5): activation code; - * + * @param array $post + * @param string $password: hased-password */ public static function activate_set_password($post, $password) { @@ -233,6 +233,37 @@ class Access_model } + /** update_password + * + * (re)set user's password + * + * @param int $id: user id + * @param string $hashpass: hashed password + */ + public static function update_password($uid, $hashpass) + { + // Update and set activate = true + $rowCount = Registry::use('database')->query( + "UPDATE user + SET `password` = :hashpass + WHERE id = :id", + [ + ':hashpass' => $hashpass, + ':id' => $uid + ] + )->rowCount(); + + // update history + if ($rowCount != 0) { + History_model::trackUserAccess( + $uid, TRACK_ACCOUNT, 'User password changed' + ); + } + + return $rowCount; + } + + ## Set permission methods ## ------------------------------------------------------------------------- diff --git a/public/app/models/Content_model.php b/public/app/models/Content_model.php index 1f145a0..cfe418f 100644 --- a/public/app/models/Content_model.php +++ b/public/app/models/Content_model.php @@ -91,7 +91,10 @@ class Content_model { public static function all_petitions() { return Registry::use('database')->runQuery( - "SELECT * FROM petition", + "SELECT petition.*, + CONCAT(user.last_name, ' ', user.first_name) as UserName + FROM petition + LEFT JOIN user ON user.id = petition.user_id", [] ); } diff --git a/public/app/routes/user.php b/public/app/routes/user.php index 2ecd3c1..e43eaa9 100644 --- a/public/app/routes/user.php +++ b/public/app/routes/user.php @@ -27,9 +27,9 @@ Route::add('/logout', function() { }); - -// request password reset -Route::add('/account/reset_password', function() { Auth::reset_password(); } ); +// TODO: +// // request password reset +// Route::add('/account/reset_password', function() { Auth::reset_password(); } ); // Replies to common requests (POST method) @@ -122,19 +122,34 @@ if (Auth::is_connected()) { // UPDATE user properties // ------------------------------------------------------------------------- - // request UPDADE FORM + // GET HTML: request UPDADE (properties) FORM // --- -- -- - - - Route::add('/user/update_form', function() { Auth::update_form(); }); - // update user (data via post) + // POST: update user (data via post) // --- -- -- - - - - Route::add('/user/update_properties', function() { + Route::add('/user/update/properties', function() { Auth::update_user(); }, 'post'); + // GET HTML: request (update) PASSWORD FORM + // --- -- -- - - - + Route::add('/user/password_form', function() { + Auth::password_form(); + }); + + // POST: update user (data via post) + // --- -- -- - - - + Route::add('/user/update/password', function() { + Auth::update_password(); + }, 'post'); + + + + // CRUD content // ------------------------------------------------------------------------- @@ -154,12 +169,24 @@ if (Auth::is_connected()) { if (Auth::in_admin_group()) { - // administer petitions + // GET HTML: administer petitions (page) // --- -- -- - - - Route::add('/admin/petitions', function() { - Render::view('user/panel'); + Render::view('templates/admin_petitions'); + }); + + + // GET JSON: request RESULTS list my petitions + Route::add('/admin/get/petitions', function() { + Office::all_petitions(); }); + + // POST AJAX: set petition protocol + Route::add('/admin/set/protocol', function() { + Office::set_protocol(); + }, 'post'); + // invite user(s) // --- -- -- - - - Route::add('/admin/invite', function() { diff --git a/public/app/views/admin/admin-menu.php b/public/app/views/admin/admin-menu.php deleted file mode 100644 index 52e8522..0000000 --- a/public/app/views/admin/admin-menu.php +++ /dev/null @@ -1,47 +0,0 @@ - 'posts', - * 'id' => 4 - * ]) - * ----------------------------------------------------------------------------- - */ - -$admin_options = [ - 'panel' => 'Διαχείριση', - 'edit_lesson' => 'Νέο Μάθημα', - 'lessons' => 'Μαθήματα', - 'categories' => 'Κεφάλαια', - 'pages' => 'Σελίδες', - 'files' => 'Αρχεία', - 'privileges' => 'Πρόσβαση', - 'users' => 'Χρήστες' -]; -?> - -
- - $label) : ?> - - - - - - - - - - - - Logout - -
\ No newline at end of file diff --git a/public/app/views/admin/categories.php b/public/app/views/admin/categories.php deleted file mode 100644 index 26fd5a2..0000000 --- a/public/app/views/admin/categories.php +++ /dev/null @@ -1,91 +0,0 @@ - -
-
Διαχείριση Κατηγοριών
-
- - -
-
- -
-
-
- -
- - - - - - -
Κατηγορία/Κεφάλαιο
- -
- - -
-
-
- - - - - - diff --git a/public/app/views/admin/edit_lesson.php b/public/app/views/admin/edit_lesson.php deleted file mode 100644 index ef875b4..0000000 --- a/public/app/views/admin/edit_lesson.php +++ /dev/null @@ -1,159 +0,0 @@ - - - -
-
-
- -
-
- - -
-
-
- - -
- - - - - - -
- -
- -
-
- -
- -
- -
-
- - -
- -
- -
-
- -
- -
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- - - - -
    -
- -
-
- - -
- -
-
-
- - -
- -
- -
- -
-
- - -
- -
- -
- -
- -
- -
- -
- - - -
-
- - - - - diff --git a/public/app/views/admin/edit_page.php b/public/app/views/admin/edit_page.php deleted file mode 100644 index 46c47bc..0000000 --- a/public/app/views/admin/edit_page.php +++ /dev/null @@ -1,139 +0,0 @@ - - - -
-
-
- -
-
- - -
-
-
- - -
- - - - - - -
- -
- -
-
- - -
- -
- -
-
- -
- -
- -
- -
- -
-
- -
- -
- - - - -
    -
- -
-
- - - - - -
- -
- -
- -
-
- - -
- -
- -
- -
- -
- -
- -
- - - -
-
- - - - - diff --git a/public/app/views/admin/files.php b/public/app/views/admin/files.php deleted file mode 100644 index c6d2771..0000000 --- a/public/app/views/admin/files.php +++ /dev/null @@ -1,96 +0,0 @@ - -
-
Διαχείριση Επιπέδων Πρόσβασης
-
- -
-
- -
-
-
- -
- - - - - - - - - - -
α/αΠεριγραφήΔιαδρομήMedia-TypeΠρόσβαση
- -
- - -
-
-
- - - - - - diff --git a/public/app/views/admin/lessons.php b/public/app/views/admin/lessons.php deleted file mode 100644 index d1cd3ae..0000000 --- a/public/app/views/admin/lessons.php +++ /dev/null @@ -1,126 +0,0 @@ - -
-
Διαχείριση Μαθημάτων
-
- - -   Νέο Μάθημα - -
-
- -
-
-
- -
- - - - - - - - - -
α/αΤίτλοςΚεφάλαιοΠρόσβαση
- -
- -
-
-
- - - - - - diff --git a/public/app/views/admin/pages.php b/public/app/views/admin/pages.php deleted file mode 100644 index dd8f954..0000000 --- a/public/app/views/admin/pages.php +++ /dev/null @@ -1,109 +0,0 @@ - -
-
Διαχείριση Μαθημάτων
-
- - -   Νέα Σελίδα - -
-
- -
-
-
- -
- - - - - - - -
α/αΤίτλος
- -
- -
-
-
- - - - - - diff --git a/public/app/views/admin/panel.php b/public/app/views/admin/panel.php deleted file mode 100644 index 59b8cba..0000000 --- a/public/app/views/admin/panel.php +++ /dev/null @@ -1,4 +0,0 @@ -
-
-
-

Admin panel

\ No newline at end of file diff --git a/public/app/views/admin/privileges.php b/public/app/views/admin/privileges.php deleted file mode 100644 index 587c363..0000000 --- a/public/app/views/admin/privileges.php +++ /dev/null @@ -1,93 +0,0 @@ - -
-
Διαχείριση Επιπέδων Πρόσβασης
-
- - -
-
- -
-
-
- -
- - - - - - - - -
ΚωδικόςΕπίπεδο ΠρόσβασηςΠεριλαμβάνει
- -
- - -
-
-
- - - - - - diff --git a/public/app/views/admin/skeleton.php b/public/app/views/admin/skeleton.php deleted file mode 100644 index 927bd2d..0000000 --- a/public/app/views/admin/skeleton.php +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - Classroom - <?=$title?> - - true] - ); - ?> - - - - - -
- - $action, - 'id' => $id - ]); - - // render main content - //////////////////////////////////////////////////////////////////// - Render::view("admin/{$action}",[ 'id' => $id ]); //////////////// - ?> -
- - - - - - - diff --git a/public/app/views/components/menu.php b/public/app/views/components/menu.php index 3e1748d..30ed673 100644 --- a/public/app/views/components/menu.php +++ b/public/app/views/components/menu.php @@ -16,7 +16,7 @@
  • Προφίλ
  • Ενημέρωση στοιχείων
  • -
  • Αλλαγή password
  • +
  • Αλλαγή password
  • Διαχείριση
  • diff --git a/public/app/views/js/submit/update-password.php b/public/app/views/js/submit/update-password.php new file mode 100644 index 0000000..625d7cd --- /dev/null +++ b/public/app/views/js/submit/update-password.php @@ -0,0 +1,61 @@ + \ No newline at end of file diff --git a/public/app/views/js/submit/update-properties.php b/public/app/views/js/submit/update-properties.php index 651ef3e..f793619 100644 --- a/public/app/views/js/submit/update-properties.php +++ b/public/app/views/js/submit/update-properties.php @@ -24,7 +24,7 @@ }; console.log(data); - var request = '/user/update_properties'; // set action url + var request = '/user/update/properties'; // set action url // send POST request $.post(request, data) @@ -34,5 +34,19 @@ }); + + + // go-back event + //////////////////////////////////////////////////////////////////////////// + + $('.btn-back2panel').click( event => { + event.preventDefault(); + + let confirm_exit = confirm(''); + if (confirm_exit) { + window.location.href = '/panel'; + } + }); + }); \ No newline at end of file diff --git a/public/app/views/templates/admin_petitions.php b/public/app/views/templates/admin_petitions.php new file mode 100644 index 0000000..59c85f6 --- /dev/null +++ b/public/app/views/templates/admin_petitions.php @@ -0,0 +1,135 @@ + + + + + <?=SITE_TITLE?> - Control Panel + + + + + + +
    +
    + +
    + +
    + +
    +
    +
    Διαχείριση Αιτήσεων και Δοικητικών Εγγράφων
    + +
    + +
    + + +
    +
    + +
    + + + + + + + + + + + +
    ΘέμαΑρ.ΠρωτόκολλουΧρήστηςΗμερ. Καταχώρισης
    + +
    + +
    +
    + +
    + +
    + +
    +
    + + + + + + + + + + + + + + diff --git a/public/app/views/user/new-password.php b/public/app/views/user/new-password.php deleted file mode 100644 index 06e7fac..0000000 --- a/public/app/views/user/new-password.php +++ /dev/null @@ -1,65 +0,0 @@ - - - - - <?=SITE_TITLE?> - Επαναφορά κωδικού πρόσβασης - - - - - - - - - - - - -
    -
    -

    Επαναφορά κωδικού πρόσβασης

    -
    -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - -
    -
    -
    - - diff --git a/public/app/views/user/update_password.php b/public/app/views/user/update_password.php new file mode 100644 index 0000000..38494ad --- /dev/null +++ b/public/app/views/user/update_password.php @@ -0,0 +1,73 @@ + + + + + <?=SITE_TITLE?> - Αλλαγή Password + + + + + +
    +
    + +
    +
    +
    +

    + Αλλαγή Password + +

    +
    + + + +
    + + +
    +
    +
    + +
    +
    + + + + + + + + + + + diff --git a/public/app/views/user/update_properties.php b/public/app/views/user/update_properties.php index f10e36b..7da976d 100644 --- a/public/app/views/user/update_properties.php +++ b/public/app/views/user/update_properties.php @@ -17,7 +17,12 @@
    -

    Ενημέρωση στοιχείων

    +

    + Ενημέρωση στοιχείων + +


    diff --git a/public/app/views/xx--admin/admin-menu.php b/public/app/views/xx--admin/admin-menu.php new file mode 100644 index 0000000..52e8522 --- /dev/null +++ b/public/app/views/xx--admin/admin-menu.php @@ -0,0 +1,47 @@ + 'posts', + * 'id' => 4 + * ]) + * ----------------------------------------------------------------------------- + */ + +$admin_options = [ + 'panel' => 'Διαχείριση', + 'edit_lesson' => 'Νέο Μάθημα', + 'lessons' => 'Μαθήματα', + 'categories' => 'Κεφάλαια', + 'pages' => 'Σελίδες', + 'files' => 'Αρχεία', + 'privileges' => 'Πρόσβαση', + 'users' => 'Χρήστες' +]; +?> + +
    + + $label) : ?> + + + + + + + + + + + + Logout + +
    \ No newline at end of file diff --git a/public/app/views/xx--admin/categories.php b/public/app/views/xx--admin/categories.php new file mode 100644 index 0000000..26fd5a2 --- /dev/null +++ b/public/app/views/xx--admin/categories.php @@ -0,0 +1,91 @@ + +
    +
    Διαχείριση Κατηγοριών
    +
    + + +
    +
    + +
    +
    +
    + +
    + + + + + + +
    Κατηγορία/Κεφάλαιο
    + +
    + + +
    +
    +
    + + + + + + diff --git a/public/app/views/xx--admin/edit_lesson.php b/public/app/views/xx--admin/edit_lesson.php new file mode 100644 index 0000000..ef875b4 --- /dev/null +++ b/public/app/views/xx--admin/edit_lesson.php @@ -0,0 +1,159 @@ + + + +
    +
    +
    + +
    +
    + + +
    +
    +
    + + +
    + + + + + + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + + +
    + +
    + +
    +
    + +
    + +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + + + + +
      +
    + +
    +
    + + +
    + +
    +
    +
    + + +
    + +
    + +
    + +
    +
    + + +
    + +
    + +
    + +
    + +
    + +
    + +
    + + + +
    +
    + + + + + diff --git a/public/app/views/xx--admin/edit_page.php b/public/app/views/xx--admin/edit_page.php new file mode 100644 index 0000000..46c47bc --- /dev/null +++ b/public/app/views/xx--admin/edit_page.php @@ -0,0 +1,139 @@ + + + +
    +
    +
    + +
    +
    + + +
    +
    +
    + + +
    + + + + + + +
    + +
    + +
    +
    + + +
    + +
    + +
    +
    + +
    + +
    + +
    + +
    + +
    +
    + +
    + +
    + + + + +
      +
    + +
    +
    + + + + + +
    + +
    + +
    + +
    +
    + + +
    + +
    + +
    + +
    + +
    + +
    + +
    + + + +
    +
    + + + + + diff --git a/public/app/views/xx--admin/files.php b/public/app/views/xx--admin/files.php new file mode 100644 index 0000000..c6d2771 --- /dev/null +++ b/public/app/views/xx--admin/files.php @@ -0,0 +1,96 @@ + +
    +
    Διαχείριση Επιπέδων Πρόσβασης
    +
    + +
    +
    + +
    +
    +
    + +
    + + + + + + + + + + +
    α/αΠεριγραφήΔιαδρομήMedia-TypeΠρόσβαση
    + +
    + + +
    +
    +
    + + + + + + diff --git a/public/app/views/xx--admin/lessons.php b/public/app/views/xx--admin/lessons.php new file mode 100644 index 0000000..d1cd3ae --- /dev/null +++ b/public/app/views/xx--admin/lessons.php @@ -0,0 +1,126 @@ + +
    +
    Διαχείριση Μαθημάτων
    + +
    + +
    +
    +
    + +
    + + + + + + + + + +
    α/αΤίτλοςΚεφάλαιοΠρόσβαση
    + +
    + +
    +
    +
    + + + + + + diff --git a/public/app/views/xx--admin/pages.php b/public/app/views/xx--admin/pages.php new file mode 100644 index 0000000..dd8f954 --- /dev/null +++ b/public/app/views/xx--admin/pages.php @@ -0,0 +1,109 @@ + +
    +
    Διαχείριση Μαθημάτων
    + +
    + +
    +
    +
    + +
    + + + + + + + +
    α/αΤίτλος
    + +
    + +
    +
    +
    + + + + + + diff --git a/public/app/views/xx--admin/panel.php b/public/app/views/xx--admin/panel.php new file mode 100644 index 0000000..59b8cba --- /dev/null +++ b/public/app/views/xx--admin/panel.php @@ -0,0 +1,4 @@ +
    +
    +
    +

    Admin panel

    \ No newline at end of file diff --git a/public/app/views/xx--admin/privileges.php b/public/app/views/xx--admin/privileges.php new file mode 100644 index 0000000..587c363 --- /dev/null +++ b/public/app/views/xx--admin/privileges.php @@ -0,0 +1,93 @@ + +
    +
    Διαχείριση Επιπέδων Πρόσβασης
    +
    + + +
    +
    + +
    +
    +
    + +
    + + + + + + + + +
    ΚωδικόςΕπίπεδο ΠρόσβασηςΠεριλαμβάνει
    + +
    + + +
    +
    +
    + + + + + + diff --git a/public/app/views/xx--admin/skeleton.php b/public/app/views/xx--admin/skeleton.php new file mode 100644 index 0000000..927bd2d --- /dev/null +++ b/public/app/views/xx--admin/skeleton.php @@ -0,0 +1,45 @@ + + + + + + Classroom - <?=$title?> + + true] + ); + ?> + + + + + +
    + + $action, + 'id' => $id + ]); + + // render main content + //////////////////////////////////////////////////////////////////// + Render::view("admin/{$action}",[ 'id' => $id ]); //////////////// + ?> +
    + + + + + + + diff --git a/public/assets/css/class.css b/public/assets/css/class.css index 81be1f2..d1e7715 100644 --- a/public/assets/css/class.css +++ b/public/assets/css/class.css @@ -84,7 +84,7 @@ html, body { .btn-back2panel, .btn-preview { border: 1px solid #aaa7; background: #ddd; } -.btn-back2panel { float: right; } +.btn-back2panel { float: right; margin-top: calc(-1 * var(--bs-btn-padding-y)); } .btn-back2panel:hover, .btn-preview:hover { border: 1px solid #7777; background: #f5f5f5; } @@ -201,3 +201,4 @@ html, body { } .image-credits a:hover { color: var(--img-credit-hover-color); } +.manage .table tbody tr:hover { background: #eeea; } \ No newline at end of file diff --git a/public/assets/js/panel/admin_petitions.js b/public/assets/js/panel/admin_petitions.js new file mode 100644 index 0000000..7b65f10 --- /dev/null +++ b/public/assets/js/panel/admin_petitions.js @@ -0,0 +1,184 @@ +// Globals +// ----------------------------------------------------------------------------- +var petitions = []; +var table; + + + +// Supplamentary functions +// ----------------------------------------------------------------------------- + +// array.indexOf polyfill +// --- -- -- - - - +if (!Array.prototype.indexOf) +{ + Array.prototype.indexOf = function(elt /*, from*/) + { + var len = this.length >>> 0; + + var from = Number(arguments[1]) || 0; + from = (from < 0) + ? Math.ceil(from) + : Math.floor(from); + if (from < 0) + from += len; + + for (; from < len; from++) + { + if (from in this && + this[from] === elt) + return from; + } + return -1; + }; +} + + +// return petitions record by petition-id +// --- -- -- - - - +function petition_record(id) { + var record = false; + petitions.forEach(el => { if (el.id == id) record = el; }); + + return record; +} + + +// create actions html (edit and delete buttons) +// --- -- -- - - - +function create_actions_html(id, signature) { + + var del, edit, show; + + del = ""; + edit = [ + '' + ].join('\n'); + + show = [ + '', + '', + '' + ].join('\n'); + + return show +' '+ edit +' '+ del; +} + + + +$(document).ready(function() { + + // When document is ready + // ------------------------------------------------------------------------- + + + /** init_table + * --- -- -- - - - + * get categories + * constuct categories array + * render dataTable + */ + function init_table() { + + // get all categories from server (ajax) + $.getJSON( "/admin/get/petitions") + .done(function( json ) { + // then ... + console.log(json); + + // reset categories + petitions.length = 0; + + // construct petitions data + json.data.forEach( el => { + petitions.push({ + id: parseInt(el.id), + subject: el.subject, + protocol: el.protocol, + username: el.UserName, + signature: el.signature, + datepost: el.creation_date, + actions: create_actions_html(el.id, el.signature) + }); + }); + + + // destroy previous datatable table instances + $('#dt-petitions').dataTable().fnClearTable(); + $('#dt-petitions').dataTable().fnDestroy(); + + // (re-)create categories datatable + table = $('#dt-petitions').DataTable({ + language: { url: '/assets/js/DataTables/localization/Greek.json' }, + data: petitions, + // ordering: false, + columns: [ + { data: 'subject', width: '42%' }, + { data: 'protocol' }, + { data: 'username' }, + // { data: 'signature' }, + { data: 'datepost' }, + { data: 'actions', width: '96px' } + ] + }); + + }) + .fail(function( jqxhr, textStatus, error ) { + console.log( "Request Failed (" + error +")" ); + }); + + } + init_table(); // init table on first run + + + + /** When modal show-up + * ------------------------------------------------------------------------- + * ... prepare the manage-category form + * ... update select2 with possible parents + */ + $('#managePetition').on('show.bs.modal', event => { + var button = $(event.relatedTarget); // Button that triggered the modal + var id = parseInt( button.data('id') ); // category_id from data-id + // var modal = $(this); // modal object + var petition = petition_record(id) + + $('#managePetition form input[name=protocol]').val( + petition.protocol ? petition.protocol : '' + ); + $('#managePetition form input[name=id]').val( id ); // category id (hidden) + }) + + + + // When form is submited + // ------------------------------------------------------------------------- + + $('#managePetition form').submit( event => { + event.preventDefault(); + + // prepare data to POST + var data = { + id: parseInt($('#managePetition form input[name=id]').val()), + protocol: $('#managePetition form input[name=protocol]').val() }; + + // select action url (add or update) + var request = '/admin/set/protocol'; + + // send POST request + $.post(request, data) + .done(function( data ) { + + $('#managePetition').modal('hide'); // when done, close modal + + init_table(); // reload table of categories + }); + + }); + +}); -- cgit v1.2.3