diff --git a/application/controllers/system/infocenter/InfoCenter.php b/application/controllers/system/infocenter/InfoCenter.php index d5ef7854d..0fd192120 100644 --- a/application/controllers/system/infocenter/InfoCenter.php +++ b/application/controllers/system/infocenter/InfoCenter.php @@ -6,7 +6,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); * Also shows infocenter-related data for a person and its prestudents, enables document and zgv checks, * displays and saves Notizen for a person, logs infocenter-related actions for a person */ -class InfoCenter extends VileSci_Controller +class InfoCenter extends FHC_Controller { // App and Verarbeitungstaetigkeit name for logging const APP = 'infocenter'; @@ -21,12 +21,14 @@ class InfoCenter extends VileSci_Controller 'saveformalgep' => array( 'logtype' => 'Action', 'name' => 'Document formally checked', - 'message' => 'Document %s formally checked, set to %s' + 'message' => 'Document %s formally checked, set to %s', + 'success' => null ), 'savezgv' => array( 'logtype' => 'Action', 'name' => 'ZGV saved', - 'message' => 'ZGV saved for degree program %s, prestudentid %s' + 'message' => 'ZGV saved for degree program %s, prestudentid %s', + 'success' => null ), 'abgewiesen' => array( 'logtype' => 'Processstate', @@ -41,12 +43,14 @@ class InfoCenter extends VileSci_Controller 'savenotiz' => array( 'logtype' => 'Action', 'name' => 'Note added', - 'message' => 'Note with title %s was added' + 'message' => 'Note with title %s was added', + 'success' => null ), 'updatenotiz' => array( 'logtype' => 'Action', 'name' => 'Note updated', - 'message' => 'Note with title %s was updated' + 'message' => 'Note with title %s was updated', + 'success' => null ) ); private $uid; // contains the UID of the logged user @@ -473,12 +477,11 @@ class InfoCenter extends VileSci_Controller ) ); - - $json = FALSE; + $json = false; if (isSuccess($result)) { - $json = TRUE; + $json = true; //set log "Notiz updated" $this->_log($person_id, 'updatenotiz', array($titel)); @@ -543,6 +546,61 @@ class InfoCenter extends VileSci_Controller ->_display(); } + /** + * Gets the date until which a person is parked + * @param $person_id + */ + public function getParkedDate($person_id) + { + $result = $this->personloglib->getParkedDate($person_id); + + $this->output + ->set_content_type('application/json') + ->set_output(json_encode($result)); + } + + /** + * Initializes parking of a person, i.e. a person is not expected to do any actions while it is parked + */ + public function park() + { + $person_id = $this->input->post('person_id'); + $date = $this->input->post('parkdate'); + + $this->personloglib->park($person_id, date_format(date_create($date), 'Y-m-d'), self::TAETIGKEIT, self::APP, null, $this->uid); + } + + /** + * Removes parking of a person + */ + public function unPark() + { + $person_id = $this->input->post('person_id'); + + $this->personloglib->unPark($person_id); + } + + /** + * Gets the End date of the current Studienjahr + */ + public function getStudienjahrEnd() + { + $this->load->model('organisation/studienjahr_model', 'StudienjahrModel'); + + $result = $this->StudienjahrModel->getCurrStudienjahr(); + + $json = false; + + if (hasData($result)) + { + $json = $result->retval[0]->ende; + } + + $this->output + ->set_content_type('application/json') + ->set_output(json_encode($json)); + } + // ----------------------------------------------------------------------------------------------------------------- // Private methods @@ -762,7 +820,7 @@ class InfoCenter extends VileSci_Controller show_error($user_person->retval); } - $messagelink = base_url('/index.ci.php/system/Messages/write/'.$user_person->retval[0]->person_id); + $messagelink = site_url('/system/Messages/write/'.$user_person->retval[0]->person_id); $data = array ( 'lockedby' => $lockedby, @@ -898,15 +956,20 @@ class InfoCenter extends VileSci_Controller { $logdata = $this->logparams[$logname]; + $datatolog = array( + 'name' => $logdata['name'] + ); + + if (isset($logdata['message'])) + $datatolog['message'] = vsprintf($logdata['message'], $messageparams); + + if (array_key_exists('success', $logdata)) + $datatolog['success'] = true; + $this->personloglib->log( $person_id, $logdata['logtype'], - array( - 'name' => $logdata['name'], - 'message' => vsprintf($logdata['message'], - $messageparams), - 'success' => 'true' - ), + $datatolog, self::TAETIGKEIT, self::APP, null, diff --git a/application/libraries/PersonLogLib.php b/application/libraries/PersonLogLib.php index cf713825d..8145b88ac 100644 --- a/application/libraries/PersonLogLib.php +++ b/application/libraries/PersonLogLib.php @@ -7,6 +7,8 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); */ class PersonLogLib { + const PARKED_LOGNAME = 'Parked'; + /** * Constructor */ @@ -79,4 +81,101 @@ class PersonLogLib else show_error($result->retval); } + + /** + * Parks a person, i.e. marks a person so no actions are expected for the person (e.g. as a prestudent) + * Done by adding a logentry in the future + * @param $person_id + * @param $date + * @param $taetigkeit_kurzbz + * @param string $app + * @param null $oe_kurzbz + * @param null $user + * @return bool wether parking was successfull + */ + public function park($person_id, $date, $taetigkeit_kurzbz, $app = 'core', $oe_kurzbz = null, $user = null) + { + $logdata = array( + 'name' => self::PARKED_LOGNAME + ); + + $data = array( + 'person_id' => $person_id, + 'zeitpunkt' => $date, + 'taetigkeit_kurzbz' => $taetigkeit_kurzbz, + 'app' => $app, + 'oe_kurzbz' => $oe_kurzbz, + 'logtype_kurzbz' => 'Processstate', + 'logdata' => json_encode($logdata), + 'insertvon' => $user + ); + + $result = $this->ci->PersonLogModel->insert($data); + if (isSuccess($result)) + return true; + else + show_error($result->retval); + } + + /** + * Unparks a person, i.e. removes all log entries in the future + * @param $person_id + */ + public function unPark($person_id) + { + $result = $this->ci->PersonLogModel->getLogsInFuture($person_id); + + $deleted = array(); + + if (isSuccess($result)) + { + if (count($result->retval) > 0) + { + foreach ($result->retval as $log) + { + $logdata = json_decode($log->logdata); + if (isset($logdata->name) && $logdata->name === self::PARKED_LOGNAME) + { + $delresult = $this->ci->PersonLogModel->deleteLog($log->log_id); + if (isSuccess($delresult)) + $deleted[] = $log->log_id; + } + } + } + } + else + show_error($result->retval); + } + + /** + * Gets date until which a person is parked + * @param $person_id + * @return the date if person is parked, null otherwise + */ + public function getParkedDate($person_id) + { + $result = $this->ci->PersonLogModel->getLogsInFuture($person_id); + + $parkeddate = null; + + if (isSuccess($result)) + { + if (count($result->retval) > 0) + { + foreach ($result->retval as $log) + { + $logdata = json_decode($log->logdata); + if (isset($logdata->name) && $logdata->name === self::PARKED_LOGNAME) + { + $parkeddate = $log->zeitpunkt; + break; + } + } + } + } + else + show_error($result->retval); + + return $parkeddate; + } } diff --git a/application/models/organisation/Studienjahr_model.php b/application/models/organisation/Studienjahr_model.php index ace9c1525..36784a280 100644 --- a/application/models/organisation/Studienjahr_model.php +++ b/application/models/organisation/Studienjahr_model.php @@ -12,4 +12,21 @@ class Studienjahr_model extends DB_Model $this->pk = 'studienjahr_kurzbz'; $this->hasSequence = false; } + + /** + * Gets current Studienjahr, as determined by its start and enddate + * @return array|null + */ + public function getCurrStudienjahr() + { + $query = 'SELECT * + FROM public.tbl_studienjahr + JOIN public.tbl_studiensemester using(studienjahr_kurzbz) + WHERE start <= now() + AND ende >= now() + ORDER by start DESC + LIMIT 1'; + + return $this->execQuery($query); + } } diff --git a/application/models/system/PersonLog_model.php b/application/models/system/PersonLog_model.php index 02f52008c..777c6eeeb 100644 --- a/application/models/system/PersonLog_model.php +++ b/application/models/system/PersonLog_model.php @@ -90,4 +90,36 @@ class PersonLog_model extends CI_Model return success($result->result()); } + + /** + * Gets all logs with zeitpunkt > today + * @param $person_id + * @return array + */ + public function getLogsInFuture($person_id) + { + $this->db->order_by('zeitpunkt', 'DESC'); + $this->db->order_by('log_id', 'DESC'); + + $result = $this->db->get_where($this->dbTable, "person_id=".$this->db->escape($person_id)." AND zeitpunkt > now()"); + + return success($result->result()); + } + + /** + * Deletes a log + * @param $log_id + * @return array + */ + public function deleteLog($log_id) + { + $this->load->library('PermissionLib'); + if(!$this->permissionlib->isEntitled('system.tbl_log', PermissionLib::DELETE_RIGHT)) + show_error('Permission denied - You need Access to system.tbl_log'); + + $this->db->where('log_id', $log_id); + $result = $this->db->delete($this->dbTable); + + return success($result); + } } diff --git a/application/views/system/infocenter/infocenterData.php b/application/views/system/infocenter/infocenterData.php index e880068b2..68b7d28a9 100755 --- a/application/views/system/infocenter/infocenterData.php +++ b/application/views/system/infocenter/infocenterData.php @@ -151,9 +151,16 @@ ),\', \' ) AS "StgAktiv", pl.zeitpunkt AS "LockDate", - pl.lockuser as "LockUser" + pl.lockuser as "LockUser", + pd.parkdate AS "ParkDate" FROM public.tbl_person p LEFT JOIN (SELECT person_id, zeitpunkt, uid as lockuser FROM system.tbl_person_lock WHERE app = \''.$APP.'\') pl USING(person_id) + LEFT JOIN ( + SELECT person_id, zeitpunkt as parkdate + FROM system.tbl_log + WHERE logdata->>\'name\' = \'Parked\' + AND zeitpunkt > now() + ) pd USING(person_id) WHERE EXISTS( SELECT 1 @@ -204,7 +211,9 @@ ucfirst($this->p->t('lehre','studiengang')) . ' (' . $this->p->t('global','nichtGesendet') . ')', ucfirst($this->p->t('lehre','studiengang')) . ' (' . $this->p->t('global','aktiv') . ')', ucfirst($this->p->t('global','sperrdatum')), - ucfirst($this->p->t('global','gesperrtVon'))), + ucfirst($this->p->t('global','gesperrtVon')), + "ParkedDate" + ), 'formatRaw' => function($datasetRaw) { $datasetRaw->{'Details'} = sprintf( @@ -267,10 +276,20 @@ }, 'markRow' => function($datasetRaw) { + $mark = ''; + if ($datasetRaw->LockDate != null) { - return FilterWidget::DEFAULT_MARK_ROW_CLASS; + $mark = FilterWidget::DEFAULT_MARK_ROW_CLASS; } + + if ($datasetRaw->ParkDate != null) + { + //parking has prio over locking + $mark = "text-info"; + } + + return $mark; } ); diff --git a/application/views/system/infocenter/infocenterDetails.php b/application/views/system/infocenter/infocenterDetails.php index 0abe9b6b1..e8221d576 100755 --- a/application/views/system/infocenter/infocenterDetails.php +++ b/application/views/system/infocenter/infocenterDetails.php @@ -131,8 +131,11 @@ load->view('system/infocenter/notizen.php'); ?> -