index.php 8.72 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

21
22
23
24
    optional_param('blockaction');
    optional_param('instanceid', 0, PARAM_INT);
    optional_param('blockid',    0, PARAM_INT);

25
    if (! $site = get_site()) {
dhawes's avatar
dhawes committed
26
        redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
martin's avatar
martin committed
27
28
    }

29
30
31
32
    if ($CFG->forcelogin) {
        require_login();
    }

33
34
    if (isadmin()) {
        if (moodle_needs_upgrading()) {
dhawes's avatar
dhawes committed
35
            redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
36
        }
37
38
39
    }

    if (empty($USER->id)) {
40
41
42
        if (empty($CFG->loginhttps)) {
            $wwwroot = $CFG->wwwroot;
        } else {
dhawes's avatar
dhawes committed
43
            $wwwroot = str_replace('http', 'https', $CFG->wwwroot);
44
        }
dhawes's avatar
dhawes committed
45
        $loginstring = "<font size=\"2\"><a href=\"$wwwroot/login/index.php\">".get_string('login').'</a></font>';
46
    } else {
dhawes's avatar
dhawes committed
47
        $loginstring = '<font size="1">'. user_login_string($site) .'</font>';
moodler's avatar
moodler committed
48
        add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
martin's avatar
martin committed
49
    }
50

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

defacer's avatar
   
defacer committed
59
    $PAGE = page_create_object(MOODLE_PAGE_COURSE, SITEID);
defacer's avatar
   
defacer committed
60

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

urs_hunkler's avatar
urs_hunkler committed
65
66
    echo '<div id="entry-page" class="entry">';  // entry wrapper start

defacer's avatar
defacer committed
67
    $editing = $PAGE->user_is_editing();
68

defacer's avatar
   
defacer committed
69
    $pageblocks = blocks_get_by_page($PAGE);
moodler's avatar
moodler committed
70

71
    if($editing) {
72
73
        if (!empty($blockaction) && confirm_sesskey()) {
            if (!empty($blockid)) {
defacer's avatar
   
defacer committed
74
                blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
urs_hunkler's avatar
urs_hunkler committed
75

76
            }
77
78
            else if (!empty($instanceid)) {
                $instance = blocks_find_instance($instanceid, $pageblocks);
defacer's avatar
   
defacer committed
79
                blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
80
            }
81
            // This re-query could be eliminated by judicious programming in blocks_execute_action(),
dhawes's avatar
dhawes committed
82
            // but I'm not sure if it's worth the complexity increase...
defacer's avatar
   
defacer committed
83
            $pageblocks = blocks_get_by_page($PAGE);
84
        }
moodler's avatar
moodler committed
85

defacer's avatar
   
defacer committed
86
        $missingblocks = blocks_get_missing($PAGE, $pageblocks);
87
    }
moodler's avatar
moodler committed
88

89
90
    optional_variable($preferred_width_left,  blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]));
    optional_variable($preferred_width_right, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]));
defacer's avatar
defacer committed
91
92
93
94
95
    $preferred_width_left = min($preferred_width_left, BLOCK_L_MAX_WIDTH);
    $preferred_width_left = max($preferred_width_left, BLOCK_L_MIN_WIDTH);
    $preferred_width_right = min($preferred_width_right, BLOCK_R_MAX_WIDTH);
    $preferred_width_right = max($preferred_width_right, BLOCK_R_MIN_WIDTH);

martin's avatar
martin committed
96
97
?>

98

urs_hunkler's avatar
urs_hunkler committed
99
<table width="100%" border="0" cellspacing="5" cellpadding="5" id="layout-table">
100
  <tr>
101
102
  <?PHP

103
    if(blocks_have_content($pageblocks[BLOCK_POS_LEFT]) || $editing) {
urs_hunkler's avatar
urs_hunkler committed
104
        echo '<td style="vertical-align: top; width: '.$preferred_width_left.'px;" id="left-column">';
defacer's avatar
   
defacer committed
105
        blocks_print_group($PAGE, $pageblocks[BLOCK_POS_LEFT]);
106
107
108
        echo '</td>';
    }

urs_hunkler's avatar
urs_hunkler committed
109
110
111
    echo '<td style="vertical-align: top;" id="middle-column">';


112
113
/// Print Section
    if ($site->numsections > 0) {
moodler's avatar
moodler committed
114
        print_simple_box_start('center', '100%', $THEME->cellcontent, 5, 'sitetopic');
urs_hunkler's avatar
urs_hunkler committed
115

116
117
        /// If currently moving a file then show the current clipboard
        if (ismoving($site->id)) {
dhawes's avatar
dhawes committed
118
119
120
121
            $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>';
122
123
124
        }


moodler's avatar
moodler committed
125
126
127
128
129
130
131
132
        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;
            $section->section = 1;
            $section->summary = '';
            $section->visible = 1;
            $section->id = insert_record('course_sections', $section);
        }
