courses.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  21. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  22. $htmlHeadXtra[] = '
  23. <script>
  24. $(document).ready(function() {
  25. $(\'.ajax\').live(\'click\', function() {
  26. var url = this.href;
  27. var dialog = $("#dialog");
  28. if ($("#dialog").length == 0) {
  29. dialog = $(\'<div id="dialog" style="display:hidden"></div>\').appendTo(\'body\');
  30. }
  31. // load remote content
  32. dialog.load(
  33. url,
  34. {},
  35. function(responseText, textStatus, XMLHttpRequest) {
  36. dialog.dialog({
  37. modal : true,
  38. width : 540,
  39. height : 400,
  40. });
  41. });
  42. //prevent the browser to follow the link
  43. return false;
  44. });
  45. });
  46. </script>';
  47. }
  48. // Section for the tabs.
  49. $this_section = SECTION_COURSES;
  50. // Access rights: anonymous users can't do anything useful here.
  51. api_block_anonymous_users();
  52. $user_can_view_page = false;
  53. //For students
  54. if (api_get_setting('allow_students_to_browse_courses') == 'false') {
  55. $user_can_view_page = false;
  56. } else {
  57. $user_can_view_page = true;
  58. }
  59. //For teachers/admins
  60. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  61. $user_can_view_page = true;
  62. }
  63. // filter actions
  64. $actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'display_courses','display_random_courses');
  65. $action = 'display_random_courses';
  66. $nameTools = get_lang('SortMyCourses');
  67. if (isset($_GET['action']) && in_array($_GET['action'],$actions)) {
  68. $action = $_GET['action'];
  69. }
  70. if ($action == 'createcoursecategory') {
  71. $nameTools = get_lang('CreateCourseCategory');
  72. }
  73. if ($action == 'subscribe') {
  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 = $_SESSION['sec_token'];
  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. $courses_controller->change_course_category($_POST['course_2_edit_category'], $_POST['course_categories']);
  112. }
  113. }
  114. // We edit course category
  115. if (isset($_POST['submit_edit_course_category']) && isset($_POST['title_course_category']) && strlen(trim($_POST['title_course_category'])) > 0) {
  116. if ($ctok == $_POST['sec_token']) {
  117. $courses_controller->edit_course_category($_POST['title_course_category'], $_POST['edit_course_category']);
  118. }
  119. }
  120. // we are deleting a course category
  121. if ($action == 'deletecoursecategory' && isset($_GET['id'])) {
  122. if ($ctok == $_GET['sec_token']) {
  123. $get_id_cat = intval($_GET['id']);
  124. $courses_controller->delete_course_category($get_id_cat);
  125. }
  126. }
  127. // We are creating a new user defined course category (= Create Course Category).
  128. if (isset($_POST['create_course_category']) && isset($_POST['title_course_category']) && strlen(trim($_POST['title_course_category'])) > 0) {
  129. if ($ctok == $_POST['sec_token']) {
  130. $courses_controller->add_course_category($_POST['title_course_category']);
  131. }
  132. }
  133. // search courses
  134. if (isset($_REQUEST['search_course'])) {
  135. //echo "<p><strong>".get_lang('SearchResultsFor')." ".api_htmlentities($_POST['search_term'], ENT_QUOTES, api_get_system_encoding())."</strong><br />";
  136. if ($ctok == $_REQUEST['sec_token']) {
  137. $courses_controller->search_courses($_REQUEST['search_term']);
  138. }
  139. }
  140. // subscribe user to course
  141. if (isset($_GET['subscribe_course'])) {
  142. if ($ctok == $_GET['sec_token']) {
  143. $courses_controller->subscribe_user($_GET['subscribe_course'], $_GET['search_term'], $_GET['category_code']);
  144. }
  145. }
  146. // We are unsubscribing from a course (=Unsubscribe from course).
  147. if (isset($_GET['unsubscribe'])) {
  148. if ($ctok == $_GET['sec_token']) {
  149. $courses_controller->unsubscribe_user_from_course($_GET['unsubscribe'], $_GET['search_term'], $_GET['category_code']);
  150. //$message = remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
  151. }
  152. }
  153. // We are unsubscribing from a course (=Unsubscribe from course).
  154. if (isset($_POST['unsubscribe'])) {
  155. if ($ctok == $_POST['sec_token']) {
  156. $courses_controller->unsubscribe_user_from_course($_POST['unsubscribe']);
  157. //$message = remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
  158. }
  159. }
  160. switch ($action) {
  161. case 'createcoursecategory':
  162. $courses_controller->categories_list($action);
  163. break;
  164. case 'deletecoursecategory':
  165. $courses_controller->courses_list($action);
  166. break;
  167. case 'sortmycourses':
  168. $courses_controller->courses_list($action);
  169. break;
  170. case 'subscribe':
  171. case 'display_random_courses':
  172. if ($user_can_view_page) {
  173. $courses_controller->courses_categories($action);
  174. } else {
  175. api_not_allowed();
  176. }
  177. break;
  178. case 'display_courses':
  179. $courses_controller->courses_categories($action, $_GET['category_code']);
  180. break;
  181. }