projects.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. * @package chamilo.plugin.ticket
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_protect_admin_script(true);
  11. $libPath = api_get_path(LIBRARY_PATH);
  12. $webLibPath = api_get_path(WEB_LIBRARY_PATH);
  13. $this_section = 'tickets';
  14. Session::erase('this_section');
  15. $table = new SortableTable(
  16. 'TicketProject',
  17. array('TicketManager', 'getProjectsCount'),
  18. array('TicketManager', 'getProjects'),
  19. 1
  20. );
  21. if ($table->per_page == 0) {
  22. $table->per_page = 20;
  23. }
  24. $formToString = '';
  25. $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  26. $action = isset($_GET['action']) ? $_GET['action'] : '';
  27. $interbreadcrumb[] = array(
  28. 'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php',
  29. 'name' => get_lang('MyTickets')
  30. );
  31. $interbreadcrumb[] = array(
  32. 'url' => api_get_path(WEB_CODE_PATH).'ticket/settings.php',
  33. 'name' => get_lang('Settings')
  34. );
  35. $interbreadcrumb[] = array(
  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($_GET['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($_GET['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. * @param int The user id
  103. * @param string URL params to add to table links
  104. * @param array Row of elements to alter
  105. * @return string Some HTML-code with modify-buttons
  106. */
  107. function modify_filter($id, $params, $row)
  108. {
  109. $result = Display::url(
  110. get_lang('Tickets'),
  111. "tickets.php?project_id={$row['id']}",
  112. ['class' => 'btn btn-small btn-default']
  113. );
  114. $result .= Display::url(
  115. get_lang('Categories'),
  116. "categories.php?project_id={$row['id']}",
  117. ['class' => 'btn btn-default']
  118. );
  119. $result .= Display::url(
  120. Display::return_icon('edit.png', get_lang('Edit')),
  121. "projects.php?action=edit&id={$row['id']}"
  122. );
  123. $result .= Display::url(
  124. Display::return_icon('delete.png', get_lang('Delete')),
  125. "projects.php?action=delete&id={$row['id']}"
  126. );
  127. return $result;
  128. }
  129. $table->set_header(0, '', false);
  130. $table->set_header(1, get_lang('Title'), false);
  131. $table->set_header(2, get_lang('Description'), true, array("style" => "width:200px"));
  132. $table->set_header(3, get_lang('Actions'), true);
  133. $table->set_column_filter('3', 'modify_filter');
  134. Display::display_header('');
  135. $items = [
  136. [
  137. 'url' => 'projects.php?action=add',
  138. 'content' => Display::return_icon('new_folder.png', null, null, ICON_SIZE_MEDIUM)
  139. ]
  140. ];
  141. echo Display::actions($items);
  142. echo $formToString;
  143. echo $table->return_table();
  144. Display::display_footer();