diff --git a/plugin/ticket/lang/english.php b/plugin/ticket/lang/english.php index 876fa65803..5b0e4d885c 100755 --- a/plugin/ticket/lang/english.php +++ b/plugin/ticket/lang/english.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 %s with no user sent to all administrators.'; $strings['TicketXAssignedToUserX'] = 'Ticket #%s assigned to user %s'; $strings['TicketXCreatedWithNoCategory'] = 'Ticket #%s created with no category'; diff --git a/plugin/ticket/src/categories.php b/plugin/ticket/src/categories.php index b2314a5d0f..e885ca66dd 100644 --- a/plugin/ticket/src/categories.php +++ b/plugin/ticket/src/categories.php @@ -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(); diff --git a/plugin/ticket/src/categories_add_user.php b/plugin/ticket/src/categories_add_user.php index 5e7af2d84a..a654c1c82d 100644 --- a/plugin/ticket/src/categories_add_user.php +++ b/plugin/ticket/src/categories_add_user.php @@ -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(); diff --git a/plugin/ticket/src/myticket.php b/plugin/ticket/src/myticket.php index febdcdcacd..0d1a883a39 100755 --- a/plugin/ticket/src/myticket.php +++ b/plugin/ticket/src/myticket.php @@ -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(); diff --git a/plugin/ticket/src/ticket.class.php b/plugin/ticket/src/ticket.class.php index 36df22cdc3..dea5efd152 100755 --- a/plugin/ticket/src/ticket.class.php +++ b/plugin/ticket/src/ticket.class.php @@ -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 = '
| ' . api_convert_and_format_date($now, DATE_TIME_FORMAT_LONG) . ' | ||
| ' . get_lang('Topic') . ' | +' . get_lang('Title') . ' | ' . $subject . ' |