From: martin Date: Tue, 25 Jun 2002 06:47:34 +0000 (+0000) Subject: Changes related to new forum type: eachuser and some general forum-related tweaking X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e07635f4d05e1c09aad56dd8e5c8bb46bb1e10fa;p=moodle.git Changes related to new forum type: eachuser and some general forum-related tweaking --- diff --git a/course/mod.php b/course/mod.php index 9ac9acdefc..76c35edc8a 100644 --- a/course/mod.php +++ b/course/mod.php @@ -63,10 +63,19 @@ } - 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)) { diff --git a/course/social.php b/course/social.php index 7a9a72ffa7..6ed869b0fe 100644 --- a/course/social.php +++ b/course/social.php @@ -11,7 +11,7 @@ id)) { - //forum_latest_topics($news->id, 5, "minimal", "DESC", false); + //print_forum_latest_topics($news->id, 5, "minimal", "DESC", false); //} //echo "

"; @@ -93,7 +93,7 @@ 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"); } diff --git a/course/topics.php b/course/topics.php index 022205384d..2839fa25aa 100644 --- a/course/topics.php +++ b/course/topics.php @@ -204,7 +204,7 @@ print_simple_box("Latest News", $align="CENTER", $width="100%", $color="$THEME->cellheading"); print_simple_box_start("CENTER", "100%", "#FFFFFF", 3, 0); echo ""; - forum_latest_topics($news->id, 5, "minimal", "DESC", false); + print_forum_latest_topics($news->id, 5, "minimal", "DESC", false); echo ""; print_simple_box_end(); } diff --git a/course/view.php b/course/view.php index 087aaff756..cdd23be2eb 100644 --- a/course/view.php +++ b/course/view.php @@ -96,7 +96,7 @@ function print_side_block($heading="", $list=NULL, $footer="", $icons=NULL) { echo ""; } echo "\n"; - echo "

$string

"; + echo "

$string

"; echo "\n"; } } diff --git a/course/weeks.php b/course/weeks.php index 721171b42a..3e7e5be970 100644 --- a/course/weeks.php +++ b/course/weeks.php @@ -193,7 +193,7 @@ print_simple_box("Latest News", $align="CENTER", $width="100%", $color="$THEME->cellheading"); print_simple_box_start("CENTER", "100%", "#FFFFFF", 3, 0); echo ""; - forum_latest_topics($news->id, 5, "minimal", "DESC", false); + print_forum_latest_topics($news->id, 5, "minimal", "DESC", false); echo ""; print_simple_box_end(); } diff --git a/index.php b/index.php index d1518fa54b..68ea276c50 100644 --- a/index.php +++ b/index.php @@ -87,7 +87,7 @@ } print_simple_box("$headertext", $align="CENTER", $width="100%", $color="$THEME->cellheading"); echo "\"\"
"; - forum_latest_topics($newsforum->id, $site->format); + print_forum_latest_topics($newsforum->id, $site->format); } ?> diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 4918127d6e..f3871319b8 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -197,7 +197,7 @@ function update_module_icon($moduleid) { global $CFG; if (isteacher($courseid)) { - return "wwwroot/course/mod.php?update=$moduleid\" TARGET=_top>wwwroot/course/mod.php?update=$moduleid&return=true\" TARGET=_top>wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0>"; } } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index c97366b093..f8237892bf 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -26,11 +26,38 @@ function forum_unsubscribe($user, $forum) { } -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"); } @@ -87,7 +114,7 @@ function get_course_discussion_forum($courseid) { } -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) { @@ -112,7 +139,7 @@ function forum_latest_topics($forum_id=0, $forum_numtopics=5, $forum_style="plai } if (! $topics = get_all_topics($forum->id, $forum_sort) ) { - echo "

There are no discussion topics yet in this forum.

"; + echo "

There are no discussion topics yet in this forum.

"; } else { @@ -147,7 +174,7 @@ function forum_latest_topics($forum_id=0, $forum_numtopics=5, $forum_style="plai } } } - if ($forum->open || $USER->editing) { + if (user_can_post_discussion($forum)) { echo "

"; echo "wwwroot/mod/discuss/post.php?forum=$forum->id\">Add a new topic..."; echo "

"; diff --git a/mod/forum/view.php b/mod/forum/view.php index 440d5473fb..e3b58d7498 100644 --- a/mod/forum/view.php +++ b/mod/forum/view.php @@ -50,10 +50,28 @@ } else { $subtext = "Subscribe to this forum"; } - echo "
id\">$subtext

"; + echo "
id\">$subtext
"; } - forum_latest_topics($forum->id, 0); + print_simple_box(text_to_html($forum->intro), "CENTER"); + + switch ($forum->type) { + case "eachuser": + echo "

"; + if (user_can_post_discussion($forum)) { + echo "This forum allows one discussion topic to be posted per person. Click here to id\">post your topic."; + } else { + echo " "; + } + echo "

"; + break; + + default: + echo "

 

"; + break; + } + + print_forum_latest_topics($forum->id, 0); print_footer($course);