2002-06-20 15:15:22 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
2002-09-01 14:34:38 +00:00
|
|
|
include_once("$CFG->dirroot/files/mimetypes.php");
|
|
|
|
|
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-10-03 11:15:50 +00:00
|
|
|
$FORUM_OPEN_MODES = array ("2" => get_string("openmode2", "forum"),
|
|
|
|
"1" => get_string("openmode1", "forum"),
|
|
|
|
"0" => get_string("openmode0", "forum") );
|
|
|
|
|
2002-10-10 07:27:57 +00:00
|
|
|
|
2002-10-26 03:21:41 +00:00
|
|
|
define("FORUM_SHORT_POST", 300); // Less non-HTML characters than this is short
|
2002-08-04 13:13:59 +00:00
|
|
|
|
2002-10-26 03:21:41 +00:00
|
|
|
define("FORUM_LONG_POST", 600); // More non-HTML characters than this is long
|
2002-08-04 13:13:59 +00:00
|
|
|
|
2002-10-26 03:21:41 +00:00
|
|
|
define("FORUM_MANY_DISCUSSIONS", 10);
|
2002-06-25 06:47:34 +00:00
|
|
|
|
|
|
|
|
2002-10-21 08:10:24 +00:00
|
|
|
/// STANDARD FUNCTIONS ///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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, $USER;
|
|
|
|
|
|
|
|
$cutofftime = time() - $CFG->maxeditingtime;
|
|
|
|
|
2002-12-23 07:01:06 +00:00
|
|
|
if ($posts = forum_get_unmailed_posts($cutofftime)) {
|
2002-10-21 08:10:24 +00:00
|
|
|
|
|
|
|
$timenow = time();
|
|
|
|
|
|
|
|
foreach ($posts as $post) {
|
|
|
|
|
|
|
|
print_string("processingpost", "forum", $post->id);
|
|
|
|
echo " ... ";
|
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
if (! $userfrom = get_record("user", "id", "$post->userid")) {
|
|
|
|
echo "Could not find user $post->userid\n";
|
2002-10-21 08:10:24 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $course = get_record("course", "id", "$forum->course")) {
|
|
|
|
echo "Could not find course $forum->course\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($users = forum_subscribed_users($course, $forum)) {
|
|
|
|
$canunsubscribe = ! forum_is_forcesubscribed($forum->id);
|
|
|
|
|
|
|
|
$mailcount=0;
|
|
|
|
foreach ($users as $userto) {
|
|
|
|
$USER->lang = $userto->lang; // Affects the language of get_string
|
2002-10-25 06:50:40 +00:00
|
|
|
$canreply = forum_user_can_post($forum, $userto);
|
2002-10-21 08:10:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
$by->name = "$userfrom->firstname $userfrom->lastname";
|
|
|
|
$by->date = userdate($post->created, "", $userto->timezone);
|
|
|
|
$strbynameondate = get_string("bynameondate", "forum", $by);
|
|
|
|
|
|
|
|
$strforums = get_string("forums", "forum");
|
|
|
|
|
|
|
|
$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";
|
|
|
|
if ($post->attachment) {
|
|
|
|
$post->course = $course->id;
|
|
|
|
$post->forum = $forum->id;
|
|
|
|
$posttext .= forum_print_attachments($post, "text");
|
|
|
|
}
|
2002-10-25 06:50:40 +00:00
|
|
|
if ($canreply) {
|
|
|
|
$posttext .= "---------------------------------------------------------------------\n";
|
|
|
|
$posttext .= get_string("postmailinfo", "forum", $course->shortname)."\n";
|
|
|
|
$posttext .= "$CFG->wwwroot/mod/forum/post.php?reply=$post->id\n";
|
|
|
|
}
|
2002-10-21 08:10:24 +00:00
|
|
|
if ($canunsubscribe) {
|
|
|
|
$posttext .= "\n---------------------------------------------------------------------\n";
|
|
|
|
$posttext .= get_string("unsubscribe", "forum");
|
|
|
|
$posttext .= ": $CFG->wwwroot/mod/forum/subscribe.php?id=$forum->id\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($userto->mailformat == 1) { // HTML
|
|
|
|
$posthtml = "<P><FONT FACE=sans-serif>".
|
2002-10-25 15:27:12 +00:00
|
|
|
"<A TARGET=\"_blank\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> ".
|
|
|
|
"<A TARGET=\"_blank\" HREF=\"$CFG->wwwroot/mod/forum/index.php?id=$course->id\">$strforums</A> -> ".
|
|
|
|
"<A TARGET=\"_blank\" HREF=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">$forum->name</A>";
|
2002-10-21 08:10:24 +00:00
|
|
|
if ($discussion->name == $forum->name) {
|
|
|
|
$posthtml .= "</FONT></P>";
|
|
|
|
} else {
|
2002-10-25 15:27:12 +00:00
|
|
|
$posthtml .= " -> <A TARGET=\"_blank\" HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id\">$discussion->name</A></FONT></P>";
|
2002-10-21 08:10:24 +00:00
|
|
|
}
|
2002-10-25 06:50:40 +00:00
|
|
|
$posthtml .= forum_make_mail_post($post, $userfrom, $userto, $course, false, $canreply, false, false);
|
2002-10-21 08:10:24 +00:00
|
|
|
|
|
|
|
if ($canunsubscribe) {
|
|
|
|
$posthtml .= "\n<BR><HR SIZE=1 NOSHADE><P ALIGN=RIGHT><FONT SIZE=1><A HREF=\"$CFG->wwwroot/mod/forum/subscribe.php?id=$forum->id\">".get_string("unsubscribe", "forum")."</A></FONT></P>";
|
|
|
|
}
|
|
|
|
|
|
|
|
} 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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "mailed to $mailcount users ...";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! set_field("forum_posts", "mailed", "1", "id", "$post->id")) {
|
|
|
|
echo "Could not update the mailed field for id $post->id\n";
|
|
|
|
}
|
|
|
|
echo "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_user_outline($course, $user, $mod, $forum) {
|
|
|
|
|
2002-12-23 07:01:06 +00:00
|
|
|
if ($posts = forum_get_user_posts($forum->id, $user->id)) {
|
2002-10-21 08:10:24 +00:00
|
|
|
$result->info = get_string("numposts", "forum", count($posts));
|
|
|
|
|
|
|
|
$lastpost = array_pop($posts);
|
|
|
|
$result->time = $lastpost->modified;
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function forum_user_complete($course, $user, $mod, $forum) {
|
|
|
|
global $CFG;
|
|
|
|
|
2002-12-23 07:01:06 +00:00
|
|
|
if ($posts = forum_get_user_posts($forum->id, $user->id)) {
|
2002-10-21 08:10:24 +00:00
|
|
|
foreach ($posts as $post) {
|
|
|
|
if ($post->parent) {
|
|
|
|
$footer = "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion&parent=$post->parent\">".
|
|
|
|
get_string("parentofthispost", "forum")."</A>";
|
|
|
|
} else {
|
|
|
|
$footer = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
forum_print_post($post, $course->id, $ownpost=false, $reply=false, $link=false, $rate=false, $footer);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
echo "<P>".get_string("noposts", "forum")."</P>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_print_recent_activity(&$logs, $isteacher=false) {
|
|
|
|
global $CFG, $COURSE_TEACHER_COLOR;
|
|
|
|
|
|
|
|
$heading = false;
|
|
|
|
$content = false;
|
|
|
|
|
|
|
|
foreach ($logs as $log) {
|
|
|
|
if ($log->module == "forum") {
|
|
|
|
|
2002-12-23 07:01:06 +00:00
|
|
|
if ($post = forum_get_post_from_log($log)) {
|
2002-10-21 08:10:24 +00:00
|
|
|
$teacherpost = "";
|
|
|
|
if ($forum = get_record("forum", "id", $post->forum) ) {
|
|
|
|
if ($forum->type == "teacher") {
|
|
|
|
if ($isteacher) {
|
|
|
|
$teacherpost = "COLOR=$COURSE_TEACHER_COLOR";
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! $heading) {
|
|
|
|
print_headline(get_string("newforumposts", "forum").":");
|
|
|
|
$heading = true;
|
|
|
|
$content = true;
|
|
|
|
}
|
2002-11-19 14:27:57 +00:00
|
|
|
$date = userdate($post->modified, "%d %b, %H:%M");
|
2002-10-21 08:10:24 +00:00
|
|
|
echo "<P><FONT SIZE=1 $teacherpost>$date - $post->firstname $post->lastname<BR>";
|
|
|
|
echo "\"<A HREF=\"$CFG->wwwroot/mod/forum/$log->url\">";
|
|
|
|
if ($log->action == "add") {
|
|
|
|
echo "<B>$post->subject</B>";
|
|
|
|
} else {
|
|
|
|
echo "$post->subject";
|
|
|
|
}
|
|
|
|
echo "</A>\"</FONT></P>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function forum_grades($forumid) {
|
|
|
|
/// Must return an array of grades, indexed by user, and a max grade.
|
|
|
|
global $FORUM_POST_RATINGS;
|
|
|
|
|
2002-10-21 08:19:15 +00:00
|
|
|
if (!$forum = get_record("forum", "id", $forumid)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!$forum->assessed) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-12-23 07:01:06 +00:00
|
|
|
if ($ratings = forum_get_user_grades($forumid)) {
|
2002-10-21 08:32:37 +00:00
|
|
|
foreach ($ratings as $rating) {
|
2002-12-23 09:39:26 +00:00
|
|
|
$u = $rating->userid;
|
2002-10-21 08:32:37 +00:00
|
|
|
$r = $rating->rating;
|
|
|
|
if (!isset($sumrating[$u])) {
|
|
|
|
$sumrating[$u][1] = 0;
|
|
|
|
$sumrating[$u][2] = 0;
|
|
|
|
$sumrating[$u][3] = 0;
|
2002-10-21 08:10:24 +00:00
|
|
|
}
|
2002-10-21 08:32:37 +00:00
|
|
|
$sumrating[$u][$r]++;
|
2002-10-21 08:10:24 +00:00
|
|
|
}
|
|
|
|
foreach ($sumrating as $user => $rating) {
|
|
|
|
$return->grades[$user] = $rating[1]."s/".$rating[2]."/".$rating[3]."c";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$return->grades = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$return->maxgrade = "";
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
/// SQL FUNCTIONS ///////////////////////////////////////////////////////////
|
|
|
|
|
2002-12-23 07:01:06 +00:00
|
|
|
function forum_get_post_full($postid) {
|
|
|
|
/// Gets a post with all info ready for forum_print_post
|
|
|
|
global $CFG;
|
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
return get_record_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture
|
2002-12-23 07:01:06 +00:00
|
|
|
FROM {$CFG->prefix}forum_posts p,
|
|
|
|
{$CFG->prefix}user u
|
|
|
|
WHERE p.id = '$postid'
|
2002-12-23 09:39:26 +00:00
|
|
|
AND p.userid = u.id");
|
2002-12-23 07:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function forum_get_discussion_posts($discussion, $sort) {
|
|
|
|
/// Gets posts with all info ready for forum_print_post
|
|
|
|
global $CFG;
|
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture
|
2002-12-23 07:01:06 +00:00
|
|
|
FROM {$CFG->prefix}forum_posts p,
|
|
|
|
{$CFG->prefix}user u
|
|
|
|
WHERE p.discussion = $discussion
|
|
|
|
AND p.parent > 0
|
2002-12-23 09:39:26 +00:00
|
|
|
AND p.userid = u.id $sort");
|
2002-12-23 07:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function forum_get_child_posts($parent) {
|
|
|
|
/// Gets posts with all info ready for forum_print_post
|
|
|
|
global $CFG;
|
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture
|
2002-12-23 07:01:06 +00:00
|
|
|
FROM {$CFG->prefix}forum_posts p,
|
|
|
|
{$CFG->prefix}user u
|
|
|
|
WHERE p.parent = '$parent'
|
2002-12-23 09:39:26 +00:00
|
|
|
AND p.userid = u.id
|
2002-12-23 07:01:06 +00:00
|
|
|
ORDER BY p.created ASC");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-23 15:33:40 +00:00
|
|
|
function forum_search_posts($search, $courseid, $page=0, $recordsperpage=50) {
|
2002-12-20 14:44:14 +00:00
|
|
|
/// Returns a list of posts that were found
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if (!isteacher($courseid)) {
|
|
|
|
$notteacherforum = "AND f.type <> 'teacher'";
|
|
|
|
} else {
|
|
|
|
$notteacherforum = "";
|
|
|
|
}
|
|
|
|
|
2002-12-23 15:33:40 +00:00
|
|
|
if ($CFG->dbtype == "mysql") {
|
|
|
|
$limit = "LIMIT $page,$recordsperpage";
|
|
|
|
} else {
|
|
|
|
$limit = "LIMIT $recordsperpage,$page";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
return get_records_sql("SELECT p.*,u.firstname,u.lastname,u.email,u.picture
|
2002-12-20 14:44:14 +00:00
|
|
|
FROM {$CFG->prefix}forum_posts p,
|
|
|
|
{$CFG->prefix}forum_discussions d,
|
|
|
|
{$CFG->prefix}user u,
|
|
|
|
{$CFG->prefix}forum f
|
|
|
|
WHERE (p.message LIKE '%$search%' OR p.subject LIKE '%$search%')
|
2002-12-23 09:39:26 +00:00
|
|
|
AND p.userid = u.id
|
2002-12-20 14:44:14 +00:00
|
|
|
AND p.discussion = d.id
|
|
|
|
AND d.course = '$courseid'
|
|
|
|
AND d.forum = f.id
|
|
|
|
$notteacherforum
|
2002-12-23 15:33:40 +00:00
|
|
|
ORDER BY p.modified DESC $limit");
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function forum_get_ratings($postid, $sort="u.firstname ASC") {
|
|
|
|
/// Returns a list of ratings for a particular post - sorted.
|
|
|
|
global $CFG;
|
|
|
|
return get_records_sql("SELECT u.*, r.rating, r.time
|
|
|
|
FROM {$CFG->prefix}forum_ratings r,
|
|
|
|
{$CFG->prefix}user u
|
2002-12-23 07:01:06 +00:00
|
|
|
WHERE r.post = '$postid'
|
2002-12-23 09:39:26 +00:00
|
|
|
AND r.userid = u.id
|
2002-12-20 14:44:14 +00:00
|
|
|
ORDER BY $sort");
|
|
|
|
}
|
|
|
|
|
2002-12-23 07:01:06 +00:00
|
|
|
function forum_get_unmailed_posts($cutofftime) {
|
|
|
|
/// Returns a list of all new posts that have not been mailed yet
|
|
|
|
global $CFG;
|
|
|
|
return get_records_sql("SELECT p.*, d.course
|
|
|
|
FROM {$CFG->prefix}forum_posts p,
|
|
|
|
{$CFG->prefix}forum_discussions d
|
|
|
|
WHERE p.mailed = 0
|
|
|
|
AND p.created < '$cutofftime'
|
|
|
|
AND p.discussion = d.id");
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_get_user_posts($forumid, $userid) {
|
|
|
|
/// Get all the posts for a user in a forum suitable for forum_print_post
|
|
|
|
global $CFG;
|
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture
|
2002-12-23 07:01:06 +00:00
|
|
|
FROM {$CFG->prefix}forum f,
|
|
|
|
{$CFG->prefix}forum_discussions d,
|
|
|
|
{$CFG->prefix}forum_posts p,
|
|
|
|
{$CFG->prefix}user u
|
|
|
|
WHERE f.id = '$forumid'
|
|
|
|
AND d.forum = f.id
|
|
|
|
AND p.discussion = d.id
|
2002-12-23 09:39:26 +00:00
|
|
|
AND p.userid = '$userid'
|
|
|
|
AND p.userid = u.id
|
2002-12-23 07:01:06 +00:00
|
|
|
ORDER BY p.modified ASC");
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_get_post_from_log($log) {
|
|
|
|
/// Given a log entry, return the forum post details for it.
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($log->action == "add post") {
|
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
return get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname, u.email, u.picture
|
2002-12-23 07:01:06 +00:00
|
|
|
FROM {$CFG->prefix}forum_discussions d,
|
|
|
|
{$CFG->prefix}forum_posts p,
|
|
|
|
{$CFG->prefix}user u
|
|
|
|
WHERE p.id = '$log->info'
|
|
|
|
AND d.id = p.discussion
|
2002-12-23 09:39:26 +00:00
|
|
|
AND p.userid = u.id
|
2002-12-23 07:01:06 +00:00
|
|
|
AND u.deleted <> '1'");
|
|
|
|
|
|
|
|
|
|
|
|
} else if ($log->action == "add discussion") {
|
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
return get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname, u.email, u.picture
|
2002-12-23 07:01:06 +00:00
|
|
|
FROM {$CFG->prefix}forum_discussions d,
|
|
|
|
{$CFG->prefix}forum_posts p,
|
|
|
|
{$CFG->prefix}user u
|
|
|
|
WHERE d.id = '$log->info'
|
|
|
|
AND d.firstpost = p.id
|
2002-12-23 09:39:26 +00:00
|
|
|
AND p.userid = u.id
|
2002-12-23 07:01:06 +00:00
|
|
|
AND u.deleted <> '1'");
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function forum_get_user_grades($forumid) {
|
|
|
|
/// Get all user grades for a forum
|
|
|
|
global $CFG;
|
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
return get_records_sql("SELECT r.id, p.userid, r.rating
|
2002-12-23 07:01:06 +00:00
|
|
|
FROM {$CFG->prefix}forum_discussions d,
|
|
|
|
{$CFG->prefix}forum_posts p,
|
|
|
|
{$CFG->prefix}forum_ratings r
|
|
|
|
WHERE d.forum = '$forumid'
|
|
|
|
AND p.discussion = d.id
|
|
|
|
AND r.post = p.id");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function forum_count_discussion_replies($forum="0") {
|
|
|
|
// Returns an array of counts of replies to each discussion (optionally in one forum)
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($forum) {
|
|
|
|
$forumselect = " AND d.forum = '$forum'";
|
|
|
|
}
|
|
|
|
return get_records_sql("SELECT p.discussion, (count(*)) as replies
|
|
|
|
FROM {$CFG->prefix}forum_posts p,
|
|
|
|
{$CFG->prefix}forum_discussions d
|
|
|
|
WHERE p.parent > 0
|
|
|
|
AND p.discussion = d.id
|
|
|
|
GROUP BY p.discussion");
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_count_unrated_posts($discussionid, $userid) {
|
|
|
|
// How many unrated posts are in the given discussion for a given user?
|
|
|
|
global $CFG;
|
|
|
|
if ($posts = get_record_sql("SELECT count(*) as num
|
|
|
|
FROM {$CFG->prefix}forum_posts
|
|
|
|
WHERE parent > 0
|
|
|
|
AND discussion = '$discussionid'
|
2002-12-23 09:39:26 +00:00
|
|
|
AND userid <> '$userid' ")) {
|
2002-12-23 07:01:06 +00:00
|
|
|
|
|
|
|
if ($rated = get_record_sql("SELECT count(*) as num
|
|
|
|
FROM {$CFG->prefix}forum_posts p,
|
|
|
|
{$CFG->prefix}forum_ratings r
|
|
|
|
WHERE p.discussion = '$discussionid'
|
|
|
|
AND p.id = r.post
|
2002-12-23 09:39:26 +00:00
|
|
|
AND r.userid = '$userid'")) {
|
2002-12-23 07:01:06 +00:00
|
|
|
$difference = $posts->num - $rated->num;
|
|
|
|
if ($difference > 0) {
|
|
|
|
return $difference;
|
|
|
|
} else {
|
|
|
|
return 0; // Just in case there was a counting error
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return $posts->num;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_get_discussions($forum="0", $forum_sort="DESC", $user=0) {
|
|
|
|
/// Get all discussions in a forum
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($user) {
|
|
|
|
$userselect = " AND u.id = '$user' ";
|
|
|
|
} else {
|
|
|
|
$userselect = "";
|
|
|
|
}
|
2002-12-23 09:39:26 +00:00
|
|
|
return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture
|
2002-12-23 07:01:06 +00:00
|
|
|
FROM {$CFG->prefix}forum_discussions d,
|
|
|
|
{$CFG->prefix}forum_posts p,
|
|
|
|
{$CFG->prefix}user u
|
|
|
|
WHERE d.forum = '$forum'
|
|
|
|
AND p.discussion = d.id
|
|
|
|
AND p.parent= 0
|
2002-12-23 09:39:26 +00:00
|
|
|
AND p.userid = u.id $userselect
|
2002-12-23 07:01:06 +00:00
|
|
|
ORDER BY p.created $forum_sort");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function forum_get_user_discussions($courseid, $userid) {
|
|
|
|
/// Get all discussions started by a particular user in a course
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture,
|
2002-12-23 09:39:26 +00:00
|
|
|
f.type as forumtype, f.name as forumname, f.id as forumid
|
2002-12-23 07:01:06 +00:00
|
|
|
FROM {$CFG->prefix}forum_discussions d,
|
|
|
|
{$CFG->prefix}forum_posts p,
|
|
|
|
{$CFG->prefix}user u,
|
|
|
|
{$CFG->prefix}forum f
|
|
|
|
WHERE d.course = '$courseid'
|
|
|
|
AND p.discussion = d.id
|
|
|
|
AND p.parent = 0
|
2002-12-23 09:39:26 +00:00
|
|
|
AND p.userid = u.id
|
2002-12-23 07:01:06 +00:00
|
|
|
AND u.id = '$userid'
|
|
|
|
AND d.forum = f.id
|
|
|
|
ORDER BY p.created ASC");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function forum_subscribed_users($course, $forum) {
|
|
|
|
/// Returns list of user objects that are subscribed to this forum
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($course->category) { // normal course
|
|
|
|
if ($forum->forcesubscribe) {
|
|
|
|
return get_course_users($course->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return get_records_sql("SELECT u.*
|
|
|
|
FROM {$CFG->prefix}user u,
|
|
|
|
{$CFG->prefix}forum_subscriptions s
|
|
|
|
WHERE s.forum = '$forum->id'
|
2002-12-23 09:39:26 +00:00
|
|
|
AND s.userid = u.id
|
2002-12-23 07:01:06 +00:00
|
|
|
AND u.deleted <> 1");
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
|
|
|
|
|
2002-10-21 08:10:24 +00:00
|
|
|
/// OTHER 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
|
2002-11-14 02:33:48 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2002-12-23 07:01:06 +00:00
|
|
|
if ($forum = get_record("forum", "course", $courseid, "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");
|
2002-10-03 11:15:50 +00:00
|
|
|
$forum->open = 1; // 0 - no, 1 - posts only, 2 - discuss and post
|
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");
|
2002-10-03 11:15:50 +00:00
|
|
|
$forum->open = 2; // 0 - no, 1 - posts only, 2 - discuss and post
|
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");
|
2002-10-03 11:15:50 +00:00
|
|
|
$forum->open = 0; // 0 - no, 1 - posts only, 2 - discuss and post
|
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);
|
2002-10-25 09:10:40 +00:00
|
|
|
|
|
|
|
if ($forum->type != "teacher") {
|
|
|
|
if (! $module = get_record("modules", "name", "forum")) {
|
|
|
|
notify("Could not find forum module!!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$mod->course = $courseid;
|
|
|
|
$mod->module = $module->id;
|
|
|
|
$mod->instance = $forum->id;
|
|
|
|
$mod->section = 0;
|
|
|
|
if (! $mod->coursemodule = add_course_module($mod) ) { // assumes course/lib.php is loaded
|
|
|
|
notify("Could not add a new course module to the course '$course->fullname'");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (! $sectionid = add_mod_to_section($mod) ) { // assumes course/lib.php is loaded
|
|
|
|
notify("Could not add the new course module to that section");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
|
|
|
|
notify("Could not update the course module with the correct section");
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-14 02:33:48 +00:00
|
|
|
include_once("$CFG->dirroot/course/lib.php");
|
|
|
|
$modinfo = serialize(get_array_of_activities($courseid));
|
|
|
|
if (!set_field("course", "modinfo", $modinfo, "id", $courseid)) {
|
|
|
|
error("Could not cache module information!");
|
|
|
|
}
|
2002-10-25 09:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return get_record("forum", "id", "$forum->id");
|
2002-07-04 08:30:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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%>";
|
|
|
|
}
|
|
|
|
|
2002-12-09 10:49:44 +00:00
|
|
|
$output .= "<TR><TD BGCOLOR=\"$THEME->cellcontent2\" WIDTH=35 VALIGN=TOP>";
|
2002-07-31 14:19:35 +00:00
|
|
|
$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>";
|
2002-12-09 10:49:44 +00:00
|
|
|
$output .= "<TR><TD BGCOLOR=\"$THEME->cellcontent2\" WIDTH=10>";
|
2002-07-31 14:19:35 +00:00
|
|
|
$output .= " ";
|
2002-08-15 04:16:39 +00:00
|
|
|
$output .= "</TD><TD BGCOLOR=\"$THEME->cellcontent\">\n";
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-09-01 14:34:38 +00:00
|
|
|
if ($post->attachment) {
|
|
|
|
$post->course = $course->id;
|
|
|
|
$post->forum = get_field("forum_discussions", "forum", "id", $post->discussion);
|
|
|
|
$output .= "<DIV ALIGN=right>";
|
|
|
|
$output .= forum_print_attachments($post, "html");
|
|
|
|
$output .= "</DIV>";
|
|
|
|
}
|
|
|
|
|
2002-10-10 07:27:57 +00:00
|
|
|
$output .= format_text($post->message, $post->format);
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-10-25 05:58:39 +00:00
|
|
|
$output .= "<P ALIGN=right><FONT SIZE=-1>";
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
$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-10-25 15:27:12 +00:00
|
|
|
$output .= " | <A TARGET=\"_blank\" 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-10-25 15:27:12 +00:00
|
|
|
$output .= "<A TARGET=\"_blank\" HREF=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."</A> ";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-11 05:20:23 +00:00
|
|
|
$output .= "</P>";
|
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-10-26 03:21:41 +00:00
|
|
|
global $THEME, $USER, $CFG;
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
if ($post->parent) {
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 CLASS=\"forumpost\">";
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 CLASS=\"forumpost\" WIDTH=100%>";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "<TR><TD BGCOLOR=\"$THEME->cellcontent2\" CLASS=\"forumpostpicture\" WIDTH=35 VALIGN=TOP>";
|
2002-07-31 14:19:35 +00:00
|
|
|
print_user_picture($post->userid, $courseid, $post->picture);
|
|
|
|
echo "</TD>";
|
|
|
|
|
|
|
|
if ($post->parent) {
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\" CLASS=\"forumpostheader\" WIDTH=\"100%\">";
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading2\" CLASS=\"forumpostheadertopic\" WIDTH=\"100%*\">";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
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>";
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "<TR><TD BGCOLOR=\"$THEME->cellcontent2\" CLASS=\"forumpostside\" WIDTH=10>";
|
2002-07-31 14:19:35 +00:00
|
|
|
echo " ";
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "</TD><TD BGCOLOR=\"$THEME->cellcontent\" CLASS=\"forumpostmessage\">\n";
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-09-01 14:34:38 +00:00
|
|
|
if ($post->attachment) {
|
|
|
|
$post->course = $courseid;
|
|
|
|
$post->forum = get_field("forum_discussions", "forum", "id", $post->discussion);
|
|
|
|
echo "<DIV ALIGN=right>";
|
|
|
|
forum_print_attachments($post);
|
|
|
|
echo "</DIV>";
|
|
|
|
}
|
|
|
|
|
2002-10-26 03:21:41 +00:00
|
|
|
if ($link and (strlen(strip_tags($post->message)) > FORUM_LONG_POST)) {
|
2002-07-31 15:34:15 +00:00
|
|
|
// Print shortened version
|
2002-10-10 07:27:57 +00:00
|
|
|
echo format_text(forum_shorten_post($post->message), $post->format);
|
2002-10-26 03:21:41 +00:00
|
|
|
$numwords = count_words(strip_tags($post->message));
|
2002-10-26 03:37:06 +00:00
|
|
|
echo "<P><A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion\">";
|
2002-08-02 17:34:26 +00:00
|
|
|
echo get_string("readtherest", "forum");
|
2002-10-26 03:37:06 +00:00
|
|
|
echo "</A> (".get_string("numwords", "", $numwords).")...</P>";
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2002-07-31 15:34:15 +00:00
|
|
|
// Print whole message
|
2002-10-10 07:27:57 +00:00
|
|
|
echo format_text($post->message, $post->format);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2002-10-24 07:09:29 +00:00
|
|
|
echo "<P ALIGN=right><FONT SIZE=-1>";
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
$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 " ";
|
|
|
|
}
|
2002-10-11 05:20:23 +00:00
|
|
|
echo "</P>";
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
echo "<DIV ALIGN=right><P ALIGN=right>";
|
|
|
|
if ($rate && $USER->id) {
|
2002-10-21 08:44:56 +00:00
|
|
|
if (isteacher($courseid)) {
|
|
|
|
forum_print_ratings($post->id);
|
|
|
|
if ($USER->id != $post->userid) {
|
|
|
|
forum_print_rating($post->id, $USER->id);
|
|
|
|
}
|
|
|
|
} else 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>\n</TABLE>\n\n";
|
|
|
|
}
|
|
|
|
|
2002-08-26 08:35:02 +00:00
|
|
|
|
|
|
|
function forum_print_post_header(&$post, $courseid, $ownpost=false, $reply=false, $link=false, $rate=false, $footer="") {
|
2002-10-26 03:21:41 +00:00
|
|
|
global $THEME, $USER, $CFG;
|
2002-08-26 08:35:02 +00:00
|
|
|
|
|
|
|
if ($post->parent) {
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 CLASS=\"forumpost\">";
|
2002-08-26 08:35:02 +00:00
|
|
|
} else {
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 CLASS=\"forumpost\" WIDTH=100%>";
|
2002-08-26 08:35:02 +00:00
|
|
|
}
|
|
|
|
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "<TR><TD BGCOLOR=\"$THEME->cellcontent2\" CLASS=\"forumpostpicture\" WIDTH=35 VALIGN=TOP>";
|
2002-08-26 08:35:02 +00:00
|
|
|
print_user_picture($post->userid, $courseid, $post->picture);
|
|
|
|
echo "</TD>";
|
|
|
|
|
|
|
|
if ($post->parent) {
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\" CLASS=\"forumpostheader\">";
|
2002-08-26 08:35:02 +00:00
|
|
|
} else {
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading2\" CLASS=\"forumpostheadertopic\">";
|
2002-08-26 08:35:02 +00:00
|
|
|
}
|
|
|
|
echo "<P>";
|
|
|
|
echo "<FONT SIZE=3><B>$post->subject</B></FONT><BR>";
|
|
|
|
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);
|
|
|
|
echo "</FONT></P></TD>";
|
|
|
|
|
|
|
|
if ($post->parent) {
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "<TD VALIGN=BOTTOM BGCOLOR=\"$THEME->cellheading\" CLASS=\"forumpostheader\">";
|
2002-08-26 08:35:02 +00:00
|
|
|
} else {
|
2002-12-10 02:48:05 +00:00
|
|
|
echo "<TD VALIGN=BOTTOM BGCOLOR=\"$THEME->cellheading2\" CLASS=\"forumpostheadertopic\">";
|
2002-08-26 08:35:02 +00:00
|
|
|
}
|
|
|
|
echo "<P ALIGN=right><FONT SIZE=-1>";
|
|
|
|
|
|
|
|
if ($link) {
|
|
|
|
if ($post->replies == 1) {
|
|
|
|
$replystring = get_string("repliesone", "forum", $post->replies);
|
|
|
|
} else {
|
|
|
|
$replystring = get_string("repliesmany", "forum", $post->replies);
|
|
|
|
}
|
|
|
|
echo "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion\"><B>".get_string("discussthistopic", "forum")."</B></A> ($replystring) ";
|
|
|
|
}
|
|
|
|
echo "</P>";
|
|
|
|
echo "</TD></TR>\n</TABLE>\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-31 15:34:15 +00:00
|
|
|
function forum_shorten_post($message) {
|
2002-10-26 03:21:41 +00:00
|
|
|
// Given a post object that we already know has a long message
|
|
|
|
// this function truncates the message nicely to the first
|
|
|
|
// sane place between FORUM_LONG_POST and FORUM_SHORT_POST
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
$tag = false;
|
|
|
|
$length = strlen($message);
|
|
|
|
$count = 0;
|
|
|
|
$stopzone = false;
|
|
|
|
$truncate = 0;
|
|
|
|
|
|
|
|
for ($i=0; $i<$length; $i++) {
|
2002-10-26 03:33:07 +00:00
|
|
|
$char = $message[$i];
|
2002-10-26 03:21:41 +00:00
|
|
|
|
|
|
|
switch ($char) {
|
|
|
|
case "<":
|
|
|
|
$tag = true;
|
|
|
|
break;
|
|
|
|
case ">":
|
|
|
|
$tag = false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!$tag) {
|
|
|
|
if ($stopzone) {
|
2002-10-26 03:37:06 +00:00
|
|
|
if ($char == ".") {
|
2002-10-26 03:33:07 +00:00
|
|
|
$truncate = $i+1;
|
2002-10-26 03:21:41 +00:00
|
|
|
break 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$count++;
|
|
|
|
}
|
2002-10-26 03:33:07 +00:00
|
|
|
break;
|
2002-10-26 03:21:41 +00:00
|
|
|
}
|
|
|
|
if (!$stopzone) {
|
|
|
|
if ($count > FORUM_SHORT_POST) {
|
|
|
|
$stopzone = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-07-31 15:34:15 +00:00
|
|
|
|
2002-10-26 03:21:41 +00:00
|
|
|
if (!$truncate) {
|
2002-10-26 03:33:07 +00:00
|
|
|
$truncate = $i;
|
2002-10-26 03:21:41 +00:00
|
|
|
}
|
|
|
|
|
2002-10-26 03:37:06 +00:00
|
|
|
return substr($message, 0, $truncate);
|
2002-07-31 15:34:15 +00:00
|
|
|
}
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-02 09:50:53 +00:00
|
|
|
function forum_print_ratings($post) {
|
2002-12-23 07:01:06 +00:00
|
|
|
if ($ratings = get_records("forum_ratings", "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;
|
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
if ($rating = get_record("forum_ratings", "userid", $user, "post", $post)) {
|
2002-12-23 07:01:06 +00:00
|
|
|
if ($FORUM_POST_RATINGS[$rating->rating]) {
|
2002-08-02 17:34:26 +00:00
|
|
|
echo "<FONT SIZE=-1>".get_string("youratedthis", "forum").": <FONT COLOR=green>";
|
2002-12-23 07:01:06 +00:00
|
|
|
echo $FORUM_POST_RATINGS[$rating->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-12-23 15:33:40 +00:00
|
|
|
function forum_print_search_form($course, $search="", $return=false, $type="") {
|
2002-07-31 14:19:35 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2002-12-23 15:33:40 +00:00
|
|
|
if ($type == "plain") {
|
|
|
|
$output = "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD NOWRAP>";
|
|
|
|
$output .= "<FORM NAME=search ACTION=\"$CFG->wwwroot/mod/forum/search.php\">";
|
|
|
|
$output .= "<FONT SIZE=\"-1\">";
|
|
|
|
$output .= "<INPUT NAME=search TYPE=text SIZE=15 VALUE=\"$search\">";
|
|
|
|
$output .= "<INPUT VALUE=\"".get_string("searchforums", "forum")."\" TYPE=submit>";
|
|
|
|
$output .= "</FONT>";
|
|
|
|
$output .= "<INPUT NAME=id TYPE=hidden VALUE=\"$course->id\">";
|
|
|
|
$output .= "</FORM>";
|
|
|
|
$output .= "</TD></TR></TABLE>";
|
|
|
|
} else {
|
|
|
|
$output = "<TABLE BORDER=0 CELLPADDING=10 CELLSPACING=0><TR><TD ALIGN=CENTER>";
|
|
|
|
$output .= "<FORM NAME=search ACTION=\"$CFG->wwwroot/mod/forum/search.php\">";
|
|
|
|
$output .= "<FONT SIZE=\"-1\">";
|
|
|
|
$output .= "<INPUT NAME=search TYPE=text SIZE=15 VALUE=\"$search\"><BR>";
|
|
|
|
$output .= "<INPUT VALUE=\"".get_string("searchforums", "forum")."\" TYPE=submit>";
|
|
|
|
$output .= "</FONT>";
|
|
|
|
$output .= "<INPUT NAME=id TYPE=hidden VALUE=\"$course->id\">";
|
|
|
|
$output .= "</FORM>";
|
|
|
|
$output .= "</TD></TR></TABLE>";
|
|
|
|
}
|
2002-12-09 07:35:40 +00:00
|
|
|
|
|
|
|
if ($return) {
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
echo $output;
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_set_return() {
|
2002-09-08 15:39:44 +00:00
|
|
|
global $CFG, $SESSION, $HTTP_REFERER;
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-09-08 15:39:44 +00:00
|
|
|
if (! isset($SESSION->fromdiscussion)) {
|
|
|
|
// If the referer is NOT a login screen then save it.
|
|
|
|
if (! strncasecmp("$CFG->wwwroot/login", $HTTP_REFERER, 300)) {
|
|
|
|
$SESSION->fromdiscussion = $HTTP_REFERER;
|
|
|
|
save_session("SESSION");
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
function forum_go_back_to($default) {
|
2002-07-31 14:19:35 +00:00
|
|
|
global $SESSION;
|
|
|
|
|
2002-12-29 17:32:32 +00:00
|
|
|
if (!empty($SESSION->fromdiscussion)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
$returnto = $SESSION->fromdiscussion;
|
|
|
|
unset($SESSION->fromdiscussion);
|
2002-08-06 17:23:45 +00:00
|
|
|
save_session("SESSION");
|
2002-07-31 14:19:35 +00:00
|
|
|
return $returnto;
|
|
|
|
} else {
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-01 14:34:38 +00:00
|
|
|
function forum_file_area_name($post) {
|
|
|
|
// Creates a directory file name, suitable for make_upload_directory()
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
return "$post->course/$CFG->moddata/forum/$post->forum/$post->id";
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_file_area($post) {
|
|
|
|
return make_upload_directory( forum_file_area_name($post) );
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_delete_old_attachments($post, $exception="") {
|
|
|
|
// Deletes all the user files in the attachments area for a post
|
|
|
|
// EXCEPT for any file named $exception
|
|
|
|
|
|
|
|
if ($basedir = forum_file_area($post)) {
|
|
|
|
if ($files = get_directory_list($basedir)) {
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file != $exception) {
|
|
|
|
unlink("$basedir/$file");
|
|
|
|
notify("Existing file '$file' has been deleted!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$exception) { // Delete directory as well, if empty
|
|
|
|
rmdir("$basedir");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_print_attachments($post, $return=NULL) {
|
|
|
|
// if return=html, then return a html string.
|
|
|
|
// if return=text, then return a text-only string.
|
|
|
|
// otherwise, print HTML
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$filearea = forum_file_area_name($post);
|
|
|
|
|
|
|
|
if ($basedir = forum_file_area($post)) {
|
|
|
|
if ($files = get_directory_list($basedir)) {
|
|
|
|
$strattachment = get_string("attachment", "forum");
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$icon = mimeinfo("icon", $file);
|
|
|
|
if ($CFG->slasharguments) {
|
|
|
|
$ffurl = "file.php/$filearea/$file";
|
|
|
|
} else {
|
|
|
|
$ffurl = "file.php?file=/$filearea/$file";
|
|
|
|
}
|
|
|
|
$image = "<IMG BORDER=0 SRC=\"$CFG->wwwroot/files/pix/$icon\" HEIGHT=16 WIDTH=16 ALT=\"File\">";
|
|
|
|
|
|
|
|
if ($return == "html") {
|
|
|
|
$output .= "<A HREF=\"$CFG->wwwroot/$ffurl\">$image</A> ";
|
|
|
|
$output .= "<A HREF=\"$CFG->wwwroot/$ffurl\">$file</A><BR>";
|
|
|
|
|
|
|
|
} else if ($return == "text") {
|
|
|
|
$output .= "$strattachment $file:\n$CFG->wwwroot/$ffurl\n";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
link_to_popup_window("/$ffurl", "attachment", $image, 500, 500, $strattachment);
|
|
|
|
echo "<A HREF=\"$CFG->wwwroot/$ffurl\">$file</A>";
|
|
|
|
echo "<BR>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($return) {
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_add_attachment($post, $newfile) {
|
|
|
|
// $post is a full post record, including course and forum
|
|
|
|
// $newfile is a full upload array from HTTP_POST_FILES
|
|
|
|
// If successful, this function returns the name of the file
|
|
|
|
|
|
|
|
if (!isset($newfile['name'])) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
$newfile_name = clean_filename($newfile['name']);
|
|
|
|
|
|
|
|
if (valid_uploaded_file($newfile)) {
|
|
|
|
if (! $newfile_name) {
|
|
|
|
notify("This file had a wierd filename and couldn't be uploaded");
|
|
|
|
|
|
|
|
} else if (! $dir = forum_file_area($post)) {
|
|
|
|
notify("Attachment could not be stored");
|
|
|
|
$newfile_name = "";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (move_uploaded_file($newfile['tmp_name'], "$dir/$newfile_name")) {
|
|
|
|
forum_delete_old_attachments($post, $newfile_name);
|
|
|
|
} else {
|
|
|
|
notify("An error happened while saving the file on the server");
|
|
|
|
$newfile_name = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$newfile_name = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $newfile_name;
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
|
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";
|
|
|
|
|
2002-09-01 14:34:38 +00:00
|
|
|
$newfile = $post->attachment;
|
|
|
|
$post->attachment = "";
|
|
|
|
|
|
|
|
if (! $post->id = insert_record("forum_posts", $post)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($post->attachment = forum_add_attachment($post, $newfile)) {
|
|
|
|
set_field("forum_posts", "attachment", $post->attachment, "id", $post->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $post->id;
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
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-22 08:01:21 +00:00
|
|
|
if (!$post->parent) { // Post is a discussion starter - update discussion title too
|
|
|
|
set_field("forum_discussions", "name", $post->subject, "id", $post->discussion);
|
|
|
|
}
|
2002-09-01 14:34:38 +00:00
|
|
|
if ($newfilename = forum_add_attachment($post, $post->attachment)) {
|
|
|
|
$post->attachment = $newfilename;
|
|
|
|
} else {
|
|
|
|
unset($post->attachment);
|
|
|
|
}
|
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;
|
2002-12-23 09:39:26 +00:00
|
|
|
$post->userid = $USER->id;
|
2002-07-31 14:19:35 +00:00
|
|
|
$post->created = $timenow;
|
|
|
|
$post->modified = $timenow;
|
|
|
|
$post->mailed = 0;
|
|
|
|
$post->subject = $discussion->name;
|
|
|
|
$post->message = $discussion->intro;
|
2002-09-01 14:34:38 +00:00
|
|
|
$post->attachment = "";
|
|
|
|
$post->forum = $discussion->forum;
|
|
|
|
$post->course = $discussion->course;
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
if (! $post->id = insert_record("forum_posts", $post) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-01 14:34:38 +00:00
|
|
|
if ($post->attachment = forum_add_attachment($post, $discussion->attachment)) {
|
|
|
|
set_field("forum_posts", "attachment", $post->attachment, "id", $post->id); //ignore errors
|
|
|
|
}
|
|
|
|
|
2002-10-21 08:10:24 +00:00
|
|
|
// Now do the real module entry
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2002-10-21 08:10:24 +00:00
|
|
|
$discussion->firstpost = $post->id;
|
|
|
|
$discussion->timemodified = $timenow;
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2002-10-21 08:10:24 +00:00
|
|
|
if (! $discussion->id = insert_record("forum_discussions", $discussion) ) {
|
|
|
|
delete_records("forum_posts", "id", $post->id);
|
|
|
|
return 0;
|
2002-08-03 02:29:21 +00:00
|
|
|
}
|
|
|
|
|
2002-10-21 08:10:24 +00:00
|
|
|
// Finally, set the pointer on the post.
|
|
|
|
if (! set_field("forum_posts", "discussion", $discussion->id, "id", $post->id)) {
|
|
|
|
delete_records("forum_posts", "id", $post->id);
|
|
|
|
delete_records("forum_discussions", "id", $discussion->id);
|
|
|
|
return 0;
|
2002-08-03 02:29:21 +00:00
|
|
|
}
|
|
|
|
|
2002-10-21 08:10:24 +00:00
|
|
|
return $discussion->id;
|
|
|
|
}
|
2002-08-03 02:29:21 +00:00
|
|
|
|
|
|
|
|
2002-10-21 08:10:24 +00:00
|
|
|
function forum_delete_discussion($discussion) {
|
|
|
|
// $discussion is a discussion record object
|
2002-08-03 02:29:21 +00:00
|
|
|
|
|
|
|
$result = true;
|
|
|
|
|
2002-10-21 08:10:24 +00:00
|
|
|
if ($posts = get_records("forum_posts", "discussion", $discussion->id)) {
|
|
|
|
foreach ($posts as $post) {
|
|
|
|
$post->course = $discussion->course;
|
|
|
|
$post->forum = $discussion->forum;
|
|
|
|
if (! delete_records("forum_ratings", "post", "$post->id")) {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
if (! forum_delete_post($post)) {
|
2002-08-03 02:29:21 +00:00
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-21 08:10:24 +00:00
|
|
|
if (! delete_records("forum_discussions", "id", "$discussion->id")) {
|
2002-08-03 02:29:21 +00:00
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-21 08:10:24 +00:00
|
|
|
function forum_delete_post($post) {
|
|
|
|
if (delete_records("forum_posts", "id", $post->id)) {
|
|
|
|
delete_records("forum_ratings", "post", $post->id); // Just in case
|
|
|
|
if ($post->attachment) {
|
|
|
|
$discussion = get_record("forum_discussions", "id", $post->discussion);
|
|
|
|
$post->course = $discussion->course;
|
|
|
|
$post->forum = $discussion->forum;
|
|
|
|
forum_delete_old_attachments($post);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
|
2002-10-21 08:10:24 +00:00
|
|
|
function forum_print_user_discussions($courseid, $userid) {
|
|
|
|
global $CFG, $USER;
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-12-23 07:01:06 +00:00
|
|
|
|
|
|
|
if ($discussions = forum_get_user_discussions($courseid, $userid)) {
|
2002-10-21 08:10:24 +00:00
|
|
|
$user = get_record("user", "id", $userid);
|
|
|
|
echo "<HR>";
|
|
|
|
print_heading( get_string("discussionsstartedby", "forum", "$user->firstname $user->lastname") );
|
|
|
|
$replies = forum_count_discussion_replies();
|
|
|
|
foreach ($discussions as $discussion) {
|
|
|
|
if (($discussion->forumtype == "teacher") and !isteacher($courseid)) {
|
2002-08-02 17:34:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
2002-12-30 05:13:43 +00:00
|
|
|
if (!empty($replies[$discussion->discussion])) {
|
2002-10-21 08:10:24 +00:00
|
|
|
$discussion->replies = $replies[$discussion->discussion]->replies;
|
|
|
|
} else {
|
|
|
|
$discussion->replies = 0;
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2002-10-21 08:10:24 +00:00
|
|
|
$inforum = get_string("inforum", "forum", "<A HREF=\"$CFG->wwwroot/mod/forum/view.php?f=$discussion->forumid\">$discussion->forumname</A>");
|
|
|
|
$discussion->subject .= " ($inforum)";
|
|
|
|
$ownpost = ($discussion->userid == $USER->id);
|
|
|
|
forum_print_post($discussion, $courseid, $ownpost, $reply=0, $link=1, $assessed=false);
|
|
|
|
echo "<BR>\n";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2002-12-23 09:39:26 +00:00
|
|
|
return record_exists("forum_subscriptions", "userid", $userid, "forum", $forumid);
|
2002-08-15 04:16:39 +00:00
|
|
|
}
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
function forum_subscribe($userid, $forumid) {
|
2002-12-20 14:44:14 +00:00
|
|
|
/// Adds user to the subscriber list
|
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
$sub->userid = $userid;
|
2002-12-20 14:44:14 +00:00
|
|
|
$sub->forum = $forumid;
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
return insert_record("forum_subscriptions", $sub);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function forum_unsubscribe($userid, $forumid) {
|
2002-12-20 14:44:14 +00:00
|
|
|
/// Removes user from the subscriber list
|
2002-12-23 09:39:26 +00:00
|
|
|
return delete_records("forum_subscriptions", "userid", $userid, "forum", $forumid);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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 {
|
2002-10-03 11:15:50 +00:00
|
|
|
return ($forum->open == 2);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-25 06:50:40 +00:00
|
|
|
function forum_user_can_post($forum, $user=NULL) {
|
|
|
|
// $forum, $user are objects
|
|
|
|
|
|
|
|
if ($user) {
|
|
|
|
$isteacher = isteacher($forum->course, $user->id);
|
|
|
|
} else {
|
|
|
|
$isteacher = isteacher($forum->course);
|
|
|
|
}
|
2002-10-03 11:15:50 +00:00
|
|
|
|
|
|
|
if ($forum->type == "teacher") {
|
2002-10-25 06:50:40 +00:00
|
|
|
return $isteacher;
|
|
|
|
} else if ($isteacher) {
|
2002-10-03 11:15:50 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return $forum->open;
|
|
|
|
}
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
|
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-10-26 03:21:41 +00:00
|
|
|
global $CFG, $USER;
|
2002-06-20 15:15:22 +00:00
|
|
|
|
|
|
|
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-10-25 08:47:53 +00:00
|
|
|
if (! $forum = forum_get_course_forum($course->id, "news")) {
|
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-08-26 08:35:02 +00:00
|
|
|
return;
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-08-26 08:35:02 +00:00
|
|
|
}
|
|
|
|
|
2002-10-26 03:21:41 +00:00
|
|
|
if ((!$forum_numdiscussions) && ($forum_style == "plain") && (count($discussions) > FORUM_MANY_DISCUSSIONS) ) {
|
2002-08-26 08:35:02 +00:00
|
|
|
$forum_style = "header"; // Abbreviate display if it's going to be long.
|
|
|
|
}
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-08-26 08:35:02 +00:00
|
|
|
$replies = forum_count_discussion_replies($forum->id);
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-10-25 05:58:39 +00:00
|
|
|
$canreply = forum_user_can_post($forum);
|
|
|
|
|
2002-08-26 08:35:02 +00:00
|
|
|
$discussioncount = 0;
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-08-26 08:35:02 +00:00
|
|
|
foreach ($discussions as $discussion) {
|
|
|
|
$discussioncount++;
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-08-26 08:35:02 +00:00
|
|
|
if ($forum_numdiscussions && ($discussioncount > $forum_numdiscussions)) {
|
|
|
|
echo "<P ALIGN=right><A HREF=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">";
|
|
|
|
echo get_string("olderdiscussions", "forum")."</A> ...</P>";
|
|
|
|
break;
|
|
|
|
}
|
2002-12-29 17:32:32 +00:00
|
|
|
if (!empty($replies[$discussion->discussion])) {
|
2002-08-26 08:35:02 +00:00
|
|
|
$discussion->replies = $replies[$discussion->discussion]->replies;
|
|
|
|
} else {
|
|
|
|
$discussion->replies = 0;
|
|
|
|
}
|
2003-01-01 06:34:54 +00:00
|
|
|
if (!empty($USER->id)) {
|
|
|
|
$ownpost = ($discussion->userid == $USER->id);
|
|
|
|
} else {
|
|
|
|
$ownpost=false;
|
|
|
|
}
|
2002-08-26 08:35:02 +00:00
|
|
|
switch ($forum_style) {
|
|
|
|
case "minimal":
|
2002-11-19 14:27:57 +00:00
|
|
|
echo "<P><FONT COLOR=#555555>".userdate($discussion->modified, "%d %b, %H:%M")." - $discussion->firstname</FONT>";
|
2002-08-26 08:35:02 +00:00
|
|
|
echo "<BR>$discussion->subject ";
|
|
|
|
echo "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->discussion\">";
|
|
|
|
echo get_string("more", "forum")."...</A>";
|
|
|
|
echo "</P>\n";
|
|
|
|
break;
|
|
|
|
case "header":
|
|
|
|
forum_print_post_header($discussion, $forum->course, $ownpost, $reply=0, $link=1, $assessed=false);
|
|
|
|
break;
|
|
|
|
default:
|
2002-10-25 05:58:39 +00:00
|
|
|
if ($canreply or $discussion->replies) {
|
|
|
|
$link = true;
|
|
|
|
} else {
|
|
|
|
$link = false;
|
|
|
|
}
|
|
|
|
forum_print_post($discussion, $forum->course, $ownpost, $reply=0, $link, $assessed=false);
|
2002-08-26 08:35:02 +00:00
|
|
|
echo "<BR>\n";
|
|
|
|
break;
|
2002-06-20 15:15:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-06 04:04:40 +00:00
|
|
|
function forum_print_discussion($course, $forum, $discussion, $post, $mode) {
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
global $USER;
|
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
$ownpost = ($USER->id == $post->userid);
|
2002-10-03 11:15:50 +00:00
|
|
|
$reply = forum_user_can_post($forum);
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-10-03 11:15:50 +00:00
|
|
|
forum_print_post($post, $course->id, $ownpost, $reply, $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
|
|
|
|
2002-08-06 06:09:44 +00:00
|
|
|
$ratingform = false;
|
2002-08-06 04:04:40 +00:00
|
|
|
if ($forum->assessed && $USER->id) {
|
2002-08-06 06:09:44 +00:00
|
|
|
$unrated = forum_count_unrated_posts($discussion->id, $USER->id);
|
|
|
|
if ($unrated > 0) {
|
|
|
|
$ratingform = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($ratingform) {
|
2002-07-31 14:19:35 +00:00
|
|
|
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-10-03 11:15:50 +00:00
|
|
|
forum_print_posts_flat($post->discussion, $course->id, $mode, $forum->assessed, $reply);
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "</UL>";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2 : // Threaded
|
2002-10-03 11:15:50 +00:00
|
|
|
forum_print_posts_threaded($post->id, $course->id, 0, $forum->assessed, $reply);
|
2002-07-31 14:19:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3 : // Nested
|
2002-10-03 11:15:50 +00:00
|
|
|
forum_print_posts_nested($post->id, $course->id, $forum->assessed, $reply);
|
2002-07-31 14:19:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-08-06 06:09:44 +00:00
|
|
|
if ($ratingform) {
|
2002-08-15 17:41:24 +00:00
|
|
|
echo "<CENTER><P ALIGN=center><INPUT TYPE=submit VALUE=\"".get_string("sendinratings", "forum")."\">";
|
2002-08-18 14:40:19 +00:00
|
|
|
helpbutton("ratings", get_string("separateandconnected"), "forum");
|
2002-08-15 17:41:24 +00:00
|
|
|
echo "</P></CENTER>";
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "</FORM>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-03 11:15:50 +00:00
|
|
|
function forum_print_posts_flat($discussion, $course, $direction, $assessed, $reply) {
|
2002-07-31 14:19:35 +00:00
|
|
|
global $USER;
|
|
|
|
|
|
|
|
$link = false;
|
|
|
|
|
|
|
|
if ($direction < 0) {
|
|
|
|
$sort = "ORDER BY created DESC";
|
|
|
|
} else {
|
|
|
|
$sort = "ORDER BY created ASC";
|
|
|
|
}
|
|
|
|
|
2002-12-23 07:01:06 +00:00
|
|
|
if ($posts = forum_get_discussion_posts($discussion, $sort)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
foreach ($posts as $post) {
|
2002-12-23 09:39:26 +00:00
|
|
|
$ownpost = ($USER->id == $post->userid);
|
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-10-03 11:15:50 +00:00
|
|
|
function forum_print_posts_threaded($parent, $course, $depth, $assessed, $reply) {
|
2002-07-31 14:19:35 +00:00
|
|
|
global $USER;
|
|
|
|
|
|
|
|
$link = false;
|
|
|
|
|
2002-12-23 07:01:06 +00:00
|
|
|
if ($posts = forum_get_child_posts($parent)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
foreach ($posts as $post) {
|
|
|
|
|
|
|
|
echo "<UL>";
|
|
|
|
if ($depth > 0) {
|
2002-12-23 09:39:26 +00:00
|
|
|
$ownpost = ($USER->id == $post->userid);
|
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-10-03 11:15:50 +00:00
|
|
|
forum_print_posts_threaded($post->id, $course, $depth-1, $assessed, $reply);
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "</UL>\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-03 11:15:50 +00:00
|
|
|
function forum_print_posts_nested($parent, $course, $assessed, $reply) {
|
2002-07-31 14:19:35 +00:00
|
|
|
global $USER;
|
|
|
|
|
|
|
|
$link = false;
|
|
|
|
|
2002-12-23 07:01:06 +00:00
|
|
|
if ($posts = forum_get_child_posts($parent)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
foreach ($posts as $post) {
|
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
$ownpost = ($USER->id == $post->userid);
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
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-10-03 11:15:50 +00:00
|
|
|
forum_print_posts_nested($post->id, $course, $assessed, $reply);
|
2002-07-31 14:19:35 +00:00
|
|
|
echo "</UL>\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function forum_set_display_mode($mode=0) {
|
2002-09-02 03:48:47 +00:00
|
|
|
global $USER, $FORUM_DEFAULT_DISPLAY_MODE;
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
if ($mode) {
|
|
|
|
$USER->mode = $mode;
|
2002-08-06 17:23:45 +00:00
|
|
|
save_session("USER");
|
2002-12-29 17:32:32 +00:00
|
|
|
} else if (empty($USER->mode)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
$USER->mode = $FORUM_DEFAULT_DISPLAY_MODE;
|
2002-08-06 17:23:45 +00:00
|
|
|
save_session("USER");
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-09-21 17:11:08 +00:00
|
|
|
|
2002-06-20 15:15:22 +00:00
|
|
|
?>
|