From 61d7b68a796e3b06e036341f4fde9b9fafc009d4 Mon Sep 17 00:00:00 2001 From: Cris Date: Thu, 17 Feb 2022 14:48:19 +0100 Subject: [PATCH] Added validation checks on post data Checking date restrictions and other mandatory post params. Deleted client side validations, now they are performed only on server side. --- .../lvplanung/AdminZeitverfuegbarkeit.php | 56 +++++++++++++++++-- public/js/lehre/lvplanung/zverfueg.js | 29 ---------- 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/application/controllers/lehre/lvplanung/AdminZeitverfuegbarkeit.php b/application/controllers/lehre/lvplanung/AdminZeitverfuegbarkeit.php index 8bfb88c71..e039b924d 100644 --- a/application/controllers/lehre/lvplanung/AdminZeitverfuegbarkeit.php +++ b/application/controllers/lehre/lvplanung/AdminZeitverfuegbarkeit.php @@ -94,7 +94,8 @@ class AdminZeitverfuegbarkeit extends Auth_Controller $bisDatum = $this->input->post('bisdatum'); $bisStunde = isEmptyString($this->input->post('bisstunde')) ? null : $this->input->post('bisstunde'); - if ($this->_validate()) // TODO + $result = $this->_validate($this->input->post()); + if (isSuccess($result)) { if (is_numeric($zeitsperre_id)) { @@ -144,7 +145,7 @@ class AdminZeitverfuegbarkeit extends Auth_Controller { $zeitsperre_id = $this->input->post('zeitsperre_id'); - if (!isset($zeitsperre_id) || !is_numeric($zeitsperre_id)) + if (!is_numeric($zeitsperre_id)) { $this->terminateWithJsonError('Wählen Sie einen Lehrenden aus der Zeitverfügbarkeit-Tabelle aus.'); } @@ -213,9 +214,56 @@ class AdminZeitverfuegbarkeit extends Auth_Controller return $this->StundeModel->load(); } - private function _validate() + /** + * Validaton checks performed on post data. + * + * @param $post + * @return array|stdClass + * @throws Exception + */ + private function _validate($post) { - return true; + if (isEmptyString($post['mitarbeiter_uid'])) + { + return (error('LektorIn fehlt')); + } + + if (isEmptyString($post['vondatum'])) + { + return error('Startdatum fehlt'); + } + + if (isEmptyString($post['bisdatum'])) + { + return error('Endedatum fehlt'); + } + + if (new DateTime($post['bisdatum']) < new DateTime($post['vondatum'])) + { + return error('Endedatum darf nicht VOR dem Startdatum liegen'); + } + + // Check bisstunde not after vonstunde within same day + if (new DateTime($post['bisdatum']) == new DateTime($post['vondatum'])) + { + if (is_numeric($post['vonstunde']) && is_numeric($post['bisstunde']) + && $post['bisstunde'] < $post['vonstunde']) + { + return error('Am gleichen Tag darf Endstunde nicht VOR der Startstunde liegen'); + } + } + + // Check dates are > then start of actual Studiensemester + $result = $this->StudiensemesterModel->getAkt(); + $studsemStart = hasData($result) ? getData($result)[0]->start : ''; + + if (new DateTime($post['vondatum']) < new DateTime($studsemStart) || + new DateTime($post['bisdatum']) < new DateTime($studsemStart)) + { + return error('Start- und Endedatum können nur für das aktuelle oder künftige Studiensemester geplant werden'); + } + + return success(); } } diff --git a/public/js/lehre/lvplanung/zverfueg.js b/public/js/lehre/lvplanung/zverfueg.js index 7cac20f14..c622edcf0 100644 --- a/public/js/lehre/lvplanung/zverfueg.js +++ b/public/js/lehre/lvplanung/zverfueg.js @@ -16,17 +16,6 @@ $(function(){ let bisdatum = this.bisdatum.value; let bisstunde = this.bisstunde.value; - - if (!Zverfueg.hasValidDate(vondatum, bisdatum)) - { - return FHC_DialogLib.alertInfo('Enddatum darf nicht NACH Startdatum liegen.'); - } - - if (!Zverfueg.hasValidStunden(vondatum, bisdatum, vonstunde, bisstunde)) - { - return FHC_DialogLib.alertInfo('Am gleichen Tag muss die Endstunde NACH der Anfangsstunde liegen.'); - } - FHC_AjaxClient.ajaxCallPost( FHC_JS_DATA_STORAGE_OBJECT.called_path + "/saveZeitverfuegbarkeit", { @@ -153,24 +142,6 @@ var Zverfueg = { enableFormElements: function (){ $('#btn-delete').prop('disabled', false); $('#mitarbeiter_uid').prop('disabled', true); - }, - hasValidDate: function(vonDatum, bisDatum){ - if (bisDatum < vonDatum) - { - return false; - } - - return true; - }, - hasValidStunden: function (vonDatum, bisDatum, vonStunde, bisStunde){ - if (vonDatum == bisDatum) - { - if ($.isNumeric(vonStunde) && $.isNumeric(bisStunde) && (bisStunde < vonStunde)) - { - return false; - } - } - return true; } }