From 3823f7f1d17c3a53b95551efc4b8753d8a2adeca Mon Sep 17 00:00:00 2001 From: bison Date: Tue, 30 Aug 2016 13:52:40 +0200 Subject: [PATCH] Now when inserting a new person with the same svnr, it will be created a new version of the svnr: + "v" + --- .../controllers/api/v1/person/Person.php | 226 ++++++++---------- application/models/person/Person_model.php | 25 +- 2 files changed, 108 insertions(+), 143 deletions(-) diff --git a/application/controllers/api/v1/person/Person.php b/application/controllers/api/v1/person/Person.php index 1bb9dcb03..81e6b6f3b 100644 --- a/application/controllers/api/v1/person/Person.php +++ b/application/controllers/api/v1/person/Person.php @@ -12,7 +12,7 @@ */ // ------------------------------------------------------------------------ -if (!defined('BASEPATH')) exit('No direct script access allowed'); +if (!defined("BASEPATH")) exit("No direct script access allowed"); class Person extends APIv1_Controller { @@ -23,7 +23,7 @@ class Person extends APIv1_Controller { parent::__construct(); // Load model PersonModel - $this->load->model('person/person_model', 'PersonModel'); + $this->load->model("person/person_model", "PersonModel"); } /** @@ -31,23 +31,23 @@ class Person extends APIv1_Controller */ public function getPerson() { - $personID = $this->get('person_id'); - $code = $this->get('code'); - $email = $this->get('email'); + $personID = $this->get("person_id"); + $code = $this->get("code"); + $email = $this->get("email"); if (isset($code) || isset($email) || isset($personID)) { if (isset($code) && isset($email)) { - $result = $this->PersonModel->addJoin('public.tbl_kontakt', 'person_id'); + $result = $this->PersonModel->addJoin("public.tbl_kontakt", "person_id"); if ($result->error == EXIT_SUCCESS) { - $result = $this->PersonModel->loadWhere(array('zugangscode' => $code, 'kontakt' => $email)); + $result = $this->PersonModel->loadWhere(array("zugangscode" => $code, "kontakt" => $email)); } } elseif (isset($code)) { - $result = $this->PersonModel->loadWhere(array('zugangscode' => $code)); + $result = $this->PersonModel->loadWhere(array("zugangscode" => $code)); } else { @@ -72,12 +72,19 @@ class Person extends APIv1_Controller if (is_object($validation) && $validation->error == EXIT_SUCCESS) { - if(isset($person['person_id']) && !(is_null($person["person_id"])) && ($person["person_id"] != "")) + if(isset($person["person_id"]) && !(is_null($person["person_id"])) && ($person["person_id"] != "")) { - $result = $this->PersonModel->update($person['person_id'], $person); + $result = $this->PersonModel->update($person["person_id"], $person); } else { + $result = $this->PersonModel->loadWhere(array("SUBSTRING(svnr FROM 1 FOR 10) = " => $person["svnr"])); + if (is_object($result) && $result->error == EXIT_SUCCESS && + is_array($result->retval) && count($result->retval) > 0) + { + $person["svnr"] = $person["svnr"] . "v" . count($result->retval); + } + $result = $this->PersonModel->insert($person); } @@ -94,8 +101,8 @@ class Person extends APIv1_Controller */ public function getCheckBewerbung() { - $email = $this->get('email'); - $studiensemester_kurzbz = $this->get('studiensemester_kurzbz'); + $email = $this->get("email"); + $studiensemester_kurzbz = $this->get("studiensemester_kurzbz"); if (isset($email)) { @@ -113,87 +120,74 @@ class Person extends APIv1_Controller { if (!isset($person)) { - return $this->_error('Parameter is null'); + return $this->_error("Parameter is null"); } - if (isset($person['nachname'])) - $person['nachname'] = trim($person['nachname']); - if (isset($person['vorname'])) - $person['vorname'] = trim($person['vorname']); - if (isset($person['vornamen'])) - $person['vornamen'] = trim($person['vornamen']); - if (isset($person['anrede'])) - $person['anrede'] = trim($person['anrede']); - if (isset($person['titelpost'])) - $person['titelpost'] = trim($person['titelpost']); - if (isset($person['titelpre'])) - $person['titelpre'] = trim($person['titelpre']); + if (isset($person["nachname"])) + $person["nachname"] = trim($person["nachname"]); + if (isset($person["vorname"])) + $person["vorname"] = trim($person["vorname"]); + if (isset($person["vornamen"])) + $person["vornamen"] = trim($person["vornamen"]); + if (isset($person["anrede"])) + $person["anrede"] = trim($person["anrede"]); + if (isset($person["titelpost"])) + $person["titelpost"] = trim($person["titelpost"]); + if (isset($person["titelpre"])) + $person["titelpre"] = trim($person["titelpre"]); - if (isset($person['sprache']) && mb_strlen($person['sprache']) > 16) + if (isset($person["sprache"]) && mb_strlen($person["sprache"]) > 16) { - return $this->_error('Sprache darf nicht laenger als 16 Zeichen sein'); + return $this->_error("Sprache darf nicht laenger als 16 Zeichen sein"); } - if (isset($person['anrede']) && mb_strlen($person['anrede']) > 16) + if (isset($person["anrede"]) && mb_strlen($person["anrede"]) > 16) { - return $this->_error('Anrede darf nicht laenger als 16 Zeichen sein'); + return $this->_error("Anrede darf nicht laenger als 16 Zeichen sein"); } - if (isset($person['titelpost']) && mb_strlen($person['titelpost']) > 32) + if (isset($person["titelpost"]) && mb_strlen($person["titelpost"]) > 32) { - return $this->_error('Titelpost darf nicht laenger als 32 Zeichen sein'); + return $this->_error("Titelpost darf nicht laenger als 32 Zeichen sein"); } - if (isset($person['titelpre']) && mb_strlen($person['titelpre']) > 64) + if (isset($person["titelpre"]) && mb_strlen($person["titelpre"]) > 64) { - return $this->_error('Titelpre darf nicht laenger als 64 Zeichen sein'); + return $this->_error("Titelpre darf nicht laenger als 64 Zeichen sein"); } - if (isset($person['nachname']) && mb_strlen($person['nachname']) > 64) + if (isset($person["nachname"]) && mb_strlen($person["nachname"]) > 64) { - return $this->_error('Nachname darf nicht laenger als 64 Zeichen sein'); + return $this->_error("Nachname darf nicht laenger als 64 Zeichen sein"); } - if (isset($person['nachname']) && ($person['nachname'] == '' || is_null($person['nachname']))) + if (isset($person["nachname"]) && ($person["nachname"] == "" || is_null($person["nachname"]))) { - return $this->_error('Nachname muss eingegeben werden'); + return $this->_error("Nachname muss eingegeben werden"); } - if (isset($person['vorname']) && mb_strlen($person['vorname']) > 32) + if (isset($person["vorname"]) && mb_strlen($person["vorname"]) > 32) { - return $this->_error('Vorname darf nicht laenger als 32 Zeichen sein'); + return $this->_error("Vorname darf nicht laenger als 32 Zeichen sein"); } - if (isset($person['vornamen']) && mb_strlen($person['vornamen']) > 128) + if (isset($person["vornamen"]) && mb_strlen($person["vornamen"]) > 128) { - return $this->_error('Vornamen darf nicht laenger als 128 Zeichen sein'); + return $this->_error("Vornamen darf nicht laenger als 128 Zeichen sein"); } - //ToDo Gebdatum pruefen -> laut bis muss student aelter als 10 Jahre sein - /* if (strlen($person['gebdatum) == 0 || is_null($person['gebdatum)) - { - return $this->_error("Geburtsdatum muss eingegeben werden\n"; - return false; - } */ - if (isset($person['gebort']) && mb_strlen($person['gebort']) > 128) + if (isset($person["gebort"]) && mb_strlen($person["gebort"]) > 128) { - return $this->_error('Geburtsort darf nicht laenger als 128 Zeichen sein'); + return $this->_error("Geburtsort darf nicht laenger als 128 Zeichen sein"); } - - if (isset($person['homepage']) && mb_strlen($person['homepage']) > 256) + if (isset($person["homepage"]) && mb_strlen($person["homepage"]) > 256) { - return $this->_error('Homepage darf nicht laenger als 256 Zeichen sein'); + return $this->_error("Homepage darf nicht laenger als 256 Zeichen sein"); } - if (isset($person['svnr']) && mb_strlen($person['svnr']) > 16) + if (isset($person["matr_nr"]) && mb_strlen($person["matr_nr"]) > 32) { - return $this->_error('SVNR darf nicht laenger als 16 Zeichen sein'); - } - - if (isset($person['matr_nr']) && mb_strlen($person['matr_nr']) > 32) - { - return $this->_error('Matrikelnummer darf nicht laenger als 32 Zeichen sein'); + return $this->_error("Matrikelnummer darf nicht laenger als 32 Zeichen sein"); return false; } - - if (isset($person['svnr']) && $person['svnr'] != '' && mb_strlen($person['svnr']) != 16 && mb_strlen($person['svnr']) != 10) + if (isset($person["svnr"]) && $person["svnr"] != "" && mb_strlen($person["svnr"]) != 16 && + mb_strlen($person["svnr"]) != 12 && mb_strlen($person["svnr"]) != 10) { - return $this->_error('SVNR muss 10 oder 16 Zeichen lang sein'); + return $this->_error("SVNR muss 10, 12 oder 16 Zeichen lang sein"); } - - if (isset($person['svnr']) && $person['svnr'] != '' && mb_strlen($person['svnr']) == 10) + if (isset($person["svnr"]) && (mb_strlen($person["svnr"]) == 10 || mb_strlen($person["svnr"]) == 12)) { //SVNR mit Pruefziffer pruefen //Die 4. Stelle in der SVNR ist die Pruefziffer @@ -201,113 +195,89 @@ class Person extends APIv1_Controller //Falls nicht, ist die SVNR ungueltig $gewichtung = array(3, 7, 9, 0, 5, 8, 4, 2, 1, 6); $erg = 0; + $tmpSvnr = substr($person["svnr"], 0, 10); //Quersumme bilden for ($i = 0; $i < 10; $i++) { - $erg += $gewichtung[$i] * $person['svnr']{$i}; + $erg += $gewichtung[$i] * $tmpSvnr{$i}; } - if ($person['svnr']{3} != ($erg % 11)) //Vergleichen der Pruefziffer mit Quersumme Modulo 11 + if ($tmpSvnr{3} != ($erg % 11)) //Vergleichen der Pruefziffer mit Quersumme Modulo 11 { - return $this->_error('SVNR ist ungueltig'); + return $this->_error("SVNR ist ungueltig"); } - } - - /*if ($person['svnr'] != '') - { - //Pruefen ob bereits ein Eintrag mit dieser SVNR vorhanden ist - $qry = "SELECT person_id FROM public.tbl_person WHERE svnr=" . $person['svnr']; - if (db_query($qry)) + + if (mb_strlen($person["svnr"]) == 12) { - if ($row = db_fetch_object()) + $last = substr($person["svnr"], 10, 12); + if ($last{0} != "v" || !is_numeric($last{1})) { - if ($row->person_id != $person['person_id']) - { - return $this->_error('Es existiert bereits eine Person mit dieser SVNR! Daten wurden NICHT gespeichert.'); - } + return $this->_error("SVNR ist ungueltig"); } } - }*/ - - if (isset($person['ersatzkennzeichen']) && mb_strlen($person['ersatzkennzeichen']) > 10) - { - return $this->_error('Ersatzkennzeichen darf nicht laenger als 10 Zeichen sein'); } - if (isset($person['familienstand']) && mb_strlen($person['familienstand']) > 1) + if (isset($person["ersatzkennzeichen"]) && mb_strlen($person["ersatzkennzeichen"]) > 10) { - return $this->_error('Familienstand ist ungueltig'); + return $this->_error("Ersatzkennzeichen darf nicht laenger als 10 Zeichen sein"); } - if (isset($person['anzahlkinder']) && $person['anzahlkinder'] != '' && !is_numeric($person['anzahlkinder'])) + if (isset($person["familienstand"]) && mb_strlen($person["familienstand"]) > 1) { - return $this->_error('Anzahl der Kinder ist ungueltig'); + return $this->_error("Familienstand ist ungueltig"); } - if (!isset($person['aktiv']) || (isset($person['aktiv']) && $person['aktiv'] != "t" && $person['aktiv'] != "f")) + if (isset($person["anzahlkinder"]) && $person["anzahlkinder"] != "" && !is_numeric($person["anzahlkinder"])) { - return $this->_error('Aktiv ist ungueltig'); + return $this->_error("Anzahl der Kinder ist ungueltig"); } - if (!isset($person['person_id']) && isset($person['insertvon']) && mb_strlen($person['insertvon']) > 32) + if (!isset($person["aktiv"]) || (isset($person["aktiv"]) && $person["aktiv"] != "t" && $person["aktiv"] != "f")) { - return $this->_error('Insertvon darf nicht laenger als 32 Zeichen sein'); + return $this->_error("Aktiv ist ungueltig"); } - if (isset($person['updatevon']) && mb_strlen($person['updatevon']) > 32) + if (!isset($person["person_id"]) && isset($person["insertvon"]) && mb_strlen($person["insertvon"]) > 32) { - return $this->_error('Updatevon darf nicht laenger als 32 Zeichen sein'); + return $this->_error("Insertvon darf nicht laenger als 32 Zeichen sein"); } - /*if ($person['ext_id'] != '' && !is_numeric($person['ext_id'])) + if (isset($person["updatevon"]) && mb_strlen($person["updatevon"]) > 32) { - return $this->_error('Ext_ID ist keine gueltige Zahl'; - return false; - }*/ - if (!isset($person['geschlecht']) || (isset($person['geschlecht']) && mb_strlen($person['geschlecht']) > 1)) - { - return $this->_error('Geschlecht darf nicht laenger als 1 Zeichen sein'); + return $this->_error("Updatevon darf nicht laenger als 32 Zeichen sein"); } - if (isset($person['geburtsnation']) && mb_strlen($person['geburtsnation']) > 3) + if (!isset($person["geschlecht"]) || (isset($person["geschlecht"]) && mb_strlen($person["geschlecht"]) > 1)) { - return $this->_error('Geburtsnation darf nicht laenger als 3 Zeichen sein'); + return $this->_error("Geschlecht darf nicht laenger als 1 Zeichen sein"); } - if (isset($person['staatsbuergerschaft']) && mb_strlen($person['staatsbuergerschaft']) > 3) + if (isset($person["geburtsnation"]) && mb_strlen($person["geburtsnation"]) > 3) { - return $this->_error('Staatsbuergerschaft darf nicht laenger als 3 Zeichen sein'); + return $this->_error("Geburtsnation darf nicht laenger als 3 Zeichen sein"); } - if (isset($person['geschlecht']) && $person['geschlecht'] != 'm' && $person['geschlecht'] != 'w' && $person['geschlecht'] != 'u') + if (isset($person["staatsbuergerschaft"]) && mb_strlen($person["staatsbuergerschaft"]) > 3) { - return $this->_error('Geschlecht muss w, m oder u sein!'); + return $this->_error("Staatsbuergerschaft darf nicht laenger als 3 Zeichen sein"); + } + if (isset($person["geschlecht"]) && $person["geschlecht"] != "m" && $person["geschlecht"] != "w" && $person["geschlecht"] != "u") + { + return $this->_error("Geschlecht muss w, m oder u sein!"); } //Pruefen ob das Geburtsdatum mit der SVNR uebereinstimmt. - if (isset($person['svnr']) && isset($person['gebdatum']) && $person['svnr'] != '' && $person['gebdatum'] != '') + if (isset($person["svnr"]) && isset($person["gebdatum"]) && $person["svnr"] != "" && $person["gebdatum"] != "") { - if (mb_ereg("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})", $person['gebdatum'], $regs)) + if (mb_ereg("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})", $person["gebdatum"], $regs)) { - //$day = sprintf('%02s',$regs[1]); - //$month = sprintf('%02s',$regs[2]); + //$day = sprintf("%02s",$regs[1]); + //$month = sprintf("%02s",$regs[2]); //$year = mb_substr($regs[3],2,2); } - elseif (mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})", $person['gebdatum'], $regs)) + elseif (mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})", $person["gebdatum"], $regs)) { - //$day = sprintf('%02s',$regs[3]); - //$month = sprintf('%02s',$regs[2]); + //$day = sprintf("%02s",$regs[3]); + //$month = sprintf("%02s",$regs[2]); //$year = mb_substr($regs[1],2,2); } else { - return $this->_error('Format des Geburtsdatums ist ungueltig'); + return $this->_error("Format des Geburtsdatums ist ungueltig"); } - - /* das muss nicht immer so sein - $day_svnr = mb_substr($person['svnr, 4, 2); - $month_svnr = mb_substr($person['svnr, 6, 2); - $year_svnr = mb_substr($person['svnr, 8, 2); - - if ($day_svnr!=$day || $month_svnr!=$month || $year_svnr!=$year) - { - return $this->_error('SVNR und Geburtsdatum passen nicht zusammen'; - return false; - } - */ } - return $this->_success('Input data are valid'); + return $this->_success("Input data are valid"); } } \ No newline at end of file diff --git a/application/models/person/Person_model.php b/application/models/person/Person_model.php index 1980f07ec..7fe986b17 100644 --- a/application/models/person/Person_model.php +++ b/application/models/person/Person_model.php @@ -17,21 +17,16 @@ class Person_model extends DB_Model */ public function checkBewerbung($email, $studiensemester_kurzbz = null) { - // Checks if the operation is permitted by the API caller - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_person'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_person'), FHC_MODEL_ERROR); - - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_kontakt'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_kontakt'), FHC_MODEL_ERROR); - - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_benutzer'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_benutzer'), FHC_MODEL_ERROR); - - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_prestudent'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_prestudent'), FHC_MODEL_ERROR); - - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_prestudentstatus'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_prestudentstatus'), FHC_MODEL_ERROR); + if (($chkRights = $this->isEntitled("public.tbl_person", "s", FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) + return $chkRights; + if (($chkRights = $this->isEntitled("public.tbl_kontakt", "s", FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) + return $chkRights; + if (($chkRights = $this->isEntitled("public.tbl_benutzer", "s", FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) + return $chkRights; + if (($chkRights = $this->isEntitled("public.tbl_prestudent", "s", FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) + return $chkRights; + if (($chkRights = $this->isEntitled("public.tbl_prestudentstatus", "s", FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) + return $chkRights; $result = null;