format.php 12.9 KB
Newer Older
1
<?php
martin's avatar
martin committed
2
3
      // Display the whole course as "weeks" made of of modules
      // Included from "view.php"
4
5
/**
 * Evaluation weekly format for course display - NO layout tables, for accessibility, etc.
6
7
8
 *
 * A duplicate course format to enable the Moodle development team to evaluate
 * CSS for the multi-column layout in place of layout tables.
9
10
11
12
13
14
 * Less risk for the Moodle 1.6 beta release.
 *   1. Straight copy of weeks/format.php
 *   2. Replace <table> and <td> with DIVs; inline styles.
 *   3. Reorder columns so that in linear view content is first then blocks;
 * styles to maintain original graphical (side by side) view.
 *
15
 * Target: 3-column graphical view using relative widths for pixel screen sizes
16
 * 800x600, 1024x768... on IE6, Firefox. Below 800 columns will shift downwards.
17
 *
18
19
20
21
22
23
 * http://www.maxdesign.com.au/presentation/em/ Ideal length for content.
 * http://www.svendtofte.com/code/max_width_in_ie/ Max width in IE.
 *
 * @copyright &copy; 2006 The Open University
 * @author N.D.Freear@open.ac.uk, and others.
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
24
 * @package
25
 */
martin's avatar
martin committed
26

27
28
defined('MOODLE_INTERNAL') || die();

29
    require_once($CFG->libdir.'/filelib.php');
30

31
32
33
    $week = optional_param('week', -1, PARAM_INT);

    if ($week != -1) {
34
35
36
37
        $displaysection = course_set_display($course->id, $week);
    } else {
        if (isset($USER->display[$course->id])) {
            $displaysection = $USER->display[$course->id];
martin's avatar
martin committed
38
        } else {
39
            $displaysection = course_set_display($course->id, 0);
martin's avatar
martin committed
40
41
42
        }
    }

defacer's avatar
   
defacer committed
43
44
45
46
47
48
49
50
51
    $streditsummary  = get_string('editsummary');
    $stradd          = get_string('add');
    $stractivities   = get_string('activities');
    $strshowallweeks = get_string('showallweeks');
    $strweek         = get_string('week');
    $strgroups       = get_string('groups');
    $strgroupmy      = get_string('groupmy');
    $editing         = $PAGE->user_is_editing();

52
    if ($editing) {
53
54
        $strweekhide = get_string('hideweekfromothers');
        $strweekshow = get_string('showweekfromothers');
moodler's avatar
moodler committed
55
56
        $strmoveup   = get_string('moveup');
        $strmovedown = get_string('movedown');
57
    }
58

toyomoyo's avatar
toyomoyo committed
59
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
60
61
62
63
64

    //Print the Your progress icon if the track completion is enabled
    $completioninfo = new completion_info($course);
    $completioninfo->print_help_icon();

65
    echo $OUTPUT->heading(get_string('weeklyoutline'), 2, 'headingblock header outline');
66

67
    echo "<span id='maincontent'></span>";
68
69
    // Note, an ordered list would confuse - "1" could be the clipboard or summary.
    echo "<ul class='weeks'>\n";
70

71
72
/// If currently moving a file then show the current clipboard
    if (ismoving($course->id)) {
73
        $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
moodler's avatar
moodler committed
74
        $strcancel= get_string('cancel');
75
        echo '<li class="clipboard">';
skodak's avatar
skodak committed
76
        echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
77
        echo "</li>\n";
78
    }
79

80
/// Print Section 0 with general activities
81

82
83
    $section = 0;
    $thissection = $sections[$section];
84
    unset($sections[0]);
85

86
    if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
87
88

        // Note, 'right side' is BEFORE content.
89
        echo '<li id="section-0" class="section main clearfix" >';
90
        echo '<div class="left side">&nbsp;</div>';
91
        echo '<div class="right side" >&nbsp;</div>';
92
        echo '<div class="content">';
93

94
        if (!empty($thissection->name)) {
Petr Skoda's avatar
Petr Skoda committed
95
            echo $OUTPUT->heading($thissection->name, 3, 'sectionname');
96
97
        }

98
        echo '<div class="summary">';
99
100

        $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
101
        $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
102
        $summaryformatoptions = new stdClass;
103
        $summaryformatoptions->noclean = true;
104
        $summaryformatoptions->overflowdiv = true;
105
        echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
106

107
        if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
