courses.php 7.6 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 'courses_controller.php';
  18. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  19. $htmlHeadXtra[] = '
  20. <script>
  21. $(document).ready(function() {
  22. $(\'.ajax\').live(\'click\', function() {
  23. var url = this.href;
  24. var dialog = $("#dialog");
  25. if ($("#dialog").length == 0) {
  26. dialog = $(\'<div id="dialog" style="display:hidden"></div>\').appendTo(\'body\');
  27. }
  28. // load remote content
  29. dialog.load(
  30. url,
  31. {},
  32. function(responseText, textStatus, XMLHttpRequest) {
  33. dialog.dialog({
  34. modal : true,
  35. width : 540,
  36. height : 400,
  37. });
  38. });
  39. //prevent the browser to follow the link
  40. return false;
  41. });
  42. });
  43. </script>';
  44. }
  45. // Section for the tabs.
  46. $this_section = SECTION_COURSES;
  47. // Access rights: anonymous users can't do anything useful here.
  48. api_block_anonymous_users();
  49. $user_can_view_page = false;
  50. //For students
  51. if (api_get_setting('allow_students_to_browse_courses') == 'false') {
  52. $user_can_view_page = false;
  53. } else {
  54. $user_can_view_page = true;
  55. }
  56. //For teachers/admins
  57. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  58. $user_can_view_page = true;
  59. }
  60. // filter actions
  61. $actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'display_courses', 'display_random_courses' , 'subscribe_user_with_password');
  62. $action = 'display_random_courses';
  63. $nameTools = get_lang('SortMyCourses');
  64. if (isset($_GET['action']) && in_array($_GET['action'],$actions)) {
  65. $action = $_GET['action'];
  66. }
  67. if ($action == 'createcoursecategory') {
  68. $nameTools = get_lang('CreateCourseCategory');
  69. }
  70. if ($action == 'subscribe') {
  71. $nameTools = get_lang('CourseManagement');
  72. }
  73. if ($action == 'subscribe_user_with_password') {
  74. $nameTools = get_lang('CourseManagement');
  75. }
  76. if ($action == 'display_random_courses' || $action == 'display_courses' ) {
  77. $nameTools = get_lang('CourseManagement');
  78. }
  79. // Breadcrumbs.
  80. $interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'user_portal.php', 'name' => get_lang('MyCourses'));
  81. if (empty($nameTools)) {
  82. $nameTools = get_lang('CourseManagement');
  83. } else {
  84. if (!in_array($action, array('sortmycourses', 'createcoursecategory', 'display_random_courses', 'display_courses', 'subscribe'))) {
  85. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'auth/courses.php', 'name' => get_lang('CourseManagement'));
  86. }
  87. if ($action == 'createcoursecategory') {
  88. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses', 'name' => get_lang('SortMyCourses'));
  89. }
  90. $interbreadcrumb[] = array('url' => '#', 'name' => $nameTools);
  91. }
  92. // course description controller object
  93. $courses_controller = new CoursesController();
  94. $ctok = Security::getCurrentToken();
  95. // We are moving a course or category of the user up/down the list (=Sort My Courses).
  96. if (isset($_GET['move'])) {
  97. if (isset($_GET['course'])) {
  98. if ($ctok == $_GET['sec_token']) {
  99. $courses_controller->move_course($_GET['move'], $_GET['course'], $_GET['category']);
  100. }
  101. }
  102. if (isset($_GET['category']) && !$_GET['course']) {
  103. if ($ctok == $_GET['sec_token']) {
  104. $courses_controller->move_category($_GET['move'], $_GET['category']);
  105. }
  106. }
  107. }
  108. // We are moving the course of the user to a different user defined course category (=Sort My Courses).
  109. if (isset($_POST['submit_change_course_category'])) {
  110. if ($ctok == $_POST['sec_token']) {
  111. $courseCode = $_POST['course_2_edit_category'];
  112. $courseInfo = api_get_course_info($courseCode);
  113. $courses_controller->change_course_category($courseInfo['real_id'], $_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. }