Better handling of single forums when secureforms is on. bug 1189
[moodle.git] / index.php
blobd8ee0339058e4d0b0765c1fb07bab683206b2c06
1 <?PHP // $Id$
2 // index.php - the front page.
4 require_once("config.php");
5 require_once("course/lib.php");
6 require_once("mod/resource/lib.php");
7 require_once("mod/forum/lib.php");
9 if (! $site = get_site()) {
10 redirect("$CFG->wwwroot/$CFG->admin/index.php");
13 if ($CFG->forcelogin) {
14 require_login();
17 if (isadmin()) {
18 if (moodle_needs_upgrading()) {
19 redirect("$CFG->wwwroot/$CFG->admin/index.php");
23 if (empty($USER->id)) {
24 $loginstring = "<font size=2><a href=\"$CFG->wwwroot/login/index.php\">".get_string("login")."</a></font>";
25 } else {
26 $loginstring = "<font size=1>".user_login_string($site)."</font>";
29 if (empty($CFG->langmenu)) {
30 $langmenu = "";
31 } else {
32 $currlang = current_language();
33 $langs = get_list_of_languages();
34 $langmenu = popup_form ("$CFG->wwwroot/?lang=", $langs, "chooselang", $currlang, "", "", "", true);
37 print_header(strip_tags($site->fullname), "$site->fullname", "home", "",
38 "<meta name=\"description\" content=\"".s(strip_tags($site->summary))."\">",
39 true, "", "$loginstring$langmenu");
41 $firstcolumn = false; // for now
42 $lastcolumn = false; // for now
43 $side = 175;
45 $site_summary_editbuttons = '';
46 if (isediting($site->id)) {
47 $site_summary_editbuttons = "<br><center><a href=\"$CFG->admin/site.php\"><img src=\"pix/i/edit.gif\" border=0></a>";
50 if ($site->summary) {
51 $lastcolumn = true;
58 <table width="100%" border="0" cellspacing="5" cellpadding="5">
59 <tr>
60 <?PHP
61 $sections = get_all_sections($site->id);
63 if ($site->newsitems > 0 or $sections[0]->sequence or isediting($site->id) or isadmin()) {
65 echo "<td width=\"$side\" valign=top nowrap>";
66 $firstcolumn=true;
68 if ($sections[0]->sequence or isediting($site->id)) {
69 get_all_mods($site->id, $mods, $modnames, $modnamesplural, $modnamesused);
70 print_section_block(get_string("mainmenu"), $site, $sections[0],
71 $mods, $modnames, $modnamesused, true, $side);
74 if (isadmin()) {
75 echo "<div align=\"center\">".update_course_icon($site->id)."</div>";
76 echo "<br />";
79 switch ($CFG->frontpage) {
80 case FRONTPAGENEWS: // print news links on the side
81 print_courses_sideblock(0, "$side");
82 break;
84 case FRONTPAGECOURSELIST:
85 case FRONTPAGECATEGORYNAMES:
86 if ($site->newsitems) {
87 if ($news = forum_get_course_forum($site->id, "news")) {
88 print_side_block_start(get_string("latestnews"), $side, "sideblocklatestnews");
89 echo "<font size=\"-2\">";
90 forum_print_latest_discussions($news->id, $site->newsitems, "minimal", "", false);
91 echo "</font>";
92 print_side_block_end();
95 break;
97 print_spacer(1,$side);
100 if (iscreator()) {
101 if (!$firstcolumn) {
102 echo "<td width=\"$side\" valign=top nowrap>";
103 $firstcolumn=true;
105 print_admin_links($site->id, $side);
108 if ($firstcolumn) {
109 echo "</td>";
111 if ($lastcolumn) {
112 echo "<td width=\"70%\" valign=\"top\">";
113 } else {
114 echo "<td width=\"100%\" valign=\"top\">";
117 switch ($CFG->frontpage) { /// Display the main part of the front page.
118 case FRONTPAGENEWS:
119 if (! $newsforum = forum_get_course_forum($site->id, "news")) {
120 error("Could not find or create a main news forum for the site");
123 if (isset($USER->id)) {
124 $SESSION->fromdiscussion = "$CFG->wwwroot";
125 if (forum_is_subscribed($USER->id, $newsforum->id)) {
126 $subtext = get_string("unsubscribe", "forum");
127 } else {
128 $subtext = get_string("subscribe", "forum");
130 $headertext = "<table border=0 width=100% cellpadding=0 cellspacing=0 class=headingblockcontent><tr>
131 <td>$newsforum->name</td>
132 <td align=right><font size=1>
133 <a href=\"mod/forum/subscribe.php?id=$newsforum->id\">$subtext</a>
134 </td></tr></table>";
135 } else {
136 $headertext = $newsforum->name;
138 print_heading_block($headertext);
139 print_spacer(8,1);
140 forum_print_latest_discussions($newsforum->id, $site->newsitems);
141 break;
143 case FRONTPAGECOURSELIST:
144 case FRONTPAGECATEGORYNAMES:
145 if (isset($USER->id) and !isset($USER->admin)) {
146 print_heading_block(get_string("mycourses"));
147 print_spacer(8,1);
148 print_my_moodle();
149 } else {
150 if (count_records("course_categories") > 1) {
151 if ($CFG->frontpage == FRONTPAGECOURSELIST) {
152 print_heading_block(get_string("availablecourses"));
153 } else {
154 print_heading_block(get_string("categories"));
156 print_spacer(8,1);
157 print_simple_box_start("center", "100%");
158 print_whole_category_list();
159 print_simple_box_end();
160 print_course_search("", false, "short");
161 } else {
162 print_heading_block(get_string("availablecourses"));
163 print_spacer(8,1);
164 print_courses(0, "100%");
167 break;
171 echo "</td>";
173 if ($lastcolumn) {
174 echo "<td width=\"30%\" valign=\"top\">";
175 print_simple_box(format_text($site->summary, FORMAT_HTML).$site_summary_editbuttons,
176 "", "100%", $THEME->cellcontent2, 5, "siteinfo");
177 print_spacer(1,$side);
178 echo "</td>";
182 </tr>
183 </table>
185 <?PHP print_footer("home"); // Please do not modify this line ?>