courses.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. // additional html (javascript and style css)
  22. $htmlHeadXtra[] = '<script type="text/javascript">' .
  23. 'var GB_ROOT_DIR = "'.api_get_path(WEB_LIBRARY_PATH).'javascript/greybox/"' .
  24. '</script>';
  25. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/greybox/AJS.js" type="text/javascript" language="javascript"></script>';
  26. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/greybox/AJS_fx.js" type="text/javascript" language="javascript"></script>';
  27. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/greybox/gb_scripts.js" type="text/javascript" language="javascript"></script>';
  28. $htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/greybox/gb_styles.css" rel="stylesheet" type="text/css" />';
  29. }
  30. // Section for the tabs.
  31. $this_section = SECTION_COURSES;
  32. // Acces rights: anonymous users can't do anything usefull here.
  33. api_block_anonymous_users();
  34. if (!(api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course())) {
  35. if (api_get_setting('allow_students_to_browse_courses') == 'false') {
  36. api_not_allowed();
  37. }
  38. }
  39. // filter actions
  40. $actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'unsubscribe', 'display_courses');
  41. $action = 'subscribe';
  42. $nameTools = get_lang('SortMyCourses');
  43. if (isset($_GET['action']) && in_array($_GET['action'],$actions)) {
  44. $action = $_GET['action'];
  45. }
  46. if ($action == 'createcoursecategory') {
  47. $nameTools = get_lang('CreateCourseCategory');
  48. }
  49. if ($action == 'subscribe') {
  50. $nameTools = get_lang('SubscribeToCourse');
  51. }
  52. // Breadcrumbs.
  53. $interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'user_portal.php', 'name' => get_lang('MyCourses'));
  54. if (empty($nameTools)) {
  55. $nameTools = get_lang('CourseManagement');
  56. } else {
  57. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'auth/courses.php', 'name' => get_lang('CourseManagement'));
  58. $interbreadcrumb[] = array('url' => '#', 'name' => $nameTools);
  59. }
  60. // course description controller object
  61. $courses_controller = new CoursesController();
  62. $ctok = $_SESSION['sec_token'];
  63. // We are moving a course or category of the user up/down the list (=Sort My Courses).
  64. if (isset($_GET['move'])) {
  65. if (isset($_GET['course'])) {
  66. if ($ctok == $_GET['sec_token']) {
  67. $courses_controller->move_course($_GET['move'], $_GET['course'], $_GET['category']);
  68. }
  69. }
  70. if (isset($_GET['category']) && !$_GET['course']) {
  71. if ($ctok == $_GET['sec_token']) {
  72. $courses_controller->move_category($_GET['move'], $_GET['category']);
  73. }
  74. }
  75. }
  76. // We are moving the course of the user to a different user defined course category (=Sort My Courses).
  77. if (isset($_POST['submit_change_course_category'])) {
  78. if ($ctok == $_POST['sec_token']) {
  79. $courses_controller->change_course_category($_POST['course_2_edit_category'], $_POST['course_categories']);
  80. }
  81. }
  82. // We edit course category
  83. if (isset($_POST['submit_edit_course_category']) && isset($_POST['title_course_category']) && strlen(trim($_POST['title_course_category'])) > 0) {
  84. if ($ctok == $_POST['sec_token']) {
  85. $courses_controller->edit_course_category($_POST['title_course_category'], $_POST['edit_course_category']);
  86. }
  87. }
  88. // we are deleting a course category
  89. if ($action == 'deletecoursecategory' && isset($_GET['id'])) {
  90. if ($ctok == $_GET['sec_token']) {
  91. $get_id_cat = intval($_GET['id']);
  92. $courses_controller->delete_course_category($get_id_cat);
  93. }
  94. }
  95. // We are unsubscribing from a course (=Unsubscribe from course).
  96. if (isset($_POST['unsubscribe'])) {
  97. if ($ctok == $_POST['sec_token']) {
  98. $courses_controller->unsubscribe_user_from_course($_POST['unsubscribe']);
  99. //$message = remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
  100. }
  101. }
  102. // We are creating a new user defined course category (= Create Course Category).
  103. if (isset($_POST['create_course_category']) && isset($_POST['title_course_category']) && strlen(trim($_POST['title_course_category'])) > 0) {
  104. if ($ctok == $_POST['sec_token']) {
  105. $courses_controller->add_course_category($_POST['title_course_category']);
  106. }
  107. }
  108. // search courses
  109. if (isset($_REQUEST['search_course'])) {
  110. //echo "<p><strong>".get_lang('SearchResultsFor')." ".api_htmlentities($_POST['search_term'], ENT_QUOTES, api_get_system_encoding())."</strong><br />";
  111. if ($ctok == $_REQUEST['sec_token']) {
  112. $courses_controller->search_courses($_REQUEST['search_term']);
  113. }
  114. }
  115. // subscribe user to course
  116. if (isset($_GET['subscribe_course'])) {
  117. //if ($ctok == $_GET['sec_token'] || $_POST['token'] == $_GET['sec_token']) {
  118. $courses_controller->subscribe_user($_GET['subscribe_course'], $_GET['search_term'], $_GET['category_code']);
  119. //}
  120. }
  121. switch ($action) {
  122. case 'createcoursecategory' :
  123. $courses_controller->categories_list($action);
  124. break;
  125. case 'deletecoursecategory' :
  126. case 'sortmycourses' :
  127. $courses_controller->courses_list($action);
  128. break;
  129. case 'subscribe' :
  130. $courses_controller->courses_categories($action);
  131. break;
  132. case 'display_courses' :
  133. $courses_controller->courses_categories($action, $_GET['category_code']);
  134. break;
  135. }