index.php 7.69 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
    $blockaction = optional_param('blockaction');
22

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

27
28
29
30
    if ($CFG->forcelogin) {
        require_login();
    }

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

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

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

defacer's avatar
   
defacer committed
57
    $PAGE       = page_create_object(PAGE_COURSE_VIEW, SITEID);
defacer's avatar
   
defacer committed
58
    $pageblocks = blocks_get_by_page($PAGE);
defacer's avatar
   
defacer committed
59
    $editing    = $PAGE->user_is_editing();
moodler's avatar
moodler committed
60

defacer's avatar
   
defacer committed
61
62
63
64
65
    if (!empty($blockaction)) {
        blocks_execute_url_action($PAGE, $pageblocks);
        // This re-query could be eliminated by judicious programming in blocks_execute_action(),
        // but I'm not sure if it's worth the complexity increase...
        $pageblocks = blocks_get_by_page($PAGE);
66
    }
moodler's avatar
moodler committed
67

defacer's avatar
   
defacer committed
68
69
    $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
70

defacer's avatar
   
defacer committed
71
72
73
74
    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
75
76
?>

77

defacer's avatar
   
defacer committed
78
<table id="layout-table">
79
  <tr>
80
81
  <?PHP

82
    if(blocks_have_content($pageblocks[BLOCK_POS_LEFT]) || $editing) {
defacer's avatar
   
defacer committed
83
        echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
defacer's avatar
   
defacer committed
84
        blocks_print_group($PAGE, $pageblocks[BLOCK_POS_LEFT]);
85
86
87
        echo '</td>';
    }

defacer's avatar
   
defacer committed
88
    echo '<td id="middle-column">';
urs_hunkler's avatar
urs_hunkler committed
89
90


91
92
/// Print Section
    if ($site->numsections > 0) {
moodler's avatar
moodler committed
93
        print_simple_box_start('center', '100%', '', 5, 'sitetopic');
urs_hunkler's avatar
urs_hunkler committed
94

95
96
        /// If currently moving a file then show the current clipboard
        if (ismoving($site->id)) {
dhawes's avatar
dhawes committed
97
98
99
100
            $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>';
101
102
103
        }


moodler's avatar
moodler committed
104
105
106
107
108
109
110
111
        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);
        }
112

moodler's avatar
moodler committed
113
        echo format_text($section->summary, FORMAT_HTML);
114
115

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

moodler's avatar
moodler committed
122
123
        get_all_mods($site->id, $mods, $modnames, $modnamesplural, $modnamesused);
        print_section($site, $section, $mods, $modnamesused, true);
124
125

        if ($editing) {
126
            print_section_add_menus($site, $section->section, $modnames);
127
        }
moodler's avatar
moodler committed
128
129
        print_simple_box_end();
        print_spacer(10);
130
131
    }

132
133
    switch ($CFG->frontpage) {     /// Display the main part of the front page.
        case FRONTPAGENEWS:
dhawes's avatar
dhawes committed
134
135
            if (! $newsforum = forum_get_course_forum($site->id, 'news')) {
                error('Could not find or create a main news forum for the site');
136
137
138
            }

            if (isset($USER->id)) {
dhawes's avatar
dhawes committed
139
                $SESSION->fromdiscussion = $CFG->wwwroot;
140
                if (forum_is_subscribed($USER->id, $newsforum->id)) {
dhawes's avatar
dhawes committed
141
                    $subtext = get_string('unsubscribe', 'forum');
142
                } else {
dhawes's avatar
dhawes committed
143
                    $subtext = get_string('subscribe', 'forum');
144
                }
gustav_delius's avatar
gustav_delius committed
145
                $headertext = "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" class=\"headingblockcontent\"><tr>
146
                               <td>$newsforum->name</td>
gustav_delius's avatar
gustav_delius committed
147
                               <td align=\"right\"><font size=\"1\">
148
149
150
151
152
                               <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
153

154
155
156
157
            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
158
            }
159
160
161
162
163
        break;

        case FRONTPAGECOURSELIST:
        case FRONTPAGECATEGORYNAMES:
            if (isset($USER->id) and !isset($USER->admin)) {
dhawes's avatar
dhawes committed
164
                print_heading_block(get_string('mycourses'));
165
166
167
                print_spacer(8,1);
                print_my_moodle();
            } else {
dhawes's avatar
dhawes committed
168
                if (count_records('course_categories') > 1) {
169
                    if ($CFG->frontpage == FRONTPAGECOURSELIST) {
dhawes's avatar
dhawes committed
170
                        print_heading_block(get_string('availablecourses'));
171
                    } else {
dhawes's avatar
dhawes committed
172
                        print_heading_block(get_string('categories'));
173
174
                    }
                    print_spacer(8,1);
dhawes's avatar
dhawes committed
175
                    print_simple_box_start('center', '100%');
176
177
                    print_whole_category_list();
                    print_simple_box_end();
dhawes's avatar
dhawes committed
178
                    print_course_search('', false, 'short');
179
                } else {
dhawes's avatar
dhawes committed
180
                    print_heading_block(get_string('availablecourses'));
181
                    print_spacer(8,1);
dhawes's avatar
dhawes committed
182
                    print_courses(0, '100%');
183
184
185
186
187
188
189
                }
            }
        break;

    }

    echo '</td>';
190
191
192
193


    // The right column
    if(blocks_have_content($pageblocks[BLOCK_POS_RIGHT]) || $editing || isadmin()) {
defacer's avatar
   
defacer committed
194
        echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
195
196
197
198
        if (isadmin()) {
            echo '<div align="center">'.update_course_icon($site->id).'</div>';
            echo '<br />';
        }
defacer's avatar
   
defacer committed
199
        blocks_print_group($PAGE, $pageblocks[BLOCK_POS_RIGHT]);
defacer's avatar
   
defacer committed
200
201
        if ($editing) {
            blocks_print_adminblock($PAGE, $pageblocks);
202
203
204
205
        }
        echo '</td>';
    }
?>
206

207
208
  </tr>
</table>
martin's avatar
martin committed
209

urs_hunkler's avatar
urs_hunkler committed
210
211
<?php
    print_footer('home');     // Please do not modify this line
moodler's avatar
moodler committed
212
?>