Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / course / format / topics / format.php
blob514f91a78ae5394409ef5e5a0b278625099e72cd
1 <?php // $Id$
2 // Display the whole course as "topics" made of of modules
3 // In fact, this is very similar to the "weeks" format, in that
4 // 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 // courses that aren't so rigidly defined by time.
7 // Included from "view.php"
10 require_once($CFG->libdir.'/ajax/ajaxlib.php');
12 if (!empty($THEME->customcorners)) {
13 require_once($CFG->dirroot.'/lib/custom_corners_lib.php');
16 $topic = optional_param('topic', -1, PARAM_INT);
18 // Bounds for block widths
19 // more flexible for theme designers taken from theme config.php
20 $lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width;
21 $lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
22 $rmin = (empty($THEME->block_r_min_width)) ? 100 : $THEME->block_r_min_width;
23 $rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
25 define('BLOCK_L_MIN_WIDTH', $lmin);
26 define('BLOCK_L_MAX_WIDTH', $lmax);
27 define('BLOCK_R_MIN_WIDTH', $rmin);
28 define('BLOCK_R_MAX_WIDTH', $rmax);
30 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
31 BLOCK_L_MAX_WIDTH);
32 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
33 BLOCK_R_MAX_WIDTH);
35 if ($topic != -1) {
36 $displaysection = course_set_display($course->id, $topic);
37 } else {
38 if (isset($USER->display[$course->id])) { // for admins, mostly
39 $displaysection = $USER->display[$course->id];
40 } else {
41 $displaysection = course_set_display($course->id, 0);
45 $context = get_context_instance(CONTEXT_COURSE, $course->id);
47 if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
48 $course->marker = $marker;
49 if (! set_field("course", "marker", $marker, "id", $course->id)) {
50 error("Could not mark that topic for this course");
54 $streditsummary = get_string('editsummary');
55 $stradd = get_string('add');
56 $stractivities = get_string('activities');
57 $strshowalltopics = get_string('showalltopics');
58 $strtopic = get_string('topic');
59 $strgroups = get_string('groups');
60 $strgroupmy = get_string('groupmy');
61 $editing = $PAGE->user_is_editing();
63 if ($editing) {
64 $strstudents = moodle_strtolower($course->students);
65 $strtopichide = get_string('topichide', '', $strstudents);
66 $strtopicshow = get_string('topicshow', '', $strstudents);
67 $strmarkthistopic = get_string('markthistopic');
68 $strmarkedthistopic = get_string('markedthistopic');
69 $strmoveup = get_string('moveup');
70 $strmovedown = get_string('movedown');
74 /// Layout the whole page as three big columns.
75 echo '<table id="layout-table" cellspacing="0" summary="'.get_string('layouttable').'"><tr>';
77 /// The left column ...
78 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
79 foreach ($lt as $column) {
80 switch ($column) {
81 case 'left':
83 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
84 echo '<td style="width:'.$preferred_width_left.'px" id="left-column">';
85 if (!empty($THEME->customcorners)) print_custom_corners_start();
86 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
87 if (!empty($THEME->customcorners)) print_custom_corners_end();
88 echo '</td>';
91 break;
92 case 'middle':
93 /// Start main column
94 echo '<td id="middle-column">';
95 if (!empty($THEME->customcorners)) print_custom_corners_start();
96 echo '<a name="startofcontent"></a>';
98 print_heading_block(get_string('topicoutline'), 'outline');
100 echo '<table class="topics" width="100%" summary="'.get_string('layouttable').'">';
102 /// If currently moving a file then show the current clipboard
103 if (ismoving($course->id)) {
104 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
105 $strcancel= get_string('cancel');
106 echo '<tr class="clipboard">';
107 echo '<td colspan="3">';
108 echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.$USER->sesskey.'">'.$strcancel.'</a>)';
109 echo '</td>';
110 echo '</tr>';
113 /// Print Section 0
115 $section = 0;
116 $thissection = $sections[$section];
118 if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
119 echo '<tr id="section-0" class="section main">';
120 echo '<td class="left side">&nbsp;</td>';
121 echo '<td class="content">';
123 echo '<div class="summary">';
124 $summaryformatoptions->noclean = true;
125 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
127 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
128 echo '<a title="'.$streditsummary.'" '.
129 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
130 ' alt="'.$streditsummary.'" /></a><br /><br />';
132 echo '</div>';
134 print_section($course, $thissection, $mods, $modnamesused);
136 if (isediting($course->id)) {
137 print_section_add_menus($course, $section, $modnames);
140 echo '</td>';
141 echo '<td class="right side">&nbsp;</td>';
142 echo '</tr>';
143 echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
147 /// Now all the normal modules by topic
148 /// Everything below uses "section" terminology - each "section" is a topic.
150 $timenow = time();
151 $section = 1;
152 $sectionmenu = array();
154 while ($section <= $course->numsections) {
156 if (!empty($sections[$section])) {
157 $thissection = $sections[$section];
159 } else {
160 unset($thissection);
161 $thissection->course = $course->id; // Create a new section structure
162 $thissection->section = $section;
163 $thissection->summary = '';
164 $thissection->visible = 1;
165 if (!$thissection->id = insert_record('course_sections', $thissection)) {
166 notify('Error inserting new topic!');
170 $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
172 if (!empty($displaysection) and $displaysection != $section) {
173 if ($showsection) {
174 $strsummary = strip_tags(format_string($thissection->summary,true));
175 if (strlen($strsummary) < 57) {
176 $strsummary = ' - '.$strsummary;
177 } else {
178 $strsummary = ' - '.substr($strsummary, 0, 60).'...';
180 $sectionmenu['topic='.$section] = s($section.$strsummary);
182 $section++;
183 continue;
186 if ($showsection) {
188 $currenttopic = ($course->marker == $section);
190 if (!$thissection->visible) {
191 $sectionstyle = ' hidden';
192 } else if ($currenttopic) {
193 $sectionstyle = ' current';
194 } else {
195 $sectionstyle = '';
198 echo '<tr id="section-'.$section.'" class="section main'.$sectionstyle.'">';
199 echo '<td class="left side">'.$section.'</td>';
201 echo '<td class="content">';
202 if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students
203 echo get_string('notavailable');
204 } else {
205 echo '<div class="summary">';
206 $summaryformatoptions->noclean = true;
207 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
209 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
210 echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
211 '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$streditsummary.'" /></a><br /><br />';
213 echo '</div>';
215 print_section($course, $thissection, $mods, $modnamesused);
217 if (isediting($course->id)) {
218 print_section_add_menus($course, $section, $modnames);
221 echo '</td>';
223 echo '<td class="right side">';
224 if ($displaysection == $section) { // Show the zoom boxes
225 echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
226 '<img src="'.$CFG->pixpath.'/i/all.gif" alt="'.$strshowalltopics.'" /></a><br />';
227 } else {
228 $strshowonlytopic = get_string('showonlytopic', '', $section);
229 echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section.'" title="'.$strshowonlytopic.'">'.
230 '<img src="'.$CFG->pixpath.'/i/one.gif" alt="'.$strshowonlytopic.'" /></a><br />';
233 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
234 if ($course->marker == $section) { // Show the "light globe" on/off
235 echo '<a href="view.php?id='.$course->id.'&amp;marker=0&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.
236 '<img src="'.$CFG->pixpath.'/i/marked.gif" alt="'.$strmarkedthistopic.'" /></a><br />';
237 } else {
238 echo '<a href="view.php?id='.$course->id.'&amp;marker='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkthistopic.'">'.
239 '<img src="'.$CFG->pixpath.'/i/marker.gif" alt="'.$strmarkthistopic.'" /></a><br />';
242 if ($thissection->visible) { // Show the hide/show eye
243 echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strtopichide.'">'.
244 '<img src="'.$CFG->pixpath.'/i/hide.gif" alt="'.$strtopichide.'" /></a><br />';
245 } else {
246 echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strtopicshow.'">'.
247 '<img src="'.$CFG->pixpath.'/i/show.gif" alt="'.$strtopicshow.'" /></a><br />';
250 if ($section > 1) { // Add a arrow to move section up
251 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.'">'.
252 '<img src="'.$CFG->pixpath.'/t/up.gif" alt="'.$strmoveup.'" /></a><br />';
255 if ($section < $course->numsections) { // Add a arrow to move section down
256 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.'">'.
257 '<img src="'.$CFG->pixpath.'/t/down.gif" alt="'.$strmovedown.'" /></a><br />';
262 echo '</td></tr>';
263 echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
266 $section++;
268 echo '</table>';
270 if (!empty($sectionmenu)) {
271 echo '<div align="center" class="jumpmenu">';
272 echo popup_form($CFG->wwwroot.'/course/view.php?id='.$course->id.'&amp;', $sectionmenu,
273 'sectionmenu', '', get_string('jumpto'), '', '', true);
274 echo '</div>';
277 if (!empty($THEME->customcorners)) print_custom_corners_end();
278 echo '</td>';
280 break;
281 case 'right':
282 // The right column
283 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) {
284 echo '<td style="width:'.$preferred_width_right.'px" id="right-column">';
285 if (!empty($THEME->customcorners)) print_custom_corners_start();
286 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
287 if (!empty($THEME->customcorners)) print_custom_corners_end();
288 echo '</td>';
291 break;
294 echo '</tr></table>';