format.php 11.8 KB
Newer Older
gustav_delius's avatar
gustav_delius committed
1
<?php // $Id$
2
3
4
      // Display the whole course as "topics" made of of modules
      // In fact, this is very similar to the "weeks" format, in that
      // each "topic" is actually a week.  The main difference is that
5
      // the dates aren't printed - it's just an aesthetic thing for
6
7
      // courses that aren't so rigidly defined by time.
      // Included from "view.php"
moodler's avatar
moodler committed
8
      
9

10
    require_once($CFG->dirroot.'/mod/forum/lib.php');
moodler's avatar
moodler committed
11
12
13
    require_once($CFG->libdir.'/ajax/ajaxlib.php');
  
    
14
15
    $topic = optional_param('topic', -1, PARAM_INT);

moodler's avatar
moodler committed
16
    
17
18
19
20
21
22
    // Bounds for block widths
    define('BLOCK_L_MIN_WIDTH', 100);
    define('BLOCK_L_MAX_WIDTH', 210);
    define('BLOCK_R_MIN_WIDTH', 100);
    define('BLOCK_R_MAX_WIDTH', 210);

23
24
25
26
    $preferred_width_left  = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),  
                                            BLOCK_L_MAX_WIDTH);
    $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 
                                            BLOCK_R_MAX_WIDTH);
27

28
    if ($topic != -1) {
29
30
31
32
        $displaysection = course_set_display($course->id, $topic);
    } else {
        if (isset($USER->display[$course->id])) {       // for admins, mostly
            $displaysection = $USER->display[$course->id];
33
        } else {
34
            $displaysection = course_set_display($course->id, 0);
35
36
37
        }
    }

toyomoyo's avatar
toyomoyo committed
38
39
40
    $context = get_context_instance(CONTEXT_COURSE, $course->id);

    if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
41
42
43
44
45
46
        $course->marker = $marker;
        if (! set_field("course", "marker", $marker, "id", $course->id)) {
            error("Could not mark that topic for this course");
        }
    }

defacer's avatar
   
defacer committed
47
48
49
50
51
52
53
54
55
    $streditsummary   = get_string('editsummary');
    $stradd           = get_string('add');
    $stractivities    = get_string('activities');
    $strshowalltopics = get_string('showalltopics');
    $strtopic         = get_string('topic');
    $strgroups        = get_string('groups');
    $strgroupmy       = get_string('groupmy');
    $editing          = $PAGE->user_is_editing();

56
    if ($editing) {
57
        $strstudents = moodle_strtolower($course->students);
58
59
60
61
62
63
        $strtopichide = get_string('topichide', '', $strstudents);
        $strtopicshow = get_string('topicshow', '', $strstudents);
        $strmarkthistopic = get_string('markthistopic');
        $strmarkedthistopic = get_string('markedthistopic');
        $strmoveup = get_string('moveup');
        $strmovedown = get_string('movedown');
64
    }
65

66

67
/// Layout the whole page as three big columns.
moodler's avatar
moodler committed
68
    echo '<table id="layout-table" cellspacing="0"><tr>';
69

