diff --git a/application/controllers/codex/UHSTAT1.php b/application/controllers/codex/UHSTAT1.php index 3ba4760a5..0e019672a 100644 --- a/application/controllers/codex/UHSTAT1.php +++ b/application/controllers/codex/UHSTAT1.php @@ -4,6 +4,8 @@ if (! defined("BASEPATH")) exit("No direct script access allowed"); class UHSTAT1 extends FHC_Controller { + const BERECHTIGUNG_UHSTAT_VERWALTEN = 'student/uhstat1daten_verwalten'; + const PERSON_ID_SESSION_INDEX = 'bewerbung/personId'; const CODEX_OESTERREICH = 'A'; const LOWER_BOUNDARY_YEARS = 160; const UPPER_BOUNDARY_YEARS = 20; @@ -12,12 +14,7 @@ class UHSTAT1 extends FHC_Controller public function __construct() { - parent::__construct( - array( - 'index' => 'admin:r', - 'saveUHSTAT1Data' => 'admin:rw' - ) - ); + parent::__construct(); // load ci libs $this->load->library('form_validation'); @@ -25,6 +22,10 @@ class UHSTAT1 extends FHC_Controller // load ci helpers $this->load->helper(array('form', 'url')); + // load libraries + $this->load->library('AuthLib'); + $this->load->library('PermissionLib'); + // load models $this->load->model('codex/Oehbeitrag_model', 'OehbeitragModel'); $this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel'); @@ -93,9 +94,7 @@ class UHSTAT1 extends FHC_Controller */ public function saveUHSTAT1Data() { - $person_id = $this->input->get('person_id'); - - if (!isset($person_id) || !is_numeric($person_id)) show_error("Person Id missing"); + $person_id = $this->_getValidPersonId(); $this->form_validation->set_error_delimiters('', ''); @@ -133,8 +132,10 @@ class UHSTAT1 extends FHC_Controller $uhstatData[$field] = $this->input->post($field); } + // check if entry already exists $uhstat1datenloadRes = $this->Uhstat1datenModel->loadWhere(array('person_id' => $person_id)); + // if yes, update if (hasData($uhstat1datenloadRes)) { $uhstat1datenRes = $this->Uhstat1datenModel->update( @@ -142,7 +143,7 @@ class UHSTAT1 extends FHC_Controller $uhstatData ); } - else + else // otherwise insert { $uhstat1datenRes = $this->Uhstat1datenModel->insert( array_merge($uhstatData, array('person_id' => $person_id)) @@ -210,9 +211,7 @@ class UHSTAT1 extends FHC_Controller */ private function _getFormMetaData() { - $person_id = $this->input->get('person_id'); - - if (!isset($person_id) || !is_numeric($person_id)) return error("Person Id missing"); + $person_id = $this->_getValidPersonId(); $languageIdx = $this->_getLanguageIndex(); @@ -272,9 +271,7 @@ class UHSTAT1 extends FHC_Controller */ private function _getUHSTAT1Data() { - $person_id = $this->input->get('person_id'); - - if (!isset($person_id) || !is_numeric($person_id)) return error("Person Id missing"); + $person_id = $this->_getValidPersonId(); $this->Uhstat1datenModel->addSelect( implode(', ', array_keys($this->_uhstat1Fields)) @@ -303,4 +300,27 @@ class UHSTAT1 extends FHC_Controller return $idx; } + + /** + * Gets Id of person having permissions to manage UHSTAT1 data. + * Can be passed as parameter or be in session. + * @return int person_id + */ + private function _getValidPersonId() + { + // if coming from bewerbungstool - person id is in session (person must be logged in bewerbungstool) + if (isset($_SESSION[self::PERSON_ID_SESSION_INDEX]) && is_numeric($_SESSION[self::PERSON_ID_SESSION_INDEX])) + return $_SESSION[self::PERSON_ID_SESSION_INDEX]; + + // if person id passed directly... + $person_id = $this->input->post('person_id'); + if (!isset($person_id)) $person_id = $this->input->get('person_id'); + + if (!isset($person_id) || !is_numeric($person_id)) show_error("invalid person id"); + + // ...check if there is a permission for editing UHSTAT1 data + if ($this->permissionlib->isBerechtigt(self::BERECHTIGUNG_UHSTAT_VERWALTEN, 'suid')) return $person_id; + + show_error("No permission for managing UHSTAT"); + } } diff --git a/application/views/codex/uhstat1.php b/application/views/codex/uhstat1.php index b60f518a4..b81b0b316 100644 --- a/application/views/codex/uhstat1.php +++ b/application/views/codex/uhstat1.php @@ -6,15 +6,17 @@ $this->load->view( 'jquery3' => true, 'bootstrap3' => true, 'fontawesome4' => true, - 'dialoglib' => true, 'phrases' => array( 'ui' => array('speichern') - ) + ), + 'customCSSs' => array('public/css/codex/uhstat1.css'), + 'customJSs' => array('public/js/codex/uhstat1.js') + ) ); ?> mutter_geburtsjahr) ? $uhstatData->mutter_geburtsjahr : set_value('mutter_geburtsjahr'); $mutter_geburtsstaat = isset($uhstatData->mutter_geburtsstaat) ? $uhstatData->mutter_geburtsstaat : set_value('mutter_geburtsstaat'); $mutter_bildungsstaat = isset($uhstatData->mutter_bildungsstaat) ? $uhstatData->mutter_bildungsstaat : set_value('mutter_bildungsstaat'); @@ -25,219 +27,224 @@ $vater_bildungsstaat = isset($uhstatData->vater_bildungsstaat) ? $uhstatData->va $vater_bildungmax = isset($uhstatData->vater_bildungmax) ? $uhstatData->vater_bildungmax : set_value('vater_bildungmax'); $disabled = $readonly === true ? ' disabled' : ''; ?> -
- p->t('uhstat', 'uhstat1AnmeldungEinleitungstext') ?> -
-