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

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

25
26
27
28
    if ($CFG->forcelogin) {
        require_login();
    }

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

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

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

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

defacer's avatar
   
defacer committed
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
            echo format_text($section->summary, FORMAT_HTML);
98

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

117
118
    switch ($CFG->frontpage) {     /// Display the main part of the front page.
        case FRONTPAGENEWS:
moodler's avatar
moodler committed
119
            if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
dhawes's avatar
dhawes committed
120
                error('Could not find or create a main news forum for the site');
121
122
123
            }

            if (isset($USER->id)) {
dhawes's avatar
dhawes committed
124
                $SESSION->fromdiscussion = $CFG->wwwroot;
125
                if (forum_is_subscribed($USER->id, $newsforum->id)) {
dhawes's avatar
dhawes committed
126
                    $subtext = get_string('unsubscribe', 'forum');
127
                } else {
dhawes's avatar
dhawes committed
128
                    $subtext = get_string('subscribe', 'forum');
129
                }
gustav_delius's avatar
gustav_delius committed
130
                $headertext = "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" class=\"headingblockcontent\"><tr>
131
                               <td>$newsforum->name</td>
gustav_delius's avatar
gustav_delius committed
132
                               <td align=\"right\"><font size=\"1\">
133
134
135
136
137
                               <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
138

moodler's avatar
moodler committed
139
            if ($SITE->newsitems) { //print forums only when needed
140
141
                print_heading_block($headertext);
                print_spacer(8,1);
moodler's avatar
moodler committed
142
                forum_print_latest_discussions($newsforum->id, $SITE->newsitems);
urs_hunkler's avatar
urs_hunkler committed
143
            }
144
145
146
147
148
        break;

        case FRONTPAGECOURSELIST:
        case FRONTPAGECATEGORYNAMES:
            if (isset($USER->id) and !isset($USER->admin)) {
dhawes's avatar
dhawes committed
149
                print_heading_block(get_string('mycourses'));
150
151
152
                print_spacer(8,1);
                print_my_moodle();
            } else {
dhawes's avatar
dhawes committed
153
                if (count_records('course_categories') > 1) {
154
                    if ($CFG->frontpage == FRONTPAGECOURSELIST) {
dhawes's avatar
dhawes committed
155
                        print_heading_block(get_string('availablecourses'));
156
                    } else {
dhawes's avatar
dhawes committed
157
                        print_heading_block(get_string('categories'));
158
159
                    }
                    print_spacer(8,1);
dhawes's avatar
dhawes committed
160
                    print_simple_box_start('center', '100%');
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
                    print_heading_block(get_string('availablecourses'));
166
                    print_spacer(8,1);
dhawes's avatar
dhawes committed
167
                    print_courses(0, '100%');
168
169
170
171
172
173
174
                }
            }
        break;

    }

    echo '</td>';
175
176
177


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

189
190
  </tr>
</table>
martin's avatar
martin committed
191

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