Fixed couple bugs in query, and improved logic of querylib.
[moodle.git] / index.php
1 <?php  // $Id$
2        // index.php - the front page.
4 ///////////////////////////////////////////////////////////////////////////
5 //                                                                       //
6 // NOTICE OF COPYRIGHT                                                   //
7 //                                                                       //
8 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
9 //          http://moodle.org                                            //
10 //                                                                       //
11 // Copyright (C) 1999-2999  Martin Dougiamas  http://moodle.com          //
12 //                                                                       //
13 // This program is free software; you can redistribute it and/or modify  //
14 // it under the terms of the GNU General Public License as published by  //
15 // the Free Software Foundation; either version 2 of the License, or     //
16 // (at your option) any later version.                                   //
17 //                                                                       //
18 // This program is distributed in the hope that it will be useful,       //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
21 // GNU General Public License for more details:                          //
22 //                                                                       //
23 //          http://www.gnu.org/copyleft/gpl.html                         //
24 //                                                                       //
25 ///////////////////////////////////////////////////////////////////////////
28     if (!file_exists('./config.php')) {
29         header('Location: install.php');
30         die;
31     }
33 /// Bounds for block widths on this page
34     define('BLOCK_L_MIN_WIDTH', 160);
35     define('BLOCK_L_MAX_WIDTH', 210);
36     define('BLOCK_R_MIN_WIDTH', 160);
37     define('BLOCK_R_MAX_WIDTH', 210);
39     require_once('config.php');
40     require_once($CFG->dirroot .'/course/lib.php');
41     require_once($CFG->dirroot .'/lib/blocklib.php');
43     if (empty($SITE)) {
44         redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
45     }
47     if ($CFG->forcelogin) {
48         require_login();
49     }
51     if (isadmin()) {
52         if (moodle_needs_upgrading()) {
53             redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
54         }
55     }
57     if (get_moodle_cookie() == '') {   
58         set_moodle_cookie('nobody');   // To help search for cookies on login page
59     }
61     if (!empty($USER->id)) {
62         add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
63     }
65     if (empty($CFG->langmenu)) {
66         $langmenu = '';
67     } else {
68         $currlang = current_language();
69         $langs = get_list_of_languages();
70         $langmenu = popup_form ($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true);
71     }
73     $PAGE       = page_create_object(PAGE_COURSE_VIEW, SITEID);
74     $pageblocks = blocks_setup($PAGE);
75     $editing    = $PAGE->user_is_editing();
76     $preferred_width_left  = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),  
77                                             BLOCK_L_MAX_WIDTH);
78     $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 
79                                             BLOCK_R_MAX_WIDTH);
81     print_header(strip_tags($SITE->fullname), $SITE->fullname, 'home', '',
82                  '<meta name="description" content="'. s(strip_tags($SITE->summary)) .'" />',
83                  true, '', user_login_string($SITE).$langmenu);
85 ?>
88 <table id="layout-table">
89   <tr>
90   <?php
92     if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
93         echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
94         blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
95         echo '</td>';
96     }
98     echo '<td id="middle-column">';
101 /// Print Section
102     if ($SITE->numsections > 0) {
104         if (!$section = get_record('course_sections', 'course', $SITE->id, 'section', 1)) {
105             delete_records('course_sections', 'course', $SITE->id, 'section', 1); // Just in case
106             $section->course = $SITE->id;
107             $section->section = 1;
108             $section->summary = '';
109             $section->sequence = '';
110             $section->visible = 1;
111             $section->id = insert_record('course_sections', $section);
112         }
114         if (!empty($section->sequence) or !empty($section->summary) or $editing) {
115             print_simple_box_start('center', '100%', '', 5, 'sitetopic');
117             /// If currently moving a file then show the current clipboard
118             if (ismoving($SITE->id)) {
119                 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
120                 echo '<p><font size="2">';
121                 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=$USER->sesskey\">". get_string('cancel') .'</a>)';
122                 echo '</font></p>';
123             }
125             $options = NULL;
126             $options->noclean = true;
127             echo format_text($section->summary, FORMAT_HTML, $options);
129             if ($editing) {
130                 $streditsummary = get_string('editsummary');
131                 echo "<a title=\"$streditsummary\" ".
132                      " href=\"course/editsection.php?id=$section->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
133                      " height=\"11\" width=\"11\" border=\"0\" alt=\"$streditsummary\" /></a><br /><br />";
134             }
136             get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
137             print_section($SITE, $section, $mods, $modnamesused, true);
138     
139             if ($editing) {
140                 print_section_add_menus($SITE, $section->section, $modnames);
141             }
142             print_simple_box_end();
143         }
144     }
146     if (isloggedin() and !isguest() and isset($CFG->frontpageloggedin)) {
147         $frontpagelayout = $CFG->frontpageloggedin;
148     } else {
149         $frontpagelayout = $CFG->frontpage;
150     }
152     foreach (explode(',',$frontpagelayout) as $v) {
153         switch ($v) {     /// Display the main part of the front page.
154             case strval(FRONTPAGENEWS):
155                 if ($SITE->newsitems) { // Print forums only when needed
156                     require_once($CFG->dirroot .'/mod/forum/lib.php');
158                     if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
159                         error('Could not find or create a main news forum for the site');
160                     }
162                     if (!empty($USER->id)) {
163                         $SESSION->fromdiscussion = $CFG->wwwroot;
164                         if (forum_is_subscribed($USER->id, $newsforum->id)) {
165                             $subtext = get_string('unsubscribe', 'forum');
166                         } else {
167                             $subtext = get_string('subscribe', 'forum');
168                         }
169                         $headertext = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>'.
170                             '<td><div class="title">'.$newsforum->name.'</div></td>'.
171                             '<td><div class="link"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div></td>'.
172                             '</tr></table>';
173                     } else {
174                         $headertext = $newsforum->name;
175                     }
177                     print_heading_block($headertext);
178                     forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
179                 }
180             break;
182             case FRONTPAGECOURSELIST:
184                 if (isloggedin() and !isadmin() and !isguest() and empty($CFG->disablemycourses)) {
185                     print_heading_block(get_string('mycourses'));
186                     print_my_moodle();
187                 } else if ((!isadmin() and !isguest()) or (count_records('course') <= FRONTPAGECOURSELIMIT)) {
188                     // admin should not see list of courses when there are too many of them
189                     print_heading_block(get_string('availablecourses'));
190                     print_courses(0, '100%', true);
191                 }
192             break;
194             case FRONTPAGECATEGORYNAMES:
196                 print_heading_block(get_string('categories'));
197                 print_simple_box_start('center', '100%', '', 5, 'categorybox');
198                 print_whole_category_list(NULL, NULL, NULL, -1, false);
199                 print_simple_box_end();
200                 print_course_search('', false, 'short');
201             break;
203             case FRONTPAGECATEGORYCOMBO:
205                 print_heading_block(get_string('categories'));
206                 print_simple_box_start('center', '100%', '', 5, 'categorybox');
207                 print_whole_category_list(NULL, NULL, NULL, -1, true);
208                 print_simple_box_end();
209                 print_course_search('', false, 'short');
210             break;
212             case FRONTPAGETOPICONLY:    // Do nothing!!  :-)
213             break;
215         }
216         echo '<br />';
217     }
219     echo '</td>';
221     // The right column
222     if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || isadmin()) {
223         echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
224         if (isadmin()) {
225             echo '<div align="center">'.update_course_icon($SITE->id).'</div>';
226             echo '<br />';
227         }
228         blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
229         echo '</td>';
230     }
231 ?>
233   </tr>
234 </table>
236 <?php
237     print_footer('home');     // Please do not modify this line
238 ?>