diff --git a/inc/itilfollowup.class.php b/inc/itilfollowup.class.php index dbf7484..92ca242 100644 --- a/inc/itilfollowup.class.php +++ b/inc/itilfollowup.class.php @@ -39,8 +39,46 @@ static function beforeAdd(ITILFollowup $fup) { $config = PluginBehaviorsConfig::getInstance(); if ($ticket->getFromDB($fup->input['items_id']) && $fup->input['itemtype'] == 'Ticket') { - + + // mailgate situation if ($config->getField('addfup_updatetech') + && isset($fup->input['_mailgate']) && $fup->input['_mailgate']) { + + $ticket_user = new Ticket_User(); + $ticket_user->getFromDBByCrit(['tickets_id' => $ticket->getID(), + 'type' => CommonITILActor::ASSIGN]); + + $ticket_requester = new Ticket_User(); + $ticket_requester->getFromDBByCrit(['tickets_id' => $ticket->getID(), + 'type' => CommonITILActor::REQUESTER]); + + # only run if user id is set AND no user has been assigned yet && user is not the requester + if (isset($fup->input['users_id']) + && !isset($ticket_user->fields['users_id']) + && $ticket_requester->fields['users_id'] <> $fup->input['users_id']) { + + $group_ticket = new Group_Ticket(); + $group_ticket->getFromDBByCrit(['tickets_id' => $ticket->getID(), + 'type' => CommonITILActor::ASSIGN]); + + $usergroup = Group_User::getGroupUsers($group_ticket->fields['groups_id']); + $users = []; + foreach ($usergroup as $user) { + $users[$user['id']] = $user['id']; + } + + if (!in_array( $fup->input['users_id'], $users)) { + $ticket_user = new Ticket_User(); + $ticket_user->add(['tickets_id' => $ticket->getID(), + 'users_id' => $fup->input['users_id'], + 'type' => CommonITILActor::ASSIGN]); + } + } + + } + + // regular situation + else if ($config->getField('addfup_updatetech') && Session::haveRight('ticket', UPDATE)) { $ticket_user = new Ticket_User(); @@ -69,6 +107,4 @@ static function beforeAdd(ITILFollowup $fup) { } } - - }