diff --git a/application/controllers/lehre/anrechnung/ApproveAnrechnungDetail.php b/application/controllers/lehre/anrechnung/ApproveAnrechnungDetail.php new file mode 100644 index 000000000..72773b11c --- /dev/null +++ b/application/controllers/lehre/anrechnung/ApproveAnrechnungDetail.php @@ -0,0 +1,421 @@ + 'lehre/anrechnung_empfehlen:rw', + 'download' => 'lehre/anrechnung_empfehlen:rw', + 'recommend' => 'lehre/anrechnung_empfehlen:rw', + 'dontRecommend' => 'lehre/anrechnung_empfehlen:rw' + ) + ); + + // Load models + $this->load->model('education/Anrechnung_model', 'AnrechnungModel'); + $this->load->model('education/Anrechnungstatus_model', 'AnrechnungstatusModel'); + $this->load->model('content/DmsVersion_model', 'DmsVersionModel'); + $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + $this->load->model('person/Notiz_model', 'NotizModel'); + $this->load->model('person/Person_model', 'PersonModel'); + + // Load libraries + $this->load->library('WidgetLib'); + $this->load->library('PermissionLib'); + $this->load->library('AnrechnungLib'); + $this->load->library('DmsLib'); + + // Load helpers + $this->load->helper('form'); + $this->load->helper('url'); + $this->load->helper('hlp_sancho_helper'); + + // Load language phrases + $this->loadPhrases( + array( + 'global', + 'ui', + 'anrechnung', + 'person', + 'lehre', + 'table' + ) + ); + + $this->_setAuthUID(); + + $this->setControllerId(); + } + + public function index() + { + $anrechnung_id = $this->input->get('anrechnung_id'); + + if (!is_numeric($anrechnung_id)) + { + show_error('Missing correct parameter'); + } + + // Get Anrechung data + if (!$anrechnungData = getData($this->anrechnunglib->getAnrechnungData($anrechnung_id))) + { + show_error('Missing data for Anrechnung.'); + } + + // Get Empfehlung data + if(!$empfehlungData = getData($this->anrechnunglib->getEmpfehlungData($anrechnung_id))) + { + show_error('Missing data for recommendation'); + } + + $viewData = array( + 'antragData' => $this->anrechnunglib->getAntragData( + $student_uid = $this->PrestudentModel->getUID($anrechnungData->prestudent_id), + $anrechnungData->studiensemester_kurzbz, + $anrechnungData->lehrveranstaltung_id + ), + 'anrechnungData' => $anrechnungData, + 'empfehlungData' => $empfehlungData + ); + + $this->load->view('lehre/anrechnung/approveAnrechnungDetail.php', $viewData); + } + + /** + * Approve Anrechnungen. + */ + public function approve() + { + $data = $this->input->post('data'); + + if(isEmptyArray($data)) + { + return $this->outputJsonError('Fehler beim Übertragen der Daten.'); + } + + // Get statusbezeichnung for 'approved' + $this->AnrechnungstatusModel->addSelect('bezeichnung_mehrsprachig'); + $approved = getData($this->AnrechnungstatusModel->load('approved'))[0]; + $approved = getUserLanguage() == 'German' + ? $approved->bezeichnung_mehrsprachig[0] + : $approved->bezeichnung_mehrsprachig[1]; + + foreach ($data as $item) + { + // Approve Anrechnung + if(getData($this->anrechnunglib->approveAnrechnung($item['anrechnung_id']))) + { + $json[]= array( + 'anrechnung_id' => $item['anrechnung_id'], + 'status_kurzbz' => self::ANRECHNUNGSTATUS_APPROVED, + 'status_bezeichnung' => $approved + ); + + if(!$this->_sendSanchoMailToStudent($item['anrechnung_id'], self::ANRECHNUNGSTATUS_APPROVED)) + { + show_error('Failed sending mail'); + } + } + } + + // Output json to ajax + if (isset($json) && !isEmptyArray($json)) + { + return $this->outputJsonSuccess($json); + } + else + { + return $this->outputJsonError('Es wurden keine Anrechnungen genehmigt.'); + } + } + + /** + * Reject Anrechnungen. + */ + public function reject() + { + $data = $this->input->post('data'); + + if(isEmptyArray($data)) + { + return $this->outputJsonError('Fehler beim Übertragen der Daten.'); + } + + // Get statusbezeichnung for 'rejected' + $this->AnrechnungstatusModel->addSelect('bezeichnung_mehrsprachig'); + $rejected = getData($this->AnrechnungstatusModel->load('rejected'))[0]; + $rejected = getUserLanguage() == 'German' + ? $rejected->bezeichnung_mehrsprachig[0] + : $rejected->bezeichnung_mehrsprachig[1]; + + foreach ($data as $item) + { + // Reject Anrechnung + if(getData($this->anrechnunglib->rejectAnrechnung($item['anrechnung_id'], $item['begruendung']))) + { + $json[]= array( + 'anrechnung_id' => $item['anrechnung_id'], + 'status_kurzbz' => self::ANRECHNUNGSTATUS_REJECTED, + 'status_bezeichnung' => $rejected + ); + + if(!$this->_sendSanchoMailToStudent($item['anrechnung_id'], self::ANRECHNUNGSTATUS_REJECTED)) + { + show_error('Failed sending mail'); + } + } + } + + // Output json to ajax + if (isset($json) && !isEmptyArray($json)) + { + return $this->outputJsonSuccess($json); + } + else + { + return $this->outputJsonError('Es wurden keine Anrechnungen genehmigt.'); + } + } + + /** + * Request recommendation for Anrechnungen. + */ + public function requestRecommendation() + { + $data = $this->input->post('data'); + + if(isEmptyArray($data)) + { + return $this->outputJsonError('Fehler beim Übertragen der Daten.'); + } + + // Get statusbezeichnung for 'inProgressLektor' + $this->AnrechnungstatusModel->addSelect('bezeichnung_mehrsprachig'); + $inProgressLektor = getData($this->AnrechnungstatusModel->load('inProgressLektor'))[0]; + $inProgressLektor = getUserLanguage() == 'German' + ? $inProgressLektor->bezeichnung_mehrsprachig[0] + : $inProgressLektor->bezeichnung_mehrsprachig[1]; + + foreach ($data as $item) + { + // Approve Anrechnung + if(getData($this->anrechnunglib->requestRecommendation($item['anrechnung_id']))) + { + $json[]= array( + 'anrechnung_id' => $item['anrechnung_id'], + 'status_kurzbz' => self::ANRECHNUNGSTATUS_PROGRESSED_BY_LEKTOR, + 'status_bezeichnung' => $inProgressLektor, + 'empfehlung_anrechnung' => null + ); + } + } + + // Output json to ajax + if (isset($json) && !isEmptyArray($json)) + { + /** + * Send mails to lectors + * NOTE: mails are sent at the end to ensure sending only ONE mail to each LV-Leitung or lector + * even if they are required for more recommendations + * */ + if (!$this->_sendSanchoMailToLectors($json)) + { + show_error('Failed sending emails'); + } + + return $this->outputJsonSuccess($json); + } + else + { + return $this->outputJsonError('Es wurden keine Empfehlungen angefordert'); + } + } + + /** + * Download and open uploaded document (Nachweisdokument). + */ + public function download() + { + $dms_id = $this->input->get('dms_id'); + + if (!is_numeric($dms_id)) + { + show_error('Wrong parameter'); + } + + $this->dmslib->download($dms_id); + } + + /** + * Retrieve the UID of the logged user and checks if it is valid + */ + private function _setAuthUID() + { + $this->_uid = getAuthUID(); + + if (!$this->_uid) show_error('User authentification failed'); + } + + /** + * Send mail to student to inform if Anrechnung was approved or rejected + * @param $mail_params + */ + private function _sendSanchoMailToStudent($anrechnung_id, $status_kurzbz) + { + $result = getData($this->anrechnunglib->getStudentData($anrechnung_id))[0]; + + // Get student name and mail address + $to = $result->uid. '@'. DOMAIN; + + $anrede = $result->geschlecht == 'w' ? 'Sehr geehrte Frau ' : 'Sehr geehrter Herr '; + // Prepare mail content + $body_fields = array( + 'anrede_name' => $anrede. $result->vorname. ' '. $result->nachname, + 'lehrveranstaltung_bezeichnung' => $result->lv_bezeichnung, + 'stattgegeben_nichtstattgegeben' => $status_kurzbz == self::ANRECHNUNGSTATUS_APPROVED + ? 'stattgegeben' + : 'nicht stattgegeben' + ); + + sendSanchoMail( + 'AnrechnungGenehmigen', + $body_fields, + $to, + 'Ihr Antrag auf Anerkennung nachgewiesener Kenntnisse wurde abgeschlossen' + ); + + return true; + } + + /** + * Send mail to lectors asking for recommendation. (first to LV-Leitung, if not present to all lectors of lv) + * @param $mail_params + * @return bool + */ + private function _sendSanchoMailToLectors($mail_params) + { + // Get Lehrveranstaltungen + $anrechnung_arr = array(); + + foreach ($mail_params as $item) + { + $this->AnrechnungModel->addSelect('lehrveranstaltung_id, studiensemester_kurzbz'); + $anrechnung_arr[]= array( + 'lehrveranstaltung_id' => $this->AnrechnungModel->load($item['anrechnung_id'])->retval[0]->lehrveranstaltung_id, + 'studiensemester_kurzbz' => $this->AnrechnungModel->load($item['anrechnung_id'])->retval[0]->studiensemester_kurzbz + ); + } + + $anrechnung_arr = array_unique($anrechnung_arr, SORT_REGULAR); + + + /** + * Get lectors (prio for LV-Leitung, if not present to all lectors of LV. + * Anyway this function will receive a unique array to avoid sending more mails to one and the same lector. + * **/ + $lector_arr = $this->_getLectors($anrechnung_arr); + + // Send mail to lectors + foreach ($lector_arr as $lector) + { + $to = $lector->uid; + $vorname = $lector->vorname; + + // Get full name of stgl + $this->load->model('person/Person_model', 'PersonModel'); + if (!$stgl_name = getData($this->PersonModel->getFullName($this->_uid))) + { + show_error ('Failed retrieving person'); + } + + // Link to Antrag genehmigen + $url = + CIS_ROOT. 'cis/index.php?menu='. + CIS_ROOT. 'cis/menu.php?content_id=&content='. + CIS_ROOT. index_page(). self::REVIEW_ANRECHNUNG_URI; + + // Prepare mail content + $body_fields = array( + 'vorname' => $vorname, + 'stgl_name' => $stgl_name, + 'link' => anchor($url, 'Anrechnungsanträge Übersicht') + ); + + sendSanchoMail( + 'AnrechnungEmpfehlungAnfordern', + $body_fields, + $to, + 'Neue LV-Anrechnungsanträge benötigen Deine Empfehlung' + ); + } + return true; + } + + /** + * Get lectors (prio for LV-Leitung, if not present to all lectors of LV. + * Anyway this function will receive a unique array to avoid sending more mails to one and the same lector. + * @param $anrechnung_arr + * @return array + */ + private function _getLectors($anrechnung_arr) + { + $lector_arr = array(); + + // Get lectors + foreach($anrechnung_arr as $anrechnung) + { + $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); + $result = $this->LehrveranstaltungModel->getLecturersByLv($anrechnung['studiensemester_kurzbz'], $anrechnung['lehrveranstaltung_id']); + + if (!$result = getData($result)) + { + show_error('Failed retrieving lectors of Lehrveranstaltung'); + } + + // Check if lv has LV-Leitung + $key = array_search(true, array_column($result, 'lvleiter')); + + // If lv has LV-Leitung, keep only the one + if ($key !== false) + { + $lector_arr[]= $result[$key]; + } + // ...otherwise keep all lectors + else + { + $lector_arr = array_merge($lector_arr, $result); + } + } + + /** + * NOTE: This step is only done to make the array unique by uid, vorname and nachname in the following step + * (e.g. if same lector is ones LV-Leitung and another time not, then array_unique would leave both. + * But we wish to send only one email by to that one person) + * **/ + foreach ($lector_arr as $lector) + { + unset($lector->lvleiter); + } + + // Now make the lector array aka mail receivers unique + $lector_arr = array_unique($lector_arr, SORT_REGULAR); + + return $lector_arr; + + } + +} \ No newline at end of file diff --git a/application/libraries/AnrechnungLib.php b/application/libraries/AnrechnungLib.php index dd8b796c7..c2f7d5f4a 100644 --- a/application/libraries/AnrechnungLib.php +++ b/application/libraries/AnrechnungLib.php @@ -201,6 +201,7 @@ class AnrechnungLib $empfehlung_data->empfehlung = null; $empfehlung_data->empfehlung_von = '-'; $empfehlung_data->empfehlung_am = '-'; + $empfehlung_data->empfehlung_angefordert_am = '-'; $empfehlung_data->notiz = ''; // Begruendung, if not recommended @@ -209,6 +210,16 @@ class AnrechnungLib show_error('Failed loading Anrechnung'); } + // Get date, where recommendation was last requested + $result = $this->ci->AnrechnungModel->getLastAnrechnungstatus( + $anrechnung_id, + self::ANRECHNUNGSTATUS_PROGRESSED_BY_LEKTOR // when STLG asks for recommendation, status is set to in progress lektor + ); + if ($result = getData($result)[0]) + { + $empfehlung_data->empfehlung_angefordert_am = (new DateTime($result->insertamum))->format('d.m.Y'); + } + if (is_null($anrechnung->empfehlung_anrechnung)) { return success($empfehlung_data); diff --git a/application/views/lehre/anrechnung/approveAnrechnungDetail.php b/application/views/lehre/anrechnung/approveAnrechnungDetail.php new file mode 100644 index 000000000..4469efc7f --- /dev/null +++ b/application/views/lehre/anrechnung/approveAnrechnungDetail.php @@ -0,0 +1,204 @@ +load->view( + 'templates/FHC-Header', + array( + 'title' => $this->p->t('anrechnung', 'anrechnungenGenehmigen'), + 'jquery' => true, + 'jqueryui' => true, + 'bootstrap' => true, + 'fontawesome' => true, + 'ajaxlib' => true, + 'dialoglib' => true, + 'phrases' => array( + 'global' => array( + 'anerkennungNachgewiesenerKenntnisse', + 'antragStellen' + ), + 'ui' => array( + 'hilfeZuDieserSeite', + 'hochladen' + ), + 'person' => array( + 'student', + 'personenkennzeichen' + ), + 'lehre' => array( + 'studiensemester', + 'studiengang', + 'lehrveranstaltung', + 'ects', + 'lektor', + ) + ), + 'customCSSs' => array( + 'public/css/Tabulator.css' + ), + 'customJSs' => array( + 'public/js/bootstrapper.js', + 'public/js/lehre/anrechnung/approveAnrechnungDetail.js' + + ) + ) +); +?> + +
+| p->t('person', 'student'); ?> | +vorname . ' ' . $antragData->nachname; ?> | +
| p->t('person', 'personenkennzeichen'); ?> | +matrikelnr ?> | +
| p->t('lehre', 'studiensemester'); ?> | +studiensemester_kurzbz ?> | +
| p->t('lehre', 'studiengang'); ?> | +stg_bezeichnung ?> | +
| p->t('lehre', 'lehrveranstaltung'); ?> | +lv_bezeichnung ?> | +
| p->t('lehre', 'ects'); ?> | +ects ?> | +
| p->t('lehre', 'lektorInnen'); ?> | ++ lektoren) - 1 ?> + lektoren as $key => $lektor): ?> + vorname . ' ' . $lektor->nachname; + echo $key === $len ? '' : ', ' ?> + + | +
| p->t('anrechnung', 'herkunftDerKenntnisse'); ?> | +anmerkung ?> | +
| p->t('anrechnung', 'nachweisdokumente'); ?> | ++ dokumentname ?> + | +