}
- redirect("view.php?id=$mod->course");
+ if ($SESSION->returnpage) {
+ $return = $SESSION->returnpage;
+ unset($SESSION->returnpage);
+ redirect($return);
+ } else {
+ redirect("view.php?id=$mod->course");
+ }
exit;
}
+ if (isset($return)) {
+ $SESSION->returnpage = $HTTP_REFERER;
+ }
if (isset($move)) {
<TD WIDTH="15%" VALIGN="TOP">
<?
//if ($news = get_course_news_forum($course->id)) {
- //forum_latest_topics($news->id, 5, "minimal", "DESC", false);
+ //print_forum_latest_topics($news->id, 5, "minimal", "DESC", false);
//}
//echo "<BR><BR>";
<?
if ($social = get_course_social_forum($course->id)) {
- forum_latest_topics($social->id, 10, "plain", "DESC", false);
+ print_forum_latest_topics($social->id, 10, "plain", "DESC", false);
} else {
error("Could not find or create a social forum here");
}
print_simple_box("Latest News", $align="CENTER", $width="100%", $color="$THEME->cellheading");
print_simple_box_start("CENTER", "100%", "#FFFFFF", 3, 0);
echo "<FONT SIZE=1>";
- forum_latest_topics($news->id, 5, "minimal", "DESC", false);
+ print_forum_latest_topics($news->id, 5, "minimal", "DESC", false);
echo "</FONT>";
print_simple_box_end();
}
echo "";
}
echo "</TD>\n<TD WIDTH=100%>";
- echo "<P><FONT SIZE=1>$string</FONT></P>";
+ echo "<P><FONT SIZE=2>$string</FONT></P>";
echo "</TD></TR>\n";
}
}
print_simple_box("Latest News", $align="CENTER", $width="100%", $color="$THEME->cellheading");
print_simple_box_start("CENTER", "100%", "#FFFFFF", 3, 0);
echo "<FONT SIZE=1>";
- forum_latest_topics($news->id, 5, "minimal", "DESC", false);
+ print_forum_latest_topics($news->id, 5, "minimal", "DESC", false);
echo "</FONT>";
print_simple_box_end();
}
}
print_simple_box("$headertext", $align="CENTER", $width="100%", $color="$THEME->cellheading");
echo "<IMG HEIGHT=8 SRC=\"pix/spacer.gif\" ALT=\"\"><BR>";
- forum_latest_topics($newsforum->id, $site->format);
+ print_forum_latest_topics($newsforum->id, $site->format);
}
?>
global $CFG;
if (isteacher($courseid)) {
- return "<A TITLE=\"Edit this activity\" HREF=\"$CFG->wwwroot/course/mod.php?update=$moduleid\" TARGET=_top><IMG
+ return "<A TITLE=\"Edit this activity\" HREF=\"$CFG->wwwroot/course/mod.php?update=$moduleid&return=true\" TARGET=_top><IMG
SRC=\"$CFG->wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0></A>";
}
}
}
-function get_all_topics($forum="0", $forum_sort="DESC") {
+function user_has_posted_discussion($forumid, $userid) {
+ if ($topics = get_all_topics($forumid, "DESC", $userid)) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+function user_can_post_discussion($forum) {
+// $forum is an object
+ global $USER;
+
+ if ($forum->type == "eachuser") {
+ return (! user_has_posted_discussion($forum->id, $USER->id));
+ } else if (isteacher($forum->course)) {
+ return true;
+ } else {
+ return $forum->open;
+ }
+}
+
+
+function get_all_topics($forum="0", $forum_sort="DESC", $user=0) {
+ if ($user) {
+ $userselect = " AND u.id = '$user' ";
+ } else {
+ $userselect = "";
+ }
return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture, u.id as userid
FROM discuss d, discuss_posts p, user u
WHERE d.forum = '$forum' AND p.discuss = d.id AND
- p.parent= 0 AND p.user = u.id
+ p.parent= 0 AND p.user = u.id $userselect
ORDER BY p.created $forum_sort");
}
}
-function forum_latest_topics($forum_id=0, $forum_numtopics=5, $forum_style="plain", $forum_sort="DESC") {
+function print_forum_latest_topics($forum_id=0, $forum_numtopics=5, $forum_style="plain", $forum_sort="DESC") {
global $CFG, $USER;
if ($forum_id) {
}
if (! $topics = get_all_topics($forum->id, $forum_sort) ) {
- echo "<P><B>There are no discussion topics yet in this forum.</B></P>";
+ echo "<P ALIGN=CENTER><B>There are no discussion topics yet in this forum.</B></P>";
} else {
}
}
}
- if ($forum->open || $USER->editing) {
+ if (user_can_post_discussion($forum)) {
echo "<P ALIGN=right>";
echo "<A HREF=\"$CFG->wwwroot/mod/discuss/post.php?forum=$forum->id\">Add a new topic...</A>";
echo "</P>";
} else {
$subtext = "Subscribe to this forum";
}
- echo "<DIV ALIGN=RIGHT><FONT SIZE=1><A HREF=\"subscribe.php?id=$forum->id\">$subtext</A></FONT></P>";
+ echo "<DIV ALIGN=RIGHT><FONT SIZE=1><A HREF=\"subscribe.php?id=$forum->id\">$subtext</A></FONT></DIV>";
}
- forum_latest_topics($forum->id, 0);
+ print_simple_box(text_to_html($forum->intro), "CENTER");
+
+ switch ($forum->type) {
+ case "eachuser":
+ echo "<P ALIGN=CENTER>";
+ if (user_can_post_discussion($forum)) {
+ echo "This forum allows one discussion topic to be posted per person. Click here to <A HREF=\"../discuss/post.php?forum=$forum->id\">post your topic</A>.";
+ } else {
+ echo " ";
+ }
+ echo "</P>";
+ break;
+
+ default:
+ echo "<P> </P>";
+ break;
+ }
+
+ print_forum_latest_topics($forum->id, 0);
print_footer($course);