Fix ticket messages to admins BT#11081

ofaj
Julio 10 years ago
parent d5610121ec
commit a341c1eba6
  1. 2
      plugin/ticket/lang/english.php
  2. 54
      plugin/ticket/src/categories.php
  3. 1
      plugin/ticket/src/categories_add_user.php
  4. 2
      plugin/ticket/src/myticket.php
  5. 173
      plugin/ticket/src/ticket.class.php

@ -93,7 +93,7 @@ $strings['warn_admin_no_user_in_category'] = "Warn admin if category doesn't hav
$strings['send_warning_to_all_admins'] = "Send warning to all admins, if category doesn't have users related";
$strings['WarningCategoryXDoesntHaveUsers'] = "Warning: The category '%s' doesn't have users assigned";
$strings['TicketInformation'] = 'Ticket information';
$strings['CategoryWithNoUserNotificationSentToAdmins'] = 'Category with no user sent to all administrators.';
$strings['CategoryWithNoUserNotificationSentToAdmins'] = 'Category <b>%s</b> with no user sent to all administrators.';
$strings['TicketXAssignedToUserX'] = 'Ticket <b>#%s</b> assigned to user <b>%s</b>';
$strings['TicketXCreatedWithNoCategory'] = 'Ticket <b>#%s</b> created with no category';

