|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00026 if (!file_exists('./config.php')) { 00027 header('Location: install.php'); 00028 die; 00029 } 00030 00031 require_once('config.php'); 00032 require_once($CFG->dirroot .'/course/lib.php'); 00033 require_once($CFG->libdir .'/filelib.php'); 00034 00035 redirect_if_major_upgrade_required(); 00036 00037 if ($CFG->forcelogin) { 00038 require_login(); 00039 } else { 00040 user_accesstime_log(); 00041 } 00042 00043 $hassiteconfig = has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); 00044 00045 $urlparams = array(); 00046 if ($CFG->defaulthomepage == HOMEPAGE_MY && optional_param('redirect', 1, PARAM_BOOL) === 0) { 00047 $urlparams['redirect'] = 0; 00048 } 00049 $PAGE->set_url('/', $urlparams); 00050 $PAGE->set_course($SITE); 00051 00053 if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) { 00054 print_maintenance_message(); 00055 } 00056 00057 if ($hassiteconfig && moodle_needs_upgrading()) { 00058 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php'); 00059 } 00060 00061 if (get_home_page() != HOMEPAGE_SITE) { 00062 // Redirect logged-in users to My Moodle overview if required 00063 if (optional_param('setdefaulthome', false, PARAM_BOOL)) { 00064 set_user_preference('user_home_page_preference', HOMEPAGE_SITE); 00065 } else if ($CFG->defaulthomepage == HOMEPAGE_MY && optional_param('redirect', 1, PARAM_BOOL) === 1) { 00066 redirect($CFG->wwwroot .'/my/'); 00067 } else if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_USER) { 00068 $PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/', array('setdefaulthome'=>true)), navigation_node::TYPE_SETTING); 00069 } 00070 } 00071 00072 if (isloggedin()) { 00073 add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID); 00074 } 00075 00077 if (get_config('local_hub', 'hubenabled') && file_exists($CFG->dirroot.'/local/hub/lib.php')) { 00078 require_once($CFG->dirroot.'/local/hub/lib.php'); 00079 $hub = new local_hub(); 00080 $continue = $hub->display_homepage(); 00081 //display_homepage() return true if the hub home page is not displayed 00082 //mostly when search form is not displayed for not logged users 00083 if (empty($continue)) { 00084 exit; 00085 } 00086 } 00087 00088 $PAGE->set_pagetype('site-index'); 00089 $PAGE->set_other_editing_capability('moodle/course:manageactivities'); 00090 $PAGE->set_docs_path(''); 00091 $PAGE->set_pagelayout('frontpage'); 00092 $editing = $PAGE->user_is_editing(); 00093 $PAGE->set_title($SITE->fullname); 00094 $PAGE->set_heading($SITE->fullname); 00095 echo $OUTPUT->header(); 00096 00098 if (!empty($CFG->customfrontpageinclude)) { 00099 include($CFG->customfrontpageinclude); 00100 00101 } else if ($SITE->numsections > 0) { 00102 00103 if (!$section = $DB->get_record('course_sections', array('course'=>$SITE->id, 'section'=>1))) { 00104 $DB->delete_records('course_sections', array('course'=>$SITE->id, 'section'=>1)); // Just in case 00105 $section->course = $SITE->id; 00106 $section->section = 1; 00107 $section->summary = ''; 00108 $section->summaryformat = FORMAT_HTML; 00109 $section->sequence = ''; 00110 $section->visible = 1; 00111 $section->id = $DB->insert_record('course_sections', $section); 00112 } 00113 00114 if (!empty($section->sequence) or !empty($section->summary) or $editing) { 00115 echo $OUTPUT->box_start('generalbox sitetopic'); 00116 00118 if (ismoving($SITE->id)) { 00119 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname)); 00120 echo '<p><font size="2">'; 00121 echo "$stractivityclipboard (<a href=\"course/mod.php?cancelcopy=true&sesskey=".sesskey()."\">". get_string('cancel') .'</a>)'; 00122 echo '</font></p>'; 00123 } 00124 00125 $context = get_context_instance(CONTEXT_COURSE, SITEID); 00126 $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id); 00127 $summaryformatoptions = new stdClass(); 00128 $summaryformatoptions->noclean = true; 00129 $summaryformatoptions->overflowdiv = true; 00130 00131 echo format_text($summarytext, $section->summaryformat, $summaryformatoptions); 00132 00133 if ($editing) { 00134 $streditsummary = get_string('editsummary'); 00135 echo "<a title=\"$streditsummary\" ". 00136 " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" ". 00137 " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />"; 00138 } 00139 00140 get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused); 00141 print_section($SITE, $section, $mods, $modnamesused, true); 00142 00143 if ($editing) { 00144 print_section_add_menus($SITE, $section->section, $modnames); 00145 } 00146 echo $OUTPUT->box_end(); 00147 } 00148 } 00149 00150 if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) { 00151 $frontpagelayout = $CFG->frontpageloggedin; 00152 } else { 00153 $frontpagelayout = $CFG->frontpage; 00154 } 00155 00156 foreach (explode(',',$frontpagelayout) as $v) { 00157 switch ($v) { 00158 case FRONTPAGENEWS: 00159 if ($SITE->newsitems) { // Print forums only when needed 00160 require_once($CFG->dirroot .'/mod/forum/lib.php'); 00161 00162 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) { 00163 print_error('cannotfindorcreateforum', 'forum'); 00164 } 00165 00166 // fetch news forum context for proper filtering to happen 00167 $newsforumcm = get_coursemodule_from_instance('forum', $newsforum->id, $SITE->id, false, MUST_EXIST); 00168 $newsforumcontext = get_context_instance(CONTEXT_MODULE, $newsforumcm->id, MUST_EXIST); 00169 00170 $forumname = format_string($newsforum->name, true, array('context' => $newsforumcontext)); 00171 echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(strip_tags($forumname))), array('href'=>'#skipsitenews', 'class'=>'skip-block')); 00172 00173 if (isloggedin()) { 00174 $SESSION->fromdiscussion = $CFG->wwwroot; 00175 $subtext = ''; 00176 if (forum_is_subscribed($USER->id, $newsforum)) { 00177 if (!forum_is_forcesubscribed($newsforum)) { 00178 $subtext = get_string('unsubscribe', 'forum'); 00179 } 00180 } else { 00181 $subtext = get_string('subscribe', 'forum'); 00182 } 00183 echo $OUTPUT->heading($forumname, 2, 'headingblock header'); 00184 $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey())); 00185 echo html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink')); 00186 } else { 00187 echo $OUTPUT->heading($forumname, 2, 'headingblock header'); 00188 } 00189 00190 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC'); 00191 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipsitenews')); 00192 } 00193 break; 00194 00195 case FRONTPAGECOURSELIST: 00196 if (isloggedin() and !$hassiteconfig and !isguestuser() and empty($CFG->disablemycourses)) { 00197 echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('mycourses'))), array('href'=>'#skipmycourses', 'class'=>'skip-block')); 00198 echo $OUTPUT->heading(get_string('mycourses'), 2, 'headingblock header'); 00199 print_my_moodle(); 00200 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipmycourses')); 00201 } else if ((!$hassiteconfig and !isguestuser()) or ($DB->count_records('course') <= FRONTPAGECOURSELIMIT)) { 00202 // admin should not see list of courses when there are too many of them 00203 echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('availablecourses'))), array('href'=>'#skipavailablecourses', 'class'=>'skip-block')); 00204 echo $OUTPUT->heading(get_string('availablecourses'), 2, 'headingblock header'); 00205 print_courses(0); 00206 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipavailablecourses')); 00207 } 00208 break; 00209 00210 case FRONTPAGECATEGORYNAMES: 00211 echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('categories'))), array('href'=>'#skipcategories', 'class'=>'skip-block')); 00212 echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header'); 00213 echo $OUTPUT->box_start('generalbox categorybox'); 00214 print_whole_category_list(NULL, NULL, NULL, -1, false); 00215 echo $OUTPUT->box_end(); 00216 print_course_search('', false, 'short'); 00217 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipcategories')); 00218 break; 00219 00220 case FRONTPAGECATEGORYCOMBO: 00221 echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('courses'))), array('href'=>'#skipcourses', 'class'=>'skip-block')); 00222 echo $OUTPUT->heading(get_string('courses'), 2, 'headingblock header'); 00223 $renderer = $PAGE->get_renderer('core','course'); 00224 // if there are too many courses, budiling course category tree could be slow, 00225 // users should go to course index page to see the whole list. 00226 $coursecount = $DB->count_records('course'); 00227 if (empty($CFG->numcoursesincombo)) { 00228 // if $CFG->numcoursesincombo hasn't been set, use default value 500 00229 $CFG->numcoursesincombo = 500; 00230 } 00231 if ($coursecount > $CFG->numcoursesincombo) { 00232 $link = new moodle_url('/course/'); 00233 echo $OUTPUT->notification(get_string('maxnumcoursesincombo', 'moodle', array('link'=>$link->out(), 'maxnumofcourses'=>$CFG->numcoursesincombo, 'numberofcourses'=>$coursecount))); 00234 } else { 00235 echo $renderer->course_category_tree(get_course_category_tree()); 00236 } 00237 print_course_search('', false, 'short'); 00238 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipcourses')); 00239 break; 00240 00241 case FRONTPAGETOPICONLY: // Do nothing!! :-) 00242 break; 00243 00244 } 00245 echo '<br />'; 00246 } 00247 00248 echo $OUTPUT->footer();