index.php 6.36 KB
Newer Older
moodler's avatar
moodler committed
1
2
<?PHP  // $Id$
       // index.php - the front page.
martin's avatar
martin committed
3
    
4
5
6
7
    require_once("config.php");
    require_once("course/lib.php");
    require_once("mod/resource/lib.php"); 
    require_once("mod/forum/lib.php");
martin's avatar
martin committed
8

9
    if (! $site = get_site()) {
moodler's avatar
moodler committed
10
        redirect("$CFG->wwwroot/$CFG->admin/index.php");
martin's avatar
martin committed
11
12
    }

13
14
15
16
    if ($CFG->forcelogin) {
        require_login();
    }

17
18
    if (isadmin()) {
        if (moodle_needs_upgrading()) {
moodler's avatar
moodler committed
19
            redirect("$CFG->wwwroot/$CFG->admin/index.php");
20
        }
21
22
23
24
    }

    if (empty($USER->id)) {
        $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>";
martin's avatar
martin committed
27
    }
28

29
30
31
32
33
    if (empty($CFG->langmenu)) {
        $langmenu = "";
    } else {
        $currlang = current_language();
        $langs = get_list_of_languages();
34
        $langmenu = popup_form ("$CFG->wwwroot/index.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
35
    }
36

moodler's avatar
moodler committed
37
    print_header(strip_tags($site->fullname), "$site->fullname", "home", "",
38
                 "<meta name=\"description\" content=\"".s(strip_tags($site->summary))."\">",
39
                 true, "", "$loginstring$langmenu");
martin's avatar
martin committed
40

41
    $firstcolumn = false;  // for now
moodler's avatar
moodler committed
42
    $lastcolumn = false;   // for now
moodler's avatar
moodler committed
43
    $side = 175;
44

moodler's avatar
moodler committed
45
    $site_summary_editbuttons = '';
moodler's avatar
moodler committed
46
    if (isediting($site->id)) {
moodler's avatar
moodler committed
47
        $site_summary_editbuttons = "<br><center><a href=\"$CFG->admin/site.php\"><img src=\"pix/i/edit.gif\" border=0></a>";
moodler's avatar
moodler committed
48
49
50
51
52
53
54
    }

    if ($site->summary) {
        $lastcolumn = true;
    }


martin's avatar
martin committed
55
56
?>

57

58
59
<table width="100%" border="0" cellspacing="5" cellpadding="5">
  <tr>
moodler's avatar
moodler committed
60
  <?PHP 
61
62
     $sections = get_all_sections($site->id);
  
63
     if ($site->newsitems > 0 or $sections[0]->sequence or isediting($site->id) or isadmin()) {
64

65
         echo "<td width=\"$side\" valign=top nowrap>"; 
66
         $firstcolumn=true;
67
68
69
  
         if ($sections[0]->sequence or isediting($site->id)) {
             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);
72
         }
martin's avatar
martin committed
73

74
75
76
77
78
         if (isadmin()) {
             echo "<div align=\"center\">".update_course_icon($site->id)."</div>";
             echo "<br />";
         }

moodler's avatar
moodler committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
         switch ($CFG->frontpage) {
             case FRONTPAGENEWS:       // print news links on the side
                 print_courses_sideblock(0, "$side");
             break;
    
             case FRONTPAGECOURSELIST:
             case FRONTPAGECATEGORYNAMES:
                 if ($site->newsitems) {
                     if ($news = forum_get_course_forum($site->id, "news")) {
                         print_side_block_start(get_string("latestnews"), $side, "sideblocklatestnews");
                         echo "<font size=\"-2\">";
                         forum_print_latest_discussions($news->id, $site->newsitems, "minimal", "", false);
                         echo "</font>";
                         print_side_block_end();
                     }
                 }
             break;
96
97
98
99
         } 
         print_spacer(1,$side);
     }
 