@ -42,17 +42,38 @@ if (isset($_GET['action'])) {
global $table;
$action = $_GET['action'];
switch ($action) {
case 'delete':
TicketManager::deleteCategory($id);
Display::addFlash(Display::return_message(get_lang('Deleted')));
header("Location: ".api_get_self());
break;
case 'add':
$url = api_get_self().'?action=add';
$form = TicketManager::getCategoryForm($url);
$formToString = $form->returnForm();
if ($form->validate()) {
$values =$form->getSubmitValues();
$params = [
'name' => $values['name'],
'description' => $values['description'],
'total_tickets' => 0,
'sys_insert_user_id' => api_get_user_id(),
'sys_insert_datetime' => api_get_utc_datetime()
];
TicketManager::addCategory($params);
Display::addFlash(Display::return_message(get_lang('Added')));
header("Location: ".api_get_self());
exit;
}
break;
case 'edit':
$form = new FormValidator('category', 'post', api_get_self().'?action=edit&id='.$id);
$form->addText('name', get_lang('Nsme'));
$form->addHtmlEditor('description', get_lang('Description'));
$form->addButtonUpdate(get_lang('Update'));
$url = api_get_self().'?action=edit&id='.$id;
$form = TicketManager::getCategoryForm($url);
$cat = TicketManager::getCategory($_GET['id']);
$form->setDefaults($cat);
$formToString = $form->returnForm();
@ -62,10 +83,13 @@ if (isset($_GET['action'])) {
$params = [
'name' => $values['name'],
'description' => $values['description'],
'sys_lastedit_datetime' => api_get_utc_datetime(),
'sys_lastedit_user_id' => api_get_user_id()
];
$cat = TicketManager::updateCategory($_GET['id'], $params);
Display::addFlash(Display::return_message(get_lang('Updated')));
header("Location: ".api_get_self());
exit;
}
break;
default:
@ -76,7 +100,6 @@ if (isset($_GET['action'])) {
$user_id = api_get_user_id();
$isAdmin = api_is_platform_admin();
/**
* Build the modify-column of the table
* @param int The user id
@ -104,14 +127,25 @@ function modify_filter($id, $params, $row)
return $result;
}
Display::display_header($plugin->get_lang('MyTickets'));
$table->set_header(0, '', false);
$table->set_header(1, $plugin->get_lang('Title'), true);
$table->set_header(1, $plugin->get_lang('Title'), false);
$table->set_header(2, get_lang('Description'), true, array("style" => "width:200px"));
$table->set_header(3, $plugin->get_lang('TotalTickets'), true);
$table->set_header(3, $plugin->get_lang('TotalTickets'), false);
$table->set_header(4, get_lang('Actions'), true);
$table->set_column_filter(4, 'modify_filter');
$interbreadcrumb[] = array('url' => 'myticket.php', 'name' => $plugin->get_lang('MyTickets'));
Display::display_header($plugin->get_lang('Categories'));
$items = [
[
'url' => 'categories.php?action=add',
'content' => Display::return_icon('new_folder.png', null, null, ICON_SIZE_MEDIUM),
]
];
echo Display::actions($items);
echo $formToString;
echo $table->return_table();

@ -46,6 +46,7 @@ if ($form->validate()) {
exit;
}
$interbreadcrumb[] = array('url' => 'myticket.php', 'name' => $plugin->get_lang('MyTickets'));
$interbreadcrumb[] = array('url' => 'categories.php', 'name' => get_lang('Categories'));
Display::display_header();
$form->display();

@ -427,7 +427,7 @@ if ($isAdmin) {
$table->set_header(3, $plugin->get_lang('Category'));
$table->set_header(4, $plugin->get_lang('Status'), false);
$table->set_header(5, get_lang('Actions'), false);
}
}
$table->display();
Display::display_footer();

@ -108,7 +108,17 @@ class TicketManager
{
$table = Database::get_main_table(TABLE_TICKET_CATEGORY);
$id = intval($id);
Database::update($table, $params, ['id = ?' => $id]);
Database::update($table, $params, ['id = ?' => $id]);
}
/**
* @param int $id
* @param array $params
*/
public static function addCategory($params)
{
$table = Database::get_main_table(TABLE_TICKET_CATEGORY);
Database::insert($table, $params);
}
/**
@ -275,42 +285,6 @@ class TicketManager
}
if (!empty($category_id)) {
$categoryInfo = TicketManager::getCategory($category_id);
if ($plugin->get('warn_admin_no_user_in_category')) {
$usersInCategory = TicketManager::getUsersInCategory($category_id);
if (empty($usersInCategory)) {
$subject = sprintf(
$plugin->get_lang('WarningCategoryXDoesntHaveUsers'),
$categoryInfo['name']
);
$message = '<h2>'.$plugin->get_lang('TicketInformation').'</h2><br />'.$helpDeskMessage;
if ($plugin->get('send_warning_to_all_admins')) {
Display::addFlash(Display::return_message(
$plugin->get_lang('CategoryWithNoUserNotificationSentToAdmins')
));
$admins = UserManager::get_all_administrators();
foreach ($admins as $userId => $data) {
if ($data['active']) {
MessageManager::send_message_simple(
$userId,
$subject,
$message
);
}
}
}
}
} else {
}
if (empty($request_user)) {
$usersInCategory = TicketManager::getUsersInCategory($category_id);
if (!empty($usersInCategory) && count($usersInCategory) > 0) {
@ -372,29 +346,6 @@ class TicketManager
(int) $ticket_id, 11, "0", STR_PAD_LEFT
);
if (empty($category_id)) {
if ($plugin->get('send_warning_to_all_admins')) {
Display::addFlash(Display::return_message(
sprintf(
$plugin->get_lang('TicketXCreatedWithNoCategory')
)
));
$admins = UserManager::get_all_administrators();
foreach ($admins as $userId => $data) {
if ($data['active']) {
MessageManager::send_message_simple(
$userId,
$subject,
$message
);
}
}
}
}
if ($assigned_user != 0) {
self::assign_ticket_user($ticket_id, $assigned_user);
@ -427,11 +378,17 @@ class TicketManager
$data_files = array();
// Update total
$sql = "UPDATE $table_support_category
SET total_tickets = total_tickets +1
WHERE category_id = '$category_id';";
SET total_tickets = total_tickets +1
WHERE category_id = '$category_id'";
Database::query($sql);
if (self::insert_message($ticket_id, $subject, $content, $file_attachments, $request_user)) {
if (self::insert_message(
$ticket_id,
$subject,
$content,
$file_attachments,
$request_user)
) {
$user = api_get_user_info($request_user);
$helpDeskMessage =
'<table>
@ -456,7 +413,7 @@ class TicketManager
<td width="400px">' . api_convert_and_format_date($now, DATE_TIME_FORMAT_LONG) . '</td>
</tr>
<tr>
<td width="100px"><b>' . get_lang('Topic') . '</b></td>
<td width="100px"><b>' . get_lang('Title') . '</b></td>
<td width="400px">' . $subject . '</td>
</tr>
<tr>
@ -465,6 +422,81 @@ class TicketManager
</tr>
</table>';
if (empty($category_id)) {
if ($plugin->get('send_warning_to_all_admins')) {
$warningSubject = sprintf(
$plugin->get_lang('TicketXCreatedWithNoCategory'),
$ticket_code
);
Display::addFlash(Display::return_message($warningSubject));
$admins = UserManager::get_all_administrators();
foreach ($admins as $userId => $data) {
if ($data['active']) {
MessageManager::send_message_simple(
$userId,
$warningSubject,
$message
);
}
}
}
} else {
$categoryInfo = TicketManager::getCategory($category_id);
$usersInCategory = TicketManager::getUsersInCategory($category_id);
$message = '<h2>'.$plugin->get_lang('TicketInformation').'</h2><br />'.$helpDeskMessage;
if ($plugin->get('warn_admin_no_user_in_category')) {
$usersInCategory = TicketManager::getUsersInCategory($category_id);
if (empty($usersInCategory)) {
$subject = sprintf(
$plugin->get_lang('WarningCategoryXDoesntHaveUsers'),
$categoryInfo['name']
);
if ($plugin->get('send_warning_to_all_admins')) {
Display::addFlash(Display::return_message(
sprintf(
$plugin->get_lang('CategoryWithNoUserNotificationSentToAdmins'),
$categoryInfo['name']
),
null,
false
));
$admins = UserManager::get_all_administrators();
foreach ($admins as $userId => $data) {
if ($data['active']) {
MessageManager::send_message_simple(
$userId,
$subject,
$message
);
}
}
} else {
Display::addFlash(Display::return_message($subject));
}
}
}
// Send notification to all users
if (!empty($usersInCategory)) {
foreach ($usersInCategory as $data) {
if ($data['user_id']) {
MessageManager::send_message_simple(
$data['user_id'],
$subject,
$message
);
}
}
}
}
global $data_files;
if ($other_area) {
@ -1831,4 +1863,17 @@ class TicketManager
return $tickets;
}
/**
* @param string $url
* @return FormValidator
*/
public static function getCategoryForm($url)
{
$form = new FormValidator('category', 'post', $url);
$form->addText('name', get_lang('Name'));
$form->addHtmlEditor('description', get_lang('Description'));
$form->addButtonUpdate(get_lang('Save'));
return $form;
}
}

Loading…
Cancel
Save