70
/// The left column ...
71
72
73
74
75
76
// uh-changes start
    $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
    foreach ($lt as $column) {
        switch ($column) {
            case 'left':
// uh-changes end
moodler's avatar
   
moodler committed
77

defacer's avatar
   
defacer committed
78
    if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
moodler's avatar
moodler committed
79
        echo '<td style="width:'.$preferred_width_left.'px" id="left-column">';
defacer's avatar
   
defacer committed
80
        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
81
        echo '</td>';
82
    }
83

84
85
86
87
// uh-changes start
            break;
            case 'middle':
// uh-changes end
88
/// Start main column
89
    echo '<td id="middle-column"><a name="startofcontent"></a>';
90

defacer's avatar
   
defacer committed
91
    print_heading_block(get_string('topicoutline'), 'outline');
92

93
    echo '<table class="topics" width="100%">';
94

95
96
/// If currently moving a file then show the current clipboard
    if (ismoving($course->id)) {
97
98
        $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
        $strcancel= get_string('cancel');
99
100
        echo '<tr class="clipboard">';
        echo '<td colspan="3">';
101
102
103
        echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.$USER->sesskey.'">'.$strcancel.'</a>)';
        echo '</td>';
        echo '</tr>';
104
105
    }

106
/// Print Section 0
107

108
109
    $section = 0;
    $thissection = $sections[$section];
110

111
    if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
moodler's avatar
moodler committed
112
        echo '<tr id="section-0" class="section main">';
113
114
        echo '<td class="left side">&nbsp;</td>';
        echo '<td class="content">';
115
116
        
        echo '<div class="summary">';
117
118
        $summaryformatoptions->noclean = true;
        echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
119

120
        if (isediting($course->id)) {
121
122
            echo '<a title="'.$streditsummary.'" '.
                 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
moodler's avatar
moodler committed
123
                 ' alt="'.$streditsummary.'" /></a><br /><br />';
124
        }
125
        echo '</div>';
126

127
        print_section($course, $thissection, $mods, $modnamesused);
128

129
        if (isediting($course->id)) {
130
            print_section_add_menus($course, $section, $modnames);
131
        }
132

133
        echo '</td>';
134
        echo '<td class="right side">&nbsp;</td>';
135
        echo '</tr>';
moodler's avatar
moodler committed
136
        echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
137
138
139
140
141
142
143
144
    }


/// Now all the normal modules by topic
/// Everything below uses "section" terminology - each "section" is a topic.

    $timenow = time();
    $section = 1;
moodler's avatar
moodler committed
145
    $sectionmenu = array();
146