108
            echo '<p><a title="'.$streditsummary.'" '.
109
                 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$OUTPUT->pix_url('t/edit') . '" '.
110
                 ' class="icon edit" alt="'.$streditsummary.'" /></a></p>';
111
        }
112
        echo '</div>';
113

114
        print_section($course, $thissection, $mods, $modnamesused);
Petr Skoda's avatar
Petr Skoda committed
115

116
        if ($PAGE->user_is_editing()) {
117
            print_section_add_menus($course, $section, $modnames);
118
119
        }

120
121
        echo '</div>';
        echo "</li>\n";
122
123
124
    }


moodler's avatar
moodler committed
125
126
127
/// Now all the normal modules by week
/// Everything below uses "section" terminology - each "section" is a week.

martin's avatar
martin committed
128
129
    $timenow = time();
    $weekdate = $course->startdate;    // this should be 0:00 Monday of that week
skodak's avatar
skodak committed
130
    $weekdate += 7200;                 // Add two hours to avoid possible DST problems
131
    $section = 1;
moodler's avatar
moodler committed
132
    $sectionmenu = array();
skodak's avatar
skodak committed
133
    $weekofseconds = 604800;
134
    $course->enddate = $course->startdate + ($weekofseconds * $course->numsections);
martin's avatar
martin committed
135

moodler's avatar
moodler committed
136
    $strftimedateshort = ' '.get_string('strftimedateshort');
moodler's avatar
   
moodler committed
137

martin's avatar
martin committed
138
    while ($weekdate < $course->enddate) {
martin's avatar
martin committed
139
140

        $nextweekdate = $weekdate + ($weekofseconds);
141
        $weekday = userdate($weekdate, $strftimedateshort);
skodak's avatar
skodak committed
142
        $endweekday = userdate($weekdate+518400, $strftimedateshort);
martin's avatar
martin committed
143

144
145
        if (!empty($sections[$section])) {
            $thissection = $sections[$section];
martin's avatar
martin committed
146

147
148
149
150
        } else {
            unset($thissection);
            $thissection->course = $course->id;   // Create a new week structure
            $thissection->section = $section;
151
            $thissection->name    = null;
moodler's avatar
moodler committed
152
            $thissection->summary = '';
Petr Skoda's avatar
Petr Skoda committed
153
            $thissection->summaryformat = FORMAT_HTML;
154
            $thissection->visible = 1;
155
            $thissection->id = $DB->insert_record('course_sections', $thissection);
156
        }
martin's avatar
martin committed
157

toyomoyo's avatar
toyomoyo committed
158
        $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
martin's avatar
martin committed
159

160
161
        if (!empty($displaysection) and $displaysection != $section) {  // Check this week is visible
            if ($showsection) {
162
                $sectionmenu[$section] = get_section_name($course, $thissection);
163
164
165
166
167
168
            }
            $section++;
            $weekdate = $nextweekdate;
            continue;
        }

169
        if ($showsection) {
martin's avatar
martin committed
170

171
            $currentweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
martin's avatar
martin committed
172

173
            $currenttext = '';
174
            if (!$thissection->visible) {
moodler's avatar
moodler committed
175
                $sectionstyle = ' hidden';
176
            } else if ($currentweek) {
moodler's avatar
moodler committed
177
                $sectionstyle = ' current';
178
                $currenttext = get_accesshide(get_string('currentweek','access'));
179
            } else {
moodler's avatar
moodler committed
180
                $sectionstyle = '';
181
182
            }

183
            echo '<li id="section-'.$section.'" class="section main clearfix'.$sectionstyle.'" >';
urs_hunkler's avatar
urs_hunkler committed
184

185
            echo '<div class="left side">&nbsp;'.$currenttext.'</div>';
186

187
188
            // Note, 'right side' is BEFORE content.
            echo '<div class="right side">';
189

190
            if ($displaysection == $section) {
191
                echo '<a href="view.php?id='.$course->id.'&amp;week=0#section-'.$section.'" title="'.$strshowallweeks.'">'.
192
                     '<img src="'.$OUTPUT->pix_url('i/all') . '" class="icon wkall" alt="'.$strshowallweeks.'" /></a><br />';
193
194
            } else {
                $strshowonlyweek = get_string("showonlyweek", "", $section);
moodler's avatar
moodler committed
195
                echo '<a href="view.php?id='.$course->id.'&amp;week='.$section.'" title="'.$strshowonlyweek.'">'.
196
                     '<img src="'.$OUTPUT->pix_url('i/one') . '" class="icon wkone" alt="'.$strshowonlyweek.'" /></a><br />';
197
            }
urs_hunkler's avatar
urs_hunkler committed
198

199
            if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
200
                if ($thissection->visible) {        // Show the hide/show eye
skodak's avatar
skodak committed
201
                    echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strweekhide.'">'.
202
                         '<img src="'.$OUTPUT->pix_url('i/hide') . '" class="icon hide" alt="'.$strweekhide.'" /></a><br />';
203
                } else {
skodak's avatar
skodak committed
204
                    echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strweekshow.'">'.
205
                         '<img src="'.$OUTPUT->pix_url('i/show') . '" class="icon hide" alt="'.$strweekshow.'" /></a><br />';
206
207
                }
                if ($section > 1) {                       // Add a arrow to move section up
skodak's avatar
skodak committed
208
                    echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.sesskey().'#section-'.($section-1).'" title="'.$strmoveup.'">'.
209
                         '<img src="'.$OUTPUT->pix_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a><br />';
210
                }
urs_hunkler's avatar
urs_hunkler committed
211

212
                if ($section < $course->numsections) {    // Add a arrow to move section down
skodak's avatar
skodak committed
213
                    echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.sesskey().'#section-'.($section+1).'" title="'.$strmovedown.'">'.
214
                         '<img src="'.$OUTPUT->pix_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a><br />';
215
216
217
218
                }
            }
            echo '</div>';

219
220
            $weekperiod = $weekday.' - '.$endweekday;

221
222
            echo '<div class="content">';
            if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) {   // Hidden for students
223
                echo $OUTPUT->heading($currenttext.$weekperiod.' ('.get_string('notavailable').')', 3, 'weekdates');
224
225

            } else {
226
                if (isset($thissection->name) && ($thissection->name !== NULL)) {  // empty string is ok
227
228
229
230
                    echo $OUTPUT->heading($thissection->name, 3, 'weekdates');
                } else {
                    echo $OUTPUT->heading($currenttext.$weekperiod, 3, 'weekdates');
                }
231
                echo '<div class="summary">';
232
                $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
233
                $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
234
                $summaryformatoptions = new stdClass;
235
                $summaryformatoptions->noclean = true;
236
                $summaryformatoptions->overflowdiv = true;
237
                echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
238

239
                if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
240
                    echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
241
                         '<img src="'.$OUTPUT->pix_url('t/edit') . '" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
242
243
244
245
                }
                echo '</div>';

                print_section($course, $thissection, $mods, $modnamesused);
