course_request_accepted.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * A list containig the accepted course requests.
  5. *
  6. * @package chamilo.admin
  7. *
  8. * @author José Manuel Abuin Mosquera <chema@cesga.es>, 2010
  9. * @author Bruno Rubio Gayo <brubio@cesga.es>, 2010
  10. * Centro de Supercomputacion de Galicia (CESGA)
  11. * @author Ivan Tcholakov <ivantcholakov@gmail.com> (technical adaptation for Chamilo 1.8.8), 2010
  12. */
  13. $cidReset = true;
  14. require_once __DIR__.'/../inc/global.inc.php';
  15. $this_section = SECTION_PLATFORM_ADMIN;
  16. api_protect_admin_script();
  17. // A check whether the course validation feature is enabled.
  18. $course_validation_feature = api_get_setting('course_validation') == 'true';
  19. // Filltering passed to this page parameters.
  20. $delete_course_request = isset($_GET['delete_course_request']) ? intval($_GET['delete_course_request']) : '';
  21. $message = isset($_GET['message']) ? trim(Security::remove_XSS(stripslashes(urldecode($_GET['message'])))) : '';
  22. $is_error_message = !empty($_GET['is_error_message']);
  23. if ($course_validation_feature) {
  24. /**
  25. * Deletion of a course request.
  26. */
  27. if (!empty($delete_course_request)) {
  28. $course_request_code = CourseRequestManager::get_course_request_code($delete_course_request);
  29. $result = CourseRequestManager::delete_course_request($delete_course_request);
  30. if ($result) {
  31. $message = sprintf(get_lang('CourseRequestDeleted'), $course_request_code);
  32. $is_error_message = false;
  33. } else {
  34. $message = sprintf(get_lang('CourseRequestDeletionFailed'), $course_request_code);
  35. $is_error_message = true;
  36. }
  37. } elseif (isset($_POST['action'])) {
  38. /**
  39. * Form actions: delete.
  40. */
  41. switch ($_POST['action']) {
  42. // Delete selected courses
  43. case 'delete_course_requests':
  44. $course_requests = $_POST['course_request'];
  45. if (is_array($_POST['course_request']) && !empty($_POST['course_request'])) {
  46. $success = true;
  47. foreach ($_POST['course_request'] as $index => $course_request_id) {
  48. $success &= CourseRequestManager::delete_course_request($course_request_id);
  49. }
  50. $message = $success ? get_lang('SelectedCourseRequestsDeleted') : get_lang('SomeCourseRequestsNotDeleted');
  51. $is_error_message = !$success;
  52. }
  53. break;
  54. }
  55. }
  56. } else {
  57. $link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Platform#course_validation';
  58. $message = sprintf(
  59. get_lang('PleaseActivateCourseValidationFeature'),
  60. sprintf('<strong><a href="%s">%s</a></strong>', $link_to_setting, get_lang('EnableCourseValidation'))
  61. );
  62. $is_error_message = true;
  63. }
  64. /**
  65. * Get the number of courses which will be displayed.
  66. */
  67. function get_number_of_requests()
  68. {
  69. return CourseRequestManager::count_course_requests(COURSE_REQUEST_ACCEPTED);
  70. }
  71. /**
  72. * Get course data to display.
  73. */
  74. function get_request_data($from, $number_of_items, $column, $direction)
  75. {
  76. $keyword = isset($_GET['keyword']) ? Database::escape_string(trim($_GET['keyword'])) : null;
  77. $course_request_table = Database::get_main_table(TABLE_MAIN_COURSE_REQUEST);
  78. $from = intval($from);
  79. $number_of_items = intval($number_of_items);
  80. $column = intval($column);
  81. $direction = !in_array(strtolower(trim($direction)), ['asc', 'desc']) ? 'asc' : $direction;
  82. $sql = "SELECT
  83. id AS col0,
  84. code AS col1,
  85. title AS col2,
  86. category_code AS col3,
  87. tutor_name AS col4,
  88. request_date AS col5,
  89. id AS col6
  90. FROM $course_request_table
  91. WHERE status = ".COURSE_REQUEST_ACCEPTED;
  92. if ($keyword != '') {
  93. $sql .= " AND (
  94. title LIKE '%".$keyword."%' OR
  95. code LIKE '%".$keyword."%' OR
  96. visual_code LIKE '%".$keyword."%'
  97. )";
  98. }
  99. $sql .= " ORDER BY col$column $direction ";
  100. $sql .= " LIMIT $from,$number_of_items";
  101. $res = Database :: query($sql);
  102. $course_requests = [];
  103. while ($course_request = Database :: fetch_row($res)) {
  104. $course_request[5] = api_get_local_time($course_request[5]);
  105. $course_requests[] = $course_request;
  106. }
  107. return $course_requests;
  108. }
  109. /**
  110. * Actions in the list: edit, accept, delete.
  111. */
  112. function modify_filter($id)
  113. {
  114. $code = CourseRequestManager::get_course_request_code($id);
  115. $result = '<a href="course_request_edit.php?id='.$id.'&caller=1">'.
  116. Display::return_icon('edit.png', get_lang('Edit'), ['style' => 'vertical-align: middle;']).'</a>'.
  117. '&nbsp;<a href="?delete_course_request='.$id.'">'.
  118. Display::return_icon(
  119. 'delete.png',
  120. get_lang('DeleteThisCourseRequest'),
  121. [
  122. 'style' => 'vertical-align: middle;',
  123. 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeDeleted'), $code), ENT_QUOTES)).'\')) return false;',
  124. ]
  125. ).
  126. '</a>';
  127. return $result;
  128. }
  129. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  130. $interbreadcrumb[] = ['url' => 'course_list.php', 'name' => get_lang('CourseList')];
  131. $tool_name = get_lang('AcceptedCourseRequests');
  132. // Display confirmation or error message.
  133. if (!empty($message)) {
  134. if ($is_error_message) {
  135. Display::addFlash(Display::return_message($message, 'error', false));
  136. } else {
  137. Display::addFlash(Display::return_message($message, 'normal', false));
  138. }
  139. }
  140. Display :: display_header($tool_name);
  141. if (!$course_validation_feature) {
  142. Display :: display_footer();
  143. exit;
  144. }
  145. // Create a simple search-box.
  146. $form = new FormValidator('search_simple', 'get', '', '', 'width=200px', false);
  147. $renderer = $form->defaultRenderer();
  148. $renderer->setCustomElementTemplate('<span>{element}</span> ');
  149. $form->addElement('text', 'keyword', get_lang('Keyword'));
  150. $form->addButtonSearch(get_lang('Search'));
  151. // The action bar.
  152. echo '<div style="float: right; margin-top: 5px; margin-right: 5px;">';
  153. echo ' <a href="course_request_review.php">'.
  154. Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').'</a>';
  155. echo ' <a href="course_request_rejected.php">'.
  156. Display::return_icon('course_request_rejected.gif', get_lang('RejectedCourseRequests')).get_lang('RejectedCourseRequests').'</a>';
  157. echo '</div>';
  158. echo '<div class="actions">';
  159. $form->display();
  160. echo '</div>';
  161. // Create a sortable table with the course data.
  162. $table = new SortableTable('course_requests_accepted', 'get_number_of_requests', 'get_request_data', 5, 20, 'DESC');
  163. $table->set_header(0, '', false);
  164. $table->set_header(1, get_lang('Code'));
  165. $table->set_header(2, get_lang('Title'));
  166. $table->set_header(3, get_lang('Category'));
  167. $table->set_header(4, get_lang('Teacher'));
  168. $table->set_header(5, get_lang('CourseRequestDate'));
  169. $table->set_header(6, '', false);
  170. $table->set_column_filter(6, 'modify_filter');
  171. $table->set_form_actions(['delete_course_requests' => get_lang('DeleteCourseRequests')], 'course_request');
  172. $table->display();
  173. /* FOOTER */
  174. Display :: display_footer();