moodle_page: MDL-12212 reimplement user_is_editing, deprecate isediting
[moodle.git] / course / format / topics / format.php
CommitLineData
dcb1bd3c 1<?php // $Id$
0b35af18 2 // Display the whole course as "topics" made of of modules
0b35af18 3 // Included from "view.php"
9f7f1a74 4/**
5 * Evaluation topics format for course display - NO layout tables, for accessibility, etc.
6 *
7 * A duplicate course format to enable the Moodle development team to evaluate
8 * CSS for the multi-column layout in place of layout tables.
9 * Less risk for the Moodle 1.6 beta release.
10 * 1. Straight copy of topics/format.php
11 * 2. Replace <table> and <td> with DIVs; inline styles.
12 * 3. Reorder columns so that in linear view content is first then blocks;
13 * styles to maintain original graphical (side by side) view.
14 *
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 * http://www.maxdesign.com.au/presentation/em/ Ideal length for content.
19 * http://www.svendtofte.com/code/max_width_in_ie/ Max width in IE.
20 *
21 * @copyright &copy; 2006 The Open University
22 * @author N.D.Freear@open.ac.uk, and others.
23 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
24 * @package
25 */
26//TODO (nfreear): Accessibility: evaluation, lang/en_utf8/moodle.php: $string['formattopicscss']
0b35af18 27
a0bfbeaa 28 require_once($CFG->libdir.'/ajax/ajaxlib.php');
644d506a 29 require_once($CFG->libdir.'/filelib.php');
689456eb 30
9f7f1a74 31 $topic = optional_param('topic', -1, PARAM_INT);
0f3fe4b6 32
0cdae0dc 33 if ($topic != -1) {
b86fc0e2 34 $displaysection = course_set_display($course->id, $topic);
35 } else {
9f7f1a74 36 if (isset($USER->display[$course->id])) {
b86fc0e2 37 $displaysection = $USER->display[$course->id];
0b35af18 38 } else {
b86fc0e2 39 $displaysection = course_set_display($course->id, 0);
0b35af18 40 }
41 }
42
3924b988 43 $context = get_context_instance(CONTEXT_COURSE, $course->id);
44
45 if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
9f7f1a74 46 $course->marker = $marker;
f400841b 47 if (! $DB->set_field("course", "marker", $marker, array("id"=>$course->id))) {
1343697c 48 print_error("cannotmarktopic");
9f7f1a74 49 }
0b35af18 50 }
51
9f7f1a74 52 $streditsummary = get_string('editsummary');
53 $stradd = get_string('add');
54 $stractivities = get_string('activities');
a3f24f7c 55 $strshowalltopics = get_string('showalltopics');
56 $strtopic = get_string('topic');
9f7f1a74 57 $strgroups = get_string('groups');
58 $strgroupmy = get_string('groupmy');
59 $editing = $PAGE->user_is_editing();
a3f24f7c 60
0f3fe4b6 61 if ($editing) {
9101efd3 62 $strtopichide = get_string('hidetopicfromothers');
63 $strtopicshow = get_string('showtopicfromothers');
64 $strmarkthistopic = get_string('markthistopic');
65 $strmarkedthistopic = get_string('markedthistopic');
9f7f1a74 66 $strmoveup = get_string('moveup');
c46f27a3 67 $strmovedown = get_string('movedown');
dfec7b01 68 }
d897cae4 69
9f7f1a74 70/* Internet Explorer min-width fix. (See theme/standard/styles_layout.css: min-width for Firefox.)
71 Window width: 800px, Firefox 763px, IE 752px. (Window width: 640px, Firefox 602px, IE 588px.)
72*/
73?>
0b35af18 74
9f7f1a74 75<!--[if IE]>
76 <style type="text/css">
77 .topics-format { width: expression(document.body.clientWidth < 800 ? "752px" : "auto"); }
78 </style>
79<![endif]-->
80<?php
81/// Layout the whole page as three big columns (was, id="layout-table")
82 echo '<div class="topics-format">';
7ff56f2d 83
0f3fe4b6 84/// The left column ...
f374fb10 85
dffd4bb9 86 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
9f7f1a74 87 echo '<div id="left-column">';
88 print_container_start();
262cb5e0 89 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
9f7f1a74 90 print_container_end();
91 echo '</div>';
92 }
93
94/// The right column, BEFORE the middle-column.
95 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) {
96 echo '<div id="right-column">';
97 print_container_start();
98 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
99 print_container_end();
100 echo '</div>';
0b35af18 101 }
f3120024 102
9a223597 103/// Start main column
9f7f1a74 104 echo '<div id="middle-column">';
105 print_container_start();
106
5c355019 107 echo skip_main_destination();
0b35af18 108
446390fb 109 print_heading_block(get_string('topicoutline'), 'outline');
2c0411e2 110
9f7f1a74 111 // Note, an ordered list would confuse - "1" could be the clipboard or summary.
112 echo "<ul class='topics'>\n";
9a223597 113
7977cffd 114/// If currently moving a file then show the current clipboard
115 if (ismoving($course->id)) {
294ce987 116 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
c46f27a3 117 $strcancel= get_string('cancel');
9f7f1a74 118 echo '<li class="clipboard">';
d4a1fcaf 119 echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
9f7f1a74 120 echo "</li>\n";
7977cffd 121 }
122
9f7f1a74 123/// Print Section 0 with general activities
9a223597 124
1ea7c627 125 $section = 0;
126 $thissection = $sections[$section];
9a223597 127
830dd6e9 128 if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
9f7f1a74 129
130 // Note, no need for a 'left side' cell or DIV.
131 // Note, 'right side' is BEFORE content.
132 echo '<li id="section-0" class="section main" >';
133 echo '<div class="left side">&nbsp;</div>';
134 echo '<div class="right side" >&nbsp;</div>';
135 echo '<div class="content">';
40901069 136 echo '<div class="summary">';
644d506a 137
138 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
edc0c493 139 $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
644d506a 140 $summaryformatoptions = new object();
179c9a50 141 $summaryformatoptions->noclean = true;
644d506a 142 echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
5f850588 143
830dd6e9 144 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $coursecontext)) {
554cec9f 145 echo '<a title="'.$streditsummary.'" '.
146 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
9f7f1a74 147 ' class="icon edit" alt="'.$streditsummary.'" /></a>';
9a223597 148 }
40901069 149 echo '</div>';
9f7f1a74 150
1ea7c627 151 print_section($course, $thissection, $mods, $modnamesused);
0f3fe4b6 152
830dd6e9 153 if ($PAGE->user_is_editing()) {
e0161bff 154 print_section_add_menus($course, $section, $modnames);
9a223597 155 }
0f3fe4b6 156
9f7f1a74 157 echo '</div>';
158 echo "</li>\n";
9a223597 159 }
160
161
162/// Now all the normal modules by topic
163/// Everything below uses "section" terminology - each "section" is a topic.
164
165 $timenow = time();
166 $section = 1;
1d019652 167 $sectionmenu = array();
9a223597 168
b5fe4c93 169 while ($section <= $course->numsections) {
0b35af18 170
7d99d695 171 if (!empty($sections[$section])) {
172 $thissection = $sections[$section];
173
174 } else {
175 unset($thissection);
f400841b 176 $thissection->course = $course->id; // Create a new section structure
7d99d695 177 $thissection->section = $section;
f400841b 178 $thissection->summary = '';
179 $thissection->visible = 1;
180 if (!$thissection->id = $DB->insert_record('course_sections', $thissection)) {
c46f27a3 181 notify('Error inserting new topic!');
7d99d695 182 }
183 }
184
3924b988 185 $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
0b35af18 186
9f7f1a74 187 if (!empty($displaysection) and $displaysection != $section) { // Check this topic is visible
8dc93b94 188 if ($showsection) {
9f7f1a74 189 $strsummary = strip_tags(format_string($thissection->summary,true));
190 if (strlen($strsummary) < 57) {
191 $strsummary = ' - '.$strsummary;
192 } else {
193 $strsummary = ' - '.substr($strsummary, 0, 60).'...';
194 }
8dc93b94 195 $sectionmenu['topic='.$section] = s($section.$strsummary);
196 }
197 $section++;
198 continue;
199 }
200
db7da819 201 if ($showsection) {
202
203 $currenttopic = ($course->marker == $section);
204
e9b9c1d8 205 $currenttext = '';
db7da819 206 if (!$thissection->visible) {
06959cfc 207 $sectionstyle = ' hidden';
db7da819 208 } else if ($currenttopic) {
06959cfc 209 $sectionstyle = ' current';
e9b9c1d8 210 $currenttext = get_accesshide(get_string('currenttopic','access'));
db7da819 211 } else {
06959cfc 212 $sectionstyle = '';
db7da819 213 }
0b35af18 214
9f7f1a74 215 echo '<li id="section-'.$section.'" class="section main'.$sectionstyle.'" >'; //'<div class="left side">&nbsp;</div>';
0b35af18 216
9f7f1a74 217 echo '<div class="left side">'.$currenttext.$section.'</div>';
218 // Note, 'right side' is BEFORE content.
219 echo '<div class="right side">';
220
221 if ($displaysection == $section) { // Show the zoom boxes
0cdae0dc 222 echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
9f7f1a74 223 '<img src="'.$CFG->pixpath.'/i/all.gif" class="icon" alt="'.$strshowalltopics.'" /></a><br />';
ff828023 224 } else {
9f7f1a74 225 $strshowonlytopic = get_string("showonlytopic", "", $section);
c46f27a3 226 echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section.'" title="'.$strshowonlytopic.'">'.
9f7f1a74 227 '<img src="'.$CFG->pixpath.'/i/one.gif" class="icon" alt="'.$strshowonlytopic.'" /></a><br />';
12905134 228 }
229
830dd6e9 230 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
9f7f1a74 231
232 if ($course->marker == $section) { // Show the "light globe" on/off
d4a1fcaf 233 echo '<a href="view.php?id='.$course->id.'&amp;marker=0&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.'<img src="'.$CFG->pixpath.'/i/marked.gif" alt="'.$strmarkedthistopic.'" /></a><br />';
9f7f1a74 234 } else {
d4a1fcaf 235 echo '<a href="view.php?id='.$course->id.'&amp;marker='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strmarkthistopic.'">'.'<img src="'.$CFG->pixpath.'/i/marker.gif" alt="'.$strmarkthistopic.'" /></a><br />';
9f7f1a74 236 }
eccc37c0 237
238 if ($thissection->visible) { // Show the hide/show eye
d4a1fcaf 239 echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopichide.'">'.
9f7f1a74 240 '<img src="'.$CFG->pixpath.'/i/hide.gif" class="icon hide" alt="'.$strtopichide.'" /></a><br />';
eccc37c0 241 } else {
d4a1fcaf 242 echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopicshow.'">'.
9f7f1a74 243 '<img src="'.$CFG->pixpath.'/i/show.gif" class="icon hide" alt="'.$strtopicshow.'" /></a><br />';
eccc37c0 244 }
eccc37c0 245 if ($section > 1) { // Add a arrow to move section up
d4a1fcaf 246 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.'">'.
9f7f1a74 247 '<img src="'.$CFG->pixpath.'/t/up.gif" class="icon up" alt="'.$strmoveup.'" /></a><br />';
eccc37c0 248 }
249
250 if ($section < $course->numsections) { // Add a arrow to move section down
d4a1fcaf 251 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.'">'.
9f7f1a74 252 '<img src="'.$CFG->pixpath.'/t/down.gif" class="icon down" alt="'.$strmovedown.'" /></a><br />';
253 }
254 }
255 echo '</div>';
256
257 echo '<div class="content">';
258 if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students
259 echo get_string('notavailable').'</div>';
260 } else {
261 echo '<div class="summary">';
262 $summaryformatoptions->noclean = true;
263 if ($thissection->summary) {
264 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
265 } else {
266 echo '&nbsp;';
267 }
268
830dd6e9 269 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
9f7f1a74 270 echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
271 '<img src="'.$CFG->pixpath.'/t/edit.gif" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
eccc37c0 272 }
9f7f1a74 273 echo '</div>';
274
275 print_section($course, $thissection, $mods, $modnamesused);
12905134 276
830dd6e9 277 if ($PAGE->user_is_editing()) {
9f7f1a74 278 print_section_add_menus($course, $section, $modnames);
279 }
7d99d695 280 }
0b35af18 281
9f7f1a74 282 echo '</div>';
283 echo "</li>\n";
0b35af18 284 }
ff828023 285
b5fe4c93 286 $section++;
0b35af18 287 }
9f7f1a74 288 echo "</ul>\n";
1d019652 289
290 if (!empty($sectionmenu)) {
85db96c5 291 echo '<div class="jumpmenu">';
0c012545 292 echo popup_form($CFG->wwwroot.'/course/view.php?id='.$course->id.'&amp;', $sectionmenu,
c46f27a3 293 'sectionmenu', '', get_string('jumpto'), '', '', true);
294 echo '</div>';
1d019652 295 }
0b35af18 296
9f7f1a74 297 print_container_end();
2119c151 298 echo '</div>';
13beeacb 299
9f7f1a74 300 echo '</div>';
301 echo '<div class="clearer"></div>';
0b35af18 302
2ef9d19a 303?>