course_list.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. api_protect_admin_script();
  12. $sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : null;
  13. /**
  14. * Get the number of courses which will be displayed
  15. */
  16. function get_number_of_courses()
  17. {
  18. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  19. $sql = "SELECT COUNT(code) AS total_number_of_items FROM $course_table c";
  20. if ((api_is_platform_admin() || api_is_session_admin()) &&
  21. api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1
  22. ) {
  23. $access_url_rel_course_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  24. $sql.= " INNER JOIN $access_url_rel_course_table url_rel_course
  25. ON (c.id = url_rel_course.c_id)";
  26. }
  27. if (isset ($_GET['keyword'])) {
  28. $keyword = Database::escape_string("%".$_GET['keyword']."%");
  29. $sql .= " WHERE (
  30. c.title LIKE '".$keyword."' OR
  31. c.code LIKE '".$keyword."' OR
  32. c.visual_code LIKE '".$keyword."'
  33. )
  34. ";
  35. } elseif (isset($_GET['keyword_code'])) {
  36. $keyword_code = Database::escape_string("%".$_GET['keyword_code']."%");
  37. $keyword_title = Database::escape_string("%".$_GET['keyword_title']."%");
  38. $keyword_category = Database::escape_string("%".$_GET['keyword_category']."%");
  39. $keyword_language = Database::escape_string("%".$_GET['keyword_language']."%");
  40. $keyword_visibility = Database::escape_string("%".$_GET['keyword_visibility']."%");
  41. $keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']);
  42. $keyword_unsubscribe = Database::escape_string($_GET['keyword_unsubscribe']);
  43. $sql .= " WHERE
  44. (c.code LIKE '".$keyword_code."' OR c.visual_code LIKE '".$keyword_code."') AND
  45. c.title LIKE '".$keyword_title."' AND
  46. c.category_code LIKE '".$keyword_category."' AND
  47. c.course_language LIKE '".$keyword_language."' AND
  48. c.visibility LIKE '".$keyword_visibility."' AND
  49. c.subscribe LIKE '".$keyword_subscribe."' AND
  50. c.unsubscribe LIKE '".$keyword_unsubscribe."'
  51. ";
  52. }
  53. // adding the filter to see the user's only of the current access_url
  54. if ((api_is_platform_admin() || api_is_session_admin()) &&
  55. api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1
  56. ) {
  57. $sql.= " AND url_rel_course.access_url_id = ".api_get_current_access_url_id();
  58. }
  59. $res = Database::query($sql);
  60. $obj = Database::fetch_object($res);
  61. return $obj->total_number_of_items;
  62. }
  63. /**
  64. * Get course data to display
  65. * @param int $from
  66. * @param int $number_of_items
  67. * @param int $column
  68. * @param string $direction
  69. *
  70. * @return array
  71. */
  72. function get_course_data($from, $number_of_items, $column, $direction)
  73. {
  74. $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  75. $sql = "SELECT code AS col0,
  76. title AS col1,
  77. code AS col2,
  78. course_language AS col3,
  79. category_code AS col4,
  80. subscribe AS col5,
  81. unsubscribe AS col6,
  82. code AS col7,
  83. visibility AS col8,
  84. directory as col9,
  85. visual_code
  86. FROM $course_table course";
  87. if ((api_is_platform_admin() || api_is_session_admin()) &&
  88. api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1
  89. ) {
  90. $access_url_rel_course_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  91. $sql.= " INNER JOIN $access_url_rel_course_table url_rel_course
  92. ON (course.id = url_rel_course.c_id)";
  93. }
  94. if (isset ($_GET['keyword'])) {
  95. $keyword = Database::escape_string("%".trim($_GET['keyword'])."%");
  96. $sql .= " WHERE (
  97. title LIKE '".$keyword."' OR
  98. code LIKE '".$keyword."' OR
  99. visual_code LIKE '".$keyword."'
  100. )
  101. ";
  102. } elseif (isset($_GET['keyword_code'])) {
  103. $keyword_code = Database::escape_string("%".$_GET['keyword_code']."%");
  104. $keyword_title = Database::escape_string("%".$_GET['keyword_title']."%");
  105. $keyword_category = Database::escape_string("%".$_GET['keyword_category']."%");
  106. $keyword_language = Database::escape_string("%".$_GET['keyword_language']."%");
  107. $keyword_visibility = Database::escape_string("%".$_GET['keyword_visibility']."%");
  108. $keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']);
  109. $keyword_unsubscribe = Database::escape_string($_GET['keyword_unsubscribe']);
  110. $sql .= " WHERE
  111. (code LIKE '".$keyword_code."' OR visual_code LIKE '".$keyword_code."') AND
  112. title LIKE '".$keyword_title."' AND
  113. category_code LIKE '".$keyword_category."' AND
  114. course_language LIKE '".$keyword_language."' AND
  115. visibility LIKE '".$keyword_visibility."' AND
  116. subscribe LIKE '".$keyword_subscribe."' AND
  117. unsubscribe LIKE '".$keyword_unsubscribe."'";
  118. }
  119. // Adding the filter to see the user's only of the current access_url.
  120. if ((api_is_platform_admin() || api_is_session_admin()) &&
  121. api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1
  122. ) {
  123. $sql.= " AND url_rel_course.access_url_id=".api_get_current_access_url_id();
  124. }
  125. $sql .= " ORDER BY col$column $direction ";
  126. $sql .= " LIMIT $from, $number_of_items";
  127. $res = Database::query($sql);
  128. $courses = array();
  129. $languages = api_get_languages_to_array();
  130. while ($course = Database::fetch_array($res)) {
  131. // Place colour icons in front of courses.
  132. $show_visual_code = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null;
  133. $course[1] = get_course_visibility_icon($course[8]).'<a href="'.api_get_path(WEB_COURSE_PATH).$course[9].'/index.php">'.$course[1].'</a> '.$show_visual_code;
  134. $course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  135. $course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  136. $language = isset($languages[$course[3]]) ? $languages[$course[3]] : $course[3];
  137. $course_rem = array(
  138. $course[0],
  139. $course[1],
  140. $course[2],
  141. $language,
  142. $course[4],
  143. $course[5],
  144. $course[6],
  145. $course[7],
  146. );
  147. $courses[] = $course_rem;
  148. }
  149. return $courses;
  150. }
  151. /**
  152. * Get course data to display filtered by session name
  153. * @param int $from
  154. * @param int $number_of_items
  155. * @param int $column
  156. * @param string $direction
  157. * @return array
  158. */
  159. function get_course_data_by_session($from, $number_of_items, $column, $direction)
  160. {
  161. $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  162. $session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  163. $session = Database::get_main_table(TABLE_MAIN_SESSION);
  164. $sql = "SELECT
  165. c.code AS col0,
  166. c.title AS col1,
  167. c.code AS col2,
  168. c.course_language AS col3,
  169. c.category_code AS col4,
  170. c.subscribe AS col5,
  171. c.unsubscribe AS col6,
  172. c.code AS col7,
  173. c.visibility AS col8,
  174. c.directory as col9,
  175. c.visual_code
  176. FROM $course_table c
  177. INNER JOIN $session_rel_course r
  178. ON c.id = r.c_id
  179. INNER JOIN $session s
  180. ON r.session_id = s.id
  181. ";
  182. if (isset($_GET['session_id']) && !empty($_GET['session_id'])) {
  183. $sessionId = intval($_GET['session_id']);
  184. $sql.= " WHERE s.id = ".$sessionId;
  185. }
  186. $sql .= " ORDER BY col$column $direction ";
  187. $sql .= " LIMIT $from,$number_of_items";
  188. $res = Database::query($sql);
  189. $courses = array ();
  190. while ($course = Database::fetch_array($res)) {
  191. // Place colour icons in front of courses.
  192. $show_visual_code = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null;
  193. $course[1] = get_course_visibility_icon($course[8]).'<a href="'.api_get_path(WEB_COURSE_PATH).$course[9].'/index.php">'.$course[1].'</a> '.$show_visual_code;
  194. $course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  195. $course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  196. $course_rem = array($course[0], $course[1], $course[2], $course[3], $course[4], $course[5], $course[6], $course[7]);
  197. $courses[] = $course_rem;
  198. }
  199. return $courses;
  200. }
  201. /**
  202. * Filter to display the edit-buttons
  203. */
  204. function modify_filter($code)
  205. {
  206. $icourse = api_get_course_info($code);
  207. return
  208. '<a href="course_information.php?code='.$code.'">'.
  209. Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>&nbsp;'.
  210. //'<a href="../course_home/course_home.php?cidReq='.$code.'">'.
  211. //Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>&nbsp;'. // This is not the preferable way to go to the homepage.
  212. '<a href="'.api_get_path(WEB_COURSE_PATH).$icourse['path'].'/index.php">'.
  213. Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>&nbsp;'.
  214. '<a href="../tracking/courseLog.php?cidReq='.$code.'">'.
  215. Display::return_icon('statistics.gif', get_lang('Tracking')).'</a>&nbsp;'.
  216. '<a href="course_edit.php?id='.$icourse['real_id'].'">'.
  217. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;'.
  218. '<a href="../coursecopy/create_backup.php?cidReq='.$code.'">'.
  219. Display::return_icon('backup.gif', get_lang('CreateBackup')).'</a>&nbsp;'.
  220. '<a href="course_list.php?delete_course='.$code.'" onclick="javascript: if (!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;">'.
  221. Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
  222. }
  223. /**
  224. * Return an icon representing the visibility of the course
  225. */
  226. function get_course_visibility_icon($v) {
  227. $style = 'margin-bottom:0;margin-right:5px;';
  228. switch($v) {
  229. case 0:
  230. return Display::return_icon('bullet_red.png', get_lang('CourseVisibilityClosed'), array('style' => $style));
  231. break;
  232. case 1:
  233. return Display::return_icon('bullet_orange.png', get_lang('Private'), array('style' => $style));
  234. break;
  235. case 2:
  236. return Display::return_icon('bullet_green.png', get_lang('OpenToThePlatform'), array('style' => $style));
  237. break;
  238. case 3:
  239. return Display::return_icon('bullet_blue.png', get_lang('OpenToTheWorld'), array('style' => $style));
  240. break;
  241. case 4:
  242. return Display::return_icon('bullet_grey.png', get_lang('CourseVisibilityHidden'), array('style' => $style));
  243. break;
  244. default:
  245. return '';
  246. }
  247. }
  248. if (isset ($_POST['action'])) {
  249. switch ($_POST['action']) {
  250. // Delete selected courses
  251. case 'delete_courses':
  252. $course_codes = $_POST['course'];
  253. if (count($course_codes) > 0) {
  254. foreach ($course_codes as $course_code) {
  255. CourseManager::delete_course($course_code);
  256. $obj_cat = new Category();
  257. $obj_cat->update_category_delete($course_code);
  258. }
  259. }
  260. break;
  261. }
  262. }
  263. $content = '';
  264. $message = '';
  265. $actions = '';
  266. if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
  267. // Get all course categories
  268. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  269. $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
  270. $tool_name = get_lang('SearchACourse');
  271. //api_display_tool_title($tool_name);
  272. $form = new FormValidator('advanced_course_search', 'get');
  273. $form->addElement('header', $tool_name);
  274. $form->addText('keyword_code', get_lang('CourseCode'), false);
  275. $form->addText('keyword_title', get_lang('Title'), false);
  276. // Category code
  277. $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
  278. $form->addElement(
  279. 'select_ajax',
  280. 'keyword_category',
  281. get_lang('CourseFaculty'),
  282. null,
  283. array(
  284. 'url' => $url
  285. )
  286. );
  287. $el = $form->addElement('select_language', 'keyword_language', get_lang('CourseLanguage'));
  288. $el->addOption(get_lang('All'), '%');
  289. $form->addElement('radio', 'keyword_visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  290. $form->addElement('radio', 'keyword_visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  291. $form->addElement('radio', 'keyword_visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  292. $form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  293. $form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
  294. $form->addElement('radio', 'keyword_visibility', null, get_lang('All'), '%');
  295. $form->addElement('radio', 'keyword_subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  296. $form->addElement('radio', 'keyword_subscribe', null, get_lang('Denied'), 0);
  297. $form->addElement('radio', 'keyword_subscribe', null, get_lang('All'), '%');
  298. $form->addElement('radio', 'keyword_unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  299. $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  300. $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('All'), '%');
  301. $form->addButtonSearch(get_lang('SearchCourse'));
  302. $defaults['keyword_language'] = '%';
  303. $defaults['keyword_visibility'] = '%';
  304. $defaults['keyword_subscribe'] = '%';
  305. $defaults['keyword_unsubscribe'] = '%';
  306. $form->setDefaults($defaults);
  307. $content .= $form->returnForm();
  308. } else {
  309. $interbreadcrumb[] = array ('url' => 'index.php', "name" => get_lang('PlatformAdmin'));
  310. $tool_name = get_lang('CourseList');
  311. if (isset($_GET['action'])) {
  312. switch ($_GET['action']) {
  313. case 'show_msg':
  314. if (!empty($_GET['warn'])) {
  315. $message = Display::return_message(urldecode($_GET['warn']), 'warning');
  316. }
  317. if (!empty($_GET['msg'])) {
  318. $message = Display::return_message(urldecode($_GET['msg']));
  319. }
  320. break;
  321. default:
  322. break;
  323. }
  324. }
  325. if (isset($_GET['delete_course'])) {
  326. CourseManager::delete_course($_GET['delete_course']);
  327. $obj_cat = new Category();
  328. $obj_cat->update_category_delete($_GET['delete_course']);
  329. }
  330. // Create a search-box
  331. $form = new FormValidator('search_simple', 'get', '', '', array(), FormValidator::LAYOUT_INLINE);
  332. $form->addElement('text', 'keyword', null, array('id' => 'course-search-keyword'));
  333. $form->addButtonSearch(get_lang('SearchCourse'));
  334. $advanced = '<a class="btn btn-default" href="'. api_get_path(WEB_CODE_PATH).'admin/course_list.php?search=advanced"><em class="fa fa-search"></em> '.get_lang('AdvancedSearch').'</a>';
  335. // Create a filter by session
  336. $sessionFilter = new FormValidator('course_filter', 'get', '', '', array(), FormValidator::LAYOUT_INLINE);
  337. $url = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=search_session';
  338. $sessionSelect = $sessionFilter->addElement(
  339. 'select_ajax',
  340. 'session_name',
  341. get_lang('SearchCourseBySession'),
  342. null,
  343. array('url' => $url)
  344. );
  345. if (!empty($sessionId)) {
  346. $sessionInfo = SessionManager::fetch($sessionId);
  347. $sessionSelect->addOption($sessionInfo['name'], $sessionInfo['id'], ['selected' => 'selected']);
  348. }
  349. $courseListUrl = api_get_self();
  350. $actions .= '<div class="row">';
  351. $actions .= '<div class="col-md-2">';
  352. $actions .= '<a href="course_add.php">'.Display::return_icon('new_course.png', get_lang('AddCourse'),'',ICON_SIZE_MEDIUM).'</a> ';
  353. if (api_get_setting('course_validation') == 'true') {
  354. $actions .= '<a href="course_request_review.php">'.Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests'),'',ICON_SIZE_MEDIUM).'</a>';
  355. }
  356. $actions .= '</div>';
  357. $actions .= '<div class="col-md-4">';
  358. $actions .= $form->returnForm();
  359. $actions .= '</div>';
  360. $actions .= '<div class="col-md-4">';
  361. $actions .= $sessionFilter->returnForm();
  362. $actions .= '</div>';
  363. $actions .= '<div class="col-md-2">';
  364. $actions .= '<div class="pull-right">';
  365. $actions .= $advanced;
  366. $actions .= '</div>';
  367. $actions .= '</div>';
  368. $actions .= '</div>';
  369. $actions .= '
  370. <script>
  371. $(function() {
  372. $("#session_name").on("change", function() {
  373. var sessionId = $(this).val();
  374. if (!sessionId) {
  375. return;
  376. }
  377. window.location = "'.$courseListUrl.'?session_id="+sessionId;
  378. });
  379. });
  380. </script>';
  381. if (isset($_GET['session_id']) && !empty($_GET['session_id'])) {
  382. // Create a sortable table with the course data filtered by session
  383. $table = new SortableTable('courses', 'get_number_of_courses', 'get_course_data_by_session', 2);
  384. } else {
  385. // Create a sortable table with the course data
  386. $table = new SortableTable('courses', 'get_number_of_courses', 'get_course_data', 2, 20, 'ASC', 'course-list');
  387. }
  388. $parameters=array();
  389. if (isset ($_GET['keyword'])) {
  390. $parameters = array ('keyword' => Security::remove_XSS($_GET['keyword']));
  391. } elseif (isset ($_GET['keyword_code'])) {
  392. $parameters['keyword_code'] = Security::remove_XSS($_GET['keyword_code']);
  393. $parameters['keyword_title'] = Security::remove_XSS($_GET['keyword_title']);
  394. $parameters['keyword_category'] = Security::remove_XSS($_GET['keyword_category']);
  395. $parameters['keyword_language'] = Security::remove_XSS($_GET['keyword_language']);
  396. $parameters['keyword_visibility'] = Security::remove_XSS($_GET['keyword_visibility']);
  397. $parameters['keyword_subscribe'] = Security::remove_XSS($_GET['keyword_subscribe']);
  398. $parameters['keyword_unsubscribe'] = Security::remove_XSS($_GET['keyword_unsubscribe']);
  399. }
  400. $table->set_additional_parameters($parameters);
  401. $table->set_header(0, '', false, 'width="8px"');
  402. $table->set_header(1, get_lang('Title'), true, null, array('class' => 'title'));
  403. $table->set_header(2, get_lang('Code'));
  404. $table->set_header(3, get_lang('Language'), false, 'width="70px"');
  405. $table->set_header(4, get_lang('Category'));
  406. $table->set_header(5, get_lang('SubscriptionAllowed'), true, 'width="60px"');
  407. $table->set_header(6, get_lang('UnsubscriptionAllowed'), false, 'width="50px"');
  408. //$table->set_header(7, get_lang('Teacher'));
  409. $table->set_header(7, get_lang('Action'), false, null, array('class'=>'td_actions'));
  410. $table->set_column_filter(7, 'modify_filter');
  411. $table->set_form_actions(array('delete_courses' => get_lang('DeleteCourse')), 'course');
  412. $content .= $table->return_table();
  413. }
  414. $tpl = new Template($tool_name);
  415. $tpl->assign('actions', $actions);
  416. $tpl->assign('message', $message);
  417. $tpl->assign('content', $content);
  418. $tpl->display_one_col_template();