index.php 7.15 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
    if (!empty($USER->id)) {
moodler's avatar
moodler committed
34
        add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
martin's avatar
martin committed
35
    }
36

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

defacer's avatar
   
defacer committed
45
    $PAGE       = page_create_object(PAGE_COURSE_VIEW, SITEID);
defacer's avatar
   
defacer committed
46
    $pageblocks = blocks_setup($PAGE);
defacer's avatar
   
defacer committed
47
    $editing    = $PAGE->user_is_editing();
48
49
50
51
    $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
52

moodler's avatar
moodler committed
53
54
    print_header(strip_tags($SITE->fullname), $SITE->fullname, 'home', '',
                 '<meta name="description" content="'. s(strip_tags($SITE->summary)) .'" />',
55
                 true, '', user_login_string($SITE).$langmenu);
defacer's avatar
   
defacer committed
56

martin's avatar
martin committed
57
58
?>

59

defacer's avatar
   
defacer committed
60
<table id="layout-table">
61
  <tr>
62
  <?php
63

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

defacer's avatar
   
defacer committed
70
    echo '<td id="middle-column">';
urs_hunkler's avatar
urs_hunkler committed
71
72


73
/// Print Section
moodler's avatar
moodler committed
74
    if ($SITE->numsections > 0) {
75

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

86
87
        if (!empty($section->sequence) or !empty($section->summary) or $editing) {
            print_simple_box_start('center', '100%', '', 5, 'sitetopic');
88

89
90
91
92
93
94
95
            /// 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">';
                echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true\">". get_string('cancel') .'</a>)';
                echo '</font></p>';
            }
96

97
98
99
            $options = NULL;
            $options->noclean = true;
            echo format_text($section->summary, FORMAT_HTML, $options);
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
            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();
115
116
117
        }
    }

118
119
    switch ($CFG->frontpage) {     /// Display the main part of the front page.
        case FRONTPAGENEWS:
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
            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>';
138
                } else {
139
                    $headertext = $newsforum->name;
140
                }
141
    
142
                print_heading_block($headertext);
143
                forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems);
urs_hunkler's avatar
urs_hunkler committed
144
            }
145
146
147
148
        break;

        case FRONTPAGECOURSELIST:
        case FRONTPAGECATEGORYNAMES:
149

150
            if (isset($USER->id) and !isset($USER->admin)) {
dhawes's avatar
dhawes committed
151
                print_heading_block(get_string('mycourses'));
152
153
                print_my_moodle();
            } else {
dhawes's avatar
dhawes committed
154
                if (count_records('course_categories') > 1) {
155
                    if ($CFG->frontpage == FRONTPAGECOURSELIST) {
dhawes's avatar
dhawes committed
156
                        print_heading_block(get_string('availablecourses'));
157
                    } else {
dhawes's avatar
dhawes committed
158
                        print_heading_block(get_string('categories'));
159
                    }
160
                    print_simple_box_start('center', '100%', '', 5, 'categorybox');
161
162
                    print_whole_category_list();
                    print_simple_box_end();
dhawes's avatar
dhawes committed
163
                    print_course_search('', false, 'short');
164
                } else {
dhawes's avatar
dhawes committed
165
166
                    print_heading_block(get_string('availablecourses'));
                    print_courses(0, '100%');
167
168
169
170
                }
            }
        break;

171
172
173
        case FRONTPAGETOPICONLY:    // Do nothing!!  :-)
        break;

174
175
176
    }

    echo '</td>';
177
178
179


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

191
192
  </tr>
</table>
martin's avatar
martin committed
193

urs_hunkler's avatar
urs_hunkler committed
194
195
<?php
    print_footer('home');     // Please do not modify this line
moodler's avatar
moodler committed
196
?>