Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chamilo-lms/public/main/ticket/categories.php

205 lines
6.1 KiB

9 years ago
<?php
9 years ago
/* For licensing terms, see /license.txt */
9 years ago
use ChamiloSession as Session;
9 years ago
/**
* This script is the Tickets plugin main entry point.
9 years ago
*/
// needed in order to load the plugin lang variables
$course_plugin = 'ticket';
$cidReset = true;
9 years ago
require_once __DIR__.'/../inc/global.inc.php';
api_protect_admin_script(true);
$toolName = get_lang('Categories');
9 years ago
$webLibPath = api_get_path(WEB_LIBRARY_PATH);
9 years ago
$user_id = api_get_user_id();
$isAdmin = api_is_platform_admin();
9 years ago
$this_section = 'tickets';
Session::erase('this_section');
9 years ago
$table = new SortableTable(
'TicketCategories',
['TicketManager', 'getCategoriesCount'],
['TicketManager', 'getCategories'],
9 years ago
1
);
if (0 == $table->per_page) {
9 years ago
$table->per_page = 20;
}
$formToString = '';
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$projectId = isset($_GET['project_id']) ? (int) $_GET['project_id'] : 0;
$project = TicketManager::getProject($projectId);
if (empty($project)) {
api_not_allowed(true);
}
9 years ago
Session::write('project_id', $projectId);
$action = isset($_GET['action']) ? $_GET['action'] : '';
9 years ago
$interbreadcrumb[] = [
9 years ago
'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId,
'name' => get_lang('My tickets'),
];
9 years ago
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/settings.php',
'name' => get_lang('Settings'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/projects.php',
'name' => get_lang('Projects'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/projects.php',
'name' => $project->getName(),
];
9 years ago
switch ($action) {
case 'delete':
$tickets = TicketManager::getTicketsFromCriteria(['category' => $id]);
if (empty($tickets)) {
TicketManager::deleteCategory($id);
Display::addFlash(Display::return_message(get_lang('Deleted')));
} else {
Display::addFlash(Display::return_message(get_lang('This item is related to other tickets.')));
}
header('Location: '.api_get_self().'?project_id='.$projectId);
exit;
9 years ago
break;
case 'add':
$toolName = get_lang('Add');
$interbreadcrumb[] = [
9 years ago
'url' => api_get_path(WEB_CODE_PATH).'ticket/categories.php',
'name' => get_lang('Categories'),
];
9 years ago
$url = api_get_self().'?action=add&project_id='.$projectId;
$form = TicketManager::getCategoryForm($url, $projectId);
$formToString = $form->returnForm();
if ($form->validate()) {
$values = $form->getSubmitValues();
9 years ago
$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(),
'course_required' => '',
'project_id' => $projectId,
9 years ago
];
TicketManager::addCategory($params);
Display::addFlash(Display::return_message(get_lang('Added')));
header('Location: '.api_get_self().'?project_id='.$projectId);
9 years ago
exit;
}
9 years ago
break;
case 'edit':
if ('true' !== api_get_setting('ticket_allow_category_edition')) {
api_not_allowed();
}
9 years ago
$toolName = get_lang('Edit');
$interbreadcrumb[] = [
9 years ago
'url' => api_get_path(WEB_CODE_PATH).'ticket/categories.php?project_id='.$projectId,
'name' => get_lang('Categories'),
];
9 years ago
$url = api_get_self().'?action=edit&project_id='.$projectId.'&id='.$id;
$form = TicketManager::getCategoryForm($url, $projectId);
$cat = TicketManager::getCategory($_GET['id']);
$form->setDefaults($cat);
$formToString = $form->returnForm();
if ($form->validate()) {
$values = $form->getSubmitValues();
9 years ago
$params = [
'name' => $values['name'],
'description' => $values['description'],
'sys_lastedit_datetime' => api_get_utc_datetime(),
'sys_lastedit_user_id' => api_get_user_id(),
9 years ago
];
$cat = TicketManager::updateCategory($_GET['id'], $params);
Display::addFlash(Display::return_message(get_lang('Update successful')));
header('Location: '.api_get_self().'?project_id='.$projectId);
9 years ago
exit;
}
9 years ago
break;
default:
break;
9 years ago
}
/**
* Build the modify-column of the table.
*
* @param int $id The user id
* @param string $params URL params to add to table links
* @param array $row Row of elements to alter
*
9 years ago
* @return string Some HTML-code with modify-buttons
*/
function modify_filter($id, $params, $row)
{
9 years ago
$projectId = Session::read('project_id');
$result = '';
if ('true' === api_get_setting('ticket_allow_category_edition')) {
$result .= Display::url(
Display::return_icon('edit.png', get_lang('Edit')),
"categories.php?action=edit&id={$row['id']}&project_id=".$projectId
);
}
9 years ago
$result .= Display::url(
Display::return_icon('user.png', get_lang('Assign user')),
9 years ago
"categories_add_user.php?id={$row['id']}&project_id=".$projectId
9 years ago
);
if ('true' === api_get_setting('ticket_allow_category_edition')) {
$result .= Display::url(
Display::return_icon('delete.png', get_lang('Delete')),
"categories.php?action=delete&id={$row['id']}&project_id=".$projectId
);
}
9 years ago
return $result;
9 years ago
}
$table->set_header(0, '', false);
$table->set_header(1, get_lang('Title'), false);
$table->set_header(2, get_lang('Description'), true, ['style' => 'width:200px']);
$table->set_header(3, get_lang('Total tickets'), false);
$table->set_header(4, get_lang('Detail'), true);
9 years ago
$table->set_column_filter(4, 'modify_filter');
Display::display_header($toolName);
$items = [
[
9 years ago
'url' => 'categories.php?action=add&project_id='.$projectId,
'content' => Display::return_icon('new_folder.png', null, null, ICON_SIZE_MEDIUM),
],
9 years ago
];
echo Display::actions($items);
echo $formToString;
echo $table->return_table();
Display::display_footer();