diff --git a/lib/LMS.class.php b/lib/LMS.class.php index e9e5474d74..72e16ebb5e 100644 --- a/lib/LMS.class.php +++ b/lib/LMS.class.php @@ -3516,6 +3516,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 fef6cb65f3..64c82d9e35 100644 --- a/lib/LMSManagers/LMSEventManager.php +++ b/lib/LMSManagers/LMSEventManager.php @@ -675,6 +675,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 71f051203e..959c5eee10 100644 --- a/lib/locale/pl_PL/strings.php +++ b/lib/locale/pl_PL/strings.php @@ -4800,6 +4800,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 f44980c012..383e4f55ab 100644 --- a/modules/eventedit.php +++ b/modules/eventedit.php @@ -37,9 +37,14 @@ $max_userlist_size = ConfigHelper::getConfig('timetable.event_max_userlist_size', ConfigHelper::getConfig('phpui.event_max_userlist_size')); $big_networks = ConfigHelper::checkConfig('phpui.big_networks'); $now = time(); +$currentuser = Auth::GetCurrentUser(); -if (isset($_GET['id'])) { - $event = $LMS->GetEvent($_GET['id']); +$action = isset($_GET['action']) ? $_GET['action'] : null; +$id = !empty($_GET['id']) ? intval($_GET['id']) : null; +$ticketid = !empty($_GET['ticketid']) ? intval($_GET['ticketid']) : null; + +if (!empty($id)) { + $event = $LMS->GetEvent($id); if (empty($event)) { $SESSION->redirect('?m=eventlist'); } @@ -62,11 +67,10 @@ $backid = $SESSION->get('backid'); $backurl = '?' . $backto . (empty($backid) ? '' : '#' . $backid); -$action = isset($_GET['action']) ? $_GET['action'] : null; switch ($action) { case 'open': if (empty($event['closeddate']) || ($event['closed'] == 1 && $aee && ($now - $event['closeddate'] < $aee)) || $superuser) { - $DB->Execute('UPDATE events SET closed = 0, closeduserid = NULL, closeddate = 0 WHERE id = ?', array($_GET['id'])); + $LMS->EventOpen($id); $SESSION->remove_history_entry(); $SESSION->redirect($backurl); } else { @@ -75,17 +79,16 @@ break; 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); + if (isset($ticketid)) { + $LMS->EventClose(array('ticketid' => $ticketid)); } else { - $DB->Execute('UPDATE events SET closed = 1, closeduserid = ?, closeddate = ?NOW? WHERE id = ?', array(Auth::GetCurrentUser(), $_GET['id'])); - $SESSION->redirect($backurl); + $LMS->EventClose(array('id' => $id)); } + $SESSION->redirect($backurl); break; case 'assign': if ($event['closed'] != 1 || ($event['closed'] == 1 && $aee && (($now - $event['closeddate']) < $aee)) || $superuser) { - $LMS->AssignUserToEvent($_GET['id'], Auth::GetCurrentUser()); + $LMS->AssignUserToEvent($id, $currentuser); $SESSION->remove_history_entry(); $SESSION->redirect($backurl); } else { @@ -94,7 +97,7 @@ break; case 'unassign': if ($event['closed'] != 1 || ($event['closed'] == 1 && $aee && (($now - $event['closeddate']) < $aee)) || $superuser) { - $LMS->UnassignUserFromEvent($_GET['id'], Auth::GetCurrentUser()); + $LMS->UnassignUserFromEvent($id, $currentuser); $SESSION->remove_history_entry(); $SESSION->redirect($backurl); } else {