Polished.
[moodle.git] / course / topics.php
blob234aa0da3d95b3530cb854013e10798f2080b6bf
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"
9 require_once("$CFG->dirroot/mod/forum/lib.php");
11 if (isset($topic)) {
12 $displaysection = course_set_display($course->id, $topic);
13 } else {
14 if (isset($USER->display[$course->id])) { // for admins, mostly
15 $displaysection = $USER->display[$course->id];
16 } else {
17 $displaysection = course_set_display($course->id, 0);
21 if (isteacher($course->id) and isset($marker)) {
22 $course->marker = $marker;
23 if (! set_field("course", "marker", $marker, "id", $course->id)) {
24 error("Could not mark that topic for this course");
28 if ($course->newsitems) {
29 $news = forum_get_course_forum($course->id, "news");
32 $streditsummary = get_string("editsummary");
33 $stradd = get_string("add");
34 $stractivities = get_string("activities");
35 $strshowalltopics = get_string("showalltopics");
36 if (isediting($course->id)) {
37 $strstudents = moodle_strtolower($course->students);
38 $strtopichide = get_string("topichide", "", $strstudents);
39 $strtopicshow = get_string("topicshow", "", $strstudents);
40 $strmarkthistopic = get_string("markthistopic");
41 $strmarkedthistopic = get_string("markedthistopic");
45 /// Layout the whole page as three big columns.
46 echo "<table border=0 cellpadding=3 cellspacing=0 width=100%>";
48 /// The left column ...
50 echo "<tr valign=top><td valign=top width=180>";
52 /// Links to people
53 $moddata[]="<a title=\"".get_string("listofallpeople")."\" href=\"../user/index.php?id=$course->id\">".get_string("participants")."</a>";
54 $modicon[]="<img src=\"$pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
55 $editmyprofile = "<a title=\"$USER->firstname $USER->lastname\" href=\"../user/edit.php?id=$USER->id&course=$course->id\">".get_string("editmyprofile")."</a>";
56 if ($USER->description) {
57 $moddata[]= $editmyprofile;
58 } else {
59 $moddata[]= $editmyprofile." <blink>*</blink>";
61 $modicon[]="<img src=\"$pixpath/i/user.gif\" height=16 width=16 alt=\"\">";
62 print_side_block(get_string("people"), "", $moddata, $modicon);
65 /// Links to all activity modules by type
66 $moddata = array();
67 $modicon = array();
68 if ($modnamesused) {
69 foreach ($modnamesused as $modname => $modfullname) {
70 $moddata[] = "<a href=\"../mod/$modname/index.php?id=$course->id\">".$modnamesplural[$modname]."</a>";
71 $modicon[] = "<img src=\"$modpixpath/$modname/icon.gif\" height=16 width=16 alt=\"\">";
74 print_side_block($stractivities, "", $moddata, $modicon);
76 /// Print a form to search forums
77 $searchform = forum_print_search_form($course, "", true);
78 $searchform = "<div align=\"center\">$searchform</div>";
79 print_side_block(get_string("search","forum"), $searchform);
81 /// Admin links and controls
82 print_course_admin_links($course);
84 /// Start main column
85 echo "</td><td width=\"*\">";
87 print_heading_block(get_string("topicoutline"), "100%", "outlineheadingblock");
88 print_spacer(8, 1, true);
90 echo "<table class=\"topicsoutline\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" width=\"100%\">";
92 /// Print Section 0
94 $section = 0;
95 $thissection = $sections[$section];
97 if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
98 echo "<tr>";
99 echo "<td nowrap bgcolor=\"$THEME->cellheading\" class=\"topicsoutlineside\" valign=top width=20>&nbsp;</td>";
100 echo "<td valign=top bgcolor=\"$THEME->cellcontent\" class=\"topicsoutlinecontent\" width=\"100%\">";
102 if (isediting($course->id)) {
103 $thissection->summary .= "&nbsp;<a title=\"$streditsummary\" ".
104 "href=\"editsection.php?id=$thissection->id\"><img src=\"$pixpath/t/edit.gif\" ".
105 "height=11 width=11 border=0 alt=\"$streditsummary\"></a></p>";
108 echo text_to_html($thissection->summary);
110 print_section($course, $thissection, $mods, $modnamesused);
112 if (isediting($course->id)) {
113 echo "<div align=right>";
114 popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
115 $modnames, "section$section", "", "$stradd...", "mods", $stractivities);
116 echo "</div>";
119 echo "</td>";
120 echo "<td nowrap bgcolor=\"$THEME->cellheading\" class=\"topicsoutlineside\" valign=top align=center width=10>";
121 echo "&nbsp;</td></tr>";
122 echo "<tr><td colspan=3><img src=\"../pix/spacer.gif\" width=1 height=1></td></tr>";
126 /// Now all the normal modules by topic
127 /// Everything below uses "section" terminology - each "section" is a topic.
129 $timenow = time();
130 $section = 1;
132 while ($section <= $course->numsections) {
134 if (!empty($displaysection) and $displaysection != $section) {
135 $section++;
136 continue;
139 if (!empty($sections[$section])) {
140 $thissection = $sections[$section];
142 } else {
143 unset($thissection);
144 $thissection->course = $course->id; // Create a new section structure
145 $thissection->section = $section;
146 $thissection->summary = "";
147 $thissection->visible = 1;
148 if (!$thissection->id = insert_record("course_sections", $thissection)) {
149 notify("Error inserting new topic!");
153 $currenttopic = ($course->marker == $section);
155 if (!$thissection->visible) {
156 $colorsides = "bgcolor=\"$THEME->hidden\" class=\"topicsoutlinesidehidden\"";
157 $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"topicsoutlinecontenthidden\"";
158 } else if ($currenttopic) {
159 $colorsides = "bgcolor=\"$THEME->cellheading2\" class=\"topicsoutlinesidehighlight\"";
160 $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"topicsoutlinecontenthighlight\"";
161 } else {
162 $colorsides = "bgcolor=\"$THEME->cellheading\" class=\"topicsoutlineside\"";
163 $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"topicsoutlinecontent\"";
166 echo "<tr>";
167 echo "<td nowrap $colorsides valign=top width=20>";
168 echo "<p align=center><font size=3><b>$section</b></font></p>";
169 echo "</td>";
171 if (!isteacher($course->id) and !$thissection->visible) { // Hidden for students
172 echo "<td valign=top align=center $colormain width=\"100%\">";
173 echo get_string("notavailable");
174 echo "</td>";
176 } else {
177 echo "<td valign=top $colormain width=\"100%\">";
179 if (isediting($course->id)) {
180 $thissection->summary .= "&nbsp;<a title=\"$streditsummary\" href=editsection.php?id=$thissection->id>".
181 "<img src=\"$pixpath/t/edit.gif\" border=0 height=11 width=11></a>";
184 echo text_to_html($thissection->summary);
186 print_section($course, $thissection, $mods, $modnamesused);
188 if (isediting($course->id)) {
189 echo "<div align=right>";
190 popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
191 $modnames, "section$section", "", "$stradd...");
192 echo "</div>";
195 echo "</td>";
197 echo "<td nowrap $colorsides valign=top align=center width=10>";
198 echo "<font size=1>";
200 if ($displaysection == $section) { // Show the zoom boxes
201 echo "<a href=\"view.php?id=$course->id&topic=all\" title=\"$strshowalltopics\">".
202 "<img src=\"$pixpath/i/all.gif\" height=25 width=16 border=0></a><br />";
203 } else {
204 $strshowonlytopic = get_string("showonlytopic", "", $section);
205 echo "<a href=\"view.php?id=$course->id&topic=$section\" title=\"$strshowonlytopic\">".
206 "<img src=\"$pixpath/i/one.gif\" height=16 width=16 border=0></a><br />";
209 if (isediting($course->id)) {
210 if ($course->marker == $section) { // Show the "light globe" on/off
211 echo "<a href=\"view.php?id=$course->id&marker=0\" title=\"$strmarkedthistopic\">".
212 "<img src=\"$pixpath/i/marked.gif\" vspace=3 height=16 width=16 border=0></a><br />";
213 } else {
214 echo "<a href=\"view.php?id=$course->id&marker=$section\" title=\"$strmarkthistopic\">".
215 "<img src=\"$pixpath/i/marker.gif\" vspace=3 height=16 width=16 border=0></a><br />";
218 if ($thissection->visible) { // Show the hide/show eye
219 echo "<a href=\"view.php?id=$course->id&hide=$section\" title=\"$strtopichide\">".
220 "<img src=\"$pixpath/i/hide.gif\" vspace=3 height=16 width=16 border=0></a><br />";
221 } else {
222 echo "<a href=\"view.php?id=$course->id&show=$section\" title=\"$strtopicshow\">".
223 "<img src=\"$pixpath/i/show.gif\" vspace=3 height=16 width=16 border=0></a><br />";
228 echo "</td>";
229 echo "</tr>";
230 echo "<tr><td colspan=3><img src=\"../pix/spacer.gif\" width=1 height=1></td></tr>";
232 $section++;
234 echo "</table>";
237 if ($news or $course->showrecent) {
238 echo "</td><td width=210>";
240 /// Print all the news items.
242 if ($news) {
243 print_side_block_start(get_string("latestnews"), 210, "sideblocklatestnews");
244 echo "<font size=\"-2\">";
245 forum_print_latest_discussions($news->id, $course->newsitems, "minimal", "", false);
246 echo "</font>";
247 print_side_block_end();
250 // Print all the recent activity
251 if ($course->showrecent) {
252 print_side_block_start(get_string("recentactivity"), 210, "sideblockrecentactivity");
253 print_recent_activity($course);
254 print_side_block_end();
257 print_spacer(1, 120, true);
260 echo "</td></tr></table>\n";