courses.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Template (front controller in MVC pattern) used for distpaching to the controllers depend on the current action
  5. * @author Christian Fasanando <christian1827@gmail.com> - Beeznest
  6. * @package chamilo.auth
  7. */
  8. /**
  9. * Code
  10. */
  11. // Names of the language file that needs to be included.
  12. $language_file = array ('courses', 'registration');
  13. // Delete the globals['_cid'], we don't need it here.
  14. $cidReset = true; // Flag forcing the 'current course' reset
  15. // including files
  16. require_once '../inc/global.inc.php';
  17. require_once api_get_path(LIBRARY_PATH).'auth.lib.php';
  18. require_once api_get_path(LIBRARY_PATH).'app_view.php';
  19. require_once 'courses_controller.php';
  20. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  21. $htmlHeadXtra[] = '
  22. <script>
  23. $(document).ready(function() {
  24. $(\'.ajax\').live(\'click\', function() {
  25. var url = this.href;
  26. var dialog = $("#dialog");
  27. if ($("#dialog").length == 0) {
  28. dialog = $(\'<div id="dialog" style="display:hidden"></div>\').appendTo(\'body\');
  29. }
  30. // load remote content
  31. dialog.load(
  32. url,
  33. {},
  34. function(responseText, textStatus, XMLHttpRequest) {
  35. dialog.dialog({
  36. modal : true,
  37. width : 540,
  38. height : 400,
  39. });
  40. });
  41. //prevent the browser to follow the link
  42. return false;
  43. });
  44. });
  45. </script>';
  46. }
  47. // Section for the tabs.
  48. $this_section = SECTION_COURSES;
  49. // Access rights: anonymous users can't do anything useful here.
  50. api_block_anonymous_users();
  51. $user_can_view_page = false;
  52. //For students
  53. if (api_get_setting('allow_students_to_browse_courses') == 'false') {
  54. $user_can_view_page = false;
  55. } else {
  56. $user_can_view_page = true;
  57. }
  58. //For teachers/admins
  59. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  60. $user_can_view_page = true;
  61. }
  62. // filter actions
  63. $actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'display_courses', 'display_random_courses' , 'subscribe_user_with_password');
  64. $action = 'display_random_courses';
  65. $nameTools = get_lang('SortMyCourses');
  66. if (isset($_GET['action']) && in_array($_GET['action'],$actions)) {
  67. $action = $_GET['action'];
  68. }
  69. if ($action == 'createcoursecategory') {
  70. $nameTools = get_lang('CreateCourseCategory');
  71. }
  72. if ($action == 'subscribe') {
  73. $nameTools = get_lang('CourseManagement');
  74. }
  75. if ($action == 'subscribe_user_with_password') {
  76. $nameTools = get_lang('CourseManagement');
  77. }
  78. if ($action == 'display_random_courses' || $action == 'display_courses' ) {
  79. $nameTools = get_lang('CourseManagement');
  80. }
  81. // Breadcrumbs.
  82. $interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'user_portal.php', 'name' => get_lang('MyCourses'));
  83. if (empty($nameTools)) {
  84. $nameTools = get_lang('CourseManagement');
  85. } else {
  86. if (!in_array($action, array('sortmycourses', 'createcoursecategory', 'display_random_courses', 'display_courses', 'subscribe'))) {
  87. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'auth/courses.php', 'name' => get_lang('CourseManagement'));
  88. }
  89. if ($action == 'createcoursecategory') {
  90. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses', 'name' => get_lang('SortMyCourses'));
  91. }
  92. $interbreadcrumb[] = array('url' => '#', 'name' => $nameTools);
  93. }
  94. // course description controller object
  95. $courses_controller = new CoursesController();
  96. $ctok = Security::getCurrentToken();
  97. // We are moving a course or category of the user up/down the list (=Sort My Courses).
  98. if (isset($_GET['move'])) {
  99. if (isset($_GET['course'])) {
  100. if ($ctok == $_GET['sec_token']) {
  101. $courses_controller->move_course($_GET['move'], $_GET['course'], $_GET['category']);
  102. }
  103. }
  104. if (isset($_GET['category']) && !$_GET['course']) {
  105. if ($ctok == $_GET['sec_token']) {
  106. $courses_controller->move_category($_GET['move'], $_GET['category']);
  107. }
  108. }
  109. }
  110. // We are moving the course of the user to a different user defined course category (=Sort My Courses).
  111. if (isset($_POST['submit_change_course_category'])) {
  112. if ($ctok == $_POST['sec_token']) {
  113. $courses_controller->change_course_category($_POST['course_2_edit_category'], $_POST['course_categories']);
  114. }
  115. }
  116. // We edit course category
  117. if (isset($_POST['submit_edit_course_category']) && isset($_POST['title_course_category']) && strlen(trim($_POST['title_course_category'])) > 0) {
  118. if ($ctok == $_POST['sec_token']) {
  119. $courses_controller->edit_course_category($_POST['title_course_category'], $_POST['edit_course_category']);
  120. }
  121. }
  122. // we are deleting a course category
  123. if ($action == 'deletecoursecategory' && isset($_GET['id'])) {
  124. if ($ctok == $_GET['sec_token']) {
  125. $get_id_cat = intval($_GET['id']);
  126. $courses_controller->delete_course_category($get_id_cat);
  127. }
  128. }
  129. // We are creating a new user defined course category (= Create Course Category).
  130. if (isset($_POST['create_course_category']) && isset($_POST['title_course_category']) && strlen(trim($_POST['title_course_category'])) > 0) {
  131. if ($ctok == $_POST['sec_token']) {
  132. $courses_controller->add_course_category($_POST['title_course_category']);
  133. }
  134. }
  135. // search courses
  136. if (isset($_REQUEST['search_course'])) {
  137. //echo "<p><strong>".get_lang('SearchResultsFor')." ".api_htmlentities($_POST['search_term'], ENT_QUOTES, api_get_system_encoding())."</strong><br />";
  138. if ($ctok == $_REQUEST['sec_token']) {
  139. $courses_controller->search_courses($_REQUEST['search_term']);
  140. }
  141. }
  142. // Subscribe user to course
  143. if (isset($_REQUEST['subscribe_course'])) {
  144. if ($ctok == $_GET['sec_token']) {
  145. $courses_controller->subscribe_user($_GET['subscribe_course'], $_GET['search_term'], $_GET['category_code']);
  146. }
  147. }
  148. // We are unsubscribing from a course (=Unsubscribe from course).
  149. if (isset($_GET['unsubscribe'])) {
  150. if ($ctok == $_GET['sec_token']) {
  151. $courses_controller->unsubscribe_user_from_course($_GET['unsubscribe'], $_GET['search_term'], $_GET['category_code']);
  152. //$message = remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
  153. }
  154. }
  155. // We are unsubscribing from a course (=Unsubscribe from course).
  156. if (isset($_POST['unsubscribe'])) {
  157. if ($ctok == $_POST['sec_token']) {
  158. $courses_controller->unsubscribe_user_from_course($_POST['unsubscribe']);
  159. //$message = remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
  160. }
  161. }
  162. switch ($action) {
  163. case 'subscribe_user_with_password':
  164. $courses_controller->subscribe_user($_POST['subscribe_user_with_password'], $_POST['search_term'], $_POST['category_code']);
  165. exit;
  166. break;
  167. case 'createcoursecategory':
  168. $courses_controller->categories_list($action);
  169. break;
  170. case 'deletecoursecategory':
  171. $courses_controller->courses_list($action);
  172. break;
  173. case 'sortmycourses':
  174. $courses_controller->courses_list($action);
  175. break;
  176. case 'subscribe':
  177. case 'display_random_courses':
  178. if ($user_can_view_page) {
  179. $courses_controller->courses_categories($action);
  180. } else {
  181. api_not_allowed();
  182. }
  183. break;
  184. case 'display_courses':
  185. $courses_controller->courses_categories($action, $_GET['category_code']);
  186. break;
  187. }