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

defacer's avatar
   
defacer committed
21
22
23
    $blockaction = optional_param('blockaction');
    $instanceid  = optional_param('instanceid', 0, PARAM_INT);
    $blockid     = optional_param('blockid',    0, PARAM_INT);
24

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(PAGE_COURSE_VIEW, SITEID);
defacer's avatar
   
defacer committed
60

defacer's avatar
defacer committed
61
    $editing = $PAGE->user_is_editing();
62

defacer's avatar
   
defacer committed
63
    $pageblocks = blocks_get_by_page($PAGE);
moodler's avatar
moodler committed
64

65
    if($editing) {
66
67
        if (!empty($blockaction) && confirm_sesskey()) {
            if (!empty($blockid)) {
defacer's avatar
   
defacer committed
68
                blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
urs_hunkler's avatar
urs_hunkler committed
69

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

81
82
    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
83
84
85
86
87
    $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);

defacer's avatar
   
defacer committed
88
89
90
91
    print_header(strip_tags($site->fullname), $site->fullname, 'home', '',
                 '<meta name="description" content="'. s(strip_tags($site->summary)) .'" />',
                 true, '', $loginstring . '<br />' . $langmenu);

martin's avatar
martin committed
92
93
?>

94

urs_hunkler's avatar
urs_hunkler committed
95
<table width="100%" border="0" cellspacing="5" cellpadding="5" id="layout-table">
96
  <tr>
97
98
  <?PHP

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

urs_hunkler's avatar
urs_hunkler committed
105
106
107
    echo '<td style="vertical-align: top;" id="middle-column">';


108
109
/// Print Section
    if ($site->numsections > 0) {
moodler's avatar
moodler committed
110
        print_simple_box_start('center', '100%', '', 5, 'sitetopic');
urs_hunkler's avatar
urs_hunkler committed
111

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


moodler's avatar
moodler committed
121
122
123
124
125
126
127
128
        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);
        }
129

moodler's avatar
moodler committed
130
        echo format_text($section->summary, FORMAT_HTML);
131
132

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

moodler's avatar
moodler committed
139
140
        get_all_mods($site->id, $mods, $modnames, $modnamesplural, $modnamesused);
        print_section($site, $section, $mods, $modnamesused, true);
141
142

        if ($editing) {
143
            print_section_add_menus($site, $section->section, $modnames);
144
        }
moodler's avatar
moodler committed
145
146
        print_simple_box_end();
        print_spacer(10);
147
148
    }

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

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

171
172
173
174
            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
175
            }
176
177
178
179
180
        break;

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

    }

    echo '</td>';
207
208
209
210


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

224
225
  </tr>
</table>
martin's avatar
martin committed
226

urs_hunkler's avatar
urs_hunkler committed
227
228
<?php
    print_footer('home');     // Please do not modify this line
moodler's avatar
moodler committed
229
?>