courses.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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[] = api_get_jquery_ui_js();
  23. $htmlHeadXtra[] = '
  24. <script language="javascript">
  25. $(document).ready(function() {
  26. $(\'.ajax\').live(\'click\', function() {
  27. var url = this.href;
  28. var dialog = $("#dialog");
  29. if ($("#dialog").length == 0) {
  30. dialog = $(\'<div id="dialog" style="display:hidden"></div>\').appendTo(\'body\');
  31. }
  32. // load remote content
  33. dialog.load(
  34. url,
  35. {},
  36. function(responseText, textStatus, XMLHttpRequest) {
  37. dialog.dialog({
  38. modal : true,
  39. width : 540,
  40. height : 400,
  41. });
  42. });
  43. //prevent the browser to follow the link
  44. return false;
  45. });
  46. });
  47. </script>';
  48. }
  49. // Section for the tabs.
  50. $this_section = SECTION_COURSES;
  51. // Access rights: anonymous users can't do anything useful here.
  52. api_block_anonymous_users();
  53. $user_can_view_page = false;
  54. //For students
  55. if (api_get_setting('allow_students_to_browse_courses') == 'false') {
  56. $user_can_view_page = false;
  57. } else {
  58. $user_can_view_page = true;
  59. }
  60. //For teachers/admins
  61. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  62. $user_can_view_page = true;
  63. }
  64. // filter actions
  65. $actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'unsubscribe', 'display_courses','display_random_courses');
  66. $action = 'display_random_courses';
  67. $nameTools = get_lang('SortMyCourses');
  68. if (isset($_GET['action']) && in_array($_GET['action'],$actions)) {
  69. $action = $_GET['action'];
  70. }
  71. if ($action == 'createcoursecategory') {
  72. $nameTools = get_lang('CreateCourseCategory');
  73. }
  74. if ($action == 'subscribe') {
  75. $nameTools = get_lang('CourseManagement');
  76. }
  77. if ($action == 'display_random_courses' || $action == 'display_courses' ) {
  78. $nameTools = get_lang('CourseManagement');
  79. }
  80. // Breadcrumbs.
  81. $interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'user_portal.php', 'name' => get_lang('MyCourses'));
  82. if (empty($nameTools)) {
  83. $nameTools = get_lang('CourseManagement');
  84. } else {
  85. if (!in_array($action, array('sortmycourses', 'createcoursecategory', 'display_random_courses', 'display_courses', 'subscribe'))) {
  86. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'auth/courses.php', 'name' => get_lang('CourseManagement'));
  87. }
  88. if ($action == 'createcoursecategory') {
  89. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses', 'name' => get_lang('SortMyCourses'));
  90. }
  91. $interbreadcrumb[] = array('url' => '#', 'name' => $nameTools);
  92. }
  93. // course description controller object
  94. $courses_controller = new CoursesController();
  95. $ctok = $_SESSION['sec_token'];
  96. // We are moving a course or category of the user up/down the list (=Sort My Courses).
  97. if (isset($_GET['move'])) {
  98. if (isset($_GET['course'])) {
  99. if ($ctok == $_GET['sec_token']) {
  100. $courses_controller->move_course($_GET['move'], $_GET['course'], $_GET['category']);
  101. }
  102. }
  103. if (isset($_GET['category']) && !$_GET['course']) {
  104. if ($ctok == $_GET['sec_token']) {
  105. $courses_controller->move_category($_GET['move'], $_GET['category']);
  106. }
  107. }
  108. }
  109. // We are moving the course of the user to a different user defined course category (=Sort My Courses).
  110. if (isset($_POST['submit_change_course_category'])) {
  111. if ($ctok == $_POST['sec_token']) {
  112. $courses_controller->change_course_category($_POST['course_2_edit_category'], $_POST['course_categories']);
  113. }
  114. }
  115. // We edit course category
  116. if (isset($_POST['submit_edit_course_category']) && isset($_POST['title_course_category']) && strlen(trim($_POST['title_course_category'])) > 0) {
  117. if ($ctok == $_POST['sec_token']) {
  118. $courses_controller->edit_course_category($_POST['title_course_category'], $_POST['edit_course_category']);
  119. }
  120. }
  121. // we are deleting a course category
  122. if ($action == 'deletecoursecategory' && isset($_GET['id'])) {
  123. if ($ctok == $_GET['sec_token']) {
  124. $get_id_cat = intval($_GET['id']);
  125. $courses_controller->delete_course_category($get_id_cat);
  126. }
  127. }
  128. // We are unsubscribing from a course (=Unsubscribe from course).
  129. if (isset($_POST['unsubscribe'])) {
  130. if ($ctok == $_POST['sec_token']) {
  131. $courses_controller->unsubscribe_user_from_course($_POST['unsubscribe']);
  132. //$message = remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
  133. }
  134. }
  135. // We are creating a new user defined course category (= Create Course Category).
  136. if (isset($_POST['create_course_category']) && isset($_POST['title_course_category']) && strlen(trim($_POST['title_course_category'])) > 0) {
  137. if ($ctok == $_POST['sec_token']) {
  138. $courses_controller->add_course_category($_POST['title_course_category']);
  139. }
  140. }
  141. // search courses
  142. if (isset($_REQUEST['search_course'])) {
  143. //echo "<p><strong>".get_lang('SearchResultsFor')." ".api_htmlentities($_POST['search_term'], ENT_QUOTES, api_get_system_encoding())."</strong><br />";
  144. if ($ctok == $_REQUEST['sec_token']) {
  145. $courses_controller->search_courses($_REQUEST['search_term']);
  146. }
  147. }
  148. // subscribe user to course
  149. if (isset($_GET['subscribe_course'])) {
  150. //if ($ctok == $_GET['sec_token'] || $_POST['token'] == $_GET['sec_token']) {
  151. $courses_controller->subscribe_user($_GET['subscribe_course'], $_GET['search_term'], $_GET['category_code']);
  152. //}
  153. }
  154. switch ($action) {
  155. case 'createcoursecategory':
  156. $courses_controller->categories_list($action);
  157. break;
  158. case 'deletecoursecategory':
  159. $courses_controller->courses_list($action);
  160. break;
  161. case 'sortmycourses':
  162. $courses_controller->courses_list($action);
  163. break;
  164. case 'subscribe':
  165. case 'display_random_courses':
  166. if ($user_can_view_page) {
  167. $courses_controller->courses_categories($action);
  168. } else {
  169. api_not_allowed();
  170. }
  171. break;
  172. case 'display_courses':
  173. $courses_controller->courses_categories($action, $_GET['category_code']);
  174. break;
  175. }