|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // Display the course home page. 00004 00005 require_once('../config.php'); 00006 require_once('lib.php'); 00007 require_once($CFG->dirroot.'/mod/forum/lib.php'); 00008 require_once($CFG->libdir.'/completionlib.php'); 00009 00010 $id = optional_param('id', 0, PARAM_INT); 00011 $name = optional_param('name', '', PARAM_RAW); 00012 $edit = optional_param('edit', -1, PARAM_BOOL); 00013 $hide = optional_param('hide', 0, PARAM_INT); 00014 $show = optional_param('show', 0, PARAM_INT); 00015 $idnumber = optional_param('idnumber', '', PARAM_RAW); 00016 $section = optional_param('section', 0, PARAM_INT); 00017 $move = optional_param('move', 0, PARAM_INT); 00018 $marker = optional_param('marker',-1 , PARAM_INT); 00019 $switchrole = optional_param('switchrole',-1, PARAM_INT); 00020 00021 if (empty($id) && empty($name) && empty($idnumber)) { 00022 print_error('unspecifycourseid', 'error'); 00023 } 00024 00025 if (!empty($name)) { 00026 if (! ($course = $DB->get_record('course', array('shortname'=>$name)))) { 00027 print_error('invalidcoursenameshort', 'error'); 00028 } 00029 } else if (!empty($idnumber)) { 00030 if (! ($course = $DB->get_record('course', array('idnumber'=>$idnumber)))) { 00031 print_error('invalidcourseid', 'error'); 00032 } 00033 } else { 00034 if (! ($course = $DB->get_record('course', array('id'=>$id)))) { 00035 print_error('invalidcourseid', 'error'); 00036 } 00037 } 00038 00039 $PAGE->set_url('/course/view.php', array('id' => $course->id)); // Defined here to avoid notices on errors etc 00040 00041 preload_course_contexts($course->id); 00042 if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) { 00043 print_error('nocontext'); 00044 } 00045 00046 // Remove any switched roles before checking login 00047 if ($switchrole == 0 && confirm_sesskey()) { 00048 role_switch($switchrole, $context); 00049 } 00050 00051 require_login($course); 00052 00053 // Switchrole - sanity check in cost-order... 00054 $reset_user_allowed_editing = false; 00055 if ($switchrole > 0 && confirm_sesskey() && 00056 has_capability('moodle/role:switchroles', $context)) { 00057 // is this role assignable in this context? 00058 // inquiring minds want to know... 00059 $aroles = get_switchable_roles($context); 00060 if (is_array($aroles) && isset($aroles[$switchrole])) { 00061 role_switch($switchrole, $context); 00062 // Double check that this role is allowed here 00063 require_login($course->id); 00064 } 00065 // reset course page state - this prevents some weird problems ;-) 00066 $USER->activitycopy = false; 00067 $USER->activitycopycourse = NULL; 00068 unset($USER->activitycopyname); 00069 unset($SESSION->modform); 00070 $USER->editing = 0; 00071 $reset_user_allowed_editing = true; 00072 } 00073 00074 //If course is hosted on an external server, redirect to corresponding 00075 //url with appropriate authentication attached as parameter 00076 if (file_exists($CFG->dirroot .'/course/externservercourse.php')) { 00077 include $CFG->dirroot .'/course/externservercourse.php'; 00078 if (function_exists('extern_server_course')) { 00079 if ($extern_url = extern_server_course($course)) { 00080 redirect($extern_url); 00081 } 00082 } 00083 } 00084 00085 00086 require_once($CFG->dirroot.'/calendar/lib.php'); 00087 00088 add_to_log($course->id, 'course', 'view', "view.php?id=$course->id", "$course->id"); 00089 00090 $course->format = clean_param($course->format, PARAM_ALPHA); 00091 if (!file_exists($CFG->dirroot.'/course/format/'.$course->format.'/format.php')) { 00092 $course->format = 'weeks'; // Default format is weeks 00093 } 00094 00095 $PAGE->set_pagelayout('course'); 00096 $PAGE->set_pagetype('course-view-' . $course->format); 00097 $PAGE->set_other_editing_capability('moodle/course:manageactivities'); 00098 00099 if ($reset_user_allowed_editing) { 00100 // ugly hack 00101 unset($PAGE->_user_allowed_editing); 00102 } 00103 00104 if (!isset($USER->editing)) { 00105 $USER->editing = 0; 00106 } 00107 if ($PAGE->user_allowed_editing()) { 00108 if (($edit == 1) and confirm_sesskey()) { 00109 $USER->editing = 1; 00110 // Redirect to site root if Editing is toggled on frontpage 00111 if ($course->id == SITEID) { 00112 redirect($CFG->wwwroot .'/?redirect=0'); 00113 } else { 00114 redirect($PAGE->url); 00115 } 00116 } else if (($edit == 0) and confirm_sesskey()) { 00117 $USER->editing = 0; 00118 if(!empty($USER->activitycopy) && $USER->activitycopycourse == $course->id) { 00119 $USER->activitycopy = false; 00120 $USER->activitycopycourse = NULL; 00121 } 00122 // Redirect to site root if Editing is toggled on frontpage 00123 if ($course->id == SITEID) { 00124 redirect($CFG->wwwroot .'/?redirect=0'); 00125 } else { 00126 redirect($PAGE->url); 00127 } 00128 } 00129 00130 if (has_capability('moodle/course:update', $context)) { 00131 if ($hide && confirm_sesskey()) { 00132 set_section_visible($course->id, $hide, '0'); 00133 } 00134 00135 if ($show && confirm_sesskey()) { 00136 set_section_visible($course->id, $show, '1'); 00137 } 00138 00139 if (!empty($section)) { 00140 if (!empty($move) and confirm_sesskey()) { 00141 if (!move_section($course, $section, $move)) { 00142 echo $OUTPUT->notification('An error occurred while moving a section'); 00143 } 00144 // Clear the navigation cache at this point so that the affects 00145 // are seen immediately on the navigation. 00146 $PAGE->navigation->clear_cache(); 00147 } 00148 } 00149 } 00150 } else { 00151 $USER->editing = 0; 00152 } 00153 00154 $SESSION->fromdiscussion = $CFG->wwwroot .'/course/view.php?id='. $course->id; 00155 00156 00157 if ($course->id == SITEID) { 00158 // This course is not a real course. 00159 redirect($CFG->wwwroot .'/'); 00160 } 00161 00162 // AJAX-capable course format? 00163 $useajax = false; 00164 $formatajax = course_format_ajax_support($course->format); 00165 00166 if (!empty($CFG->enablecourseajax) 00167 and $formatajax->capable 00168 and !empty($USER->editing) 00169 and ajaxenabled($formatajax->testedbrowsers) 00170 and $PAGE->theme->enablecourseajax 00171 and has_capability('moodle/course:manageactivities', $context)) { 00172 $PAGE->requires->yui2_lib('dragdrop'); 00173 $PAGE->requires->yui2_lib('connection'); 00174 $PAGE->requires->yui2_lib('selector'); 00175 $PAGE->requires->js('/lib/ajax/block_classes.js', true); 00176 $PAGE->requires->js('/lib/ajax/section_classes.js', true); 00177 00178 // Okay, global variable alert. VERY UGLY. We need to create 00179 // this object here before the <blockname>_print_block() 00180 // function is called, since that function needs to set some 00181 // stuff in the javascriptportal object. 00182 $COURSE->javascriptportal = new jsportal(); 00183 $useajax = true; 00184 } 00185 00186 $CFG->blocksdrag = $useajax; // this will add a new class to the header so we can style differently 00187 00188 $completion = new completion_info($course); 00189 if ($completion->is_enabled() && ajaxenabled()) { 00190 $PAGE->requires->string_for_js('completion-title-manual-y', 'completion'); 00191 $PAGE->requires->string_for_js('completion-title-manual-n', 'completion'); 00192 $PAGE->requires->string_for_js('completion-alt-manual-y', 'completion'); 00193 $PAGE->requires->string_for_js('completion-alt-manual-n', 'completion'); 00194 00195 $PAGE->requires->js_init_call('M.core_completion.init'); 00196 } 00197 00198 // We are currently keeping the button here from 1.x to help new teachers figure out 00199 // what to do, even though the link also appears in the course admin block. It also 00200 // means you can back out of a situation where you removed the admin block. :) 00201 if ($PAGE->user_allowed_editing()) { 00202 $buttons = $OUTPUT->edit_button(new moodle_url('/course/view.php', array('id' => $course->id))); 00203 $PAGE->set_button($buttons); 00204 } 00205 00206 $PAGE->set_title(get_string('course') . ': ' . $course->fullname); 00207 $PAGE->set_heading($course->fullname); 00208 echo $OUTPUT->header(); 00209 00210 if ($completion->is_enabled() && ajaxenabled()) { 00211 // This value tracks whether there has been a dynamic change to the page. 00212 // It is used so that if a user does this - (a) set some tickmarks, (b) 00213 // go to another page, (c) clicks Back button - the page will 00214 // automatically reload. Otherwise it would start with the wrong tick 00215 // values. 00216 echo html_writer::start_tag('form', array('action'=>'.', 'method'=>'get')); 00217 echo html_writer::start_tag('div'); 00218 echo html_writer::empty_tag('input', array('type'=>'hidden', 'id'=>'completion_dynamic_change', 'name'=>'completion_dynamic_change', 'value'=>'0')); 00219 echo html_writer::end_tag('div'); 00220 echo html_writer::end_tag('form'); 00221 } 00222 00223 // Course wrapper start. 00224 echo html_writer::start_tag('div', array('class'=>'course-content')); 00225 00226 $modinfo =& get_fast_modinfo($COURSE); 00227 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); 00228 foreach($mods as $modid=>$unused) { 00229 if (!isset($modinfo->cms[$modid])) { 00230 rebuild_course_cache($course->id); 00231 $modinfo =& get_fast_modinfo($COURSE); 00232 debugging('Rebuilding course cache', DEBUG_DEVELOPER); 00233 break; 00234 } 00235 } 00236 00237 if (! $sections = get_all_sections($course->id)) { // No sections found 00238 // Double-check to be extra sure 00239 if (! $section = $DB->get_record('course_sections', array('course'=>$course->id, 'section'=>0))) { 00240 $section->course = $course->id; // Create a default section. 00241 $section->section = 0; 00242 $section->visible = 1; 00243 $section->summaryformat = FORMAT_HTML; 00244 $section->id = $DB->insert_record('course_sections', $section); 00245 } 00246 if (! $sections = get_all_sections($course->id) ) { // Try again 00247 print_error('cannotcreateorfindstructs', 'error'); 00248 } 00249 } 00250 00251 // Include the actual course format. 00252 require($CFG->dirroot .'/course/format/'. $course->format .'/format.php'); 00253 // Content wrapper end. 00254 00255 echo html_writer::end_tag('div'); 00256 00257 // Use AJAX? 00258 if ($useajax && has_capability('moodle/course:manageactivities', $context)) { 00259 // At the bottom because we want to process sections and activities 00260 // after the relevant html has been generated. We're forced to do this 00261 // because of the way in which lib/ajax/ajaxcourse.js is written. 00262 echo html_writer::script(false, new moodle_url('/lib/ajax/ajaxcourse.js')); 00263 $COURSE->javascriptportal->print_javascript($course->id); 00264 } 00265 00266 00267 echo $OUTPUT->footer(); 00268 00269