index.php 7.2 KB
Newer Older
dhawes's avatar
dhawes committed
1
<?php  // $Id$
moodler's avatar
moodler committed
2
       // index.php - the front page.
3

4
5
6
7
8
9
    if (!file_exists('./config.php')) {
        header('Location: install.php');
        die;
    }

/// Bounds for block widths on this page
defacer's avatar
defacer committed
10
11
12
13
14
    define('BLOCK_L_MIN_WIDTH', 160);
    define('BLOCK_L_MAX_WIDTH', 210);
    define('BLOCK_R_MIN_WIDTH', 160);
    define('BLOCK_R_MAX_WIDTH', 210);

15
    require_once('config.php');
dhawes's avatar
dhawes committed
16
17
18
19
    require_once($CFG->dirroot .'/course/lib.php');
    require_once($CFG->dirroot .'/lib/blocklib.php');
    require_once($CFG->dirroot .'/mod/resource/lib.php');
    require_once($CFG->dirroot .'/mod/forum/lib.php');
martin's avatar
martin committed
20

moodler's avatar
moodler committed
21
    if (empty($SITE)) {
dhawes's avatar
dhawes committed
22
        redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
martin's avatar
martin committed
23
24
    }

25
26
27
28
    if ($CFG->forcelogin) {
        require_login();
    }

29
30
    if (isadmin()) {
        if (moodle_needs_upgrading()) {
dhawes's avatar
dhawes committed
31
            redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
32
        }
33
34
35
    }

    if (empty($USER->id)) {
36
37
38
        if (empty($CFG->loginhttps)) {
            $wwwroot = $CFG->wwwroot;
        } else {
dhawes's avatar
dhawes committed
39
            $wwwroot = str_replace('http', 'https', $CFG->wwwroot);
40
        }
41
        $loginstring = "<div class=\"logininfo\"><a href=\"$wwwroot/login/index.php\">".get_string('login').'</a></div>';
42
    } else {
43
        $loginstring = user_login_string($SITE);
moodler's avatar
moodler committed
44
        add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
martin's avatar
martin committed
45
    }
46

47
    if (empty($CFG->langmenu)) {
dhawes's avatar
dhawes committed
48
        $langmenu = '';
49
50
51
    } else {
        $currlang = current_language();
        $langs = get_list_of_languages();
dhawes's avatar
dhawes committed
52
        $langmenu = popup_form ($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true);
53
    }
54

defacer's avatar
   
defacer committed
55
    $PAGE       = page_create_object(PAGE_COURSE_VIEW, SITEID);
defacer's avatar
   
defacer committed
56
    $pageblocks = blocks_setup($PAGE);
defacer's avatar
   
defacer committed
57
58
59
    $editing    = $PAGE->user_is_editing();
    $preferred_width_left  = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),  BLOCK_L_MAX_WIDTH);
    $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH);
defacer's avatar
defacer committed
60

moodler's avatar
moodler committed
61
62
    print_header(strip_tags($SITE->fullname), $SITE->fullname, 'home', '',
                 '<meta name="description" content="'. s(strip_tags($SITE->summary)) .'" />',
63
                 true, '', $loginstring.$langmenu);
defacer's avatar
   
defacer committed
64

martin's avatar
martin committed
65
66
?>

67

defacer's avatar
   
defacer committed
68
<table id="layout-table">
69
  <tr>
70
71
  <?PHP

defacer's avatar
   
defacer committed
72
    if(blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
defacer's avatar
   
defacer committed
73
        echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
defacer's avatar
   
defacer committed
74
        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
75
76
77
        echo '</td>';
    }

defacer's avatar
   
defacer committed
78
    echo '<td id="middle-column">';
urs_hunkler's avatar
urs_hunkler committed
79
80


81
/// Print Section
moodler's avatar
moodler committed
82
    if ($SITE->numsections > 0) {
moodler's avatar
moodler committed
83
        print_simple_box_start('center', '100%', '', 5, 'sitetopic');
urs_hunkler's avatar
urs_hunkler committed
84

85
        /// If currently moving a file then show the current clipboard
moodler's avatar
moodler committed
86
        if (ismoving($SITE->id)) {
dhawes's avatar
dhawes committed
87
88
89
90
            $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
            echo '<p><font size="2">';
            echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true\">". get_string('cancel') .'</a>)';
            echo '</font></p>';
91
92
93
        }


moodler's avatar
moodler committed
94
95
96
        if (!$section = get_record('course_sections', 'course', $SITE->id, 'section', 1)) {
            delete_records('course_sections', 'course', $SITE->id, 'section', 1); // Just in case
            $section->course = $SITE->id;
moodler's avatar
moodler committed
97
98
99
100
101
            $section->section = 1;
            $section->summary = '';
            $section->visible = 1;
            $section->id = insert_record('course_sections', $section);
        }
102

moodler's avatar
moodler committed
103
        echo format_text($section->summary, FORMAT_HTML);
104
105

        if ($editing) {
moodler's avatar
moodler committed
106
            $streditsummary = get_string('editsummary');
107
            echo "<a title=\"$streditsummary\" ".
moodler's avatar
moodler committed
108
                 " href=\"course/editsection.php?id=$section->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
109
                 " height=\"11\" width=\"11\" border=\"0\" alt=\"$streditsummary\" /></a><br /><br />";
110
111
        }

moodler's avatar
moodler committed
112
113
        get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
        print_section($SITE, $section, $mods, $modnamesused, true);
114
115

        if ($editing) {
moodler's avatar
moodler committed
116
            print_section_add_menus($SITE, $section->section, $modnames);
117
        }
moodler's avatar
moodler committed
118
119
        print_simple_box_end();
        print_spacer(10);
120
121
    }

