course_request_accepted.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. /* INIT SECTION */
  13. // Language files that need to be included.
  14. $language_file = array('admin', 'create_course');
  15. $cidReset = true;
  16. ////require_once '../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. $delete_course_request = intval($_GET['delete_course_request']);
  23. $message = trim(Security::remove_XSS(stripslashes(urldecode($_GET['message']))));
  24. $is_error_message = !empty($_GET['is_error_message']);
  25. $keyword = Database::escape_string(trim($_GET['keyword']));
  26. if ($course_validation_feature) {
  27. /**
  28. * Deletion of a course request.
  29. */
  30. if (!empty($delete_course_request)) {
  31. $course_request_code = CourseRequestManager::get_course_request_code($delete_course_request);
  32. $result = CourseRequestManager::delete_course_request($delete_course_request);
  33. if ($result) {
  34. $message = sprintf(get_lang('CourseRequestDeleted'), $course_request_code);
  35. $is_error_message = false;
  36. } else {
  37. $message = sprintf(get_lang('CourseRequestDeletionFailed'), $course_request_code);
  38. $is_error_message = true;
  39. }
  40. }
  41. /**
  42. * Form actions: delete.
  43. */
  44. elseif (isset($_POST['action'])) {
  45. switch ($_POST['action']) {
  46. // Delete selected courses
  47. case 'delete_course_requests' :
  48. $course_requests = $_POST['course_request'];
  49. if (is_array($_POST['course_request']) && !empty($_POST['course_request'])) {
  50. $success = true;
  51. foreach ($_POST['course_request'] as $index => $course_request_id) {
  52. $success &= CourseRequestManager::delete_course_request($course_request_id);
  53. }
  54. $message = $success ? get_lang('SelectedCourseRequestsDeleted') : get_lang('SomeCourseRequestsNotDeleted');
  55. $is_error_message = !$success;
  56. }
  57. break;
  58. }
  59. }
  60. } else {
  61. $link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Platform#course_validation';
  62. $message = sprintf(get_lang('PleaseActivateCourseValidationFeature'), sprintf('<strong><a href="%s">%s</a></strong>', $link_to_setting, get_lang('EnableCourseValidation')));
  63. $is_error_message = true;
  64. }
  65. /**
  66. * Get the number of courses which will be displayed.
  67. */
  68. function get_number_of_requests() {
  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. $keyword = Database::escape_string(trim($_GET['keyword']));
  76. $course_request_table = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST);
  77. $sql = "SELECT id AS col0,
  78. code AS col1,
  79. title AS col2,
  80. category_code AS col3,
  81. tutor_name AS col4,
  82. request_date AS col5,
  83. id AS col6
  84. FROM $course_request_table WHERE status = ".COURSE_REQUEST_ACCEPTED;
  85. if ($keyword != '') {
  86. $sql .= " AND (title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%' OR visual_code LIKE '%".$keyword."%')";
  87. }
  88. $sql .= " ORDER BY col$column $direction ";
  89. $sql .= " LIMIT $from,$number_of_items";
  90. $res = Database :: query($sql);
  91. $course_requests = array();
  92. while ($course_request = Database :: fetch_row($res)) {
  93. $course_request[5] = api_get_local_time($course_request[5]);
  94. $course_requests[] = $course_request;
  95. }
  96. return $course_requests;
  97. }
  98. /**
  99. * Actions in the list: edit, accept, delete.
  100. */
  101. function modify_filter($id) {
  102. $code = CourseRequestManager::get_course_request_code($id);
  103. $result = '<a href="course_request_edit.php?id='.$id.'&caller=1">'.Display::return_icon('edit.gif', get_lang('Edit'), array('style' => 'vertical-align: middle;')).'</a>'.
  104. '&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>';
  105. return $result;
  106. }
  107. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  108. $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
  109. $tool_name = get_lang('AcceptedCourseRequests');
  110. Display :: display_header($tool_name);
  111. // Display confirmation or error message.
  112. if (!empty($message)) {
  113. if ($is_error_message) {
  114. Display::display_error_message($message, false);
  115. } else {
  116. Display::display_normal_message($message, false);
  117. }
  118. }
  119. if (!$course_validation_feature) {
  120. Display :: display_footer();
  121. exit;
  122. }
  123. // Create a simple search-box.
  124. $form = new FormValidator('search_simple', 'get', '', '', 'width=200px', false);
  125. $renderer = $form->defaultRenderer();
  126. $renderer->setElementTemplate('<span>{element}</span> ');
  127. $form->addElement('text', 'keyword', get_lang('keyword'));
  128. $form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"');
  129. // The action bar.
  130. echo '<div style="float: right; margin-top: 5px; margin-right: 5px;">';
  131. //echo '<a href="course_list.php">'.Display::return_icon('courses.gif', get_lang('CourseList')).get_lang('CourseList').'</a>';
  132. echo ' <a href="course_request_review.php">'.Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').'</a>';
  133. echo ' <a href="course_request_rejected.php">'.Display::return_icon('course_request_rejected.gif', get_lang('RejectedCourseRequests')).get_lang('RejectedCourseRequests').'</a>';
  134. echo '</div>';
  135. echo '<div class="actions">';
  136. $form->display();
  137. echo '</div>';
  138. // Create a sortable table with the course data.
  139. $table = new SortableTable('course_requests_accepted', 'get_number_of_requests', 'get_request_data', 5, 20, 'DESC');
  140. $table->set_additional_parameters($parameters);
  141. $table->set_header(0, '', false);
  142. $table->set_header(1, get_lang('Code'));
  143. $table->set_header(2, get_lang('Title'));
  144. $table->set_header(3, get_lang('Category'));
  145. $table->set_header(4, get_lang('Teacher'));
  146. $table->set_header(5, get_lang('CourseRequestDate'));
  147. $table->set_header(6, '', false);
  148. $table->set_column_filter(6, 'modify_filter');
  149. $table->set_form_actions(array('delete_course_requests' => get_lang('DeleteCourseRequests')), 'course_request');
  150. $table->display();
  151. /* FOOTER */
  152. Display :: display_footer();