Merge branch 'feature-25999/C4' into feature-40309/Cis_News_widget

This commit is contained in:
SimonGschnell
2024-07-24 14:40:15 +02:00
26 changed files with 1833 additions and 458 deletions
+14 -14
View File
@@ -244,23 +244,23 @@ class Profil extends Auth_Controller
$this->GemeindeModel->addDistinct();
$this->GemeindeModel->addSelect(["name"]);
if ($nation == "A") {
if (isset($zip) && $zip > 999 && $zip < 32000) {
if (isset($zip) && $zip > 999 && $zip < 32000) {
$gemeinde_res = $this->GemeindeModel->loadWhere(['plz' => $zip]);
if (isError($gemeinde_res)) {
show_error("error while trying to query bis.tbl_gemeinde");
$gemeinde_res = $this->GemeindeModel->loadWhere(['plz' => $zip]);
if (isError($gemeinde_res)) {
show_error("error while trying to query bis.tbl_gemeinde");
}
$gemeinde_res = hasData($gemeinde_res) ? getData($gemeinde_res) : null;
$gemeinde_res = array_map(function ($obj) {
return $obj->name;
}, $gemeinde_res);
echo json_encode($gemeinde_res);
} else {
echo json_encode(error("ortschaftskennziffer code was not valid"));
}
$gemeinde_res = hasData($gemeinde_res) ? getData($gemeinde_res) : null;
$gemeinde_res = array_map(function ($obj) {
return $obj->name;
}, $gemeinde_res);
echo json_encode($gemeinde_res);
} else {
echo json_encode(error("ortschaftskennziffer code was not valid"));
}
} else {
echo json_encode(error("Nation was not 'A' (Austria)"));
echo json_encode(error("Nation was not 'A' (Austria)"));
}
}
@@ -525,8 +525,6 @@ class ProfilUpdate extends Auth_Controller
public function acceptProfilRequest()
{
$_POST = json_decode($this->input->raw_input_stream, true);
$id = $this->input->post('profil_update_id', true);
$uid = $this->input->post('uid', true);
@@ -0,0 +1,690 @@
<?php
/**
* Copyright (C) 2024 fhcomplete.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end)
* Provides data to the ajax get calls about the searchbar component
* This controller works with JSON calls on the HTTP GET and the output is always JSON
*/
class Profil extends FHCAPI_Controller
{
/**
* Object initialization
*/
public function __construct()
{
parent::__construct([
'getView' => self::PERM_LOGGED,
'fotoSperre' => self::PERM_LOGGED,
'getGemeinden' => self::PERM_LOGGED,
'getAllNationen' => self::PERM_LOGGED,
'isMitarbeiter' => self::PERM_LOGGED,
]);
$this->load->model('ressource/mitarbeiter_model', 'MitarbeiterModel');
$this->load->model('crm/Student_model', 'StudentModel');
$this->load->model('person/Benutzer_model', 'BenutzerModel');
$this->load->model('person/Person_model', 'PersonModel');
$this->load->model('person/Adresse_model', 'AdresseModel');
$this->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel');
$this->load->model('person/Benutzergruppe_model', 'BenutzergruppeModel');
$this->load->model('ressource/Betriebsmittelperson_model', 'BetriebsmittelpersonModel');
$this->load->model('person/Kontakt_model', 'KontaktModel');
$this->load->model('person/Profil_update_model', 'ProfilUpdateModel');
$this->load->model('content/DmsVersion_model', 'DmsVersionModel');
//? put the uid and pid inside the controller for reusability
$this->uid = getAuthUID();
$this->pid = getAuthPersonID();
}
//------------------------------------------------------------------------------------------------------------------
// Public methods
/**
* function that returns the data used for the corresponding view
* the client side parses the @param $uid and calls this function to get the data to the correct view
* @access public
* @param boolean $uid the userID used to identify which information should be retrieved for which view
* @return stdClass all the data corresponding to a view of a user
*/
public function getView($uid)
{
$res = new stdClass();
// if parsing the URL did not found a UID then the UID of the logged in user is used
if ($uid == "Profil" || $uid == $this->uid) {
$isMitarbeiter = $this->MitarbeiterModel->isMitarbeiter($this->uid);
if (isError($isMitarbeiter)) {
show_error("error while checking if UID: " . $this->uid . " is a mitarbeiter");
}
$isMitarbeiter = getData($isMitarbeiter);
if ($isMitarbeiter) {
$res->view = "MitarbeiterProfil";
$res->data = $this->mitarbeiterProfil();
$res->data->pid = $this->pid;
} else {
$res->view = "StudentProfil";
$res->data = $this->studentProfil();
$res->data->pid = $this->pid;
}
}
// UID is availabe when accessing Profil/View/:uid
else {
$this->PersonModel->addSelect(["person_id"]);
$pid = $this->PersonModel->getByUid($uid);
if (isError($pid)) {
show_error("error while trying to update table public.tbl_person while searching for a person with UID: " . $uid);
}
$pid = hasData($pid) ? getData($pid)[0] : null;
if (!$pid) {
show_error("Person with UID: " . $uid . " does not exist");
}
$isMitarbeiter = $this->MitarbeiterModel->isMitarbeiter($uid);
if (isError($isMitarbeiter)) {
show_error("error while checking if UID: " . $uid . " is a mitarbeiter");
}
$isMitarbeiter = getData($isMitarbeiter);
if ($isMitarbeiter) {
$res->view = "ViewMitarbeiterProfil";
$res->data = $this->viewMitarbeiterProfil($uid);
} else {
$res->view = "ViewStudentProfil";
$res->data = $this->viewStudentProfil($uid);
}
}
$this->terminateWithSuccess($res);
}
/**
* update column foto_sperre in public.tbl_person
* @access public
* @param boolean $value new value for the column
* @return boolean the new value added to the column in public.tbl_person
*/
public function fotoSperre($value)
{
if(!isset($value)){
$this->terminateWithError("Missing parameter", self::ERROR_TYPE_GENERAL);
}
$res = $this->PersonModel->update($this->pid, ["foto_sperre" => $value]);
if (isError($res)) {
show_error("error while trying to update table public.tbl_person");
}
$this->PersonModel->addSelect("foto_sperre");
$res = $this->PersonModel->load($this->pid);
if (isError($res)) {
show_error("error while trying to query table public.tbl_person");
}
$res = $this->getDataOrTerminateWithError($res);
$this->terminateWithSuccess(current($res));
}
/**
* gets all nations in the table bis.tbl_nation
*
* @access public
* @return array all the nations in table bis.tbl_nation
*/
public function getAllNationen()
{
// load the nationen from the database
$this->load->model('codex/Nation_model', "NationModel");
$this->NationModel->addSelect(["nation_code as code", "langtext"]);
$nation_res = $this->NationModel->load();
if (isError($nation_res)) {
$this->terminateWithError("error while trying to query table codex.tbl_nation", self::ERROR_TYPE_GENERAL);
}
$nation_res = $this->getDataOrTerminateWithError($nation_res);
$this->terminateWithSuccess($nation_res);
}
public function getGemeinden($nation, $zip)
{
if(!isset($nation) || !isset($zip)){
echo json_encode(error("Missing parameters"));
return;
}
$this->load->model('codex/Gemeinde_model', "GemeindeModel");
$gemeinde_res = $this->GemeindeModel->getGemeindeByPlz($zip);
if (isError($gemeinde_res)) {
$this->terminateWithError(getError($gemeinde_res),self::ERROR_TYPE_GENERAL);
}
$gemeinde_res = $this->getDataOrTerminateWithError($gemeinde_res);
/* $gemeinde_res = array_map(function ($obj) {
return $obj->ortschaftsname;
}, $gemeinde_res); */
$this->terminateWithSuccess($gemeinde_res);
}
// -----------------------------------------------------------------------------------------------------------------
// Private methods
/**
* function that returns the data used for viewing another mitarbeiter profile
* @access private
* @param integer $uid the userID to retrieve the mitarbeiter data
* @return stdClass restricted mitarbeiter data
*/
private function viewMitarbeiterProfil($uid)
{
$mailverteiler_res = $this->getMailverteiler($uid);
$benutzer_funktion_res = $this->getBenutzerFunktion($uid);
$benutzer_res = $this->getBenutzerAlias($uid);
$person_res = $this->getPersonInfo($uid);
$mitarbeiter_res = $this->getMitarbeiterInfo($uid);
$telefon_res = $this->getTelefonInfo($uid);
$res = new stdClass();
$res->username = $uid;
//? Person Info
foreach ($person_res as $key => $val) {
$res->$key = $val;
}
//? Mitarbeiter Info
foreach ($mitarbeiter_res as $key => $val) {
$res->$key = $val;
}
$intern_email = array();
$intern_email["type"] = "intern";
$intern_email["email"] = $uid . "@" . DOMAIN;
$extern_email = array();
$extern_email["type"] = "alias";
$extern_email["email"] = $benutzer_res->alias . "@" . DOMAIN;
$res->emails = array($intern_email, $extern_email);
$res->funktionen = $benutzer_funktion_res;
$res->mailverteiler = $mailverteiler_res;
$res->standort_telefon = isset($telefon_res) ? $telefon_res->kontakt : null;
return $res;
}
/**
* function that returns the data used for viewing another student profile
* @access private
* @param integer $uid the userID to retrieve the student data
* @return stdClass restricted student data
*/
private function viewStudentProfil($uid)
{
$mailverteiler_res = $this->getMailverteiler($uid);
$person_res = $this->getPersonInfo($uid);
$student_res = $this->getStudentInfo($uid);
$matr_res = $this->getMatrikelNummer($uid);
$res = new stdClass();
$res->username = $uid;
//? Person Information
foreach ($person_res as $key => $value) {
$res->$key = $value;
}
//? Student Information
foreach ($student_res as $key => $value) {
$res->$key = $value;
}
$intern_email = array();
$intern_email["type"] = "intern";
$intern_email["email"] = $uid . "@" . DOMAIN;
$res->emails = [$intern_email];
$res->matrikelnummer = $matr_res->matr_nr;
$res->mailverteiler = $mailverteiler_res;
return $res;
}
/**
* checks whether a specific userID is a mitarbeiter or not (foreword declaration of the function isMitarbeiter in Mitarbeiter_model.php)
* @access public
* @param $uid the userID used to check if it is a mitarbeiter
* @return boolean
*/
public function isMitarbeiter($uid)
{
if(!$uid) $this->terminateWithError("No uid provided", self::ERROR_TYPE_GENERAL);
$result = $this->MitarbeiterModel->isMitarbeiter($uid);
if (isError($result)) {
$this->terminateWithError("error when calling Mitarbeiter_model function isMitarbeiter with uid " . $uid, self::ERROR_TYPE_GENERAL);
}
$result = $this->getDataOrTerminateWithError($result);
$this->terminateWithSuccess($result);
}
/**
* function that returns the data used for the mitarbeiter profile
* @access private
* @return stdClass mitarbeiter data
*/
private function mitarbeiterProfil()
{
$zutrittskarte_ausgegebenam = $this->getZutrittskarteDatum($this->uid);
$adresse_res = $this->getAdressenInfo($this->pid);
$kontakte_res = $this->getKontaktInfo($this->pid);
$mailverteiler_res = $this->getMailverteiler($this->uid);
$person_res = $this->getPersonInfo($this->uid, true);
$benutzer_funktion_res = $this->getBenutzerFunktion($this->uid);
$betriebsmittelperson_res = $this->getBetriebsmittelInfo($this->pid);
$profilUpdates = $this->getProfilUpdates($this->uid);
$telefon_res = $this->getTelefonInfo($this->uid);
$mitarbeiter_res = $this->getMitarbeiterInfo($this->uid);
$res = new stdClass();
$res->username = $this->uid;
//? Person Information
foreach ($person_res as $key => $value) {
$res->$key = $value;
}
//? Mitarbeiter Information
foreach ($mitarbeiter_res as $key => $value) {
$res->$key = $value;
}
$res->adressen = $adresse_res;
$res->zutrittsdatum = $zutrittskarte_ausgegebenam;
$res->kontakte = $kontakte_res;
$res->mittel = $betriebsmittelperson_res;
$res->mailverteiler = $mailverteiler_res;
$intern_email = array();
$intern_email["type"] = "intern";
$intern_email["email"] = $this->uid . "@" . DOMAIN;
$extern_email = array();
$extern_email["type"] = "alias";
$extern_email["email"] = $mitarbeiter_res->alias . "@" . DOMAIN;
$res->emails = [$intern_email, $extern_email];
$res->funktionen = $benutzer_funktion_res;
$res->standort_telefon = $telefon_res;
$res->profilUpdates = $profilUpdates;
return $res;
}
/**
* function that returns the data used for the student profile
* @access private
* @return stdClass student data
*/
private function studentProfil()
{
$betriebsmittelperson_res = $this->getBetriebsmittelInfo($this->pid);
$kontakte_res = $this->getKontaktInfo($this->pid);
$zutrittskarte_ausgegebenam = $this->getZutrittskarteDatum($this->uid);
$adresse_res = $this->getAdressenInfo($this->pid);
$mailverteiler_res = $this->getMailverteiler($this->uid);
$person_res = $this->getPersonInfo($this->uid, true);
$zutrittsgruppe_res = $this->getZutrittsgruppen($this->uid);
$student_res = $this->getStudentInfo($this->uid);
$matr_res = $this->getMatrikelNummer($this->uid);
$profilUpdates = $this->getProfilUpdates($this->uid);
$res = new stdClass();
$res->username = $this->uid;
//? Person Information
foreach ($person_res as $key => $value) {
$res->$key = $value;
}
//? Student Information
foreach ($student_res as $key => $value) {
$res->$key = trim($value);
}
$intern_email = array();
$intern_email["type"] = "intern";
$intern_email["email"] = $this->uid . "@" . DOMAIN;
$res->emails = [$intern_email];
$res->adressen = $adresse_res;
$res->zutrittsdatum = $zutrittskarte_ausgegebenam;
$res->kontakte = $kontakte_res;
$res->mittel = $betriebsmittelperson_res;
$res->matrikelnummer = $matr_res->matr_nr;
$res->zuttritsgruppen = $zutrittsgruppe_res;
$res->mailverteiler = $mailverteiler_res;
$res->profilUpdates = $profilUpdates;
return $res;
}
/**
* gets all the mailverteiler using the tables: tbl_benutzer, tbl_benutzergruppe, tbl_gruppe
* @access private
* @param integer $uid the userID used to retrieve the mailverteiler
* @return array returns the mailvertailer corresponding to a userID
*/
private function getMailverteiler($uid)
{
$this->PersonModel->addSelect('gruppe_kurzbz, beschreibung');
$this->PersonModel->addJoin('tbl_benutzer', 'person_id');
$this->PersonModel->addJoin('tbl_benutzergruppe', 'uid');
$this->PersonModel->addJoin('tbl_gruppe', 'gruppe_kurzbz');
$mailverteiler_res = $this->PersonModel->loadWhere(array('mailgrp' => true, 'uid' => $uid));
if (isError($mailverteiler_res)) {
show_error("was not able to query the table public.tbl_benutzer:" . getData($mailverteiler_res));
}
$mailverteiler_res = hasData($mailverteiler_res) ? getData($mailverteiler_res) : null;
$mailverteiler_res = array_map(function ($element) {
$element->mailto = "mailto:" . $element->gruppe_kurzbz . "@" . DOMAIN;
return $element;
}, $mailverteiler_res);
return $mailverteiler_res;
}
/**
* gets all the Benutzerfunktionen of a corresponding user
* @access private
* @param integer $uid the userID used to retrieve the Benutzerfunktionen
* @return array returns the Benutzerfunktionen corresponding to a userID
*/
private function getBenutzerFunktion($uid)
{
$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"]);
$this->BenutzerfunktionModel->addJoin("tbl_organisationseinheit", "oe_kurzbz");
$benutzer_funktion_res = $this->BenutzerfunktionModel->loadWhere(array('uid' => $uid));
if (isError($benutzer_funktion_res)) {
show_error("was not able to query the table public.tbl_benutzerfunktion:" . getData($benutzer_funktion_res));
}
$benutzer_funktion_res = hasData($benutzer_funktion_res) ? getData($benutzer_funktion_res) : null;
return $benutzer_funktion_res;
}
/**
* gets all the Betriebsmittel of a corresponding user
* @access private
* @param integer $uid the userID used to retrieve the Betriebsmittel
* @return array returns the Betriebsmittel corresponding to a userID
*/
private function getBetriebsmittelInfo($pid)
{
$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($pid);
if (isError($betriebsmittelperson_res)) {
show_error("was not able to query the table public.tbl_betriebsmittelperson:" . getData($betriebsmittelperson_res));
}
$betriebsmittelperson_res = hasData($betriebsmittelperson_res) ? getData($betriebsmittelperson_res) : null;
return $betriebsmittelperson_res;
}
/**
* gets the alias of a corresponding user
* @access private
* @param integer $uid the userID used to get the alias
* @return string the alias of the userID
*/
private function getBenutzerAlias($uid)
{
$this->BenutzerModel->addSelect(["alias"]);
$benutzer_res = $this->BenutzerModel->load([$uid]);
if (isError($benutzer_res)) {
show_error("was not able to query the table public.tbl_benutzer:" . getData($benutzer_res));
} else {
$benutzer_res = hasData($benutzer_res) ? getData($benutzer_res)[0] : null;
}
return $benutzer_res;
}
/**
* gets the person information corresponding to a user
* @access private
* @param integer $uid the userID used to get the person information
* @param integer $geburtsInfo flag wether to add the columns gebort, gebdatum, foto_sperre or not
* @return array all the person informaion corresponding to a userID
*/
private function getPersonInfo($uid, $geburtsInfo = null)
{
$selectClause = ["foto", "anrede", "titelpost as postnomen", "titelpre as titel", "vorname", "nachname"];
/** @param integer $geburtsInfo */
if ($geburtsInfo) {
array_push($selectClause, "gebort");
array_push($selectClause, "gebdatum");
array_push($selectClause, "foto_sperre");
}
$this->BenutzerModel->addSelect($selectClause);
$this->BenutzerModel->addJoin("tbl_person", "person_id");
$person_res = $this->BenutzerModel->load([$uid]);
if (isError($person_res)) {
show_error("was not able to query the table public.tbl_benutzer:" . getData($person_res));
} else {
$person_res = hasData($person_res) ? getData($person_res)[0] : null;
}
return $person_res;
}
/**
* gets the mitarbeiter information corresponding to a user
* @access private
* @param integer $uid the userID used to get the mitarbeiter information
* @return array all the mitarbeiter informaion corresponding to a userID
*/
private function getMitarbeiterInfo($uid)
{
$this->MitarbeiterModel->addSelect(["kurzbz", "telefonklappe", "alias", "ort_kurzbz"]);
$this->MitarbeiterModel->addJoin("tbl_benutzer", "tbl_benutzer.uid = tbl_mitarbeiter.mitarbeiter_uid");
$mitarbeiter_res = $this->MitarbeiterModel->load($uid);
if (isError($mitarbeiter_res)) {
show_error("was not able to query the table public.tbl_mitarbeiter:" . getData($mitarbeiter_res));
} else {
$mitarbeiter_res = hasData($mitarbeiter_res) ? getData($mitarbeiter_res)[0] : null;
}
return $mitarbeiter_res;
}
/**
* gets the telefon information corresponding to a user
* @access private
* @param integer $uid the userID used to get the telefon information
* @return array all the telefon informaion corresponding to a userID
*/
private function getTelefonInfo($uid)
{
$this->MitarbeiterModel->addSelect(["kontakt"]);
$this->MitarbeiterModel->addJoin("tbl_kontakt", "tbl_mitarbeiter.standort_id = tbl_kontakt.standort_id");
$this->MitarbeiterModel->addLimit(1);
$telefon_res = $this->MitarbeiterModel->loadWhere(["mitarbeiter_uid" => $uid, "kontakttyp" => "telefon"]);
if (isError($telefon_res)) {
show_error("was not able to query the table public.tbl_mitarbeiter:" . getData($telefon_res));
}
$telefon_res = hasData($telefon_res) ? getData($telefon_res)[0] : null;
return $telefon_res;
}
/**
* gets the student information corresponding to a user
* @access private
* @param integer $uid the userID used to get the student information
* @return array all the student informaion corresponding to a userID
*/
private function getStudentInfo($uid)
{
$this->StudentModel->addSelect(['tbl_studiengang.bezeichnung as studiengang', 'tbl_student.semester', 'tbl_student.verband', 'tbl_student.gruppe', 'tbl_student.matrikelnr as personenkennzeichen']);
$this->StudentModel->addJoin('tbl_studiengang', "tbl_studiengang.studiengang_kz=tbl_student.studiengang_kz");
$student_res = $this->StudentModel->load([$uid]);
if (isError($student_res)) {
show_error("was not able to query the table public.tbl_student:" . getData($student_res));
}
$student_res = hasData($student_res) ? getData($student_res)[0] : null;
return $student_res;
}
/**
* gets the profil updates corresponding to a user
* @access private
* @param integer $uid the userID used to get the profil updates
* @return array all the profil updates corresponding to a userID
*/
private function getProfilUpdates($uid)
{
$profilUpdates = $this->ProfilUpdateModel->getProfilUpdatesWhere(['uid' => $uid]);
if (isError($profilUpdates)) {
show_error("was not able to query the table public.tbl_profil_update:" . getData($profilUpdates));
}
$profilUpdates = hasData($profilUpdates) ? getData($profilUpdates) : null;
return $profilUpdates;
}
/**
* gets the Matrikelnummer corresponding to a user
* @access private
* @param integer $uid the userID used to get the Matrikelnummer
* @return integer the Matrikelnummer corresponding to a userID
*/
private function getMatrikelNummer($uid)
{
$this->BenutzerModel->addSelect(["matr_nr"]);
$this->BenutzerModel->addJoin("tbl_person", "person_id");
$matr_res = $this->BenutzerModel->load([$uid]);
if (isError($matr_res)) {
show_error("was not able to query the table public.tbl_benutzer:" . getData($matr_res));
}
$matr_res = hasData($matr_res) ? getData($matr_res)[0] : [];
return $matr_res;
}
/**
* gets the Zutrittsgruppen corresponding to a user
* @access private
* @param integer $uid the userID used to get the Zutrittsgruppen
* @return array all the Zutrittsgruppen corresponding to a userID
*/
private function getZutrittsgruppen($uid)
{
$this->BenutzergruppeModel->addSelect(['bezeichnung']);
$this->BenutzergruppeModel->addJoin('tbl_gruppe', 'gruppe_kurzbz');
$zutrittsgruppe_res = $this->BenutzergruppeModel->loadWhere(array("uid" => $uid, "zutrittssystem" => true));
if (isError($zutrittsgruppe_res)) {
show_error("was not able to query the table public.tbl_benutzergruppe:" . getData($zutrittsgruppe_res));
}
$zutrittsgruppe_res = hasData($zutrittsgruppe_res) ? getData($zutrittsgruppe_res) : null;
return $zutrittsgruppe_res;
}
/**
* gets the address information corresponding to a user
* @access private
* @param integer $uid the userID used to get the address information
* @return array all the address information corresponding to a userID
*/
private function getAdressenInfo($pid)
{
$adresse_res = $this->AdresseModel->addSelect(["adresse_id", "strasse", "tbl_adressentyp.bezeichnung as typ", "plz", "ort", "zustelladresse", "gemeinde", "nation"]);
$adresse_res = $this->AdresseModel->addOrder("zustelladresse", "DESC");
$adresse_res = $this->AdresseModel->addJoin("tbl_adressentyp", "typ=adressentyp_kurzbz");
$adresse_res = $this->AdresseModel->loadWhere(["person_id" => $pid]);
if (isError($adresse_res)) {
show_error("was not able to query the table public.tbl_adresse:" . getData($adresse_res));
}
$adresse_res = hasData($adresse_res) ? getData($adresse_res) : null;
return $adresse_res;
}
/**
* gets the kontakt information corresponding to a user
* @access private
* @param integer $uid the userID used to get the kontakt information
* @return array all the kontakt information corresponding to a userID
*/
private function getKontaktInfo($pid)
{
$this->KontaktModel->addSelect(['kontakttyp', 'kontakt_id', 'kontakt', 'tbl_kontakt.anmerkung', 'tbl_kontakt.zustellung']);
$this->KontaktModel->addJoin('public.tbl_standort', 'standort_id', 'LEFT');
$this->KontaktModel->addJoin('public.tbl_firma', 'firma_id', 'LEFT');
$this->KontaktModel->addOrder('kontakttyp, kontakt, tbl_kontakt.updateamum, tbl_kontakt.insertamum');
$kontakte_res = $this->KontaktModel->loadWhere(['person_id' => $pid]);
if (isError($kontakte_res)) {
show_error("was not able to query the table public.tbl_kontakt:" . getData($kontakte_res));
}
$kontakte_res = hasData($kontakte_res) ? getData($kontakte_res) : null;
return $kontakte_res;
}
/**
* gets the date of issue of the FH access card corresponding to a user
* @access private
* @param integer $uid the userID used to get the date of issue of the FH access card
* @return string the date of issue of the FH access card corresponding to a userID
*/
private function getZutrittskarteDatum($uid)
{
$zutrittskarte_ausgegebenam = $this->BetriebsmittelpersonModel->getBetriebsmittelByUid($uid, "Zutrittskarte");
if (isError($zutrittskarte_ausgegebenam)) {
show_error("was not able to query the table wavi.tbl_bentriebsmittelperson:" . getData($zutrittskarte_ausgegebenam));
}
$zutrittskarte_ausgegebenam = hasData($zutrittskarte_ausgegebenam) ? getData($zutrittskarte_ausgegebenam)[0]->ausgegebenam : null;
//? formats date from 01-01-2000 to 01.01.2000
$zutrittskarte_ausgegebenam = str_replace("-", ".", $zutrittskarte_ausgegebenam);
return $zutrittskarte_ausgegebenam;
}
}
@@ -0,0 +1,704 @@
<?php
/**
* Copyright (C) 2024 fhcomplete.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end)
* Provides data to the ajax get calls about the searchbar component
* This controller works with JSON calls on the HTTP GET and the output is always JSON
*/
class ProfilUpdate extends FHCAPI_Controller
{
public static $STATUS_PENDING = NULL;
public static $STATUS_ACCEPTED = NULL;
public static $STATUS_REJECTED = NULL;
public static $TOPICS = [];
/**
* Object initialization
*/
public function __construct()
{
parent::__construct([
'getStatus' => self::PERM_LOGGED,
'getTopic' => self::PERM_LOGGED,
'getProfilRequestFiles' => self::PERM_LOGGED,
'denyProfilRequest' => ['student/stammdaten:rw', 'mitarbeiter/stammdaten:rw'],
'acceptProfilRequest' => ['student/stammdaten:rw', 'mitarbeiter/stammdaten:rw'],
'selectProfilRequest' => self::PERM_LOGGED,
'insertProfilRequest' => self::PERM_LOGGED,
'updateProfilRequest' => self::PERM_LOGGED,
'deleteProfilRequest' => self::PERM_LOGGED,
'insertFile' => self::PERM_LOGGED,
]);
// Load language phrases
$this->loadPhrases(
array(
'ui',
'global',
'person',
'profil',
'profilUpdate'
)
);
$this->load->model('person/Profil_update_model', 'ProfilUpdateModel');
$this->load->model('person/Kontakt_model', 'KontaktModel');
$this->load->model('person/Adresse_model', 'AdresseModel');
$this->load->model('person/Adressentyp_model', 'AdressenTypModel');
$this->load->model('person/Person_model', 'PersonModel');
$this->load->model('ressource/mitarbeiter_model', 'MitarbeiterModel');
$this->load->model('crm/Student_model', 'StudentModel');
$this->load->model('person/Benutzer_model', 'BenutzerModel');
$this->load->model('system/Sprache_model', 'SpracheModel');
$this->load->model('person/Profil_update_status_model', 'ProfilUpdateStatusModel');
$this->load->model('person/Profil_update_topic_model', 'ProfilUpdateTopicModel');
$this->load->library('DmsLib');
$this->load->library('PermissionLib');
//? put the uid and pid inside the controller for reusability
$this->uid = getAuthUID();
$this->pid = getAuthPersonID();
// setup the ProfilUpdate states
$this->ProfilUpdateStatusModel->addSelect(['status_kurzbz']);
$status_kurzbz = $this->ProfilUpdateStatusModel->load();
if (hasData($status_kurzbz)) {
list($status_pending, $status_accepted, $status_rejected) = getData($status_kurzbz);
self::$STATUS_PENDING = $status_pending->status_kurzbz;
self::$STATUS_ACCEPTED = $status_accepted->status_kurzbz;
self::$STATUS_REJECTED = $status_rejected->status_kurzbz;
}
// setup the ProfilUpdate topics
$this->ProfilUpdateTopicModel->addSelect(['topic_kurzbz']);
$topic_kurzbz = $this->ProfilUpdateTopicModel->load();
if (hasData($topic_kurzbz)) {
foreach (getData($topic_kurzbz) as $topic) {
self::$TOPICS[$topic->topic_kurzbz] = $topic->topic_kurzbz;
}
}
}
//------------------------------------------------------------------------------------------------------------------
// Public methods
public function getStatus()
{
$this->terminateWithSuccess([self::$STATUS_PENDING => self::$STATUS_PENDING, self::$STATUS_ACCEPTED => self::$STATUS_ACCEPTED, self::$STATUS_REJECTED => self::$STATUS_REJECTED]);
}
public function getTopic()
{
if(!count(self::$TOPICS)){
$this->terminateWithError('No topics found');
}
$this->terminateWithSuccess(self::$TOPICS);
}
public function selectProfilRequest()
{
$uid = $this->input->get('uid',true);
$id = $this->input->get('id',true);
$whereClause = ['uid' => $this->uid];
if (isset($uid))
$whereClause['uid'] = $uid;
if (isset($id))
$whereClause['id'] = $id;
$res = $this->ProfilUpdateModel->getProfilUpdatesWhere($whereClause);
$res = $this->getDataOrTerminateWithError($res);
$this->terminateWithSuccess($res);
}
public function insertProfilRequest()
{
$payload = $this->input->post('payload',true);
$topic = $this->input->post('topic',true);
$fileID = $this->input->post('fileID',true);
if(!isset($payload) || !isset($topic)){
$this->terminateWithError("required parameters are missing");
}
$identifier = array_key_exists("kontakt_id", $payload) ? "kontakt_id" : (array_key_exists("adresse_id", $payload) ? "adresse_id" : null);
$data = ["topic" => $topic, "uid" => $this->uid, "requested_change" => json_encode($payload), "insertamum" => "NOW()", "insertvon" => $this->uid, "status" => self::$STATUS_PENDING ?: 'Pending'];
//? insert fileID in the dataset if sent with post request
if (isset($fileID)) {
$data['attachment_id'] = $fileID;
}
//? loops over all updateRequests from a user to validate if the new request is valid
$res = $this->ProfilUpdateModel->getProfilUpdatesWhere(["uid" => $this->uid]);
if (isError($res)) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_loading_error'));
}
$res = $this->getDataOrTerminateWithError($res);
//? the user cannot delete a zustelladresse/kontakt
if (isset($payload->delete) && $payload->{$identifier == "kontakt_id" ? "zustellung" : "zustelladresse"}) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_deleteZustellung_error'));
}
//? if the user tries to delete a adresse, checks whether the adresse is a heimatadresse, if so an error is raised
if (isset($payload->delete) && $identifier == "adresse_id") {
$adr = $this->AdresseModel->load($payload->$identifier);
$adr = $this->getDataOrTerminateWithError($adr)[0];
if ($adr->heimatadresse) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_deleteZustellung_error'));
}
}
if ($res) {
$pending_changes = array_filter($res, function ($element) {
return $element->status == (self::$STATUS_PENDING ?: "Pending");
});
foreach ($pending_changes as $update_request) {
$existing_change = $update_request->requested_change;
//? the user can add as many new kontakte/adressen as he likes
if (!isset($payload->add) && property_exists($existing_change, $identifier) && property_exists($payload, $identifier) && $existing_change->$identifier == $payload->$identifier) {
//? the kontakt_id / adresse_id of a change has to be unique
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_changeTwice_error'));
}
//? if it is not updating any kontakt/adresse, the topic has to be unique
elseif (!$identifier && $update_request->topic == $topic) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_changeTopicTwice_error', ['0' => $update_request->topic]));
}
}
}
$insertID = $this->ProfilUpdateModel->insert($data);
if (isError($insertID)) {
$this->terminateWithError(getError($insertID));
} else {
$insertID = hasData($insertID) ? getData($insertID) : null;
//? sends emails to the correspondents of the $uid
$this->sendEmail_onProfilUpdate_insertion($this->uid, $insertID, $topic);
$this->terminateWithSuccess(success($insertID));
}
}
public function updateProfilRequest()
{
$topic = $this->input->post('topic', true);
$payload = $this->input->post('payload', true);
$ID = $this->input->post('ID', true);
$fileID = $this->input->post('fileID', true);//optional
if(!isset($topic) || !isset($payload) || !isset($ID)){
$this->terminateWithError("required parameters are missing");
}
$updateData = ["requested_change" => json_encode($payload), "updateamum" => "NOW()", "updatevon" => $this->uid];
if (isset($fileID)) {
$updateData['attachment_id'] = json_decode($fileID);
}
$updateID = $this->ProfilUpdateModel->update([$ID], $updateData);
//? insert fileID in the dataset if sent with post request
if (isError($updateID)) {
$this->terminateWithError(getError($updateID));
}
$updateID = $this->getDataOrTerminateWithError($updateID)[0];
$this->terminateWithSuccess(success($updateID));
}
public function deleteProfilRequest()
{
$requestID = $this->input->post('requestID', true);
$result = $this->ProfilUpdateModel->delete([$requestID]);
if (isError($result)) {
$this->terminateWithError(getError($result));
}
$this->terminateWithSuccess($result);
}
public function getProfilRequestFiles($id)
{
if(!$id){
$this->terminateWithError("parameter id is missing");
}
$this->ProfilUpdateModel->addSelect(["attachment_id"]);
$attachmentID = $this->ProfilUpdateModel->load([$id]);
if (isError($attachmentID)) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_loading_error'),self::ERROR_TYPE_GENERAL);
}
//? get the attachmentID
$dms_id = $this->getDataOrTerminateWithError($attachmentID)[0]->attachment_id;
//? get the name to the file
$this->DmsVersionModel->addSelect(["name", "dms_id"]);
$attachment = $this->DmsVersionModel->load([$dms_id, 0]);
if (isError($attachment)) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_dmsVersion_error'),self::ERROR_TYPE_GENERAL);
}
$attachment = $this->getDataOrTerminateWithError($attachment);
//? returns {name:..., dms_id:...}
$this->terminateWithSuccess($attachment);
}
public function denyProfilRequest()
{
$id = $this->input->post('profil_update_id', true);
$uid = $this->input->post('uid', true);
$topic = $this->input->post('topic', true);
$status_message = $this->input->post('status_message', true); //optional
if(!isset($id) || !isset($uid) || !isset($topic)){
$this->terminateWithError("parameter id, uid, topic or status_message is missing");
}
$is_mitarbeiter = $this->MitarbeiterModel->isMitarbeiter($uid);
$is_mitarbeiter = $this->getDataOrTerminateWithError($is_mitarbeiter);
$is_student = $this->StudentModel->isStudent($uid);
$is_student = $this->getDataOrTerminateWithError($is_student);
if (
$is_student && $this->permissionlib->isBerechtigt('student/stammdaten', "suid", $this->getOE_from_student($uid)) ||
$is_mitarbeiter && $this->permissionlib->isBerechtigt('mitarbeiter/stammdaten', "suid")
) {
$this->sendEmail_onProfilUpdate_response($uid, $topic, self::$STATUS_REJECTED);
$this->terminateWithSuccess($this->setStatusOnUpdateRequest($id, self::$STATUS_REJECTED, $status_message));
} else {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_permission_error'),self::ERROR_TYPE_GENERAL);
}
}
public function acceptProfilRequest()
{
$id = $this->input->post('profil_update_id', true);
$uid = $this->input->post('uid', true);
$topic = $this->input->post('topic', true);
$requested_change = $this->input->post('requested_change');
$status_message = $this->input->post('status_message', true); //optional
//? fetching person_id using UID
$personID = $this->PersonModel->getByUid($uid);
$personID = $this->getDataOrTerminateWithError($personID)[0]->person_id;
//! check for required information
if (!isset($id) || !isset($uid) || !isset($personID) || !isset($requested_change) || !isset($topic)) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_requiredInformation_error'));
}
$is_mitarbeiter = $this->MitarbeiterModel->isMitarbeiter($uid);
$is_mitarbeiter = $this->getDataOrTerminateWithError($is_mitarbeiter);
$is_student = $this->StudentModel->isStudent($uid);
$is_student = $this->getDataOrTerminateWithError($is_student);
//? check if the permissions are set correctly
if (
$is_student && $this->permissionlib->isBerechtigt('student/stammdaten', "suid", $this->getOE_from_student($uid)) ||
$is_mitarbeiter && $this->permissionlib->isBerechtigt('mitarbeiter/stammdaten', "suid")
) {
if (is_array($requested_change) && array_key_exists("adresse_id", $requested_change)) {
$insertID = $this->handleAdresse($requested_change, $personID);
$insertID = getData($insertID);
if (isset($insertID)) {
$requested_change['adresse_id'] = $insertID;
$update_res = $this->updateRequestedChange($id, $requested_change);
if (isError($update_res)) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_address_error', [$insertID]));
}
}
} else if (is_array($requested_change) && array_key_exists("kontakt_id", $requested_change)) {
$insertID = $this->handleKontakt($requested_change, $personID);
$insertID = getData($insertID);
if (isset($insertID)) {
$requested_change['kontakt_id'] = $insertID;
$update_res = $this->updateRequestedChange($id, $requested_change);
if (isError($update_res)) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_kontakt_error', [$insertID]));
}
}
} else {
switch ($topic) {
// mapping phrasen to database columns to make the update with the correct column names
case self::$TOPICS['Titel']:
$topic = "titelpre";
break;
case self::$TOPICS['Postnomen']:
$topic = "titelpost";
break;
case self::$TOPICS['Vorname']:
$topic = "vorname";
break;
case self::$TOPICS['Nachname']:
$topic = "nachname";
break;
default:
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_topic_error', [$topic]));
}
$result = $this->PersonModel->update($personID, [$topic => $requested_change["value"]]);
if (isError($result)) $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_insert_error'));
}
$this->sendEmail_onProfilUpdate_response($uid, $topic, self::$STATUS_ACCEPTED);
$this->terminateWithSuccess($this->setStatusOnUpdateRequest($id, self::$STATUS_ACCEPTED, $status_message, $requested_change));
} else {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_permission_error'));
}
}
public function insertFile($replace)
{
$replace = json_decode($replace);
if (!count($_FILES)) {
$this->terminateWithError("No file available for upload");
}
//? if replace is set it contains the profil_update_id in which the attachment_id has to be replaced
if (isset($replace)) {
$this->ProfilUpdateModel->addSelect(["attachment_id"]);
$profilUpdate = $this->ProfilUpdateModel->load([$replace]);
if (isError($profilUpdate)) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_loading_error'));
}
//? get the attachmentID
$dms_id = $this->getDataOrTerminateWithError($profilUpdate)[0]->attachment_id;
//? delete old dms_file of Profil Update
$deleteOldFile_result = $this->deleteOldVersionFile($dms_id);
if(!$deleteOldFile_result){
$this->terminateWithError("error while deleting the old file");
}
}
$files = $_FILES['files'];
$file_count = count($files['name']);
$res = [];
for ($i = 0; $i < $file_count; $i++) {
$_FILES['files']['name'] = $files['name'][$i];
$_FILES['files']['type'] = $files['type'][$i];
$_FILES['files']['tmp_name'] = $files['tmp_name'][$i];
$_FILES['files']['error'] = $files['error'][$i];
$_FILES['files']['size'] = $files['size'][$i];
$dms = [
"kategorie_kurzbz" => "profil_aenderung",
"version" => 0,
"name" => $_FILES['files']['name'],
"mimetype" => $_FILES['files']['type'],
"beschreibung" => $this->uid . " Profil Änderung",
"insertvon" => $this->uid,
"insertamum" => "NOW()",
];
$tmp_res = $this->dmslib->upload($dms, 'files', array("jpg", "png", "pdf"));
if(isError($tmp_res)){
$this->addError(getError($tmp_res));
}
$tmp_res = $this->getDataOrTerminateWithError($tmp_res);
array_push($res, $tmp_res);
}
$this->terminateWithSuccess($res);
}
//------------------------------------------------------------------------------------------------------------------
// Private methods
private function sendEmail_onProfilUpdate_insertion($uid, $profil_update_id, $topic)
{
$this->load->helper('hlp_sancho_helper');
$emails = [];
$is_mitarbeiter = $this->MitarbeiterModel->isMitarbeiter($uid);
if (isError($is_mitarbeiter)) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_mitarbeiterCheck_error'));
}
$is_mitarbeiter = $this->getDataOrTerminateWithError($is_mitarbeiter);
//! if the $uid is a mitarbeiter and student, only the hr is notified by email
if ($is_mitarbeiter) {
//? user is not a student therefore he is a mitarbeiter, send email to Personalverwaltung
//? use constant variable MAIL_GST to mail to the personalverwaltung
$this->MitarbeiterModel->addSelect([TRUE]);
$this->MitarbeiterModel->addJoin("public.tbl_benutzer", "public.tbl_benutzer.uid = public.tbl_mitarbeiter.mitarbeiter_uid");
//? check if the the userID is a mitarbeiter and if the benutzer is active
$res = $this->MitarbeiterModel->loadWhere(["public.tbl_mitarbeiter.mitarbeiter_uid" => $uid, "public.tbl_benutzer.aktiv" => TRUE]);
if (isError($res)) {
$this->terminateWithError("was not able to query the mitarbeiter and benutzer by the uid: " . $uid);
}
if (hasData($res)) {
array_push($emails, MAIL_GST);
} else {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_mitarbeiterCheck_error'));
}
} else {
//? if it is not a mitarbeiter, check whether it is a student and send email to studiengang
$is_student = $this->StudentModel->isStudent($uid);
if (isError($is_student)) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_studentCheck_error'));
}
$is_student = $this->getDataOrTerminateWithError($is_student);
if ($is_student) {
//? Send email to the Studiengangsassistentinnen
$this->StudentModel->addSelect(["public.tbl_studiengang.email"]);
$this->StudentModel->addJoin("public.tbl_benutzer", "public.tbl_benutzer.uid = public.tbl_student.student_uid");
$this->StudentModel->addJoin("public.tbl_prestudent", "public.tbl_benutzer.person_id = public.tbl_prestudent.person_id");
$this->StudentModel->addJoin("public.tbl_prestudentstatus", "public.tbl_prestudentstatus.prestudent_id = public.tbl_prestudent.prestudent_id");
$this->StudentModel->addJoin("public.tbl_studiengang", "public.tbl_studiengang.studiengang_kz = public.tbl_prestudent.studiengang_kz");
//* check if the benutzer itself is active
//* check if the student status is Student or Diplomand (active students)
$this->StudentModel->db->where_in("public.tbl_prestudentstatus.status_kurzbz", ['Student', 'Diplomand']);
$res = $this->StudentModel->loadWhere(["public.tbl_benutzer.aktiv" => TRUE, "public.tbl_student.student_uid" => $uid]);
if (isError($res)) {
$this->terminateWithError(getError($res));
} else {
$res = $this->getDataOrTerminateWithError($res);
foreach ($res as $emailObj) {
array_push($emails, $emailObj->email);
}
}
}
}
$mail_res = [];
//? sending email
foreach ($emails as $email) {
array_push($mail_res, sendSanchoMail("profil_update", ['uid' => $uid, 'topic' => $topic, 'href' => APP_ROOT . 'Cis/ProfilUpdate/id/' . $profil_update_id], $email, ("Profil Änderung von " . $uid)));
}
foreach ($mail_res as $m_res) {
if (!$m_res) {
$this->addError($this->p->t('profilUpdate', 'profilUpdate_email_error'));
}
}
}
private function sendEmail_onProfilUpdate_response($uid, $topic, $status)
{
$this->load->helper('hlp_sancho_helper');
$email = $uid . "@" . DOMAIN;
function languageQuery($language)
{
return "select index from public.tbl_sprache where sprache = '" + $language + "'";
}
$this->ProfilUpdateStatusModel->addSelect(["bezeichnung_mehrsprachig[(" . languageQuery('German') . ")] as status_de", "bezeichnung_mehrsprachig[(" . languageQuery('English') . ")] as status_en"]);
$status_translation = $this->ProfilUpdateStatusModel->loadWhere(["status_kurzbz" => $status]);
if (isError($status_translation)) {
$this->terminateWithError($this->p->t('profilUpdate', 'ProfilUpdateStatusTranslationError'));
}
$status_translation = hasData($status_translation) ? getData($status_translation)[0] : null;
if (isset($status_translation)) {
$mail_res = sendSanchoMail("profil_update_response", ['topic' => $topic, 'status_de' => $status_translation->status_de, 'status_en' => $status_translation->status_en, 'href' => APP_ROOT . 'Cis/Profil'], $email, ("Profil Änderung " . $this->p->t('profilUpdate', 'pending')));
if (!$mail_res) {
$this->addError($this->p->t('profilUpdate', 'profilUpdate_email_error'));
}
}
}
private function setStatusOnUpdateRequest($id, $status, $status_message)
{
return $this->ProfilUpdateModel->update([$id], ["status" => $status, "status_timestamp" => "NOW()", "status_message" => $status_message]);
}
private function updateRequestedChange($id, $requested_change)
{
return $this->ProfilUpdateModel->update([$id], ['requested_change' => json_encode($requested_change)]);
}
private function handleAdresse($requested_change, $personID)
{
$this->AdressenTypModel->addSelect(["adressentyp_kurzbz"]);
$adr_kurzbz = $this->AdressenTypModel->loadWhere(["bezeichnung" => $requested_change['typ']]);
$adr_kurzbz = $this->getDataOrTerminateWithError($adr_kurzbz)[0]->adressentyp_kurzbz;
//? replace the address_typ with its correct kurzbz foreign key
$requested_change['typ'] = $adr_kurzbz;
$adresse_id = $requested_change["adresse_id"];
//? removes the adresse_id because we don't want to update the kontakt_id in the database
unset($requested_change["adresse_id"]);
//! ADD
if (array_key_exists('add', $requested_change) && $requested_change['add']) {
//? removes add flag
unset($requested_change['add']);
$requested_change['insertamum'] = "NOW()";
$requested_change['insertvon'] = getAuthUID();
$requested_change['person_id'] = $personID;
//TODO: zustelladresse, heimatadresse, rechnungsadresse und nation werden nicht beachtet
$insertID = $this->AdresseModel->insert($requested_change);
$insert_adresse_id = $insertID;
if (isError($insert_adresse_id)) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_insertAdresse_error'));
}
$insert_adresse_id = $this->getDataOrTerminateWithError($insert_adresse_id);
if ($insert_adresse_id) {
$this->handleDupplicateZustellAdressen($requested_change['zustelladresse'], $insert_adresse_id);
}
}
//! DELETE
elseif (array_key_exists('delete', $requested_change) && $requested_change['delete']) {
$result = $this->AdresseModel->delete($adresse_id);
if(isError($result)){
$this->terminateWithError(getError($result));
}
}
//! UPDATE
else {
$requested_change['updateamum'] = "NOW()";
$requested_change['updatevon'] = getAuthUID();
$update_adresse_id = $this->AdresseModel->update($adresse_id, $requested_change);
if (isError($update_adresse_id)) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_updateAdresse_error'));
}
$update_adresse_id = $this->getDataOrTerminateWithError($update_adresse_id);
$this->handleDupplicateZustellAdressen($requested_change['zustelladresse'], $update_adresse_id);
}
return $insertID ?? null;
}
private function handleDupplicateZustellAdressen($zustellung, $adresse_id)
{
if ($zustellung) {
$this->PersonModel->addSelect("public.tbl_adresse.adresse_id");
$this->PersonModel->addJoin("public.tbl_adresse", "public.tbl_adresse.person_id = public.tbl_person.person_id");
$zustellAdressenArray = $this->PersonModel->loadWhere(["public.tbl_person.person_id" => $this->pid, "zustelladresse" => TRUE]);
if (isError($zustellAdressenArray)) {
$this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_loadingZustellAdressen_error'));
}
$zustellAdressenArray = $this->getDataOrTerminateWithError($zustellAdressenArray);
if (count($zustellAdressenArray) > 0) {
$zustellAdressenArray = array_filter($zustellAdressenArray, function ($adresse) use ($adresse_id) {
return $adresse->adresse_id != $adresse_id;
});
// remove the zustelladresse from all other zustelladressen
foreach ($zustellAdressenArray as $adresse) {
$this->AdresseModel->update($adresse->adresse_id, ["zustelladresse" => FALSE]);
}
}
}
}
private function deleteOldVersionFile($dms_id)
{
// starting the transaction
$this->db->trans_start();
if (!isset($dms_id)) {
return;
}
//? delete the file from the profilUpdate first
$profilUpdateFileDelete = $this->ProfilUpdateModel->removeFileFromProfilUpdate($dms_id);
if(isError($profilUpdateFileDelete)){
$this->terminateWithError(getError($profilUpdateFileDelete));
}
//? delete all the different versions of the dms_file
$dmsVersions = $this->DmsVersionModel->loadWhere(["dms_id" => $dms_id]);
$dmsVersions = $this->getDataOrTerminateWithError($dmsVersions);
$dms_versions = array_map(function ($item) {
return $item->version;
}, $dmsVersions);
$test_array = array();
foreach ($dms_versions as $version) {
$delete_result = $this->dmslib->removeVersion($dms_id, $version);
array_push($test_array, $delete_result);
if(isError($delete_result)){
$this->addError(getError($delete_result));
}
}
// transaction complete
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE)
{
return false;
}
else
{
return true;
}
}
}
@@ -19,4 +19,28 @@ class Gemeinde_model extends DB_Model
return $this->loadWhere(array("plz" => $plz));
}
public function getGemeindeByNation($nation, $zip){
$this->addSelect(["name"]);
if ($nation == "A") {
if (isset($zip) && $zip > 999 && $zip < 32000) {
$gemeinde_res = $this->GemeindeModel->loadWhere(['plz' => $zip]);
if (isError($gemeinde_res)) {
show_error("error while trying to query bis.tbl_gemeinde");
}
$gemeinde_res = hasData($gemeinde_res) ? getData($gemeinde_res) : null;
$gemeinde_res = array_map(function ($obj) {
return $obj->name;
}, $gemeinde_res);
echo json_encode($gemeinde_res);
} else {
echo json_encode(error("ortschaftskennziffer code was not valid"));
}
} else {}
}
}
@@ -77,6 +77,21 @@ class Profil_update_model extends DB_Model
}
//? remove File from the Profil Update
public function removeFileFromProfilUpdate($dms_id)
{
if(!is_int($dms_id) || $dms_id < 0){
return error("not valid dms_id");
}
return $this->execReadOnlyQuery("
UPDATE public.tbl_profil_update
SET attachment_id = NULL
WHERE attachment_id = ?", [$dms_id]);
}
/**
* getProfilUpdateWithPermission
+5 -3
View File
@@ -12,9 +12,10 @@ $this->load->view('templates/CISHTML-Header', $includesArray);
<div class="fhc-header">
<h1><?= $this->p->t('tools', 'dokumente'); ?><small><?= $this->p->t('tools', 'bestaetigungenZeugnisse'); ?></small></h1>
</div>
<div class="row">
<div class="col<?= $selfservice ? '-8' : ''; ?>">
<div class="order-2 col-lg-8">
<div class="fhc-table mb-3">
<div class="fhc-table-header d-flex align-items-center mb-2 gap-2">
<h3 class="h5 col m-0"><?= $this->p->t('tools', 'inskriptionsbestaetigung'); ?><?= $studienbuchblatt ? ' & ' . $this->p->t('tools', 'studienbuchblatt') : ''; ?></h3>
@@ -199,12 +200,13 @@ $this->load->view('templates/CISHTML-Header', $includesArray);
<?php } ?>
</div>
<?php if ($selfservice) { ?>
<div class="col-4">
<div class="order-1 order-lg-3 col-lg-4">
<div class="alert alert-warning" role="alert">
<?= $this->p->t('tools', 'warnungDruckDigitaleSignatur'); ?>
</div>
</div>
<?php } ?>
</div>
</div>
+4
View File
@@ -20,6 +20,8 @@ import phrasen from "./phrasen.js";
import navigation from "./navigation.js";
import filter from "./filter.js";
import studstatus from "./studstatus.js";
import profil from "./profil.js";
import profilUpdate from "./profilUpdate.js";
import ort from "./ort.js";
import cms from "./cms.js";
@@ -29,6 +31,8 @@ export default {
navigation,
filter,
studstatus,
profil,
profilUpdate,
ort,
cms,
};
+73
View File
@@ -0,0 +1,73 @@
export default {
getView: function (uid) {
return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/Profil/getView/${uid}`,{}
);
},
fotoSperre: function (value) {
return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/Profil/fotoSperre/${value}`,
{}
);
},
isStudent: function (uid) {
return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/Profil/isStudent`,
{
uid:uid,
}
);
},
isMitarbeiter: function (uid) {
return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/Profil/isMitarbeiter/${uid}`,
{}
);
},
getZustellAdresse: function () {
return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/Profil/getZustellAdresse`,{}
);
},
getZustellKontakt: function () {
return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/Profil/getZustellKontakt`,{}
);
},
getGemeinden: function(nation,zip){
return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/Profil/getGemeinden/${nation}/${zip}`,
{}
);
},
getAllNationen:function(){
return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
"/api/frontend/v1/Profil/getAllNationen",{}
);
},
}
+99
View File
@@ -0,0 +1,99 @@
export default {
//! API calls for profil update requests
getStatus: function () {
return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/ProfilUpdate/getStatus`,{});
},
getTopic: function () {
return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/ProfilUpdate/getTopic`,{});
},
acceptProfilRequest: function ({profil_update_id, uid, status_message, topic, requested_change}) {
return this.$fhcApi.post(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
"/api/frontend/v1/ProfilUpdate/acceptProfilRequest",{profil_update_id, uid, status_message, topic, requested_change});
},
denyProfilRequest: function ({profil_update_id, uid, topic, status_message}) {
return this.$fhcApi.post(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
"/api/frontend/v1/ProfilUpdate/denyProfilRequest",{profil_update_id,uid,topic,status_message});
},
insertFile: function (dms, replace = null) {
return this.$fhcApi.post(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/ProfilUpdate/insertFile/${replace}`,
dms);
},
getProfilRequestFiles: function (requestID) {
return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/ProfilUpdate/getProfilRequestFiles/${requestID}`,{});
},
selectProfilRequest: function (uid = null, id = null) {
return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/ProfilUpdate/selectProfilRequest`,
{...(uid?{uid}:{}),
...(id?{id}:{})
});
},
insertProfilRequest: function (topic, payload, fileID = null) {
return this.$fhcApi.post(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
"/api/frontend/v1/ProfilUpdate/insertProfilRequest",
{
topic,
payload,
...(fileID ? { fileID } : {}),
});
},
updateProfilRequest: function (topic, payload, ID, fileID = null) {
return this.$fhcApi.post(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/ProfilUpdate/updateProfilRequest`,
{
topic,
payload,
ID,
...(fileID ? { fileID: fileID } : {}),
});
},
deleteProfilRequest: function (requestID) {
return this.$fhcApi.post(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/ProfilUpdate/deleteProfilRequest`,
{
requestID,
});
},
};
+9 -9
View File
@@ -2,11 +2,10 @@ import StudentProfil from "../../components/Cis/Profil/StudentProfil.js";
import MitarbeiterProfil from "../../components/Cis/Profil/MitarbeiterProfil.js";
import ViewStudentProfil from "../../components/Cis/Profil/StudentViewProfil.js";
import ViewMitarbeiterProfil from "../../components/Cis/Profil/MitarbeiterViewProfil.js";
import fhcapifactory from "../api/fhcapifactory.js";
import Loading from "../../components/Loader.js";
import Phrasen from "../../plugin/Phrasen.js";
Vue.$fhcapi = fhcapifactory;
Vue.$collapseFormatter = function (data) {
//data - an array of objects containing the column title and value for each cell
var container = document.createElement("div");
@@ -317,16 +316,16 @@ const profilApp = Vue.createApp({
?.filter((item) => {
return !this.data.profilUpdates?.some((update) => {
return (
update.status === "pending" &&
update.status === this.profilUpdateStates["Pending"] &&
update.requested_change?.adresse_id == item.adresse_id
);
});
})
.map((kontakt) => {
.map((adresse) => {
return {
listview: "Adresse",
view: "EditAdresse",
data: kontakt,
data: adresse,
};
}),
},
@@ -352,9 +351,10 @@ const profilApp = Vue.createApp({
},
},
created() {
async created() {
// fetch profilUpdateStates to provide them to children components
Vue.$fhcapi.ProfilUpdate.getStatus()
await this.$fhcApi.factory.profilUpdate.getStatus()
.then((response) => {
this.profilUpdateStates = response.data;
})
@@ -362,7 +362,7 @@ const profilApp = Vue.createApp({
console.error(error);
});
Vue.$fhcapi.ProfilUpdate.getTopic()
this.$fhcApi.factory.profilUpdate.getTopic()
.then((response) => {
this.profilUpdateTopic = response.data;
})
@@ -373,7 +373,7 @@ const profilApp = Vue.createApp({
//? uid contains the last part of the uri
let uid = location.pathname.split("/").pop();
Vue.$fhcapi.UserData.getView(uid).then((res) => {
this.$fhcApi.factory.profil.getView(uid).then((res) => {
if (!res.data) {
this.notFoundUID = uid;
} else {
+1 -3
View File
@@ -1,7 +1,5 @@
import fhcapifactory from "../api/fhcapifactory.js";
import ProfilUpdateView from "../../components/Cis/ProfilUpdate/ProfilUpdateView.js";
import Phrasen from "../../plugin/Phrasen.js";
Vue.$fhcapi = fhcapifactory;
const app = Vue.createApp({
components: {
@@ -22,7 +20,7 @@ const app = Vue.createApp({
},
methods: {},
created() {
Vue.$fhcapi.ProfilUpdate.getStatus()
this.$fhcApi.factory.profilUpdate.getStatus()
.then((response) => {
this.profilUpdateStates = response.data;
})
-4
View File
@@ -1,11 +1,7 @@
import Search from "./search.js";
import Cms from "./cms.js";
import UserData from "./userdata.js";
import ProfilUpdate from "./profilUpdate.js"
export default {
"Search": Search,
"UserData": UserData,
"ProfilUpdate": ProfilUpdate,
"Cms": Cms,
};
-120
View File
@@ -1,120 +0,0 @@
export default {
//! API calls for profil update requests
getStatus: function () {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
"/Cis/ProfilUpdate/getStatus";
return axios.get(url);
},
getTopic: function () {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
"/Cis/ProfilUpdate/getTopic";
return axios.get(url);
},
getProfilUpdateRequest: function () {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
"/Cis/ProfilUpdate/getAllRequests";
return axios.get(url);
},
acceptProfilRequest: function (payload) {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
"/Cis/ProfilUpdate/acceptProfilRequest";
return axios.post(url, payload);
},
denyProfilRequest: function (payload) {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
"/Cis/ProfilUpdate/denyProfilRequest";
return axios.post(url, payload);
},
replaceProfilUpdateAttachment: function (dms) {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/Cis/ProfilUpdate/replaceProfilUpdateAttachment`;
return axios.post(url, dms, {
headers: { "Content-Type": "multipart/form-data" },
});
},
//? new reuquests
insertFile: function (dms, replace = null) {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/Cis/ProfilUpdate/insertFile/${replace}`;
return axios.post(url, dms, {
headers: { "Content-Type": "multipart/form-data" },
});
},
getProfilRequestFiles: function (requestID) {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/Cis/ProfilUpdate/getProfilRequestFiles`;
return axios.post(url, requestID);
},
selectProfilRequest: function (uid = null, id = null) {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/Cis/ProfilUpdate/selectProfilRequest`;
return axios.get(url, { uid: uid, id: id });
},
insertProfilRequest: function (topic, payload, fileID = null) {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/Cis/ProfilUpdate/insertProfilRequest`;
return axios.post(url, {
topic,
payload,
...(fileID ? { fileID: fileID } : {}),
});
},
updateProfilRequest: function (topic, payload, ID, fileID = null) {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/Cis/ProfilUpdate/updateProfilRequest`;
return axios.post(url, {
topic,
payload,
ID,
...(fileID ? { fileID: fileID } : {}),
});
},
deleteProfilRequest: function (requestID) {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/Cis/ProfilUpdate/deleteProfilRequest`;
return axios.post(url, requestID);
},
};
-58
View File
@@ -1,58 +0,0 @@
export default {
//! API Calls for Profil Views
getGemeinden: function(nation,zip=null){
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
`cis.php/Cis/Profil/getGemeinden`;
return axios.get(url,{params:{nation:nation,zip:zip}});
},
getAllNationen:function(){
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
`cis.php/Cis/Profil/getAllNationen`;
return axios.get(url);
},
getView: function (uid) {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root + `cis.php/Cis/Profil/getView/${uid}`;
return axios.get(url);
},
sperre_foto_function: function (value) {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
`cis.php/Cis/Profil/foto_sperre_function/${value}`;
return axios.get(url);
},
isStudent: function (uid) {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
`cis.php/Cis/Profil/isStudent/${uid}`;
return axios.get(url);
},
isMitarbeiter: function (uid) {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
`cis.php/Cis/Profil/isMitarbeiter/${uid}`;
return axios.get(url);
},
getZustellAdresse: function () {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
`cis.php/Cis/Profil/getZustellAdresse`;
return axios.get(url);
},
getZustellKontakt: function () {
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
`cis.php/Cis/Profil/getZustellKontakt`;
return axios.get(url);
},
};
@@ -83,7 +83,7 @@ export default {
this.setLoading(true);
this.editData.updateID
? Vue.$fhcapi.ProfilUpdate.updateProfilRequest(
? this.$fhcApi.factory.profilUpdate.updateProfilRequest(
this.topic,
this.profilUpdate,
this.editData.updateID,
@@ -95,7 +95,7 @@ export default {
.catch((err) => {
console.error(err);
})
: Vue.$fhcapi.ProfilUpdate.insertProfilRequest(
: this.$fhcApi.factory.profilUpdate.insertProfilRequest(
this.topic,
this.profilUpdate,
this.fileID ? this.fileID[0] : null
@@ -116,14 +116,14 @@ export default {
const result = this.editData.updateID
? //? updating old attachment by replacing
//* second parameter of api request insertFile checks if the file has to be replaced or not
await Vue.$fhcapi.ProfilUpdate.insertFile(
await this.$fhcApi.factory.profilUpdate.insertFile(
formData,
this.editData.updateID
).then((res) => {
return res.data?.map((file) => file.dms_id);
})
: //? fresh insert of new attachment
await Vue.$fhcapi.ProfilUpdate.insertFile(formData).then((res) => {
await this.$fhcApi.factory.profilUpdate.insertFile(formData).then((res) => {
return res.data?.map((file) => file.dms_id);
});
return result;
@@ -151,17 +151,17 @@ export default {
hideEditProfilModal: function () {
//? checks the editModal component property result, if the user made a successful request or not
if (this.$refs.editModal.result) {
Vue.$fhcapi.ProfilUpdate.selectProfilRequest()
this.$fhcApi.factory.profilUpdate.selectProfilRequest()
.then((request) => {
if (!request.error) {
if (!request.error && request) {
this.data.profilUpdates = request.data;
this.data.profilUpdates.sort(this.sortProfilUpdates);
} else {
console.log("Error when fetching profile updates: " + res.data);
console.error("Error when fetching profile updates: " + res.data);
}
})
.catch((err) => {
console.log(err);
console.error(err);
});
} else {
// when modal was closed without submitting request
@@ -184,8 +184,8 @@ export default {
},
fetchProfilUpdates: function () {
Vue.$fhcapi.ProfilUpdate.selectProfilRequest().then((res) => {
if (!res.error) {
this.$fhcApi.factory.profilUpdate.selectProfilRequest().then((res) => {
if (!res.error && res) {
this.data.profilUpdates = res.data?.length
? res.data.sort(this.sortProfilUpdates)
: null;
@@ -238,6 +238,7 @@ export default {
created() {
//? sorts the profil Updates: pending -> accepted -> rejected
this.data.profilUpdates?.sort(this.sortProfilUpdates);
},
template: /*html*/ `
@@ -450,8 +451,6 @@ export default {
<div v-if="data.profilUpdates" class="row d-none d-md-block mb-3">
<div class="col mb-3">
<!-- PROFIL UPDATES -->
<fetch-profil-updates v-if="data.profilUpdates && data.profilUpdates.length" @fetchUpdates="fetchProfilUpdates" :data="data.profilUpdates"></fetch-profil-updates>
@@ -37,21 +37,23 @@ export default {
},
async showEditProfilModal(updateRequest) {
let view = this.getView(updateRequest.topic, updateRequest.status);
let view = this.getView(updateRequest.topic, updateRequest.status);
let data = null;
let content = null;
let files = null;
let withFiles = false;
if (view === "TextInputDokument") {
console.log("text input")
data = {
titel: updateRequest.topic,
value: updateRequest.requested_change.value,
};
const filesFromDatabase =
await Vue.$fhcapi.ProfilUpdate.getProfilRequestFiles(
await this.$fhcApi.factory.profilUpdate.getProfilRequestFiles(
updateRequest.profil_update_id
).then((res) => {
return res.data;
@@ -74,11 +76,9 @@ export default {
files: files,
};
//?TODO: check if updateRequest.uid is a mitarbeiter, if so add the flag isMitarbeiter:true
if (view === "EditAdresse") {
const isMitarbeiter = await Vue.$fhcapi.UserData.isMitarbeiter(
updateRequest.uid
).then((res) => res.data);
const isMitarbeiter = await this.$fhcApi.factory.profil.isMitarbeiter(updateRequest.uid).then((res)=>res.data);
if (isMitarbeiter) {
content["isMitarbeiter"] = isMitarbeiter;
@@ -107,17 +107,18 @@ export default {
},
deleteRequest: function (item) {
Vue.$fhcapi.ProfilUpdate.deleteProfilRequest(item.profil_update_id).then(
this.$fhcApi.factory.profilUpdate.deleteProfilRequest(item.profil_update_id).then(
(res) => {
if (res.data.error) {
//? open alert
console.log(res.data);
console.error("error happened",res.data);
} else {
this.$emit("fetchUpdates");
}
}
);
},
getView: function (topic, status) {
if (!(status === this.profilUpdateStates["Pending"])) {
return "Status";
@@ -141,84 +142,9 @@ export default {
}
},
// OLD way to open the editProfil modal, which was dynamically added to the html and then removed
async openModal(updateRequest) {
let view = this.getView(updateRequest.topic, updateRequest.status);
let data = null;
let content = null;
let files = null;
let withFiles = false;
if (view === "TextInputDokument") {
data = {
titel: updateRequest.topic,
value: updateRequest.requested_change.value,
};
const filesFromDatabase =
await Vue.$fhcapi.ProfilUpdate.getProfilRequestFiles(
updateRequest.profil_update_id
).then((res) => {
return res.data;
});
files = filesFromDatabase;
if (files) {
withFiles = true;
}
} else {
data = updateRequest.requested_change;
}
content = {
updateID: updateRequest.profil_update_id,
view: view,
data: data,
withFiles: withFiles,
topic: updateRequest.topic,
files: files,
};
//?TODO: check if updateRequest.uid is a mitarbeiter, if so add the flag isMitarbeiter:true
if (view === "EditAdresse") {
const isMitarbeiter = await Vue.$fhcapi.UserData.isMitarbeiter(
updateRequest.uid
).then((res) => res.data);
if (isMitarbeiter) {
content["isMitarbeiter"] = isMitarbeiter;
}
}
//? adds the status information if the profil update request was rejected or accepted
if (updateRequest.status !== this.profilUpdateStates["Pending"]) {
content["status"] = updateRequest.status;
content["status_message"] = updateRequest.status_message;
content["status_timestamp"] = updateRequest.status_timestamp;
}
//? only show the popup if also the right content is available
if (content) {
EditProfil.popup({
value: content,
title: updateRequest.topic,
zustellkontakteCount: this.getZustellkontakteCount,
zustelladressenCount: this.getZustelladressenCount,
})
.then((res) => {
if (res === true) {
this.$emit("fetchUpdates");
}
})
.catch((e) => {
// Wenn der User das Modal abbricht ohne Änderungen
});
}
},
},
created() {},
created() {
},
computed: {},
@@ -20,11 +20,9 @@ export default {
if (!this.data) {
return;
}
Vue.$fhcapi.UserData.sperre_foto_function(!this.FotoSperre).then(
(res) => {
this.FotoSperre = res.data.foto_sperre;
}
);
this.$fhcApi.factory.profil.fotoSperre(!this.FotoSperre).then(res =>{
this.FotoSperre = res.data.foto_sperre;
})
},
},
computed: {
@@ -55,6 +55,10 @@ export default {
},
async submitProfilChange() {
//todo delete this debugging line
console.log("this is a test")
//? check if data is valid before making a request
if (this.topic && this.profilUpdate) {
//? if profil update contains any attachment
@@ -71,18 +75,18 @@ export default {
this.loading = false;
this.setLoading(false);
if (res.data.error == 0) {
this.result = true;
this.hide();
Alert.popup(
"Ihre Anfrage wurde erfolgreich gesendet. Bitte warten Sie, während sich das Team um Ihre Anfrage kümmert."
);
} else {
if (res.data.error) {
this.result = false;
this.hide();
Alert.popup(
"Ein Fehler ist aufgetreten: " + JSON.stringify(res.data.retval)
);
} else {
this.result = true;
this.hide();
Alert.popup(
"Ihre Anfrage wurde erfolgreich gesendet. Bitte warten Sie, während sich das Team um Ihre Anfrage kümmert."
);
}
};
@@ -92,7 +96,7 @@ export default {
this.setLoading(true);
this.editData.updateID
? Vue.$fhcapi.ProfilUpdate.updateProfilRequest(
? this.$fhcApi.factory.profilUpdate.updateProfilRequest(
this.topic,
this.profilUpdate,
this.editData.updateID,
@@ -104,7 +108,7 @@ export default {
.catch((err) => {
console.error(err);
})
: Vue.$fhcapi.ProfilUpdate.insertProfilRequest(
: this.$fhcApi.factory.profilUpdate.insertProfilRequest(
this.topic,
this.profilUpdate,
this.fileID ? this.fileID[0] : null
@@ -125,14 +129,14 @@ export default {
const result = this.editData.updateID
? //? updating old attachment by replacing
//* second parameter of api request insertFile checks if the file has to be replaced or not
await Vue.$fhcapi.ProfilUpdate.insertFile(
await this.$fhcApi.factory.profilUpdate.insertFile(
formData,
this.editData.updateID
).then((res) => {
return res.data?.map((file) => file.dms_id);
})
: //? fresh insert of new attachment
await Vue.$fhcapi.ProfilUpdate.insertFile(formData).then((res) => {
await this.$fhcApi.factory.profilUpdate.insertFile(formData).then((res) => {
return res.data?.map((file) => file.dms_id);
});
return result;
@@ -16,6 +16,7 @@ export default {
data() {
return {
gemeinden: [],
ortschaftnamen: [],
selectedNation: null,
nationenList: [],
originalValue: null,
@@ -27,13 +28,25 @@ export default {
"data.gemeinde": function (newValue, oldValue) {
this.$emit("profilUpdate", this.isChanged ? this.data : null);
},
"data.ort": function (newValue, oldValue) {
this.$emit("profilUpdate", this.isChanged ? this.data : null);
},
},
methods: {
autocompleteSearch: function (event) {
test: function () {
console.log(this.gemeinden, "this are the gemeinden");
console.log(this.ortschaftnamen, "this are the ortschaftsnamen");
},
autocompleteSearchGemeinden: function (event) {
this.gemeinden = this.gemeinden.map((gemeinde) => gemeinde);
},
autocompleteSearchOrtschaftsnamen: function (event) {
this.ortschaftnamen = this.ortschaftnamen.map((ortschaft) => ortschaft);
},
getGemeinde: function () {
//? only query the gemeinde is the nation is Austria and the PLZ is greater than 999 and less than 32000
if (
@@ -43,13 +56,26 @@ export default {
this.data.plz > 999 &&
this.data.plz < 32000
) {
Vue.$fhcapi.UserData.getGemeinden(this.data.nation, this.data.plz).then(
(res) => {
this.$fhcApi.factory.profil
.getGemeinden(this.data.nation, this.data.plz)
.then((res) => {
if (res.data.length) {
this.gemeinden = res.data;
this.gemeinden = [
...new Set(
res.data.map((element) => {
return element.name;
})
),
];
this.ortschaftnamen = [
...new Set(
res.data.map((element) => {
return element.ortschaftsname;
})
),
];
}
}
);
});
} else {
this.gemeinden = [];
}
@@ -86,118 +112,106 @@ export default {
) {
return false;
}
return this.originalValue !== JSON.stringify(this.data);
},
},
created() {
Vue.$fhcapi.UserData.getAllNationen().then((res) => {
// get all available nationen
this.$fhcApi.factory.profil.getAllNationen().then((res)=>{
this.nationenList = res.data;
this.getGemeinde();
});
})
this.originalValue = JSON.stringify(this.data);
this.zustellAdressenCount = this.getZustelladressenCount();
},
template: /*html*/ `
<div class="gy-3 row justify-content-center align-items-center">
<!-- warning message for too many zustellungs Adressen -->
<div v-if="showZustellAdressenWarning" class="col-12 ">
<div class="card bg-danger mx-2">
<div class="card-body text-white ">
<span>{{$p.t('profilUpdate','zustelladresseWarning')}}</span>
</div>
</div>
</div>
<!-- End of warning -->
<div class="gy-3 row justify-content-center align-items-center">
<div class="col-12 ">
<div class="form-check mb-2">
<input class="form-check-input" type="checkbox" @change="updateValue($event,'zustelladresse')" :checked="data.zustelladresse" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
{{$p.t('person','zustelladresse')}}
</label>
</div>
</div>
<div class="col-12 col-sm-9 col-xl-12 col-xxl-9 order-1">
<div class="form-underline ">
<div class="form-underline-titel">{{$p.t('person','strasse')}}*</div>
<input class="form-control" :value="data.strasse" @input="updateValue($event,'strasse')" :placeholder="data.strasse">
</div>
</div>
<div class=" order-2 order-sm-4 order-xl-3 order-xxl-4 col-12 col-sm-5 col-xl-8 col-xxl-5 ">
<div class="form-underline">
<div class="form-underline-titel">{{$p.t('profilUpdate','kontaktTyp')}}*</div>
<select :value="data.typ" @change="updateValue($event,'typ')" class="form-select" aria-label="Select Kontakttyp">
<option selected></option>
<option value="Nebenwohnsitz">{{$p.t('profilUpdate','nebenwohnsitz')}}</option>
<option value="Hauptwohnsitz">{{$p.t('profilUpdate','hauptwohnsitz')}}</option>
<option v-if="isMitarbeiter" value="Homeoffice">{{$p.t('profilUpdate','homeoffice')}}</option>
<option v-if="isMitarbeiter" value="Rechnungsadresse">{{$p.t('profilUpdate','rechnungsadresse')}}</option>
</select>
</div>
</template>
</div>
<div class="order-3 order-sm-3 order-xl-2 order-xxl-3 col-12 col-sm-7 col-xl-12 col-xxl-7 " >
<div class="form-underline ">
<div class="form-underline-titel">{{$p.t('person','ort')}}*</div>
<input class="form-control" :value="data.ort" @input="updateValue($event,'ort')" :placeholder="data.ort">
</div>
</div>
<div class="order-4 order-sm-2 order-xl-4 order-xxl-2 col-12 col-sm-3 col-xl-4 col-xxl-3 ">
<div class="form-underline ">
<div class="form-underline-titel">{{$p.t('person','plz')}}*</div>
<input class="form-control" :value="data.plz" @input="updateValue($event,'plz')" @input="getGemeinde" :placeholder="data.plz">
</div>
</div>
<div class="col-6 order-5">
<div class="form-underline ">
<div class="form-underline-titel">{{$p.t('person','gemeinde')}}*</div>
<auto-complete class="w-100" v-model="data.gemeinde" dropdown :forceSelection="data.nation ==='A'?true:false" :suggestions="gemeinden" @complete="autocompleteSearch" ></auto-complete>
</div>
</div>
<div class="col-6 order-5 ">
<div class="form-underline ">
<div class="form-underline-titel">{{$p.t('person','nation')}}*</div>
<select :value="data.nation" @change="updateValue($event,'nation')" @change="getGemeinde" class="form-select" aria-label="Select Kontakttyp">
<option selected></option>
<option :value="nation.code" v-for="nation in nationenList">{{nation.langtext}}</option>
</select>
</div>
</div>
<!-- warning message for too many zustellungs Adressen -->
<div v-if="showZustellAdressenWarning" class="col-12 ">
<div class="card bg-danger mx-2">
<div class="card-body text-white ">
<span>{{$p.t('profilUpdate','zustelladresseWarning')}}</span>
</div>
</div>
</div>
<!-- End of warning -->
<div class="col-12 ">
<div class="form-check mb-2">
<input class="form-check-input" type="checkbox" @change="updateValue($event,'zustelladresse')" :checked="data.zustelladresse" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
{{$p.t('person','zustelladresse')}}
</label>
</div>
</div>
<!-- NATION -->
<div class="col-8">
<div class="form-underline ">
<div class="form-underline-titel">{{$p.t('person','nation')}}*</div>
<select :value="data.nation" @change="updateValue($event,'nation')" @change="getGemeinde" class="form-select" aria-label="Select Kontakttyp">
<option selected></option>
<option :value="nation.code" v-for="nation in nationenList">{{nation.langtext}}</option>
</select>
</div>
</div>
<!-- PLZ -->
<div class=" col-4">
<div class="form-underline">
<div class="form-underline-titel">{{$p.t('person','plz')}}*</div>
<input class="form-control" :value="data.plz" @input="updateValue($event,'plz')" @input="getGemeinde" :placeholder="data.plz">
</div>
</div>
<!-- GEMEINDE -->
<div class="col-lg-6">
<div class="form-underline ">
<div class="form-underline-titel">{{$p.t('person','gemeinde')}}*</div>
<auto-complete class="w-100" v-model="data.gemeinde" dropdown :forceSelection="data.nation ==='A'?true:false" :suggestions="gemeinden" @complete="autocompleteSearchGemeinden" ></auto-complete>
</div>
</div>
<!-- ORT -->
<div class="col-lg-6" >
<div class="form-underline ">
<div class="form-underline-titel">{{$p.t('person','ort')}}*</div>
<auto-complete class="w-100" v-model="data.ort" dropdown :forceSelection="data.nation ==='A'?true:false" :suggestions="ortschaftnamen" @complete="autocompleteSearchOrtschaftsnamen" ></auto-complete>
</div>
</div>
<!-- STRASSE -->
<div class="col-lg-8">
<div class="form-underline ">
<div class="form-underline-titel">{{$p.t('person','strasse')}}*</div>
<input class="form-control" :value="data.strasse" @input="updateValue($event,'strasse')" :placeholder="data.strasse">
</div>
</div>
<!-- ADRESSEN TYP -->
<div class="col-lg-4">
<div class="form-underline">
<div class="form-underline-titel">{{$p.t('profilUpdate','kontaktTyp')}}*</div>
<select :value="data.typ" @change="updateValue($event,'typ')" class="form-select" aria-label="Select Kontakttyp">
<option selected></option>
<option value="Nebenwohnsitz">{{$p.t('profilUpdate','nebenwohnsitz')}}</option>
<option value="Hauptwohnsitz">{{$p.t('profilUpdate','hauptwohnsitz')}}</option>
<option v-if="isMitarbeiter" value="Homeoffice">{{$p.t('profilUpdate','homeoffice')}}</option>
<option v-if="isMitarbeiter" value="Rechnungsadresse">{{$p.t('profilUpdate','rechnungsadresse')}}</option>
</select>
</div>
</div>
</div>
`,
};
@@ -65,7 +65,7 @@ export default {
topic: { type: String },
},
created() {
Vue.$fhcapi.ProfilUpdate.getProfilRequestFiles(this.updateID).then(
this.$fhcApi.factory.profilUpdate.getProfilRequestFiles(this.updateID).then(
(res) => {
this.files = res.data;
}
@@ -85,6 +85,7 @@ export default {
editData: Object,
},
methods: {
betriebsmittelTableBuilt: function () {
this.$refs.betriebsmittelTable.tabulator.setData(this.data.mittel);
},
@@ -94,8 +95,8 @@ export default {
);
},
fetchProfilUpdates: function () {
Vue.$fhcapi.ProfilUpdate.selectProfilRequest().then((res) => {
if (!res.error) {
this.$fhcApi.factory.profilUpdate.selectProfilRequest().then((res) => {
if (!res.error && res) {
this.data.profilUpdates = res.data?.length
? res.data.sort(this.sortProfilUpdates)
: null;
@@ -106,17 +107,17 @@ export default {
hideEditProfilModal: function () {
//? checks the editModal component property result, if the user made a successful request or not
if (this.$refs.editModal.result) {
Vue.$fhcapi.ProfilUpdate.selectProfilRequest()
this.$fhcApi.factory.profilUpdate.selectProfilRequest()
.then((request) => {
if (!request.error) {
if (!request.error && res) {
this.data.profilUpdates = request.data;
this.data.profilUpdates.sort(this.sortProfilUpdates);
} else {
console.log("Error when fetching profile updates: " + res.data);
console.error("Error when fetching profile updates: " + res.data);
}
})
.catch((err) => {
console.log(err);
console.error(err);
});
} else {
// when modal was closed without submitting request
@@ -181,6 +182,7 @@ export default {
created() {
//? sorts the profil Updates: pending -> accepted -> rejected
this.data.profilUpdates?.sort(this.sortProfilUpdates);
},
@@ -205,6 +207,7 @@ export default {
<div class="row ">
<div class="col mb-3">
<button @click="showEditProfilModal" type="button" class="text-start w-100 btn btn-outline-secondary" >
<div class="row">
<div class="col-2">
@@ -62,7 +62,7 @@ export default {
handleRequest: function (type) {
this.loading = true;
this.setLoading(true);
Vue.$fhcapi.ProfilUpdate[
this.$fhcApi.factory.profilUpdate[
type.toLowerCase() == "accept"
? "acceptProfilRequest"
: "denyProfilRequest"
@@ -95,7 +95,7 @@ export default {
created() {
// only fetching the profilUpdate Attachemnts if the profilUpdate actually has attachments
if (this.value.attachment_id) {
Vue.$fhcapi.ProfilUpdate.getProfilRequestFiles(
this.$fhcApi.factory.profilUpdate.getProfilRequestFiles(
this.data.profil_update_id
).then((res) => {
this.files = res.data;
@@ -45,8 +45,11 @@ export default {
events: [],
profil_update_id: Number(this.id),
// tabulator options
profil_updates_table_options: {
};
},
computed:{
profilUpdateOptions: function(){
return {
ajaxURL:
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
@@ -128,7 +131,7 @@ export default {
"this is the data of the context menu action",
column.getData()
);
Vue.$fhcapi.ProfilUpdate.acceptProfilRequest(column.getData())
this.$fhcApi.factory.profilUpdate.acceptProfilRequest(column.getData())
.then((res) => {
this.$refs.UpdatesTable.tabulator.setData();
})
@@ -146,7 +149,7 @@ export default {
"denyUpdate"
)}`,
action: (e, column) => {
Vue.$fhcapi.ProfilUpdate.denyProfilRequest(column.getData())
this.$fhcApi.factory.profilUpdate.denyProfilRequest(column.getData())
.then((res) => {
this.$refs.UpdatesTable.tabulator.setData();
})
@@ -187,7 +190,7 @@ export default {
columns: [
{
title: Vue.computed(() => this.$p.t("profilUpdate", "UID")),
title: this.$p.t("profilUpdate", "UID"),
field: "uid",
minWidth: 200,
resizable: true,
@@ -195,7 +198,7 @@ export default {
//responsive:0,
},
{
title: Vue.computed(() => this.$p.t("profilUpdate", "Name")),
title: this.$p.t("profilUpdate", "Name"),
field: "name",
minWidth: 200,
resizable: true,
@@ -203,7 +206,7 @@ export default {
//responsive:0,
},
{
title: Vue.computed(() => this.$p.t("profilUpdate", "Topic")),
title: this.$p.t("profilUpdate", "Topic"),
field: "topic",
resizable: true,
minWidth: 200,
@@ -211,7 +214,7 @@ export default {
//responsive:0,
},
{
title: Vue.computed(() => this.$p.t("profilUpdate", "insertamum")),
title: this.$p.t("profilUpdate", "insertamum"),
field: "insertamum",
resizable: true,
headerFilter: true,
@@ -219,7 +222,7 @@ export default {
//responsive:0,
},
{
title: Vue.computed(() => this.$p.t("profilUpdate", "Status")),
title: this.$p.t("profilUpdate", "Status"),
field: "status_translated",
hozAlign: "center",
headerFilter: true,
@@ -245,7 +248,7 @@ export default {
//responsive:0,
},
{
title: Vue.computed(() => this.$p.t("profilUpdate", "actions")),
title: this.$p.t("profilUpdate", "actions"),
headerSort: false,
formatter: (cell, params) => {
let STATUS_PENDING =
@@ -257,7 +260,9 @@ export default {
${
STATUS_PENDING ?
`<button class="btn border-success border-2" id="acceptButton"><i class='fa fa-lg fa-circle-check text-success'></i></button>
<button class="btn border-danger border-2" id="denyButton"><i class=' fa fa-lg fa-circle-xmark text-danger'></i></button>`:''
<button class="btn border-danger border-2" id="denyButton"><i class=' fa fa-lg fa-circle-xmark text-danger'></i></button>`
:
``
}
</div>`;
@@ -293,12 +298,13 @@ export default {
hozAlign: "center",
},
],
},
};
};
}
},
methods: {
denyProfilUpdate: function (data) {
Vue.$fhcapi.ProfilUpdate.denyProfilRequest(data)
this.$fhcApi.factory.profilUpdate.denyProfilRequest(data)
.then((res) => {
// block when the request was successful
})
@@ -310,7 +316,7 @@ export default {
});
},
acceptProfilUpdate: function (data) {
Vue.$fhcapi.ProfilUpdate.acceptProfilRequest(data)
this.$fhcApi.factory.profilUpdate.acceptProfilRequest(data)
.then((res) => {
// block when the request was successful
})
@@ -409,7 +415,7 @@ export default {
</div>
<loading ref="loadingModalRef" :timeout="0"></loading>
<core-filter-cmpt v-if="profilUpdateStates && categoryLoaded" :title="$p.t('profilUpdate','profilUpdateRequests')" ref="UpdatesTable" :tabulatorEvents="events" :tabulator-options="profil_updates_table_options" tableOnly :sideMenu="false" />
<core-filter-cmpt v-if="profilUpdateStates && categoryLoaded" :title="$p.t('profilUpdate','profilUpdateRequests')" ref="UpdatesTable" :tabulatorEvents="events" :tabulator-options="profilUpdateOptions" tableOnly :sideMenu="false" />
</div>`,
};
+1 -1
View File
@@ -25873,7 +25873,7 @@ array(
'phrases' => array(
array(
'sprache' => 'German',
'text' => '!Achtung: Eine deiner Adressen ist bereits als Zustelladresse gespeichert, sind sie sicher, dass sie die aktuelle Adresse stattdessen als Zustelladresse speichern wollen?',
'text' => '!Achtung: Eine Ihrer Adressen ist bereits als Zustelladresse gespeichert, sind sie sicher, dass sie die aktuelle Adresse stattdessen als Zustelladresse speichern wollen?',
'description' => '',
'insertvon' => 'system'
),