courses.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. // Names of the language file that needs to be included.
  9. $language_file = array ('courses', 'registration');
  10. // Delete the globals['_cid'], we don't need it here.
  11. $cidReset = true; // Flag forcing the 'current course' reset
  12. // including files
  13. require_once '../inc/global.inc.php';
  14. require_once api_get_path(LIBRARY_PATH).'auth.lib.php';
  15. require_once api_get_path(LIBRARY_PATH).'app_view.php';
  16. require_once 'courses_controller.php';
  17. //require_once api_get_path(LIBRARY_PATH).'debug.lib.inc.php';
  18. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  19. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  20. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  21. $htmlHeadXtra[] = api_get_jquery_ui_js();
  22. $htmlHeadXtra[] = '
  23. <script language="javascript">
  24. $(\'a.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. $("#dialog").dialog({modal :true, width:540, height:400});
  31. // load remote content
  32. dialog.load(
  33. url,
  34. {},
  35. function(responseText, textStatus, XMLHttpRequest) {
  36. dialog.dialog();
  37. }
  38. );
  39. //prevent the browser to follow the link
  40. return false;
  41. });
  42. </script>';
  43. }
  44. // Section for the tabs.
  45. $this_section = SECTION_COURSES;
  46. // Acces rights: anonymous users can't do anything usefull here.
  47. api_block_anonymous_users();
  48. if (!(api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course())) {
  49. if (api_get_setting('allow_students_to_browse_courses') == 'false') {
  50. api_not_allowed();
  51. }
  52. }
  53. // filter actions
  54. $actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'unsubscribe', 'display_courses','display_random_courses');
  55. $action = 'display_random_courses';
  56. $nameTools = get_lang('SortMyCourses');
  57. if (isset($_GET['action']) && in_array($_GET['action'],$actions)) {
  58. $action = $_GET['action'];
  59. }
  60. if ($action == 'createcoursecategory') {
  61. $nameTools = get_lang('CreateCourseCategory');
  62. }
  63. if ($action == 'subscribe') {
  64. $nameTools = get_lang('SubscribeToCourse');
  65. }
  66. // Breadcrumbs.
  67. $interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'user_portal.php', 'name' => get_lang('MyCourses'));
  68. if (empty($nameTools)) {
  69. $nameTools = get_lang('CourseManagement');
  70. } else {
  71. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'auth/courses.php', 'name' => get_lang('CourseManagement'));
  72. $interbreadcrumb[] = array('url' => '#', 'name' => $nameTools);
  73. }
  74. // course description controller object
  75. $courses_controller = new CoursesController();
  76. $ctok = $_SESSION['sec_token'];
  77. // We are moving a course or category of the user up/down the list (=Sort My Courses).
  78. if (isset($_GET['move'])) {
  79. if (isset($_GET['course'])) {
  80. if ($ctok == $_GET['sec_token']) {
  81. $courses_controller->move_course($_GET['move'], $_GET['course'], $_GET['category']);
  82. }
  83. }
  84. if (isset($_GET['category']) && !$_GET['course']) {
  85. if ($ctok == $_GET['sec_token']) {
  86. $courses_controller->move_category($_GET['move'], $_GET['category']);
  87. }
  88. }
  89. }
  90. // We are moving the course of the user to a different user defined course category (=Sort My Courses).
  91. if (isset($_POST['submit_change_course_category'])) {
  92. if ($ctok == $_POST['sec_token']) {
  93. $courses_controller->change_course_category($_POST['course_2_edit_category'], $_POST['course_categories']);
  94. }
  95. }
  96. // We edit course category
  97. if (isset($_POST['submit_edit_course_category']) && isset($_POST['title_course_category']) && strlen(trim($_POST['title_course_category'])) > 0) {
  98. if ($ctok == $_POST['sec_token']) {
  99. $courses_controller->edit_course_category($_POST['title_course_category'], $_POST['edit_course_category']);
  100. }
  101. }
  102. // we are deleting a course category
  103. if ($action == 'deletecoursecategory' && isset($_GET['id'])) {
  104. if ($ctok == $_GET['sec_token']) {
  105. $get_id_cat = intval($_GET['id']);
  106. $courses_controller->delete_course_category($get_id_cat);
  107. }
  108. }
  109. // We are unsubscribing from a course (=Unsubscribe from course).
  110. if (isset($_POST['unsubscribe'])) {
  111. if ($ctok == $_POST['sec_token']) {
  112. $courses_controller->unsubscribe_user_from_course($_POST['unsubscribe']);
  113. //$message = remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
  114. }
  115. }
  116. // We are creating a new user defined course category (= Create Course Category).
  117. if (isset($_POST['create_course_category']) && isset($_POST['title_course_category']) && strlen(trim($_POST['title_course_category'])) > 0) {
  118. if ($ctok == $_POST['sec_token']) {
  119. $courses_controller->add_course_category($_POST['title_course_category']);
  120. }
  121. }
  122. // search courses
  123. if (isset($_REQUEST['search_course'])) {
  124. //echo "<p><strong>".get_lang('SearchResultsFor')." ".api_htmlentities($_POST['search_term'], ENT_QUOTES, api_get_system_encoding())."</strong><br />";
  125. if ($ctok == $_REQUEST['sec_token']) {
  126. $courses_controller->search_courses($_REQUEST['search_term']);
  127. }
  128. }
  129. // subscribe user to course
  130. if (isset($_GET['subscribe_course'])) {
  131. //if ($ctok == $_GET['sec_token'] || $_POST['token'] == $_GET['sec_token']) {
  132. $courses_controller->subscribe_user($_GET['subscribe_course'], $_GET['search_term'], $_GET['category_code']);
  133. //}
  134. }
  135. switch ($action) {
  136. case 'createcoursecategory':
  137. $courses_controller->categories_list($action);
  138. break;
  139. case 'deletecoursecategory':
  140. case 'sortmycourses':
  141. $courses_controller->courses_list($action);
  142. break;
  143. case 'subscribe':
  144. case 'display_random_courses':
  145. $courses_controller->courses_categories($action);
  146. break;
  147. case 'display_courses':
  148. $courses_controller->courses_categories($action, $_GET['category_code']);
  149. break;
  150. }