diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index d6ec53a1a..dd1de706d 100644 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -16,6 +16,8 @@ class Profil extends Auth_Controller { parent::__construct([ 'index' => ['student/anrechnung_beantragen:r','user:r'], // TODO(chris): permissions? + 'View' => ['student/anrechnung_beantragen:r','user:r'], + 'isMitarbeiterOrStudent' => ['student/anrechnung_beantragen:r','user:r'], 'getMitarbeiterAnsicht' => ['student/anrechnung_beantragen:r','user:r'], 'foto_sperre_function' => ['student/anrechnung_beantragen:r','user:r'], @@ -48,23 +50,54 @@ class Profil extends Auth_Controller /** * @return void */ + + public function index() { //? we can pass data to the view by using the second parameter of the load->view() function //* the first parameter is the route that Code Igniter will switch to //* the second parameter can be used to pass data to the view - $this->load->view('Cis/Profil', ["uid" => getAuthUID(),"pid" => getAuthPersonId()]); + $this->load->view('Cis/Profil', ["uid" => getAuthUID(),"pid" => getAuthPersonId(), "view"=> false]); } + //? attempt at rerouting methods + /* public function _remap($method, $params = array()) + { + if($method ==='View' || $method === 'Mitarbeiter'){ + + + return call_user_func_array(array($this, "searchView"), $params); + + }else{ + if (method_exists($this, $method)) + { + return call_user_func_array(array($this, $method), $params); + } + } + } */ + + public function View($uid){ + + //? get the personID of the uid + isSuccess($this->BenutzerModel->addSelect(["person_id"])); + $personID_res = $this->BenutzerModel->load([$uid]); + $personID_res = hasData($personID_res) ? getData($personID_res)[0] : null; + + $this->load->view('Cis/Profil', ["uid" => $uid,"pid" => $personID_res->person_id,"view"=>true]); + + } + - public function studentProfil(){ + + public function studentProfil($uid, $view=false){ if( + !$view && isSuccess($this->BenutzergruppeModel->addSelect(['bezeichnung'])) && isSuccess($this->BenutzergruppeModel->addJoin('tbl_gruppe', 'gruppe_kurzbz' )) ){ - $zutrittsgruppe_res = $this->BenutzergruppeModel->loadWhere(array("uid"=>getAuthUID(), "zutrittssystem"=>true)); + $zutrittsgruppe_res = $this->BenutzergruppeModel->loadWhere(array("uid"=>$uid, "zutrittssystem"=>true)); if(isError($zutrittsgruppe_res)){ // catch error } @@ -78,7 +111,7 @@ class Profil extends Auth_Controller if(isSuccess($this->StudentModel->addSelect(['tbl_studiengang.bezeichnung as studiengang','tbl_student.semester', 'tbl_student.verband', 'tbl_student.gruppe' ,'tbl_student.matrikelnr as personenkennzeichen'])) && isSuccess($this->StudentModel->addJoin('tbl_studiengang', "tbl_studiengang.studiengang_kz=tbl_student.studiengang_kz"))) { - $student_res = $this->StudentModel->load([getAuthUID()]); + $student_res = $this->StudentModel->load([$uid]); if(isError($student_res)){ // catch error } @@ -89,8 +122,9 @@ class Profil extends Auth_Controller //? Matrikelnummer ist die Spalte matr_nr in Person - if(isSuccess($this->StudentModel->addSelect(["matr_nr"]))){ - $person_res = $this->PersonModel->load(getAuthPersonID()); + if(isSuccess($this->BenutzerModel->addSelect(["matr_nr"])) + && isSuccess($this->BenutzerModel->addJoin("tbl_person","person_id"))){ + $person_res = $this->BenutzerModel->load([$uid]); if(isError($person_res)){ // catch error }else{ @@ -104,7 +138,9 @@ class Profil extends Auth_Controller foreach($student_res as $key => $value){ $res->$key = $value; } + if(!$view){ $res->zuttritsgruppen = $zutrittsgruppe_res; + } echo json_encode($res); @@ -112,7 +148,7 @@ class Profil extends Auth_Controller } - public function mitarbeiterProfil(){ + public function mitarbeiterProfil($uid){ //? informationen die nur für den Mitarbeiter verfügbar sind @@ -121,7 +157,7 @@ class Profil extends Auth_Controller isSuccess($this->BenutzerfunktionModel->addSelect(["tbl_benutzerfunktion.bezeichnung as Bezeichnung","tbl_organisationseinheit.bezeichnung as Organisationseinheit","datum_von as Gültig_von","datum_bis as Gültig_bis","wochenstunden as Wochenstunden"]))&& isSuccess($this->BenutzerfunktionModel->addJoin("tbl_organisationseinheit","oe_kurzbz")) ){ - $benutzer_funktion_res = $this->BenutzerfunktionModel->loadWhere(array('uid'=>getAuthUID())); + $benutzer_funktion_res = $this->BenutzerfunktionModel->loadWhere(array('uid'=>$uid)); if(isError($benutzer_funktion_res)){ // error handling }else{ @@ -134,7 +170,7 @@ class Profil extends Auth_Controller if(isSuccess($this->MitarbeiterModel->addSelect(["kurzbz","telefonklappe", "alias"])) && isSuccess($this->MitarbeiterModel->addJoin("tbl_benutzer", "tbl_benutzer.uid = tbl_mitarbeiter.mitarbeiter_uid")) ){ - $mitarbeiter_res = $this->MitarbeiterModel->load(getAuthUID()); + $mitarbeiter_res = $this->MitarbeiterModel->load($uid); if(isError($mitarbeiter_res)){ // error handling }else{ @@ -148,7 +184,7 @@ class Profil extends Auth_Controller } $intern_email = array(); $intern_email+=array("type" => "intern"); - $intern_email+=array("email"=> getAuthUID() . "@" . DOMAIN); + $intern_email+=array("email"=> $uid . "@" . DOMAIN); $extern_email=array(); $extern_email+=array("type" => "alias"); $extern_email+=array("email" => $mitarbeiter_res->alias . "@" . DOMAIN); @@ -158,10 +194,84 @@ class Profil extends Auth_Controller echo json_encode($res); } - public function indexProfilInformaion(){ + + //? the view parameter is a flag that describes if a Profile from a different person is being viewed + public function indexProfilInformaion($uid, $view=false){ //? funktion returns all data needed for the student and the mitarbeiter profil view + $res = new stdClass(); + + //! falls der view flag auf flase gesetzt ist werden extra informationen des Users abgefragt + if(!$view){ + //? betriebsmittel soll nur der user selber sehen + if( + + isSuccess($this->BetriebsmittelpersonModel->addSelect(["CONCAT(betriebsmitteltyp, ' ' ,beschreibung) as Betriebsmittel","nummer as Nummer","ausgegebenam as Ausgegeben_am"])) + + ){ + //? betriebsmittel are not needed in a view + $betriebsmittelperson_res = $this->BetriebsmittelpersonModel->getBetriebsmittel(getAuthPersonId()); + if(isError($betriebsmittelperson_res)){ + // error handling + }else{ + $betriebsmittelperson_res = hasData($betriebsmittelperson_res)? getData($betriebsmittelperson_res) : null; + } + } + + if( + + //? kontaktdaten soll auch nur der user selbst sehen + isSuccess($this->KontaktModel->addSelect('DISTINCT ON (kontakttyp) kontakttyp, kontakt, tbl_kontakt.anmerkung, tbl_kontakt.zustellung')) && + isSuccess($this->KontaktModel->addJoin('public.tbl_standort', 'standort_id', 'LEFT')) && + isSuccess($this->KontaktModel->addJoin('public.tbl_firma', 'firma_id', 'LEFT'))&& + isSuccess($this->KontaktModel->addOrder('kontakttyp, kontakt, tbl_kontakt.updateamum, tbl_kontakt.insertamum')) + ){ + $kontakte_res = $this->KontaktModel->loadWhere(array('person_id' => getAuthPersonID())); + if(isError($kontakte_res)){ + // handle error + }else{ + $kontakte_res = hasData($kontakte_res)? getData($kontakte_res) : null; + } + + } + + //? FH Ausweis Austellungsdatum soll auch nur der user selbst sehen + $zutrittskarte_ausgegebenam = $this->BetriebsmittelpersonModel->getBetriebsmittelByUid($uid,"Zutrittskarte"); + if(isError($zutrittskarte_ausgegebenam)){ + // error handling + }else{ + $zutrittskarte_ausgegebenam = hasData($zutrittskarte_ausgegebenam)? getData($zutrittskarte_ausgegebenam)[0]->ausgegebenam : null; + //? formats the date from 01-01-2000 to 01.01.2000 + $zutrittskarte_ausgegebenam = str_replace("-",".",$zutrittskarte_ausgegebenam); + } + + + //? Die Adressen soll auch nur der user selber sehen + + if( + !$view && + isSuccess($adresse_res = $this->AdresseModel->addSelect(array("strasse","tbl_adressentyp.bezeichnung as adr_typ","plz","ort")))&& + isSuccess($adresse_res = $this->AdresseModel->addOrder("zustelladresse","DESC"))&& + isSuccess($adresse_res = $this->AdresseModel->addOrder("sort"))&& + isSuccess($adresse_res = $this->AdresseModel->addJoin("tbl_adressentyp","typ=adressentyp_kurzbz")) + ){ + $adresse_res = $this->AdresseModel->loadWhere(array("person_id"=>getAuthPersonID())); + if(isError($adresse_res)){ + // error handling + }else{ + $adresse_res = hasData($adresse_res)? getData($adresse_res) : null; + } + } + + //? die folgenden Informationen darf nur der eigene user sehen + $res->adressen = $adresse_res; + $res->zutrittsdatum = $zutrittskarte_ausgegebenam; + $res->kontakte = $kontakte_res; + $res->mittel = $betriebsmittelperson_res; + + } + if( isSuccess($this->PersonModel->addSelect('gruppe_kurzbz, beschreibung'))&& @@ -169,7 +279,7 @@ class Profil extends Auth_Controller isSuccess($this->PersonModel->addJoin('tbl_benutzergruppe', 'uid')) && isSuccess($this->PersonModel->addJoin('tbl_gruppe', 'gruppe_kurzbz'))){ - $mailverteiler_res = $this->PersonModel->loadWhere(array('mailgrp' => true, 'uid'=>getAuthUID())); + $mailverteiler_res = $this->PersonModel->loadWhere(array('mailgrp' => true, 'uid'=>$uid)); if( isError($mailverteiler_res)){ // catch error } @@ -179,60 +289,15 @@ class Profil extends Auth_Controller } - - if( - isSuccess($this->BetriebsmittelpersonModel->addSelect(["CONCAT(betriebsmitteltyp, ' ' ,beschreibung) as Betriebsmittel","nummer as Nummer","ausgegebenam as Ausgegeben_am"])) - - ){ - $betriebsmittelperson_res = $this->BetriebsmittelpersonModel->getBetriebsmittel(getAuthPersonId()); - if(isError($betriebsmittelperson_res)){ - // error handling - }else{ - $betriebsmittelperson_res = hasData($betriebsmittelperson_res)? getData($betriebsmittelperson_res) : null; - } - } - - - if(isSuccess($this->KontaktModel->addSelect('DISTINCT ON (kontakttyp) kontakttyp, kontakt, tbl_kontakt.anmerkung, tbl_kontakt.zustellung')) && - isSuccess($this->KontaktModel->addJoin('public.tbl_standort', 'standort_id', 'LEFT')) && - isSuccess($this->KontaktModel->addJoin('public.tbl_firma', 'firma_id', 'LEFT'))&& - isSuccess($this->KontaktModel->addOrder('kontakttyp, kontakt, tbl_kontakt.updateamum, tbl_kontakt.insertamum')) - ){ - $kontakte_res = $this->KontaktModel->loadWhere(array('person_id' => getAuthPersonID())); - if(isError($kontakte_res)){ - // handle error - }else{ - $kontakte_res = hasData($kontakte_res)? getData($kontakte_res) : null; - } - - } - - $zutrittskarte_ausgegebenam = $this->BetriebsmittelpersonModel->getBetriebsmittelByUid(getAuthUID(),"Zutrittskarte"); - if(isError($zutrittskarte_ausgegebenam)){ - // error handling - }else{ - $zutrittskarte_ausgegebenam = hasData($zutrittskarte_ausgegebenam)? getData($zutrittskarte_ausgegebenam)[0]->ausgegebenam : null; - //? formats the date from 01-01-2000 to 01.01.2000 - $zutrittskarte_ausgegebenam = str_replace("-",".",$zutrittskarte_ausgegebenam); + $benutzer_info_sql_columns = ["foto","foto_sperre","anrede","titelpost","titelpre","vorname","nachname"]; + //? der Geburtsort und das Geburtsdatum darf auch nur der eigene User sehen + if (!$view){ + array_push($benutzer_info_sql_columns, "gebort", "gebdatum"); } + if(isSuccess($this->BenutzerModel->addSelect($benutzer_info_sql_columns)) + && isSuccess($this->BenutzerModel->addJoin("tbl_person", "person_id"))){ - if( - isSuccess($adresse_res = $this->AdresseModel->addSelect(array("strasse","tbl_adressentyp.bezeichnung as adr_typ","plz","ort")))&& - isSuccess($adresse_res = $this->AdresseModel->addOrder("zustelladresse","DESC"))&& - isSuccess($adresse_res = $this->AdresseModel->addOrder("sort"))&& - isSuccess($adresse_res = $this->AdresseModel->addJoin("tbl_adressentyp","typ=adressentyp_kurzbz")) - ){ - $adresse_res = $this->AdresseModel->loadWhere(array("person_id"=>getAuthPersonID())); - if(isError($adresse_res)){ - // error handling - }else{ - $adresse_res = hasData($adresse_res)? getData($adresse_res) : null; - } - } - - if(isSuccess($this->PersonModel->addSelect(["foto","foto_sperre","anrede","titelpost","titelpre","vorname","nachname", "gebort", "gebdatum"]))){ - - $person_res = $this->PersonModel->load(getAuthPersonId()); + $person_res = $this->BenutzerModel->load([$uid]); if(isError($person_res)){ // error handling }else{ @@ -242,27 +307,27 @@ class Profil extends Auth_Controller - $res = new stdClass(); + $res->foto = $person_res->foto; $res->foto_sperre = $person_res->foto_sperre; - $res->username = getAuthUID(); + $res->username = $uid; $res->anrede = $person_res->anrede; $res->titel = $person_res->titelpre ." " . $person_res->titelpost; $res->vorname = $person_res->vorname; $res->nachname = $person_res->nachname; + if(!$view){ $res->gebort = $person_res->gebort; $res->gebdatum = $person_res->gebdatum; - $res->adressen = $adresse_res; - $res->zutrittsdatum = $zutrittskarte_ausgegebenam; + } //$res->postnomen = $person_res->postnomen; //! still not found $intern_email = array(); $intern_email+=array("type" => "intern"); - $intern_email+=array("email"=> getAuthUID() . "@" . DOMAIN); + $intern_email+=array("email"=> $uid . "@" . DOMAIN); $res->emails = array($intern_email); - $res->kontakte = $kontakte_res; - $res->mittel = $betriebsmittelperson_res; + + $res->mailverteiler = $mailverteiler_res; @@ -271,6 +336,10 @@ class Profil extends Auth_Controller } + + + //! old function that was used to fetch all the data + // todo delete the function at the end public function getMitarbeiterAnsicht(){ diff --git a/application/views/Cis/Profil.php b/application/views/Cis/Profil.php index 931d879d5..83d9e6008 100644 --- a/application/views/Cis/Profil.php +++ b/application/views/Cis/Profil.php @@ -14,8 +14,8 @@ $this->load->view('templates/CISHTML-Header', $includesArray);
FH-Ausweis Status
{{"Der FH Ausweis ist am "+ wert+ " ausgegeben worden."}}