course_request_accepted.php 7.0 KB

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