courses.php 6.3 KB

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