course_list.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script shows a list of courses and allows searching for courses codes
  5. * and names
  6. * @package chamilo.admin
  7. */
  8. /* INIT SECTION */
  9. // Language files that need to be included.
  10. $language_file = array('admin', 'courses');
  11. $cidReset = true;
  12. require_once '../inc/global.inc.php';
  13. $this_section = SECTION_PLATFORM_ADMIN;
  14. api_protect_admin_script();
  15. require_once '../gradebook/lib/be/gradebookitem.class.php';
  16. require_once '../gradebook/lib/be/category.class.php';
  17. /**
  18. * Get the number of courses which will be displayed
  19. */
  20. function get_number_of_courses() {
  21. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  22. $sql = "SELECT COUNT(code) AS total_number_of_items FROM $course_table";
  23. global $_configuration;
  24. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls'] && api_get_current_access_url_id() != -1) {
  25. $access_url_rel_course_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  26. $sql.= " INNER JOIN $access_url_rel_course_table url_rel_course ON (code=url_rel_course.course_code)";
  27. }
  28. if (isset ($_GET['keyword'])) {
  29. $keyword = Database::escape_string($_GET['keyword']);
  30. $sql .= " WHERE (title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%' OR visual_code LIKE '%".$keyword."%')";
  31. }
  32. elseif (isset ($_GET['keyword_code'])) {
  33. $keyword_code = Database::escape_string($_GET['keyword_code']);
  34. $keyword_title = Database::escape_string($_GET['keyword_title']);
  35. $keyword_category = Database::escape_string($_GET['keyword_category']);
  36. $keyword_language = Database::escape_string($_GET['keyword_language']);
  37. $keyword_visibility = Database::escape_string($_GET['keyword_visibility']);
  38. $keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']);
  39. $keyword_unsubscribe = Database::escape_string($_GET['keyword_unsubscribe']);
  40. $sql .= " WHERE (code LIKE '%".$keyword_code."%' OR visual_code LIKE '%".$keyword_code."%') AND title LIKE '%".$keyword_title."%' AND category_code LIKE '%".$keyword_category."%' AND course_language LIKE '%".$keyword_language."%' AND visibility LIKE '%".$keyword_visibility."%' AND subscribe LIKE '".$keyword_subscribe."'AND unsubscribe LIKE '".$keyword_unsubscribe."'";
  41. }
  42. // adding the filter to see the user's only of the current access_url
  43. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls'] && api_get_current_access_url_id() != -1) {
  44. $sql.= " AND url_rel_course.access_url_id=".api_get_current_access_url_id();
  45. }
  46. $res = Database::query($sql);
  47. $obj = Database::fetch_object($res);
  48. return $obj->total_number_of_items;
  49. }
  50. /**
  51. * Get course data to display
  52. */
  53. function get_course_data($from, $number_of_items, $column, $direction) {
  54. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  55. $sql = "SELECT code AS col0, title AS col1, visual_code AS col2, course_language AS col3, category_code AS col4, subscribe AS col5, unsubscribe AS col6,
  56. code AS col7, visibility AS col8, directory as col9
  57. FROM $course_table";
  58. global $_configuration;
  59. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls'] && api_get_current_access_url_id() != -1) {
  60. $access_url_rel_course_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  61. $sql.= " INNER JOIN $access_url_rel_course_table url_rel_course ON (code=url_rel_course.course_code)";
  62. }
  63. if (isset ($_GET['keyword'])) {
  64. $keyword = Database::escape_string(trim($_GET['keyword']));
  65. $sql .= " WHERE (title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%' OR visual_code LIKE '%".$keyword."%' ) ";
  66. } elseif (isset ($_GET['keyword_code'])) {
  67. $keyword_code = Database::escape_string($_GET['keyword_code']);
  68. $keyword_title = Database::escape_string($_GET['keyword_title']);
  69. $keyword_category = Database::escape_string($_GET['keyword_category']);
  70. $keyword_language = Database::escape_string($_GET['keyword_language']);
  71. $keyword_visibility = Database::escape_string($_GET['keyword_visibility']);
  72. $keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']);
  73. $keyword_unsubscribe = Database::escape_string($_GET['keyword_unsubscribe']);
  74. $sql .= " WHERE (code LIKE '%".$keyword_code."%' OR visual_code LIKE '%".$keyword_code."%') AND title LIKE '%".$keyword_title."%' AND category_code LIKE '%".$keyword_category."%' AND course_language LIKE '%".$keyword_language."%' AND visibility LIKE '%".$keyword_visibility."%' AND subscribe LIKE '".$keyword_subscribe."'AND unsubscribe LIKE '".$keyword_unsubscribe."'";
  75. }
  76. // Adding the filter to see the user's only of the current access_url.
  77. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls'] && api_get_current_access_url_id() != -1) {
  78. $sql.= " AND url_rel_course.access_url_id=".api_get_current_access_url_id();
  79. }
  80. $sql .= " ORDER BY col$column $direction ";
  81. $sql .= " LIMIT $from,$number_of_items";
  82. $res = Database::query($sql);
  83. $courses = array ();
  84. while ($course = Database::fetch_row($res)) {
  85. // Place colour icons in front of courses.
  86. $course[1] = get_course_visibility_icon($course[8]).'<a href="'.api_get_path(WEB_COURSE_PATH).$course[9].'/index.php">'.$course[1].'</a>';
  87. $course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  88. $course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  89. $course_rem = array($course[0], $course[1], $course[2], $course[3], $course[4], $course[5], $course[6], $course[7]);
  90. $courses[] = $course_rem;
  91. }
  92. return $courses;
  93. }
  94. /**
  95. * Filter to display the edit-buttons
  96. */
  97. function modify_filter($code) {
  98. $icourse = api_get_course_info($code);
  99. return
  100. '<a href="course_information.php?code='.$code.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>&nbsp;'.
  101. //'<a href="../course_home/course_home.php?cidReq='.$code.'">'.Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>&nbsp;'. // This is not the preferable way to go to the homepage.
  102. '<a href="'.api_get_path(WEB_COURSE_PATH).$icourse['path'].'/index.php">'.Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>&nbsp;'.
  103. '<a href="../tracking/courseLog.php?cidReq='.$code.'">'.Display::return_icon('statistics.gif', get_lang('Tracking')).'</a>&nbsp;'.
  104. '<a href="course_edit.php?course_code='.$code.'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;'.
  105. '<a href="../coursecopy/backup.php?cidReq='.$code.'">'.Display::return_icon('backup.gif', get_lang('CreateBackup')).'</a>&nbsp;'.
  106. '<a href="course_list.php?delete_course='.$code.'" onclick="javascript: if (!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
  107. }
  108. /**
  109. * Return an icon representing the visibility of the course
  110. */
  111. function get_course_visibility_icon($v) {
  112. $path = api_get_path(REL_CODE_PATH);
  113. $style = 'margin-bottom:-5px;margin-right:5px;';
  114. switch($v) {
  115. case 0:
  116. return Display::return_icon('bullet_red.gif', get_lang('CourseVisibilityClosed'), array('style' => $style));
  117. break;
  118. case 1:
  119. return Display::return_icon('bullet_orange.gif', get_lang('Private'), array('style' => $style));
  120. break;
  121. case 2:
  122. return Display::return_icon('bullet_green.gif', get_lang('OpenToThePlatform'), array('style' => $style));
  123. break;
  124. case 3:
  125. return Display::return_icon('bullet_blue.gif', get_lang('OpenToTheWorld'), array('style' => $style));
  126. break;
  127. default:
  128. return '';
  129. }
  130. }
  131. if (isset ($_POST['action'])) {
  132. switch ($_POST['action']) {
  133. // Delete selected courses
  134. case 'delete_courses' :
  135. $course_codes = $_POST['course'];
  136. if (count($course_codes) > 0) {
  137. foreach ($course_codes as $index => $course_code) {
  138. CourseManager :: delete_course($course_code);
  139. $obj_cat=new Category();
  140. $obj_cat->update_category_delete($course_code);
  141. }
  142. }
  143. break;
  144. }
  145. }
  146. $content = '';
  147. $message = '';
  148. $actions = '';
  149. if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
  150. // Get all course categories
  151. $table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  152. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  153. $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
  154. $tool_name = get_lang('SearchACourse');
  155. //api_display_tool_title($tool_name);
  156. $form = new FormValidator('advanced_course_search', 'get');
  157. $form->addElement('header', $tool_name);
  158. $form->add_textfield('keyword_code', get_lang('CourseCode'), false);
  159. $form->add_textfield('keyword_title', get_lang('Title'), false);
  160. $categories = array();
  161. $categories_select = $form->addElement('select', 'keyword_category', get_lang('CourseFaculty'), $categories);
  162. CourseManager::select_and_sort_categories($categories_select);
  163. $el = & $form->addElement('select_language', 'keyword_language', get_lang('CourseLanguage'));
  164. $el->addOption(get_lang('All'), '%');
  165. $form->addElement('radio', 'keyword_visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  166. $form->addElement('radio', 'keyword_visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  167. $form->addElement('radio', 'keyword_visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  168. $form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  169. $form->addElement('radio', 'keyword_visibility', null, get_lang('All'), '%');
  170. $form->addElement('radio', 'keyword_subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  171. $form->addElement('radio', 'keyword_subscribe', null, get_lang('Denied'), 0);
  172. $form->addElement('radio', 'keyword_subscribe', null, get_lang('All'), '%');
  173. $form->addElement('radio', 'keyword_unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  174. $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  175. $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('All'), '%');
  176. $form->addElement('style_submit_button', 'submit', get_lang('SearchCourse'),'class="btn"');
  177. $defaults['keyword_language'] = '%';
  178. $defaults['keyword_visibility'] = '%';
  179. $defaults['keyword_subscribe'] = '%';
  180. $defaults['keyword_unsubscribe'] = '%';
  181. $form->setDefaults($defaults);
  182. $content .= $form->return_form();
  183. } else {
  184. $interbreadcrumb[] = array ('url' => 'index.php', "name" => get_lang('PlatformAdmin'));
  185. $tool_name = get_lang('CourseList');
  186. if (isset($_GET['action'])) {
  187. switch ($_GET['action']) {
  188. case 'show_msg':
  189. if (!empty($_GET['warn'])) {
  190. $message = Display::return_message(urldecode($_GET['warn']), 'warning');
  191. }
  192. if (!empty($_GET['msg'])) {
  193. $message = Display::return_message(urldecode($_GET['msg']));
  194. }
  195. break;
  196. default:
  197. break;
  198. }
  199. }
  200. if (isset ($_GET['delete_course'])) {
  201. CourseManager :: delete_course($_GET['delete_course']);
  202. $obj_cat = new Category();
  203. $obj_cat->update_category_delete($_GET['delete_course']);
  204. }
  205. // Create a search-box
  206. $form = new FormValidator('search_simple', 'get', '', '', array('class'=>'form-search'), false);
  207. $form->addElement('text', 'keyword', null);
  208. $form->addElement('style_submit_button', 'submit', get_lang('SearchCourse'), 'class="btn"');
  209. $form->addElement('static', 'search_advanced_link', null, '<a href="course_list.php?search=advanced">'.get_lang('AdvancedSearch').'</a>');
  210. $actions .= '<div style="float: right; ">';
  211. $actions .= '<a href="course_add.php">'.Display::return_icon('new_course.png', get_lang('AddCourse'),'',ICON_SIZE_MEDIUM).'</a> ';
  212. if (api_get_setting('course_validation') == 'true') {
  213. $actions .= '<a href="course_request_review.php">'.Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests'),'',ICON_SIZE_MEDIUM).'</a>';
  214. }
  215. $actions .= '</div>';
  216. $actions .= $form->return_form();
  217. // Create a sortable table with the course data
  218. $table = new SortableTable('courses', 'get_number_of_courses', 'get_course_data', 2);
  219. $parameters=array();
  220. if (isset ($_GET['keyword'])) {
  221. $parameters = array ('keyword' => Security::remove_XSS($_GET['keyword']));
  222. } elseif (isset ($_GET['keyword_code'])) {
  223. $parameters['keyword_code'] = Security::remove_XSS($_GET['keyword_code']);
  224. $parameters['keyword_title'] = Security::remove_XSS($_GET['keyword_title']);
  225. $parameters['keyword_category'] = Security::remove_XSS($_GET['keyword_category']);
  226. $parameters['keyword_language'] = Security::remove_XSS($_GET['keyword_language']);
  227. $parameters['keyword_visibility'] = Security::remove_XSS($_GET['keyword_visibility']);
  228. $parameters['keyword_subscribe'] = Security::remove_XSS($_GET['keyword_subscribe']);
  229. $parameters['keyword_unsubscribe'] = Security::remove_XSS($_GET['keyword_unsubscribe']);
  230. }
  231. $table->set_additional_parameters($parameters);
  232. $table->set_header(0, '', false, 'width="8px"');
  233. $table->set_header(1, get_lang('Title'), true, 'width="360px"');
  234. $table->set_header(2, get_lang('Code'));
  235. $table->set_header(3, get_lang('Language'), true, 'width="70px"');
  236. $table->set_header(4, get_lang('Category'));
  237. $table->set_header(5, get_lang('SubscriptionAllowed'), true, 'width="60px"');
  238. $table->set_header(6, get_lang('UnsubscriptionAllowed'), false, 'width="50px"');
  239. //$table->set_header(7, get_lang('Teacher'));
  240. $table->set_header(7, get_lang('Action'), false, 'width="160px"', array('class'=>'td_actions'));
  241. $table->set_column_filter(7, 'modify_filter');
  242. $table->set_form_actions(array('delete_courses' => get_lang('DeleteCourse')), 'course');
  243. $content .= $table->return_table();
  244. }
  245. $tpl = new Template($tool_name);
  246. $tpl->assign('actions', $actions);
  247. $tpl->assign('message', $message);
  248. $tpl->assign('content', $content);
  249. $tpl->display_one_col_template();