projects.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script is the Tickets plugin main entry point
  5. * @package chamilo.plugin.ticket
  6. */
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. api_protect_admin_script(true);
  9. $libPath = api_get_path(LIBRARY_PATH);
  10. $webLibPath = api_get_path(WEB_LIBRARY_PATH);
  11. $this_section = 'tickets';
  12. unset($_SESSION['this_section']);
  13. $table = new SortableTable(
  14. 'TicketProject',
  15. array('TicketManager', 'getProjectsCount'),
  16. array('TicketManager', 'getProjects'),
  17. 1
  18. );
  19. if ($table->per_page == 0) {
  20. $table->per_page = 20;
  21. }
  22. $formToString = '';
  23. $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  24. $action = isset($_GET['action']) ? $_GET['action'] : '';
  25. $interbreadcrumb[] = array(
  26. 'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php',
  27. 'name' => get_lang('MyTickets')
  28. );
  29. $interbreadcrumb[] = array(
  30. 'url' => api_get_path(WEB_CODE_PATH).'ticket/settings.php',
  31. 'name' => get_lang('Settings')
  32. );
  33. $interbreadcrumb[] = array(
  34. 'url' => api_get_path(WEB_CODE_PATH).'ticket/projects.php',
  35. 'name' => get_lang('Projects')
  36. );
  37. switch ($action) {
  38. case 'delete':
  39. $tickets = TicketManager::getTicketsFromCriteria(['project' => $id]);
  40. if (empty($tickets)) {
  41. TicketManager::deleteProject($id);
  42. Display::addFlash(Display::return_message(get_lang('Deleted')));
  43. } else {
  44. Display::addFlash(Display::return_message(get_lang('ThisItemIsRelatedToOtherTickets')));
  45. }
  46. header("Location: ".api_get_self());
  47. exit;
  48. break;
  49. case 'add':
  50. $toolName = get_lang('Add');
  51. $url = api_get_self().'?action=add';
  52. $form = TicketManager::getProjectForm($url);
  53. $formToString = $form->returnForm();
  54. if ($form->validate()) {
  55. $values = $form->getSubmitValues();
  56. $params = [
  57. 'name' => $values['name'],
  58. 'description' => $values['description']
  59. ];
  60. TicketManager::addProject($params);
  61. Display::addFlash(Display::return_message(get_lang('Added')));
  62. header("Location: ".api_get_self());
  63. exit;
  64. }
  65. break;
  66. case 'edit':
  67. $item = TicketManager::getProject($_GET['id']);
  68. if (empty($item)) {
  69. api_not_allowed(true);
  70. }
  71. $toolName = get_lang('Edit');
  72. $url = api_get_self().'?action=edit&id='.$id;
  73. $form = TicketManager::getProjectForm($url);
  74. $form->setDefaults([
  75. 'name' => $item->getName(),
  76. 'description' => $item->getDescription()
  77. ]);
  78. $formToString = $form->returnForm();
  79. if ($form->validate()) {
  80. $values = $form->getSubmitValues();
  81. $params = [
  82. 'name' => $values['name'],
  83. 'description' => $values['description'],
  84. 'sys_lastedit_datetime' => api_get_utc_datetime(),
  85. 'sys_lastedit_user_id' => api_get_user_id()
  86. ];
  87. TicketManager::updateProject($_GET['id'], $params);
  88. Display::addFlash(Display::return_message(get_lang('Updated')));
  89. header("Location: ".api_get_self());
  90. exit;
  91. }
  92. break;
  93. default:
  94. break;
  95. }
  96. $user_id = api_get_user_id();
  97. $isAdmin = api_is_platform_admin();
  98. /**
  99. * Build the modify-column of the table
  100. * @param int The user id
  101. * @param string URL params to add to table links
  102. * @param array Row of elements to alter
  103. * @return string Some HTML-code with modify-buttons
  104. */
  105. function modify_filter($id, $params, $row)
  106. {
  107. $result = Display::url(
  108. get_lang('Tickets'),
  109. "tickets.php?project_id={$row['id']}",
  110. ['class' => 'btn btn-small btn-default']
  111. );
  112. $result .= Display::url(
  113. get_lang('Categories'),
  114. "categories.php?project_id={$row['id']}",
  115. ['class' => 'btn btn-default']
  116. );
  117. $result .= Display::url(
  118. Display::return_icon('edit.png', get_lang('Edit')),
  119. "projects.php?action=edit&id={$row['id']}"
  120. );
  121. $result .= Display::url(
  122. Display::return_icon('delete.png', get_lang('Delete')),
  123. "projects.php?action=delete&id={$row['id']}"
  124. );
  125. return $result;
  126. }
  127. $table->set_header(0, '', false);
  128. $table->set_header(1, get_lang('Title'), false);
  129. $table->set_header(2, get_lang('Description'), true, array("style" => "width:200px"));
  130. $table->set_header(3, get_lang('Actions'), true);
  131. $table->set_column_filter('3', 'modify_filter');
  132. Display::display_header('');
  133. $items = [
  134. [
  135. 'url' => 'projects.php?action=add',
  136. 'content' => Display::return_icon('new_folder.png', null, null, ICON_SIZE_MEDIUM)
  137. ]
  138. ];
  139. echo Display::actions($items);
  140. echo $formToString;
  141. echo $table->return_table();
  142. Display::display_footer();