From 864fbb806621c8167c49f7449486fbc3bdaca1a6 Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Thu, 1 Jun 2023 03:33:18 +0300 Subject: user update; user petitions copy; fixed docker performance issues --- Dockerfile | 20 +-- Roadmap.md | 53 ++++++ public/app/config/setup_application.php | 70 ++++++++ public/app/controllers/Auth.php | 82 ++++++++- public/app/controllers/Office.php | 20 +++ public/app/models/Access_model.php | 54 +++++- public/app/models/Content_model.php | 30 ++++ public/app/routes/user.php | 21 ++- public/app/views/components/header_includes.php | 96 +++++------ public/app/views/components/menu.php | 4 +- public/app/views/components/own_petitions.php | 32 ++-- public/app/views/js/submit/application-form.php | 3 +- public/app/views/js/submit/penalty-form.php | 3 +- public/app/views/js/submit/update-properties.php | 38 +++++ public/app/views/templates/create_pdf.php | 69 ++++++++ public/app/views/user/panel.php | 13 +- public/app/views/user/update_properties.php | 70 ++++++++ public/assets/css/class.css | 17 +- public/assets/css/overides.css | 124 +++++++------- .../assets/js/DataTables/localization/Greek.json | 29 ++++ public/assets/js/panel/info.js | 1 + public/assets/js/panel/own_petitions.js | 183 +++++++++++++++++++++ 22 files changed, 861 insertions(+), 171 deletions(-) create mode 100644 Roadmap.md create mode 100644 public/app/views/js/submit/update-properties.php create mode 100644 public/app/views/templates/create_pdf.php create mode 100644 public/app/views/user/update_properties.php create mode 100644 public/assets/js/DataTables/localization/Greek.json create mode 100644 public/assets/js/panel/info.js create mode 100644 public/assets/js/panel/own_petitions.js diff --git a/Dockerfile b/Dockerfile index 16662a1..8d4e76b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,9 +25,6 @@ ARG MODE="debug" # } >> /usr/local/etc/php-fpm.d/www.conf - - - # setup apache # ------------------------------------------------------------------------------ @@ -111,18 +108,15 @@ RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/a # (+) run once after ex. 4 minutes - # Install XDebug (only for develop/debud modes) # ------------------------------------------------------------------------------ -RUN apt-get install -y apt-utils \ - && pecl install xdebug \ - && docker-php-ext-enable xdebug - -COPY docker/config/php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini -RUN touch /usr/local/etc/php/xdebug.log -RUN chown www-data:www-data /usr/local/etc/php/xdebug.log -RUN chmod 664 /usr/local/etc/php/xdebug.log - +# RUN apt-get install -y apt-utils \ +# && pecl install xdebug \ +# && docker-php-ext-enable xdebug +# COPY docker/config/php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +# RUN touch /usr/local/etc/php/xdebug.log +# RUN chown www-data:www-data /usr/local/etc/php/xdebug.log +# RUN chmod 664 /usr/local/etc/php/xdebug.log # Prepare the entrypoint as in the original image diff --git a/Roadmap.md b/Roadmap.md new file mode 100644 index 0000000..31ff302 --- /dev/null +++ b/Roadmap.md @@ -0,0 +1,53 @@ +# Roadmap + + +## Feature list + +Firse I need to list all features and optimizations that the framework +should/could have + + +Sophisticated ***Object Relational Mapper*** (ORM) +* needs to be extremely light and fast +* (?) coded as an abstruct model class +* (?) implement the Factory design pattern +* method names shall be the same as in Laravel +* (?) or use existing [riverside/php-orm](https://github.com/riverside/php-orm) + + +Core ***Database Abstraction Layer*** (DBAL) + + +Implement a ***lighter docker image***; check: +* https://docs.bitnami.com/tutorials/develop-http-api-php-containers/ +* https://github.com/8ctopus/apache-php-fpm-alpine + + +Core ***Log interface*** and a few Log-implementations +* File based +* Slack channel +* Databased + + +Deeper and more ***intelligent error handling*** for easy debuging + + +***Advanced CLI interface*** + + +An ***Auth/Auth2.0 authenticator*** + + +***Basket interface*** + + +***Payment interface*** + + + + + +## Short term goals + +unknown; +development shall restart after 2023-07-24; diff --git a/public/app/config/setup_application.php b/public/app/config/setup_application.php index 068c8a8..f56cc1a 100644 --- a/public/app/config/setup_application.php +++ b/public/app/config/setup_application.php @@ -283,6 +283,76 @@ define('REGISTRATION_FORM', [ ] ]); + + +define('USER_PROPERTIES_FORM', [ + 'defaults' => [ + 'outer_class' => 'col-12', + 'inner_class' => 'form-control', + 'type' => 'text', + 'source' => '\app\controllers\User::current' + ], + 'form' => [ + [ + 'name' => 'first_name', + 'label' => 'Όνομα', + 'attributes' => ['required', 'auto'] + ], + [ + 'name' => 'last_name', + 'label' => 'Επίθετο', + 'attributes' => ['required', 'auto'] + ], + [ + 'name' => 'email', + 'label' => 'Email', + 'type' => 'email', + 'attributes' => ['required', 'auto'] + ], + [ + 'name' => 'father_name', + 'label' => 'Πατρώνυμο', + 'attributes' => ['required', 'auto'] + ], + [ + 'name' => 'registration_number', + 'label' => 'Αριθμός μητρώου', + 'class' => 'col-8', + 'attributes' => ['required', 'auto'] + ], + [ + 'name' => 'sector', + 'label' => 'Κλάδος / Ειδικότητα', + 'type' => 'select', + 'attributes' => ['required', 'auto'], + 'options' => TEACHER_SECTORS + ], + [ + 'name' => 'belonging_school', + 'label' => 'Σχολείο τοποθέτησης', + 'attributes' => ['required', 'auto'] + ], + // [ // working school = (obviously) is the current school + // 'name' => 'working_school', + // 'label' => 'Σχολείο εργασίας', + // 'attributes' => ['required'] + // ], + [ + 'name' => 'position', + 'label' => 'Θέση', + 'type' => 'select', + 'attributes' => ['required', 'auto'], + 'options' => [] + ], + [ + 'name' => 'phone', + 'label' => 'Τηλέφωνο', + 'class' => 'col-8', + 'attributes' => ['required', 'auto'] + ] + ] +]); + // Application (common request) form // --- define('APPLICATION_FORM', [ diff --git a/public/app/controllers/Auth.php b/public/app/controllers/Auth.php index 9f440ed..cbf4d19 100644 --- a/public/app/controllers/Auth.php +++ b/public/app/controllers/Auth.php @@ -20,7 +20,7 @@ use app\extends\SendMail_service; */ class Auth { - /** login + /** AJAX POST: login * * checks visitor's credentials; * if valid, authenticates user @@ -98,7 +98,7 @@ class Auth { } - /** activate + /** AJAX POST: activate * resolves call POST:/account/activate * * @param void : all parametres passed via request->POST @@ -118,20 +118,50 @@ class Auth { if ($check != 0) { Render::json([ 'title' => ACCOUNT_ACTIVATED_TITLE, - 'message' => ACCOUNT_ACTIVATED_MESSAGE . '
(msg code: '. $check .')' + 'message' => ACCOUNT_ACTIVATED_MESSAGE . '
(msg code: '. $check .')' ]); } else { Render::json([ 'title' => NOT_VALID_ACTIVATION_TITLE, - 'message' => NOT_VALID_ACTIVATION_MESSAGE + 'message' => NOT_VALID_ACTIVATION_MESSAGE ]); } } - /** invitation + + /** AJAX POST: update_user + * + * resolves call POST:/user/update_properties; + * updates user's proiperties with POSTed data + * + * @param void : all parametres passed via request->POST + */ + public static function update_user() + { + $req = Registry::get('REQUEST'); + $manager = new App_manager(); + ; + // print_r($req->POST); die(); + + // ask model to update user; get user-id from user-manager + $check = Access_model::update_user( + $req->POST, + $manager->getUserToken()->getUser()->getID() + ); + + // TODO: message for user updating properties + Render::json([ + 'title' => ACCOUNT_ACTIVATED_TITLE, + 'message' => ACCOUNT_ACTIVATED_MESSAGE . '
(msg code: '. $check .')' + ]); + + } + + + /** SERVE FORM: invitation * * setups and renders the form for a certain invitation * @@ -188,6 +218,48 @@ class Auth { } + /** SERVE FORM: update_form + * + * renders a form with all user's properties + * + * NOTE: + * after form is submited, client shall call Auth::update_user() + * + */ + public static function update_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(USER_PROPERTIES_FORM, JSON_UNESCAPED_UNICODE)); + + // get $key of position item inside the form_setup->form array + for( $i=0; $i < sizeof($form_setup->form) ; $i++ ) { + if ($form_setup->form[$i]->name == 'position') { $key = $i; } + } + + // prepare gendered options to position field + $positions = ($user->prefix != 'η') + ? GENDERED_POSITIONS['he'] + : GENDERED_POSITIONS['she']; + $gendered_position = json_decode( json_encode( $positions, JSON_UNESCAPED_UNICODE )); + $form_setup->form[$key]->options = $gendered_position; + + // attach default values + $form_setup->defaults = $user; + + // 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_properties', [ + 'form' => $form + ]); + } + + /** is_connected * checks if the user is connected * diff --git a/public/app/controllers/Office.php b/public/app/controllers/Office.php index 83135de..f57cf08 100644 --- a/public/app/controllers/Office.php +++ b/public/app/controllers/Office.php @@ -327,6 +327,26 @@ class Office { + public static function petition_copy($sign) + { + if (false) { //(Auth::in_admin_group()) { + $petition = Content_model::get_petition(['signature' => $sign]); + + } else { + $manager = new App_manager(); + $petition = Content_model::get_petition([ + 'signature' => $sign, + 'user_id' => $manager->getUserToken()->getUser()->getID() + ]); + } + if ($petition === false) Render::view('error/404'); + else { + Render::view( 'templates/create_pdf',['petition' => $petition]); + } + } + + + ## TICKET METHODS (create, remove) ## tickets eliminate CSRF attacks ## ------------------------------------------------------------------------- diff --git a/public/app/models/Access_model.php b/public/app/models/Access_model.php index 844ff6b..5c9f991 100644 --- a/public/app/models/Access_model.php +++ b/public/app/models/Access_model.php @@ -41,7 +41,7 @@ class Access_model { return Registry::use('database')->query( "SELECT * FROM user WHERE invitation = :invitation", - ['invitation' => $invitation] + [ 'invitation' => $invitation ] )->getFirst(); } @@ -166,6 +166,58 @@ class Access_model + /** update_user + * + * activate user and set password + * + * @param array $post; + * @param int $id: user id + */ + public static function update_user($post, $id) + { + // Update and set activate = true + $rowCount = Registry::use('database')->query( + "UPDATE user + SET first_name = :first_name, + last_name = :last_name, + email = :email, + father_name = :father_name, + registration_number = :registration_number, + sector = :sector, + belonging_school = :belonging_school, + position = :position, + phone = :phone, + invitation = NULL, + active = :active + WHERE id = :id", + [ + ':first_name' => $post['first_name'], + ':last_name' => $post['last_name'], + ':email' => $post['email'], + ':father_name' => $post['father_name'], + ':registration_number' => $post['registration_number'], + ':sector' => $post['sector'], + ':belonging_school' => $post['belonging_school'], + ':position' => $post['position'], + ':phone' => $post['phone'], + ':active' => 1, + ':id' => $id + ] + )->rowCount(); + + // update history + if ($rowCount != 0) { + History_model::trackUserAccess( + $id, TRACK_ACCOUNT, 'User properties changed' + ); + } + + return $rowCount; + + } + + + ## Set permission methods ## ------------------------------------------------------------------------- diff --git a/public/app/models/Content_model.php b/public/app/models/Content_model.php index 2a79159..1f145a0 100644 --- a/public/app/models/Content_model.php +++ b/public/app/models/Content_model.php @@ -73,6 +73,7 @@ class Content_model { 'subject' => $rec['subject'], 'signature' => $rec['signature'], 'protocol' => $rec['protocol'] ?? '', + 'creation_date' => date("Y-m-d", strtotime($rec['creation_date'])), 'form_structure' => unserialize($rec['form_structure']) ]; } @@ -96,6 +97,35 @@ class Content_model { } + public static function get_petition($filters) + { + $where = []; + $binds = []; + foreach($filters as $key => $val) { + $where[] = $key ." = :". $key; + $binds[':'.$key] = $val; + } + + $rec = Registry::use('database')->query( + "SELECT * FROM petition WHERE ". implode(" AND ", $where), + $filters + )->getFirst(); + + if ($rec === false) return false; + else { + return [ + 'id' => $rec['id'], + 'type' => (($rec['type_id'] == 1) ? 'application' : 'penalty'), + 'subject' => $rec['subject'], + 'signature' => $rec['signature'], + 'protocol' => $rec['protocol'] ?? false, + 'creation_date' => date("Y-m-d", strtotime($rec['creation_date'])), + 'form_structure' => unserialize($rec['form_structure']) + ]; + } + } + + ## F I L E S ## ------------------------------------------------------------------------- diff --git a/public/app/routes/user.php b/public/app/routes/user.php index 4a09801..2ecd3c1 100644 --- a/public/app/routes/user.php +++ b/public/app/routes/user.php @@ -111,13 +111,30 @@ if (Auth::is_connected()) { Office::request_petition($tag); }); - // request EXISTING PETITION + // request EXISTING petition copy // --- -- -- - - - Route::add('/petition/signature/([0-9a-f]*)', function($signature) { - Office::filter_request_petition($signature); + Office::petition_copy($signature); }); + + // UPDATE user properties + // ------------------------------------------------------------------------- + + // request UPDADE FORM + // --- -- -- - - - + Route::add('/user/update_form', function() { + Auth::update_form(); + }); + + // update user (data via post) + // --- -- -- - - - + Route::add('/user/update_properties', function() { + Auth::update_user(); + }, 'post'); + + // CRUD content // ------------------------------------------------------------------------- diff --git a/public/app/views/components/header_includes.php b/public/app/views/components/header_includes.php index c20811b..0600450 100644 --- a/public/app/views/components/header_includes.php +++ b/public/app/views/components/header_includes.php @@ -4,12 +4,15 @@ } ?> - - - + + + + --> + */ +?> @@ -20,7 +23,9 @@ - + + @@ -31,7 +36,10 @@ - + + + @@ -42,7 +50,10 @@ - + + + @@ -50,20 +61,12 @@ - - - + - + + @@ -71,36 +74,37 @@ + \ No newline at end of file + original date: Fri Jan 29 2021 23:16:11 GMT-0600 (Central Standard Time) + UTC date string: Sat, 30 Jan 2021 05:16:11 GMT + UTC date string Date constructor: Fri Jan 29 2021 23:16:11 GMT-0600 (Central Standard Time) + UTC date string Date constructor (without 'GMT*'): Sat Jan 30 2021 23:16:11 GMT-0600 (Central Standard Time) + UTC date number: 30 + UTC modified date: Sat Jan 30 2021 23:16:11 GMT-0600 (Central Standard Time) + --> +*/ \ No newline at end of file diff --git a/public/app/views/components/menu.php b/public/app/views/components/menu.php index 524547c..3e1748d 100644 --- a/public/app/views/components/menu.php +++ b/public/app/views/components/menu.php @@ -15,8 +15,8 @@
  • Πρακτικά και αιτήσεις
  • Προφίλ
  • -
  • Ενημέρωση στοιχείων
  • -
  • Αλλαγή password
  • +
  • Ενημέρωση στοιχείων
  • +
  • Αλλαγή password
  • Διαχείριση
  • diff --git a/public/app/views/components/own_petitions.php b/public/app/views/components/own_petitions.php index 4b076c4..41e59b4 100644 --- a/public/app/views/components/own_petitions.php +++ b/public/app/views/components/own_petitions.php @@ -1,15 +1,18 @@ - -
    -
    Διαχείριση Αιτήσεων και Δοικητικών Εγγράφων
    -
    - - -   Νέο Μάθημα - +
    + +
    +
    +
    Διαχείριση Αιτήσεων και Δοικητικών Εγγράφων
    + +
    +
    -
    -
    +
    @@ -18,9 +21,9 @@ - + - + @@ -30,8 +33,5 @@ + - - - - diff --git a/public/app/views/js/submit/application-form.php b/public/app/views/js/submit/application-form.php index 168ca0d..272fbcb 100644 --- a/public/app/views/js/submit/application-form.php +++ b/public/app/views/js/submit/application-form.php @@ -21,7 +21,8 @@ position: selected_text($('select[name=position]')), request: $('textarea[name=request]').val(), now: Math.floor(Date.now() / 1000), // client timestamp - ticket: ref.ticket + ticket: ref.ticket, + ref: ref }; } diff --git a/public/app/views/js/submit/penalty-form.php b/public/app/views/js/submit/penalty-form.php index a5a8ec6..e3d2748 100644 --- a/public/app/views/js/submit/penalty-form.php +++ b/public/app/views/js/submit/penalty-form.php @@ -23,7 +23,8 @@ president: selected_text($('select[name=president]')), now: Math.floor(Date.now() / 1000), // client timestamp members: selected_multitexts($('select[name="members[]"]')), - ticket: ref.ticket + ticket: ref.ticket, + ref: ref }; } diff --git a/public/app/views/js/submit/update-properties.php b/public/app/views/js/submit/update-properties.php new file mode 100644 index 0000000..651ef3e --- /dev/null +++ b/public/app/views/js/submit/update-properties.php @@ -0,0 +1,38 @@ + \ No newline at end of file diff --git a/public/app/views/templates/create_pdf.php b/public/app/views/templates/create_pdf.php new file mode 100644 index 0000000..19b2894 --- /dev/null +++ b/public/app/views/templates/create_pdf.php @@ -0,0 +1,69 @@ + + + + + <?=SITE_TITLE?> + + + + + + + + + +
    +
    + + + Η διαδικασία λήψης του εγγράφου είναι σε εξέλιξη...
    + +
    +
    + + + \ No newline at end of file diff --git a/public/app/views/user/panel.php b/public/app/views/user/panel.php index 80f4071..fbfdd0c 100644 --- a/public/app/views/user/panel.php +++ b/public/app/views/user/panel.php @@ -38,18 +38,6 @@ ]); ?> - - @@ -110,6 +98,7 @@ +
    ΤίτλοςΘέμα Αρ.ΠρωτόκολλουSignature Ημερ. Καταχώρισης