diff --git a/main/inc/lib/TicketManager.php b/main/inc/lib/TicketManager.php index ffc8e50538..3067a3c992 100644 --- a/main/inc/lib/TicketManager.php +++ b/main/inc/lib/TicketManager.php @@ -1875,4 +1875,19 @@ class TicketManager return $form; } + + public static function getProjects() + { + $em = Database::getManager()->getRepository('ChamiloTicketBundle')->findAll(); + + return $em; + } + + + public static function getProjectsCount() + { + $em = Database::getManager()->getRepository('ChamiloTicketBundle')->findAll(); + + return $em; + } } diff --git a/main/ticket/categories.php b/main/ticket/categories.php index 6d23da12f5..4de766b1e6 100644 --- a/main/ticket/categories.php +++ b/main/ticket/categories.php @@ -11,8 +11,6 @@ $cidReset = true; $course_plugin = 'ticket'; require_once __DIR__.'/../inc/global.inc.php'; -$plugin = TicketPlugin::create(); - api_protect_admin_script(true); $toolName = get_lang('Categories'); @@ -69,8 +67,6 @@ if (isset($_GET['action'])) { 'total_tickets' => 0, 'sys_insert_user_id' => api_get_user_id(), 'sys_insert_datetime' => api_get_utc_datetime(), - 'category_id' => 0, - 'project_id' => 0, 'course_required' => '' ]; TicketManager::addCategory($params); diff --git a/main/ticket/index.php b/main/ticket/index.php index 06f51d76fe..4e9bb0d063 100644 --- a/main/ticket/index.php +++ b/main/ticket/index.php @@ -7,5 +7,5 @@ */ require_once __DIR__.'/../inc/global.inc.php'; -header('Location:' . api_get_path(WEB_CODE_PATH) . '/ticket/myticket.php'); +header('Location:' . api_get_path(WEB_CODE_PATH) . 'ticket/myticket.php'); exit; diff --git a/main/ticket/new_ticket.php b/main/ticket/new_ticket.php index f511674bf1..d51ce5aacc 100644 --- a/main/ticket/new_ticket.php +++ b/main/ticket/new_ticket.php @@ -8,7 +8,7 @@ $cidReset = true; require_once __DIR__.'/../inc/global.inc.php'; -if (!api_is_platform_admin() || api_get_setting('ticket_allow_student_add') != 'true' +if (!api_is_platform_admin() && api_get_setting('ticket_allow_student_add') != 'true' ) { header('location:' . api_get_path(WEB_CODE_PATH).'ticket/myticket.php'); exit; diff --git a/main/ticket/projects.php b/main/ticket/projects.php new file mode 100644 index 0000000000..7570650878 --- /dev/null +++ b/main/ticket/projects.php @@ -0,0 +1,156 @@ +per_page == 0) { + $table->per_page = 20; +} + +$formToString = ''; +$id = isset($_GET['id']) ? intval($_GET['id']) : 0; + +$interbreadcrumb[] = array( + 'url' => api_get_path(WEB_CODE_PATH).'ticket/myticket.php', + 'name' => get_lang('MyTickets') +); + +if (isset($_GET['action'])) { + global $table; + $action = $_GET['action']; + switch ($action) { + case 'delete': + TicketManager::deleteProject($id); + Display::addFlash(Display::return_message(get_lang('Deleted'))); + header("Location: ".api_get_self()); + break; + case 'add': + $toolName = get_lang('Add'); + $interbreadcrumb[] = array( + 'url' => api_get_path(WEB_CODE_PATH).'ticket/categories.php', + 'name' => get_lang('Categories') + ); + $url = api_get_self().'?action=add'; + $form = TicketManager::getProjectForm($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(), + 'course_required' => '' + ]; + TicketManager::addProject($params); + + Display::addFlash(Display::return_message(get_lang('Added'))); + + header("Location: ".api_get_self()); + exit; + } + break; + case 'edit': + $toolName = get_lang('Edit'); + $interbreadcrumb[] = array( + 'url' => api_get_path(WEB_CODE_PATH).'ticket/categories.php', + 'name' => get_lang('Categories') + ); + $url = api_get_self().'?action=edit&id='.$id; + $form = TicketManager::getProjectForm($url); + + $cat = TicketManager::getProject($_GET['id']); + $form->setDefaults($cat); + $formToString = $form->returnForm(); + if ($form->validate()) { + $values =$form->getSubmitValues(); + + $params = [ + 'name' => $values['name'], + 'description' => $values['description'], + 'sys_lastedit_datetime' => api_get_utc_datetime(), + 'sys_lastedit_user_id' => api_get_user_id() + ]; + $cat = TicketManager::updateProject($_GET['id'], $params); + Display::addFlash(Display::return_message(get_lang('Updated'))); + header("Location: ".api_get_self()); + exit; + } + break; + default: + break; + } +} + +$user_id = api_get_user_id(); +$isAdmin = api_is_platform_admin(); + +/** + * Build the modify-column of the table + * @param int The user id + * @param string URL params to add to table links + * @param array Row of elements to alter + * @return string Some HTML-code with modify-buttons + */ +function modify_filter($id, $params, $row) +{ + $result = Display::url( + Display::return_icon('edit.png', get_lang('Edit')), + "projects.php?action=edit&id={$row['id']}" + ); + + $result .= Display::url( + Display::return_icon('delete.png', get_lang('Delete')), + "projects.php?action=delete&id={$row['id']}" + ); + + return $result; +} + +$table->set_header(0, '', false); +$table->set_header(1, get_lang('Title'), false); +$table->set_header(2, get_lang('Description'), true, array("style" => "width:200px")); +$table->set_header(3, get_lang('Actions'), true); +$table->set_column_filter(3, 'modify_filter'); + +Display::display_header($toolName); + +$items = [ + [ + 'url' => 'projects.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(); + +Display::display_footer();