course_request_rejected.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * A list containig the rejected 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. /* INIT SECTION */
  13. // Language files that need to be included.
  14. $language_file = array('admin', 'create_course');
  15. $cidReset = true;
  16. require '../inc/global.inc.php';
  17. $this_section = SECTION_PLATFORM_ADMIN;
  18. api_protect_admin_script();
  19. // A check whether the course validation feature is enabled.
  20. $course_validation_feature = api_get_setting('course_validation') == 'true';
  21. // Filltering passed to this page parameters.
  22. $accept_course_request = intval($_GET['accept_course_request']);
  23. $delete_course_request = intval($_GET['delete_course_request']);
  24. $request_info = intval($_GET['request_info']);
  25. $message = trim(Security::remove_XSS(stripslashes(urldecode($_GET['message']))));
  26. $is_error_message = !empty($_GET['is_error_message']);
  27. $keyword = Database::escape_string(trim($_GET['keyword']));
  28. if ($course_validation_feature) {
  29. /**
  30. * Acceptance and creation of the requested course.
  31. */
  32. if (!empty($accept_course_request)) {
  33. $course_request_code = CourseRequestManager::get_course_request_code($accept_course_request);
  34. $course_id = CourseRequestManager::accept_course_request($accept_course_request);
  35. if ($course_id) {
  36. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  37. $message = sprintf(get_lang('CourseRequestAccepted'), $course_request_code, $course_code);
  38. $is_error_message = false;
  39. } else {
  40. $message = sprintf(get_lang('CourseRequestAcceptanceFailed'), $course_request_code);
  41. $is_error_message = true;
  42. }
  43. }
  44. /**
  45. * Sending to the teacher a request for additional information about the proposed course.
  46. */
  47. elseif (!empty($request_info)) {
  48. $course_request_code = CourseRequestManager::get_course_request_code($request_info);
  49. $result = CourseRequestManager::ask_for_additional_info($request_info);
  50. if ($result) {
  51. $message = sprintf(get_lang('CourseRequestInfoAsked'), $course_request_code);
  52. $is_error_message = false;
  53. } else {
  54. $message = sprintf(get_lang('CourseRequestInfoFailed'), $course_request_code);
  55. $is_error_message = true;
  56. }
  57. }
  58. /**
  59. * Deletion of a course request.
  60. */
  61. elseif (!empty($delete_course_request)) {
  62. $course_request_code = CourseRequestManager::get_course_request_code($delete_course_request);
  63. $result = CourseRequestManager::delete_course_request($delete_course_request);
  64. if ($result) {
  65. $message = sprintf(get_lang('CourseRequestDeleted'), $course_request_code);
  66. $is_error_message = false;
  67. } else {
  68. $message = sprintf(get_lang('CourseRequestDeletionFailed'), $course_request_code);
  69. $is_error_message = true;
  70. }
  71. }
  72. /**
  73. * Form actions: delete.
  74. */
  75. elseif (isset($_POST['action'])) {
  76. switch ($_POST['action']) {
  77. // Delete selected courses
  78. case 'delete_course_requests' :
  79. $course_requests = $_POST['course_request'];
  80. if (is_array($_POST['course_request']) && !empty($_POST['course_request'])) {
  81. $success = true;
  82. foreach ($_POST['course_request'] as $index => $course_request_id) {
  83. $success &= CourseRequestManager::delete_course_request($course_request_id);
  84. }
  85. $message = $success ? get_lang('SelectedCourseRequestsDeleted') : get_lang('SomeCourseRequestsNotDeleted');
  86. $is_error_message = !$success;
  87. }
  88. break;
  89. }
  90. }
  91. } else {
  92. $link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Platform#course_validation';
  93. $message = sprintf(get_lang('PleaseActivateCourseValidationFeature'), sprintf('<strong><a href="%s">%s</a></strong>', $link_to_setting, get_lang('EnableCourseValidation')));
  94. $is_error_message = true;
  95. }
  96. /**
  97. * Get the number of courses which will be displayed.
  98. */
  99. function get_number_of_requests() {
  100. return CourseRequestManager::count_course_requests(COURSE_REQUEST_REJECTED);
  101. }
  102. /**
  103. * Get course data to display
  104. */
  105. function get_request_data($from, $number_of_items, $column, $direction) {
  106. global $keyword;
  107. $course_request_table = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST);
  108. $sql = "SELECT id AS col0,
  109. code AS col1,
  110. title AS col2,
  111. category_code AS col3,
  112. tutor_name AS col4,
  113. request_date AS col5,
  114. id AS col6
  115. FROM $course_request_table
  116. WHERE status = ".COURSE_REQUEST_REJECTED;
  117. if ($keyword != '') {
  118. $sql .= " AND (title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%' OR visual_code LIKE '%".$keyword."%')";
  119. }
  120. $sql .= " ORDER BY col$column $direction ";
  121. $sql .= " LIMIT $from,$number_of_items";
  122. $res = Database :: query($sql);
  123. $course_requests = array();
  124. while ($course_request = Database :: fetch_row($res)) {
  125. $course_request[5] = api_get_local_time($course_request[5]);
  126. $course_requests[] = $course_request;
  127. }
  128. return $course_requests;
  129. }
  130. /**
  131. * Actions in the list: edit, accept, delete, request additional information.
  132. */
  133. function modify_filter($id) {
  134. $code = CourseRequestManager::get_course_request_code($id);
  135. $result = '<a href="course_request_edit.php?id='.$id.'&caller=2">'.Display::return_icon('edit.gif', get_lang('Edit'), array('style' => 'vertical-align: middle;')).'</a>'.
  136. '&nbsp;<a href="?accept_course_request='.$id.'">'.Display::return_icon('action_accept.gif', get_lang('AcceptThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(sprintf(get_lang('ANewCourseWillBeCreated'), $code)).'\')) return false;')).'</a>';
  137. if (!CourseRequestManager::additional_info_asked($id)) {
  138. $result .= '&nbsp;<a href="?request_info='.$id.'">'.Display::return_icon('request_info.gif', get_lang('AskAdditionalInfo'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(sprintf(get_lang('AdditionalInfoWillBeAsked'), $code)).'\')) return false;')).'</a>';
  139. }
  140. $result .= '&nbsp;<a href="?delete_course_request='.$id.'">'.Display::return_icon('delete.gif', get_lang('DeleteThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(sprintf(get_lang('ACourseRequestWillBeDeleted'), $code)).'\')) return false;')).'</a>';
  141. return $result;
  142. }
  143. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  144. $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
  145. $tool_name = get_lang('RejectedCourseRequests');
  146. Display :: display_header($tool_name);
  147. // Display confirmation or error message.
  148. if (!empty($message)) {
  149. if ($is_error_message) {
  150. Display::display_error_message($message, false);
  151. } else {
  152. Display::display_normal_message($message, false);
  153. }
  154. }
  155. if (!$course_validation_feature) {
  156. Display :: display_footer();
  157. exit;
  158. }
  159. // Create a simple search-box.
  160. $form = new FormValidator('search_simple', 'get', '', '', 'width=200px', false);
  161. $renderer = $form->defaultRenderer();
  162. $renderer->setElementTemplate('<span>{element}</span> ');
  163. $form->addElement('text', 'keyword', get_lang('keyword'));
  164. $form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"');
  165. // The action bar.
  166. echo '<div style="float: right; margin-top: 5px; margin-right: 5px;">';
  167. //echo '<a href="course_list.php">'.Display::return_icon('courses.gif', get_lang('CourseList')).get_lang('CourseList').'</a>';
  168. echo ' <a href="course_request_review.php">'.Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').'</a>';
  169. echo ' <a href="course_request_accepted.php">'.Display::return_icon('course_request_accepted.gif', get_lang('AcceptedCourseRequests')).get_lang('AcceptedCourseRequests').'</a>';
  170. echo '</div>';
  171. echo '<div class="actions">';
  172. $form->display();
  173. echo '</div>';
  174. // Create a sortable table with the course data.
  175. $table = new SortableTable('course_requests_rejected', 'get_number_of_requests', 'get_request_data', 5, 20, 'DESC');
  176. $table->set_additional_parameters($parameters);
  177. $table->set_header(0, '', false);
  178. $table->set_header(1, get_lang('Code'));
  179. $table->set_header(2, get_lang('Title'));
  180. $table->set_header(3, get_lang('Category'));
  181. $table->set_header(4, get_lang('Teacher'));
  182. $table->set_header(5, get_lang('CourseRequestDate'));
  183. $table->set_header(6, '', false);
  184. $table->set_column_filter(6, 'modify_filter');
  185. $table->set_form_actions(array('delete_course_requests' => get_lang('DeleteCourseRequests')), 'course_request');
  186. $table->display();
  187. /* FOOTER */
  188. Display :: display_footer();