index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Moodle frontpage.
  18. *
  19. * @package core
  20. * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. if (!file_exists('./config.php')) {
  24. header('Location: install.php');
  25. die;
  26. }
  27. require_once('config.php');
  28. require_once($CFG->dirroot .'/course/lib.php');
  29. require_once($CFG->libdir .'/filelib.php');
  30. redirect_if_major_upgrade_required();
  31. $urlparams = array();
  32. if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && optional_param('redirect', 1, PARAM_BOOL) === 0) {
  33. $urlparams['redirect'] = 0;
  34. }
  35. $PAGE->set_url('/', $urlparams);
  36. $PAGE->set_course($SITE);
  37. $PAGE->set_other_editing_capability('moodle/course:update');
  38. $PAGE->set_other_editing_capability('moodle/course:manageactivities');
  39. $PAGE->set_other_editing_capability('moodle/course:activityvisibility');
  40. // Prevent caching of this page to stop confusion when changing page after making AJAX changes.
  41. $PAGE->set_cacheable(false);
  42. if ($CFG->forcelogin) {
  43. require_login();
  44. } else {
  45. user_accesstime_log();
  46. }
  47. $hassiteconfig = has_capability('moodle/site:config', context_system::instance());
  48. // If the site is currently under maintenance, then print a message.
  49. if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
  50. print_maintenance_message();
  51. }
  52. if ($hassiteconfig && moodle_needs_upgrading()) {
  53. redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
  54. }
  55. if (get_home_page() != HOMEPAGE_SITE) {
  56. // Redirect logged-in users to My Moodle overview if required.
  57. $redirect = optional_param('redirect', 1, PARAM_BOOL);
  58. if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
  59. set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
  60. } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && $redirect === 1) {
  61. redirect($CFG->wwwroot .'/my/');
  62. } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {
  63. $frontpagenode = $PAGE->settingsnav->find('frontpage', null);
  64. if ($frontpagenode) {
  65. $frontpagenode->add(
  66. get_string('makethismyhome'),
  67. new moodle_url('/', array('setdefaulthome' => true)),
  68. navigation_node::TYPE_SETTING);
  69. } else {
  70. $frontpagenode = $PAGE->settingsnav->add(get_string('frontpagesettings'), null, navigation_node::TYPE_SETTING, null);
  71. $frontpagenode->force_open();
  72. $frontpagenode->add(get_string('makethismyhome'),
  73. new moodle_url('/', array('setdefaulthome' => true)),
  74. navigation_node::TYPE_SETTING);
  75. }
  76. }
  77. }
  78. // Trigger event.
  79. course_view(context_course::instance(SITEID));
  80. // If the hub plugin is installed then we let it take over the homepage here.
  81. if (file_exists($CFG->dirroot.'/local/hub/lib.php') and get_config('local_hub', 'hubenabled')) {
  82. require_once($CFG->dirroot.'/local/hub/lib.php');
  83. $hub = new local_hub();
  84. $continue = $hub->display_homepage();
  85. // Function display_homepage() returns true if the hub home page is not displayed
  86. // ...mostly when search form is not displayed for not logged users.
  87. if (empty($continue)) {
  88. exit;
  89. }
  90. }
  91. $PAGE->set_pagetype('site-index');
  92. $PAGE->set_docs_path('');
  93. $PAGE->set_pagelayout('frontpage');
  94. $editing = $PAGE->user_is_editing();
  95. $PAGE->set_title($SITE->fullname);
  96. $PAGE->set_heading($SITE->fullname);
  97. $courserenderer = $PAGE->get_renderer('core', 'course');
  98. echo $OUTPUT->header();
  99. // Print Section or custom info.
  100. $siteformatoptions = course_get_format($SITE)->get_format_options();
  101. $modinfo = get_fast_modinfo($SITE);
  102. $modnames = get_module_types_names();
  103. $modnamesplural = get_module_types_names(true);
  104. $modnamesused = $modinfo->get_used_module_names();
  105. $mods = $modinfo->get_cms();
  106. if (!empty($CFG->customfrontpageinclude)) {
  107. include($CFG->customfrontpageinclude);
  108. } else if ($siteformatoptions['numsections'] > 0) {
  109. if ($editing) {
  110. // Make sure section with number 1 exists.
  111. course_create_sections_if_missing($SITE, 1);
  112. // Re-request modinfo in case section was created.
  113. $modinfo = get_fast_modinfo($SITE);
  114. }
  115. $section = $modinfo->get_section_info(1);
  116. if (($section && (!empty($modinfo->sections[1]) or !empty($section->summary))) or $editing) {
  117. echo $OUTPUT->box_start('generalbox sitetopic');
  118. // If currently moving a file then show the current clipboard.
  119. if (ismoving($SITE->id)) {
  120. $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
  121. echo '<p><font size="2">';
  122. echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">";
  123. echo get_string('cancel') . '</a>)';
  124. echo '</font></p>';
  125. }
  126. $context = context_course::instance(SITEID);
  127. // If the section name is set we show it.
  128. if (!is_null($section->name)) {
  129. echo $OUTPUT->heading(
  130. format_string($section->name, true, array('context' => $context)),
  131. 2,
  132. 'sectionname'
  133. );
  134. }
  135. $summarytext = file_rewrite_pluginfile_urls($section->summary,
  136. 'pluginfile.php',
  137. $context->id,
  138. 'course',
  139. 'section',
  140. $section->id);
  141. $summaryformatoptions = new stdClass();
  142. $summaryformatoptions->noclean = true;
  143. $summaryformatoptions->overflowdiv = true;
  144. echo format_text($summarytext, $section->summaryformat, $summaryformatoptions);
  145. if ($editing && has_capability('moodle/course:update', $context)) {
  146. $streditsummary = get_string('editsummary');
  147. echo "<a title=\"$streditsummary\" ".
  148. " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" ".
  149. " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
  150. }
  151. $courserenderer = $PAGE->get_renderer('core', 'course');
  152. echo $courserenderer->course_section_cm_list($SITE, $section);
  153. echo $courserenderer->course_section_add_cm_control($SITE, $section->section);
  154. echo $OUTPUT->box_end();
  155. }
  156. }
  157. // Include course AJAX.
  158. include_course_ajax($SITE, $modnamesused);
  159. if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
  160. $frontpagelayout = $CFG->frontpageloggedin;
  161. } else {
  162. $frontpagelayout = $CFG->frontpage;
  163. }
  164. foreach (explode(',', $frontpagelayout) as $v) {
  165. switch ($v) {
  166. // Display the main part of the front page.
  167. case FRONTPAGENEWS:
  168. if ($SITE->newsitems) {
  169. // Print forums only when needed.
  170. require_once($CFG->dirroot .'/mod/forum/lib.php');
  171. if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
  172. print_error('cannotfindorcreateforum', 'forum');
  173. }
  174. // Fetch news forum context for proper filtering to happen.
  175. $newsforumcm = get_coursemodule_from_instance('forum', $newsforum->id, $SITE->id, false, MUST_EXIST);
  176. $newsforumcontext = context_module::instance($newsforumcm->id, MUST_EXIST);
  177. $forumname = format_string($newsforum->name, true, array('context' => $newsforumcontext));
  178. echo html_writer::link('#skipsitenews',
  179. get_string('skipa', 'access', core_text::strtolower(strip_tags($forumname))),
  180. array('class' => 'skip-block skip'));
  181. // Wraps site news forum in div container.
  182. echo html_writer::start_tag('div', array('id' => 'site-news-forum'));
  183. if (isloggedin()) {
  184. $SESSION->fromdiscussion = $CFG->wwwroot;
  185. $subtext = '';
  186. if (\mod_forum\subscriptions::is_subscribed($USER->id, $newsforum)) {
  187. if (!\mod_forum\subscriptions::is_forcesubscribed($newsforum)) {
  188. $subtext = get_string('unsubscribe', 'forum');
  189. }
  190. } else {
  191. $subtext = get_string('subscribe', 'forum');
  192. }
  193. echo $OUTPUT->heading($forumname);
  194. $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey()));
  195. echo html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink'));
  196. } else {
  197. echo $OUTPUT->heading($forumname);
  198. }
  199. forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
  200. // End site news forum div container.
  201. echo html_writer::end_tag('div');
  202. echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipsitenews'));
  203. }
  204. break;
  205. case FRONTPAGEENROLLEDCOURSELIST:
  206. $mycourseshtml = $courserenderer->frontpage_my_courses();
  207. if (!empty($mycourseshtml)) {
  208. echo html_writer::link('#skipmycourses',
  209. get_string('skipa', 'access', core_text::strtolower(get_string('mycourses'))),
  210. array('class' => 'skip skip-block'));
  211. // Wrap frontpage course list in div container.
  212. echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));
  213. echo $OUTPUT->heading(get_string('mycourses'));
  214. echo $mycourseshtml;
  215. // End frontpage course list div container.
  216. echo html_writer::end_tag('div');
  217. echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipmycourses'));
  218. break;
  219. }
  220. // No "break" here. If there are no enrolled courses - continue to 'Available courses'.
  221. case FRONTPAGEALLCOURSELIST:
  222. $availablecourseshtml = $courserenderer->frontpage_available_courses();
  223. if (!empty($availablecourseshtml)) {
  224. echo html_writer::link('#skipavailablecourses',
  225. get_string('skipa', 'access', core_text::strtolower(get_string('availablecourses'))),
  226. array('class' => 'skip skip-block'));
  227. // Wrap frontpage course list in div container.
  228. echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));
  229. echo $OUTPUT->heading(get_string('availablecourses'));
  230. echo $availablecourseshtml;
  231. // End frontpage course list div container.
  232. echo html_writer::end_tag('div');
  233. echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipavailablecourses'));
  234. }
  235. break;
  236. case FRONTPAGECATEGORYNAMES:
  237. echo html_writer::link('#skipcategories',
  238. get_string('skipa', 'access', core_text::strtolower(get_string('categories'))),
  239. array('class' => 'skip skip-block'));
  240. // Wrap frontpage category names in div container.
  241. echo html_writer::start_tag('div', array('id' => 'frontpage-category-names'));
  242. echo $OUTPUT->heading(get_string('categories'));
  243. echo $courserenderer->frontpage_categories_list();
  244. // End frontpage category names div container.
  245. echo html_writer::end_tag('div');
  246. echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcategories'));
  247. break;
  248. case FRONTPAGECATEGORYCOMBO:
  249. echo html_writer::link('#skipcourses',
  250. get_string('skipa', 'access', core_text::strtolower(get_string('courses'))),
  251. array('class' => 'skip skip-block'));
  252. // Wrap frontpage category combo in div container.
  253. echo html_writer::start_tag('div', array('id' => 'frontpage-category-combo'));
  254. echo $OUTPUT->heading(get_string('courses'));
  255. echo $courserenderer->frontpage_combo_list();
  256. // End frontpage category combo div container.
  257. echo html_writer::end_tag('div');
  258. echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcourses'));
  259. break;
  260. case FRONTPAGECOURSESEARCH:
  261. echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align');
  262. break;
  263. }
  264. echo '<br />';
  265. }
  266. if ($editing && has_capability('moodle/course:create', context_system::instance())) {
  267. echo $courserenderer->add_new_course_button();
  268. }
  269. echo $OUTPUT->footer();