index.php 7.57 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');
16
    require_once($CFG->dirroot .'/course/lib.php');
dhawes's avatar
dhawes committed
17
    require_once($CFG->dirroot .'/lib/blocklib.php');
martin's avatar
martin committed
18

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

23
24
25
26
    if ($CFG->forcelogin) {
        require_login();
    }

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

33
34
35
36
    if (get_moodle_cookie() == '') {   
        set_moodle_cookie('nobody');   // To help search for cookies on login page
    }

37
    if (!empty($USER->id)) {
moodler's avatar
moodler committed
38
        add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
martin's avatar
martin committed
39
    }
40

41
    if (empty($CFG->langmenu)) {
dhawes's avatar
dhawes committed
42
        $langmenu = '';
43
44
45
    } else {
        $currlang = current_language();
        $langs = get_list_of_languages();
dhawes's avatar
dhawes committed
46
        $langmenu = popup_form ($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true);
47
    }
48

defacer's avatar
   
defacer committed
49
    $PAGE       = page_create_object(PAGE_COURSE_VIEW, SITEID);
defacer's avatar
   
defacer committed
50
    $pageblocks = blocks_setup($PAGE);
defacer's avatar
   
defacer committed
51
    $editing    = $PAGE->user_is_editing();
52
53
54
55
    $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
56

moodler's avatar
moodler committed
57
58
    print_header(strip_tags($SITE->fullname), $SITE->fullname, 'home', '',
                 '<meta name="description" content="'. s(strip_tags($SITE->summary)) .'" />',
59
                 true, '', user_login_string($SITE).$langmenu);
defacer's avatar
   
defacer committed
60

martin's avatar
martin committed
61
62
?>

63

defacer's avatar
   
defacer committed
64
<table id="layout-table">
65
  <tr>
66
  <?php
67

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

defacer's avatar
   
defacer committed
74
    echo '<td id="middle-column">';
urs_hunkler's avatar
urs_hunkler committed
75
76


77
/// Print Section
moodler's avatar
moodler committed
78
    if ($SITE->numsections > 0) {
79

moodler's avatar
moodler committed
80
81
82
        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
83
84
            $section->section = 1;
            $section->summary = '';
85
            $section->sequence = '';
moodler's avatar
moodler committed
86
87
88
            $section->visible = 1;
            $section->id = insert_record('course_sections', $section);
        }
89

90
91
        if (!empty($section->sequence) or !empty($section->summary) or $editing) {
            print_simple_box_start('center', '100%', '', 5, 'sitetopic');
92

93
94
95
96
            /// If currently moving a file then show the current clipboard
            if (ismoving($SITE->id)) {
                $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
                echo '<p><font size="2">';
97
                echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=$USER->sesskey\">". get_string('cancel') .'</a>)';
98
99
                echo '</font></p>';
            }
100

101
102
103
            $options = NULL;
            $options->noclean = true;
            echo format_text($section->summary, FORMAT_HTML, $options);
104

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

            get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
            print_section($SITE, $section, $mods, $modnamesused, true);
    
            if ($editing) {
                print_section_add_menus($SITE, $section->section, $modnames);
            }
            print_simple_box_end();
119
120
121
        }
    }

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
    foreach (explode(',',$CFG->frontpage) as $v) {
        switch ($v) {     /// Display the main part of the front page.
            case strval(FRONTPAGENEWS):
                if ($SITE->newsitems) { // Print forums only when needed
                    require_once($CFG->dirroot .'/mod/forum/lib.php');

                    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');
                        }
                        $headertext = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>'.
                            '<td><div class="title">'.$newsforum->name.'</div></td>'.
                            '<td><div class="link"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div></td>'.
                            '</tr></table>';
143
                    } else {
144
                        $headertext = $newsforum->name;
145
                    }
146
147
148

                    print_heading_block($headertext);
                    forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems);
149
                }
150
            break;
151

152
153
            case FRONTPAGECOURSELIST:
            case FRONTPAGECATEGORYNAMES:
154

155
156
157
158
159
160
161
162
163
164
165
166
167
168
                if (isloggedin() && !isset($USER->admin) && empty($CFG->disablemycourses)) {
                    print_heading_block(get_string('mycourses'));
                    print_my_moodle();
                } else {
                    if (count_records('course_categories') > 1) {
                        if ($v == FRONTPAGECOURSELIST) {
                            print_heading_block(get_string('availablecourses'));
                        } else {
                            print_heading_block(get_string('categories'));
                        }
                        print_simple_box_start('center', '100%', '', 5, 'categorybox');
                        print_whole_category_list();
                        print_simple_box_end();
                        print_course_search('', false, 'short');
169
                    } else {
170
171
                        print_heading_block(get_string('availablecourses'));
                        print_courses(0, '100%');
172
173
                    }
                }
174
            break;
175

176
177
            case FRONTPAGETOPICONLY:    // Do nothing!!  :-)
            break;
178

179
180
        }
        echo '<br />';
181
182
183
    }

    echo '</td>';
184
185
186


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

198
199
  </tr>
</table>
martin's avatar
martin committed
200

urs_hunkler's avatar
urs_hunkler committed
201
202
<?php
    print_footer('home');     // Please do not modify this line
moodler's avatar
moodler committed
203
?>