Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement/bugfix: opening/closing events was not generating messages in syslog … #2369

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/LMS.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
101 changes: 101 additions & 0 deletions lib/LMSManagers/LMSEventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<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)
{
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' => '<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 @@ -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!';
Expand Down
25 changes: 14 additions & 11 deletions modules/eventedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down