summaryrefslogtreecommitdiff
path: root/public/app
diff options
context:
space:
mode:
Diffstat (limited to 'public/app')
-rw-r--r--public/app/config/app_constants.php7
-rw-r--r--public/app/controllers/Office.php60
-rw-r--r--public/app/views/templates/common-form.php206
3 files changed, 269 insertions, 4 deletions
diff --git a/public/app/config/app_constants.php b/public/app/config/app_constants.php
index 3404033..f788946 100644
--- a/public/app/config/app_constants.php
+++ b/public/app/config/app_constants.php
@@ -166,6 +166,13 @@ define('NOT_VALID_ACTIVATION_TITLE', 'Σφάλμα!');
define('NOT_VALID_ACTIVATION_MESSAGE', 'Ο λογαριασμός δεν έχει ενεργοποιηθεί.
Ξαναδοκιμάστε αργότερα κι αν το σφάλμα επιμείνει, επικοινωνήστε με την υπεύθυνη του προγράμμαρος.');
+define ('PETITION_TYPE', [
+ 1 => 'common',
+ 2 => 'penalty'
+]);
+
+
+
// forms
// --- -- -- - - -
diff --git a/public/app/controllers/Office.php b/public/app/controllers/Office.php
index 6a55efe..5e8af75 100644
--- a/public/app/controllers/Office.php
+++ b/public/app/controllers/Office.php
@@ -120,10 +120,8 @@ class Office {
/** (any) petition
*
- * Route method to specific petition;
- *
- * also...
- * checks if user is authorized to view the content;
+ * check if user is authorized to view the content;
+ * if so, prepare and render the petition view
*
* @param $petition_type (string): [common|penalty]
*/
@@ -162,6 +160,60 @@ class Office {
}
+ private static function render_common_petition($opts)
+ {
+ $user_id = $opts['user']->getID();
+
+ $form_setup = json_decode(json_encode(COMMON_REQUEST_FORM, JSON_UNESCAPED_UNICODE));
+
+ // get Form's HTML and Jsvascript
+ $form = JsonToForm::json_form($form_setup, [
+ ['name' => 'user_id', 'value' => $user_id] // pass user identity
+ ]);
+
+ Render::view('templates/common-form', ['form' => $form]);
+ }
+
+ private static function render_penalty_form($opts)
+ {
+ $user_id = $opts['user']->getID();
+
+ $form_setup = json_decode(json_encode(PENALTY_FORM, JSON_UNESCAPED_UNICODE));
+
+ // get all teachers
+ $teachers_array = Registry::use('database')->runQuery(
+ "SELECT concat(last_name, ' ', first_name) as TeacherName
+ FROM user ORDER BY TeacherName", []
+ );
+ $teachers = []; // constuct teacher names as a simple array
+ foreach($teachers_array as $key => $person) {
+ $teachers[] = $person['TeacherName'];
+ }
+ // print_r( $teachers); die();
+
+ // get $key of rapporteur, president and members inside the form_setup->form array
+ for($i=0; $i < sizeof($form_setup->form) ; $i++) {
+ if (isset($form_setup->form[$i]->name)) {
+ if ($form_setup->form[$i]->name == 'rapporteur') { $keyRapporteur = $i; }
+ if ($form_setup->form[$i]->name == 'president') { $keyPresident = $i; }
+ if ($form_setup->form[$i]->name == 'members') { $keyMembers = $i; }
+ }
+ }
+
+ // set option sources for rapporteur, president and members
+ $form_setup->form[$keyRapporteur]->options = $teachers;
+ $form_setup->form[$keyPresident]->options = $teachers;
+ $form_setup->form[$keyMembers]->options = $teachers;
+
+ // get Form's HTML and Jsvascript
+ $form = JsonToForm::json_form($form_setup, [
+ ['name' => 'user_id', 'value' => $user_id] // pass user identity
+ ]);
+
+ Render::view('templates/penalty', ['form' => $form]);
+
+ }
+
## -------------------------------------------------------------------------
diff --git a/public/app/views/templates/common-form.php b/public/app/views/templates/common-form.php
new file mode 100644
index 0000000..1ecc85d
--- /dev/null
+++ b/public/app/views/templates/common-form.php
@@ -0,0 +1,206 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title><?=SITE_TITLE?> - Αίτηση</title>
+
+ <?php // header includes
+ ////////////////////////////////////////////////////////////////////////
+ Render::view('components/header_includes');
+ ?>
+
+</head>
+<body class="office central-form">
+
+<div class='container'>
+ <div class="content max720px">
+
+ <div class='content-form'>
+ <form method="post">
+ <div>
+
+ <h4>Αίτηση</h4>
+ <hr />
+
+ <?=$form['html']?>
+
+ <br />
+ <button type="submit" class="btn btn-primary btn-sm col-12">Καταχώριση</button>
+
+ </div>
+ </form>
+ </div>
+
+ </div>
+ </div>
+
+</body>
+<script>
+var values = {};
+var empty = '';
+
+$(document).ready(function() {
+
+ // supplementary functions to select2 control
+ ////////////////////////////////////////////////////////////////////////////
+
+ /** getValues
+ * --- -- -- - - -
+ * Get selected value(s) of Select2 control
+ *
+ * @param arg: source-element
+ * @return (string) value(s) comma-separated
+ */
+ function getValues(srcElm) {
+ var res;
+ var obj = srcElm.select2('data'); // get delected data array
+
+ if (obj.length === 0) return ''; // if empty list then nothig is selected
+ else {
+ var i = 0;
+ obj.forEach(function(elm){ // loop through object elements array
+
+ if (i) res += ',' + elm.id; // if not first item, prepend ',' befor value(id)
+ else res = elm.id; // else set (first) checked value
+
+ i++;
+ });
+ }
+ return res;
+ }
+
+ /** select2_set_text
+ * --- -- -- - - -
+ * select an (select2-)option by text
+ * onto a (single) select2 control
+ *
+ * @param control = jquery selector,
+ * @param t (string) = text of option
+ */
+ function select2_set_text(control, t) {
+ opts = control.select2()[0].options;
+ var id;
+ for(i=0; i<opts.length; i++) { if (opts[i].text == t) id = i; }
+ control.val(id).trigger('change');
+ }
+
+ /** get_id_of_text
+ * --- -- -- - - -
+ * get id (=value) of an option with `t` as text
+ * onto a select2 control;
+ *
+ * Can be used on single or multiple select2 contols
+ *
+ * @param control = jquery selector,
+ * @param t (string) = text of option
+ */
+ function get_id_of_text( control , t) {
+ opts = control.select2()[0].options;
+ var id = false;
+ for(i=0; i<opts.length; i++) { if (opts[i].text == t) id = i; }
+ return id;
+ }
+
+ /** select2_set_multi_text
+ * --- -- -- - - -
+ * select several (select2-)options by text
+ *
+ * @param control = jquery selector,
+ * @param t_list (string) = list of selected texts
+ */
+ function select2_set_multi_text(control, t_list) { /* define function */
+ var ids = [];
+ t_list.forEach (t => { let id = get_id_of_text(control, t);
+ if (id !== false) ids.push(id);
+ })
+ control.val(ids).change();
+ }
+
+ /**
+ * get selected text of a select2 control
+ */
+ function selected_text(control) {
+ if (typeof control.select2('data') === 'undefined') return false;
+ else if (control.select2('data').length == 0) return false;
+ else return control.select2('data')[0].text;
+ }
+
+ /**
+ * get all selected texts from a multi-select2 contol
+ */
+ function selected_multitexts(control) {
+ if (typeof control.select2('data') === 'undefined') return false;
+ else if (control.select2('data').length == 0) return false;
+ else {
+ var result = [];
+ control.select2('data').forEach( item => { result.push(item.text); });
+ return result;
+ }
+ }
+
+ // intializations from form-definition
+ ////////////////////////////////////////////////////////////////////////////
+
+ <?=$form['init_js']?>
+
+
+ // track empty values
+ ////////////////////////////////////////////////////////////////////////////
+
+
+
+
+
+ // When form is submited
+ ////////////////////////////////////////////////////////////////////////////
+
+ $('.content-form form').submit( event => {
+ event.preventDefault();
+
+ if (false) {
+ alert('Τα δυο passrods δεν ταιριάζουν!');
+
+ } else {
+
+ var data = { // select content data
+ of_article: selected_text($('select[name=of_article]')),
+ student_names: $('textarea[name=student_names]').val(),
+ of_department: $('input[name=of_department]').val(),
+ date: $('input[name=date]').val(),
+ time: $('input[name=time]').val(),
+ place: selected_text($('select[name=place]')),
+ rapporteur: selected_text($('select[name=rapporteur]')),
+ charge: $('textarea[name=charge]').val(),
+ apology: $('textarea[name=apology]').val(),
+ decision_reasoning: $('textarea[name=decision_reasoning]').val(),
+ decision: selected_text($('select[name=decision]')),
+ decision_more: $('input[name=decision_more]').val(),
+ president: selected_text($('select[name=president]')),
+ members: selected_multitexts($('select[name="members[]"]'))
+ };
+
+ var form_data = { // prepare data to post
+ subject: $('input[name=of_department]').val(),
+ content: JSON.stringify(data),
+ on_date: $('input[name=date]').val(),
+ user_id: $('input[name=id]').val()
+ }
+
+ // select action url (add or update)
+ // var request = '/account/register';
+ console.log(data);
+
+ // send POST request
+ // $.post(request, form_data)
+ // .done(function( data ) {
+ // $('.classroom .content-form').html(data.message)
+ // });
+ }
+
+ });
+
+
+ });
+</script>
+
+</html>