~ubuntu-branches/ubuntu/jaunty/moodle/jaunty

« back to all changes in this revision

Viewing changes to course/view.php

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha, Matt Oquist
  • Date: 2009-02-25 15:16:22 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225151622-0ekt1liwhv2obfza
Tags: 1.9.4.dfsg-0ubuntu1
* Merge with Debian git (Closes LP: #322961, #239481, #334611):
  - use Ubuntu's smarty lib directory for linking
  - use internal yui library 
  - add update-notifier support back in

[Matt Oquist]
  * renamed prerm script
  * significantly rewrote postinst and other maintainer scripts to improve
    user experience and package maintainability
    (Closes LP: #225662, #325450, #327843, #303078, #234609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php // $Id: view.php,v 1.102.2.2 2007/04/17 09:24:26 moodler Exp $
 
1
<?php // $Id: view.php,v 1.106.2.5 2008/12/17 12:40:09 sam_marshall Exp $
2
2
 
3
3
//  Display the course home page.
4
4
 
39
39
        }
40
40
    }
41
41
 
 
42
    preload_course_contexts($course->id);
42
43
    if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) {
43
44
        print_error('nocontext');
44
45
    }
45
46
 
46
 
    if ($switchrole == 0) {  // Remove any switched roles before checking login
 
47
    // Remove any switched roles before checking login
 
48
    if ($switchrole == 0 && confirm_sesskey()) {
47
49
        role_switch($switchrole, $context);
48
50
    }
49
51
 
50
 
    require_login($course->id);
 
52
    require_login($course);
51
53
 
52
 
    if ($switchrole > 0) {
53
 
        role_switch($switchrole, $context);
54
 
        require_login($course->id);   // Double check that this role is allowed here
 
54
    // Switchrole - sanity check in cost-order...
 
55
    $reset_user_allowed_editing = false;
 
56
    if ($switchrole > 0 && confirm_sesskey() &&
 
57
        has_capability('moodle/role:switchroles', $context)) {
 
58
        // is this role assignable in this context?
 
59
        // inquiring minds want to know...
 
60
        $aroles = get_assignable_roles($context);
 
61
        if (is_array($aroles) && isset($aroles[$switchrole])) {
 
62
            role_switch($switchrole, $context);
 
63
            // Double check that this role is allowed here
 
64
            require_login($course->id);
 
65
        }
 
66
        // reset course page state - this prevents some weird problems ;-)
 
67
        $USER->activitycopy = false;
 
68
        $USER->activitycopycourse = NULL;
 
69
        unset($USER->activitycopyname);
 
70
        unset($SESSION->modform);
 
71
        $USER->editing = 0;
 
72
        $reset_user_allowed_editing = true;
55
73
    }
56
74
 
57
75
    //If course is hosted on an external server, redirect to corresponding
78
96
    $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id);
79
97
    $pageblocks = blocks_setup($PAGE, BLOCKS_PINNED_BOTH);
80
98
 
 
99
    if ($reset_user_allowed_editing) {
 
100
        // ugly hack
 
101
        unset($PAGE->_user_allowed_editing);
 
102
    }
81
103
 
82
104
    if (!isset($USER->editing)) {
83
105
        $USER->editing = 0;
122
144
 
123
145
 
124
146
    // AJAX-capable course format?
125
 
    $CFG->useajax = false; 
 
147
    $useajax = false; 
126
148
    $ajaxformatfile = $CFG->dirroot.'/course/format/'.$course->format.'/ajax.php';
127
149
    $bodytags = '';
128
150
 
129
 
    if (file_exists($ajaxformatfile)) {      // Needs to exist otherwise no AJAX by default
 
151
    if (empty($CFG->disablecourseajax) and file_exists($ajaxformatfile)) {      // Needs to exist otherwise no AJAX by default
130
152
 
 
153
        // TODO: stop abusing CFG global here
131
154
        $CFG->ajaxcapable = false;           // May be overridden later by ajaxformatfile
132
155
        $CFG->ajaxtestedbrowsers = array();  // May be overridden later by ajaxformatfile
133
156
 
134
157
        require_once($ajaxformatfile);
135
158
 
136
 
        if (!empty($USER->editing) && $CFG->ajaxcapable) {   // Course-based switches
 
159
        if (!empty($USER->editing) && $CFG->ajaxcapable && has_capability('moodle/course:manageactivities', $context)) {
 
160
                                                             // Course-based switches
137
161
 
138
 
            if (ajaxenabled($CFG->ajaxtestedbrowsers)) {     // rowser, user and site-based switches
 
162
            if (ajaxenabled($CFG->ajaxtestedbrowsers)) {     // Browser, user and site-based switches
139
163
                
140
164
                require_js(array('yui_yahoo',
141
165
                                 'yui_dom',
163
187
                // function is called, since that function needs to set some
164
188
                // stuff in the javascriptportal object.
165
189
                $COURSE->javascriptportal = new jsportal();
166
 
                $CFG->useajax = true;
 
190
                $useajax = true;
167
191
            }
168
192
        }
169
193
    }
170
194
 
171
 
    $CFG->blocksdrag = $CFG->useajax;   // this will add a new class to the header so we can style differently
 
195
    $CFG->blocksdrag = $useajax;   // this will add a new class to the header so we can style differently
172
196
 
173
197
 
174
198
    $PAGE->print_header(get_string('course').': %fullname%', NULL, '', $bodytags);
175
199
    // Course wrapper start.
176
200
    echo '<div class="course-content">';
177
201
 
178
 
 
 
202
    $modinfo =& get_fast_modinfo($COURSE);
179
203
    get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
 
204
    foreach($mods as $modid=>$unused) {
 
205
        if (!isset($modinfo->cms[$modid])) {
 
206
            rebuild_course_cache($course->id);
 
207
            $modinfo =& get_fast_modinfo($COURSE);
 
208
            debugging('Rebuilding course cache', DEBUG_DEVELOPER);
 
209
            break;
 
210
        }
 
211
    }
180
212
 
181
213
    if (! $sections = get_all_sections($course->id)) {   // No sections found
182
214
        // Double-check to be extra sure
191
223
        }
192
224
    }
193
225
 
194
 
 
195
 
    if (empty($course->modinfo)) {
196
 
        // Course cache was never made.
197
 
        rebuild_course_cache($course->id);
198
 
        if (! $course = get_record('course', 'id', $course->id) ) {
199
 
            error("That's an invalid course id");
200
 
        }
201
 
    }
202
 
 
203
 
 
204
226
    // Include the actual course format.
205
227
    require($CFG->dirroot .'/course/format/'. $course->format .'/format.php');
206
228
    // Content wrapper end.
208
230
 
209
231
 
210
232
    // Use AJAX?
211
 
    if ($CFG->useajax) {
 
233
    if ($useajax && has_capability('moodle/course:manageactivities', $context)) {
212
234
        // At the bottom because we want to process sections and activities
213
235
        // after the relevant html has been generated. We're forced to do this
214
236
        // because of the way in which lib/ajax/ajaxcourse.js is written.