122
123
    switch ($CFG->frontpage) {     /// Display the main part of the front page.
        case FRONTPAGENEWS:
moodler's avatar
moodler committed
124
            if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
dhawes's avatar
dhawes committed
125
                error('Could not find or create a main news forum for the site');
126
127
128
            }

            if (isset($USER->id)) {
dhawes's avatar
dhawes committed
129
                $SESSION->fromdiscussion = $CFG->wwwroot;
130
                if (forum_is_subscribed($USER->id, $newsforum->id)) {
dhawes's avatar
dhawes committed
131
                    $subtext = get_string('unsubscribe', 'forum');
132
                } else {
dhawes's avatar
dhawes committed
133
                    $subtext = get_string('subscribe', 'forum');
134
                }
gustav_delius's avatar
gustav_delius committed
135
                $headertext = "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" class=\"headingblockcontent\"><tr>
136
                               <td>$newsforum->name</td>
gustav_delius's avatar
gustav_delius committed
137
                               <td align=\"right\"><font size=\"1\">
138
139
140
141
142
                               <a href=\"mod/forum/subscribe.php?id=$newsforum->id\">$subtext</a>
                               </td></tr></table>";
            } else {
                $headertext = $newsforum->name;
            }
urs_hunkler's avatar
urs_hunkler committed
143

moodler's avatar
moodler committed
144
            if ($SITE->newsitems) { //print forums only when needed
145
146
                print_heading_block($headertext);
                print_spacer(8,1);
moodler's avatar
moodler committed
147
                forum_print_latest_discussions($newsforum->id, $SITE->newsitems);
urs_hunkler's avatar
urs_hunkler committed
148
            }
149
150
151
152
153
        break;

        case FRONTPAGECOURSELIST:
        case FRONTPAGECATEGORYNAMES:
            if (isset($USER->id) and !isset($USER->admin)) {
dhawes's avatar
dhawes committed
154
                print_heading_block(get_string('mycourses'));
155
156
157
                print_spacer(8,1);
                print_my_moodle();
            } else {
dhawes's avatar
dhawes committed
158
                if (count_records('course_categories') > 1) {
159
                    if ($CFG->frontpage == FRONTPAGECOURSELIST) {
dhawes's avatar
dhawes committed
160
                        print_heading_block(get_string('availablecourses'));
161
                    } else {
dhawes's avatar
dhawes committed
162
                        print_heading_block(get_string('categories'));
163
164
                    }
                    print_spacer(8,1);
dhawes's avatar
dhawes committed
165
                    print_simple_box_start('center', '100%');
166
167
                    print_whole_category_list();
                    print_simple_box_end();
dhawes's avatar
dhawes committed
168
                    print_course_search('', false, 'short');
169
                } else {
dhawes's avatar
dhawes committed
170
                    print_heading_block(get_string('availablecourses'));
171
                    print_spacer(8,1);
dhawes's avatar
dhawes committed
172
                    print_courses(0, '100%');
173
174
175
176
177
178
179
                }
            }
        break;

    }

    echo '</td>';
180
181
182


    // The right column
defacer's avatar
   
defacer committed
183
    if(blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || isadmin()) {
defacer's avatar
   
defacer committed
184
        echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
185
        if (isadmin()) {
moodler's avatar
moodler committed
186
            echo '<div align="center">'.update_course_icon($SITE->id).'</div>';
187
188
            echo '<br />';
        }
defacer's avatar
   
defacer committed
189
        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
190
191
192
        echo '</td>';
    }
?>
193

194
195
  </tr>
</table>
martin's avatar
martin committed
196

urs_hunkler's avatar
urs_hunkler committed
197
198
<?php
    print_footer('home');     // Please do not modify this line
moodler's avatar
moodler committed
199
?>