moodle_page: MDL-12212 reimplement user_is_editing, deprecate isediting
[moodle.git] / course / format / topics / format.php
1 <?php // $Id$
2       // Display the whole course as "topics" made of of modules
3       // Included from "view.php"
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']
28     require_once($CFG->libdir.'/ajax/ajaxlib.php');
29     require_once($CFG->libdir.'/filelib.php');
31     $topic = optional_param('topic', -1, PARAM_INT);
33     if ($topic != -1) {
34         $displaysection = course_set_display($course->id, $topic);
35     } else {
36         if (isset($USER->display[$course->id])) {
37             $displaysection = $USER->display[$course->id];
38         } else {
39             $displaysection = course_set_display($course->id, 0);
40         }
41     }
43     $context = get_context_instance(CONTEXT_COURSE, $course->id);
45     if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
46         $course->marker = $marker;
47         if (! $DB->set_field("course", "marker", $marker, array("id"=>$course->id))) {
48             print_error("cannotmarktopic");
49         }
50     }
52     $streditsummary  = get_string('editsummary');
53     $stradd          = get_string('add');
54     $stractivities   = get_string('activities');
55     $strshowalltopics = get_string('showalltopics');
56     $strtopic         = get_string('topic');
57     $strgroups       = get_string('groups');
58     $strgroupmy      = get_string('groupmy');
59     $editing         = $PAGE->user_is_editing();
61     if ($editing) {
62         $strtopichide = get_string('hidetopicfromothers');
63         $strtopicshow = get_string('showtopicfromothers');
64         $strmarkthistopic = get_string('markthistopic');
65         $strmarkedthistopic = get_string('markedthistopic');
66         $strmoveup   = get_string('moveup');
67         $strmovedown = get_string('movedown');
68     }
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 ?>
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">';
84 /// The left column ...
86     if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
87         echo '<div id="left-column">';
88         print_container_start();
89         blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
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>';
101     }
103 /// Start main column
104     echo '<div id="middle-column">';
105     print_container_start();
107     echo skip_main_destination();
109     print_heading_block(get_string('topicoutline'), 'outline');
111     // Note, an ordered list would confuse - "1" could be the clipboard or summary.
112     echo "<ul class='topics'>\n";
114 /// If currently moving a file then show the current clipboard
115     if (ismoving($course->id)) {
116         $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
117         $strcancel= get_string('cancel');
118         echo '<li class="clipboard">';
119         echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
120         echo "</li>\n";
121     }
123 /// Print Section 0 with general activities
125     $section = 0;
126     $thissection = $sections[$section];
128     if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
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">';
136         echo '<div class="summary">';
138         $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
139         $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
140         $summaryformatoptions = new object();
141         $summaryformatoptions->noclean = true;
142         echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
144         if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $coursecontext)) {
145             echo '<a title="'.$streditsummary.'" '.
146                  ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
147                  ' class="icon edit" alt="'.$streditsummary.'" /></a>';
148         }
149         echo '</div>';
150         
151         print_section($course, $thissection, $mods, $modnamesused);
153         if ($PAGE->user_is_editing()) {
154             print_section_add_menus($course, $section, $modnames);
155         }
157         echo '</div>';
158         echo "</li>\n";
159     }
162 /// Now all the normal modules by topic
163 /// Everything below uses "section" terminology - each "section" is a topic.
165     $timenow = time();
166     $section = 1;
167     $sectionmenu = array();
169     while ($section <= $course->numsections) {
171         if (!empty($sections[$section])) {
172             $thissection = $sections[$section];
174         } else {
175             unset($thissection);
176             $thissection->course  = $course->id;   // Create a new section structure
177             $thissection->section = $section;
178             $thissection->summary  = '';
179             $thissection->visible  = 1;
180             if (!$thissection->id = $DB->insert_record('course_sections', $thissection)) {
181                 notify('Error inserting new topic!');
182             }
183         }
185         $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
187         if (!empty($displaysection) and $displaysection != $section) {  // Check this topic is visible
188             if ($showsection) {
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                 }
195                 $sectionmenu['topic='.$section] = s($section.$strsummary);
196             }
197             $section++;
198             continue;
199         }
201         if ($showsection) {
203             $currenttopic = ($course->marker == $section);
205             $currenttext = '';
206             if (!$thissection->visible) {
207                 $sectionstyle = ' hidden';
208             } else if ($currenttopic) {
209                 $sectionstyle = ' current';
210                 $currenttext = get_accesshide(get_string('currenttopic','access'));
211             } else {
212                 $sectionstyle = '';
213             }
215             echo '<li id="section-'.$section.'" class="section main'.$sectionstyle.'" >'; //'<div class="left side">&nbsp;</div>';
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
222                 echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
223                      '<img src="'.$CFG->pixpath.'/i/all.gif" class="icon" alt="'.$strshowalltopics.'" /></a><br />';
224             } else {
225                 $strshowonlytopic = get_string("showonlytopic", "", $section);
226                 echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section.'" title="'.$strshowonlytopic.'">'.
227                      '<img src="'.$CFG->pixpath.'/i/one.gif" class="icon" alt="'.$strshowonlytopic.'" /></a><br />';
228             }
230             if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
232                 if ($course->marker == $section) {  // Show the "light globe" on/off
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 />';
234                 } else {
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 />';
236                 }
238                 if ($thissection->visible) {        // Show the hide/show eye
239                     echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopichide.'">'.
240                          '<img src="'.$CFG->pixpath.'/i/hide.gif" class="icon hide" alt="'.$strtopichide.'" /></a><br />';
241                 } else {
242                     echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopicshow.'">'.
243                          '<img src="'.$CFG->pixpath.'/i/show.gif" class="icon hide" alt="'.$strtopicshow.'" /></a><br />';
244                 }
245                 if ($section > 1) {                       // Add a arrow to move section up
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.'">'.
247                          '<img src="'.$CFG->pixpath.'/t/up.gif" class="icon up" alt="'.$strmoveup.'" /></a><br />';
248                 }
250                 if ($section < $course->numsections) {    // Add a arrow to move section down
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.'">'.
252                          '<img src="'.$CFG->pixpath.'/t/down.gif" class="icon down" alt="'.$strmovedown.'" /></a><br />';
253                 }
254             }
255             echo '</div>';
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                 }
269                 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
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 />';
272                 }
273                 echo '</div>';
275                 print_section($course, $thissection, $mods, $modnamesused);
277                 if ($PAGE->user_is_editing()) {
278                     print_section_add_menus($course, $section, $modnames);
279                 }
280             }
282             echo '</div>';
283             echo "</li>\n";
284         }
286         $section++;
287     }
288     echo "</ul>\n";
290     if (!empty($sectionmenu)) {
291         echo '<div class="jumpmenu">';
292         echo popup_form($CFG->wwwroot.'/course/view.php?id='.$course->id.'&amp;', $sectionmenu,
293                    'sectionmenu', '', get_string('jumpto'), '', '', true);
294         echo '</div>';
295     }
297     print_container_end();
298     echo '</div>';
300     echo '</div>';
301     echo '<div class="clearer"></div>';
303 ?>