DB schema updated, code restructured, full exception and empty posts handling,...

DB schema updated, code restructured, full exception and empty posts handling, added download script and new route, various fixes
parent ebb0fd83
...@@ -35,6 +35,7 @@ return [ ...@@ -35,6 +35,7 @@ return [
['/receive-equip', ['school'], ['get', 'post']], ['/receive-equip', ['school'], ['get', 'post']],
['/receive-equip/submit-success', ['school'], ['get']], ['/receive-equip/submit-success', ['school'], ['get']],
['/receive-equip/report', ['school'], ['get']], ['/receive-equip/report', ['school'], ['get']],
['/receive-equip/receive-doc/{fn}', ['school'], ['get']],
['/tpe_survey', ['school'], ['get', 'post']], ['/tpe_survey', ['school'], ['get', 'post']],
['/tpe_survey/total-teachers', ['school'], ['post']], ['/tpe_survey/total-teachers', ['school'], ['post']],
['/forum', ['guest', 'user'], ['get']], ['/forum', ['guest', 'user'], ['get']],
...@@ -42,6 +43,7 @@ return [ ...@@ -42,6 +43,7 @@ return [
['/in_numbers', ['guest', 'user'], ['get']], ['/in_numbers', ['guest', 'user'], ['get']],
['/export/csv/edulabs_{type}.csv', ['guest', 'user'], ['get']], ['/export/csv/edulabs_{type}.csv', ['guest', 'user'], ['get']],
['/open-data', ['guest', 'user'], ['get']], ['/open-data', ['guest', 'user'], ['get']],
['/receive-equip/undo-submit/{applicationform_id}', ['school'], ['get']], // only for tests. Must be removed
], ],
], ],
], ],
......
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return [
'receive_equip' => [
'file_upload_path' => __DIR__ . '/../../data/uploads', // path to save file
'file_upload_max_size' => 3145728, // Maximum number of bytes allowed(default 3MB)
'file_upload_types_permitted' => ['jpg', 'jpeg', 'pdf', 'png'], // Array of allowed extensions
],
];
...@@ -24,6 +24,7 @@ CREATE TABLE `applicationform` ( ...@@ -24,6 +24,7 @@ CREATE TABLE `applicationform` (
`submitted_by` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `submitted_by` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`received_ts` timestamp NULL, `received_ts` timestamp NULL,
`received_by` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `received_by` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`received_document` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT '',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `index_foreignkey_applicationform_school` (`school_id`), KEY `index_foreignkey_applicationform_school` (`school_id`),
CONSTRAINT `c_fk_applicationform_school_id` FOREIGN KEY (`school_id`) REFERENCES `school` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE CONSTRAINT `c_fk_applicationform_school_id` FOREIGN KEY (`school_id`) REFERENCES `school` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
......
...@@ -24,6 +24,7 @@ CREATE TABLE `applicationform` ( ...@@ -24,6 +24,7 @@ CREATE TABLE `applicationform` (
`submitted_by` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `submitted_by` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`received_ts` timestamp NULL, `received_ts` timestamp NULL,
`received_by` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `received_by` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`received_document` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT '',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `index_foreignkey_applicationform_school` (`school_id`), KEY `index_foreignkey_applicationform_school` (`school_id`),
CONSTRAINT `c_fk_applicationform_school_id` FOREIGN KEY (`school_id`) REFERENCES `school` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE CONSTRAINT `c_fk_applicationform_school_id` FOREIGN KEY (`school_id`) REFERENCES `school` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/) * @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html * @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/ */
use Slim\Http\Request;
use Slim\Http\Response;
use RedBeanPHP\R;
return function (Slim\App $app) { return function (Slim\App $app) {
$container = $app->getContainer(); $container = $app->getContainer();
...@@ -17,7 +20,6 @@ return function (Slim\App $app) { ...@@ -17,7 +20,6 @@ return function (Slim\App $app) {
}); });
$events('on', 'app.services', function ($container) { $events('on', 'app.services', function ($container) {
$container[GrEduLabs\ReceiveEquip\Service\ReceiveEquipServiceInterface::class] = function ($c) { $container[GrEduLabs\ReceiveEquip\Service\ReceiveEquipServiceInterface::class] = function ($c) {
return new GrEduLabs\ReceiveEquip\Service\ReceiveEquipService($c['logger']); return new GrEduLabs\ReceiveEquip\Service\ReceiveEquipService($c['logger']);
}; };
...@@ -43,13 +45,13 @@ return function (Slim\App $app) { ...@@ -43,13 +45,13 @@ return function (Slim\App $app) {
$container[GrEduLabs\ReceiveEquip\Action\ReceiveEquip::class] = function ($c) { $container[GrEduLabs\ReceiveEquip\Action\ReceiveEquip::class] = function ($c) {
$settings = $c->get('settings'); $settings = $c->get('settings');
return new GrEduLabs\ReceiveEquip\Action\ReceiveEquip( return new GrEduLabs\ReceiveEquip\Action\ReceiveEquip(
$c->get('view'), $c->get('view'),
$c->get(GrEduLabs\ReceiveEquip\Service\ReceiveEquipServiceInterface::class), $c->get(GrEduLabs\ReceiveEquip\Service\ReceiveEquipServiceInterface::class),
$c->get(GrEduLabs\ReceiveEquip\InputFilter\ReceiveEquip::class), $c->get(GrEduLabs\ReceiveEquip\InputFilter\ReceiveEquip::class),
$c->get('authentication_service'), $c->get('authentication_service'),
$c->get('router')->pathFor('receive_equip.submit_success'), $c->get('router')->pathFor('receive_equip.submit_success'),
$c['flash'],
$c $c
); );
}; };
...@@ -74,15 +76,18 @@ return function (Slim\App $app) { ...@@ -74,15 +76,18 @@ return function (Slim\App $app) {
$c->get(GrEduLabs\ReceiveEquip\Service\ReceiveEquipServiceInterface::class) $c->get(GrEduLabs\ReceiveEquip\Service\ReceiveEquipServiceInterface::class)
); );
}; };
});
$container[GrEduLabs\ReceiveEquip\Middleware\SchoolReceiveEquip::class] = function ($c) { $events('on', 'app.services', function ($container) {
return new GrEduLabs\ReceiveEquip\Middleware\SchoolReceiveEquip( $container[GrEduLabs\ReceiveEquip\Middleware\HandleEmptyPosts::class] = function ($c) {
return new GrEduLabs\ReceiveEquip\Middleware\HandleEmptyPosts(
$c->get('view'), $c->get('view'),
$c->get(GrEduLabs\ReceiveEquip\Service\ReceiveEquipServiceInterface::class), $c->get(GrEduLabs\ReceiveEquip\Service\ReceiveEquipServiceInterface::class),
$c['flash'],
$c $c
); );
}; };
}); }, -100000);
$events('on', 'app.bootstrap', function ($app, $container) { $events('on', 'app.bootstrap', function ($app, $container) {
$container['view']->getEnvironment()->getLoader()->prependPath(__DIR__ . '/templates'); $container['view']->getEnvironment()->getLoader()->prependPath(__DIR__ . '/templates');
...@@ -91,11 +96,46 @@ return function (Slim\App $app) { ...@@ -91,11 +96,46 @@ return function (Slim\App $app) {
$this->map(['get', 'post'], '', GrEduLabs\ReceiveEquip\Action\ReceiveEquip::class) $this->map(['get', 'post'], '', GrEduLabs\ReceiveEquip\Action\ReceiveEquip::class)
->add(GrEduLabs\Application\Middleware\AddCsrfToView::class) ->add(GrEduLabs\Application\Middleware\AddCsrfToView::class)
->add('csrf') ->add('csrf')
->add(GrEduLabs\ReceiveEquip\Middleware\HandleEmptyPosts::class)
->setName('receive_equip'); ->setName('receive_equip');
$this->get('/submit-success', GrEduLabs\ReceiveEquip\Action\SubmitSuccess::class) $this->get('/submit-success', GrEduLabs\ReceiveEquip\Action\SubmitSuccess::class)
->setName('receive_equip.submit_success'); ->setName('receive_equip.submit_success');
$this->get('/report', GrEduLabs\ReceiveEquip\Action\ReceiveEquipPdf::class) $this->get('/report', GrEduLabs\ReceiveEquip\Action\ReceiveEquipPdf::class)
->setName('receive_equip.report'); ->setName('receive_equip.report');
})->add(GrEduLabs\Schools\Middleware\FetchSchoolFromIdentity::class); })->add(GrEduLabs\Schools\Middleware\FetchSchoolFromIdentity::class);
$app->get('/receive-equip/receive-doc/{fn}', function (Request $req, Response $res) use ($container) {
$route = $req->getAttribute('route');
$fn = $route->getArgument('fn');
/* $container["logger"]->info(sprintf('filename = %s url=%s', $fn, path_for('receive_equip.receive_doc', [
'fn' => form.values.received_document,])
)); */
$file = $container['settings']['receive_equip']['file_upload_path'] . "/" . $fn;
$response = $res->withHeader('Content-Description', 'File Transfer')
->withHeader('Content-Type', 'application/octet-stream')
->withHeader('Content-Disposition', 'attachment;filename="' . basename($file) . '"')
->withHeader('Expires', '0')
->withHeader('Cache-Control', 'must-revalidate')
->withHeader('Content-Length', filesize($file));
readfile($file);
return $response;
})->setName('receive_equip.receive_doc');
/******************* only for tests ***************************/
$app->get('/receive-equip/undo-submit/{applicationform_id}', function (Request $req, Response $res) use ($container) {
$route = $req->getAttribute('route');
$applicationform_id = $route->getArgument('applicationform_id');
$sql = 'update `applicationform` set `approved`=1, `received_ts`=null where `id`=' . $applicationform_id;
R::exec($sql);
return $res->withRedirect("/receive-equip");
})->setName('receive_equip.undosubmit');
/****************** /only for tests ***************************/
}); });
}; };
...@@ -44,13 +44,6 @@ class ReceiveEquip ...@@ -44,13 +44,6 @@ class ReceiveEquip
*/ */
protected $authService; protected $authService;
/**
*
* @var flash messages
*/
protected $flash;
/** /**
* *
* @var type SLIM application container * @var type SLIM application container
...@@ -63,23 +56,28 @@ class ReceiveEquip ...@@ -63,23 +56,28 @@ class ReceiveEquip
*/ */
protected $successUrl; protected $successUrl;
/**
*
* @var array
*/
protected $formErrorMessages;
public function __construct( public function __construct(
Twig $view, ReceiveEquipServiceInterface $receiveEquipService, InputFilterInterface $receiveEquipInputFilter, AuthenticationServiceInterface $authService, $successUrl, $flash, $container Twig $view, ReceiveEquipServiceInterface $receiveEquipService, InputFilterInterface $receiveEquipInputFilter, AuthenticationServiceInterface $authService, $successUrl, $container
) { ) {
$this->view = $view; $this->view = $view;
$this->receiveEquipService = $receiveEquipService; $this->receiveEquipService = $receiveEquipService;
$this->receiveEquipInputFilter = $receiveEquipInputFilter; $this->receiveEquipInputFilter = $receiveEquipInputFilter;
$this->authService = $authService; $this->authService = $authService;
$this->successUrl = $successUrl; $this->successUrl = $successUrl;
$this->flash = $flash;
$this->container = $container; $this->container = $container;
$this->formErrorMessages = [];
} }
public function __invoke(Request $req, Response $res) public function __invoke(Request $req, Response $res)
{ {
$school = $req->getAttribute('school'); $school = $req->getAttribute('school');
$receivedDocumentFileName = $school->id; $receivedDocumentFileName = $school->id;
if ($req->isPost()) { if ($req->isPost()) {
$reqParams = $req->getParams(); $reqParams = $req->getParams();
array_splice($reqParams['items'], 0, 0); array_splice($reqParams['items'], 0, 0);
...@@ -89,74 +87,44 @@ class ReceiveEquip ...@@ -89,74 +87,44 @@ class ReceiveEquip
'submitted_by' => $this->authService->getIdentity()->mail, 'submitted_by' => $this->authService->getIdentity()->mail,
])); ]));
$isValid = $this->receiveEquipInputFilter->isValid(); $isValid = $this->receiveEquipInputFilter->isValid();
$isValidFile = true;
if ($isValid) { if ($isValid) {
$isValidFile = true;
$files = $req->getUploadedFiles(); $files = $req->getUploadedFiles();
if (empty($files['received_document'])) { if (empty($files['received_document'])) {
$isValidFile = false; $isValidFile = false;
$this->flash->addMessage('danger', "Πρέπει να επισυνάψετε το δελτίο παραλαβής και μετά να επιλέξετε Υποβολή"); array_push($this->formErrorMessages, "Πρέπει να επισυνάψετε το δελτίο παραλαβής και μετά να επιλέξετε Υποβολή");
// throw new Exception('Expected a newfile'); $this->container["logger"]->info(sprintf('empty($files[received_document]) = true'));
} else { } else {
$clientFile = $files['received_document']; $clientFile = $files['received_document'];
$receivedDocumentFileName = $this->fileUpload($clientFile, $receivedDocumentFileName);
if ($clientFile->getError() === UPLOAD_ERR_OK) { if ($receivedDocumentFileName === null) {
$this->container["logger"]->info(sprintf(
'mediatype = %s, filesize= %s',
$clientFile->getClientMediaType(), $clientFile->getSize()
));
if ((int) $clientFile->getSize() > (int) $this->container['settings']['application_form']['file_upload_max_size']) {
$isValidFile = false;
$this->flash->addMessage('danger', "Η επισύναψη - αποστολή του αρχείου απέτυχε. Το μέγεθος του αρχείου υπερβαίνει το επιτρεπτό όριο");
} else {
$clientFileName = $clientFile->getClientFilename();
$clientFileNameExt = strtolower(pathinfo($clientFileName, PATHINFO_EXTENSION));
if (in_array($clientFileNameExt, $this->container['settings']['application_form']['file_upload_extensions'])) {
$receivedDocumentFileName = $receivedDocumentFileName . "." . $clientFileNameExt;
$clientFile->moveTo($this->container['settings']['application_form']['file_upload_path'] . "/" . $receivedDocumentFileName);
} else {
$isValidFile = false;
$this->flash->addMessage('danger', "Η επισύναψη - αποστολή του αρχείου απέτυχε. Ο τύπος του αρχείου δεν είναι επιτρεπτός");
}
}
} else {
$isValidFile = false; $isValidFile = false;
$this->flash->addMessage('danger', "Η επισύναψη - αποστολή του αρχείου απέτυχε");
} }
} }
if ($isValidFile) { if ($isValidFile === true) {
$data = $this->receiveEquipInputFilter->getValues(); $data = $this->receiveEquipInputFilter->getValues();
$receiveEquip = $this->receiveEquipService->submit($data, $receivedDocumentFileName); $receiveEquip = $this->receiveEquipService->submit($data, $receivedDocumentFileName);
$_SESSION['receiveEquipForm']['receiveEquip'] = $receiveEquip; $_SESSION['receiveEquipForm']['receiveEquip'] = $receiveEquip;
$res = $res->withRedirect($this->successUrl); $res = $res->withRedirect($this->successUrl);
return $res; return $res;
} else {
return $res->withRedirect($req->getUri());
} }
} }
$this->view['form'] = [ $this->populateInvalidForm($school);
'is_valid' => $isValid, } else { // not post request
'values' => $this->receiveEquipInputFilter->getValues(),
'raw_values' => $this->receiveEquipInputFilter->getRawValues(),
'messages' => $this->receiveEquipInputFilter->getMessages(),
];
}
if (!$req->isPost()) {
if (null !== ($receiveEquip = $this->receiveEquipService->findSchoolReceiveEquip($school->id))) { if (null !== ($receiveEquip = $this->receiveEquipService->findSchoolReceiveEquip($school->id))) {
$this->view['form'] = [ $this->view['form'] = [
'school' => $school, 'school' => $school,
'is_valid' => true,
'exists' => true, 'exists' => true,
'values' => $receiveEquip, 'values' => $receiveEquip,
]; ];
} else { } else {
$this->view['form'] = [ $this->view['form'] = [
'school' => $school, 'school' => $school,
'is_valid' => true,
'exists' => false, 'exists' => false,
'values' => null, 'values' => null,
]; ];
...@@ -170,71 +138,115 @@ class ReceiveEquip ...@@ -170,71 +138,115 @@ class ReceiveEquip
return $res; return $res;
} }
private function fileUpload($clientFile) private function populateInvalidForm($school) {
$receiveEquip = $this->receiveEquipService->findSchoolReceiveEquip($school->id);
$dataFromForm = $this->receiveEquipInputFilter->getValues();
if ($receiveEquip !== null) {
$items = $receiveEquip['items'];
$dataItemsFromForm = $dataFromForm['items'];
$dataItemsFromFormLength = count($dataItemsFromForm);
foreach ($items as $item) {
for ($i=0; $i<$dataItemsFromFormLength; $i++) {
if ((int) $item['id'] === (int) $dataItemsFromForm[$i]['id']) {
$dataItemsFromForm[$i]['itemcategory'] = $item['itemcategory'];
$dataItemsFromForm[$i]['qty'] = $item['qty'];
$dataItemsFromForm[$i]['lab'] = $item['lab'];
break;
}
}
}
$dataFromForm['items'] = $dataItemsFromForm;
}
$this->view['form'] = [
'school' => $school,
'exists' => true,
'is_valid' => false,
'values' => $dataFromForm,
'raw_values' => $this->receiveEquipInputFilter->getRawValues(),
'messages' => $this->receiveEquipInputFilter->getMessages(),
'formErrorMessages' => $this->formErrorMessages
];
}
private function fileUpload($clientFile, $receivedDocumentFileName)
{ {
switch ($error) { $vf = true;
$this->container["logger"]->info(sprintf(
'error code= %d, mediatype = %s, filesize= %s, sizepermitted= %s',
$clientFile->getError(), $clientFile->getClientMediaType(), $clientFile->getSize(), $this->container['settings']['receive_equip']['file_upload_max_size']
));
switch ($clientFile->getError()) {
case UPLOAD_ERR_OK: case UPLOAD_ERR_OK:
$this->container["logger"]->info(sprintf( if ((int) $clientFile->getSize() > (int) $this->container['settings']['receive_equip']['file_upload_max_size']) {
'mediatype = %s, filesize= %s', $vf = false;
$clientFile->getClientMediaType(), $clientFile->getSize() array_push($this->formErrorMessages, "Η επισύναψη - αποστολή του αρχείου απέτυχε. Το μέγεθος του αρχείου υπερβαίνει το επιτρεπτό όριο της εφαρμογής Edulabs");
));
if ((int) $clientFile->getSize() > (int) $this->container['settings']['application_form']['file_upload_max_size']) {
$isValidFile = false;
$this->flash->addMessage('danger', "Η επισύναψη - αποστολή του αρχείου απέτυχε. Το μέγεθος του αρχείου υπερβαίνει το επιτρεπτό όριο");
} else { } else {
$clientFileName = $clientFile->getClientFilename(); $clientFileName = $clientFile->getClientFilename();
$clientFileNameExt = strtolower(pathinfo($clientFileName, PATHINFO_EXTENSION)); $clientFileNameExt = strtolower(pathinfo($clientFileName, PATHINFO_EXTENSION));
if (in_array($clientFileNameExt, $this->container['settings']['application_form']['file_upload_extensions'])) { if (in_array($clientFileNameExt, $this->container['settings']['receive_equip']['file_upload_types_permitted'])) {
$receivedDocumentFileName = $receivedDocumentFileName . "." . $clientFileNameExt; $receivedDocumentFileName = $receivedDocumentFileName . "." . $clientFileNameExt;
$clientFile->moveTo($this->container['settings']['application_form']['file_upload_path'] . "/" . $receivedDocumentFileName);
try {
$clientFile->moveTo($this->container['settings']['receive_equip']['file_upload_path'] . "/" . $receivedDocumentFileName);
}
catch (InvalidArgumentException $e) {
array_push($this->formErrorMessages, "Η επισύναψη - αποστολή του αρχείου απέτυχε. Η διαδρομή προορισμού δεν υπάρχει");
$vf = false;
}
catch (RuntimeException $e) {
array_push($this->formErrorMessages, "Η επισύναψη - αποστολή του αρχείου απέτυχε. Σφάλμα στην μετακίνηση του αρχείου");
$vf = false;
}
} else { } else {
$isValidFile = false; $vf = false;
$this->flash->addMessage('danger', "Η επισύναψη - αποστολή του αρχείου απέτυχε. Ο τύπος του αρχείου δεν είναι επιτρεπτός"); array_push($this->formErrorMessages, "Η επισύναψη - αποστολή του αρχείου απέτυχε. Ο τύπος του αρχείου δεν είναι επιτρεπτός");
} }
} }
$response = 'There is no error, the file uploaded with success.';
break; break;
case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_INI_SIZE:
$isValidFile = false; $vf = false;
$this->flash->addMessage('danger', "Η επισύναψη - αποστολή του αρχείου απέτυχε"); array_push($this->formErrorMessages, "Η επισύναψη - αποστολή του αρχείου απέτυχε. Το μέγεθος του αρχείου υπερβαίνει το επιτρεπτό όριο");
$response = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
break; break;
case UPLOAD_ERR_FORM_SIZE: case UPLOAD_ERR_FORM_SIZE:
$isValidFile = false; $vf = false;
$this->flash->addMessage('danger', "Η επισύναψη - αποστολή του αρχείου απέτυχε"); array_push($this->formErrorMessages, "Η επισύναψη - αποστολή του αρχείου απέτυχε. Το μέγεθος του αρχείου υπερβαίνει το επιτρεπτό όριο της φόρμας παραλαβής");
$response = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';
break; break;
case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_PARTIAL:
$isValidFile = false; $vf = false;
$this->flash->addMessage('danger', "Η επισύναψη - αποστολή του αρχείου απέτυχε"); array_push($this->formErrorMessages, "Η επισύναψη - αποστολή του αρχείου απέτυχε. Μόνο τμήμα του αρχείου αποστάλθηκε. Προσπαθήστε πάλι");
$response = 'The uploaded file was only partially uploaded.';
break; break;
case UPLOAD_ERR_NO_FILE: case UPLOAD_ERR_NO_FILE:
$isValidFile = false; $vf = false;
$this->flash->addMessage('danger', "Η επισύναψη - αποστολή του αρχείου απέτυχε"); array_push($this->formErrorMessages, "Η επισύναψη - αποστολή του αρχείου απέτυχε. Το αρχείο δεν βρέθηκε. Προσπαθήστε πάλι");
$response = 'No file was uploaded.';
break; break;
case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_NO_TMP_DIR:
$isValidFile = false; $vf = false;
$this->flash->addMessage('danger', "Η επισύναψη - αποστολή του αρχείου απέτυχε"); array_push($this->formErrorMessages, "Η επισύναψη - αποστολή του αρχείου απέτυχε. Δεν υπάρχει προσωρινός χώρος αποθήκευσης");
$response = 'Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.';
break; break;
case UPLOAD_ERR_CANT_WRITE: case UPLOAD_ERR_CANT_WRITE:
$isValidFile = false; $vf = false;
$this->flash->addMessage('danger', "Η επισύναψη - αποστολή του αρχείου απέτυχε"); array_push($this->formErrorMessages, "Η επισύναψη - αποστολή του αρχείου απέτυχε. Αποτυχία αποθήκευσης");
$response = 'Failed to write file to disk. Introduced in PHP 5.1.0.';
break; break;
case UPLOAD_ERR_EXTENSION: case UPLOAD_ERR_EXTENSION:
$isValidFile = false; $vf = false;
$this->flash->addMessage('danger', "Η επισύναψη - αποστολή του αρχείου απέτυχε"); array_push($this->formErrorMessages, "Η επισύναψη - αποστολή του αρχείου απέτυχε. Η αποστολή τερματίστηκε πρόωρα");
$response = 'File upload stopped by extension. Introduced in PHP 5.2.0.';
break; break;
default: default:
$isValidFile = false; $vf = false;
$this->flash->addMessage('danger', "Η επισύναψη - αποστολή του αρχείου απέτυχε"); array_push($this->formErrorMessages, "Η επισύναψη - αποστολή του αρχείου απέτυχε. Απροσδιόριστο σφάλμα");
$response = 'Unknown upload error';
break; break;
} }
if ($vf === true) {
return $receivedDocumentFileName;
}
else {
return null;
}
} }
} }
...@@ -15,6 +15,7 @@ use Zend\Filter; ...@@ -15,6 +15,7 @@ use Zend\Filter;
use Zend\InputFilter\CollectionInputFilter; use Zend\InputFilter\CollectionInputFilter;
use Zend\InputFilter\Input; use Zend\InputFilter\Input;
use Zend\InputFilter\InputFilter; use Zend\InputFilter\InputFilter;
use Zend\InputFilter\FileInput;
use Zend\Validator; use Zend\Validator;
class ReceiveEquip extends InputFilter class ReceiveEquip extends InputFilter
...@@ -30,7 +31,7 @@ class ReceiveEquip extends InputFilter ...@@ -30,7 +31,7 @@ class ReceiveEquip extends InputFilter
->attach(new Filter\ToInt()); ->attach(new Filter\ToInt());
$id->getValidatorChain() $id->getValidatorChain()
->attach(new Validator\NotEmpty()); ->attach(new Validator\NotEmpty());
$schoolId = new Input('school_id'); $schoolId = new Input('school_id');
$schoolId->setRequired(true) $schoolId->setRequired(true)
->getFilterChain() ->getFilterChain()
...@@ -46,9 +47,14 @@ class ReceiveEquip extends InputFilter ...@@ -46,9 +47,14 @@ class ReceiveEquip extends InputFilter
'useDomainCheck' => false, 'useDomainCheck' => false,
])); ]));
/* $received_document = new FileInput('received_document');
$received_document->getValidatorChain()
->attach(new Validator\File\UploadFile()); */
$this->add($id) $this->add($id)
->add($schoolId) ->add($schoolId)
->add($submittedBy) ->add($submittedBy)
// ->add($received_document)
->add($itemsInputFilter, 'items'); ->add($itemsInputFilter, 'items');
} }
} }
...@@ -17,7 +17,7 @@ use Slim\Http\Response; ...@@ -17,7 +17,7 @@ use Slim\Http\Response;
use Slim\Views\Twig;