projects.php 5.1 KB

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