course_home.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * See HomeController::indexAction
  5. * src/Chamilo/CourseBundle/Controller/Home/HomeController.php
  6. */
  7. exit;
  8. use ChamiloSession as Session;
  9. /**
  10. * HOME PAGE FOR EACH COURSE
  11. *
  12. * This page, included in every course's index.php is the home
  13. * page. To make administration simple, the teacher edits his
  14. * course from the home page. Only the login detects that the
  15. * visitor is allowed to activate, deactivate home page links,
  16. * access to the teachers tools (statistics, edit forums...).
  17. *
  18. * Edit visibility of tools
  19. *
  20. * visibility = 1 - everybody
  21. * visibility = 0 - course admin (teacher) and platform admin
  22. *
  23. * Who can change visibility ?
  24. *
  25. * admin = 0 - course admin (teacher) and platform admin
  26. * admin = 1 - platform admin
  27. *
  28. * Show message to confirm that a tools must be hide from available tools
  29. *
  30. * visibility 0,1
  31. *
  32. * @package chamilo.course_home
  33. */
  34. $use_anonymous = true;
  35. require_once __DIR__.'/../inc/global.inc.php';
  36. $htmlHeadXtra[] = '<script>
  37. /* option show/hide thematic-block */
  38. $(document).ready(function(){
  39. $("#thematic-show").click(function(){
  40. $(".btn-hide-thematic").hide();
  41. $(".btn-show-thematic").show(); //show using class
  42. $("#pross").fadeToggle(); //Not working collapse for Chrome
  43. });
  44. $("#thematic-hide").click(function(){
  45. $(".btn-show-thematic").hide(); //show using class
  46. $(".btn-hide-thematic").show();
  47. $("#pross").fadeToggle(); //Not working collapse for Chrome
  48. });
  49. });
  50. $(document).ready(function() {
  51. $(".make_visible_and_invisible").attr("href", "javascript:void(0);");
  52. $(".make_visible_and_invisible > img").click(function () {
  53. make_visible = "visible.gif";
  54. make_invisible = "invisible.gif";
  55. path_name = $(this).attr("src");
  56. list_path_name = path_name.split("/");
  57. image_link = list_path_name[list_path_name.length - 1];
  58. tool_id = $(this).attr("id");
  59. tool_info = tool_id.split("_");
  60. my_tool_id = tool_info[1];
  61. $("#id_normal_message").attr("class", "normal-message alert alert-success");
  62. $.ajax({
  63. contentType: "application/x-www-form-urlencoded",
  64. beforeSend: function(objeto) {
  65. $(".normal-message").show();
  66. $("#id_confirmation_message").hide();
  67. },
  68. type: "GET",
  69. url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?'.api_get_cidreq().'&a=set_visibility",
  70. data: "id=" + my_tool_id + "&sent_http_request=1",
  71. success: function(data) {
  72. eval("var info=" + data);
  73. new_current_tool_image = info.image;
  74. new_current_view = "'.api_get_path(WEB_IMG_PATH).'" + info.view;
  75. //eyes
  76. $("#" + tool_id).attr("src", new_current_view);
  77. //tool
  78. $("#toolimage_" + my_tool_id).attr("src", new_current_tool_image);
  79. //clase
  80. $("#tooldesc_" + my_tool_id).attr("class", info.tclass);
  81. $("#istooldesc_" + my_tool_id).attr("class", info.tclass);
  82. if (image_link == "visible.gif") {
  83. $("#" + tool_id).attr("alt", "'.get_lang('Activate', '').'");
  84. $("#" + tool_id).attr("title", "'.get_lang('Activate', '').'");
  85. } else {
  86. $("#" + tool_id).attr("alt", "'.get_lang('Deactivate', '').'");
  87. $("#" + tool_id).attr("title", "'.get_lang('Deactivate', '').'");
  88. }
  89. if (info.message == "is_active") {
  90. message = "'.get_lang('ToolIsNowVisible', '').'";
  91. } else {
  92. message = "'.get_lang('ToolIsNowHidden', '').'";
  93. }
  94. $(".normal-message").hide();
  95. $("#id_confirmation_message").html(message);
  96. $("#id_confirmation_message").show();
  97. }
  98. });
  99. });
  100. });
  101. </script>';
  102. // The section for the tabs
  103. $this_section = SECTION_COURSES;
  104. $user_id = api_get_user_id();
  105. $course_code = api_get_course_id();
  106. $courseId = api_get_course_int_id();
  107. $sessionId = api_get_session_id();
  108. $show_message = '';
  109. if (api_is_invitee()) {
  110. $isInASession = $sessionId > 0;
  111. $isSubscribed = CourseManager::is_user_subscribed_in_course(
  112. $user_id,
  113. $course_code,
  114. $isInASession,
  115. $sessionId
  116. );
  117. if (!$isSubscribed) {
  118. api_not_allowed(true);
  119. }
  120. }
  121. // Deleting group session
  122. Session::erase('toolgroup');
  123. Session::erase('_gid');
  124. $isSpecialCourse = CourseManager::isSpecialCourse($courseId);
  125. if ($isSpecialCourse) {
  126. if (isset($_GET['autoreg']) && $_GET['autoreg'] == 1) {
  127. if (CourseManager::subscribe_user($user_id, $course_code, STUDENT)) {
  128. Session::write('is_allowed_in_course', true);
  129. }
  130. }
  131. }
  132. if (isset($_GET['action']) && $_GET['action'] == 'subscribe') {
  133. if (Security::check_token('get')) {
  134. Security::clear_token();
  135. $auth = new Auth();
  136. $msg = $auth->subscribe_user($course_code);
  137. if (CourseManager::is_user_subscribed_in_course($user_id, $course_code)) {
  138. Session::write('is_allowed_in_course', true);
  139. }
  140. if (!empty($msg)) {
  141. $show_message .= Display::return_message(
  142. get_lang($msg['message']),
  143. 'info',
  144. false
  145. );
  146. }
  147. }
  148. }
  149. /* Is the user allowed here? */
  150. api_protect_course_script(true);
  151. /* STATISTICS */
  152. if (!isset($coursesAlreadyVisited[$course_code])) {
  153. Event::accessCourse();
  154. $coursesAlreadyVisited[$course_code] = 1;
  155. Session::write('coursesAlreadyVisited', $coursesAlreadyVisited);
  156. }
  157. /*Auto launch code */
  158. $show_autolaunch_lp_warning = false;
  159. $auto_launch = api_get_course_setting('enable_lp_auto_launch');
  160. $session_id = api_get_session_id();
  161. if (!empty($auto_launch)) {
  162. if ($auto_launch == 2) { //LP list
  163. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  164. $show_autolaunch_lp_warning = true;
  165. } else {
  166. $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  167. if (!isset($_SESSION[$session_key])) {
  168. // Redirecting to the LP
  169. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&id_session='.$session_id;
  170. $_SESSION[$session_key] = true;
  171. header("Location: $url");
  172. exit;
  173. }
  174. }
  175. } else {
  176. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  177. $course_id = api_get_course_int_id();
  178. $condition = '';
  179. if (!empty($session_id)) {
  180. $condition = api_get_session_condition($session_id);
  181. $sql = "SELECT id FROM $lp_table
  182. WHERE c_id = $course_id AND autolaunch = 1 $condition
  183. LIMIT 1";
  184. $result = Database::query($sql);
  185. // If we found nothing in the session we just called the session_id = 0 autolaunch
  186. if (Database::num_rows($result) == 0) {
  187. $condition = '';
  188. }
  189. }
  190. $sql = "SELECT id FROM $lp_table
  191. WHERE c_id = $course_id AND autolaunch = 1 $condition
  192. LIMIT 1";
  193. $result = Database::query($sql);
  194. if (Database::num_rows($result) > 0) {
  195. $lp_data = Database::fetch_array($result, 'ASSOC');
  196. if (!empty($lp_data['id'])) {
  197. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  198. $show_autolaunch_lp_warning = true;
  199. } else {
  200. $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  201. if (!isset($_SESSION[$session_key])) {
  202. //redirecting to the LP
  203. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id'];
  204. $_SESSION[$session_key] = true;
  205. header("Location: $url");
  206. exit;
  207. }
  208. }
  209. }
  210. }
  211. }
  212. }
  213. $forumAutoLaunch = api_get_course_setting('enable_forum_auto_launch');
  214. if ($forumAutoLaunch == 1) {
  215. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  216. Display::addFlash(Display::return_message(
  217. get_lang('TheForumAutoLaunchSettingIsOnStudentsWillBeRedirectToTheForumTool'),
  218. 'warning'
  219. ));
  220. } else {
  221. //$forumKey = 'forum_auto_launch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  222. //if (!isset($_SESSION[$forumKey])) {
  223. //redirecting to the LP
  224. $url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&id_session='.$session_id;
  225. // $_SESSION[$forumKey] = true;
  226. header("Location: $url");
  227. exit;
  228. //}
  229. }
  230. }
  231. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  232. $temps = time();
  233. $reqdate = "&reqdate=$temps";
  234. /* MAIN CODE */
  235. /* Introduction section (editable by course admins) */
  236. $content = Display::return_introduction_section(
  237. TOOL_COURSE_HOMEPAGE,
  238. array(
  239. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  240. 'CreateDocumentDir' => 'document/',
  241. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/',
  242. )
  243. );
  244. /* SWITCH TO A DIFFERENT HOMEPAGE VIEW
  245. the setting homepage_view is adjustable through
  246. the platform administration section */
  247. if ($show_autolaunch_lp_warning) {
  248. $show_message .= Display::return_message(
  249. get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'),
  250. 'warning'
  251. );
  252. }
  253. if (api_get_setting('homepage_view') === 'activity' || api_get_setting('homepage_view') === 'activity_big') {
  254. require 'activity.php';
  255. } elseif (api_get_setting('homepage_view') === '2column') {
  256. require '2column.php';
  257. } elseif (api_get_setting('homepage_view') === '3column') {
  258. require '3column.php';
  259. } elseif (api_get_setting('homepage_view') === 'vertical_activity') {
  260. require 'vertical_activity.php';
  261. }
  262. // Get session-career diagram
  263. $diagram = '';
  264. $allow = api_get_configuration_value('allow_career_diagram');
  265. if ($allow === true) {
  266. $htmlHeadXtra[] = api_get_js('jsplumb2.js');
  267. $extra = new ExtraFieldValue('session');
  268. $value = $extra->get_values_by_handler_and_field_variable(
  269. api_get_session_id(),
  270. 'external_career_id'
  271. );
  272. if (!empty($value) && isset($value['value'])) {
  273. $careerId = $value['value'];
  274. $extraFieldValue = new ExtraFieldValue('career');
  275. $item = $extraFieldValue->get_item_id_from_field_variable_and_field_value(
  276. 'external_career_id',
  277. $careerId,
  278. false,
  279. false,
  280. false
  281. );
  282. if (!empty($item) && isset($item['item_id'])) {
  283. $careerId = $item['item_id'];
  284. $career = new Career();
  285. $careerInfo = $career->get($careerId);
  286. if (!empty($careerInfo)) {
  287. $extraFieldValue = new ExtraFieldValue('career');
  288. $item = $extraFieldValue->get_values_by_handler_and_field_variable(
  289. $careerId,
  290. 'career_diagram',
  291. false,
  292. false,
  293. false
  294. );
  295. if (!empty($item) && isset($item['value']) && !empty($item['value'])) {
  296. $graph = unserialize($item['value']);
  297. $diagram = Career::renderDiagram($careerInfo, $graph);
  298. }
  299. }
  300. }
  301. }
  302. }
  303. $content = '<div id="course_tools">'.$diagram.$content.'</div>';
  304. $tpl = new Template(null);
  305. $tpl->assign('message', $show_message);
  306. $tpl->assign('content', $content);
  307. // Direct login to course
  308. $tpl->assign('course_code', $course_code);
  309. $tpl->display_one_col_template();
  310. // Deleting the objects
  311. Session::erase('_gid');
  312. Session::erase('oLP');
  313. Session::erase('lpobject');
  314. api_remove_in_gradebook();
  315. DocumentManager::removeGeneratedAudioTempFile();