133

moodler's avatar
moodler committed
134
        echo format_text($section->summary, FORMAT_HTML);
135
136

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

moodler's avatar
moodler committed
143
144
        get_all_mods($site->id, $mods, $modnames, $modnamesplural, $modnamesused);
        print_section($site, $section, $mods, $modnamesused, true);
145
146

        if ($editing) {
147
            print_section_add_menus($site, $section->section, $modnames);
148
        }
moodler's avatar
moodler committed
149
150
        print_simple_box_end();
        print_spacer(10);
151
152
    }

153
154
    switch ($CFG->frontpage) {     /// Display the main part of the front page.
        case FRONTPAGENEWS:
dhawes's avatar
dhawes committed
155
156
            if (! $newsforum = forum_get_course_forum($site->id, 'news')) {
                error('Could not find or create a main news forum for the site');
157
158
159
            }

            if (isset($USER->id)) {
dhawes's avatar
dhawes committed
160
                $SESSION->fromdiscussion = $CFG->wwwroot;
161
                if (forum_is_subscribed($USER->id, $newsforum->id)) {
dhawes's avatar
dhawes committed
162
                    $subtext = get_string('unsubscribe', 'forum');
163
                } else {
dhawes's avatar
dhawes committed
164
                    $subtext = get_string('subscribe', 'forum');
165
                }
gustav_delius's avatar
gustav_delius committed
166
                $headertext = "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" class=\"headingblockcontent\"><tr>
167
                               <td>$newsforum->name</td>
gustav_delius's avatar
gustav_delius committed
168
                               <td align=\"right\"><font size=\"1\">
169
170
171
172
173
                               <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
174

175
176
177
178
            if ($site->newsitems) { //print forums only when needed
                print_heading_block($headertext);
                print_spacer(8,1);
                forum_print_latest_discussions($newsforum->id, $site->newsitems);
urs_hunkler's avatar
urs_hunkler committed
179
            }
180
181
182
183
184
        break;

        case FRONTPAGECOURSELIST:
        case FRONTPAGECATEGORYNAMES:
            if (isset($USER->id) and !isset($USER->admin)) {
dhawes's avatar
dhawes committed
185
                print_heading_block(get_string('mycourses'));
186
187
188
                print_spacer(8,1);
                print_my_moodle();
            } else {
dhawes's avatar
dhawes committed
189
                if (count_records('course_categories') > 1) {
190
                    if ($CFG->frontpage == FRONTPAGECOURSELIST) {
dhawes's avatar
dhawes committed
191
                        print_heading_block(get_string('availablecourses'));
192
                    } else {
dhawes's avatar
dhawes committed
193
                        print_heading_block(get_string('categories'));
194
195
                    }
                    print_spacer(8,1);
dhawes's avatar
dhawes committed
196
                    print_simple_box_start('center', '100%');
197
198
                    print_whole_category_list();
                    print_simple_box_end();
dhawes's avatar
dhawes committed
199
                    print_course_search('', false, 'short');
200
                } else {
dhawes's avatar
dhawes committed
201
                    print_heading_block(get_string('availablecourses'));
202
                    print_spacer(8,1);
dhawes's avatar
dhawes committed
203
                    print_courses(0, '100%');
204
205
206
207
208
209
210
                }
            }
        break;

    }

    echo '</td>';
211
212
213
214


    // The right column
    if(blocks_have_content($pageblocks[BLOCK_POS_RIGHT]) || $editing || isadmin()) {
urs_hunkler's avatar
urs_hunkler committed
215
        echo '<td style="vertical-align: top; width: '.$preferred_width_right.'px;" id="right-column">';
216
217
218
219
        if (isadmin()) {
            echo '<div align="center">'.update_course_icon($site->id).'</div>';
            echo '<br />';
        }
defacer's avatar
   
defacer committed
220
        blocks_print_group($PAGE, $pageblocks[BLOCK_POS_RIGHT]);
221
        if ($editing && !empty($missingblocks)) {
defacer's avatar
   
defacer committed
222
            blocks_print_adminblock($PAGE, $missingblocks);
223
224
225
226
        }
        echo '</td>';
    }
?>
227

228
229
  </tr>
</table>
martin's avatar
martin committed
230

urs_hunkler's avatar
urs_hunkler committed
231
232
233
234
235
<?php
    echo '</div>';  // entry wrapper end

    print_footer('home');     // Please do not modify this line
?>