course_list.php 19 KB

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