100
     if (iscreator()) {
101
         if (!$firstcolumn) {
102
103
             echo "<td width=\"$side\" valign=top nowrap>"; 
             $firstcolumn=true;
104
         }
105
106
107
108
         print_admin_links($site->id, $side);
     }

     if ($firstcolumn) {
109
         echo "</td>";
110
     }
moodler's avatar
moodler committed
111
112
113
114
115
     if ($lastcolumn) {
         echo "<td width=\"70%\" valign=\"top\">";
     } else {
         echo "<td width=\"100%\" valign=\"top\">";
     }
116

moodler's avatar
moodler committed
117
118
119
120
121
122
123
124
125
126
127
128
129
     switch ($CFG->frontpage) {     /// Display the main part of the front page.
         case FRONTPAGENEWS:
             if (! $newsforum = forum_get_course_forum($site->id, "news")) {
                 error("Could not find or create a main news forum for the site");
             }
    
             if (isset($USER->id)) {
                 $SESSION->fromdiscussion = "$CFG->wwwroot";
                 if (forum_is_subscribed($USER->id, $newsforum->id)) {
                     $subtext = get_string("unsubscribe", "forum");
                 } else {
                     $subtext = get_string("subscribe", "forum");
                 }
130
                 $headertext = "<table border=0 width=100% cellpadding=0 cellspacing=0 class=headingblockcontent><tr>
moodler's avatar
moodler committed
131
132
133
134
                                <td>$newsforum->name</td>
                                <td align=right><font size=1>
                                <a href=\"mod/forum/subscribe.php?id=$newsforum->id\">$subtext</a>
                                </td></tr></table>";
135
             } else {
moodler's avatar
moodler committed
136
                 $headertext = $newsforum->name;
137
             }
moodler's avatar
moodler committed
138
139
140
141
142
143
144
145
146
147
148
149
150
             print_heading_block($headertext);
             print_spacer(8,1);
             forum_print_latest_discussions($newsforum->id, $site->newsitems);
         break;
    
         case FRONTPAGECOURSELIST:
         case FRONTPAGECATEGORYNAMES:
             if (isset($USER->id) and !isset($USER->admin)) {
                 print_heading_block(get_string("mycourses"));
                 print_spacer(8,1);
                 print_my_moodle();
             } else {
                 if (count_records("course_categories") > 1) {
151
152
153
154
155
156
                     if ($CFG->frontpage == FRONTPAGECOURSELIST) {
                         print_heading_block(get_string("availablecourses"));
                     } else {
                         print_heading_block(get_string("categories"));
                     }
                     print_spacer(8,1);
moodler's avatar
moodler committed
157
                     print_simple_box_start("center", "100%");
moodler's avatar
moodler committed
158
                     print_whole_category_list();
moodler's avatar
moodler committed
159
                     print_simple_box_end();
160
                     print_course_search("", false, "short");
moodler's avatar
moodler committed
161
                 } else {
162
163
                     print_heading_block(get_string("availablecourses"));
                     print_spacer(8,1);
moodler's avatar
moodler committed
164
165
166
167
168
                     print_courses(0, "100%");
                 }
             }
         break;

169
170
     }

171
     echo "</td>";
172

moodler's avatar
moodler committed
173
174
     if ($lastcolumn) {
         echo "<td width=\"30%\" valign=\"top\">";
moodler's avatar
moodler committed
175
176
         print_simple_box(format_text($site->summary, FORMAT_HTML).$site_summary_editbuttons, 
                          "", "100%", $THEME->cellcontent2, 5, "siteinfo");
moodler's avatar
moodler committed
177
178
179
         print_spacer(1,$side);
         echo "</td>";
     }
180
  ?>
181

182
183
  </tr>
</table>
martin's avatar
martin committed
184

moodler's avatar
moodler committed
185
<?PHP print_footer("home");     // Please do not modify this line ?>
martin's avatar
martin committed
186