course_list.php 15 KB

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