From 2e84ccdb116692718c84c1ab016bddffa1fe2ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20K=C5=82opotek=20-=20INTERDUO?= Date: Wed, 31 May 2023 15:51:47 +0200 Subject: [PATCH] improvement/bugfix: opening/closing events was not generating messages in syslog and helpdesk --- lib/LMS.class.php | 12 ++++ lib/LMSManagers/LMSEventManager.php | 101 ++++++++++++++++++++++++++++ lib/locale/pl_PL/strings.php | 2 + modules/eventedit.php | 10 +-- 4 files changed, 120 insertions(+), 5 deletions(-) diff --git a/lib/LMS.class.php b/lib/LMS.class.php index c2f477b404..5696b27614 100644 --- a/lib/LMS.class.php +++ b/lib/LMS.class.php @@ -3487,6 +3487,18 @@ public function GetEventList(array $params) return $manager->GetEventList($params); } + public function EventOpen($id) + { + $manager = $this->getEventManager(); + return $manager->EventOpen($id); + } + + public function EventClose($params) + { + $manager = $this->getEventManager(); + return $manager->EventClose($params); + } + public function GetCustomerIdByTicketId($id) { $manager = $this->getEventManager(); diff --git a/lib/LMSManagers/LMSEventManager.php b/lib/LMSManagers/LMSEventManager.php index 4b407f72f1..5762843b82 100644 --- a/lib/LMSManagers/LMSEventManager.php +++ b/lib/LMSManagers/LMSEventManager.php @@ -670,6 +670,107 @@ public function EventSearch($search, $order = 'date,asc', $simple = false) } } + /** + * @param array $params associative array of parameters described below: + * id - id of event to close, single integer value, + * ticketid - assigned ticketid of all events to close + */ + + public function EventClose($params) + { + if (!ConfigHelper::checkPrivilege('timetable_mangement')) { + die('Error - cannot close event(s) - no permissions'); + } + if (empty($params)) { + die('Error - cannot close event(s)'); + } + + if (!empty($params['ticketid'])) { + $where = 'closed = 0 AND ticketid = ?'; + $sqlreplacedata = $params['ticketid']; + $helpdesk_manager = new LMSHelpdeskManager($this->db, $this->auth, $this->cache); + $ids = $helpdesk_manager->GetEventsByTicketId($params['ticketid']); + $ids = $ids ?? $params['id']; + + foreach ($ids as $id) { + $helpdesk_manager->TicketMessageAdd(array( + 'ticketid' => $params['ticketid'], + 'messageid' => '', + 'body' => trans('Assigned event ($a) was closed.', $a = $id['id']), + 'type' => RTMESSAGE_ASSIGNED_EVENT_CHANGE, + )); + } + } else { + $where = 'id = ?'; + $sqlreplacedata = $params['id']; + $ids = array($params['id']); + } + + if ($this->syslog) { + foreach ($ids as $id) { + $this->syslog->AddMessage( + SYSLOG::RES_EVENT, + SYSLOG::OPER_UPDATE, + $id, + array('mod' . SYSLOG::getResourceKey(SYSLOG::RES_USER)) + ); + } + } + + return $this->db->Execute( + 'UPDATE events + SET closed = 1, closeduserid = ?, closeddate = ?NOW? + WHERE ' . $where, + array(Auth::GetCurrentUser(), $sqlreplacedata) + ); + } + + public function EventOpen($id) + { + if (!ConfigHelper::checkPrivilege('timetable_mangement')) { + die('Error - cannot open event(s) - no permissions'); + } + + $aee = ConfigHelper::getConfig( + 'timetable.allow_modify_closed_events_newer_than', + ConfigHelper::getConfig('phpui.allow_modify_closed_events_newer_than', 604800) + ); + $event = $this->GetEvent($id); + if (empty($event['closed'])) { + die('Cannot open event - event not closed'); + } + if (!ConfigHelper::checkPrivilege('superuser') && $aee && ((time() - $event['closeddate']) < $aee)) { + die('Cannot open event - event closed too long ago'); + } + + if ($this->syslog) { + $this->syslog->AddMessage( + SYSLOG::RES_EVENT, + SYSLOG::OPER_UPDATE, + $id, + array('mod' . SYSLOG::getResourceKey(SYSLOG::RES_USER)) + ); + } + + if (!empty($event['ticketid'])) { + $helpdesk_manager = new LMSHelpdeskManager($this->db, $this->auth, $this->cache); + $ticketqueue = $helpdesk_manager->GetQueueByTicketId($event['ticketid']); + + $helpdesk_manager->TicketMessageAdd(array( + 'ticketid' => $event['ticketid'], + 'messageid' => '', + 'body' => trans('Assigned event ($a) was opened.', $a = $id), + 'type' => RTMESSAGE_ASSIGNED_EVENT_CHANGE, + )); + } + + return $this->db->Execute( + 'UPDATE events SET closed = 0, closeduserid = NULL, closeddate = 0 + WHERE id = ?', + array($id) + ); + } + public function GetCustomerIdByTicketId($id) { return $this->db->GetOne('SELECT customerid FROM rttickets WHERE id=?', array($id)); diff --git a/lib/locale/pl_PL/strings.php b/lib/locale/pl_PL/strings.php index 676c42b3fa..c0550056ec 100644 --- a/lib/locale/pl_PL/strings.php +++ b/lib/locale/pl_PL/strings.php @@ -4729,6 +4729,8 @@ $_LANG['Assigned event ($a) was created.'] = 'Utworzono przypisane zdarzenie ($a).'; $_LANG['Assigned event ($a) was modified.'] = 'Zmodyfikowano przypisane zdarzenie ($a).'; $_LANG['Assigned event ($a) was deleted.'] = 'Usunięto przypisane zdarzenie ($a).'; +$_LANG['Assigned event ($a) was opened.'] = 'Przypisane zdarzenie ($a) zostało otwarte.'; +$_LANG['Assigned event ($a) was closed.'] = 'Przypisane zdarzenie ($a) zostało zamknięte.'; $_LANG['New ticket body should not be empty if you set new ticket subject!'] = 'Treść powiadomienia o nowym zgłoszeniu nie może być pusta w sytuacji, gdy ustawiono temat powiadomienia o nowym zgłoszeniu!'; $_LANG['New ticket subject should not be empty if you set new ticket body!'] = 'Temat powiadomienia o nowym zgłoszeniu nie może być pusty w sytuacji, gdy ustawiono treść powiadomienia o nowym zgłoszeniu!'; diff --git a/modules/eventedit.php b/modules/eventedit.php index 5d78b13aad..3dc65acd06 100644 --- a/modules/eventedit.php +++ b/modules/eventedit.php @@ -62,7 +62,7 @@ switch ($action) { case 'open': if (empty($event['closeddate']) || ($event['closed'] == 1 && $aee && (time() - $event['closeddate'] < $aee)) || ConfigHelper::checkPrivilege('superuser')) { - $DB->Execute('UPDATE events SET closed = 0, closeduserid = NULL, closeddate = 0 WHERE id = ?', array($_GET['id'])); + $LMS->EventOpen($_GET['id']); $SESSION->remove_history_entry(); $SESSION->redirect($backurl); } else { @@ -72,12 +72,12 @@ case 'close': $SESSION->remove_history_entry(); if (isset($_GET['ticketid'])) { - $DB->Execute('UPDATE events SET closed = 1, closeduserid = ?, closeddate = ?NOW? WHERE closed = 0 AND ticketid = ?', array(Auth::GetCurrentUser(), $_GET['ticketid'])); - $SESSION->redirect($backurl); + $params = array('ticketid' => $_GET['ticketid']); } else { - $DB->Execute('UPDATE events SET closed = 1, closeduserid = ?, closeddate = ?NOW? WHERE id = ?', array(Auth::GetCurrentUser(), $_GET['id'])); - $SESSION->redirect($backurl); + $params = array('id' => $_GET['id']); } + $LMS->EventClose($params); + $SESSION->redirect($backurl); break; case 'assign': if ($event['closed'] != 1 || ($event['closed'] == 1 && $aee && ((time() - $event['closeddate']) < $aee)) || ConfigHelper::checkPrivilege('superuser')) {