diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-05-26 04:44:45 +0300 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-05-26 04:44:45 +0300 |
| commit | 64da2d519297302400930785a968ac3a19bddfb3 (patch) | |
| tree | 96fd97b29fc5e94900c3e9b557dcf4691560e7d9 /public/app | |
| parent | ddf8531d41856f1d941b5fd3e5b504b123bd6d44 (diff) | |
| download | gyraf1gov-64da2d519297302400930785a968ac3a19bddfb3.tar.gz gyraf1gov-64da2d519297302400930785a968ac3a19bddfb3.tar.bz2 gyraf1gov-64da2d519297302400930785a968ac3a19bddfb3.zip | |
custom fonts on pdf; ticket system for CSRF elimination; and more
Diffstat (limited to 'public/app')
| -rw-r--r-- | public/app/config/setup_application.php | 2 | ||||
| -rw-r--r-- | public/app/controllers/Office.php | 66 | ||||
| -rw-r--r-- | public/app/views/components/header_includes.php | 12 | ||||
| -rw-r--r-- | public/app/views/js/pdf-designer/application.php | 142 | ||||
| -rw-r--r-- | public/app/views/js/pdf-designer/penalty.php (renamed from public/app/views/js/pdf/penalty-styler.php) | 0 | ||||
| -rw-r--r-- | public/app/views/js/pdf/application-styler.php | 191 | ||||
| -rw-r--r-- | public/app/views/js/submit/application-form.php | 62 | ||||
| -rw-r--r-- | public/app/views/js/submit/penalty-form.php | 74 | ||||
| -rw-r--r-- | public/app/views/templates/application.php | 136 |
9 files changed, 366 insertions, 319 deletions
diff --git a/public/app/config/setup_application.php b/public/app/config/setup_application.php index a5b7557..a9f48af 100644 --- a/public/app/config/setup_application.php +++ b/public/app/config/setup_application.php @@ -7,6 +7,8 @@ * ----------------------------------------------------------------------------- */ +define('DEFAULT_SCHOOL', '1ο Γυμνάσιο Ραφήνας'); + // email setup ///////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- diff --git a/public/app/controllers/Office.php b/public/app/controllers/Office.php index d4b0217..800247e 100644 --- a/public/app/controllers/Office.php +++ b/public/app/controllers/Office.php @@ -199,8 +199,13 @@ class Office { ['name' => 'user_id', 'value' => $user_id] // pass user identity ]); - // #5: render the view ------------------------------------------------- - Render::view('templates/application', ['form' => $form]); + // #5: create ticket; then render the view ----------------------------- + $ticket = self::create_ticket($ticket); // save ticket + Render::view('templates/application', [ + 'form' => $form, + 'applier' => (($userData['prefix'] == 'η') ? 'Η Αιτούσα' : 'Ο Αιτών'), + 'ticket' => $ticket + ]); } @@ -255,6 +260,63 @@ class Office { + + ## ------------------------------------------------------------------------- + ## + ## TICKET METHODS (create, remove) + ## tickets eliminate CSRF attacks + ## + ## ------------------------------------------------------------------------- + + + /** create_ticket + * + * creates a tickef and saves it into session + * + * @return string new ticket (MD5) + */ + private static function create_ticket() + { + // create ticket + $tick = md5( time() . Auth::user_data() . rand(1,65536) ); + // then save to session + if (isset($_SESSION['tickets'])) { + $tickets = explode(',', $_SESSION['tickets']); + $tickets[] = $tick; + $_SESSION['tickets'] = implode(',', $tickets); + + } else { + $_SESSION['tickets'] = $tick; + } + + return $tick; + } + + /** remove_ticker + * + * removes a ticket and return true; + * if ticket not exists return fase; + * + * @param string $t : ticket (MD5) + * @return boolean + */ + private static function remove_ticket($t) + { + if (isset($_SESSION['tickets'])) { + $tickets = explode(',', $_SESSION['tickets']); + if (($key = array_search($t, $tickets)) !== false) { + unset($tickets[$key]); + $_SESSION['tickets'] = implode(',', $tickets); + return true; + } + } + return false; + } + + + + + ## ------------------------------------------------------------------------- ## ## ADMIN METHODS (insert, updated etc.) diff --git a/public/app/views/components/header_includes.php b/public/app/views/components/header_includes.php index 15685b5..48f63c6 100644 --- a/public/app/views/components/header_includes.php +++ b/public/app/views/components/header_includes.php @@ -51,9 +51,19 @@ <script src="/assets/js/cookie.js"></script> <!-- datatables js --> +<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script> -<script src="https://cdn.datatables.net/v/bs5/jszip-2.5.0/dt-1.13.4/b-2.3.6/b-colvis-2.3.6/b-html5-2.3.6/b-print-2.3.6/cr-1.6.2/date-1.4.0/fc-4.2.2/fh-3.3.2/kt-2.8.2/r-2.4.1/rr-1.3.3/sc-2.1.1/sl-1.6.2/sr-1.2.2/datatables.min.js"></script> + +<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script> +<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script> +--> + +<script src="<?=SITE_URL?>/assets/js/pdfmake/pdfmake.min.js"></script> +<script src="<?=SITE_URL?>/assets/js/pdfmake/vfs_fonts.js"></script> + +<!-- +<script src="https://cdn.datatables.net/v/bs5/jszip-2.5.0/dt-1.13.4/b-2.3.6/b-colvis-2.3.6/b-html5-2.3.6/b-print-2.3.6/cr-1.6.2/date-1.4.0/fc-4.2.2/fh-3.3.2/kt-2.8.2/r-2.4.1/rr-1.3.3/sc-2.1.1/sl-1.6.2/sr-1.2.2/datatables.min.js"></script>--> <!-- select2 js --> <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script> diff --git a/public/app/views/js/pdf-designer/application.php b/public/app/views/js/pdf-designer/application.php new file mode 100644 index 0000000..1d77c67 --- /dev/null +++ b/public/app/views/js/pdf-designer/application.php @@ -0,0 +1,142 @@ +<script> +function designer(data, defines) { + // handle date + const d = new Date( data.date ); + const options = { + weekday: 'long', + year: 'numeric', + month: 'long', + day: 'numeric' + }; + var elDate = d.toLocaleDateString('el-GR', options); + var year = d.getFullYear().toString(); + + // get labels from id-specified objects + let petition = 'Αίτηση'; + + return { + info: { + title: data.subject, + author: defines.organization, + subject: data.subject, + keywords: [petition, year].join(', '), + }, + content: [ + { + text: 'ΑΙΤΗΣΗ\n\n', + style: 'header' + }, + { + alignment: 'justify', + columns: [ + { + width: 210, + text: '' + }, + { + width: 'auto', + lineHeight: 1.35, + text:[ + 'ΠΡΟΣ\n', + { + style: 'bigger', + text: defines.organization + } + ] + } + ] + }, + { + columns: [ + { + width: 210, + lineHeight: 1.25, + alignment: 'left', + text: [ + 'Επώνυμο: ', { style: 'bigger', text: data.last_name }, + '\n\nΌνομα: ', { style: 'bigger', text: data.first_name }, + '\n\nΌνομα πατρός: ',{ style: 'bigger', text: data.father_name }, + '\n\nAM: ',{ style: 'bigger', text: data.registration_number }, + '\n\nΚλάδος/Ειδικότητα: ',{ style: 'bigger', text: data.sector }, + '\n\nΣχολείο Οργανικής: ',{ + style: 'bigger', text: data.belonging_school + }, + // '\n\nΣχολείο Υπηρέτησης:\n\t',{ + // style: 'bigger', text: data.constants.organization + // }, + '\n\nΤηλέφωνο Επικοινωνίας: ',{ style: 'bigger', text: data.phone }, + '\n\nEmail: ', { style: 'bigger', text: data.email }, + '\n\nΘέση Υπηρέτησης: ',{ style: 'bigger', text: data.position } + + ] + }, + { + width: 'auto', + lineHeight: 1.33, + text: [ + '\n\n', + { + style: 'bigger', + text: data.request+'\n', + alignment: 'left' + }, + '\n\n', + { + text: elDate, + style: 'bigger', + alignment: 'center' + }, + { + text: '\n\n'+ defines.applier +'\n', + style: 'bigger', + alignment: 'center' + }, + { + style: 'bigger', + text: data.last_name +' '+data.first_name, + alignment: 'center' + } + ] + } + ] + } + ], + footer: { + text: [ + 'Αριθμός πρωτοκόλου: A124-2501-4568-7 / 2023-12-15', + '\ndocument signature: ' + defines.ticket + + ], + style: 'signature' + }, + styles: { + header: { + fontSize: 20, + bold: true, + alignment: 'center', + color: '#000' + }, + bigger: { + fontSize: 10, + italics: false, + bold: true, + color: '#000' + // decoration: 'underline' + }, + signature: { + fontSize: 8, + italics: false, + alignment: 'center', + font: 'FiraMono' + + } + }, + defaultStyle: { + columnGap: 35, + fontSize: 9, + font: 'FiraSans' + } + }; +} + +</script>
\ No newline at end of file diff --git a/public/app/views/js/pdf/penalty-styler.php b/public/app/views/js/pdf-designer/penalty.php index e69de29..e69de29 100644 --- a/public/app/views/js/pdf/penalty-styler.php +++ b/public/app/views/js/pdf-designer/penalty.php diff --git a/public/app/views/js/pdf/application-styler.php b/public/app/views/js/pdf/application-styler.php deleted file mode 100644 index 35077ef..0000000 --- a/public/app/views/js/pdf/application-styler.php +++ /dev/null @@ -1,191 +0,0 @@ -<!-- application pdf template - check: http://pdfmake.org/playground.html - // playground requires you to assign document definition to a variable called dd - - var dd = { - content: [ - 'APPLICATION:\n\n', - { - alignment: 'justify', - columns: [ - { - text: [ - 'NAME: My Name', - 'Father: I do', - 'Mother:Me too', - 'Specs: Some quite big Address Lorem ipsum dolor sit amet, consectetur adipisicing elit' - ].join('\n\n') - }, - { - text:[ - 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.', - 'Malit profecta versatur nomine ocurreret multavit, officiis viveremus aeternum.', - 'Quando nostros congressus susceperant concederetur leguntur iam, vigiliae democritea tantopere causae.', - 'Atilii plerumque ipsas potitur pertineant multis rem quaeri pro, legendum didicisse credere ex maluisset per videtis.', - 'Cur discordans praetereat aliae ruinae dirigentur orestem eodem, praetermittenda divinum.', - 'Collegisti, deteriora malint loquuntur officii cotidie finitas referri doleamus ambigua acute.', - 'Adhaesiones ratione beate arbitraretur detractis perdiscere, constituant hostis polyaeno.', - 'Diu concederetur.' - ].join('\n') - } - ] - }, - '\n\nOh, don\'t forget, we can use everything from styling examples (named styles, custom overrides) here as well.', - '\n\nWow, you\'ve read the whole document! Congratulations :D' - ], - styles: { - header: { - fontSize: 18, - bold: true - }, - bigger: { - fontSize: 15, - italics: true - } - }, - defaultStyle: { - columnGap: 20 - } - - } - - - - --- also --- - - var dd = { - content: [ - { - text: 'This is a header with style', - style: 'header' - }, - - 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Confectum ponit legam, perferendis nomine miserum, animi. Moveat nesciunt triari naturam.\n\n', - - 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Confectum ponit legam, perferendis nomine miserum, animi. Moveat nesciunt triari naturam posset, eveniunt specie deorsus efficiat sermone instituendarum fuisse veniat, eademque mutat debeo. Delectet plerique protervi diogenem dixerit logikh levius probabo adipiscuntur afficitur, factis magistra inprobitatem aliquo andriam obiecta, religionis, imitarentur studiis quam, clamat intereant vulgo admonitionem operis iudex stabilitas vacillare scriptum nixam, reperiri inveniri maestitiam istius eaque dissentias idcirco gravis, refert suscipiet recte sapiens oportet ipsam terentianus, perpauca sedatio aliena video.\n\n', - - { - text: 'It is possible to apply multiple styles, by passing an array. This paragraph uses two styles: quote and small. When multiple styles are provided, they are evaluated in the specified order which is important in case they define the same properties', - style: ['quote', 'small'] - } - ], - styles: { - header: { - fontSize: 18, - bold: true, - alignment: 'center' - }, - subheader: { - fontSize: 15, - bold: true - }, - quote: { - italics: true - }, - small: { - fontSize: 8 - } - } - -} ---> - - - -<script> -var source = { - first_name: 'George', - last_name: 'Its me!', - father_name: 'Pipis', - message: 'Adhaesiones ratione beate arbitraretur detractis perdiscere, constituant hostis polyaeno.', - constants: { - organization: 'Ministry of Nothing' - } -} - - -function designer(data) { - return { - content: [ - { - text: 'ΑΙΤΗΣΗ\n\n', - style: 'header' - }, - { - alignment: 'justify', - columns: [ - { - width: 210, - text: '' - }, - { - width: 'auto', - text:[ - 'ΠΡΟΣ\n', - { - style: 'bigger', - text: data.constants.organization - } - ] - } - ] - }, - { - alignment: 'justify', - columns: [ - { - width: 210, - lineHeight: 1.5, - text: [ - 'Όνομα: ', { style: 'bigger', text: data.first_name }, - '\nΕπίθετο: ', { style: 'bigger', text: data.last_name }, - '\nΌνομα πατρός: ',{ style: 'bigger', text: data.father_name }, - '\nEmail: ', { style: 'bigger', text: data.email }, - ] - }, - { - width: 'auto', - lineHeight: 1.33, - text: [ - '\n\n', - { - style: 'bigger', - text: data.message+'\n' - }, - '\n\ndate: ', - '\n\nze Is', - '\n\n\n', - { - style: 'bigger', - text: data.last_name +' '+data.first_name - } - ] - } - ] - }, - '\n\nOh, don\'t forget, we can use everything from styling examples (named styles, custom overrides) here as well.', - '\n\nWow, you\'ve read the whole document! Congratulations :D' - ], - styles: { - header: { - fontSize: 24, - bold: true, - alignment: 'center', - color: '#000' - }, - bigger: { - fontSize: 15, - italics: false, - color: '#000' - } - }, - defaultStyle: { - columnGap: 25, - fontSize: 13 - } - - }; - -} - -var dd = designer(source); diff --git a/public/app/views/js/submit/application-form.php b/public/app/views/js/submit/application-form.php index badff03..ed77c1f 100644 --- a/public/app/views/js/submit/application-form.php +++ b/public/app/views/js/submit/application-form.php @@ -1,4 +1,25 @@ <script> + function postObject() { + return { // select content data + subject: $('input[name=subject]').val(), + date: $('input[name=date]').val(), + first_name: $('input[name=first_name]').val(), + last_name: $('input[name=last_name]').val(), + father_name: $('input[name=father_name]').val(), + phone: $('input[name=phone]').val(), + email: $('input[name=email]').val(), + registration_number: $('input[name=registration_number]').val(), + belonging_school: $('input[name=belonging_school]').val(), + date: $('input[name=date]').val(), + sector: selected_text($('select[name=sector]')), + position: selected_text($('select[name=position]')), + request: $('textarea[name=request]').val(), + now: Math.floor(Date.now() / 1000), + ticket: ref.ticket + }; + } + + $(document).ready(function() { // When form is submited @@ -12,22 +33,7 @@ } 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 data = postObject(); var form_data = { // prepare data to post subject: $('input[name=of_department]').val(), @@ -50,5 +56,29 @@ }); + + // preview event + //////////////////////////////////////////////////////////////////////// + + $('.btn-preview').click( event => { + event.preventDefault(); + console.log('preview', postObject()); + + pdfMake.fonts = { + FiraSans: { + normal: '<?=SITE_URL?>/assets/fonts/FiraSans-Light.ttf', + bold: '<?=SITE_URL?>/assets/fonts/FiraSans-Medium.ttf' + // italics: 'https://example.com/fonts/fontFile3.ttf', + // bolditalics: 'https://example.com/fonts/fontFile4.ttf' + }, + FiraMono: { + normal: '<?=SITE_URL?>/assets/fonts/FiraMono-Regular.ttf', + } + } + + pdfMake.createPdf(designer( postObject(), ref )).open(); + }); + + }); </script> diff --git a/public/app/views/js/submit/penalty-form.php b/public/app/views/js/submit/penalty-form.php new file mode 100644 index 0000000..fcf9093 --- /dev/null +++ b/public/app/views/js/submit/penalty-form.php @@ -0,0 +1,74 @@ +<script> + function constructPost() { + post = { // 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[]"]')) + }; + } + + + $(document).ready(function() { + + // 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> diff --git a/public/app/views/templates/application.php b/public/app/views/templates/application.php index 6e36d00..4611a2d 100644 --- a/public/app/views/templates/application.php +++ b/public/app/views/templates/application.php @@ -25,7 +25,18 @@ <?=$form['html']?> <br /> - <button type="submit" class="btn btn-primary btn-sm col-12">Καταχώριση</button> + <div class="row"> + <div class="col-4"> + <button class="btn btn-preview btn-sm col-12"> + Προεπισκόπηση + </button> + </div> + <div class="col-8"> + <button type="submit" class="btn btn-primary btn-sm col-12"> + Καταχώριση + </button> + </div> + </div> </div> </form> @@ -74,8 +85,12 @@ --> <script>// initialize needed global variables - var values = {}; - var empty = ''; + var ref = { + organization: '<?=DEFAULT_SCHOOL?>', + applier: '<?=$applier?>', + ticket: '<?=$ticket?>' + }; + </script> @@ -102,12 +117,18 @@ ?> +<?php // load application pdf-designer + //////////////////////////////////////////////////////////////////////////// + Render::view('js/pdf-designer/application'); +?> + + <?php // include attachments handling //////////////////////////////////////////////////////////////////////////// Render::view('js/attachments-handling'); ?> - +<!-- <script> var source = { first_name: 'George', @@ -120,113 +141,10 @@ var source = { } -function designer(data) { - return { - info: { - title: 'some-document', - author: 'name', - subject: 'theme', - keywords: 'petition type, year', - }, - content: [ - { - text: 'ΑΙΤΗΣΗ\n\n', - style: 'header' - }, - { - alignment: 'justify', - columns: [ - { - width: 210, - text: '' - }, - { - width: 'auto', - lineHeight: 1.35, - text:[ - 'ΠΡΟΣ\n', - { - style: 'bigger', - text: data.constants.organization - } - ] - } - ] - }, - { - alignment: 'justify', - columns: [ - { - width: 210, - lineHeight: 1.5, - text: [ - 'Όνομα: ', { style: 'bigger', text: data.first_name }, - '\nΕπίθετο: ', { style: 'bigger', text: data.last_name }, - '\nΌνομα πατρός: ',{ style: 'bigger', text: data.father_name }, - '\nEmail: ', { style: 'bigger', text: data.email }, - ] - }, - { - width: 'auto', - lineHeight: 1.33, - text: [ - '\n\n', - { - style: 'bigger', - text: data.message+'\n' - }, - '\n\ndate: ', - '\n\nze Is', - '\n\n\n', - { - style: 'bigger', - text: data.last_name +' '+data.first_name - } - ] - } - ] - }, - '\n\n\n\nWow, you\'ve read the whole document! Congratulations :D' - ], - footer: { - text: [ - 'the document has been registered with number A124-2501-4589-4568-7 / 2023-12-15', - '\ndocument signature: <?=sha1(rand(1,1111))?>' - - ], - style: 'signature' - }, - styles: { - header: { - fontSize: 24, - bold: true, - alignment: 'center', - color: '#000' - }, - bigger: { - fontSize: 13, - italics: false, - color: '#000' - }, - signature: { - fontSize: 11, - italics: false, - alignment: 'center' - - } - }, - defaultStyle: { - columnGap: 25, - fontSize: 12 - } - }; -} - - -pdfMake.createPdf(designer(source)).open(); +// pdfMake.createPdf(designer(source)).open(); // download (+title): .download('my-doc-title.pdf'); // open in same window: .open({}, window); // print: .print(); </script> - +--> </html> |