147
    while ($section <= $course->numsections) {
148

moodler's avatar
moodler committed
149
150
151
152
153
154
155
        if (!empty($sections[$section])) {
            $thissection = $sections[$section];

        } else {
            unset($thissection);
            $thissection->course = $course->id;   // Create a new section structure
            $thissection->section = $section;
156
            $thissection->summary = '';
moodler's avatar
moodler committed
157
            $thissection->visible = 1;
158
159
            if (!$thissection->id = insert_record('course_sections', $thissection)) {
                notify('Error inserting new topic!');
moodler's avatar
moodler committed
160
161
162
            }
        }

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

165
166
        if (!empty($displaysection) and $displaysection != $section) {
            if ($showsection) {
167
                $strsummary = strip_tags(format_string($thissection->summary,true));
168
169
170
171
172
173
174
175
176
177
178
                if (strlen($strsummary) < 57) {
                    $strsummary = ' - '.$strsummary;
                } else {
                    $strsummary = ' - '.substr($strsummary, 0, 60).'...';
                }
                $sectionmenu['topic='.$section] = s($section.$strsummary);
            }
            $section++;
            continue;
        }

179
180
181
182
183
        if ($showsection) {

            $currenttopic = ($course->marker == $section);

            if (!$thissection->visible) {
184
                $sectionstyle = ' hidden';
185
            } else if ($currenttopic) {
186
                $sectionstyle = ' current';
187
            } else {
188
                $sectionstyle = '';
189
            }
190

moodler's avatar
moodler committed
191
            echo '<tr id="section-'.$section.'" class="section main'.$sectionstyle.'">';
192
            echo '<td class="left side">'.$section.'</td>';
193

194
            echo '<td class="content">';
toyomoyo's avatar
toyomoyo committed
195
            if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) {   // Hidden for students
196
                echo get_string('notavailable');
197
            } else {
198
                echo '<div class="summary">';
199
200
                $summaryformatoptions->noclean = true;
                echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
201

202
                if (isediting($course->id)) {
moodler's avatar
moodler committed
203
                    echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
moodler's avatar
moodler committed
204
                         '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$streditsummary.'" /></a><br /><br />';
205
                }
206
                echo '</div>';
207

208
                print_section($course, $thissection, $mods, $modnamesused);
moodler's avatar
moodler committed
209

210
                if (isediting($course->id)) {
211
                    print_section_add_menus($course, $section, $modnames);
212
                }
moodler's avatar
moodler committed
213
            }
214
            echo '</td>';
215

216
            echo '<td class="right side">';
217
            if ($displaysection == $section) {      // Show the zoom boxes
218
                echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
moodler's avatar
moodler committed
219
                     '<img src="'.$CFG->pixpath.'/i/all.gif" alt="'.$strshowalltopics.'" /></a><br />';
moodler's avatar
moodler committed
220
            } else {
221
222
                $strshowonlytopic = get_string('showonlytopic', '', $section);
                echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section.'" title="'.$strshowonlytopic.'">'.
moodler's avatar
moodler committed
223
                     '<img src="'.$CFG->pixpath.'/i/one.gif" alt="'.$strshowonlytopic.'" /></a><br />';
224
225
            }

226
227
            if (isediting($course->id)) {
                if ($course->marker == $section) {  // Show the "light globe" on/off
defacer's avatar
   
defacer committed
228
                    echo '<a href="view.php?id='.$course->id.'&amp;marker=0&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.
moodler's avatar
moodler committed
229
                         '<img src="'.$CFG->pixpath.'/i/marked.gif" alt="'.$strmarkedthistopic.'" /></a><br />';
230
                } else {
defacer's avatar
   
defacer committed
231
                    echo '<a href="view.php?id='.$course->id.'&amp;marker='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkthistopic.'">'.
moodler's avatar
moodler committed
232
                         '<img src="'.$CFG->pixpath.'/i/marker.gif" alt="'.$strmarkthistopic.'" /></a><br />';
233
234
235
                }

                if ($thissection->visible) {        // Show the hide/show eye
defacer's avatar
   
defacer committed
236
                    echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strtopichide.'">'.
moodler's avatar
moodler committed
237
                         '<img src="'.$CFG->pixpath.'/i/hide.gif" alt="'.$strtopichide.'" /></a><br />';
238
                } else {
239
                    echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strtopicshow.'">'.
moodler's avatar
moodler committed
240
                         '<img src="'.$CFG->pixpath.'/i/show.gif" alt="'.$strtopicshow.'" /></a><br />';
241
242
243
                }

                if ($section > 1) {                       // Add a arrow to move section up
244
                    echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.$USER->sesskey.'#section-'.($section-1).'" title="'.$strmoveup.'">'.
moodler's avatar
moodler committed
245
                         '<img src="'.$CFG->pixpath.'/t/up.gif" alt="'.$strmoveup.'" /></a><br />';
246
247
248
                }

                if ($section < $course->numsections) {    // Add a arrow to move section down
249
                    echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.$USER->sesskey.'#section-'.($section+1).'" title="'.$strmovedown.'">'.
moodler's avatar
moodler committed
250
                         '<img src="'.$CFG->pixpath.'/t/down.gif" alt="'.$strmovedown.'" /></a><br />';
251
                }
252

moodler's avatar
moodler committed
253
            }
254

255
            echo '</td></tr>';
moodler's avatar
moodler committed
256
            echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
257
        }
moodler's avatar
moodler committed
258

259
        $section++;
260
    }
261
    echo '</table>';
moodler's avatar
moodler committed
262
263

    if (!empty($sectionmenu)) {
264
        echo '<div align="center" class="jumpmenu">';
265
        echo popup_form($CFG->wwwroot.'/course/view.php?id='.$course->id.'&amp;', $sectionmenu,
266
267
                   'sectionmenu', '', get_string('jumpto'), '', '', true);
        echo '</div>';
moodler's avatar
moodler committed
268
    }
269

270

271
    echo '</td>';
272

273
274
275
276
// uh-changes start
            break;
            case 'right':
// uh-changes end
277
    // The right column
defacer's avatar
   
defacer committed
278
    if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) {
moodler's avatar
moodler committed
279
        echo '<td style="width:'.$preferred_width_right.'px" id="right-column">';
defacer's avatar
   
defacer committed
280
        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
281
        echo '</td>';
282
283
    }

284
285
286
287
288
// uh-changes start
            break;
        }
    }
// uh-changes end
289
    echo '</tr></table>';
moodler's avatar
moodler committed
290
    
291
?>