diff --git a/application/config/anrechnung.php b/application/config/anrechnung.php index 2466d2bb1..6713ef37d 100644 --- a/application/config/anrechnung.php +++ b/application/config/anrechnung.php @@ -1,6 +1,6 @@ TRUE, + 'referenzbeispiele_ects' => TRUE, + 'voraussetzungen' => TRUE, + 'nachweisdokumente' => TRUE, + 'herkunft_kenntnisse' => TRUE +]; diff --git a/application/config/mail.php b/application/config/mail.php index 9d577720d..4f1baa85d 100644 --- a/application/config/mail.php +++ b/application/config/mail.php @@ -32,3 +32,18 @@ $config['validate'] = false; // If true then the email address will be validated // If enabled will be logged info about emails in Codeigniter error logs $config['enable_debug'] = false; + +// default sender +$config['sancho_mail_default_sender'] = defined('SANCHO_MAIL_DEFAULT_SENDER') ? SANCHO_MAIL_DEFAULT_SENDER : ''; + +// If to use images for custom mails +$config['sancho_mail_use_images'] = defined('SANCHO_MAIL_USE_IMAGES') ? SANCHO_MAIL_USE_IMAGES : false; + +// image path for sancho mail, relativ to document root +$config['sancho_mail_img_path'] = defined('SANCHO_MAIL_IMG_PATH') ? SANCHO_MAIL_IMG_PATH : ''; + +// header image for custom mails +$config['sancho_mail_header_img'] = defined('SANCHO_MAIL_HEADER_IMG') ? SANCHO_MAIL_HEADER_IMG : ''; + +// footer image for custom mails +$config['sancho_mail_footer_img'] = defined('SANCHO_MAIL_FOOTER_IMG') ? SANCHO_MAIL_FOOTER_IMG : ''; diff --git a/application/config/stv.php b/application/config/stv.php new file mode 100644 index 000000000..31ce3f521 --- /dev/null +++ b/application/config/stv.php @@ -0,0 +1,76 @@ + [ + //all fields can be configured to be hidden, see class attribute stv-details-details-name for name + 'hiddenFields' => [], + 'hideUDFs' => false + ], + + 'prestudent' => [ + + //all fields can be configured to be hidden, see class attribute stv-details-prestudent-name for name + 'hiddenFields' => [ + + //propably used by FH-Communities + 'aufnahmeschluessel', 'standort_code', 'facheinschlaegigBerufstaetig' + + ], + 'hideUDFs' => false + ], + 'finalexam' => [ + 'documents' => [ + 'pruefungsprotokoll' => [ + 'de' => [ + 'Bakk' => 'PrProtBA', + 'Master' => 'PrProtMA', + ], + 'en' => [ + 'Bakk' => 'PrProtBAEng', + 'Master' => 'PrProtMAEng', + ], + ], + 'pruefungszeugnis' => [ + 'de' => [ + 'Bakk' => 'Bakkzeugnis', + 'Master' => 'Diplomzeugnis', + ], + 'en' => [ + 'Bakk' => 'BakkzeugnisEng', + 'Master' => 'DiplomzeugnisEng', + ], + ], + 'urkunde' => [ + 'de' => [ + 'Bakk' => 'Bakkurkunde', + 'Master' => 'Diplomurkunde', + ], + 'en' => [ + 'Bakk' => 'BakkurkundeEng', + 'Master' => 'DiplomurkundeEng', + ], + ], + ], + ] + ]; + +// List of fields to show when ZGV_DOKTOR_ANZEIGEN is defined +$fieldsZgvDoktor = ['zgvdoktorort', 'zgvdoktordatum', 'zgvdoktornation', 'zgvdoktor_erfuellt', 'zgvdoktor_code']; + +// List of fields to show when ZGV_ERFUELLT_ANZEIGEN is defined +$fieldsZgvErfuellt = ['zgv_erfuellt', 'zgvmas_erfuellt','zgvdoktor_erfuellt']; + +//order important: to show zgf_erfuellt_doktor just in case visibility of doktor is true +if (!defined('ZGV_ERFUELLT_ANZEIGEN') || !ZGV_ERFUELLT_ANZEIGEN) { + $config['tabs']['prestudent']['hiddenFields'] = array_merge( + $config['tabs']['prestudent']['hiddenFields'], $fieldsZgvErfuellt + ); +} + +if (!defined('ZGV_DOKTOR_ANZEIGEN') || !ZGV_DOKTOR_ANZEIGEN) { + $config['tabs']['prestudent']['hiddenFields'] = array_merge( + $config['tabs']['prestudent']['hiddenFields'], + $fieldsZgvDoktor + ); +} diff --git a/application/controllers/Documents.php b/application/controllers/Documents.php new file mode 100644 index 000000000..47aae7ed1 --- /dev/null +++ b/application/controllers/Documents.php @@ -0,0 +1,294 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +/** + * This controller handles output and access to documents. + * It creates a XML file, transforms it with the XSL-FO Vorlage from the + * database and generates a PDF file with unoconv or docsbox. + * This file is then outputted as download. + * + * It is the CodeIgniter version of content/pdfExport.php when not using the + * get paremeters: "archivdokument" and "archive". + * Use exportSigned() instead of providing the "sign" get parameter and + * export() otherwise. + */ +class Documents extends Auth_Controller +{ + public function __construct() + { + parent::__construct([ + 'export' => self::PERM_LOGGED, + 'exportSigned' => self::PERM_LOGGED + ]); + + // Load Phrases + $this->loadPhrases([ + 'stv' + ]); + } + + /** + * Download a not signed document. + * + * @param string $xml + * @param string $xsl + * + * @return void + */ + public function export($xml, $xsl) + { + return $this->_export($xml, $xsl); + } + + /** + * Download a signed document. + * + * @param string $xml + * @param string $xsl + * + * @return void + */ + public function exportSigned($xml, $xsl) + { + return $this->_export($xml, $xsl, getAuthUID()); + } + + /** + * Helper function for export() and exportSigned() + * + * @param string $xml + * @param string $xsl + * @param string $sign_user (optional) + * + * @return void + */ + protected function _export($xml, $xsl, $sign_user = null) + { + $xsl_oe_kurzbz = null; + $version = $this->input->post_get('version') ?: null; + + // Get the OE or STG of the document + $xsl_oe_kurzbz = $this->input->post_get('xsl_oe_kurzbz') + ?: $this->input->post_get('xsl_stg_kz') + ?: $this->input->post_get('stg_kz'); + if (is_null($xsl_oe_kurzbz)) { + $uid = $this->input->post_get('uid'); + if ($uid) { + $uid = current(explode(';', $uid)); + $this->load->model('crm/Student_model', 'StudentModel'); + $result = $this->StudentModel->load([$uid]); + if (!isError($result) && hasData($result)) + $xsl_oe_kurzbz = current(getData($result))->studiengang_kz; + } + } + if (is_null($xsl_oe_kurzbz)) { + $prestudent_id = $this->input->post_get('prestudent_id'); + if ($prestudent_id) { + $prestudent_id = current(explode(';', $prestudent_id)); + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + $result = $this->PrestudentModel->load($prestudent_id); + if (!isError($result) && hasData($result)) + $xsl_oe_kurzbz = current(getData($result))->studiengang_kz; + } + } + if (is_null($xsl_oe_kurzbz)) + $xsl_oe_kurzbz = 0; + + // Access rights + if ($xsl == 'AccountInfo') { + $this->load->model('resource/Mitarbeiter_model', 'MitarbeiterModel'); + $this->load->model('crm/Student_model', 'StudentModel'); + $uids = $this->input->post_get('uid'); + if ($uids) { + $uids = explode(';', $uids); + foreach ($uids as $uid) { + $result = $this->MitarbeiterModel->load($uid); + if (!isError($result) && hasData($result)) { + if (!$this->permissionlib->isBerechtigt('admin', 'suid', 0) + && !$this->permissionlib->isBerechtigt('mitarbeiter', 'suid', 0)) + return $this->_outputAuthError([$this->router->method => ['admin:rw', 'mitarbeiter:rw']]); + } else { + $result = $this->StudentModel->load([$uid]); + if (!isError($result) && hasData($result)) { + $student = current(getData($result)); + if (!$this->permissionlib->isBerechtigt('admin', 'suid', $student->studiengang_kz) + && !$this->permissionlib->isBerechtigt('admin', 'suid', 0) + && !$this->permissionlib->isBerechtigt('assistenz', 'suid', $student->studiengang_kz) + && !$this->permissionlib->isBerechtigt('assistenz', 'suid', 0) + && !$this->permissionlib->isBerechtigt('support', 'suid', 0)) + return $this->_outputAuthError([$this->router->method => ['admin:rw', 'assistenz:rw', 'support:rw']]); + } + } + } + } + } else { + $this->load->model('system/Vorlagestudiengang_model', 'VorlagestudiengangModel'); + + $result = $this->VorlagestudiengangModel->getCurrent($xsl, $xsl_oe_kurzbz, $version); + if (isError($result)) + return show_error(getError($result)); + if (!hasData($result)) + return show_404(); + + $access_rights = current(getData($result))->berechtigung; + if (!$access_rights) + return show_404(); + $allowed = false; + foreach ($access_rights as $access_right) { + if ($this->permissionlib->isBerechtigt($access_right)) { + $allowed = true; + break; + } + } + if (!$allowed) + return $this->_outputAuthError([$this->router->method => $access_rights]); + } + + // Output format + $outputformat = $this->input->post_get('output') ?: 'pdf'; + if ($outputformat != 'pdf' + // An der FHTW darf das Studienblatt und das Prüfungsprotokoll auch in anderen Formaten exportiert werden + && !(CAMPUS_NAME == 'FH Technikum Wien' + && ($xsl == 'Studienblatt' + || $xsl == 'StudienblattEng' + || $xsl == 'PrProtBA' + || $xsl == 'PrProtBAEng' + || $xsl == 'PrProtMA' + || $xsl == 'PrProtMAEng' + ) + ) + && !$this->permissionlib->isBerechtigt('system/change_outputformat', null, $xsl_oe_kurzbz) + ) { + $outputformat = 'pdf'; + } + + // XML Params + $params = 'xmlformat=xml'; + foreach ([ + 'uid', + 'stg_kz', + 'person_id', + 'id', + 'prestudent_id', + 'buchungsnummern', + 'ss', + 'abschlusspruefung_id', + 'typ', + 'all', + 'preoutgoing_id', + 'lvid', + 'projekt_kurzbz', + 'von', + 'bis', + 'stundevon', + 'stundebis', + 'sem', + 'lehreinheit', + 'mitarbeiter_uid', + 'studienordnung_id', + 'fixangestellt', + 'standort', + 'abrechnungsmonat', + 'form', + 'projektarbeit_id', + 'betreuerart_kurzbz', + 'studiensemester_kurzbz' + ] as $key) { + $value = $this->input->post_get($key); + if ($value !== null) + $params .= '&' . $key . '=' . urlencode($value); + } + $value = $this->input->post_get('vertrag_id'); + if ($value !== null) { + foreach ($value as $id) + $params .= '&vertrag_id[]=' . urlencode($id); + } + + $this->load->library('DocumentExportLib'); + $this->load->model('system/Vorlage_model', 'VorlageModel'); + + $result = $this->VorlageModel->load($xsl); + if (isError($result)) + return show_error(getError($result)); + if (!hasData($result)) + show_404(); + + $vorlage = current(getData($result)); + if ($sign_user && !$vorlage->signierbar) + return show_error($this->p->t("stv", "grades_error_sign")); + + + // Filename + $filename = ($vorlage->bezeichnung ?: $vorlage->vorlage_kurzbz); + switch ($xsl) { + case 'LV_Informationen': + $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); + $result = $this->StudiengangModel->load($this->input->post_get('stg_kz')); + if (!isError($result) && hasData($result)) + $filename .= '_' . sanitizeProblemChars(current(getData($result))->kurzbzlang); + + $this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel'); + $result = $this->StudiensemesterModel->load($this->input->post_get('ss')); + if (!isError($result) && hasData($result)) + $filename .= '_' . sanitizeProblemChars(current(getData($result))->studiensemester_kurzbz); + break; + case 'Honorarvertrag': + $uid = str_replace(';', '', $this->input->post_get('uid') ?: ''); + $this->load->model('person/Benutzer_model', 'BenutzerModel'); + $this->BenutzerModel->addJoin('public.tbl_person', 'person_id', 'LEFT'); + $result = $this->BenutzerModel->load([$uid]); + if (!isError($result) && hasData($result)) { + $user = current(getData($result)); + $filename .= '_' . sanitizeProblemChars($user->nachname) . '_' . sanitizeProblemChars($user->vorname); + } + break; + case 'Studienordnung': + $filename = 'Studienordnung-Studienplan-'; + + $this->load->model('organisation/Studienordnung_model', 'StudienordnungModel'); + $result = $this->StudienordnungModel->load($this->input->post_get('studienordnung_id')); + if (!isError($result) && hasData($result)) { + $so = current(getData($result)); + $filename .= sprintf("%'.04d", $so->studiengang_kz) . '-' . $so->studiengangkurzbzlang; + } + break; + default: + $uid = str_replace(';', '', $this->input->post_get('uid') ?: ''); + $this->load->model('person/Benutzer_model', 'BenutzerModel'); + $this->BenutzerModel->addJoin('public.tbl_person', 'person_id', 'LEFT'); + $result = $this->BenutzerModel->load([$uid]); + if (!isError($result) && hasData($result)) { + $user = current(getData($result)); + $filename .= '_' . sanitizeProblemChars($user->nachname); + } + break; + } + + // XML Data + $result = $this->documentexportlib->getDataURL($xml, $params); + if (isError($result)) + return show_error(getError($result)); + + $data = getData($result); + + // Output + $this->documentexportlib->showContent($filename, $vorlage, $data, $xsl_oe_kurzbz, $version, $outputformat, $sign_user); + } +} diff --git a/application/controllers/Studentenverwaltung.php b/application/controllers/Studentenverwaltung.php index e09d04c6a..2ce19c58a 100644 --- a/application/controllers/Studentenverwaltung.php +++ b/application/controllers/Studentenverwaltung.php @@ -30,7 +30,8 @@ class Studentenverwaltung extends Auth_Controller 'admin' => $this->permissionlib->isBerechtigt('admin'), 'assistenz_schreibrechte' => $this->permissionlib->isBerechtigt('assistenz','suid'), 'student/keine_studstatuspruefung' => $this->permissionlib->isBerechtigt('student/keine_studstatuspruefung'), - 'lehre/reihungstestAufsicht' => $this->permissionlib->isBerechtigt('lehre/reihungstestAufsicht') + 'lehre/reihungstestAufsicht' => $this->permissionlib->isBerechtigt('lehre/reihungstestAufsicht'), + 'system/change_outputformat' => $this->permissionlib->getOE_isEntitledFor('system/change_outputformat'), ], 'variables' => [ 'semester_aktuell' => $this->variablelib->getVar('semester_aktuell') diff --git a/application/controllers/api/frontend/v1/Documents.php b/application/controllers/api/frontend/v1/Documents.php new file mode 100644 index 000000000..60010e14d --- /dev/null +++ b/application/controllers/api/frontend/v1/Documents.php @@ -0,0 +1,422 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +/** + * This controller operates between (interface) the JS (GUI) and the back-end + * Provides data to the ajax get calls about documents + * Listens to ajax post calls to change the documents data + * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON + * + * This controller handles output and access to documents. + * It checks permissions to render documents in an alternative format + * or it creates a XML file, transforms it with the XSL-FO Vorlage from the + * database and generates a PDF file with unoconv or docsbox. + * This file is then archivated in the database. + * + * The last part is the CodeIgniter version of content/pdfExport.php when not + * using the get paremeter: "archivdokument" but using the get parameter: + * "archive". + * Use archiveSigned() instead of providing the "sign" get parameter and + * archive() otherwise. + */ +class Documents extends FHCAPI_Controller +{ + public function __construct() + { + parent::__construct([ + 'permissionAlternativeFormat' => self::PERM_LOGGED, + 'archive' => ['admin:rw', 'assistenz:rw'], + 'archiveSigned' => ['admin:rw', 'assistenz:rw'] + ]); + + // Load Phrases + $this->loadPhrases([ + 'stv' + ]); + } + + /** + * Checks if the current user has permission to render documents in an + * alternative format. + * + * @param string $oe_kurzbz Or studiengang_kz + * + * @return void + */ + public function permissionAlternativeFormat($oe_kurzbz) + { + $this->terminateWithSuccess($this->permissionlib->isBerechtigt('system/change_outputformat', null, $oe_kurzbz)); + } + + /** + * Download a not signed document. + * + * @param string $xml (optional) + * @param string $xsl (optional) + * + * @return void + */ + public function archive($xml = null, $xsl = null) + { + return $this->_archive($xml, $xsl); + } + + /** + * Download a signed document. + * + * @param string $xml (optional) + * @param string $xsl (optional) + * + * @return void + */ + public function archiveSigned($xml = null, $xsl = null) + { + return $this->_archive($xml, $xsl, getAuthUID()); + } + + /** + * Helper function for archive() and archiveSigned() + * + * @param string $xml + * @param string $xsl + * @param string $sign_user (optional) + * + * @return void + */ + public function _archive($xml, $xsl, $sign_user = null) + { + if (!$xml || !$xsl) { + $this->load->library('form_validation'); + if (!$xml) { + $xml = $this->input->post_get('xml'); + $this->form_validation->set_rules('xml', 'xml', 'required'); + } + if (!$xsl) { + $xsl = $this->input->post_get('xsl'); + $this->form_validation->set_rules('xsl', 'xsl', 'required'); + } + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + } + + $xsl_oe_kurzbz = null; + $version = $this->input->post_get('version') ?: null; + + // Get the OE or STG of the document + $xsl_oe_kurzbz = $this->input->post_get('xsl_oe_kurzbz') + ?: $this->input->post_get('xsl_stg_kz') + ?: $this->input->post_get('stg_kz'); + if (is_null($xsl_oe_kurzbz)) { + $uid = $this->input->post_get('uid'); + if ($uid) { + $uid = current(explode(';', $uid)); + $this->load->model('crm/Student_model', 'StudentModel'); + $result = $this->StudentModel->load([$uid]); + if (!isError($result) && hasData($result)) + $xsl_oe_kurzbz = current(getData($result))->studiengang_kz; + } + } + if (is_null($xsl_oe_kurzbz)) { + $prestudent_id = $this->input->post_get('prestudent_id'); + if ($prestudent_id) { + $prestudent_id = current(explode(';', $prestudent_id)); + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + $result = $this->PrestudentModel->load($prestudent_id); + if (!isError($result) && hasData($result)) + $xsl_oe_kurzbz = current(getData($result))->studiengang_kz; + } + } + if (is_null($xsl_oe_kurzbz)) + $xsl_oe_kurzbz = 0; + + // Vorlage + $this->load->model('system/Vorlage_model', 'VorlageModel'); + + $result = $this->VorlageModel->load($xsl); + $vorlage = current($this->getDataOrTerminateWithError($result)); + if (!$vorlage) + show_404(); + + // Akte Data + $akteData = [ + 'dokument_kurzbz' => $vorlage->dokument_kurzbz ?: 'Zeugnis', + 'mimetype' => 'application/pdf', + 'erstelltam' => date('Y-m-d'), + 'gedruckt' => true, + 'insertamum' => date('c'), + 'insertvon' => getAuthUID(), + 'uid' => $this->input->post_get('uid') ?: '', + 'archiv' => true, + 'signiert' => !!$sign_user, + 'stud_selfservice' => $vorlage->stud_selfservice + ]; + $studiengang_kz = null; + if ($akteData['uid']) { + $this->load->model('crm/Student_model', 'StudentModel'); + $this->StudentModel->addJoin('public.tbl_studiengang', 'studiengang_kz', 'LEFT'); + $result = $this->StudentModel->load([$akteData['uid']]); + $student = current($this->getDataOrTerminateWithError($result)); + + $ss = $this->input->post_get('ss'); + + if ($ss !== null) { + $this->load->model('crm/prestudentstatus_model', 'PrestudentstatusModel'); + $result = $this->PrestudentstatusModel->getLastStatus($student->prestudent_id, $ss); + $status = current($this->getDataOrTerminateWithError($result)); + if (!$status) + $this->terminateWithError($this->p->t("stv", "grades_error_prestudentstatus")); + $semester = $status->ausbildungssemester; + + $this->load->model('education/Studentlehrverband_model', 'StudentlehrverbandModel'); + $this->StudentlehrverbandModel->addJoin('public.tbl_benutzer', 'uid = student_uid'); + $this->StudentlehrverbandModel->addJoin('public.tbl_studiengang', 'studiengang_kz'); + $result = $this->StudentlehrverbandModel->load([ + 'studiensemester_kurzbz' => $ss, + 'student_uid' => $akteData['uid'] + ]); + $res = current($this->getDataOrTerminateWithError($result)); + + $studiengang_kz = $res->studiengang_kz; + $akteData['person_id'] = $res->person_id; + switch ($xsl) { + case 'Ausbildungsver': + case 'AusbVerEng': + $akteData['titel'] = mb_substr($xsl . + "_" . + strtoupper($res->typ) . + strtoupper($res->kurzbz) . + "_" . + $semester . + "_" . + $ss, 0, 64); + $akteData['bezeichnung'] = mb_substr($vorlage->bezeichnung . " " . $student->kuerzel, 0, 64); + break; + case 'LVZeugnisEng': + case 'LVZeugnis': + case 'Zertifikat': + $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); + $result = $this->LehrveranstaltungModel->load($this->input->post_get('lvid')); + $lv = current($this->getDataOrTerminateWithError($result)); + $akteData['dokument_kurzbz'] = $xsl; + $akteData['titel'] = mb_substr($xsl . + "_" . + strtoupper($res->typ) . + strtoupper($res->kurzbz) . + "_" . + $semester . + '_' . + $ss . + '_' . + str_replace(' ', '_', $lv->bezeichnung), 0, 60); + $akteData['bezeichnung'] = mb_substr($xsl . + " " . + strtoupper($res->typ) . + strtoupper($res->kurzbz) . + " " . + $semester . + ". Semester" . + ' ' . + $ss . + ' ' . + $lv->bezeichnung, 0, 64); + break; + case 'SZeugnis': + $akteData['titel'] = mb_substr($vorlage->bezeichnung . " " . $student->kuerzel, 0, 64); + $akteData['bezeichnung'] = mb_substr($vorlage->bezeichnung . " " . $student->kuerzel, 0, 64); + break; + default: + $akteData['titel'] = mb_substr($xsl . + "_" . + strtoupper($res->typ) . + strtoupper($res->kurzbz) . + "_" . + $semester . + "_" . + $ss, 0, 64); + $akteData['bezeichnung'] = mb_substr($xsl . + " " . + strtoupper($res->typ) . + strtoupper($res->kurzbz) . + " " . + $semester . + ". Semester" . + ' ' . + $ss, 0, 64); + break; + } + } else { + $studiengang_kz = $student->studiengang_kz; + $akteData['person_id'] = $student->person_id; + $akteData['titel'] = $vorlage->bezeichnung . '_' . $student->kuerzel; + $akteData['bezeichnung'] = mb_substr($vorlage->bezeichnung . " " . $student->kuerzel, 0, 64); + } + } else { + $prestudent_id = $this->input->post_get('prestudent_id'); + if ($prestudent_id) { + $this->load->model('crm/prestudent_model', 'PrestudentModel'); + $this->PrestudentModel->addJoin('public.tbl_studiengang', 'studiengang_kz', 'LEFT'); + $result = $this->PrestudentModel->load($prestudent_id); + $prestudent = current($this->getDataOrTerminateWithError($result)); + + $studiengang_kz = $prestudent->studiengang_kz; + $akteData['person_id'] = $prestudent->person_id; + $akteData['titel'] = mb_substr($xsl . "_" . $prestudent->kuerzel, 0, 64); + $akteData['bezeichnung'] = mb_substr($vorlage->bezeichnung . " " . $prestudent->kuerzel, 0, 64); + } + } + + // Access rights + if (!$this->permissionlib->isBerechtigt('admin', 'suid', $studiengang_kz) + && !$this->permissionlib->isBerechtigt('assistenz', 'suid', $studiengang_kz)) + return $this->_outputAuthError([$this->router->method => ['admin:rw', 'assistenz:rw']]); + if ($xsl == 'AccountInfo') { + $this->load->model('resource/Mitarbeiter_model', 'MitarbeiterModel'); + $this->load->model('crm/Student_model', 'StudentModel'); + $uids = $this->input->post_get('uid'); + if ($uids) { + $uids = explode(';', $uids); + foreach ($uids as $uid) { + $result = $this->MitarbeiterModel->load($uid); + if (!isError($result) && hasData($result)) { + if (!$this->permissionlib->isBerechtigt('admin', 'suid', 0) + && !$this->permissionlib->isBerechtigt('mitarbeiter', 'suid', 0)) + return $this->_outputAuthError([$this->router->method => ['admin:rw', 'mitarbeiter:rw']]); + } else { + $result = $this->StudentModel->load([$uid]); + if (!isError($result) && hasData($result)) { + $student = current(getData($result)); + if (!$this->permissionlib->isBerechtigt('admin', 'suid', $student->studiengang_kz) + && !$this->permissionlib->isBerechtigt('admin', 'suid', 0) + && !$this->permissionlib->isBerechtigt('assistenz', 'suid', $student->studiengang_kz) + && !$this->permissionlib->isBerechtigt('assistenz', 'suid', 0) + && !$this->permissionlib->isBerechtigt('support', 'suid', 0)) + return $this->_outputAuthError([$this->router->method => ['admin:rw', 'assistenz:rw', 'support:rw']]); + } + } + } + } + } else { + $this->load->model('system/Vorlagestudiengang_model', 'VorlagestudiengangModel'); + + $result = $this->VorlagestudiengangModel->getCurrent($xsl, $xsl_oe_kurzbz, $version); + $access_rights = current($this->getDataOrTerminateWithError($result)); + if (!$access_rights || !$access_rights->berechtigung) + return show_404(); + + $allowed = false; + foreach ($access_rights->berechtigung as $access_right) { + if ($this->permissionlib->isBerechtigt($access_right)) { + $allowed = true; + break; + } + } + if (!$allowed) + return $this->_outputAuthError([$this->router->method => $access_rights]); + } + + // Output format + $outputformat = $this->input->post_get('output') ?: 'pdf'; + if ($outputformat != 'pdf' + // An der FHTW darf das Studienblatt und das Prüfungsprotokoll auch in anderen Formaten exportiert werden + && !(CAMPUS_NAME == 'FH Technikum Wien' + && ($xsl == 'Studienblatt' + || $xsl == 'StudienblattEng' + || $xsl == 'PrProtBA' + || $xsl == 'PrProtBAEng' + || $xsl == 'PrProtMA' + || $xsl == 'PrProtMAEng' + ) + ) + && !$this->permissionlib->isBerechtigt('system/change_outputformat', null, $xsl_oe_kurzbz) + ) { + $outputformat = 'pdf'; + } + + // XML Params + $params = 'xmlformat=xml'; + foreach ([ + 'uid', + 'stg_kz', + 'person_id', + 'id', + 'prestudent_id', + 'buchungsnummern', + 'ss', + 'abschlusspruefung_id', + 'typ', + 'all', + 'preoutgoing_id', + 'lvid', + 'projekt_kurzbz', + 'von', + 'bis', + 'stundevon', + 'stundebis', + 'sem', + 'lehreinheit', + 'mitarbeiter_uid', + 'studienordnung_id', + 'fixangestellt', + 'standort', + 'abrechnungsmonat', + 'form', + 'projektarbeit_id', + 'betreuerart_kurzbz', + 'studiensemester_kurzbz' + ] as $key) { + $value = $this->input->post_get($key); + if ($value !== null) + $params .= '&' . $key . '=' . urlencode($value); + } + $value = $this->input->post_get('vertrag_id'); + if ($value !== null) { + foreach ($value as $id) + $params .= '&vertrag_id[]=' . urlencode($id); + } + + if (!$vorlage->archivierbar) + $this->terminateWithError($this->p->t("stv", "grades_error_archive")); + + if ($sign_user && !$vorlage->signierbar) + $this->terminateWithError($this->p->t("stv", "grades_error_sign")); + + + $this->load->library('DocumentExportLib'); + + // XML Data + $result = $this->documentexportlib->getDataURL($xml, $params); + $data = $this->getDataOrTerminateWithError($result); + $this->documentexportlib->addArchiveToData($data); + + // Output + $result = $this->documentexportlib->getContent($vorlage, $data, $xsl_oe_kurzbz, $version, $outputformat, $sign_user); + + $content = $this->getDataOrTerminateWithError($result); + $akteData['titel'] .= '.pdf'; + $akteData['inhalt'] = base64_encode($content); + + $this->load->model('crm/Akte_model', 'AkteModel'); + $result = $this->AkteModel->insert($akteData); + $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess(true); + } +} diff --git a/application/controllers/api/frontend/v1/Filter.php b/application/controllers/api/frontend/v1/Filter.php index 45838fc5f..b195e0012 100644 --- a/application/controllers/api/frontend/v1/Filter.php +++ b/application/controllers/api/frontend/v1/Filter.php @@ -113,7 +113,7 @@ class Filter extends FHCAPI_Controller */ public function applyFilterFields() { - $this->form_validation->set_rules('filterFields', 'filterFields', 'required'); + $this->form_validation->set_rules('filterFields[]', 'filterFields', 'required'); if (!$this->form_validation->run()) $this->terminateWithValidationErrors($this->form_validation->error_array()); diff --git a/application/controllers/api/frontend/v1/betriebsmittel/BetriebsmittelP.php b/application/controllers/api/frontend/v1/betriebsmittel/BetriebsmittelP.php index 8e44b2326..8e9d931f2 100644 --- a/application/controllers/api/frontend/v1/betriebsmittel/BetriebsmittelP.php +++ b/application/controllers/api/frontend/v1/betriebsmittel/BetriebsmittelP.php @@ -342,7 +342,7 @@ class BetriebsmittelP extends FHCAPI_Controller $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id' => 'Betriebsmittelperson_id']), self::ERROR_TYPE_GENERAL); } - $this->terminateWithSuccess(current(getData($result))); + return $this->terminateWithSuccess(current(getData($result))); } public function deleteBetriebsmittel($betriebsmittelperson_id) @@ -358,7 +358,7 @@ class BetriebsmittelP extends FHCAPI_Controller if (!hasData($result)) { return $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id' => 'Betriebsmittelperson_id']), self::ERROR_TYPE_GENERAL); } - return $this->outputJsonSuccess(current(getData($result))); + $this->terminateWithSuccess(current(getData($result))); } public function getTypenBetriebsmittel() diff --git a/application/controllers/api/frontend/v1/organisation/StudiengangEP.php b/application/controllers/api/frontend/v1/organisation/StudiengangEP.php new file mode 100644 index 000000000..463243f57 --- /dev/null +++ b/application/controllers/api/frontend/v1/organisation/StudiengangEP.php @@ -0,0 +1,57 @@ + self::PERM_LOGGED + ) + ); + // Load model StudiengangModel + $this->load->model('organisation/studiengang_model', 'StudiengangModel'); + } + + /** + * @return void + */ + public function getStudiengangByKz() + { + $studiengang_kz = intval($this->input->get('studiengang_kz')); + + $this->StudiengangModel->addSelect('studiengang_kz, kurzbz, kurzbzlang, ' + . 'typ, bezeichnung, english, aktiv, orgform_kurzbz, sprache, ' + . 'oe_kurzbz'); + $result = $this->StudiengangModel->load($studiengang_kz); + + if (isError($result)) + { + $this->terminateWithError(getError($result), self::ERROR_TYPE_DB); + } + + $stg = null; + if(hasData($result)) + { + $stg = (getData($result))[0]; + } + $this->terminateWithSuccess($stg); + } +} diff --git a/application/controllers/api/frontend/v1/organisation/Studienjahr.php b/application/controllers/api/frontend/v1/organisation/Studienjahr.php new file mode 100644 index 000000000..cdbb524c7 --- /dev/null +++ b/application/controllers/api/frontend/v1/organisation/Studienjahr.php @@ -0,0 +1,80 @@ + self::PERM_LOGGED, + 'getNext' => self::PERM_LOGGED + ) + ); + // Load model StudiensemesterModel + $this->load->model('organisation/studienjahr_model', 'StudienjahrModel'); + } + + /** + * Get all Studienjahre. + * + * @param null|string $order Sorting order for the Studienjahr, 'asc' or 'desc'. Defaults to 'asc'. + * @param null|string $start Starting Studienjahre with given studienjahr_kurzbz + */ + public function getAll() + { + $order = $this->input->get('order'); + $start = $this->input->get('studienjahr_kurzbz'); + + if (strcasecmp($order, 'DESC') == 0) { + $this->StudienjahrModel->addOrder('studienjahr_kurzbz', 'DESC'); + } else { + $this->StudienjahrModel->addOrder('studienjahr_kurzbz', 'ASC'); + } + + if ($start) { + $result = $this->StudienjahrModel->loadWhere([ + 'studienjahr_kurzbz >= ' => $start + ]); + } else { + $result = $this->StudienjahrModel->load(); + } + + if (isError($result)) { + $this->terminateWithError(getError($result), self::ERROR_TYPE_DB); + } + + $this->terminateWithSuccess((getData($result) ?: [])); + } + + public function getNext() + { + $this->StudienjahrModel->addJoin('public.tbl_studiensemester', 'studienjahr_kurzbz'); + $this->StudienjahrModel->addOrder('start'); + $this->StudienjahrModel->addLimit(1); + + $result = $this->StudienjahrModel->loadWhere(['start >' => 'NOW()']); + + if (isError($result)) { + $this->terminateWithError(getError($result), self::ERROR_TYPE_DB); + } + + $this->terminateWithSuccess(current(getData($result))); + } +} diff --git a/application/controllers/api/frontend/v1/organisation/Studiensemester.php b/application/controllers/api/frontend/v1/organisation/Studiensemester.php index 72a449aaa..bb56ea71a 100644 --- a/application/controllers/api/frontend/v1/organisation/Studiensemester.php +++ b/application/controllers/api/frontend/v1/organisation/Studiensemester.php @@ -24,7 +24,8 @@ class Studiensemester extends FHCAPI_Controller parent::__construct( array( 'getAll' => self::PERM_LOGGED, - 'getAktNext' => self::PERM_LOGGED + 'getAktNext' => self::PERM_LOGGED, + 'getStudienjahrByStudiensemester' => self::PERM_LOGGED ) ); // Load model StudiensemesterModel @@ -115,4 +116,40 @@ class Studiensemester extends FHCAPI_Controller $this->terminateWithSuccess((getData($result) ?: '')); } + + /** + * Get Studienjahr by Studiensemester. + * input param semester: studiensemester_kurzbz + */ + public function getStudienjahrByStudiensemester() + { + $semester = $this->input->get('semester'); + + $studienjahrObj = null; + + if (!is_numeric($semester)) + { + $this->StudiensemesterModel->addSelect('studienjahr_kurzbz'); + $result = $this->StudiensemesterModel->loadWhere(array('studiensemester_kurzbz =' => $semester)); + } + + if (hasData($result)) + { + $studienjahr = getData($result)[0]->studienjahr_kurzbz; + $startstudienjahr = substr($studienjahr, 0, 4); + $endstudienjahr = substr($studienjahr, 0, 2) . substr($studienjahr, -2); + + $studienjahrObj = new StdClass(); + + $studienjahrObj->studienjahr_kurzbz = $studienjahr; + $studienjahrObj->startstudienjahr = $startstudienjahr; + $studienjahrObj->endstudienjahr= $endstudienjahr; + } + + if (isError($result)) { + $this->terminateWithError(getError($result), self::ERROR_TYPE_DB); + } + + $this->terminateWithSuccess((getData(success($studienjahrObj)))); + } } diff --git a/application/controllers/api/frontend/v1/stv/Abschlusspruefung.php b/application/controllers/api/frontend/v1/stv/Abschlusspruefung.php new file mode 100644 index 000000000..daaf043b5 --- /dev/null +++ b/application/controllers/api/frontend/v1/stv/Abschlusspruefung.php @@ -0,0 +1,420 @@ + ['admin:r', 'assistenz:r'], + 'loadAbschlusspruefung' => ['admin:r', 'assistenz:r'], + 'insertAbschlusspruefung' => ['admin:rw', 'assistenz:rw'], + 'updateAbschlusspruefung' => ['admin:rw', 'assistenz:rw'], + 'deleteAbschlusspruefung' => ['admin:rw', 'assistenz:rw'], + 'getTypenAbschlusspruefung' => ['admin:rw', 'assistenz:rw'], + 'getNoten' => ['admin:rw', 'assistenz:rw'], + 'getTypenAntritte' => ['admin:rw', 'assistenz:rw'], + 'getBeurteilungen' => ['admin:rw', 'assistenz:rw'], + 'getAkadGrade' => ['admin:rw', 'assistenz:rw'], + 'getMitarbeiter' => ['admin:rw', 'assistenz:rw'], + 'getPruefer' => ['admin:rw', 'assistenz:rw'], + 'getTypStudiengang' => ['admin:rw', 'assistenz:rw'], + 'checkForExistingExams' => ['admin:rw', 'assistenz:rw'], + ]); + + // Load Libraries + $this->load->library('VariableLib', ['uid' => getAuthUID()]); + $this->load->library('form_validation'); + + // Load language phrases + $this->loadPhrases([ + 'ui', + 'person', + 'abschlusspruefung' + ]); + + // Load models + $this->load->model('education/Abschlusspruefung_model', 'AbschlusspruefungModel'); + } + + public function getAbschlusspruefung($student_uid) + { + $result = $this->AbschlusspruefungModel->getAbschlusspruefungForPrestudent($student_uid); + + if (isError($result)) { + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + + $this->terminateWithSuccess((getData($result) ?: [])); + } + + public function loadAbschlusspruefung() + { + $abschlusspruefung_id = $this->input->post('id'); + + $this->AbschlusspruefungModel->addSelect('lehre.tbl_abschlusspruefung.*'); + $this->AbschlusspruefungModel->addSelect(" + CASE + WHEN pruefer1 IS NOT NULL + THEN CONCAT(p1.nachname, ' ', p1.vorname, COALESCE(' ' || p1.titelpre, '')) + ELSE NULL + END AS p1 + "); + $this->AbschlusspruefungModel->addSelect(" + CASE + WHEN pruefer2 IS NOT NULL + THEN CONCAT(p2.nachname, ' ', p2.vorname, COALESCE(' ' || p2.titelpre, '')) + ELSE NULL + END AS p2 + "); + $this->AbschlusspruefungModel->addSelect(" + CASE + WHEN pruefer3 IS NOT NULL + THEN CONCAT(p3.nachname, ' ', p3.vorname, COALESCE(' ' || p3.titelpre, '')) + ELSE NULL + END AS p3 + "); + $this->AbschlusspruefungModel->addSelect(" + CASE + WHEN vorsitz IS NOT NULL + THEN CONCAT(pv.nachname, ' ', pv.vorname, COALESCE(' ' || pv.titelpre, ''), ' (', ben.uid , ')' ) + ELSE NULL + END AS pv + "); + $this->AbschlusspruefungModel->addJoin('public.tbl_benutzer ben', 'ON (ben.uid = lehre.tbl_abschlusspruefung.vorsitz)', 'LEFT'); + $this->AbschlusspruefungModel->addJoin('public.tbl_person pv', 'ON (pv.person_id = ben.person_id)', 'LEFT'); + $this->AbschlusspruefungModel->addJoin('public.tbl_person p1', 'ON (p1.person_id = lehre.tbl_abschlusspruefung.pruefer1)', 'LEFT'); + $this->AbschlusspruefungModel->addJoin('public.tbl_person p2', 'ON (p2.person_id = lehre.tbl_abschlusspruefung.pruefer2)', 'LEFT'); + $this->AbschlusspruefungModel->addJoin('public.tbl_person p3', 'ON (p3.person_id = lehre.tbl_abschlusspruefung.pruefer3)', 'LEFT'); + $result = $this->AbschlusspruefungModel->loadWhere( + array('abschlusspruefung_id' => $abschlusspruefung_id) + ); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess(current($data)); + } + + public function getTypenAbschlusspruefung() + { + $this->load->model('education/Pruefungstyp_model', 'PruefungstypModel'); + + $result = $this->PruefungstypModel->loadWhere( + array('abschluss' => true) + ); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getTypenAntritte() + { + $this->load->model('education/Pruefungsantritt_model', 'PruefungsantrittModel'); + + $result = $this->PruefungsantrittModel->load(); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getBeurteilungen() + { + $this->load->model('education/Abschlussbeurteilung_model', 'AbschlussbeurteilungModel'); + + $result = $this->AbschlussbeurteilungModel->load(); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getAkadGrade() + { + $studiengang_kz= $this->input->post('studiengang_kz'); + + + $this->load->model('education/Akadgrad_model', 'AkadgradModel'); + + $result = $this->AkadgradModel->loadWhere( + array('studiengang_kz' => $studiengang_kz) + ); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getTypStudiengang() + { + $studiengang_kz= $this->input->post('studiengang_kz'); + +/* if (!$studiengang_kzs || !is_array($studiengang_kzs)) { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('studiengang_kzs', '', 'required|is_null', [ + 'is_null' => $this->p->t('ui', 'error_fieldMustBeArray') + ]); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + }*/ + + + $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); + + $result = $this->StudiengangModel->loadWhere( + array('studiengang_kz' => $studiengang_kz) + ); + $data = $this->getDataOrTerminateWithError($result); + + $typStudiengang = current($data)->typ; + + $this->terminateWithSuccess($typStudiengang); + } + + public function getMitarbeiter($searchString) + { + $this->load->model('ressource/Mitarbeiter_model', 'MitarbeiterModel'); + + $result = $this->MitarbeiterModel->searchMitarbeiter($searchString, 'mitAkadGrad'); + + if (isError($result)) { + $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); + } + $this->terminateWithSuccess($result ?: []); + } + + public function getPruefer($searchString) + { + $this->load->model('ressource/Mitarbeiter_model', 'MitarbeiterModel'); + + $result = $this->MitarbeiterModel->searchMitarbeiter($searchString, 'ohneMaUid'); + + if (isError($result)) { + $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); + } + + $this->terminateWithSuccess($result ?: []); + } + + public function getNoten() + { + $this->load->model('education/Note_model', 'NoteModel'); + + $this->NoteModel->addOrder('note', 'ASC'); + $result = $this->NoteModel->load(); + + if (isError($result)) { + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + return $this->terminateWithSuccess(getData($result) ?: []); + } + + public function insertAbschlusspruefung() + { + $this->load->library('form_validation'); + + $student_uid = $this->input->post('uid'); + + if(!$student_uid) + { + return $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Student UID']), self::ERROR_TYPE_GENERAL); + } + + $formData = $this->input->post('formData'); + + $_POST['pruefungstyp_kurzbz'] = $formData['pruefungstyp_kurzbz']; + $_POST['akadgrad_id']= $formData['akadgrad_id']; + $_POST['vorsitz'] = isset($formData['vorsitz']['mitarbeiter_uid']) ? $formData['vorsitz']['mitarbeiter_uid'] : $formData['vorsitz']; + $_POST['pruefer1'] = isset($formData['pruefer1']['person_id']) ? $formData['pruefer1']['person_id'] : $formData['pruefer1']; + $_POST['pruefer2'] = isset($formData['pruefer2']['person_id']) ? $formData['pruefer2']['person_id'] : $formData['pruefer2']; + $_POST['pruefer3'] = isset($formData['pruefer3']['person_id']) ? $formData['pruefer3']['person_id'] : $formData['pruefer3']; + $_POST['pruefungsantritt_kurzbz'] = $formData['pruefungsantritt_kurzbz']; + $_POST['abschlussbeurteilung_kurzbz'] = $formData['abschlussbeurteilung_kurzbz']; + $_POST['datum']= $formData['datum']; + $_POST['sponsion']= $formData['sponsion']; + $_POST['anmerkung'] = $formData['anmerkung']; + $_POST['protokoll']= $formData['protokoll']; + $_POST['note'] = $formData['note']; + + $this->form_validation->set_rules('pruefungstyp_kurzbz', 'Typ', 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Typ']) + ]); + + $this->form_validation->set_rules('akadgrad_id', 'AkadGrad', 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'AkadGrad']) + ]); + + $this->form_validation->set_rules('datum', 'Datum', 'is_valid_date', [ + 'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'Datum']) + ]); + + $this->form_validation->set_rules('sponsion', 'Sponsion', 'is_valid_date', [ + 'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'Sponsion']) + ]); + + if ($this->form_validation->run() == false) + { + $this->terminateWithValidationErrors($this->form_validation->error_array()); + } + + $result = $this->AbschlusspruefungModel->insert([ + 'student_uid' => $student_uid, + 'pruefungstyp_kurzbz' => $this->input->post('pruefungstyp_kurzbz'), + 'akadgrad_id' => $this->input->post('akadgrad_id'), + 'vorsitz' => $this->input->post('vorsitz'), + 'pruefungsantritt_kurzbz' => $this->input->post('pruefungsantritt_kurzbz'), + 'abschlussbeurteilung_kurzbz' => $this->input->post('abschlussbeurteilung_kurzbz'), + 'datum' => $this->input->post('datum'), //TODO(Manu) check if minute format like FAS + 'sponsion' => $this->input->post('sponsion'), + 'pruefer1' => $this->input->post('pruefer1'), + 'pruefer2' => $this->input->post('pruefer2'), + 'pruefer3' => $this->input->post('pruefer3'), + 'protokoll' => $this->input->post('protokoll'), + 'note' => $this->input->post('note'), + 'anmerkung' => $this->input->post('anmerkung'), + 'insertamum' => date('c'), + 'insertvon' => getAuthUID() + ]); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function updateAbschlusspruefung() + { + $this->load->library('form_validation'); + + $abschlusspruefung_id = $this->input->post('id'); + + if(!$abschlusspruefung_id) + { + return $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Abschlussprüfung ID']), self::ERROR_TYPE_GENERAL); + } + + $formData = $this->input->post('formData'); + $_POST['student_uid'] = $formData['student_uid']; + $_POST['pruefungstyp_kurzbz'] = $formData['pruefungstyp_kurzbz']; + $_POST['akadgrad_id']= $formData['akadgrad_id']; + $_POST['vorsitz'] = isset($formData['vorsitz']['mitarbeiter_uid']) ? $formData['vorsitz']['mitarbeiter_uid'] : $formData['vorsitz']; + $_POST['pruefer1'] = isset($formData['pruefer1']['person_id']) ? $formData['pruefer1']['person_id'] : $formData['pruefer1']; + $_POST['pruefer2'] = isset($formData['pruefer2']['person_id']) ? $formData['pruefer2']['person_id'] : $formData['pruefer2']; + $_POST['pruefer3'] = isset($formData['pruefer3']['person_id']) ? $formData['pruefer3']['person_id'] : $formData['pruefer3']; + $_POST['pruefungsantritt_kurzbz'] = $formData['pruefungsantritt_kurzbz']; + $_POST['abschlussbeurteilung_kurzbz'] = $formData['abschlussbeurteilung_kurzbz']; + $_POST['datum']= $formData['datum']; + $_POST['sponsion']= $formData['sponsion']; + $_POST['anmerkung'] = $formData['anmerkung']; + $_POST['protokoll']= $formData['protokoll']; + $_POST['note'] = $formData['note']; + + $this->form_validation->set_rules('pruefungstyp_kurzbz', 'Typ', 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Typ']) + ]); + + $this->form_validation->set_rules('akadgrad_id', 'AkadGrad', 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'AkadGrad']) + ]); + + $this->form_validation->set_rules('datum', 'Datum', 'is_valid_date', [ + 'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'Datum']) + ]); + + $this->form_validation->set_rules('sponsion', 'Sponsion', 'is_valid_date', [ + 'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'Sponsion']) + ]); + + + if ($this->form_validation->run() == false) + { + $this->terminateWithValidationErrors($this->form_validation->error_array()); + } + + $result = $this->AbschlusspruefungModel->update( + [ + 'abschlusspruefung_id' => $abschlusspruefung_id + ], + [ + 'student_uid' => $this->input->post('student_uid'), + 'pruefungstyp_kurzbz' => $this->input->post('pruefungstyp_kurzbz'), + 'akadgrad_id' => $this->input->post('akadgrad_id'), + 'vorsitz' => $this->input->post('vorsitz'), + 'pruefungsantritt_kurzbz' => $this->input->post('pruefungsantritt_kurzbz'), + 'abschlussbeurteilung_kurzbz' => $this->input->post('abschlussbeurteilung_kurzbz'), + 'datum' => $this->input->post('datum'), + 'sponsion' => $this->input->post('sponsion'), + 'pruefer1' => $this->input->post('pruefer1'), + 'pruefer2' => $this->input->post('pruefer2'), + 'pruefer3' => $this->input->post('pruefer3'), + 'protokoll' => $this->input->post('protokoll'), + 'note' => $this->input->post('note'), + 'anmerkung' => $this->input->post('anmerkung'), + 'insertamum' => date('c'), + 'insertvon' => getAuthUID() + ] + ); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function deleteAbschlusspruefung() + { + $abschlusspruefung_id = $this->input->post('id'); + + $result = $this->AbschlusspruefungModel->delete( + array('abschlusspruefung_id' => $abschlusspruefung_id) + ); + + if (isError($result)) + { + return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); + } + if (!hasData($result)) + { + $this->outputJson($result); + } + return $this->terminateWithSuccess(current(getData($result)) ? : null); + } + + public function checkForExistingExams() + { + $warning = false; + $output = []; + + $student_uids = $this->input->post('uids'); + + if (empty($student_uids)) { + throw new InvalidArgumentException("Keine UID(s) übergeben."); + } + + if( !is_array($student_uids) ) + { + $student_uids = array($student_uids); + } + + foreach ($student_uids as $uid) + { + $result = $this->AbschlusspruefungModel->loadWhere( + array('student_uid' => $uid) + ); + if (isError($result)) { + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + if (!hasData($result)) + { + $warning = true; + $output[] = $uid; + } + } + if($warning) + { + $uids = is_array($output) ? implode(", ", $output) : $output; + return $this->terminateWithError($this->p->t('abschlusspruefung', 'error_studentOhneFinalExam', ['id'=> $uids]), self::ERROR_TYPE_GENERAL); + } + $this->terminateWithSuccess('step3'); + } +} diff --git a/application/controllers/api/frontend/v1/stv/Address.php b/application/controllers/api/frontend/v1/stv/Address.php index 7685fcd04..324e306f3 100644 --- a/application/controllers/api/frontend/v1/stv/Address.php +++ b/application/controllers/api/frontend/v1/stv/Address.php @@ -45,7 +45,7 @@ class Address extends FHCAPI_Controller $this->terminateWithSuccess($data); } - public function getPlaces($plz) + public function getPlaces($plz = null) { $this->load->model('codex/Gemeinde_model', 'GemeindeModel'); @@ -53,7 +53,7 @@ class Address extends FHCAPI_Controller $this->form_validation->set_data(['address.plz' => $plz]); - $this->form_validation->set_rules('address.plz', 'PLZ', 'numeric|less_than[10000]'); + $this->form_validation->set_rules('address.plz', 'PLZ', 'required|numeric|less_than[10000]'); if (!$this->form_validation->run()) $this->terminateWithValidationErrors($this->form_validation->error_array()); diff --git a/application/controllers/api/frontend/v1/stv/Config.php b/application/controllers/api/frontend/v1/stv/Config.php index c28c49485..42de1b02f 100644 --- a/application/controllers/api/frontend/v1/stv/Config.php +++ b/application/controllers/api/frontend/v1/stv/Config.php @@ -44,16 +44,23 @@ class Config extends FHCAPI_Controller 'person', 'lehre', 'stv', - 'konto' + 'konto', + 'abschlusspruefung' ]); + + // Load Config + $this->load->config('stv'); } public function student() { $result = []; + $config = $this->config->item('tabs'); + $result['details'] = [ 'title' => $this->p->t('stv', 'tab_details'), - 'component' => './Stv/Studentenverwaltung/Details/Details.js' + 'component' => './Stv/Studentenverwaltung/Details/Details.js', + 'config' => $config['details'] ]; $result['notes'] = [ 'title' => $this->p->t('stv', 'tab_notes'), @@ -69,7 +76,8 @@ class Config extends FHCAPI_Controller ]; $result['prestudent'] = [ 'title' => $this->p->t('stv', 'tab_prestudent'), - 'component' => './Stv/Studentenverwaltung/Details/Prestudent.js' + 'component' => './Stv/Studentenverwaltung/Details/Prestudent.js', + 'config' => $config['prestudent'] ]; $result['status'] = [ 'title' => 'Status', @@ -91,12 +99,34 @@ class Config extends FHCAPI_Controller 'title' => $this->p->t('stv', 'tab_resources'), 'component' => './Stv/Studentenverwaltung/Details/Betriebsmittel.js' ]; - /* TODO(chris): Ausgeblendet für Testing $result['grades'] = [ 'title' => $this->p->t('stv', 'tab_grades'), - 'component' => './Stv/Studentenverwaltung/Details/Noten.js' + 'component' => './Stv/Studentenverwaltung/Details/Noten.js', + 'showOnlyWithUid' => true, + 'config' => [ + 'usePoints' => defined('CIS_GESAMTNOTE_PUNKTE') && CIS_GESAMTNOTE_PUNKTE, + 'edit' => 'both', // Possible values: both|header|inline + 'delete' => 'both', // Possible values: both|header|inline + 'documents' => 'both', // Possible values: both|header|inline + 'documentslist' => $this->gradesDocumentsList() + ] + ]; + + $result['exam'] = [ + 'title' => $this->p->t('stv', 'tab_exam'), + 'component' => './Stv/Studentenverwaltung/Details/Pruefung.js' + ]; + + $result['finalexam'] = [ + 'title' => $this->p->t('stv', 'tab_finalexam'), + 'component' => './Stv/Studentenverwaltung/Details/Abschlusspruefung.js', + 'config' => $config['finalexam'] + ]; + + $result['mobility'] = [ + 'title' => $this->p->t('stv', 'tab_mobility'), + 'component' => './Stv/Studentenverwaltung/Details/Mobility.js' ]; - */ Events::trigger('stv_conf_student', function & () use (&$result) { return $result; @@ -108,6 +138,7 @@ class Config extends FHCAPI_Controller public function students() { $result = []; + $config = $this->config->item('tabs'); $result['banking'] = [ 'title' => $this->p->t('stv', 'tab_banking'), 'component' => './Stv/Studentenverwaltung/Details/Konto.js', @@ -131,6 +162,11 @@ class Config extends FHCAPI_Controller 'changeStatusToAbsolvent' => $this->permissionlib->isBerechtigt('admin') ] ]; + $result['finalexam'] = [ + 'title' => $this->p->t('stv', 'tab_finalexam'), + 'component' => './Stv/Studentenverwaltung/Details/Abschlusspruefung.js', + 'config' => $config['finalexam'] + ]; Events::trigger('stv_conf_students', function & () use (&$result) { return $result; @@ -230,4 +266,186 @@ class Config extends FHCAPI_Controller ] ] + $this->kontoColumns(); } + + /** + * Helper function to generate the default documentslist config for the + * grades tab. + * + * The resulting array consists of elements which are associative arrays + * that can have the following entries: + * title (required) on the first level this can be HTML code. + * permissioncheck (optional) an URL to an FHCAPI endpoint which returns + * true or false. + * link (optional) an URL that will be called if "action" and + * "children" are not defined. + * action (optional) an associative array that describes an + * POST action that will be called if "children" is + * not defined. + * It can have the following entries: + * - url (required) an URL to an FHCAPI endpoint. + * - post (optional) an associative array with the POST data to + * be sent. + * - response (optional) a string that will be displayed on success. + * children (optional) an array of child elements + * + * All strings that start with { and end with } in the URLs and the + * actions post parameter will be replaced with the corresponding + * attribute of the current dataset (e.G: {uid} will be replaced with the + * uid of the current dataset) + * + * @return array + */ + protected function gradesDocumentsList() + { + $permissioncheck = site_url("api/frontend/v1/documents/permissionAlternativeFormat/{studiengang_kz}"); + + $title_ger = $this->p->t("global", "deutsch"); + $title_eng = $this->p->t("global", "englisch"); + $title_ff = $this->p->t("stv", "document_certificate"); + $title_lv = $this->p->t("stv", "document_coursecertificate"); + + $link_ff = "documents/export/" . + "zertifikat.rdf.php/" . + "Zertifikat" . + "?stg_kz={studiengang_kz_lv}" . + "&uid={uid}" . + "&ss={studiensemester_kurzbz}" . + "&lvid={lehrveranstaltung_id}"; + $link_lv_ger = "documents/export/" . + "lehrveranstaltungszeugnis.rdf.php/" . + "LVZeugnis" . + "?stg_kz={studiengang_kz}" . + "&uid={uid}" . + "&ss={studiensemester_kurzbz}" . + "&lvid={lehrveranstaltung_id}"; + $link_lv_eng = "documents/export/" . + "lehrveranstaltungszeugnis.rdf.php/" . + "LVZeugnisEng" . + "?stg_kz={studiengang_kz}" . + "&uid={uid}" . + "&ss={studiensemester_kurzbz}" . + "&lvid={lehrveranstaltung_id}"; + + $archive_url = "api/frontend/v1/documents/archiveSigned"; + $archive_response = $this->p->t("stv", "document_signed_and_archived"); + $archive_post_ff = [ + "xml" => "zertifikat.rdf.php", + "xsl" => "Zertifikat", + "stg_kz" => "{studiengang_kz_lv}", + "uid" => "{uid}", + "ss" => "{studiensemester_kurzbz}", + "lvid" => "{lehrveranstaltung_id}" + ]; + $archive_post_lv_ger = [ + "xml" => "lehrveranstaltungszeugnis.rdf.php", + "xsl" => "LVZeugnis", + "stg_kz" => "{studiengang_kz}", + "uid" => "{uid}", + "ss" => "{studiensemester_kurzbz}", + "lvid" => "{lehrveranstaltung_id}" + ]; + $archive_post_lv_eng = [ + "xml" => "lehrveranstaltungszeugnis.rdf.php", + "xsl" => "LVZeugnisEng", + "stg_kz" => "{studiengang_kz}", + "uid" => "{uid}", + "ss" => "{studiensemester_kurzbz}", + "lvid" => "{lehrveranstaltung_id}" + ]; + + $list = [ + [ + 'title' => '', + 'children' => [ + [ + 'title' => $title_ff, + 'link' => site_url($link_ff) + ], + [ + 'title' => $title_lv, + 'children' => [ + [ + 'title' => $title_ger, + 'link' => site_url($link_lv_ger), + 'children' => [ + [ + 'title' => 'PDF', + 'permissioncheck' => $permissioncheck, + 'link' => site_url($link_lv_ger) + ], + [ + 'title' => 'DOC', + 'permissioncheck' => $permissioncheck, + 'link' => site_url($link_lv_ger . "&output=doc") + ], + [ + 'title' => 'ODT', + 'permissioncheck' => $permissioncheck, + 'link' => site_url($link_lv_ger . "&output=odt") + ] + ] + ], + [ + 'title' => $title_eng, + 'link' => site_url($link_lv_eng), + 'children' => [ + [ + 'title' => 'PDF', + 'permissioncheck' => $permissioncheck, + 'link' => site_url($link_lv_eng) + ], + [ + 'title' => 'DOC', + 'permissioncheck' => $permissioncheck, + 'link' => site_url($link_lv_eng . "&output=doc") + ], + [ + 'title' => 'ODT', + 'permissioncheck' => $permissioncheck, + 'link' => site_url($link_lv_eng . "&output=odt") + ] + ] + ] + ] + ] + ] + ], + [ + 'title' => '', + 'children' => [ + [ + 'title' => $title_ff, + 'action' => [ + 'url' => site_url($archive_url), + 'post' => $archive_post_ff, + 'response' => $archive_response + ] + ], + [ + 'title' => $title_lv, + 'children' => [ + [ + 'title' => $title_ger, + 'action' => [ + 'url' => site_url($archive_url), + 'post' => $archive_post_lv_ger, + 'response' => $archive_response + ] + ], + [ + 'title' => $title_eng, + 'action' => [ + 'url' => site_url($archive_url), + 'post' => $archive_post_lv_eng, + 'response' => $archive_response + ] + ] + ] + ] + ] + ] + ]; + + return $list; + } } diff --git a/application/controllers/api/frontend/v1/stv/Favorites.php b/application/controllers/api/frontend/v1/stv/Favorites.php index 8d7a6cd14..b8fe6f3d7 100644 --- a/application/controllers/api/frontend/v1/stv/Favorites.php +++ b/application/controllers/api/frontend/v1/stv/Favorites.php @@ -48,7 +48,7 @@ class Favorites extends FHCAPI_Controller if (!$data) $this->terminateWithSuccess(null); else - $this->terminateWithSuccess($data['stv_favorites']); + $this->terminateWithSuccess($data['stv_favorites'] ?? null); } public function set() diff --git a/application/controllers/api/frontend/v1/stv/Grades.php b/application/controllers/api/frontend/v1/stv/Grades.php new file mode 100644 index 000000000..61d797495 --- /dev/null +++ b/application/controllers/api/frontend/v1/stv/Grades.php @@ -0,0 +1,685 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +/** + * This controller operates between (interface) the JS (GUI) and the back-end + * Provides data to the ajax get calls about grades + * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON + */ +class Grades extends FHCAPI_Controller +{ + public function __construct() + { + parent::__construct([ + 'list' => 'student/noten:r', + 'getCertificate' => 'student/noten:r', + 'getTeacherProposal' => 'student/noten:r', + 'getRepeaterGrades' => 'student/noten:r', + 'updateCertificate' => ['admin:w', 'assistenz:w'], + 'deleteCertificate' => ['admin:w', 'assistenz:w'], + 'copyTeacherProposalToCertificate' => 'student/noten:w', + 'copyRepeaterGradeToCertificate' => 'student/noten:w', + 'getGradeFromPoints' => 'student/noten:r' + ]); + + // Load Libraries + $this->load->library('VariableLib', ['uid' => getAuthUID()]); + + // Load Phrases + $this->loadPhrases([ + 'stv', + 'person', + 'lehre' + ]); + } + + /** + * List all possible grades + * (Entries in lehre.tbl_note) + * + * @return void + */ + public function list() + { + $this->load->model('codex/Note_model', 'NoteModel'); + + $this->NoteModel->addOrder('note'); + + $result = $this->NoteModel->load(); + + $grades = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($grades); + } + + /** + * List grades for the certificate of a prestudent. + * (Entries in lehre.tbl_zeugnisnote) + * + * @param string $prestudent_id + * @param string|null $all (optional) If null only the current semesters grades will be loaded, otherwise all semesters grades will be loaded. + * + * @return void + */ + public function getCertificate($prestudent_id, $all = null) + { + $this->load->model('crm/Student_model', 'StudentModel'); + $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); + + $result = $this->StudentModel->loadWhere([ + 'prestudent_id' => $prestudent_id + ]); + + $student = $this->getDataOrTerminateWithError($result); + if (!$student) + $this->terminateWithSuccess([]); + + + $student_uid = current($student)->student_uid; + + $studiensemester_kurzbz = ($all === null) ? $this->variablelib->getVar('semester_aktuell') : null; + + + $result = $this->ZeugnisnoteModel->getZeugnisnoten($student_uid, $studiensemester_kurzbz); + + $grades = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($grades); + } + + /** + * List grades of a prestudent that teachers gave. + * (Entries in campus.tbl_lvgesamtnote) + * + * @param string $prestudent_id + * @param string|null $all (optional) If null only the current semesters grades will be loaded, otherwise all semesters grades will be loaded. + * + * @return void + */ + public function getTeacherProposal($prestudent_id, $all = null) + { + $this->load->model('crm/Student_model', 'StudentModel'); + $this->load->model('education/Lvgesamtnote_model', 'LvgesamtnoteModel'); + + $result = $this->StudentModel->loadWhere([ + 'prestudent_id' => $prestudent_id + ]); + + $student = $this->getDataOrTerminateWithError($result); + if (!$student) + $this->terminateWithSuccess([]); + + + $student_uid = current($student)->student_uid; + + $studiensemester_kurzbz = ($all === null) ? $this->variablelib->getVar('semester_aktuell') : null; + + + $result = $this->LvgesamtnoteModel->getLvGesamtNoten(null, $student_uid, $studiensemester_kurzbz); + + $grades = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($grades); + } + + /** + * List grades of a prestudent that an assistant marked as already done + * or as not allowed because of the repeating of a semester. + * + * @param string $prestudent_id + * @param string|null $all (optional) If null only the current semesters grades will be loaded, otherwise all semesters grades will be loaded. + * + * @return void + */ + public function getRepeaterGrades($prestudent_id, $all = null) + { + $this->load->library('AntragLib'); + + $studiensemester_kurzbz = ($all === null) ? $this->variablelib->getVar('semester_aktuell') : false; + + + $result = $this->antraglib->getLvsForPrestudent($prestudent_id, $studiensemester_kurzbz); + + $grades = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($grades); + } + + /** + * Update or Insert a grade for the certificate of a prestudent. + * (Entry in lehre.tbl_zeugnisnote) + * + * @return void + */ + public function updateCertificate() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules("lehrveranstaltung_id", $this->p->t('lehre', 'lehrveranstaltung'), "required|integer"); + $this->form_validation->set_rules("student_uid", $this->p->t('person', 'student'), "required"); + $this->form_validation->set_rules("studiensemester_kurzbz", $this->p->t('lehre', 'studiensemester'), "required"); + $this->form_validation->set_rules('note', $this->p->t('lehre', 'note'), 'required|numeric'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + + $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); + $student_uid = $this->input->post('student_uid'); + $lehrveranstaltung_id = $this->input->post('lehrveranstaltung_id'); + $note = $this->input->post('note'); + $authUID = getAuthUID(); + $now = date('c'); + + // NOTE(chris): Stg Permissions + if (!$this->hasPermissionUpdate($lehrveranstaltung_id, $student_uid)) + return $this->_outputAuthError([$this->router->method => ['admin', 'assistenz']]); + + $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); + + $result = $this->ZeugnisnoteModel->load([ + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'student_uid' => $student_uid, + 'lehrveranstaltung_id' => $lehrveranstaltung_id + ]); + $current = $this->getDataOrTerminateWithError($result); + + if ($current) { + $result = $this->ZeugnisnoteModel->update([ + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'student_uid' => $student_uid, + 'lehrveranstaltung_id' => $lehrveranstaltung_id + ], [ + 'note' => $note, + 'benotungsdatum' => $now, + 'updateamum' => $now, + 'updatevon' => $authUID + ]); + } else { + $result = $this->ZeugnisnoteModel->insert([ + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'student_uid' => $student_uid, + 'lehrveranstaltung_id' => $lehrveranstaltung_id, + 'note' => $note, + 'benotungsdatum' => $now, + 'insertamum' => $now, + 'insertvon' => $authUID + ]); + } + $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess(true); + } + + /** + * Delete a grade from the certificate of a prestudent. + * (Entry in lehre.tbl_zeugnisnote) + * + * @return void + */ + public function deleteCertificate() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules("lehrveranstaltung_id", $this->p->t('lehre', 'lehrveranstaltung'), "required|integer"); + $this->form_validation->set_rules("student_uid", $this->p->t('person', 'student'), "required"); + $this->form_validation->set_rules("studiensemester_kurzbz", $this->p->t('lehre', 'studiensemester'), "required"); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + + $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); + $student_uid = $this->input->post('student_uid'); + $lehrveranstaltung_id = $this->input->post('lehrveranstaltung_id'); + + // NOTE(chris): Stg Permissions + if (!$this->hasPermissionDelete($lehrveranstaltung_id, $student_uid)) + return $this->_outputAuthError([$this->router->method => ['admin', 'assistenz']]); + + $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); + + $result = $this->ZeugnisnoteModel->delete([ + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'student_uid' => $student_uid, + 'lehrveranstaltung_id' => $lehrveranstaltung_id + ]); + $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess(true); + } + + /** + * Copy a grade that teachers gave to the certificate of a prestudent. + * (Entry in campus.tbl_lvgesamtnote to an entry in lehre.tbl_zeugnisnote) + * + * @return void + */ + public function copyTeacherProposalToCertificate() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules("lehrveranstaltung_id", $this->p->t('lehre', 'lehrveranstaltung'), "required|integer"); + $this->form_validation->set_rules("student_uid", $this->p->t('person', 'student'), "required"); + $this->form_validation->set_rules("studiensemester_kurzbz", $this->p->t('lehre', 'studiensemester'), "required"); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $lehrveranstaltung_id = $this->input->post('lehrveranstaltung_id'); + $student_uid = $this->input->post('student_uid'); + $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); + $authUID = getAuthUID(); + + // NOTE(chris): Stg Permissions + if (!$this->hasPermissionCopy($lehrveranstaltung_id, $student_uid)) + return $this->_outputAuthError([$this->router->method => 'student/noten']); + + $this->load->model('education/Lvgesamtnote_model', 'LvgesamtnoteModel'); + + $result = $this->LvgesamtnoteModel->load([ + 'student_uid' => $student_uid, + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'lehrveranstaltung_id' => $lehrveranstaltung_id + ]); + $teacherGrade = $this->getDataOrTerminateWithError($result); + + if (!$teacherGrade) + show_404(); + + $teacherGrade = current($teacherGrade); + + $data = [ + 'note' => $teacherGrade->note, + 'punkte' => $teacherGrade->punkte, + 'uebernahmedatum' => date('c'), + 'benotungsdatum' => $teacherGrade->benotungsdatum, + 'bemerkung' => $teacherGrade->bemerkung + ]; + + $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); + + $this->ZeugnisnoteModel->addJoin('lehre.tbl_note n', 'note'); + $result = $this->ZeugnisnoteModel->load([ + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'student_uid' => $student_uid, + 'lehrveranstaltung_id' => $lehrveranstaltung_id + ]); + $certificateGrade = $this->getDataOrTerminateWithError($result); + + if ($certificateGrade) { + $certificateGrade = current($certificateGrade); + + if (!$certificateGrade->lkt_ueberschreibbar) + $this->terminateWithError($this->p->t("stv", "grades_error_overwrite")); + + // NOTE(chris): update + $data['updateamum'] = $data['uebernahmedatum']; + $data['updatevon'] = $authUID; + + $this->ZeugnisnoteModel->update([ + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'student_uid' => $student_uid, + 'lehrveranstaltung_id' => $lehrveranstaltung_id + ], $data); + } else { + // NOTE(chris): insert + $data['insertamum'] = $data['uebernahmedatum']; + $data['insertvon'] = $authUID; + $data['lehrveranstaltung_id'] = $lehrveranstaltung_id; + $data['student_uid'] = $student_uid; + $data['studiensemester_kurzbz'] = $studiensemester_kurzbz; + + $this->ZeugnisnoteModel->insert($data); + + if (defined('FAS_PRUEFUNG_BEI_NOTENEINGABE_ANLEGEN') + && FAS_PRUEFUNG_BEI_NOTENEINGABE_ANLEGEN) { + $result = $this->addTestsForGrade( + $studiensemester_kurzbz, + $student_uid, + $lehrveranstaltung_id, + $teacherGrade->note, + $teacherGrade->punkte + ); + $this->getDataOrTerminateWithError($result); + } + } + + + $this->terminateWithSuccess(true); + } + + /** + * Copy a grade that was marked by an assistant as already done or not + * allowed because of the repeating of a semester to the certificate of a + * prestudent. + * + * @return void + */ + public function copyRepeaterGradeToCertificate() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules("studierendenantrag_lehrveranstaltung_id", "studierendenantrag_lehrveranstaltung_id", "required|integer"); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $id = $this->input->post('studierendenantrag_lehrveranstaltung_id'); + $authUID = getAuthUID(); + + $this->load->model('education/Studierendenantraglehrveranstaltung_model', 'StudierendenantraglehrveranstaltungModel'); + + $this->StudierendenantraglehrveranstaltungModel->addSelect("tbl_studierendenantrag_lehrveranstaltung.*"); + $this->StudierendenantraglehrveranstaltungModel->addSelect("student_uid"); + $this->StudierendenantraglehrveranstaltungModel->addJoin("campus.tbl_studierendenantrag", "studierendenantrag_id"); + $this->StudierendenantraglehrveranstaltungModel->addJoin("public.tbl_student", "prestudent_id", "LEFT"); + + $result = $this->StudierendenantraglehrveranstaltungModel->load($id); + $repeaterGrade = $this->getDataOrTerminateWithError($result); + + if (!$repeaterGrade) + show_404(); + + $repeaterGrade = current($repeaterGrade); + + // NOTE(chris): Stg Permissions + if (!$this->hasPermissionCopy($repeaterGrade->lehrveranstaltung_id, $repeaterGrade->student_uid)) + return $this->_outputAuthError([$this->router->method => 'student/noten']); + + $data = [ + 'note' => $repeaterGrade->note, + 'uebernahmedatum' => date('c'), + 'benotungsdatum' => $repeaterGrade->insertamum, + 'bemerkung' => $repeaterGrade->anmerkung + ]; + + $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); + + $result = $this->ZeugnisnoteModel->load([ + $repeaterGrade->studiensemester_kurzbz, + $repeaterGrade->student_uid, + $repeaterGrade->lehrveranstaltung_id + ]); + $certificateGrade = $this->getDataOrTerminateWithError($result); + + if ($certificateGrade) { + // NOTE(chris): update + $data['updateamum'] = $data['uebernahmedatum']; + $data['updatevon'] = $authUID; + + $this->ZeugnisnoteModel->update([ + $repeaterGrade->studiensemester_kurzbz, + $repeaterGrade->student_uid, + $repeaterGrade->lehrveranstaltung_id + ], $data); + } else { + // NOTE(chris): insert + $data['insertamum'] = $data['uebernahmedatum']; + $data['insertvon'] = $authUID; + $data['lehrveranstaltung_id'] = $repeaterGrade->lehrveranstaltung_id; + $data['student_uid'] = $repeaterGrade->student_uid; + $data['studiensemester_kurzbz'] = $repeaterGrade->studiensemester_kurzbz; + + $this->ZeugnisnoteModel->insert($data); + } + + + $this->terminateWithSuccess(true); + } + + /** + * Loads the grade from the points using the gradingkey + * + * @return void + */ + public function getGradeFromPoints() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules("lehrveranstaltung_id", $this->p->t('lehre', 'lehrveranstaltung'), "required|integer"); + $this->form_validation->set_rules("points", $this->p->t("stv", "grades_points"), "required|numeric"); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $this->load->model('education/Notenschluesselaufteilung_model', 'NotenschluesselaufteilungModel'); + + $studiensemester_kurzbz = $this->variablelib->getVar('semester_aktuell'); + + $result = $this->NotenschluesselaufteilungModel->getNote( + $this->input->post('points'), + $this->input->post('lehrveranstaltung_id'), + $studiensemester_kurzbz + ); + + $note = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($note); + } + + /** + * Helper function that adds tests for a student + * (Entries in lehre.tbl_pruefung) + * + * @param string $studiensemester_kurzbz + * @param string $student_uid + * @param integer $lehrveranstaltung_id + * @param integer $note + * @param numeric $punkte + * + * @return stdClass + */ + protected function addTestsForGrade($studiensemester_kurzbz, $student_uid, $lehrveranstaltung_id, $note, $punkte) + { + $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); + + // Get Lehreinheit + $result = $this->LehrveranstaltungModel->getLeByStudent($student_uid, $studiensemester_kurzbz, $lehrveranstaltung_id); + + if (isError($result)) + return $result; + if (!hasData($result)) + return error($this->p->t("stv", "grades_error_lehreinheit_id")); + $le = current(getData($result)); + + // Prepare + $this->load->model('education/LePruefung_model', 'LePruefungModel'); + $data = [ + "student_uid" => $student_uid, + "lehreinheit_id" => $le->lehreinheit_id, + "datum" => date('Y-m-d'), + "pruefungstyp_kurzbz" => "Termin1", + "note" => $note + ]; + + if (defined('CIS_GESAMTNOTE_PUNKTE') && CIS_GESAMTNOTE_PUNKTE) + $data["punkte"] = $punkte; + + // Get Anwesenheit + $this->load->model('education/Anwesenheit_model', 'AnwesenheitModel'); + $result = $this->AnwesenheitModel->loadAnwesenheitStudiensemester($studiensemester_kurzbz, $student_uid, $lehrveranstaltung_id); + if (isError($result)) + return $result; + $anwesenheit = getData($result); + + if ($anwesenheit && (float)current($anwesenheit)->prozent < FAS_ANWESENHEIT_ROT) { + // Get Anwesenheitsbefreiung + $this->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel'); + $result = $this->BenutzerfunktionModel->getBenutzerFunktionByUidInStdsem($student_uid, $studiensemester_kurzbz, 'awbefreit'); + + if (isError($result)) + return $result; + + $anwesenheitsbefreit = hasData($result); + + // Wenn nicht Anwesenheitsbefreit und Anwesenheit unter einem bestimmten Prozentsatz fällt dann wird ein Pruefungsantritt abgezogen + if (!$anwesenheitsbefreit) { + $data2 = $data; + $data2["note"] = 7; + if (isset($data2["punkte"])) + unset($data2["punkte"]); + + $result = $this->LePruefungModel->insert($data2); + + if (isError($result)) + return $result; + + $data["pruefungstyp_kurzbz"] = "Termin2"; + } + } + + return $this->LePruefungModel->insert($data); + } + + /** + * Helper function to check permissions for updateCertificate() + * + * @param integer $lehrveranstaltung_id + * @param string $student_uid + * + * @return boolean + */ + protected function hasPermissionUpdate($lehrveranstaltung_id, $student_uid) + { + if ($lehrveranstaltung_id === null || $student_uid === null) + return true; + + $this->load->model('crm/Student_model', 'StudentModel'); + + $result = $this->StudentModel->load([$student_uid]); + if (isError($result) || !hasData($result)) + return false; + + $student = current(getData($result)); + + if ($this->permissionlib->isBerechtigt('admin', 'suid', $student->studiengang_kz)) + return true; + if ($this->permissionlib->isBerechtigt('assistenz', 'suid', $student->studiengang_kz)) + return true; + + $this->load->model('organisation/Studienplan_model', 'StudienplanModel'); + + $result = $this->StudienplanModel->getAllOesForLv($lehrveranstaltung_id); + if (isError($result)) + return false; + + $oes = getData($result) ?: []; + + $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); + + $result = $this->LehrveranstaltungModel->getStg($lehrveranstaltung_id); + if (isError($result)) + return false; + + if (hasData($result)) + $oes[] = current(getData($result)); + + foreach ($oes as $oe) { + if ($this->permissionlib->isBerechtigt('admin', 'suid', $oe->oe_kurzbz)) + return true; + if ($this->permissionlib->isBerechtigt('assistenz', 'suid', $oe->oe_kurzbz)) + return true; + } + + return false; + } + + /** + * Helper function to check permissions for deleteCertificate() + * + * @param integer $lehrveranstaltung_id + * @param string $student_uid + * + * @return boolean + */ + protected function hasPermissionDelete($lehrveranstaltung_id, $student_uid) + { + if ($lehrveranstaltung_id === null || $student_uid === null) + return true; + + $this->load->model('crm/Student_model', 'StudentModel'); + + $result = $this->StudentModel->load([$student_uid]); + if (isError($result) || !hasData($result)) + return false; + + $student = current(getData($result)); + + if ($this->permissionlib->isBerechtigt('admin', 'suid', $student->studiengang_kz)) + return true; + if ($this->permissionlib->isBerechtigt('assistenz', 'suid', $student->studiengang_kz)) + return true; + + $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); + + $result = $this->LehrveranstaltungModel->load($lehrveranstaltung_id); + if (isError($result) || !hasData($result)) + return false; + + $oe = current(getData($result)); + + if ($this->permissionlib->isBerechtigt('admin', 'suid', $oe->oe_kurzbz)) + return true; + if ($this->permissionlib->isBerechtigt('assistenz', 'suid', $oe->oe_kurzbz)) + return true; + + return false; + } + + /** + * Helper function to check permissions for + * copyTeacherProposalToCertificate() and copyRepeaterGradeToCertificate() + * + * @param integer $lehrveranstaltung_id + * @param string $student_uid + * + * @return boolean + */ + protected function hasPermissionCopy($lehrveranstaltung_id, $student_uid) + { + if ($lehrveranstaltung_id === null || $student_uid === null) + return true; + + $this->load->model('crm/Student_model', 'StudentModel'); + + $result = $this->StudentModel->load([$student_uid]); + if (isError($result) || !hasData($result)) + return false; + + $student = current(getData($result)); + + if ($this->permissionlib->isBerechtigt('student/noten', 'suid', $student->studiengang_kz)) + return true; + + $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); + + $result = $this->LehrveranstaltungModel->load($lehrveranstaltung_id); + if (isError($result) || !hasData($result)) + return false; + + $oe = current(getData($result)); + + if ($this->permissionlib->isBerechtigt('student/noten', 'suid', $oe->oe_kurzbz)) + return true; + + return false; + } +} diff --git a/application/controllers/api/frontend/v1/stv/Kontakt.php b/application/controllers/api/frontend/v1/stv/Kontakt.php index 379184ee0..fd16fff06 100644 --- a/application/controllers/api/frontend/v1/stv/Kontakt.php +++ b/application/controllers/api/frontend/v1/stv/Kontakt.php @@ -97,7 +97,14 @@ class Kontakt extends FHCAPI_Controller || $this->router->method == 'deleteContact' || $this->router->method == 'deleteBankverbindung' ) { - $id = current(array_slice($this->uri->rsegments, 2)); + if($this->input->post('address_id')) + $id = $this->input->post('address_id'); + if($this->input->post('adresse_id')) + $id = $this->input->post('adresse_id'); + if($this->input->post('bankverbindung_id')) + $id = $this->input->post('bankverbindung_id'); + if($this->input->post('kontakt_id')) + $id = $this->input->post('kontakt_id'); $model = 'person/Adresse_model'; if ($this->router->method == 'loadContact' @@ -125,7 +132,12 @@ class Kontakt extends FHCAPI_Controller } public function getAdressen($person_id) { - $this->AdresseModel->addSelect('public.tbl_adresse.*'); + $this->AdresseModel->addSelect("public.tbl_adresse.*, + (CASE + WHEN public.tbl_adresse.updateamum >= public.tbl_adresse.insertamum + THEN public.tbl_adresse.updateamum + ELSE public.tbl_adresse.insertamum + END) AS lastUpdate"); $this->AdresseModel->addSelect('t.*'); $this->AdresseModel->addSelect('f.firma_id'); $this->AdresseModel->addSelect('f.name as firmenname'); @@ -143,15 +155,26 @@ class Kontakt extends FHCAPI_Controller public function addNewAddress($person_id) { - $this->form_validation->set_rules('plz', 'PLZ', 'required|numeric', [ + $this->form_validation->set_data(['address.plz' => $_POST['plz']]); + + $this->form_validation->set_rules('address.plz', 'PLZ', 'required', [ 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'PLZ']), - 'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'PLZ']) ]); - if(isset($_POST['gemeinde']) && isset($_POST['ort'])) - $this->form_validation->set_rules('plz', 'Postleitzahl', 'callback_validateLocationCombination', [ - 'validateLocationCombination' => $this->p->t('ui', 'error_location_combination') - ]); + if(isset($_POST['nation']) && $_POST['nation'] == 'A') + { + $this->form_validation->set_rules('address.plz', 'PLZ', 'required|numeric', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'PLZ']), + 'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'PLZ']) + ]); + } + + if(isset($_POST['gemeinde']) && isset($_POST['ort']) && isset($_POST['nation']) && $_POST['nation'] == 'A') + { + $this->form_validation->set_rules('address.plz', 'Postleitzahl', 'callback_validateLocationCombination', [ + 'validateLocationCombination' => $this->p->t('ui', 'error_location_combination') + ]); + } if ($this->form_validation->run() == false) { @@ -196,25 +219,37 @@ class Kontakt extends FHCAPI_Controller ] ); - if (isError($result)) - { - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - return $this->outputJsonSuccess(true); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); } - public function updateAddress($address_id) + public function updateAddress() { + $address_id = $this->input->post('adresse_id'); + + $this->form_validation->set_data(['address.plz' => $_POST['plz']]); + $uid = getAuthUID(); - $this->form_validation->set_rules('plz', 'PLZ', 'required|numeric', [ + + $this->form_validation->set_rules('address.plz', 'PLZ', 'required', [ 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'PLZ']), - 'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'PLZ']) ]); - if(isset($_POST['gemeinde']) && isset($_POST['ort'])) - $this->form_validation->set_rules('plz', 'Postleitzahl', 'callback_validateLocationCombination', [ + if(isset($_POST['nation']) && $_POST['nation'] == 'A') + { + $this->form_validation->set_rules('address.plz', 'PLZ', 'required|numeric', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'PLZ']), + 'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'PLZ']) + ]); + } + + if(isset($_POST['gemeinde']) && isset($_POST['ort']) && isset($_POST['nation']) && $_POST['nation'] == 'A') + { + $this->form_validation->set_rules('address.plz', 'Postleitzahl', 'callback_validateLocationCombination', [ 'validateLocationCombination' => $this->p->t('ui', 'error_location_combination') ]); + } if ($this->form_validation->run() == false) { @@ -272,15 +307,15 @@ class Kontakt extends FHCAPI_Controller ] ); - if (isError($result)) - { - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - return $this->outputJsonSuccess(true); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); } - public function loadAddress($adresse_id) + public function loadAddress() { + $adresse_id = $this->input->post('address_id'); + $this->load->model('person/Adresse_model', 'AdresseModel'); $this->AdresseModel->addSelect('public.tbl_adresse.*'); @@ -306,8 +341,10 @@ class Kontakt extends FHCAPI_Controller $this->terminateWithSuccess(current(getData($result)) ? : null); } - public function deleteAddress($adresse_id) + public function deleteAddress() { + $adresse_id = $this->input->post('address_id'); + $this->load->model('person/Adresse_model', 'AdresseModel'); $result = $this->AdresseModel->load([ 'adresse_id'=> $adresse_id, @@ -366,10 +403,10 @@ class Kontakt extends FHCAPI_Controller $this->load->model('organisation/standort_model', 'StandortModel'); $result = $this->StandortModel->searchStandorte($searchString); - if (isError($result)) { - $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); - } - $this->terminateWithSuccess($result ?: []); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); } public function getStandorteByFirma($firma_id) @@ -386,11 +423,11 @@ class Kontakt extends FHCAPI_Controller public function getKontakte($person_id) { $this->KontaktModel->addSelect("public.tbl_kontakt.*, - TO_CHAR (CASE - WHEN public.tbl_kontakt.updateamum >= public.tbl_kontakt.insertamum - THEN public.tbl_kontakt.updateamum - ELSE public.tbl_kontakt.insertamum - END::timestamp, 'DD.MM.YYYY HH24:MI:SS') AS lastUpdate, st.bezeichnung, f.name"); + (CASE + WHEN public.tbl_kontakt.updateamum >= public.tbl_kontakt.insertamum + THEN public.tbl_kontakt.updateamum + ELSE public.tbl_kontakt.insertamum + END) AS lastUpdate, st.bezeichnung, f.name"); $this->StandortModel->addJoin('public.tbl_standort st', 'ON (public.tbl_kontakt.standort_id = st.standort_id)', 'LEFT'); $this->FirmaModel->addJoin('public.tbl_firma f', 'ON (f.firma_id = st.firma_id)', 'LEFT'); $result = $this->KontaktModel->loadWhere( @@ -418,8 +455,9 @@ class Kontakt extends FHCAPI_Controller } } - public function loadContact($kontakt_id) + public function loadContact() { + $kontakt_id = $this->input->post('kontakt_id'); $this->load->model('person/Kontakt_model', 'KontaktModel'); $this->KontaktModel->addSelect('*, public.tbl_kontakt.*'); @@ -439,7 +477,6 @@ class Kontakt extends FHCAPI_Controller { return $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Kontakt_id']), self::ERROR_TYPE_GENERAL); } - // $this->outputJsonSuccess(current(getData($result))); $this->terminateWithSuccess(current(getData($result))); } @@ -492,11 +529,12 @@ class Kontakt extends FHCAPI_Controller { return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); } - return $this->outputJsonSuccess(true); + $this->terminateWithSuccess($result); } - public function updateContact($kontakt_id) + public function updateContact() { + $kontakt_id = $this->input->post('kontakt_id'); $this->load->model('person/Kontakt_model', 'KontaktModel'); if(!$kontakt_id) @@ -523,13 +561,6 @@ class Kontakt extends FHCAPI_Controller $this->terminateWithValidationErrors($this->form_validation->error_array()); } -/* if(isset($_POST['standort'])) - { - $standort_id = $_POST['standort']['standort_id']; - } - else - $standort_id = null;*/ - $uid = getAuthUID(); $kontakttyp = $this->input->post('kontakttyp'); $anmerkung = $this->input->post('anmerkung'); @@ -538,8 +569,6 @@ class Kontakt extends FHCAPI_Controller $person_id = $this->input->post('person_id'); $standort_id = $this->input->post('standort_id'); - //return $this->terminateWithError("in update " . $standort_id, self::ERROR_TYPE_GENERAL); - $result = $this->KontaktModel->update( [ 'kontakt_id' => $kontakt_id @@ -557,15 +586,14 @@ class Kontakt extends FHCAPI_Controller ] ); - if (isError($result)) - { - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - return $this->outputJsonSuccess(true); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); } - public function deleteContact($kontakt_id) + public function deleteContact() { + $kontakt_id = $this->input->post('kontakt_id'); $this->load->model('person/Kontakt_model', 'KontaktModel'); $result = $this->KontaktModel->delete( @@ -643,15 +671,15 @@ class Kontakt extends FHCAPI_Controller 'orgform_kurzbz' => $orgform_kurzbz ] ); - if (isError($result)) - { - return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); - } - return $this->outputJsonSuccess(true); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); } - public function loadBankverbindung($bankverbindung_id) + public function loadBankverbindung() { + $bankverbindung_id = $this->input->post('bankverbindung_id'); + $this->load->model('person/Bankverbindung_model', 'BankverbindungModel'); $this->BankverbindungModel->addSelect('*'); @@ -719,15 +747,15 @@ class Kontakt extends FHCAPI_Controller ] ); - if (isError($result)) - { - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - return $this->outputJsonSuccess(true); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); } - public function deleteBankverbindung($bankverbindung_id) + public function deleteBankverbindung() { + $bankverbindung_id = $this->input->post('bankverbindung_id'); + $this->load->model('person/Bankverbindung_model', 'BankverbindungModel'); $result = $this->BankverbindungModel->delete( @@ -740,7 +768,7 @@ class Kontakt extends FHCAPI_Controller } if (!hasData($result)) { - $this->outputJson($result); + return $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Bankverbindung_id']), self::ERROR_TYPE_GENERAL); } return $this->terminateWithSuccess(current(getData($result)) ? : null); } diff --git a/application/controllers/api/frontend/v1/stv/Mobility.php b/application/controllers/api/frontend/v1/stv/Mobility.php new file mode 100644 index 000000000..2ab0ac682 --- /dev/null +++ b/application/controllers/api/frontend/v1/stv/Mobility.php @@ -0,0 +1,528 @@ + ['admin:r', 'assistenz:r'], + 'loadMobility' => ['admin:r', 'assistenz:r'], + 'insertMobility' => ['admin:rw', 'assistenz:rw'], + 'updateMobility' => ['admin:rw', 'assistenz:rw'], + 'deleteMobility' => ['admin:rw', 'assistenz:rw'], + 'getProgramsMobility' => ['admin:r', 'assistenz:r'], + 'getLVList' => ['admin:r', 'assistenz:r'], + 'getAllLehreinheiten' => ['admin:r', 'assistenz:r'], + 'getLvsandLesByStudent' => ['admin:r', 'assistenz:r'], + 'getPurposes' => ['admin:r', 'assistenz:r'], + 'getSupports' => ['admin:r', 'assistenz:r'], + 'getListPurposes' => ['admin:r', 'assistenz:r'], + 'getListSupports' => ['admin:r', 'assistenz:r'], + 'deleteMobilityPurpose' => ['admin:r', 'assistenz:r'], + 'addMobilityPurpose' => ['admin:r', 'assistenz:r'], + 'deleteMobilitySupport' => ['admin:r', 'assistenz:r'], + 'addMobilitySupport' => ['admin:r', 'assistenz:r'], + ]); + + // Load Libraries + $this->load->library('VariableLib', ['uid' => getAuthUID()]); + $this->load->library('form_validation'); + + // Load language phrases + $this->loadPhrases([ + 'ui', + 'mobility' + ]); + + // Load models + $this->load->model('codex/Bisio_model', 'BisioModel'); + } + + public function getMobilitaeten($student_uid) + { + $this->BisioModel->addSelect("*"); + $this->BisioModel->addJoin('bis.tbl_mobilitaetsprogramm mp', 'ON (mp.mobilitaetsprogramm_code = bis.tbl_bisio.mobilitaetsprogramm_code)', 'LEFT'); + $this->BisioModel->addJoin('lehre.tbl_lehreinheit le', 'ON (le.lehreinheit_id = bis.tbl_bisio.lehreinheit_id)','LEFT'); + $this->BisioModel->addOrder('von', 'DESC'); + $this->BisioModel->addOrder('bis', 'DESC'); + $this->BisioModel->addOrder('bisio_id', 'DESC'); + $result = $this->BisioModel->loadWhere( + array('student_uid' => $student_uid) + ); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getProgramsMobility() + { + $this->load->model('codex/Mobilitaetsprogramm_model', 'MobilitaetsprogrammModel'); + + $result = $this->MobilitaetsprogrammModel->load(); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function insertMobility() + { + $this->load->library('form_validation'); + $authUID = getAuthUID(); + + $student_uid = $this->input->post('uid'); + + if(!$student_uid) + { + return $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Student UID']), self::ERROR_TYPE_GENERAL); + } + + $formData = $this->input->post('formData'); + + $_POST['von'] = (isset($formData['von']) && !empty($formData['von'])) ? $formData['von'] : null; + $_POST['bis'] = (isset($formData['bis']) && !empty($formData['bis'])) ? $formData['bis'] : null; + $_POST['nation_code'] = (isset($formData['nation_code']) && !empty($formData['nation_code'])) ? $formData['nation_code'] : 'A'; + $_POST['mobilitaetsprogramm_code'] = (isset($formData['mobilitaetsprogramm_code']) && !empty($formData['mobilitaetsprogramm_code'])) ? $formData['mobilitaetsprogramm_code'] : null; + $_POST['herkunftsland_code'] = (isset($formData['herkunftsland_code']) && !empty($formData['herkunftsland_code'])) ? $formData['herkunftsland_code'] : 'A'; + $_POST['ects_erworben'] = (isset($formData['ects_erworben']) && !empty($formData['ects_erworben'])) ? $formData['ects_erworben'] : null; + $_POST['ects_angerechnet'] = (isset($formData['ects_angerechnet']) && !empty($formData['ects_angerechnet'])) ? $formData['ects_angerechnet'] : null; + $_POST['lehreinheit_id'] = (isset($formData['lehreinheit_id']) && !empty($formData['lehreinheit_id'])) ? $formData['lehreinheit_id'] : null; + + $this->form_validation->set_rules('nation_code', 'Nation_code', 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Nation_code']) + ]); + $this->form_validation->set_rules('herkunftsland_code', 'Herkunftsland_code', 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Herkunftsland_code']) + ]); + $this->form_validation->set_rules('mobilitaetsprogramm_code', 'Mobilitaetsprogramm_code', 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Mobilitaetsprogramm_code']) + ]); + $this->form_validation->set_rules('von', 'VonDatum', 'is_valid_date', [ + 'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'VonDatum']) + ]); + + $this->form_validation->set_rules('bis', 'VBisDatum', 'is_valid_date', [ + 'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'VBisDatum']) + ]); + + $this->form_validation->set_rules('ects_erworben', 'Ects_erworben', 'numeric', [ + 'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'Ects_erworben']) + ]); + + $this->form_validation->set_rules('ects_angerechnet', 'Ects_angerechnet', 'numeric', [ + 'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'Ects_angerechnet']) + ]); + + $this->form_validation->set_rules('lehreinheit_id', 'Lehreinheit', 'numeric', [ + 'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'Lehreinheit']) + ]); + + if ($this->form_validation->run() == false) + { + $this->terminateWithValidationErrors($this->form_validation->error_array()); + } + + $ort = (isset($formData['ort']) && !empty($formData['ort'])) ? $formData['ort'] : null; + $universitaet = (isset($formData['universitaet']) && !empty($formData['universitaet'])) ? $formData['universitaet'] : null; + $localPurposes = (isset($formData['localPurposes']) && !empty($formData['localPurposes'])) ? $formData['localPurposes'] : null; + $localSupports = (isset($formData['localSupports']) && !empty($formData['localSupports'])) ? $formData['localSupports'] : null; + + $result = $this->BisioModel->insert([ + 'student_uid' => $student_uid, + 'von' => $_POST['von'], + 'bis' => $_POST['bis'], + 'mobilitaetsprogramm_code' => $_POST['mobilitaetsprogramm_code'], + 'nation_code' => $_POST['nation_code'], + 'herkunftsland_code' => $_POST['herkunftsland_code'], + 'lehreinheit_id' => $_POST['lehreinheit_id'], + 'ort' => $ort, + 'universitaet' => $universitaet, + 'ects_erworben' => $_POST['ects_erworben'] , + 'ects_angerechnet' => $_POST['ects_angerechnet'], + 'insertamum' => date('c'), + 'insertvon' => $authUID, + ]); + + $bisio_id = $this->getDataOrTerminateWithError($result); + + //check if localData (purposes) + if(count($localPurposes) > 0){ + foreach ($localPurposes as $zweck){ + $zweck = (int)$zweck; + $this->addMobilityPurpose($bisio_id, $zweck); + } + } + + //check if localData (supports) + if(count($localSupports) > 0){ + foreach ($localSupports as $support){ + $this->addMobilitySupport($bisio_id, $support); + } + } + + $this->terminateWithSuccess($bisio_id); + } + + public function loadMobility($bisio_id) + { + $this->BisioModel->addSelect("*"); + $this->BisioModel->addJoin('bis.tbl_mobilitaetsprogramm mp', 'ON (mp.mobilitaetsprogramm_code = bis.tbl_bisio.mobilitaetsprogramm_code)', 'LEFT'); + $this->BisioModel->addJoin('lehre.tbl_lehreinheit le', 'ON (le.lehreinheit_id = bis.tbl_bisio.lehreinheit_id)','LEFT'); + $result = $this->BisioModel->loadWhere( + array('bisio_id' => $bisio_id) + ); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess(current($data)); + } + + public function updateMobility() + { + + $this->load->library('form_validation'); + $authUID = getAuthUID(); + + $student_uid = $this->input->post('uid'); + + if(!$student_uid) + { + return $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Student UID']), self::ERROR_TYPE_GENERAL); + } + $formData = $this->input->post('formData'); + + $_POST['von'] = (isset($formData['von']) && !empty($formData['von'])) ? $formData['von'] : null; + $_POST['bis'] = (isset($formData['bis']) && !empty($formData['bis'])) ? $formData['bis'] : null; + $_POST['nation_code'] = (isset($formData['nation_code']) && !empty($formData['nation_code'])) ? $formData['nation_code'] : 'A'; + $_POST['mobilitaetsprogramm_code'] = (isset($formData['mobilitaetsprogramm_code']) && !empty($formData['mobilitaetsprogramm_code'])) ? $formData['mobilitaetsprogramm_code'] : null; + $_POST['herkunftsland_code'] = (isset($formData['herkunftsland_code']) && !empty($formData['herkunftsland_code'])) ? $formData['herkunftsland_code'] : 'A'; + $_POST['ects_erworben'] = (isset($formData['ects_erworben']) && !empty($formData['ects_erworben'])) ? $formData['ects_erworben'] : null; + $_POST['ects_angerechnet'] = (isset($formData['ects_angerechnet']) && !empty($formData['ects_angerechnet'])) ? $formData['ects_angerechnet'] : null; + $_POST['lehreinheit_id'] = (isset($formData['lehreinheit_id']) && !empty($formData['lehreinheit_id'])) ? $formData['lehreinheit_id'] : null; + + $this->form_validation->set_rules('nation_code', 'Nation_code', 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Nation_code']) + ]); + $this->form_validation->set_rules('herkunftsland_code', 'Herkunftsland_code', 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Herkunftsland_code']) + ]); + $this->form_validation->set_rules('mobilitaetsprogramm_code', 'Mobilitaetsprogramm_code', 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Mobilitaetsprogramm_code']) + ]); + $this->form_validation->set_rules('von', 'VonDatum', 'is_valid_date', [ + 'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'VonDatum']) + ]); + + $this->form_validation->set_rules('bis', 'VBisDatum', 'is_valid_date', [ + 'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'VBisDatum']) + ]); + + $this->form_validation->set_rules('ects_erworben', 'Ects_erworben', 'numeric', [ + 'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'Ects_erworben']) + ]); + + $this->form_validation->set_rules('ects_angerechnet', 'Ects_angerechnet', 'numeric', [ + 'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'Ects_angerechnet']) + ]); + + $this->form_validation->set_rules('lehreinheit_id', 'Lehreinheit', 'numeric', [ + 'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'Lehreinheit']) + ]); + + if ($this->form_validation->run() == false) + { + $this->terminateWithValidationErrors($this->form_validation->error_array()); + } + + $result = $this->BisioModel->update( + [ + 'bisio_id' => $formData['bisio_id'] + ], + [ + 'student_uid' => $student_uid, + 'von' => $_POST['von'], + 'bis' => $_POST['bis'], + 'mobilitaetsprogramm_code' => $_POST['mobilitaetsprogramm_code'], + 'nation_code' => $_POST['nation_code'], + 'herkunftsland_code' => $_POST['herkunftsland_code'], + 'lehreinheit_id' => $_POST['lehreinheit_id'], + 'ort' => $formData['ort'], + 'universitaet' => $formData['universitaet'], + 'ects_erworben' => $_POST['ects_erworben'] , + 'ects_angerechnet' => $_POST['ects_angerechnet'], + 'updateamum' => date('c'), + 'updatevon' => $authUID, + ] + ); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess(current($data)); + } + + public function deleteMobility($bisio_id) + { + //check if extension table exists + $result = $this->BisioModel->tableExists('extension', 'tbl_mo_bisioidzuordnung'); + $data = $this->getDataOrTerminateWithError($result); + + //if table exists check if existing entry + if(!empty($data)) + { + $this->BisioModel->addSelect("count(*)"); + $this->BisioModel->addJoin('extension.tbl_mo_bisioidzuordnung mo', 'ON (mo.bisio_id = bis.tbl_bisio.bisio_id)', 'LEFT'); + + $resultCheckMo = $this->BisioModel->loadWhere( + array('mo.bisio_id' => $bisio_id) + ); + + $resultCheckMo = $this->getDataOrTerminateWithError($resultCheckMo); + $count = current($resultCheckMo)->count; + + $existsInExtension = $count > 0 ? true : false; + + if($existsInExtension) + $this->terminateWithError($this->p->t('mobility', 'error_existingEntryInExtension'), self::ERROR_TYPE_GENERAL); + } + + $result = $this->BisioModel->delete( + array('bisio_id' => $bisio_id) + ); + + $data = $this->getDataOrTerminateWithError($result); + $this->terminateWithSuccess($data); + } + + public function getLVList($studiengang_kz) + { + $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); + + $result = $this->LehrveranstaltungModel->getLvsByStudiengangkz($studiengang_kz); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getAllLehreinheiten() + { + $lv_id = $this->input->post('lv_id'); + $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); + + $this->load->model('education/Lehreinheit_model', 'LehreinheitModel'); + + $result = $this->LehreinheitModel->getLesFromLvIds($lv_id, $studiensemester_kurzbz); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getLvsandLesByStudent($student_uid) + { + $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); + + $result = $this->LehrveranstaltungModel->getLvsByStudent($student_uid); + + $data = $this->getDataOrTerminateWithError($result); + + $lv_ids = array(); + $allData = array(); + + foreach ($data as $lehrveranstaltung) { + $lv_ids[] = $lehrveranstaltung->lehrveranstaltung_id; + } + + $this->load->model('education/Lehreinheit_model', 'LehreinheitModel'); + + foreach ($lv_ids as $id) + { + $result = $this->LehreinheitModel->getLesFromLvIds($id); + $data = $this->getDataOrTerminateWithError($result); + + if (is_array($data)) { + $allData = array_merge($allData, $data); + } + } + + return $this->terminateWithSuccess($allData); + } + + public function getPurposes($bisio_id) + { + $bisio_id = (int)$bisio_id; + + $this->load->model('codex/Bisiozweck_model', 'BisiozweckModel'); + + $this->BisiozweckModel->addSelect("*"); + $this->BisiozweckModel->addJoin('bis.tbl_zweck zw', 'ON (zw.zweck_code = bis.tbl_bisio_zweck.zweck_code)'); + + $result = $this->BisiozweckModel->loadWhere( + array('bisio_id' => $bisio_id) + ); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getSupports($bisio_id) + { + $bisio_id = (int)$bisio_id; + + $this->load->model('codex/Bisioaufenthaltfoerderung_model', 'BisioaufenthaltfoerderungModel'); + + $this->BisioaufenthaltfoerderungModel->addSelect("*"); + $this->BisioaufenthaltfoerderungModel->addJoin('bis.tbl_aufenthaltfoerderung af', 'ON (af.aufenthaltfoerderung_code = bis.tbl_bisio_aufenthaltfoerderung.aufenthaltfoerderung_code)'); + + $result = $this->BisioaufenthaltfoerderungModel->loadWhere( + array('bisio_id' => $bisio_id) + ); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getListPurposes() + { + $this->load->model('codex/Zweck_model', 'ZweckModel'); + + $result = $this->ZweckModel->load(); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getListSupports() + { + $this->load->model('codex/Aufenthaltfoerderung_model', 'AufenthaltfoerderungModel'); + + $result = $this->AufenthaltfoerderungModel->load(); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function addMobilityPurpose($bisio_id, $local_purpose = null) + { + $zweck_code = $this->input->post('zweck_code'); + + if($local_purpose){ + $zweck_code = $local_purpose; + } + + $this->load->model('codex/Bisiozweck_model', 'BisiozweckModel'); + if(!$local_purpose) + { + $check = $this->BisiozweckModel->loadWhere( + [ + 'bisio_id' => $bisio_id, + 'zweck_code' => $zweck_code, + ] + ); + if (hasData($check)) + { + $this->terminateWithError($this->p->t('ui', 'error_entryExisting'), self::ERROR_TYPE_GENERAL); + } + } + + $result = $this->BisiozweckModel->insert( + array( + 'bisio_id' => $bisio_id, + 'zweck_code' => $zweck_code + ) + ); + + $data = $this->getDataOrTerminateWithError($result); + + if($local_purpose) + { + return $data; + } + + return $this->terminateWithSuccess(current($data)); + } + + public function deleteMobilityPurpose($bisio_id) + { + $zweck_code = $this->input->post('zweck_code'); + + $this->load->model('codex/Bisiozweck_model', 'BisiozweckModel'); + + + $result = $this->BisiozweckModel->delete( + array( + 'bisio_id' => $bisio_id, + 'zweck_code' => $zweck_code + ) + ); + + $data = $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess(current($data)); + } + + public function addMobilitySupport($bisio_id, $local_support = null) + { + $aufenthaltfoerderung_code = $this->input->post('aufenthaltfoerderung_code'); + + if($local_support){ + $aufenthaltfoerderung_code = $local_support; + } + + $this->load->model('codex/Bisioaufenthaltfoerderung_model', 'BisioaufenthaltfoerderungModel'); + + if(!$local_support) + { + $check = $this->BisioaufenthaltfoerderungModel->loadWhere( + [ + 'bisio_id' => $bisio_id, + 'aufenthaltfoerderung_code' => $aufenthaltfoerderung_code, + ] + ); + if (hasData($check)) + { + $this->terminateWithError($this->p->t('ui', 'error_entryExisting'), self::ERROR_TYPE_GENERAL); + } + } + + $result = $this->BisioaufenthaltfoerderungModel->insert( + array( + 'bisio_id' => $bisio_id, + 'aufenthaltfoerderung_code' => $aufenthaltfoerderung_code + ) + ); + + $data = $this->getDataOrTerminateWithError($result); + + if($local_support) + { + return $data; + } + + return $this->terminateWithSuccess(current($data)); + } + + public function deleteMobilitySupport($bisio_id) + { + $aufenthaltfoerderung_code = $this->input->post('aufenthaltfoerderung_code'); + + $this->load->model('codex/Bisioaufenthaltfoerderung_model', 'BisioaufenthaltfoerderungModel'); + + $result = $this->BisioaufenthaltfoerderungModel->delete( + array( + 'bisio_id' => $bisio_id, + 'aufenthaltfoerderung_code' => $aufenthaltfoerderung_code + ) + ); + $data = $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess(current($data)); + } +} diff --git a/application/controllers/api/frontend/v1/stv/Prestudent.php b/application/controllers/api/frontend/v1/stv/Prestudent.php index ef9aeb111..0b06b9667 100644 --- a/application/controllers/api/frontend/v1/stv/Prestudent.php +++ b/application/controllers/api/frontend/v1/stv/Prestudent.php @@ -19,6 +19,7 @@ class Prestudent extends FHCAPI_Controller 'getAufmerksamdurch' => ['admin:r', 'assistenz:r'], 'getBerufstaetigkeit' => ['admin:r', 'assistenz:r'], 'getTypenStg' => ['admin:r', 'assistenz:r'], + 'getBisstandort' => ['admin:r', 'assistenz:r'], 'getStudienplaene' => ['admin:r', 'assistenz:r'], 'getStudiengang' => ['admin:r', 'assistenz:r'] ]); @@ -265,6 +266,17 @@ class Prestudent extends FHCAPI_Controller return $this->terminateWithSuccess(getData($result) ?: []); } + public function getBisstandort() + { + $this->load->model('codex/Bisstandort_model', 'BisstandortModel'); + + $result = $this->BisstandortModel->load(); + if (isError($result)) { + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + return $this->terminateWithSuccess(getData($result) ?: []); + } + public function getStudienplaene($prestudent_id) { $this->load->model('organisation/Studienplan_model', 'StudienplanModel'); diff --git a/application/controllers/api/frontend/v1/stv/Pruefung.php b/application/controllers/api/frontend/v1/stv/Pruefung.php new file mode 100644 index 000000000..e205c85b8 --- /dev/null +++ b/application/controllers/api/frontend/v1/stv/Pruefung.php @@ -0,0 +1,577 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +/** + * This controller operates between (interface) the JS (GUI) and the back-end + * Provides data to the ajax get calls about addresses + * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON + */ +class Pruefung extends FHCAPI_Controller +{ + public function __construct() + { + parent::__construct([ + 'getPruefungen' => ['admin:r', 'assistenz:r'], + 'loadPruefung' => ['admin:r', 'assistenz:r'], + 'getTypenPruefungen' => ['admin:r', 'assistenz:r'], + 'getLehreinheiten' => ['admin:r', 'assistenz:r'], + 'getAllLehreinheiten' => ['admin:r', 'assistenz:r'], + 'getLvsByStudent' => ['admin:r', 'assistenz:r'], + 'getLvsandLesByStudent' => ['admin:r', 'assistenz:r'], + 'getLvsAndMas' => ['admin:r', 'assistenz:r'], + 'getMitarbeiterLv' => ['admin:r', 'assistenz:r'], + 'getNoten' => ['admin:r', 'assistenz:r'], + 'checkZeugnisnoteLv' => ['admin:r', 'assistenz:r'], + 'checkTermin1' => ['admin:r', 'assistenz:r'], + 'insertPruefung' => self::PERM_LOGGED, + 'updatePruefung' =>self::PERM_LOGGED, + 'deletePruefung' =>self::PERM_LOGGED, + ]); + + //Load Models + $this->load->model('education/LePruefung_model', 'PruefungModel'); + + //version with postParameter + if ($this->router->method == 'insertPruefung') + { + $student_uid = $this->input->post('student_uid'); + + $this->load->model('crm/Student_model', 'StudentModel'); + $result = $this->StudentModel->load([$student_uid]); + $student = $this->getDataOrTerminateWithError($result); + + $prestudent_id = current($student)->prestudent_id; + $this->checkPermissionsForPrestudent($prestudent_id, ['admin:w', 'assistenz:w']); + } + + // parameter from uri + if ($this->router->method == 'updatePruefung' || $this->router->method == 'deletePruefung') + { + $pruefung_id = current(array_slice($this->uri->rsegments, 2)); + + $result = $this->PruefungModel->load($pruefung_id); + $pruefung = $this->getDataOrTerminateWithError($result); + $student_uid = current($pruefung)->student_uid; + + + $this->load->model('crm/Student_model', 'StudentModel'); + $result = $this->StudentModel->load([$student_uid]); + $student = $this->getDataOrTerminateWithError($result); + $prestudent_id = current($student)->prestudent_id; + + $this->checkPermissionsForPrestudent($prestudent_id, ['admin:rw', 'assistenz:rw']); + } + + if ($this->router->method == 'loadPruefung') + { + $pruefung_id = current(array_slice($this->uri->rsegments, 2)); + + $result = $this->PruefungModel->load($pruefung_id); + $pruefung = $this->getDataOrTerminateWithError($result); + + + $student_uid = current($pruefung)->student_uid; + + $this->load->model('crm/Student_model', 'StudentModel'); + $result = $this->StudentModel->load([$student_uid]); + $student = $this->getDataOrTerminateWithError($result); + $prestudent_id = current($student)->prestudent_id; + + $this->checkPermissionsForPrestudent($prestudent_id, ['admin:r', 'assistenz:r']); + } + + if ($this->router->method == 'getPruefungen') + { + $student_uid = current(array_slice($this->uri->rsegments, 2)); + + $this->load->model('crm/Student_model', 'StudentModel'); + $result = $this->StudentModel->load([$student_uid]); + $student = $this->getDataOrTerminateWithError($result); + $prestudent_id = current($student)->prestudent_id; + + $this->checkPermissionsForPrestudent($prestudent_id, ['admin:r', 'assistenz:r']); + } + + // Load language phrases + $this->loadPhrases([ + 'global', 'ui','lehre' + ]); + } + + public function getPruefungen($student_uid, $studiensemester_kurzbz = null) + { + $result = $this->PruefungModel->getPruefungenByStudentuid($student_uid); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function loadPruefung($pruefung_id) + { + $this->PruefungModel->addSelect('tbl_pruefung.datum'); + $this->PruefungModel->addSelect("TO_CHAR(tbl_pruefung.datum::timestamp, 'DD.MM.YYYY') AS format_datum"); + $this->PruefungModel->addSelect('tbl_pruefung.anmerkung'); + $this->PruefungModel->addSelect('tbl_pruefung.pruefungstyp_kurzbz'); + $this->PruefungModel->addSelect('tbl_pruefung.pruefung_id'); + $this->PruefungModel->addSelect('tbl_pruefung.lehreinheit_id'); + $this->PruefungModel->addSelect('tbl_pruefung.student_uid'); + $this->PruefungModel->addSelect('tbl_pruefung.mitarbeiter_uid'); + $this->PruefungModel->addSelect('tbl_pruefung.punkte'); + $this->PruefungModel->addSelect('tbl_pruefung.note'); + + $this->PruefungModel->addSelect('tbl_lehrveranstaltung.bezeichnung as lehrveranstaltung_bezeichnung'); + $this->PruefungModel->addSelect('tbl_lehrveranstaltung.lehrveranstaltung_id'); + $this->PruefungModel->addSelect('tbl_lehrveranstaltung.semester'); + $this->PruefungModel->addSelect('tbl_lehrveranstaltung.lehrform_kurzbz'); + $this->PruefungModel->addSelect('tbl_note.bezeichnung as note_bezeichnung'); + $this->PruefungModel->addSelect('tbl_pruefungstyp.beschreibung as typ_beschreibung'); + $this->PruefungModel->addSelect('tbl_lehreinheit.studiensemester_kurzbz as studiensemester_kurzbz'); + + $this->PruefungModel->addJoin('lehre.tbl_lehreinheit', 'lehre.tbl_pruefung.lehreinheit_id = lehre.tbl_lehreinheit.lehreinheit_id'); + $this->PruefungModel->addJoin('lehre.tbl_lehrveranstaltung', 'lehrveranstaltung_id'); + $this->PruefungModel->addJoin('lehre.tbl_note', 'note'); + $this->PruefungModel->addJoin('lehre.tbl_pruefungstyp', 'pruefungstyp_kurzbz'); + + + $this->PruefungModel->addLimit(1); + + $result = $this->PruefungModel->loadWhere( + array('pruefung_id' => $pruefung_id) + ); + if (isError($result)) { + return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); + } + + if (!hasData($result)) + { + return $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Pruefung_id']), self::ERROR_TYPE_GENERAL); + } + $this->terminateWithSuccess(current(getData($result)) ? : null); + } + + /** + * Inserts a pruefung + * + * @param lehrveranstaltung_id, student_uid, lehreinheit_id + * + * @return values on success + * retval 0: pruefung inserted + * reval 1: pruefung and zeugnisnote inserted + * retval 2: pruefung inserted, no insert Zeugnisnote + * (change after date of examination) + * retval 3: pruefung of type Termin2 inserted + * and pruefung of type Termin1 as well + * retval 5: prueufungen Termin 2 and 1 inserted + * and no insert Zeugnisnote (change after date of examination) + */ + public function insertPruefung() + { + $authUID = getAuthUID(); + + $this->load->library('form_validation'); + + $this->form_validation->set_rules('lehrveranstaltung_id', $this->p->t('lehre', 'lehrveranstaltung'), 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'lehrveranstaltung')]), + ]); + $this->form_validation->set_rules('lehreinheit_id', $this->p->t('lehre', 'lehreinheit'), 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'lehreinheit')]), + ]); + $this->form_validation->set_rules('pruefungstyp_kurzbz', $this->p->t('lehre', 'pruefung'), 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('global', 'typ')]), + ]); + $this->form_validation->set_rules( + 'datum', + $this->p->t('global', 'datum'), + ['is_valid_date'] + ); + + if ($this->form_validation->run() == false) + { + $this->terminateWithValidationErrors($this->form_validation->error_array()); + } + + //calculate studiensemester_kurzbz this from lehreinheit (case newPruefung) + $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); + if (!$studiensemester_kurzbz) + { + $this->load->model('education/Lehreinheit_model', 'LehreinheitModel'); + + $result = $this->LehreinheitModel->load($this->input->post('lehreinheit_id')); + + $lehreinheit = $this->getDataOrTerminateWithError($result); + $studiensemester_kurzbz = current($lehreinheit)->studiensemester_kurzbz; + + if (isError($result)) + { + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + } + + $result = $this->PruefungModel->insert([ + 'lehreinheit_id' => $this->input->post('lehreinheit_id'), + 'student_uid' => $this->input->post('student_uid'), + 'mitarbeiter_uid' => $this->input->post('mitarbeiter_uid'), + 'datum' => $this->input->post('datum'), + 'pruefungstyp_kurzbz' => $this->input->post('pruefungstyp_kurzbz'), + 'note' => $this->input->post('note'), + 'anmerkung' => $this->input->post('anmerkung'), + 'insertamum' => date('c'), + 'insertvon' => $authUID, + ]); + + $this->getDataOrTerminateWithError($result); + + //check if existing zeugnisnote + $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); + + $result = $this->ZeugnisnoteModel->loadWhere(array( + 'lehrveranstaltung_id' => $this->input->post('lehrveranstaltung_id'), + 'student_uid' => $this->input->post('student_uid'), + 'studiensemester_kurzbz' => $studiensemester_kurzbz)); + + if (isError($result)) + { + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + + if (!hasData($result)) + { + //insert zeugnisnote, if not existing + $result = $this->ZeugnisnoteModel->insert(array( + 'lehrveranstaltung_id' => $this->input->post('lehrveranstaltung_id'), + 'student_uid' => $this->input->post('student_uid'), + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'note' => $this->input->post('note'), + 'uebernahmedatum' => date('c'), + 'benotungsdatum' => $this->input->post('datum'), + 'insertamum' => date('c'), + 'insertvon' => $authUID + )); + + if (isError($result)) + { + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + $this->terminateWithSuccess(1); + } + + $return_code = 0; + + //handling Termin1 if not existing + if($this->input->post('pruefungstyp_kurzbz') == "Termin2") + { + $resultP = $this->PruefungModel->loadWhere(array( + 'lehreinheit_id' => $this->input->post('lehreinheit_id'), + 'student_uid' => $this->input->post('student_uid'), + 'pruefungstyp_kurzbz' => 'Termin1')); + + if (isError($resultP)) + { + $this->terminateWithError(getError($resultP), self::ERROR_TYPE_GENERAL); + } + if(!hasData($resultP)) + { + //check if existing Zeugnisnote + $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); + $this->ZeugnisnoteModel->addJoin('lehre.tbl_lehreinheit', 'lehrveranstaltung_id'); + + $resultP = $this->ZeugnisnoteModel->loadWhere(array( + 'lehrveranstaltung_id' => $this->input->post('lehrveranstaltung_id'), + 'student_uid' => $this->input->input->post('student_uid'), + 'lehre.tbl_zeugnisnote.studiensemester_kurzbz' => $studiensemester_kurzbz)); + if (isError($resultP)) + { + $this->terminateWithError(getError($resultP), self::ERROR_TYPE_GENERAL); + } + if (!hasData($resultP)) + { + $this->terminateWithError("Zeugnisnote existiert nicht", self::ERROR_TYPE_GENERAL); + } + $dataNote = current(getData($resultP)); + + $resultN = $this->PruefungModel->insert([ + 'lehreinheit_id' => $this->input->post('lehreinheit_id'), + 'student_uid' => $this->input->post('student_uid'), + 'mitarbeiter_uid' => $this->input->post('mitarbeiter_uid'), + 'datum' => $dataNote->benotungsdatum, + 'pruefungstyp_kurzbz' => 'Termin1', + 'note' => $dataNote->note, + 'punkte' => $dataNote->punkte, + 'anmerkung' => 'automatisiert aus Zeugnisnote erstellt', + 'insertamum' => date('c'), + 'insertvon' => $authUID, + ]); + + if (isError($resultN)) { + $this->terminateWithError(getError($resultN), self::ERROR_TYPE_GENERAL); + } + $return_code = 3; + } + } + + $note = current(getData($result)); + $uebernahmedatum = new DateTime($note->uebernahmedatum); + $benotungsdatum = new DateTime($note->benotungsdatum); + + $checkDate = $uebernahmedatum === '' || $benotungsdatum > $uebernahmedatum + ? $benotungsdatum + : $uebernahmedatum; + + if ($checkDate >= $this->input->post('datum') && $note !== $note->note) + { + $this->terminateWithSuccess($return_code + 2); + } + $this->terminateWithSuccess($return_code + 2); + } + + /** + * Updates a pruefung + * + * @param pruefung_id + * + * @return success or error + * + * no impact on lehre.tbl_zeugnisnote + */ + public function updatePruefung($pruefung_id) + { + $result = $this->PruefungModel->load($pruefung_id); + + $oldpruefung = $this->getDataOrTerminateWithError($result); + if (!$oldpruefung) + show_404(); // Pruefung that should be updated does not exist + + $authUID = getAuthUID(); + + $this->load->library('form_validation'); + + $this->form_validation->set_rules('lehrveranstaltung_id', $this->p->t('lehre', 'lehrveranstaltung'), 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'lehrveranstaltung')]), + ]); + $this->form_validation->set_rules('lehreinheit_id', $this->p->t('lehre', 'lehreinheit'), 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'lehreinheit')]), + ]); + $this->form_validation->set_rules('pruefungstyp_kurzbz', $this->p->t('lehre', 'pruefung'), 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('global', 'typ')]), + ]); + $this->form_validation->set_rules( + 'datum', + $this->p->t('global', 'datum'), + ['is_valid_date'] + ); + + if ($this->form_validation->run() == false) + { + $this->terminateWithValidationErrors($this->form_validation->error_array()); + } + + $result = $this->PruefungModel->update( + [ + 'pruefung_id' => $pruefung_id + ], + [ 'lehreinheit_id' => $this->input->post('lehreinheit_id'), + 'student_uid' => $this->input->post('student_uid'), + 'mitarbeiter_uid' => $this->input->post('mitarbeiter_uid'), + 'note' => $this->input->post('note'), + 'pruefungstyp_kurzbz' => $this->input->post('pruefungstyp_kurzbz'), + 'datum' => $this->input->post('datum'), + 'anmerkung' => $this->input->post('anmerkung'), + 'updatevon' => $authUID, + 'updateamum' => date('c'), + ] + ); + $this->getDataOrTerminateWithError($result); + + return $this->outputJsonSuccess(true); + } + + /** + * Deletes a pruefung + * + * @param pruefung_id + * + * @return success or error + * + * no impact on lehre.tbl_zeugnisnote + */ + public function deletePruefung($pruefung_id) + { + $result = $this->PruefungModel->load($pruefung_id); + + $oldpruefung = $this->getDataOrTerminateWithError($result); + if (!$oldpruefung) + show_404(); // Pruefung that should be deleted does not exist + + $result = $this->PruefungModel->delete( + [ + 'pruefung_id' => $pruefung_id + ] + ); + + $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess(true); + } + + public function getTypenPruefungen() + { + $this->load->model('education/Pruefungstyp_model', 'PruefungtypModel'); + + //TODO(Manu) sort Termin3 + $this->PruefungtypModel->addOrder('sort', 'ASC'); + $result = $this->PruefungtypModel->loadWhere( + array('abschluss' => 'false') + ); + + if (isError($result)) { + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + return $this->terminateWithSuccess(getData($result) ?: []); + } + + public function getAllLehreinheiten() + { + $lv_id = $this->input->post('lv_id'); + $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); + + $this->load->model('education/Lehreinheit_model', 'LehreinheitModel'); + + $result = $this->LehreinheitModel->getLesFromLvIds($lv_id, $studiensemester_kurzbz); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getLvsandLesByStudent($student_uid, $semester_kurzbz=null) + { + $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); + + $result = $this->LehrveranstaltungModel->getLvsByStudent($student_uid, $semester_kurzbz); + + $data = $this->getDataOrTerminateWithError($result); + + $lv_ids = array(); + $allData = array(); + + foreach ($data as $lehrveranstaltung) { + $lv_ids[] = $lehrveranstaltung->lehrveranstaltung_id; + } + + $this->load->model('education/Lehreinheit_model', 'LehreinheitModel'); + + foreach ($lv_ids as $id) + { + $result = $this->LehreinheitModel->getLesFromLvIds($id, $semester_kurzbz); + $data = $this->getDataOrTerminateWithError($result); + + if (is_array($data)) { + $allData = array_merge($allData, $data); + } + } + + return $this->terminateWithSuccess($allData); + } + + public function getLvsAndMas($student_uid) + { + $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); + + $result = $this->LehrveranstaltungModel->getLvsByStudent($student_uid); + + $data = $this->getDataOrTerminateWithError($result); + + $lv_ids = array(); + $allDataMa = array(); + + foreach ($data as $lehrveranstaltung) + { + $lv_ids[] = $lehrveranstaltung->lehrveranstaltung_id; + } + + $this->load->model('ressource/Mitarbeiter_model', 'MitarbeiterModel'); + + foreach ($lv_ids as $id) + { + $resultMa = $this->MitarbeiterModel->getMitarbeiterFromLV($id); + $dataMa = $this->getDataOrTerminateWithError($resultMa); + + if (is_array($dataMa)) + { + $allDataMa = array_merge($allDataMa, $dataMa); + } + } + return $this->terminateWithSuccess($allDataMa); + } + + public function getLvsByStudent($student_uid, $studiensemester_kurzbz = null) + { + $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); + + $result = $this->LehrveranstaltungModel->getLvsByStudent($student_uid, $studiensemester_kurzbz); + + $data = $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess($data); + } + + public function getMitarbeiterLv($lv_id) + { + $this->load->model('ressource/Mitarbeiter_model', 'MitarbeiterModel'); + + $result = $this->MitarbeiterModel->getMitarbeiterFromLV($lv_id); + + $data = $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess($data); + } + + public function getNoten() + { + $this->load->model('education/Note_model', 'NoteModel'); + + $this->NoteModel->addOrder('note', 'ASC'); + $result = $this->NoteModel->load(); + + if (isError($result)) { + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + return $this->terminateWithSuccess(getData($result) ?: []); + } + + public function checkZeugnisnoteLv() + { + $student_uid = $this->input->post('student_uid'); + $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); + $lehrveranstaltung_id = $this->input->post('lehrveranstaltung_id'); + + $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); + + $result = $this->ZeugnisnoteModel->loadWhere(array( + 'lehrveranstaltung_id' => $lehrveranstaltung_id, + 'student_uid' => $student_uid, + 'studiensemester_kurzbz' => $studiensemester_kurzbz)); + + $data = $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess($data); + } +} diff --git a/application/controllers/api/frontend/v1/stv/Status.php b/application/controllers/api/frontend/v1/stv/Status.php index 074f4029e..8167bd90f 100644 --- a/application/controllers/api/frontend/v1/stv/Status.php +++ b/application/controllers/api/frontend/v1/stv/Status.php @@ -647,15 +647,8 @@ class Status extends FHCAPI_Controller return $this->outputJsonSuccess(true); } - public function loadStatus() + public function loadStatus($prestudent_id, $status_kurzbz, $studiensemester_kurzbz, $ausbildungssemester) { - $_POST = json_decode(utf8_encode($this->input->raw_input_stream), true); - - $prestudent_id = $this->input->post('prestudent_id'); - $status_kurzbz = $this->input->post('status_kurzbz'); - $ausbildungssemester = $this->input->post('ausbildungssemester'); - $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); - $result = $this->PrestudentstatusModel->loadWhere( array( 'prestudent_id' => $prestudent_id, @@ -1344,13 +1337,13 @@ class Status extends FHCAPI_Controller 'updatevon' => $authUID ]; foreach ([ - 'orgform_kurzbz', - 'anmerkung', - 'bewerbung_abgeschicktamum', - 'studienplan_id', - 'rt_stufe', - 'statusgrund_id' - ] as $key) + 'orgform_kurzbz', + 'anmerkung', + 'bewerbung_abgeschicktamum', + 'studienplan_id', + 'rt_stufe', + 'statusgrund_id' + ] as $key) if ($this->input->post($key)) $updateData[$key] = $this->input->post($key); diff --git a/application/controllers/api/frontend/v1/stv/Student.php b/application/controllers/api/frontend/v1/stv/Student.php index 89c317ae4..f24ef62bb 100644 --- a/application/controllers/api/frontend/v1/stv/Student.php +++ b/application/controllers/api/frontend/v1/stv/Student.php @@ -55,7 +55,7 @@ class Student extends FHCAPI_Controller // Load language phrases $this->loadPhrases([ - 'ui' + 'ui', 'lehre' ]); } @@ -156,6 +156,8 @@ class Student extends FHCAPI_Controller $uid = $student ? current($student)->student_uid : null; + $studiengang_kz = $student ? current($student)->studiengang_kz : null; + $result = $this->PrestudentModel->loadWhere(['prestudent_id' => $prestudent_id]); $person = $this->getDataOrTerminateWithError($result); @@ -223,20 +225,35 @@ class Student extends FHCAPI_Controller // Check PKs if (count($update_lehrverband) + count($update_student) && $uid === null) { - // TODO(chris): phrase - $this->terminateWithValidationErrors(['' => "Kein/e StudentIn vorhanden!"]); + $this->terminateWithValidationErrors(['' => $this->p->t('lehre', 'error_no_student')]); } if (count($update_person) && $person_id === null) { - // TODO(chris): phrase - $this->terminateWithValidationErrors(['' => "Keine Person vorhanden!"]); + $this->terminateWithValidationErrors(['' => $this->p->t('lehre', 'error_no_person')]); } // Do Updates if (count($update_lehrverband)) { - $result = $this->StudentlehrverbandModel->update([ + $curstudlvb = $this->StudentlehrverbandModel->load([ 'studiensemester_kurzbz' => $studiensemester_kurzbz, 'student_uid' => $uid - ], $update_lehrverband); + ]); + + if(hasData($curstudlvb) && count(getData($curstudlvb)) > 0 ) + { + $result = $this->StudentlehrverbandModel->update([ + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'student_uid' => $uid + ], $update_lehrverband); + } + else + { + $result = $this->StudentlehrverbandModel->insert(array_merge([ + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'student_uid' => $uid, + 'studiengang_kz' => $studiengang_kz + ], $update_lehrverband)); + } + $this->getDataOrTerminateWithError($result); } diff --git a/application/controllers/components/stv/Noten.php b/application/controllers/components/stv/Noten.php deleted file mode 100644 index fb61de065..000000000 --- a/application/controllers/components/stv/Noten.php +++ /dev/null @@ -1,168 +0,0 @@ - 'student/noten:r', - 'getZeugnis' => 'student/noten:r', - 'update' => ['admin:w', 'assistenz:w'] - ]); - - // Load Libraries - $this->load->library('VariableLib', ['uid' => getAuthUID()]); - } - - public function get() - { - $this->load->model('codex/Note_model', 'NoteModel'); - - $result = $this->NoteModel->addOrder('note'); - - $result = $this->NoteModel->load(); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - } - - return $this->outputJson($result); - } - - public function getZeugnis($prestudent_id, $all = null) - { - $this->load->model('crm/Student_model', 'StudentModel'); - $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); - - $result = $this->StudentModel->loadWhere([ - 'prestudent_id' => $prestudent_id - ]); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - return $this->outputJson($result); - } - if (!hasData($result)) - return $this->outputJsonSuccess(null); - - $student_uid = current(getData($result))->student_uid; - - $studiensemester_kurzbz = ($all === null) ? $this->variablelib->getVar('semester_aktuell') : null; - - $result = $this->ZeugnisnoteModel->getZeugnisnoten($student_uid, $studiensemester_kurzbz); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - } - - return $this->outputJson($result); - } - - public function update() - { - $this->load->model('crm/Student_model', 'StudentModel'); - $this->load->model('organisation/Studienplan_model', 'StudienplanModel'); - $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); - $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); - - $this->load->library('form_validation'); - - $_POST = json_decode(utf8_encode($this->input->raw_input_stream), true); - - if (empty($_POST) || !is_array(current($_POST))) { - $result = $this->hasPermissionUpdate($this->input->post('lehrveranstaltung_id'), $this->input->post('student_uid')); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_FORBIDDEN); - return $this->outputJson($result); - } - - $this->form_validation->set_rules('lehrveranstaltung_id', 'Lehrverantaltung ID', 'required|numeric'); - $this->form_validation->set_rules('student_uid', 'Student UID', 'required'); - $this->form_validation->set_rules('studiensemester_kurzbz', 'Studiensemester Kurzbezeichnung', 'required'); - $this->form_validation->set_rules('note', 'Note', 'required|numeric'); - $post = [$_POST]; - } else { - foreach ($_POST as $i => $data) { - $lvid = isset($data['lehrveranstaltung_id']) ? $data['lehrveranstaltung_id'] : null; - $uid = isset($data['student_uid']) ? $data['student_uid'] : null; - $result = $this->hasPermissionUpdate($lvid, $uid); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_FORBIDDEN); - return $this->outputJson($result); - } - - $this->form_validation->set_rules($i . '[lehrveranstaltung_id]', '#' . $i . ' Lehrverantaltung ID', 'required|numeric'); - $this->form_validation->set_rules($i . '[student_uid]', '#' . $i . ' Student UID', 'required'); - $this->form_validation->set_rules($i . '[studiensemester_kurzbz]', '#' . $i . ' Studiensemester Kurzbezeichnung', 'required'); - $this->form_validation->set_rules($i . '[note]', '#' . $i . ' Note', 'required|numeric'); - } - $post = $_POST; - } - if ($this->form_validation->run() == false) { - $this->output->set_status_header(REST_Controller::HTTP_BAD_REQUEST); - return $this->outputJsonError($this->form_validation->error_array()); - } - - $final_result = success(); - $this->ZeugnisnoteModel->db->trans_start(); - - foreach ($post as $i => $data) { - $note = $data['note']; - unset($data['note']); - $result = $this->ZeugnisnoteModel->update($data, [ - 'note' => $note, - 'benotungsdatum' => date('c'), - 'updateamum' => date('c'), - 'updatevon' => getAuthUID() - ]); - if (isError($result)) { - $final_result = $result; - break; - } - } - - $this->ZeugnisnoteModel->db->trans_complete(); - - if (isError($final_result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - } - - $this->outputJson($final_result); - } - - protected function hasPermissionUpdate($lehrveranstaltung_id, $student_uid) - { - // TODO(chris): error phrases! - if ($lehrveranstaltung_id === null || $student_uid === null) - return success(); - $result = $this->StudentModel->load([$student_uid]); - if (isError($result)) - return $result; - if (!hasData($result)) - return error('Fehler beim Ermitteln des Studenten'); - $student = current(getData($result)); - - if ($this->permissionlib->isBerechtigt('admin', 'suid', $student->studiengang_kz)) - return success(); - if ($this->permissionlib->isBerechtigt('assistenz', 'suid', $student->studiengang_kz)) - return success(); - - $result = $this->StudienplanModel->getAllOesForLv($lehrveranstaltung_id); - if (isError($result)) - return $result; - $oes = getData($result) ?: []; - $result = $this->LehrveranstaltungModel->getStg($lehrveranstaltung_id); - if (isError($result)) - return $result; - if (hasData($result)) - $oes[] = current(getData($result)); - - foreach ($oes as $oe) { - if ($this->permissionlib->isBerechtigt('admin', 'suid', $oe->oe_kurzbz)) - return success(); - if ($this->permissionlib->isBerechtigt('assistenz', 'suid', $oe->oe_kurzbz)) - return success(); - } - - return error('Forbidden'); - } -} diff --git a/application/controllers/jobs/AnrechnungJob.php b/application/controllers/jobs/AnrechnungJob.php index 5784830b6..52bf972e3 100644 --- a/application/controllers/jobs/AnrechnungJob.php +++ b/application/controllers/jobs/AnrechnungJob.php @@ -195,10 +195,10 @@ class AnrechnungJob extends JOB_Controller $studiengang_bezeichnung = $this->StudiengangModel->load($studiengang_kz)->retval[0]->stg_bezeichnung; // Get STGL mail address - $stglMailReceiver_arr = self::_getSTGLMailAddress($studiengang_kz); + $stglMailReceiver_arr = $this->_getSTGLMailAddress($studiengang_kz); // Get HTML table with new Anrechnungen of that STG plus amount of them - list ($anrechnungen_amount, $anrechnungen_table) = self::_getSTGLMailDataTable($studiengang_kz, $anrechnungen); + list ($anrechnungen_amount, $anrechnungen_table) = $this->_getSTGLMailDataTable($studiengang_kz, $anrechnungen); // Link to Antrag genehmigen dashboard $url = @@ -514,8 +514,6 @@ html; 'vorname' => $stgl->vorname ); } - - return $stglMailAdress_arr; } // If not available, get assistance mail address else @@ -524,12 +522,13 @@ html; if (hasData($result)) { - return array( - $result->retval[0]->email, - '' + $stglMailAdress_arr[]= array( + 'to' => $result->retval[0]->email, + 'vorname' => '' ); } } + return $stglMailAdress_arr; } // Build HTML table with yesterdays new Anrechnungen of the given STG diff --git a/application/controllers/jobs/AntragJob.php b/application/controllers/jobs/AntragJob.php index 46a31f3d6..11b950174 100644 --- a/application/controllers/jobs/AntragJob.php +++ b/application/controllers/jobs/AntragJob.php @@ -183,8 +183,8 @@ class AntragJob extends JOB_Controller $data, $to, 'Anträge - Aktion(en) erforderlich', - DEFAULT_SANCHO_HEADER_IMG, - DEFAULT_SANCHO_FOOTER_IMG, + '', + '', '', $cc )) diff --git a/application/controllers/jobs/OneTimeMessages.php b/application/controllers/jobs/OneTimeMessages.php index 525f63c3b..0e49ca8a5 100644 --- a/application/controllers/jobs/OneTimeMessages.php +++ b/application/controllers/jobs/OneTimeMessages.php @@ -52,6 +52,7 @@ class OneTimeMessages extends JOB_Controller JOIN public.tbl_prestudentstatus ps USING (prestudent_id) JOIN public.tbl_studiengang s USING (studiengang_kz) WHERE get_rolle_prestudent(ps.prestudent_id, NULL) = \'Wartender\' + AND ps.status_kurzbz = \'Wartender\' AND ps.studiensemester_kurzbz = ? AND ps.datum <= NOW() - \''.$days.' days\'::interval AND s.typ = ? diff --git a/application/controllers/jobs/ReihungstestJob.php b/application/controllers/jobs/ReihungstestJob.php index b55287439..6dd214fbb 100644 --- a/application/controllers/jobs/ReihungstestJob.php +++ b/application/controllers/jobs/ReihungstestJob.php @@ -431,8 +431,8 @@ class ReihungstestJob extends JOB_Controller $mailcontent_data_arr, $applicant->email, 'Ihre Anmeldung zum Reihungstest - Reminder / Your registration for the placement test - Reminder', - DEFAULT_SANCHO_HEADER_IMG, - DEFAULT_SANCHO_FOOTER_IMG, + '', + '', $from, '', $bcc); @@ -821,7 +821,7 @@ class ReihungstestJob extends JOB_Controller JOIN lehre.tbl_studienordnung USING (studienordnung_id) JOIN PUBLIC.tbl_studiengang ON (tbl_studienordnung.studiengang_kz = tbl_studiengang.studiengang_kz) WHERE get_rolle_prestudent (tbl_prestudent.prestudent_id, ?) IN ('Aufgenommener','Bewerber','Wartender','Abgewiesener') - AND studiensemester_kurzbz = ? + AND studiensemester_kurzbz = ? AND tbl_studiengang.typ IN ('b', 'm') ) SELECT * FROM prst @@ -861,7 +861,7 @@ class ReihungstestJob extends JOB_Controller { // Alle niedrigeren Prios laden $qryNiedrPrios = " - SELECT DISTINCT + SELECT DISTINCT ON(prestudent_id) get_rolle_prestudent (tbl_prestudent.prestudent_id, '".$row_ps->studiensemester_kurzbz."') AS laststatus, tbl_studienplan.orgform_kurzbz, tbl_person.nachname, @@ -876,11 +876,11 @@ class ReihungstestJob extends JOB_Controller JOIN PUBLIC.tbl_studiengang ON (tbl_prestudent.studiengang_kz = tbl_studiengang.studiengang_kz) WHERE tbl_prestudent.person_id = ".$row_ps->person_id." AND tbl_prestudent.prestudent_id != ".$row_ps->prestudent_id." - AND get_rolle_prestudent (tbl_prestudent.prestudent_id, '".$row_ps->studiensemester_kurzbz."') IN ('Aufgenommener','Bewerber','Wartender') + AND get_rolle_prestudent (tbl_prestudent.prestudent_id, '".$row_ps->studiensemester_kurzbz."') IN ('Aufgenommener','Bewerber','Wartender', 'Student') AND studiensemester_kurzbz = '".$row_ps->studiensemester_kurzbz."' AND tbl_studiengang.typ IN ('b', 'm') AND priorisierung > ".$row_ps->priorisierung." - ORDER BY studiengang_kz, laststatus + ORDER BY prestudent_id, studiengang_kz, laststatus, tbl_prestudentstatus.datum DESC "; // Wenn der letzte Status "Aufgenommener" ist, alle niedrigeren Prios auf "Abgewiesen" setzen @@ -894,12 +894,22 @@ class ReihungstestJob extends JOB_Controller { foreach ($resultNiedrPrios->retval as $rowNiedrPrios) { - // nur Info wenn aufgenommen oder master - if ($rowNiedrPrios->laststatus == 'Aufgenommener' || $rowNiedrPrios->studiengang_typ == 'm') + // nur Info wenn aufgenommen/student oder master + if ($rowNiedrPrios->laststatus == 'Aufgenommener' || $rowNiedrPrios->laststatus == 'Student' || $rowNiedrPrios->studiengang_typ == 'm') { - // Mail zur Info an Assistenz schicken, dass in höherer Prio aufgenommen wurde - $mailArray[$rowNiedrPrios->studiengang_kz][$rowNiedrPrios->orgform_kurzbz]['AufnahmeHoeherePrio'][] - = $rowNiedrPrios->nachname.' '.$rowNiedrPrios->vorname.' ('.$rowNiedrPrios->prestudent_id.')'; + + if ($rowNiedrPrios->laststatus == 'Aufgenommener') + { + // Mail zur Info an Assistenz schicken, dass in höherer Prio aufgenommen wurde + $mailArray[$rowNiedrPrios->studiengang_kz][$rowNiedrPrios->orgform_kurzbz]['AufnahmeHoeherePrio'][] + = $rowNiedrPrios->nachname.' '.$rowNiedrPrios->vorname.' ('.$rowNiedrPrios->prestudent_id.')'; + } + else if ($rowNiedrPrios->laststatus == 'Student') + { + $mailArray[$rowNiedrPrios->studiengang_kz][$rowNiedrPrios->orgform_kurzbz]['StudentHoeherePrio'][] + = $rowNiedrPrios->nachname.' '.$rowNiedrPrios->vorname.' ('.$rowNiedrPrios->prestudent_id.')'; + } + } elseif ($rowNiedrPrios->laststatus == 'Bewerber' && $row_ps->prestudenstatus_datum > $rowNiedrPrios->datum) { @@ -966,7 +976,7 @@ class ReihungstestJob extends JOB_Controller FROM public.tbl_konto WHERE person_id = " . $row_ps->person_id . " AND studiensemester_kurzbz = '" . $row_ps->studiensemester_kurzbz . "' - AND buchungstyp_kurzbz = 'StudiengebuehrAnzahlung'"; + AND buchungstyp_kurzbz IN ('StudiengebuehrAnzahlung','KautionDrittStaat')"; $resultKautionExists = $db->execReadOnlyQuery($qryKautionExists); if (hasdata($resultKautionExists)) @@ -1061,6 +1071,20 @@ class ReihungstestJob extends JOB_Controller $mailcontent .= ''; $content = true; } + if (isset($value['StudentHoeherePrio']) && !isEmptyArray($value['StudentHoeherePrio'])) + { + $mailcontent .= '
+ Folgende Studenten wurden in einem höher priorisierten Studiengang aufgenommen:
'; + $mailcontent .= '| '.$bewerber.' |
diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php
index 36de01a4a..2f33bc82e 100644
--- a/application/core/DB_Model.php
+++ b/application/core/DB_Model.php
@@ -991,14 +991,17 @@ class DB_Model extends CI_Model
// Find and replace all the occurrences of the provided encrypted columns
// with the postgresql decryption function
- $query = str_replace(
- $encryptedColumn,
- sprintf(
- self::CRYPT_WHERE_TEMPLATE,
- $encryptedColumn,
- $decryptionPassword,
- $definition[self::CRYPT_CAST]
- ),
+ $query = preg_replace_callback(
+ '/(?load->model('person/Notizdokument_model', 'NotizdokumentModel');
$this->NotizdokumentModel->addJoin('campus.tbl_dms_version', 'dms_id');
diff --git a/application/core/Tag_Controller.php b/application/core/Tag_Controller.php
index 6f6cef31b..10e54780e 100644
--- a/application/core/Tag_Controller.php
+++ b/application/core/Tag_Controller.php
@@ -33,22 +33,30 @@ class Tag_Controller extends FHCAPI_Controller
public function getTag()
{
+ $language = $this->_getLanguageIndex();
$id = $this->input->get('id');
$this->NotizModel->addSelect(
- 'tbl_notiz.titel,
+ "tbl_notiz.titel,
tbl_notiz.text,
- array_to_json(bezeichnung_mehrsprachig::varchar[])->>0 as bezeichnung,
+ array_to_json(bezeichnung_mehrsprachig::varchar[])->>". $language. " as bezeichnung,
tbl_notiz.notiz_id,
tbl_notiz_typ.style,
tbl_notiz.erledigt as done,
tbl_notiz.insertamum,
tbl_notiz.updateamum,
- tbl_notiz.insertvon,
- tbl_notiz.updatevon
- '
+ (verfasserperson.vorname || ' ' || verfasserperson.nachname || ' ' || '(' || verfasserbenutzer.uid || ')') as verfasser,
+ (bearbeiterperson.vorname || ' ' || bearbeiterperson.nachname || ' ' || '(' || bearbeiterbenutzer.uid || ')') as bearbeiter
+ "
);
$this->NotizModel->addJoin('public.tbl_notiz_typ', 'public.tbl_notiz.typ = public.tbl_notiz_typ.typ_kurzbz');
+
+ $this->NotizModel->addJoin('public.tbl_benutzer verfasserbenutzer', 'tbl_notiz.verfasser_uid = verfasserbenutzer.uid', 'LEFT');
+ $this->NotizModel->addJoin('public.tbl_person verfasserperson', 'verfasserbenutzer.person_id = verfasserperson.person_id', 'LEFT');
+
+ $this->NotizModel->addJoin('public.tbl_benutzer bearbeiterbenutzer', 'tbl_notiz.verfasser_uid = bearbeiterbenutzer.uid', 'LEFT');
+ $this->NotizModel->addJoin('public.tbl_person bearbeiterperson', 'bearbeiterbenutzer.person_id = bearbeiterperson.person_id', 'LEFT');
+
$notiz = $this->NotizModel->loadWhere(array('notiz_id' => $id));
$this->terminateWithSuccess(hasData($notiz) ? getData($notiz)[0] : array());
@@ -134,7 +142,11 @@ class Tag_Controller extends FHCAPI_Controller
{
$postData = $this->getPostJson();
$updateData = $this->NotizModel->update(array('notiz_id' => $postData->id),
- array('text' => $postData->notiz)
+ array('text' => $postData->notiz,
+ 'updateamum' => date('Y-m-d H:i:s'),
+ 'updatevon' => $this->_uid,
+ 'bearbeiter_uid' => $this->_uid,
+ )
);
$this->terminateWithSuccess($updateData);
}
@@ -142,7 +154,11 @@ class Tag_Controller extends FHCAPI_Controller
{
$postData = $this->getPostJson();
$updateData = $this->NotizModel->update(array('notiz_id' => $postData->id),
- array('erledigt' => !$postData->done)
+ array('erledigt' => !$postData->done,
+ 'updateamum' => date('Y-m-d H:i:s'),
+ 'updatevon' => $this->_uid,
+ 'bearbeiter_uid' => $this->_uid,
+ )
);
$this->terminateWithSuccess($updateData);
@@ -183,5 +199,14 @@ class Tag_Controller extends FHCAPI_Controller
show_error('User authentification failed');
}
+ private function _getLanguageIndex()
+ {
+ $this->load->model('system/Sprache_model', 'SpracheModel');
+ $this->SpracheModel->addSelect('index');
+ $result = $this->SpracheModel->loadWhere(array('sprache' => getUserLanguage()));
+
+ return hasData($result) ? getData($result)[0]->index : 1;
+ }
+
}
\ No newline at end of file
diff --git a/application/helpers/hlp_sancho_helper.php b/application/helpers/hlp_sancho_helper.php
index d599e40bc..9a32f5e1a 100644
--- a/application/helpers/hlp_sancho_helper.php
+++ b/application/helpers/hlp_sancho_helper.php
@@ -23,9 +23,6 @@ if (! defined('BASEPATH')) exit('No direct script access allowed');
// Functions needed in the view FHC-Header
// ------------------------------------------------------------------------
-const DEFAULT_SANCHO_HEADER_IMG = 'sancho_header_DEFAULT.jpg';
-const DEFAULT_SANCHO_FOOTER_IMG = 'sancho_footer_DEFAULT.jpg';
-
/**
* Send single Mail with Sancho Design and Layout.
* @param string $vorlage_kurzbz Name of the template for specific mail content.
@@ -38,27 +35,88 @@ const DEFAULT_SANCHO_FOOTER_IMG = 'sancho_footer_DEFAULT.jpg';
* @param string $bcc Sets BCC of mail.
* @return void
*/
-function sendSanchoMail($vorlage_kurzbz, $vorlage_data, $to, $subject, $headerImg = DEFAULT_SANCHO_HEADER_IMG, $footerImg = DEFAULT_SANCHO_FOOTER_IMG, $from = null, $cc = null, $bcc = null)
+function sendSanchoMail(
+ $vorlage_kurzbz,
+ $vorlage_data,
+ $to,
+ $subject,
+ $headerImg = '',
+ $footerImg = '',
+ $from = null,
+ $cc = null,
+ $bcc = null
+)
{
$ci =& get_instance();
$ci->load->library('email');
$ci->load->library('MailLib');
- $sanchoHeader_img = 'skin/images/sancho/'. $headerImg;
- $sanchoFooter_img = 'skin/images/sancho/'. $footerImg;
+ $sancho_mail_config = $ci->config->item('mail');
+
if ($from == '')
{
- $from = 'sancho@'.DOMAIN;
+ $from = ((isset($sancho_mail_config['sancho_mail_default_sender'])
+ && $sancho_mail_config['sancho_mail_default_sender'])
+ ? $sancho_mail_config['sancho_mail_default_sender']
+ : 'noreply')
+ . '@' . DOMAIN;
}
// Embed sancho header and footer image
// reset important to ensure embedding of images when called in a loop
$ci->email->clear(true); // clear vars and attachments
- $ci->email->attach($sanchoHeader_img);
- $ci->email->attach($sanchoFooter_img);
- $cid_header = $ci->email->attachment_cid($sanchoHeader_img); // sets unique content id for embedding
- $cid_footer = $ci->email->attachment_cid($sanchoFooter_img); // sets unique content id for embedding
+
+ $cid_header = '';
+ $cid_footer = '';
+
+ if (isset($sancho_mail_config['sancho_mail_use_images']) && $sancho_mail_config['sancho_mail_use_images'])
+ {
+ $sanchoHeader_img = '';
+ $sanchoFooter_img = '';
+
+ if (isset($headerImg) && $headerImg != '')
+ {
+ // use provided header image
+ $sanchoHeader_img = $headerImg;
+ }
+ elseif (isset($sancho_mail_config['sancho_mail_header_img']) && $sancho_mail_config['sancho_mail_header_img'])
+ {
+ // use default header image
+ $sanchoHeader_img = $sancho_mail_config['sancho_mail_header_img'];
+ }
+
+ if (isset($footerImg) && $footerImg != '')
+ {
+ // use provided footer image
+ $sanchoFooter_img = $footerImg;
+ }
+ elseif (isset($sancho_mail_config['sancho_mail_footer_img']) && $sancho_mail_config['sancho_mail_footer_img'])
+ {
+ // use default footer image
+ $sanchoFooter_img = $sancho_mail_config['sancho_mail_footer_img'];
+ }
+
+ // add image file paths
+ if (isset($sancho_mail_config['sancho_mail_img_path']))
+ {
+ if ($sanchoHeader_img != '')
+ {
+ $sanchoHeader_img = $sancho_mail_config['sancho_mail_img_path'].$sanchoHeader_img;
+ }
+
+ if ($sanchoFooter_img != '')
+ {
+ $sanchoFooter_img = $sancho_mail_config['sancho_mail_img_path'].$sanchoFooter_img;
+ }
+ }
+
+ // attach header and footer
+ $ci->email->attach($sanchoHeader_img, 'inline');
+ $ci->email->attach($sanchoFooter_img, 'inline');
+ $cid_header = $ci->email->attachment_cid($sanchoHeader_img); // sets unique content id for embedding
+ $cid_footer = $ci->email->attachment_cid($sanchoFooter_img); // sets unique content id for embedding
+ }
// Set specific mail content into specific content template
$content = _parseMailContent($vorlage_kurzbz, $vorlage_data);
@@ -74,7 +132,18 @@ function sendSanchoMail($vorlage_kurzbz, $vorlage_data, $to, $subject, $headerIm
$body = _parseMailContent('Sancho_Mail_Template', $layout);
// Send mail
- return $ci->maillib->send($from, $to, $subject, $body, $alias = '', $cc, $bcc, $altMessage = '', $bulk = true, $autogenerated = true);
+ return $ci->maillib->send(
+ $from,
+ $to,
+ $subject,
+ $body,
+ '', // alias
+ $cc,
+ $bcc,
+ '', // altMessage
+ true, // bulk
+ true // autogenerated
+ );
}
/**
diff --git a/application/libraries/DocumentExportLib.php b/application/libraries/DocumentExportLib.php
new file mode 100644
index 000000000..595ac461a
--- /dev/null
+++ b/application/libraries/DocumentExportLib.php
@@ -0,0 +1,714 @@
+vorlage_kurzbz, $oe_kurzbz, $version);
+ * $doc->setFilename($filename);
+ * $doc->addDataXML($data);
+ * $doc->addImage($imagepath, $imagename, $imagecontenttype);
+ * $doc->create($outputformat);
+ * $doc->output(true);
+ * $doc->close();
+ *
+ * New:
+ * $xml_data = $this->documentexportlib->getDataXML($data);
+ * $images = [[
+ * 'path' => $imagepath,
+ * 'name' => $imagename,
+ * 'contenttype' => $imagecontenttype
+ * ]];
+ * $this->documentexportlib->showContent(
+ * $filename,
+ * $vorlage,
+ * $xml_data,
+ * $oe_kurzbz,
+ * $version,
+ * $outputformat,
+ * null,
+ * null,
+ * $images
+ * );
+ */
+class DocumentExportLib
+{
+ private $unoconv_version;
+
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ // Gets CI instance
+ $this->ci =& get_instance();
+
+ // Load Phrases
+ $this->ci->load->library('PhrasesLib', ['document_export', null], 'documentExportPhrases');
+
+ // Which document converter has to be used
+ if (defined('DOCSBOX_ENABLED') && DOCSBOX_ENABLED === true)
+ {
+ // Use docsbox!!
+ }
+ else
+ {
+ exec('unoconv --version', $ret_arr);
+
+ if(isset($ret_arr[0]))
+ {
+ $hlp = explode(' ', $ret_arr[0]);
+ if(isset($hlp[1]))
+ {
+ $this->unoconv_version = $hlp[1];
+ }
+ else
+ show_error($this->ci->documentExportPhrases->t("document_export", "error_unoconv_version"));
+ }
+ else
+ show_error($this->ci->documentExportPhrases->t("document_export", "error_unoconv"));
+ }
+ }
+
+ /**
+ * Laedt die XML Daten fuer die XSL Transformation anhand eines Arrays
+ *
+ * @param array $data Array mit Daten
+ * @param string $root Bezeichnung des Root Nodes
+ *
+ * @return DOMDocument
+ */
+ public function getDataArray($data, $root)
+ {
+ $xml_data = new DOMDocument();
+ $xml_data->loadXML($this->convertArrayToXML($data, $root));
+ return $xml_data;
+ }
+
+ /**
+ * XML Daten fuer die XSL Transformation
+ *
+ * @param string $xml
+ *
+ * @return DOMDocument
+ */
+ public function getDataXML($xml)
+ {
+ $xml_data = new DOMDocument();
+ $xml_data->loadXML($xml);
+ return $xml_data;
+ }
+
+ /**
+ * URL zu XML Datei die fuer XSLTransformation verwendet werden soll
+ *
+ * @param string $xml URL to XML
+ * @param string $params GET parameter
+ *
+ * @return stdClass
+ */
+ public function getDataURL($xml, $params)
+ {
+ $xml_found = false;
+
+ $aktive_addons = array_filter(array_map('trim', explode(";", ACTIVE_ADDONS)));
+ foreach($aktive_addons as $addon) {
+ $xmlfile = DOC_ROOT . 'addons/' . $addon . '/rdf/' . $xml;
+ if (file_exists($xmlfile)) {
+ $xml_found = true;
+ $xml_url = XML_ROOT . '../addons/' . $addon . '/rdf/' . $xml . '?' . $params;
+ break;
+ }
+ }
+ if (!$xml_found)
+ $xml_url = XML_ROOT . $xml . '?' . $params;
+
+
+ // Load the XML source
+ $xml_data = new DOMDocument;
+
+ if (!$xml_data->load($xml_url))
+ return error($this->ci->documentExportPhrases->t("document_export", "error_xml_load", [
+ "url" => $xml_url,
+ "xml" => $xml,
+ "params" => $params
+ ]));
+
+ return success($xml_data);
+ }
+
+ /**
+ * Adds a XML Tag for signatur to the document
+ *
+ * @param DomDocument $xml_data
+ *
+ * @return void
+ */
+ protected function addSignToData($xml_data)
+ {
+ $signblock = $xml_data->createElement("signed", "true");
+ $xml_data->documentElement->appendChild($signblock);
+ }
+
+ /**
+ * Adds a XML Tag for archive to the document
+ *
+ * @param DomDocument $xml_data
+ *
+ * @return void
+ */
+ public function addArchiveToData($xml_data)
+ {
+ $archiv = $xml_data->createElement("archivierbar", "true");
+ $xml_data->documentElement->appendChild($archiv);
+ }
+
+ /**
+ * Get the contents of a Document
+ *
+ * @param stdClass $vorlage A db entry from tbl_vorlage
+ * @param DomDocument $xml_data
+ * @param string $oe_kurzbz
+ * @param integer|null $version (optional)
+ * @param string $outputformat (optional)
+ * @param string $sign_user (optional) Must be a valid uid
+ * @param string $sign_profile (optional) Signatureprofile for signing
+ * @param array $images (optional) Each element should have a property path, name & contenttype which are all strings
+ *
+ * @return stdClass
+ */
+ public function getContent(
+ $vorlage,
+ $xml_data,
+ $oe_kurzbz,
+ $version = null,
+ $outputformat = null,
+ $sign_user = null,
+ $sign_profile = null,
+ $images = []
+ ) {
+ $source_folder = getcwd();
+ $temp_folder = sys_get_temp_dir() . '/fhcunoconv-' . uniqid();
+
+ $outputformat = $this->getDefaultOutputFormat($outputformat, $vorlage->mimetype);
+
+ $result = $this->createAndSignContent(
+ $temp_folder,
+ $outputformat,
+ $vorlage,
+ $oe_kurzbz,
+ $version,
+ $xml_data,
+ $images,
+ $sign_user,
+ $sign_profile
+ );
+ if (isError($result)) {
+ $this->close($temp_folder, $source_folder);
+ return $result;
+ }
+ $temp_filename = getData($result);
+
+ $fsize = filesize($temp_filename);
+ $handle = fopen($temp_filename, 'r');
+ if (!$handle)
+ return error($this->ci->documentExportPhrases->t("document_export", "error_file_load"));
+ $result = fread($handle, $fsize);
+ fclose($handle);
+
+ $this->close($temp_folder, $source_folder);
+
+ return success($result);
+ }
+
+ /**
+ * Sets the headers and displays the Document.
+ * On failure the exit() function will be called
+ *
+ * @param string $filename
+ * @param stdClass $vorlage A db entry from tbl_vorlage
+ * @param DomDocument $xml_data
+ * @param string $oe_kurzbz
+ * @param integer|null $version (optional)
+ * @param string $outputformat (optional)
+ * @param string $sign_user (optional) Must be a valid uid
+ * @param string $sign_profile (optional) Signatureprofile for signing
+ * @param array $images (optional) Each element should have a property path, name & contenttype which are all strings
+ *
+ * @return void
+ */
+ public function showContent(
+ $filename,
+ $vorlage,
+ $xml_data,
+ $oe_kurzbz,
+ $version = null,
+ $outputformat = null,
+ $sign_user = null,
+ $sign_profile = null,
+ $images = []
+ ) {
+ $source_folder = getcwd();
+ $temp_folder = sys_get_temp_dir() . '/fhcunoconv-' . uniqid();
+
+ $outputformat = $this->getDefaultOutputFormat($outputformat, $vorlage->mimetype);
+
+ $result = $this->createAndSignContent(
+ $temp_folder,
+ $outputformat,
+ $vorlage,
+ $oe_kurzbz,
+ $version,
+ $xml_data,
+ $images,
+ $sign_user,
+ $sign_profile
+ );
+ if (isError($result)) {
+ $this->close($temp_folder, $source_folder);
+ exit(getError($result));
+ }
+ $temp_filename = getData($result);
+
+ $fsize = filesize($temp_filename);
+ $handle = fopen($temp_filename, 'r');
+ if (!$handle) {
+ $this->close($temp_folder, $source_folder);
+ exit($this->ci->documentExportPhrases->t("document_export", "error_file_load"));
+ }
+
+ if (headers_sent()) {
+ $this->close($temp_folder, $source_folder);
+ exit($this->ci->documentExportPhrases->t("document_export", "error_headers"));
+ }
+
+ switch ($outputformat) {
+ case 'pdf':
+ header('Content-type: application/pdf');
+ header('Content-Disposition: attachment; filename="' . $filename . '.pdf"');
+ header('Content-Length: ' . $fsize);
+ break;
+
+ case 'doc':
+ header('Content-type: application/vnd.ms-word');
+ header('Content-Disposition: attachment; filename="' . $filename . '.doc"');
+ header('Content-Length: ' . $fsize);
+ break;
+
+ case 'odt':
+ header('Content-type: application/vnd.oasis.opendocument.text');
+ header('Content-Disposition: attachment; filename="' . $filename . '.odt"');
+ header('Content-Length: ' . $fsize);
+ break;
+ default:
+ $this->close($temp_folder, $source_folder);
+ exit($this->ci->documentExportPhrases->t("document_export", "error_outputformat_missing"));
+ }
+
+ while (!feof($handle)) {
+ echo fread($handle, 8192);
+ }
+ fclose($handle);
+
+ $this->close($temp_folder, $source_folder);
+ }
+
+ /**
+ * Helper function for getContent and showContent.
+ * Creates the temp folder and calls create and sign functions.
+ *
+ * @param string $temp_folder
+ * @param string $outputformat
+ * @param stdClass $vorlage
+ * @param string $oe_kurzbz
+ * @param integer $version
+ * @param DomDocument $xml_data
+ * @param array $images Each element should have a property path, name and contenttype which are all strings
+ * @param string $sign_user Must be a valid uid
+ * @param string $sign_profile Signatureprofile for signing
+ *
+ * @return stdClass
+ */
+ protected function createAndSignContent(
+ $temp_folder,
+ $outputformat,
+ $vorlage,
+ $oe_kurzbz,
+ $version,
+ $xml_data,
+ $images,
+ $sign_user,
+ $sign_profile
+ ) {
+ mkdir($temp_folder);
+ chdir($temp_folder);
+
+ $this->ci->load->model('system/Vorlagestudiengang_model', 'VorlagestudiengangModel');
+
+ $result = $this->ci->VorlagestudiengangModel->getCurrent($vorlage->vorlage_kurzbz, $oe_kurzbz, $version);
+ if (isError($result))
+ return $result;
+ if (!hasData($result))
+ return error($this->ci->documentExportPhrases->t("document_export", "error_template_missing"));
+ $vorlage_stg = current(getData($result));
+ foreach ($vorlage_stg as $k => $v)
+ $vorlage->$k = $v;
+
+ $result = $this->create($temp_folder, $outputformat, $vorlage, $xml_data, $images);
+ if (isError($result))
+ return $result;
+
+ $temp_filename = getData($result);
+
+ if ($sign_user) {
+ $this->addSignToData($xml_data);
+
+ $result = $this->sign($temp_folder, $temp_filename, $outputformat, $sign_user, $sign_profile);
+ if (isError($result))
+ return $result;
+
+ $temp_filename = getData($result);
+ }
+
+ return success($temp_filename);
+ }
+
+ /**
+ * Helper function for createAndSignContent.
+ * Creates the files in the temp folder.
+ *
+ * @param string $temp_folder
+ * @param string $outputformat
+ * @param stdClass $vorlage
+ * @param DomDocument $xml_data
+ * @param array $images Each element should have a property path, name and contenttype which are all strings
+ *
+ * @return stdClass
+ */
+ protected function create($temp_folder, $outputformat, $vorlage, $xml_data, $images)
+ {
+ $content_xsl = new DOMDocument();
+ if (!$content_xsl->loadXML($vorlage->text))
+ return error($this->ci->documentExportPhrases->t("document_export", "error_xsl_load"));
+
+ $proc = new XSLTProcessor();
+ $proc->importStyleSheet($content_xsl);
+
+ $contentbuffer = $proc->transformToXml($xml_data);
+
+ file_put_contents($temp_folder . '/content.xml', $contentbuffer);
+
+ if ($xml_data->firstChild->tagName == 'error')
+ return error($xml_data->firstChild->textContent);
+
+ // styles.xml erstellen
+ if ($vorlage->style) {
+ $styles_xsl = new DOMDocument();
+ if (!$styles_xsl->loadXML($vorlage->style))
+ return error($this->ci->documentExportPhrases->t("document_export", "error_styles_load"));
+ $style_proc = new XSLTProcessor();
+ $style_proc->importStyleSheet($styles_xsl);
+
+ $stylesbuffer = $style_proc->transformToXml($xml_data);
+
+ file_put_contents($temp_folder . '/styles.xml', $stylesbuffer);
+ }
+
+ // Template holen
+ $vorlage_found = false;
+ $vorlage_filename = $vorlage->vorlage_kurzbz . ($vorlage->mimetype == 'application/vnd.oasis.opendocument.spreadsheet' ? '.ods' : '.odt');
+
+ $aktive_addons = array_filter(array_map('trim', explode(";", ACTIVE_ADDONS)));
+ foreach($aktive_addons as $addon) {
+ $zipfile = DOC_ROOT . 'addons/' . $addon . '/system/vorlage_zip/' . $vorlage_filename;
+
+ if (file_exists($zipfile)) {
+ $vorlage_found = true;
+ break;
+ }
+ }
+ if (!$vorlage_found)
+ $zipfile = DOC_ROOT . 'system/vorlage_zip/' . $vorlage_filename;
+
+ $tempname_zip = $temp_folder . '/out.zip';
+
+ if (!copy($zipfile, $tempname_zip))
+ return error($this->ci->documentExportPhrases->t("document_export", "error_file_copy"));
+
+ exec("zip $tempname_zip content.xml");
+ if (!is_null($styles_xsl))
+ exec("zip $tempname_zip styles.xml");
+
+ // bilder hinzufuegen
+ if (count($images) > 0)
+ {
+ // Unterordner fuer die Bilder erstellen
+ mkdir('Pictures');
+
+ // Manifest Datei holen
+ exec('unzip ' . $tempname_zip . ' META-INF/manifest.xml');
+
+ // Bild zur Manifest Datei hinzufuegen
+ $manifest = file_get_contents('META-INF/manifest.xml');
+
+ $manifest_xml = new DOMDocument;
+ if (!$manifest_xml->loadXML($manifest))
+ return error($this->ci->documentExportPhrases->t("document_export", "error_manifest"));
+
+ //root-node holen
+ $root = $manifest_xml->getElementsByTagName('manifest')->item(0);
+
+ foreach ($images as $bild) {
+ copy($bild['path'], 'Pictures/' . $bild['name']);
+
+ //Neues Element unterhalb des Root Nodes anlegen
+ $node = $manifest_xml->createElement("manifest:file-entry");
+ $node->setAttribute("manifest:full-path", 'Pictures/' . $bild['name']);
+ $node->setAttribute("manifest:media-type", $bild['contenttype']);
+ $root->appendChild($node);
+ }
+
+ $out = $manifest_xml->saveXML();
+
+ //geaenderte Manifest Datei speichern und wieder ins Zip packen
+ file_put_contents('META-INF/manifest.xml', $out);
+ exec('zip ' . $tempname_zip . ' META-INF/*');
+
+ // Bilder zum ZIP-File hinzufuegen
+ exec('zip ' . $tempname_zip . ' Pictures/*');
+ }
+
+ clearstatcache();
+
+ switch ($outputformat) {
+ case 'pdf':
+ case 'doc':
+ $ret = 0;
+ $temp_filename = $temp_folder . '/out.' . $outputformat;
+
+ if (defined('DOCSBOX_ENABLED') && DOCSBOX_ENABLED === true) {
+ // Use docsbox
+
+ $this->ci->load->library("DocsboxLib");
+
+ $docboxlib = get_class($this->ci->docboxlib);
+
+ $ret = $docboxlib::convert($tempname_zip, $temp_filename, $outputformat);
+ } else {
+ // Use unoconv
+
+ // Unoconv Version 0.6 hat eine Bug wodurch die Berechtigungen des PDF/Doc nicht korrekt gesetzt
+ // werden. Deshalb wird dies hier speziell behandelt.
+ // Die 2. Variante hat den Vorteil dass hier eine bessere Fehlerbehandlung moeglich ist
+ if ($this->unoconv_version == '0.6')
+ $command = 'unoconv -e IsSkipEmptyPages=false -f ' . $outputformat . ' %2$s > %1$s';
+ else
+ $command = 'unoconv -e IsSkipEmptyPages=false -f ' . $outputformat . ' --output %s %s 2>&1';
+
+ $command = sprintf($command, $temp_filename, $tempname_zip);
+
+ exec($command, $out, $ret);
+ }
+
+ if ($ret)
+ return error($this->ci->documentExportPhrases->t("document_export", "error_conv_timeout"));
+ break;
+ case 'odt':
+ default:
+ $temp_filename = $tempname_zip;
+ }
+
+ return success($temp_filename);
+ }
+
+ /**
+ * Helper function for createAndSignContent.
+ * Signs the main file in the temp folder.
+ *
+ * @param string $temp_folder
+ * @param string $temp_filename
+ * @param string $outputformat
+ * @param string $user Must be a valid uid
+ * @param string $profile Signatureprofile for signing
+ *
+ * @return stdClass
+ */
+ protected function sign($temp_folder, $temp_filename, $outputformat, $user, $profile)
+ {
+ if ($outputformat != 'pdf')
+ return error($this->ci->documentExportPhrases->t("document_export", "error_sign_pdf"));
+
+ // Load the File
+ $file_data = file_get_contents($temp_filename);
+
+ $data = new stdClass();
+ $data->document = base64_encode($file_data);
+
+ // Signatur Profil
+ if (!is_null($profile))
+ $data->profile = $profile;
+ else
+ $data->profile = SIGNATUR_DEFAULT_PROFILE;
+
+ // Username des Endusers der die Signatur angefordert hat
+ $data->user = $user;
+
+ $ch = curl_init();
+
+ curl_setopt($ch, CURLOPT_URL, SIGNATUR_URL . '/' . SIGNATUR_SIGN_API);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 7);
+ curl_setopt($ch, CURLOPT_USERAGENT, "FH-Complete");
+
+ // SSL Zertifikatsprüfung deaktivieren
+ // Besser ist es das Zertifikat am Server zu installieren!
+ //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+ //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+
+ $data_string = json_encode($data, JSON_FORCE_OBJECT);
+
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, [
+ 'Content-Type: application/json',
+ 'Content-Length:' . mb_strlen($data_string),
+ 'Authorization: Basic ' . base64_encode(SIGNATUR_USER . ":" . SIGNATUR_PASSWORD)
+ ]);
+
+ $result = curl_exec($ch);
+ if (curl_errno($ch)) {
+ curl_close($ch);
+ return error($this->ci->documentExportPhrases->t("document_export", "error_sign_timeout"));
+ }
+ curl_close($ch);
+ $resultdata = json_decode($result);
+
+ // If it is success
+ if (isset($resultdata->error) && $resultdata->error == 0) {
+ $signed_filename = $temp_folder . '/signed.pdf';
+ file_put_contents($signed_filename, base64_decode($resultdata->retval));
+ return success($signed_filename);
+ }
+
+ // otherwise if it is an error
+ return error($resultdata->retval ?? $this->ci->documentExportPhrases->t("global", "unknown_error", ["error" => $result]));
+ }
+
+ /**
+ * Deletes all files in the $temp_folder and changes back to the source_folder
+ *
+ * @param string $temp_folder
+ * @param string $source_folder
+ *
+ * @return void
+ */
+ protected function close($temp_folder, $source_folder)
+ {
+ $files = glob($temp_folder . '/*'); // get all file names
+ foreach ($files as $file)
+ if (is_file($file))
+ unlink($file);
+
+ chdir($source_folder);
+ rmdir($temp_folder);
+ }
+
+ /**
+ * Convert an array to XML
+ *
+ * @param array $data
+ * @param string $root
+ * @param SimpleXMLElement $xml_data
+ *
+ * @return string|boolean
+ */
+ private function convertArrayToXML($data, $root = null, $xml_data = null)
+ {
+ $_xml_data = $xml_data;
+ if ($_xml_data === null)
+ $_xml_data = new SimpleXMLElement($root !== null ? '<' . $root . ' />' : '