file ongoing.html was added on branch MOODLE_15_STABLE on 2005-07-07 16:14:36 +0000
[moodle.git] / index.php
blobede2d13e3104824b4609c4ca7d084d5d44e15546
1 <?php // $Id$
2 // index.php - the front page.
4 if (!file_exists('./config.php')) {
5 header('Location: install.php');
6 die;
9 /// Bounds for block widths on this page
10 define('BLOCK_L_MIN_WIDTH', 160);
11 define('BLOCK_L_MAX_WIDTH', 210);
12 define('BLOCK_R_MIN_WIDTH', 160);
13 define('BLOCK_R_MAX_WIDTH', 210);
15 require_once('config.php');
16 require_once($CFG->dirroot .'/course/lib.php');
17 require_once($CFG->dirroot .'/lib/blocklib.php');
19 if (empty($SITE)) {
20 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
23 if ($CFG->forcelogin) {
24 require_login();
27 if (isadmin()) {
28 if (moodle_needs_upgrading()) {
29 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
33 if (get_moodle_cookie() == '') {
34 set_moodle_cookie('nobody'); // To help search for cookies on login page
37 if (!empty($USER->id)) {
38 add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
41 if (empty($CFG->langmenu)) {
42 $langmenu = '';
43 } else {
44 $currlang = current_language();
45 $langs = get_list_of_languages();
46 $langmenu = popup_form ($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true);
49 $PAGE = page_create_object(PAGE_COURSE_VIEW, SITEID);
50 $pageblocks = blocks_setup($PAGE);
51 $editing = $PAGE->user_is_editing();
52 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
53 BLOCK_L_MAX_WIDTH);
54 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
55 BLOCK_R_MAX_WIDTH);
57 print_header(strip_tags($SITE->fullname), $SITE->fullname, 'home', '',
58 '<meta name="description" content="'. s(strip_tags($SITE->summary)) .'" />',
59 true, '', user_login_string($SITE).$langmenu);
64 <table id="layout-table">
65 <tr>
66 <?php
68 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
69 echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
70 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
71 echo '</td>';
74 echo '<td id="middle-column">';
77 /// Print Section
78 if ($SITE->numsections > 0) {
80 if (!$section = get_record('course_sections', 'course', $SITE->id, 'section', 1)) {
81 delete_records('course_sections', 'course', $SITE->id, 'section', 1); // Just in case
82 $section->course = $SITE->id;
83 $section->section = 1;
84 $section->summary = '';
85 $section->sequence = '';
86 $section->visible = 1;
87 $section->id = insert_record('course_sections', $section);
90 if (!empty($section->sequence) or !empty($section->summary) or $editing) {
91 print_simple_box_start('center', '100%', '', 5, 'sitetopic');
93 /// If currently moving a file then show the current clipboard
94 if (ismoving($SITE->id)) {
95 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
96 echo '<p><font size="2">';
97 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true\">". get_string('cancel') .'</a>)';
98 echo '</font></p>';
101 $options = NULL;
102 $options->noclean = true;
103 echo format_text($section->summary, FORMAT_HTML, $options);
105 if ($editing) {
106 $streditsummary = get_string('editsummary');
107 echo "<a title=\"$streditsummary\" ".
108 " href=\"course/editsection.php?id=$section->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
109 " height=\"11\" width=\"11\" border=\"0\" alt=\"$streditsummary\" /></a><br /><br />";
112 get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
113 print_section($SITE, $section, $mods, $modnamesused, true);
115 if ($editing) {
116 print_section_add_menus($SITE, $section->section, $modnames);
118 print_simple_box_end();
122 switch ($CFG->frontpage) { /// Display the main part of the front page.
123 case FRONTPAGENEWS:
124 if ($SITE->newsitems) { // Print forums only when needed
125 require_once($CFG->dirroot .'/mod/forum/lib.php');
127 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
128 error('Could not find or create a main news forum for the site');
131 if (isset($USER->id)) {
132 $SESSION->fromdiscussion = $CFG->wwwroot;
133 if (forum_is_subscribed($USER->id, $newsforum->id)) {
134 $subtext = get_string('unsubscribe', 'forum');
135 } else {
136 $subtext = get_string('subscribe', 'forum');
138 $headertext = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>'.
139 '<td><div class="title">'.$newsforum->name.'</div></td>'.
140 '<td><div class="link"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div></td>'.
141 '</tr></table>';
142 } else {
143 $headertext = $newsforum->name;
146 print_heading_block($headertext);
147 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems);
149 break;
151 case FRONTPAGECOURSELIST:
152 case FRONTPAGECATEGORYNAMES:
154 if (isloggedin() && !isset($USER->admin) && empty($CFG->disablemycourses)) {
155 print_heading_block(get_string('mycourses'));
156 print_my_moodle();
157 } else {
158 if (count_records('course_categories') > 1) {
159 if ($CFG->frontpage == FRONTPAGECOURSELIST) {
160 print_heading_block(get_string('availablecourses'));
161 } else {
162 print_heading_block(get_string('categories'));
164 print_simple_box_start('center', '100%', '', 5, 'categorybox');
165 print_whole_category_list();
166 print_simple_box_end();
167 print_course_search('', false, 'short');
168 } else {
169 print_heading_block(get_string('availablecourses'));
170 print_courses(0, '100%');
173 break;
175 case FRONTPAGETOPICONLY: // Do nothing!! :-)
176 break;
180 echo '</td>';
183 // The right column
184 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || isadmin()) {
185 echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
186 if (isadmin()) {
187 echo '<div align="center">'.update_course_icon($SITE->id).'</div>';
188 echo '<br />';
190 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
191 echo '</td>';
195 </tr>
196 </table>
198 <?php
199 print_footer('home'); // Please do not modify this line