2002-06-20 15:15:22 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
/// CONSTANTS ///////////////////////////////////////////////////////////
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
$FORUM_DEFAULT_DISPLAY_MODE = 3;
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-08-02 17:34:26 +00:00
|
|
|
$FORUM_LAYOUT_MODES = array ( "1" => get_string("modeflatoldestfirst", "forum"),
|
|
|
|
"-1" => get_string("modeflatnewestfirst", "forum"),
|
|
|
|
"2" => get_string("modethreaded", "forum"),
|
|
|
|
"3" => get_string("modenested", "forum") );
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
// These are course content forums that can be added to the course manually
|
2002-08-02 17:34:26 +00:00
|
|
|
$FORUM_TYPES = array ("general" => get_string("generalforum", "forum"),
|
|
|
|
"eachuser" => get_string("eachuserforum", "forum"),
|
|
|
|
"single" => get_string("singleforum", "forum") );
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-08-02 17:34:26 +00:00
|
|
|
$FORUM_POST_RATINGS = array ("3" => get_string("postrating3", "forum"),
|
|
|
|
"2" => get_string("postrating2", "forum"),
|
|
|
|
"1" => get_string("postrating1", "forum") );
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-08-04 13:13:59 +00:00
|
|
|
$FORUM_SHORT_POST = 300; // Less than this is "short"
|
|
|
|
|
|
|
|
$FORUM_LONG_POST = 600; // More than this is "long"
|
|
|
|
|
2002-06-25 06:47:34 +00:00
|
|
|
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
/// FUNCTIONS ///////////////////////////////////////////////////////////
|
2002-06-20 15:15:22 +00:00
|
|
|
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_get_course_forum($courseid, $type) {
|
|
|
|
// How to set up special 1-per-course forums
|
|
|
|
if ($forum = get_record_sql("SELECT * from forum WHERE course = '$courseid' AND type = '$type'")) {
|
2002-06-20 15:15:22 +00:00
|
|
|
return $forum;
|
2002-08-02 17:34:26 +00:00
|
|
|
|
2002-06-20 15:15:22 +00:00
|
|
|
} else {
|
|
|
|
// Doesn't exist, so create one now.
|
|
|
|
$forum->course = $courseid;
|
2002-08-01 03:50:27 +00:00
|
|
|
$forum->type = "$type";
|
|
|
|
switch ($forum->type) {
|
|
|
|
case "news":
|
2002-08-02 17:34:26 +00:00
|
|
|
$forum->name = get_string("namenews", "forum");
|
|
|
|
$forum->intro = get_string("intronews", "forum");
|
|
|
|
$forum->open = 0;
|
2002-08-01 03:50:27 +00:00
|
|
|
$forum->assessed = 0;
|
|
|
|
$forum->forcesubscribe = 1;
|
|
|
|
break;
|
|
|
|
case "social":
|
2002-08-02 17:34:26 +00:00
|
|
|
$forum->name = get_string("namesocial", "forum");
|
|
|
|
$forum->intro = get_string("introsocial", "forum");
|
|
|
|
$forum->open = 1;
|
2002-08-01 03:50:27 +00:00
|
|
|
$forum->assessed = 0;
|
|
|
|
$forum->forcesubscribe = 0;
|
|
|
|
break;
|
|
|
|
case "teacher":
|
2002-08-02 17:34:26 +00:00
|
|
|
$forum->name = get_string("nameteacher", "forum");
|
|
|
|
$forum->intro = get_string("introteacher", "forum");
|
|
|
|
$forum->open = 0;
|
2002-08-01 03:50:27 +00:00
|
|
|
$forum->assessed = 0;
|
|
|
|
$forum->forcesubscribe = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
notify("That forum type doesn't exist!");
|
|
|
|
return false;
|
|
|
|
break;
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
}
|
2002-07-04 08:30:36 +00:00
|
|
|
$forum->timemodified = time();
|
|
|
|
$forum->id = insert_record("forum", $forum);
|
|
|
|
return get_record_sql("SELECT * from forum WHERE id = '$forum->id'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_make_mail_post(&$post, $user, $touser, $course,
|
|
|
|
$ownpost=false, $reply=false, $link=false, $rate=false, $footer="") {
|
2002-07-31 14:19:35 +00:00
|
|
|
// Given the data about a posting, builds up the HTML to display it and
|
|
|
|
// returns the HTML in a string. This is designed for sending via HTML email.
|
|
|
|
|
|
|
|
global $THEME, $CFG;
|
|
|
|
|
|
|
|
$output = "";
|
|
|
|
|
|
|
|
if ($post->parent) {
|
|
|
|
$output .= "<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=1><TR><TD BGCOLOR=#888888>";
|
|
|
|
$output .= "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0>";
|
|
|
|
} else {
|
|
|
|
$output .= "<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=1 WIDTH=100%><TR><TD BGCOLOR=#888888>";
|
|
|
|
$output .= "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 WIDTH=100%>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= "<TR><TD BGCOLOR=\"$THEME->body\" WIDTH=35 VALIGN=TOP>";
|
|
|
|
$output .= print_user_picture($user->id, $course->id, $user->picture, false, true);
|
|
|
|
$output .= "</TD>";
|
|
|
|
|
|
|
|
if ($post->parent) {
|
|
|
|
$output .= "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\">";
|
|
|
|
} else {
|
|
|
|
$output .= "<TD NOWRAP BGCOLOR=\"$THEME->cellheading2\">";
|
|
|
|
}
|
|
|
|
$output .= "<P>";
|
|
|
|
$output .= "<FONT SIZE=3><B>$post->subject</B></FONT><BR>";
|
2002-08-02 17:34:26 +00:00
|
|
|
$output .= "<FONT SIZE=2>";
|
|
|
|
$by->name = "<A HREF=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A>";
|
|
|
|
$by->date = userdate($post->created, "", $touser->timezone);
|
|
|
|
$output .= get_string("bynameondate", "forum", $by);
|
2002-07-31 14:19:35 +00:00
|
|
|
$output .= "</FONT></P></TD></TR>";
|
|
|
|
$output .= "<TR><TD BGCOLOR=\"$THEME->body\" WIDTH=10>";
|
|
|
|
$output .= " ";
|
|
|
|
$output .= "</TD><TD BGCOLOR=\"#FFFFFF\">\n";
|
|
|
|
|
|
|
|
$output .= text_to_html($post->message);
|
|
|
|
|
|
|
|
$output .= "<P ALIGN=right><FONT SIZE=-1>";
|
|
|
|
|
|
|
|
$age = time() - $post->created;
|
|
|
|
if ($ownpost) {
|
2002-08-02 17:34:26 +00:00
|
|
|
$output .= "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?delete=$post->id\">".get_string("delete", "forum")."</A>";
|
2002-07-31 14:19:35 +00:00
|
|
|
if ($reply) {
|
2002-08-02 17:34:26 +00:00
|
|
|
$output .= "| <A HREF=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."</A>";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
$output .= " ";
|
|
|
|
} else {
|
|
|
|
if ($reply) {
|
2002-08-02 17:34:26 +00:00
|
|
|
$output .= "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."</A> ";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= "<DIV ALIGN=right><P ALIGN=right>";
|
|
|
|
|
|
|
|
if ($link) {
|
|
|
|
if ($post->replies == 1) {
|
2002-08-02 17:34:26 +00:00
|
|
|
$replystring = get_string("repliesone", "forum", $post->replies);
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2002-08-02 17:34:26 +00:00
|
|
|
$replystring = get_string("repliesmany", "forum", $post->replies);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2002-08-02 17:34:26 +00:00
|
|
|
$output .= "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion\"><B>".get_string("discussthistopic", "forum")."</B></A> ($replystring) ";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
$output .= "</P></DIV>";
|
|
|
|
if ($footer) {
|
|
|
|
$output .= "<P>$footer</P>";
|
|
|
|
}
|
|
|
|
$output .= "</TD></TR></TABLE>\n";
|
|
|
|
$output .= "</TD></TR></TABLE>\n\n";
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false, $rate=false, $footer="") {
|
2002-07-31 15:43:02 +00:00
|
|
|
global $THEME, $USER, $CFG, $FORUM_LONG_POST;
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
if ($post->parent) {
|
|
|
|
echo "<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=1><TR><TD BGCOLOR=#888888>";
|
|
|
|
echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0>";
|
|
|
|
} else {
|
|
|
|
echo "<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=1 WIDTH=100%><TR><TD BGCOLOR=#888888>";
|
|
|
|
echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 WIDTH=100%>";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "<TR><TD BGCOLOR=\"$THEME->body\" WIDTH=35 VALIGN=TOP>";
|
|
|
|
print_user_picture($post->userid, $courseid, $post->picture);
|
|
|
|
echo "</TD>";
|
|
|
|
|
|
|
|
if ($post->parent) {
|
|
|
|
echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\">";
|
|
|
|
} else {
|
|
|
|
echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading2\">";
|
|
|
|
}
|
|
|
|
echo "<P>";
|
|
|
|
echo "<FONT SIZE=3><B>$post->subject</B></FONT><BR>";
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "<FONT SIZE=2>";
|
|
|
|
$by->name = "<A HREF=\"$CFG->wwwroot/user/view.php?id=$post->userid&course=$courseid\">$post->firstname $post->lastname</A>";
|
|
|
|
$by->date = userdate($post->created);
|
|
|
|
print_string("bynameondate", "forum", $by);
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "</FONT></P></TD></TR>";
|
|
|
|
echo "<TR><TD BGCOLOR=\"$THEME->body\" WIDTH=10>";
|
|
|
|
echo " ";
|
|
|
|
echo "</TD><TD BGCOLOR=\"#FFFFFF\">\n";
|
|
|
|
|
|
|
|
if ($link && (strlen($post->message) > $FORUM_LONG_POST)) {
|
2002-07-31 15:34:15 +00:00
|
|
|
// Print shortened version
|
|
|
|
echo text_to_html(forum_shorten_post($post->message));
|
2002-07-31 14:19:35 +00:00
|
|
|
$numwords = count_words($post->message);
|
2002-07-31 15:34:15 +00:00
|
|
|
echo "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion\">";
|
2002-08-02 17:34:26 +00:00
|
|
|
echo get_string("readtherest", "forum");
|
|
|
|
echo "</A> (".get_string("numwords", "forum", $numwords).")...";
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2002-07-31 15:34:15 +00:00
|
|
|
// Print whole message
|
2002-07-31 14:19:35 +00:00
|
|
|
echo text_to_html($post->message);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "<P ALIGN=right><FONT SIZE=-1>";
|
|
|
|
|
|
|
|
$age = time() - $post->created;
|
|
|
|
if ($ownpost) {
|
|
|
|
if ($age < $CFG->maxeditingtime) {
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?edit=$post->id\">".get_string("edit", "forum")."</A> | ";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2002-08-05 09:48:17 +00:00
|
|
|
}
|
|
|
|
if ($ownpost or isteacher($courseid)) {
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?delete=$post->id\">".get_string("delete", "forum")."</A>";
|
2002-07-31 14:19:35 +00:00
|
|
|
if ($reply) {
|
2002-08-05 09:48:17 +00:00
|
|
|
echo "| ";
|
|
|
|
} else {
|
|
|
|
echo " ";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2002-08-05 09:48:17 +00:00
|
|
|
}
|
|
|
|
if ($reply) {
|
|
|
|
echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."</A>";
|
2002-07-31 14:19:35 +00:00
|
|
|
echo " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
echo "<DIV ALIGN=right><P ALIGN=right>";
|
|
|
|
if ($rate && $USER->id) {
|
|
|
|
if ($USER->id == $post->userid) {
|
2002-08-02 09:50:53 +00:00
|
|
|
forum_print_ratings($post->id);
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2002-08-02 09:50:53 +00:00
|
|
|
forum_print_rating($post->id, $USER->id);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($link) {
|
|
|
|
if ($post->replies == 1) {
|
2002-08-02 17:34:26 +00:00
|
|
|
$replystring = get_string("repliesone", "forum", $post->replies);
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2002-08-02 17:34:26 +00:00
|
|
|
$replystring = get_string("repliesmany", "forum", $post->replies);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion\"><B>".get_string("discussthistopic", "forum")."</B></A> ($replystring) ";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
echo "</P>";
|
|
|
|
if ($footer) {
|
|
|
|
echo "<P>$footer</P>";
|
|
|
|
}
|
|
|
|
echo "</DIV>";
|
|
|
|
echo "</TD></TR></TABLE>";
|
|
|
|
echo "</TD></TR>\n</TABLE>\n\n";
|
|
|
|
}
|
|
|
|
|
2002-07-31 15:34:15 +00:00
|
|
|
function forum_shorten_post($message) {
|
2002-08-04 13:13:59 +00:00
|
|
|
global $FORUM_LONG_POST, $FORUM_SHORT_POST;
|
2002-07-31 15:34:15 +00:00
|
|
|
|
|
|
|
if (strlen($message) > $FORUM_LONG_POST) {
|
2002-08-04 13:13:59 +00:00
|
|
|
// Look for the first return between $FORUM_SHORT_POST and $FORUM_LONG_POST
|
|
|
|
$shortmessage = substr($message, $FORUM_SHORT_POST, $FORUM_LONG_POST);
|
2002-07-31 15:34:15 +00:00
|
|
|
if ($pos = strpos($shortmessage, "\n")) {
|
2002-08-04 13:13:59 +00:00
|
|
|
return substr($message, 0, $FORUM_SHORT_POST + $pos);
|
2002-07-31 15:34:15 +00:00
|
|
|
} else {
|
2002-08-02 17:34:26 +00:00
|
|
|
return substr($message, 0, $FORUM_LONG_POST)."...";
|
2002-07-31 15:34:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return $message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-02 09:50:53 +00:00
|
|
|
function forum_print_ratings($post) {
|
2002-07-31 14:19:35 +00:00
|
|
|
if ($ratings = get_records_sql("SELECT * from forum_ratings WHERE post='$post'")) {
|
2002-08-02 17:34:26 +00:00
|
|
|
$sumrating[1] = 0;
|
|
|
|
$sumrating[2] = 0;
|
|
|
|
$sumrating[3] = 0;
|
2002-07-31 14:19:35 +00:00
|
|
|
foreach ($ratings as $rating) {
|
2002-08-02 17:34:26 +00:00
|
|
|
$sumrating[$rating->rating]++;
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2002-08-02 17:34:26 +00:00
|
|
|
$summary = $sumrating[1]."s/".$sumrating[2]."/".$sumrating[3]."c";
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-02 17:34:26 +00:00
|
|
|
echo get_string("ratings", "forum").": ";
|
2002-07-31 14:19:35 +00:00
|
|
|
link_to_popup_window ("/mod/forum/report.php?id=$post", "ratings", $summary, 400, 550);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-02 09:50:53 +00:00
|
|
|
function forum_print_rating($post, $user) {
|
2002-07-31 14:19:35 +00:00
|
|
|
global $FORUM_POST_RATINGS;
|
|
|
|
|
|
|
|
if ($rs = get_record_sql("SELECT rating from forum_ratings WHERE user='$user' AND post='$post'")) {
|
|
|
|
if ($FORUM_POST_RATINGS[$rs->rating]) {
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "<FONT SIZE=-1>".get_string("youratedthis", "forum").": <FONT COLOR=green>";
|
2002-07-31 14:19:35 +00:00
|
|
|
echo $FORUM_POST_RATINGS[$rs->rating];
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "</FONT></FONT>";
|
|
|
|
return;
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-02 17:34:26 +00:00
|
|
|
choose_from_menu($FORUM_POST_RATINGS, $post, "", get_string("rate", "forum")."...");
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2002-08-02 09:50:53 +00:00
|
|
|
function forum_print_mode_form($discussion, $mode) {
|
|
|
|
GLOBAL $FORUM_LAYOUT_MODES;
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
echo "<CENTER><P>";
|
2002-08-02 09:50:53 +00:00
|
|
|
popup_form("discuss.php?d=$discussion&mode=", $FORUM_LAYOUT_MODES, "mode", $mode, "");
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "</P></CENTER>\n";
|
|
|
|
}
|
|
|
|
|
2002-08-02 09:50:53 +00:00
|
|
|
function forum_print_search_form($course, $search="") {
|
2002-07-31 14:19:35 +00:00
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
echo "<TABLE BORDER=0 CELLPADDING=10 CELLSPACING=0><TR><TD ALIGN=CENTER>";
|
|
|
|
echo "<FORM NAME=search ACTION=\"$CFG->wwwroot/mod/forum/search.php\">";
|
|
|
|
echo "<INPUT NAME=search TYPE=text SIZE=15 VALUE=\"$search\"><BR>";
|
|
|
|
echo "<INPUT VALUE=\"".get_string("search", "forum")."\" TYPE=submit>";
|
|
|
|
echo "<INPUT NAME=id TYPE=hidden VALUE=\"$course->id\">";
|
|
|
|
echo "</FORM>";
|
|
|
|
echo "</TD></TR></TABLE>";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_count_discussion_replies($forum="0") {
|
2002-07-31 14:19:35 +00:00
|
|
|
if ($forum) {
|
|
|
|
$forumselect = " AND d.forum = '$forum'";
|
|
|
|
}
|
|
|
|
return get_records_sql("SELECT p.discussion, (count(*)) as replies
|
|
|
|
FROM forum_posts p, forum_discussions d
|
|
|
|
WHERE p.parent > 0 AND p.discussion = d.id
|
|
|
|
GROUP BY p.discussion");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_set_return() {
|
2002-07-31 14:19:35 +00:00
|
|
|
global $SESSION, $HTTP_REFERER;
|
|
|
|
|
|
|
|
if (! $SESSION->fromdiscussion) {
|
|
|
|
$SESSION->fromdiscussion = $HTTP_REFERER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_go_back_to($default) {
|
2002-07-31 14:19:35 +00:00
|
|
|
global $SESSION;
|
|
|
|
|
|
|
|
if ($SESSION->fromdiscussion) {
|
|
|
|
$returnto = $SESSION->fromdiscussion;
|
|
|
|
unset($SESSION->fromdiscussion);
|
|
|
|
return $returnto;
|
|
|
|
} else {
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_get_post_full($postid) {
|
2002-07-31 14:19:35 +00:00
|
|
|
return get_record_sql("SELECT p.*, u.firstname, u.lastname,
|
|
|
|
u.email, u.picture, u.id as userid
|
|
|
|
FROM forum_posts p, user u
|
|
|
|
WHERE p.id = '$postid' AND p.user = u.id");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_add_new_post($post) {
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-02 17:34:26 +00:00
|
|
|
$post->created = $post->modified = time();
|
2002-07-31 14:19:35 +00:00
|
|
|
$post->mailed = "0";
|
|
|
|
|
|
|
|
return insert_record("forum_posts", $post);
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_update_post($post) {
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-02 17:34:26 +00:00
|
|
|
$post->modified = time();
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-02 17:34:26 +00:00
|
|
|
return update_record("forum_posts", $post);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function forum_add_discussion($discussion) {
|
|
|
|
// Given an object containing all the necessary data,
|
|
|
|
// create a new discussion and return the id
|
|
|
|
|
|
|
|
GLOBAL $USER;
|
|
|
|
|
|
|
|
$timenow = time();
|
|
|
|
|
|
|
|
// The first post is stored as a real post, and linked
|
|
|
|
// to from the discuss entry.
|
|
|
|
|
|
|
|
$post->discussion = 0;
|
|
|
|
$post->parent = 0;
|
|
|
|
$post->user = $USER->id;
|
|
|
|
$post->created = $timenow;
|
|
|
|
$post->modified = $timenow;
|
|
|
|
$post->mailed = 0;
|
|
|
|
$post->subject = $discussion->name;
|
|
|
|
$post->message = $discussion->intro;
|
|
|
|
|
|
|
|
if (! $post->id = insert_record("forum_posts", $post) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now do the real module entry
|
|
|
|
|
|
|
|
$discussion->firstpost = $post->id;
|
|
|
|
$discussion->timemodified = $timenow;
|
|
|
|
|
|
|
|
if (! $discussion->id = insert_record("forum_discussions", $discussion) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, set the pointer on the post.
|
|
|
|
if (! set_field("forum_posts", "discussion", $discussion->id, "id", $post->id)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $discussion->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function forum_delete_discussion($discussion) {
|
|
|
|
// $discussion is a discussion record object
|
|
|
|
|
|
|
|
$result = true;
|
|
|
|
|
|
|
|
if ($posts = get_records("forum_posts", "discussion", $discussion->id)) {
|
|
|
|
foreach ($posts as $post) {
|
|
|
|
if (! delete_records("forum_ratings", "post", "$post->id")) {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! delete_records("forum_posts", "discussion", "$discussion->id")) {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! delete_records("forum_discussions", "id", "$discussion->id")) {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-05 09:48:17 +00:00
|
|
|
function forum_delete_post($postid) {
|
|
|
|
if (delete_records("forum_posts", "id", $postid)) {
|
|
|
|
delete_records("forum_ratings", "post", $postid); // Just in case
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_print_user_discussions($courseid, $userid) {
|
2002-08-01 04:05:56 +00:00
|
|
|
global $CFG, $USER;
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-01 04:00:56 +00:00
|
|
|
$discussions = get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture,
|
2002-08-01 04:05:56 +00:00
|
|
|
u.id as userid, f.type as forumtype, f.name as forumname, f.id as forumid
|
2002-08-01 03:56:55 +00:00
|
|
|
FROM forum_discussions d, forum_posts p, user u, forum f
|
2002-08-01 03:50:27 +00:00
|
|
|
WHERE d.course = '$courseid' AND p.discussion = d.id AND
|
2002-08-01 03:56:55 +00:00
|
|
|
p.parent = 0 AND p.user = u.id AND u.id = '$userid' AND
|
|
|
|
d.forum = f.id
|
2002-08-01 04:00:56 +00:00
|
|
|
ORDER BY p.created ASC");
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
if ($discussions) {
|
2002-08-01 04:00:56 +00:00
|
|
|
$user = get_record("user", "id", $userid);
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "<HR>";
|
2002-08-02 17:34:26 +00:00
|
|
|
print_heading( get_string("discussionsstartedby", "forum", "$user->firstname $user->lastname") );
|
2002-08-01 03:50:27 +00:00
|
|
|
$replies = forum_count_discussion_replies();
|
|
|
|
foreach ($discussions as $discussion) {
|
2002-08-01 03:56:55 +00:00
|
|
|
if (($discussion->forumtype == "teacher") and !isteacher($courseid)) {
|
|
|
|
continue;
|
|
|
|
}
|
2002-08-01 03:50:27 +00:00
|
|
|
if ($replies[$discussion->discussion]) {
|
|
|
|
$discussion->replies = $replies[$discussion->discussion]->replies;
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2002-08-01 03:50:27 +00:00
|
|
|
$discussion->replies = 0;
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2002-08-02 17:34:26 +00:00
|
|
|
$inforum = get_string("inforum", "forum", "<A HREF=\"$CFG->wwwroot/mod/forum/view.php?f=$discussion->forumid\">$discussion->forumname</A>");
|
|
|
|
$discussion->subject .= " ($inforum)";
|
2002-08-01 03:50:27 +00:00
|
|
|
$ownpost = ($discussion->userid == $USER->id);
|
|
|
|
forum_print_post($discussion, $course->id, $ownpost, $reply=0, $link=1, $assessed=false);
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "<BR>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function forum_user_outline($course, $user, $mod, $forum) {
|
|
|
|
|
|
|
|
if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture
|
2002-07-31 16:52:27 +00:00
|
|
|
FROM forum f, forum_discussions d, forum_posts p, user u
|
|
|
|
WHERE f.id = '$forum->id' AND d.forum = f.id AND p.discussion = d.id
|
|
|
|
AND p.user = '$user->id' AND p.user = u.id
|
2002-07-31 14:19:35 +00:00
|
|
|
ORDER BY p.modified ASC")) {
|
|
|
|
|
2002-08-02 17:34:26 +00:00
|
|
|
$result->info = get_string("numposts", "forum", count($posts));
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
$lastpost = array_pop($posts);
|
|
|
|
$result->time = $lastpost->modified;
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function forum_user_complete($course, $user, $mod, $forum) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture
|
2002-07-31 16:52:27 +00:00
|
|
|
FROM forum f, forum_discussions d, forum_posts p, user u
|
|
|
|
WHERE f.id = '$forum->id' AND d.forum = f.id AND p.discussion = d.id
|
|
|
|
AND p.user = '$user->id' AND p.user = u.id
|
|
|
|
ORDER BY p.modified ASC")) {
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
foreach ($posts as $post) {
|
|
|
|
if ($post->parent) {
|
2002-08-02 17:34:26 +00:00
|
|
|
$footer = "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion&parent=$post->parent\">".
|
|
|
|
get_string("parentofthispost", "forum")."</A>";
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
|
|
|
$footer = "";
|
|
|
|
}
|
|
|
|
|
2002-08-04 17:13:49 +00:00
|
|
|
forum_print_post($post, $course->id, $ownpost=false, $reply=false, $link=false, $rate=false, $footer);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "<P>".get_string("noposts", "forum")."</P>";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-08-03 02:29:21 +00:00
|
|
|
|
|
|
|
function forum_add_instance($forum) {
|
|
|
|
// Given an object containing all the necessary data,
|
|
|
|
// (defined by the form in mod.html) this function
|
|
|
|
// will create a new instance and return the id number
|
|
|
|
// of the new instance.
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$forum->timemodified = time();
|
|
|
|
|
|
|
|
if (! $forum->id = insert_record("forum", $forum)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($forum->type == "single") { // Create related discussion.
|
|
|
|
|
|
|
|
$discussion->course = $forum->course;
|
|
|
|
$discussion->forum = $forum->id;
|
|
|
|
$discussion->name = $forum->name;
|
|
|
|
$discussion->intro = $forum->intro;
|
|
|
|
$discussion->assessed = $forum->assessed;
|
|
|
|
|
|
|
|
if (! forum_add_discussion($discussion)) {
|
|
|
|
error("Could not add the discussion for this forum");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_to_log($forum->course, "forum", "add", "index.php?f=$forum->id", "$forum->id");
|
|
|
|
|
|
|
|
return $forum->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function forum_update_instance($forum) {
|
|
|
|
// Given an object containing all the necessary data,
|
|
|
|
// (defined by the form in mod.html) this function
|
|
|
|
// will update an existing instance with new data.
|
|
|
|
|
|
|
|
$forum->timemodified = time();
|
|
|
|
$forum->id = $forum->instance;
|
|
|
|
|
|
|
|
if ($forum->type == "single") { // Update related discussion and post.
|
|
|
|
if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) {
|
|
|
|
if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) {
|
|
|
|
notify("Warning! There is more than one discussion in this forum - using the most recent");
|
|
|
|
$discussion = array_pop($discussions);
|
|
|
|
} else {
|
|
|
|
error("Could not find the discussion in this forum");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! $post = get_record("forum_posts", "id", $discussion->firstpost)) {
|
|
|
|
error("Could not find the first post in this forum discussion");
|
|
|
|
}
|
|
|
|
|
|
|
|
$post->subject = $forum->name;
|
|
|
|
$post->message = $forum->intro;
|
|
|
|
$post->modified = $forum->timemodified;
|
|
|
|
|
|
|
|
if (! update_record("forum_posts", $post)) {
|
|
|
|
error("Could not update the first post");
|
|
|
|
}
|
|
|
|
|
|
|
|
$discussion->name = $forum->name;
|
|
|
|
|
|
|
|
if (! update_record("forum_discussions", $discussion)) {
|
|
|
|
error("Could not update the discussion");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_record("forum", $forum)) {
|
|
|
|
add_to_log($forum->course, "forum", "update", "index.php?f=$forum->id", "$forum->id");
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function forum_delete_instance($id) {
|
|
|
|
// Given an ID of an instance of this module,
|
|
|
|
// this function will permanently delete the instance
|
|
|
|
// and any data that depends on it.
|
|
|
|
|
|
|
|
if (! $forum = get_record("forum", "id", "$id")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = true;
|
|
|
|
|
|
|
|
if ($discussions = get_records("forum_discussions", "forum", $forum->id)) {
|
|
|
|
foreach ($discussions as $discussion) {
|
|
|
|
if (! forum_delete_discussion($discussion)) {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! delete_records("forum_subscriptions", "forum", "$forum->id")) {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! delete_records("forum", "id", "$forum->id")) {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
function forum_cron () {
|
|
|
|
// Function to be run periodically according to the moodle cron
|
|
|
|
// Finds all posts that have yet to be mailed out, and mails them
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$cutofftime = time() - $CFG->maxeditingtime;
|
|
|
|
|
|
|
|
if ($posts = get_records_sql("SELECT p.*, d.course FROM forum_posts p, forum_discussions d
|
|
|
|
WHERE p.mailed = '0' AND p.created < '$cutofftime' AND p.discussion = d.id")) {
|
|
|
|
|
|
|
|
$timenow = time();
|
|
|
|
|
|
|
|
foreach ($posts as $post) {
|
|
|
|
|
2002-08-02 17:34:26 +00:00
|
|
|
print_string("processingpost", "forum", $post->id);
|
|
|
|
echo " ... ";
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
if (! $userfrom = get_record("user", "id", "$post->user")) {
|
|
|
|
echo "Could not find user $post->user\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $discussion = get_record("forum_discussions", "id", "$post->discussion")) {
|
|
|
|
echo "Could not find discussion $post->discussion\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $forum = get_record("forum", "id", "$discussion->forum")) {
|
|
|
|
echo "Could not find forum $discussion->forum\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-08-02 17:34:26 +00:00
|
|
|
if (! $course = get_record("course", "id", "$forum->course")) {
|
|
|
|
echo "Could not find course $forum->course\n";
|
|
|
|
continue;
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-02 17:34:26 +00:00
|
|
|
if ($users = get_course_users($course->id)) {
|
|
|
|
$strforums = get_string("forums", "forum");
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-02 17:34:26 +00:00
|
|
|
$mailcount=0;
|
2002-07-31 14:19:35 +00:00
|
|
|
foreach ($users as $userto) {
|
2002-08-02 17:34:26 +00:00
|
|
|
$by->name = "$userfrom->firstname $userfrom->lastname";
|
|
|
|
$by->date = userdate($post->created, "", $userto->timezone);
|
|
|
|
$strbynameondate = get_string("bynameondate", "forum", $by);
|
|
|
|
|
|
|
|
if (forum_is_subscribed($userto->id, $forum->id)) {
|
|
|
|
$postsubject = "$course->shortname: $post->subject";
|
|
|
|
$posttext = "$course->shortname -> $strforums -> $forum->name";
|
|
|
|
if ($discussion->name == $forum->name) {
|
|
|
|
$posttext .= "\n";
|
|
|
|
} else {
|
|
|
|
$posttext .= " -> $discussion->name\n";
|
|
|
|
}
|
|
|
|
$posttext .= "---------------------------------------------------------------------\n";
|
|
|
|
$posttext .= "$post->subject\n";
|
|
|
|
$posttext .= $strbynameondate."\n";
|
|
|
|
$posttext .= "---------------------------------------------------------------------\n";
|
|
|
|
$posttext .= strip_tags($post->message);
|
|
|
|
$posttext .= "\n\n";
|
|
|
|
$posttext .= "---------------------------------------------------------------------\n";
|
|
|
|
$posttext .= get_string("postmailinfo", "forum", $course->shortname)."\n";
|
|
|
|
$posttext .= "$CFG->wwwroot/mod/forum/post.php?reply=$post->id";
|
|
|
|
|
|
|
|
if ($userto->mailformat == 1) { // HTML
|
|
|
|
$posthtml = "<P><FONT FACE=sans-serif>".
|
|
|
|
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> ".
|
|
|
|
"<A HREF=\"$CFG->wwwroot/mod/forum/index.php?id=$course->id\">$strforums</A> -> ".
|
|
|
|
"<A HREF=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">$forum->name</A>";
|
|
|
|
if ($discussion->name == $forum->name) {
|
|
|
|
$posthtml .= "</FONT></P>";
|
|
|
|
} else {
|
|
|
|
$posthtml .= " -> <A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id\">$discussion->name</A></FONT></P>";
|
|
|
|
}
|
|
|
|
$posthtml .= forum_make_mail_post($post, $userfrom, $userto, $course, false, true, false, false);
|
|
|
|
} else {
|
|
|
|
$posthtml = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! email_to_user($userto, $userfrom, $postsubject, $posttext, $posthtml)) {
|
|
|
|
echo "Error: mod/forum/cron.php: Could not send out mail for id $post->id to user $userto->id ($userto->email)\n";
|
|
|
|
} else {
|
|
|
|
$mailcount++;
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "mailed to $mailcount users ...";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! set_field("forum_posts", "mailed", "1", "id", "$post->id")) {
|
|
|
|
echo "Could not update the mailed field for id $post->id\n";
|
|
|
|
}
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "\n";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function forum_forcesubscribe($forumid, $value=1) {
|
|
|
|
return set_field("forum", "forcesubscribe", $value, "id", $forumid);
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_is_forcesubscribed($forumid) {
|
|
|
|
return get_field("forum", "forcesubscribe", "id", $forumid);
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_is_subscribed($userid, $forumid) {
|
|
|
|
if (forum_is_forcesubscribed($forumid)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return record_exists_sql("SELECT * FROM forum_subscriptions WHERE user='$userid' AND forum='$forumid'");
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_subscribe($userid, $forumid) {
|
|
|
|
global $db;
|
|
|
|
|
|
|
|
return $db->Execute("INSERT INTO forum_subscriptions SET user = '$userid', forum = '$forumid'");
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_unsubscribe($userid, $forumid) {
|
|
|
|
global $db;
|
|
|
|
|
|
|
|
return $db->Execute("DELETE FROM forum_subscriptions WHERE user = '$userid' AND forum = '$forumid'");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_user_has_posted_discussion($forumid, $userid) {
|
|
|
|
if ($discussions = forum_get_discussions($forumid, "DESC", $userid)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_user_can_post_discussion($forum) {
|
2002-07-31 14:19:35 +00:00
|
|
|
// $forum is an object
|
|
|
|
global $USER;
|
|
|
|
|
|
|
|
if ($forum->type == "eachuser") {
|
2002-08-01 03:50:27 +00:00
|
|
|
return (! forum_user_has_posted_discussion($forum->id, $USER->id));
|
2002-07-31 14:19:35 +00:00
|
|
|
} else if ($forum->type == "teacher") {
|
|
|
|
return isteacher($forum->course);
|
|
|
|
} else if (isteacher($forum->course)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return $forum->open;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_get_discussions($forum="0", $forum_sort="DESC", $user=0) {
|
2002-07-31 14:19:35 +00:00
|
|
|
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 forum_discussions d, forum_posts p, user u
|
|
|
|
WHERE d.forum = '$forum' AND p.discussion = d.id AND
|
|
|
|
p.parent= 0 AND p.user = u.id $userselect
|
|
|
|
ORDER BY p.created $forum_sort");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $forum_style="plain", $forum_sort="DESC") {
|
2002-06-20 15:15:22 +00:00
|
|
|
global $CFG, $USER;
|
|
|
|
|
|
|
|
if ($forum_id) {
|
|
|
|
if (! $forum = get_record("forum", "id", $forum_id)) {
|
|
|
|
error("Forum ID was incorrect");
|
|
|
|
}
|
|
|
|
if (! $course = get_record("course", "id", $forum->course)) {
|
|
|
|
error("Could not find the course this forum belongs to!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($course->category) {
|
|
|
|
require_login($course->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (! $course = get_record("course", "category", 0)) {
|
|
|
|
error("Could not find a top-level course!");
|
|
|
|
}
|
2002-08-01 03:50:27 +00:00
|
|
|
if (! $forum = forum_get_course_news_forum($course->id)) {
|
2002-06-20 15:15:22 +00:00
|
|
|
error("Could not find or create a main forum in this course (id $course->id)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
if (forum_user_can_post_discussion($forum)) {
|
2002-08-01 09:38:45 +00:00
|
|
|
echo "<P ALIGN=CENTER>";
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?forum=$forum->id\">";
|
|
|
|
echo get_string("addanewdiscussion", "forum")."</A>...";
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "</P>\n";
|
2002-07-29 09:17:14 +00:00
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
if (! $discussions = forum_get_discussions($forum->id, $forum_sort) ) {
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "<P ALIGN=CENTER><B>(".get_string("nodiscussions", "forum").")</B></P>";
|
2002-06-20 15:15:22 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
$replies = forum_count_discussion_replies($forum->id);
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
$discussioncount = 0;
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
foreach ($discussions as $discussion) {
|
|
|
|
$discussioncount++;
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
if ($forum_numdiscussions && ($discussioncount > $forum_numdiscussions)) {
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "<P ALIGN=right><A HREF=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">";
|
|
|
|
echo get_string("olderdiscussions", "forum")."</A> ...</P>";
|
2002-06-20 15:15:22 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-08-01 03:50:27 +00:00
|
|
|
if ($replies[$discussion->discussion]) {
|
|
|
|
$discussion->replies = $replies[$discussion->discussion]->replies;
|
2002-06-20 15:15:22 +00:00
|
|
|
} else {
|
2002-08-01 03:50:27 +00:00
|
|
|
$discussion->replies = 0;
|
2002-06-20 15:15:22 +00:00
|
|
|
}
|
2002-08-01 03:50:27 +00:00
|
|
|
$ownpost = ($discussion->userid == $USER->id);
|
2002-06-20 15:15:22 +00:00
|
|
|
switch ($forum_style) {
|
|
|
|
case "minimal":
|
2002-08-01 03:50:27 +00:00
|
|
|
echo "<P><FONT COLOR=#555555>".userdate($discussion->modified, "%e %b, %H:%M")." - $discussion->firstname</FONT>";
|
|
|
|
echo "<BR>$discussion->subject ";
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->discussion\">";
|
|
|
|
echo get_string("more", "forum")."...</A>";
|
2002-06-20 15:15:22 +00:00
|
|
|
echo "</P>\n";
|
|
|
|
break;
|
|
|
|
default:
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_print_post($discussion, $forum->course, $ownpost, $reply=0, $link=1, $assessed=false);
|
2002-06-20 15:15:22 +00:00
|
|
|
echo "<BR>\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_print_discussion($course, $discussion, $post, $mode) {
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
global $USER;
|
|
|
|
|
|
|
|
$ownpost = ($USER->id == $post->user);
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_print_post($post, $course->id, $ownpost, $reply=true, $link=false, $rate=false);
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-02 09:50:53 +00:00
|
|
|
forum_print_mode_form($discussion->id, $mode);
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
if ($discussion->assessed && $USER->id) {
|
|
|
|
echo "<FORM NAME=form METHOD=POST ACTION=rate.php>";
|
|
|
|
echo "<INPUT TYPE=hidden NAME=id VALUE=\"$course->id\">";
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($mode) {
|
|
|
|
case 1 : // Flat ascending
|
|
|
|
case -1 : // Flat descending
|
|
|
|
default:
|
|
|
|
echo "<UL>";
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_print_posts_flat($post->discussion, $course->id, $mode, $discussion->assessed);
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "</UL>";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2 : // Threaded
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_print_posts_threaded($post->id, $course->id, 0, $discussion->assessed);
|
2002-07-31 14:19:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3 : // Nested
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_print_posts_nested($post->id, $course->id, $discussion->assessed);
|
2002-07-31 14:19:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($discussion->assessed && $USER->id) {
|
2002-08-02 19:01:14 +00:00
|
|
|
echo "<CENTER><P ALIGN=center><INPUT TYPE=submit VALUE=\"".get_string("sendinratings", "forum")."\"></P></CENTER>";
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "</FORM>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_print_posts_flat($discussion, $course, $direction, $assessed) {
|
2002-07-31 14:19:35 +00:00
|
|
|
global $USER;
|
|
|
|
|
|
|
|
$reply = true;
|
|
|
|
$link = false;
|
|
|
|
|
|
|
|
if ($direction < 0) {
|
|
|
|
$sort = "ORDER BY created DESC";
|
|
|
|
} else {
|
|
|
|
$sort = "ORDER BY created ASC";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture
|
|
|
|
FROM forum_posts p, user u
|
|
|
|
WHERE p.discussion = $discussion AND p.parent > 0 AND p.user = u.id $sort")) {
|
|
|
|
|
|
|
|
foreach ($posts as $post) {
|
|
|
|
$ownpost = ($USER->id == $post->user);
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_print_post($post, $course, $ownpost, $reply, $link, $assessed);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_print_posts_threaded($parent, $course, $depth, $assessed) {
|
2002-07-31 14:19:35 +00:00
|
|
|
global $USER;
|
|
|
|
|
|
|
|
$reply = true;
|
|
|
|
$link = false;
|
|
|
|
|
|
|
|
if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture
|
|
|
|
FROM forum_posts p, user u
|
|
|
|
WHERE p.parent = '$parent' AND p.user = u.id")) {
|
|
|
|
|
|
|
|
foreach ($posts as $post) {
|
|
|
|
|
|
|
|
echo "<UL>";
|
|
|
|
if ($depth > 0) {
|
|
|
|
$ownpost = ($USER->id == $post->user);
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_print_post($post, $course, $ownpost, $reply, $link, $assessed); // link=true?
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "<BR>";
|
|
|
|
} else {
|
2002-08-02 19:01:14 +00:00
|
|
|
$by->name = "$post->firstname $post->lastname";
|
|
|
|
$by->date = userdate($post->created);
|
|
|
|
echo "<LI><P><FONT SIZE=-1><B><A HREF=\"discuss.php?d=$post->discussion&parent=$post->id\">$post->subject</A></B> ";
|
|
|
|
print_string("bynameondate", "forum", $by);
|
|
|
|
echo "</FONT></P></LI>";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_print_posts_threaded($post->id, $course, $depth-1, $assessed);
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "</UL>\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_print_posts_nested($parent, $course, $assessed) {
|
2002-07-31 14:19:35 +00:00
|
|
|
global $USER;
|
|
|
|
|
|
|
|
$reply = true;
|
|
|
|
$link = false;
|
|
|
|
|
|
|
|
if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture
|
|
|
|
FROM forum_posts p, user u
|
|
|
|
WHERE p.parent = $parent AND p.user = u.id
|
|
|
|
ORDER BY p.created ASC ")) {
|
|
|
|
|
|
|
|
foreach ($posts as $post) {
|
|
|
|
|
|
|
|
$ownpost = ($USER->id == $post->user);
|
|
|
|
|
|
|
|
echo "<UL>";
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_print_post($post, $course, $ownpost, $reply, $link, $assessed);
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "<BR>";
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_print_posts_nested($post->id, $course, $assessed);
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "</UL>\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_set_display_mode($mode=0) {
|
|
|
|
global $USER;
|
|
|
|
|
|
|
|
if ($mode) {
|
|
|
|
$USER->mode = $mode;
|
|
|
|
} else if (!$USER->mode) {
|
|
|
|
$USER->mode = $FORUM_DEFAULT_DISPLAY_MODE;
|
|
|
|
}
|
|
|
|
}
|
2002-06-20 15:15:22 +00:00
|
|
|
|
|
|
|
?>
|