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'); ?> -
+
+
+
load->view('system/infocenter/logs.php'); ?> +
diff --git a/public/js/infocenter/infocenterDetails.js b/public/js/infocenter/infocenterDetails.js index e5c966f7b..90509e288 100644 --- a/public/js/infocenter/infocenterDetails.js +++ b/public/js/infocenter/infocenterDetails.js @@ -20,6 +20,7 @@ function getUrlParameter(sParam) } var fhc_controller_id = getUrlParameter("fhc_controller_id"); +const CONTROLLER_URL = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + "/"+FHC_JS_DATA_STORAGE_OBJECT.called_path; /** * javascript file for infocenterDetails page @@ -42,6 +43,8 @@ $(document).ready( "dateFormat": "dd.mm.yy" }); + var personid = $("#hiddenpersonid").val(); + //add submit event to message send link $("#sendmsglink").click( function () @@ -54,7 +57,6 @@ $(document).ready( $(".prchbox").click(function () { var boxid = this.id; - var personid = $("#hiddenpersonid").val(); var akteid = boxid.substr(boxid.indexOf("_") + 1); var checked = this.checked; saveFormalGeprueft(personid, akteid, checked) @@ -64,7 +66,6 @@ $(document).ready( $(".zgvUebernehmen").click(function () { var btn = $(this); - var personid = $("#hiddenpersonid").val(); var prestudentid = this.id.substr(this.id.indexOf("_") + 1); $('#zgvUebernehmenNotice').remove(); zgvUebernehmen(personid, prestudentid, btn) @@ -118,11 +119,11 @@ $(document).ready( if (notizId !== '') { - updateNotiz(notizId, personId, data); + updateNotiz(notizId, personid, data); } else { - saveNotiz(personId, data); + saveNotiz(personid, data); } } ); @@ -150,6 +151,9 @@ $(document).ready( } ); + //check if person is parked and display it + getParkedDateAjax(personid); + }); function openZgvInfoForPrestudent(prestudent_id) @@ -169,7 +173,7 @@ function saveFormalGeprueft(personid, akteid, checked) $.ajax({ type: "POST", dataType: "json", - url: "../saveFormalGeprueft/" + personid + '?fhc_controller_id=' + fhc_controller_id, + url: CONTROLLER_URL+"/saveFormalGeprueft/" + personid + '?fhc_controller_id=' + fhc_controller_id, data: {"akte_id": akteid, "formal_geprueft": checked}, success: function (data, textStatus, jqXHR) { @@ -197,9 +201,9 @@ function saveFormalGeprueft(personid, akteid, checked) function zgvUebernehmen(personid, prestudentid, btn) { $.ajax({ - type: "POST", + type: "GET", dataType: "json", - url: "../getLastPrestudentWithZgvJson/" + personid + '?fhc_controller_id=' + fhc_controller_id, + url: CONTROLLER_URL+"/getLastPrestudentWithZgvJson/" + personid + '?fhc_controller_id=' + fhc_controller_id, success: function (data, textStatus, jqXHR) { if (data !== null) @@ -239,7 +243,7 @@ function saveZgv(data) type: "POST", dataType: "json", data: data, - url: "../saveZgvPruefung/" + prestudentid + '?fhc_controller_id=' + fhc_controller_id, + url: CONTROLLER_URL+"/saveZgvPruefung/" + prestudentid + '?fhc_controller_id=' + fhc_controller_id, success: function (data, textStatus, jqXHR) { if (data === prestudentid) @@ -265,7 +269,7 @@ function saveNotiz(personid, data) type: "POST", dataType: "json", data: data, - url: "../saveNotiz/" + personid + '?fhc_controller_id=' + fhc_controller_id, + url: CONTROLLER_URL+"/saveNotiz/" + personid + '?fhc_controller_id=' + fhc_controller_id, success: function (data, textStatus, jqXHR) { refreshNotizen(); @@ -284,7 +288,7 @@ function updateNotiz(notizId, personId, data) type: "POST", dataType: "json", data: data, - url: "../updateNotiz/" + notizId + "/" + personId + '?fhc_controller_id=' + fhc_controller_id, + url: CONTROLLER_URL+"/updateNotiz/" + notizId + "/" + personId + '?fhc_controller_id=' + fhc_controller_id, success: function (data, textStatus, jqXHR) { if (data) @@ -301,6 +305,86 @@ function updateNotiz(notizId, personId, data) }); } +function getStudienjahrEndAjax() +{ + $.ajax({ + url: CONTROLLER_URL+"/getStudienjahrEnd?fhc_controller_id="+getUrlParameter("fhc_controller_id"), + method: "GET", + success: function(data, textStatus, jqXHR) + { + console.log(data); + //var gerdate = data.substring(8, 10) + "."+data.substring(5, 7) + "." + data.substring(0, 4); + var engdate = $.datepicker.parseDate("yy-mm-dd", data); + var gerdate = $.datepicker.formatDate("dd.mm.yy", engdate); + $("#parkdate").val(gerdate); + }, + error: function (jqXHR, textStatus, errorThrown) + { + alert(textStatus); + } + }); +} + +function getParkedDateAjax(personid) +{ + $.ajax({ + url: CONTROLLER_URL+"/getParkedDate/"+personid+"?fhc_controller_id="+getUrlParameter("fhc_controller_id"), + method: "GET", + success: function(data, textStatus, jqXHR) + { + console.log(data); + refreshParking(data); + refreshLog(); + getStudienjahrEndAjax(); + }, + error: function (jqXHR, textStatus, errorThrown) + { + alert(textStatus); + } + }); +} + +function parkPersonAjax(personid, date) +{ + $.ajax({ + url: CONTROLLER_URL+"/park?fhc_controller_id="+getUrlParameter("fhc_controller_id"), + method: "POST", + data: + { + "person_id": personid, + "parkdate": date + }, + success: function(data, textStatus, jqXHR) + { + getParkedDateAjax(personid); + }, + error: function (jqXHR, textStatus, errorThrown) + { + alert(textStatus); + } + }); +} + +function unparkPersonAjax(personid) +{ + $.ajax({ + url: CONTROLLER_URL+"/unpark?fhc_controller_id="+getUrlParameter("fhc_controller_id"), + method: "POST", + data: + { + "person_id": personid + }, + success: function(data, textStatus, jqXHR) + { + getParkedDateAjax(personid); + }, + error: function (jqXHR, textStatus, errorThrown) + { + alert(textStatus); + } + }); +} + // ----------------------------------------------------------------------------------------------------------------- // methods executed after ajax (refreshers) @@ -336,6 +420,50 @@ function refreshNotizen() ); } +function refreshParking(date) +{ + if (date === null) + { + $("#parking").html( + '
'+ + '     '+ + 'bis  '+ + ''+ + '
'); + + $("#parkdate").datepicker({ + "dateFormat": "dd.mm.yy", + "minDate": 0 + }); + + $("#parklink").click( + function () + { + var personid = $("#hiddenpersonid").val(); + var date = $("#parkdate").val(); + + parkPersonAjax(personid, date); + } + ); + } + else + { + var parkdate = $.datepicker.parseDate("yy-mm-dd", date); + var gerparkdate = $.datepicker.formatDate("dd.mm.yy", parkdate); + $("#parking").html( + 'BewerberIn geparkt bis '+gerparkdate+'     '+ + ' '); + + $("#unparklink").click( + function () + { + var personid = $("#hiddenpersonid").val(); + unparkPersonAjax(personid, date); + } + ); + } +} + function formatNotizTable() { addTablesorter("notiztable", [[0, 1]], ["filter"], 2); diff --git a/public/js/infocenter/infocenterPersonDataset.js b/public/js/infocenter/infocenterPersonDataset.js index 7f99b6fc6..02e693314 100644 --- a/public/js/infocenter/infocenterPersonDataset.js +++ b/public/js/infocenter/infocenterPersonDataset.js @@ -25,10 +25,13 @@ function appendTableActionsHtml() '' + ' Keinen    '; - var messageHtml = 'Mit Ausgewählten:  ' + + var actionHtml = 'Mit Ausgewählten:  ' + '' + ' Nachricht senden'; + var legendHtml = ' Gesperrt    ' + + ' Geparkt'; + var personcount = 0; $.ajax({ @@ -51,9 +54,12 @@ function appendTableActionsHtml() var countHtml = personcount + " " + persontext; $("#datasetActionsTop, #datasetActionsBottom").append( - "
" + selectAllHtml + "  " + messageHtml + "
"+ - "
" + countHtml + "
"+ - "
" + "
"+ + "
" + selectAllHtml + "  " + actionHtml + "
"+ + "
" + legendHtml + "
"+ + "
" + countHtml + "
"+ + "
"+ + "
" ); $("#datasetActionsBottom").append("

"); }