Skip to content

Commit

Permalink
bugfix: opening/closing events was not generating messages in syslog …
Browse files Browse the repository at this point in the history
…and helpdesk
  • Loading branch information
interduo committed May 31, 2023
1 parent 81bcfba commit 35e4c94
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 5 deletions.
12 changes: 12 additions & 0 deletions lib/LMS.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
92 changes: 92 additions & 0 deletions lib/LMSManagers/LMSEventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,98 @@ 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 (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' => '<msg.' . $params['ticketid'] . $id['id'] . '.' . time() . '@rtsystem.' . gethostname() . '>',
'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) {
$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' => '<msg.' . $ticketqueue['id'] . '.' . $event['ticketid'] . '.' . time() . '@rtsystem.' . gethostname() . '>',
'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));
Expand Down
2 changes: 2 additions & 0 deletions lib/locale/pl_PL/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!';
Expand Down
10 changes: 5 additions & 5 deletions modules/eventedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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')) {
Expand Down

0 comments on commit 35e4c94

Please sign in to comment.