Petr Skoda's avatar
Petr Skoda committed
246

247
                if ($PAGE->user_is_editing()) {
248
                    print_section_add_menus($course, $section, $modnames);
249
                }
250
            }
urs_hunkler's avatar
urs_hunkler committed
251

252
253
            echo '</div>';
            echo "</li>\n";
254
255
        }

256
        unset($sections[$section]);
257
        $section++;
martin's avatar
martin committed
258
259
        $weekdate = $nextweekdate;
    }
260

261
    if (!$displaysection and $PAGE->user_is_editing() and has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
        // print stealth sections if present
        $modinfo = get_fast_modinfo($course);
        foreach ($sections as $section=>$thissection) {
            if (empty($modinfo->sections[$section])) {
                continue;
            }

            echo '<li id="section-'.$section.'" class="section main clearfix stealth hidden">'; //'<div class="left side">&nbsp;</div>';

            echo '<div class="left side">';
            echo '</div>';
            // Note, 'right side' is BEFORE content.
            echo '<div class="right side">';
            echo '</div>';
            echo '<div class="content">';
277
            echo $OUTPUT->heading(get_string('orphanedactivities'), 3, 'sectionname');
278
279
280
281
282
283
            print_section($course, $thissection, $mods, $modnamesused);
            echo '</div>';
            echo "</li>\n";
        }
    }

284
    echo "</ul>\n";
moodler's avatar
moodler committed
285
286

    if (!empty($sectionmenu)) {
287
288
289
290
291
        $select = new single_select(new moodle_url('/course/view.php', array('id'=>$course->id)), 'week', $sectionmenu);
        $select->label = get_string('jumpto');
        $select->class = 'jumpmenu';
        $select->formid = 'sectionmenu';
        echo $OUTPUT->render($select);
moodler's avatar
moodler committed
292
    }