if (!isset($CFG->forum_displaymode)) {
set_config("forum_displaymode", FORUM_MODE_NESTED);
-}
+}
if (!isset($CFG->forum_shortpost)) {
set_config("forum_shortpost", 300); // Less non-HTML characters than this is short
-}
+}
if (!isset($CFG->forum_longpost)) {
set_config("forum_longpost", 600); // More non-HTML characters than this is long
-}
+}
if (!isset($CFG->forum_manydiscussions)) {
set_config("forum_manydiscussions", 100); // Number of discussions on a page
-}
+}
if (!isset($CFG->forum_maxbytes)) {
set_config("forum_maxbytes", 512000); // Default maximum size for all forums
-}
+}
/// 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
+// 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;
}
if (!empty($forum->ratingtime)) {
- $forum->assesstimestart = make_timestamp($forum->startyear, $forum->startmonth, $forum->startday,
+ $forum->assesstimestart = make_timestamp($forum->startyear, $forum->startmonth, $forum->startday,
$forum->starthour, $forum->startminute, 0);
- $forum->assesstimefinish = make_timestamp($forum->finishyear, $forum->finishmonth, $forum->finishday,
+ $forum->assesstimefinish = make_timestamp($forum->finishyear, $forum->finishmonth, $forum->finishday,
$forum->finishhour, $forum->finishminute, 0);
} else {
$forum->assesstimestart = 0;
function forum_update_instance($forum) {
-// Given an object containing all the necessary data,
-// (defined by the form in mod.html) this function
+// 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();
}
if (!empty($forum->ratingtime)) {
- $forum->assesstimestart = make_timestamp($forum->startyear, $forum->startmonth, $forum->startday,
+ $forum->assesstimestart = make_timestamp($forum->startyear, $forum->startmonth, $forum->startday,
$forum->starthour, $forum->startminute, 0);
- $forum->assesstimefinish = make_timestamp($forum->finishyear, $forum->finishmonth, $forum->finishday,
+ $forum->assesstimefinish = make_timestamp($forum->finishyear, $forum->finishmonth, $forum->finishday,
$forum->finishhour, $forum->finishminute, 0);
} else {
$forum->assesstimestart = 0;
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.
+// 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;
if ($posts = forum_get_unmailed_posts($cutofftime)) {
- /// Mark them all now as being mailed. It's unlikely but possible there
- /// might be an error later so that a post is NOT actually mailed out,
+ /// Mark them all now as being mailed. It's unlikely but possible there
+ /// might be an error later so that a post is NOT actually mailed out,
/// but since mail isn't crucial, we can accept this risk. Doing it now
/// prevents the risk of duplicated mails, which is a worse problem.
- foreach ($posts as $key => $post) {
+ foreach ($posts as $key => $post) {
if (! set_field("forum_posts", "mailed", "1", "id", "$post->id")) {
echo "Error marking post id post->id as being mailed. This post will not be mailed.\n";
unset($posts[$key]);
}
}
}
-
+
/// GWD: reset timelimit so that script does not get timed out when posting to many users
set_time_limit(10);
-
- /// Override the language and timezone of the "current" user, so that
+
+ /// Override the language and timezone of the "current" user, so that
/// mail is customised for the receiver.
$USER->lang = $userto->lang;
$USER->timezone = $userto->timezone;
$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\">".
"<a target=\"_blank\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> -> ".
} 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) .. not trying again.\n";
add_to_log($course->id, 'forum', 'mail error', "discuss.php?d=$discussion->id#$post->id", substr($post->subject,0,15), $cm->id, $userto->id);
}
function forum_print_recent_activity($course, $isteacher, $timestart) {
-/// Given a course and a date, prints a summary of all the new
+/// Given a course and a date, prints a summary of all the new
/// messages posted in the course since that date
global $CFG;
foreach ($logs as $log) {
//Get post info, I'll need it later
$post = forum_get_post_from_log($log);
-
+
//Create a temp valid module structure (course,id)
$tempmod->course = $log->course;
$tempmod->id = $post->forum;
//Obtain the visible property from the instance
$modvisible = instance_is_visible($log->module, $tempmod);
-
+
//Only if the mod is visible
if ($modvisible) {
if ($post) {
}
}
}
- /// Check whether this is belongs to a discussion in a group that
+ /// Check whether this is belongs to a discussion in a group that
/// should NOT be accessible to the current user
if (!$isteacheredit) { /// Because editing teachers can see everything anyway
function forum_get_participants($forumid) {
//Returns the users with data in one forum
-//(users with records in forum_subscriptions, forum_posts and forum_ratings, students)
+//(users with records in forum_subscriptions, forum_posts and forum_ratings, students)
global $CFG;
FROM {$CFG->prefix}user u,
{$CFG->prefix}forum_subscriptions s
WHERE s.forum = '$forumid' and
- u.id = s.userid");
+ u.id = s.userid");
//Get students from forum_posts
$st_posts = get_records_sql("SELECT DISTINCT u.*
FROM {$CFG->prefix}user u,
function forum_scale_used ($forumid,$scaleid) {
//This function returns if a scale is being used by one forum
-
+
$return = false;
-
+
$rec = get_record("forum","id","$forumid","scale","-$scaleid");
-
- if (!empty($rec) && !empty($scaleid)) {
+
+ if (!empty($rec) && !empty($scaleid)) {
$return = true;
}
-
+
return $return;
}
global $CFG;
return get_record_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture
- FROM {$CFG->prefix}forum_posts p,
- {$CFG->prefix}user u
- WHERE p.id = '$postid'
+ FROM {$CFG->prefix}forum_posts p,
+ {$CFG->prefix}user u
+ WHERE p.id = '$postid'
AND p.userid = u.id");
}
global $CFG;
return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture
- FROM {$CFG->prefix}forum_posts p,
- {$CFG->prefix}user u
- WHERE p.discussion = $discussion
- AND p.parent > 0
+ FROM {$CFG->prefix}forum_posts p,
+ {$CFG->prefix}user u
+ WHERE p.discussion = $discussion
+ AND p.parent > 0
AND p.userid = u.id $sort");
}
global $CFG;
return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture
- FROM {$CFG->prefix}forum_posts p,
- {$CFG->prefix}user u
- WHERE p.parent = '$parent'
+ FROM {$CFG->prefix}forum_posts p,
+ {$CFG->prefix}user u
+ WHERE p.parent = '$parent'
AND p.userid = u.id
ORDER BY p.created ASC");
}
case "postgres7":
$limit = "LIMIT $recordsperpage OFFSET ".($page * $recordsperpage);
break;
- default:
+ default:
$limit = "LIMIT $recordsperpage,$page";
}
}
}
- $selectsql = "{$CFG->prefix}forum_posts p,
- {$CFG->prefix}forum_discussions d,
- {$CFG->prefix}user u,
+ $selectsql = "{$CFG->prefix}forum_posts p,
+ {$CFG->prefix}forum_discussions d,
+ {$CFG->prefix}user u,
{$CFG->prefix}forum f $onlyvisibletable
WHERE ($messagesearch OR $subjectsearch)
- AND p.userid = u.id
- AND p.discussion = d.id
- AND d.course = '$courseid'
+ AND p.userid = u.id
+ AND p.discussion = d.id
+ AND d.course = '$courseid'
AND d.forum = f.id $notteacherforum $onlyvisible";
-
+
$totalcount = count_records_sql("SELECT COUNT(*) FROM $selectsql");
return get_records_sql("SELECT p.*,u.firstname,u.lastname,u.email,u.picture FROM
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,
+ return get_records_sql("SELECT u.*, r.rating, r.time
+ FROM {$CFG->prefix}forum_ratings r,
{$CFG->prefix}user u
- WHERE r.post = '$postid'
- AND r.userid = u.id
+ WHERE r.post = '$postid'
+ AND r.userid = u.id
ORDER BY $sort");
}
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,
+ 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'
+ WHERE p.mailed = 0
+ AND p.created < '$cutofftime'
AND p.discussion = d.id");
}
global $CFG;
return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture
- 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
+ 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
- AND p.userid = '$userid'
+ AND p.userid = '$userid'
AND p.userid = u.id
ORDER BY p.modified ASC");
}
if ($log->action == "add post") {
return get_record_sql("SELECT p.*, d.forum, d.groupid, u.firstname, u.lastname, u.email, u.picture
- 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
- AND p.userid = u.id
+ 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
+ AND p.userid = u.id
AND u.deleted <> '1'");
} else if ($log->action == "add discussion") {
return get_record_sql("SELECT p.*, d.forum, d.groupid, u.firstname, u.lastname, u.email, u.picture
- 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
- AND p.userid = u.id
+ 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
+ AND p.userid = u.id
AND u.deleted <> '1'");
}
return NULL;
global $CFG;
return get_record_sql("SELECT p.*
- FROM {$CFG->prefix}forum_discussions d,
+ FROM {$CFG->prefix}forum_discussions d,
{$CFG->prefix}forum_posts p
- WHERE d.id = '$discussionid'
+ WHERE d.id = '$discussionid'
AND d.firstpost = p.id ");
}
global $CFG;
return get_records_sql("SELECT r.id, p.userid, r.rating
- FROM {$CFG->prefix}forum_discussions d,
- {$CFG->prefix}forum_posts p,
+ FROM {$CFG->prefix}forum_discussions d,
+ {$CFG->prefix}forum_posts p,
{$CFG->prefix}forum_ratings r
- WHERE d.forum = '$forumid'
+ WHERE d.forum = '$forumid'
AND p.discussion = d.id
AND r.post = p.id
ORDER by p.userid ");
$forumselect = " AND d.forum = '$forum'";
}
return get_records_sql("SELECT p.discussion, (count(*)) as replies
- FROM {$CFG->prefix}forum_posts p,
+ FROM {$CFG->prefix}forum_posts p,
{$CFG->prefix}forum_discussions d
- WHERE p.parent > 0
- AND p.discussion = d.id
+ WHERE p.parent > 0
+ AND p.discussion = d.id
GROUP BY p.discussion");
}
global $CFG;
if ($posts = get_record_sql("SELECT count(*) as num
FROM {$CFG->prefix}forum_posts
- WHERE parent > 0
- AND discussion = '$discussionid'
+ WHERE parent > 0
+ AND discussion = '$discussionid'
AND userid <> '$userid' ")) {
- if ($rated = get_record_sql("SELECT count(*) as num
- FROM {$CFG->prefix}forum_posts p,
+ 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
+ AND p.id = r.post
AND r.userid = '$userid'")) {
$difference = $posts->num - $rated->num;
if ($difference > 0) {
}
}
-function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
+function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
$user=0, $fullpost=true, $currentgroup=0) {
/// Get all discussions in a forum
global $CFG;
$postdata = "p.*";
}
- return get_records_sql("SELECT $postdata, d.timemodified, d.usermodified,
+ return get_records_sql("SELECT $postdata, d.timemodified, d.usermodified,
u.firstname, u.lastname, u.email, u.picture
- FROM {$CFG->prefix}forum_discussions d,
+ 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
+ {$CFG->prefix}user u
+ WHERE d.forum = '$forum'
+ AND p.discussion = d.id
+ AND p.parent = 0
AND p.userid = u.id $groupselect $userselect
ORDER BY $forumsort");
}
$groupselect = "";
}
- return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture,
+ return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture,
f.type as forumtype, f.name as forumname, f.id as forumid
- FROM {$CFG->prefix}forum_discussions d,
- {$CFG->prefix}forum_posts p,
- {$CFG->prefix}user u,
+ 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
- AND p.userid = u.id
- AND u.id = '$userid'
+ WHERE d.course = '$courseid'
+ AND p.discussion = d.id
+ AND p.parent = 0
+ AND p.userid = u.id
+ AND u.id = '$userid'
AND d.forum = f.id $groupselect
ORDER BY p.created DESC");
}
}
return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.emailstop,
u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture, u.timezone, u.lang
- FROM {$CFG->prefix}user u,
+ FROM {$CFG->prefix}user u,
{$CFG->prefix}forum_subscriptions s $grouptables
WHERE s.forum = '$forum->id'
- AND s.userid = u.id
+ AND s.userid = u.id
AND u.deleted <> 1 $groupselect
ORDER BY u.email ASC");
}
global $CFG;
if ($forums = get_records_select("forum", "course = '$courseid' AND type = '$type'", "id ASC")) {
- // There should always only be ONE, but with the right combination of
+ // There should always only be ONE, but with the right combination of
// errors there might be more. In this case, just return the oldest one (lowest ID).
foreach ($forums as $forum) {
return $forum; // ie the first one
include_once("$CFG->dirroot/course/lib.php");
rebuild_course_cache($courseid);
}
-
+
return get_record("forum", "id", "$forum->id");
}
-function forum_make_mail_post(&$post, $user, $touser, $course,
+function forum_make_mail_post(&$post, $user, $touser, $course,
$ownpost=false, $reply=false, $link=false, $rate=false, $footer="") {
-// Given the data about a posting, builds up the HTML to display it and
+// 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 .= "</p>";
$output .= "<div align=right><p align=right>";
-
+
if ($link) {
if ($post->replies == 1) {
$replystring = get_string("repliesone", "forum", $post->replies);
}
-function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false,
+function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false,
$ratings=NULL, $footer="", $highlight="") {
global $THEME, $USER, $CFG;
} else {
echo format_text($post->message, $post->format, NULL, $courseid);
}
- echo $attachedimages;
+ echo $attachedimages;
}
echo "<p align=right><font size=-1>";
}
}
}
-
+
if ($link) {
if ($post->replies == 1) {
$replystring = get_string("repliesone", "forum", $post->replies);
function forum_shorten_post($message) {
// Given a post object that we already know has a long message
-// this function truncates the message nicely to the first
+// this function truncates the message nicely to the first
// sane place between $CFG->forum_longpost and $CFG->forum_shortpost
global $CFG;
$char = $message[$i];
switch ($char) {
- case "<":
+ case "<":
$tag = true;
break;
- case ">":
+ case ">":
$tag = false;
break;
default:
static $strrate;
$mean = forum_get_ratings_mean($postid, $scale);
-
+
if ($mean !== "") {
if (empty($strratings)) {
$total += $rating;
}
$mean = round( ((float)$total/(float)$count) + 0.001); // Little fudge factor so that 0.5 goes UP
-
+
if (isset($scale[$mean])) {
return $scale[$mean]." ($count)";
} else {
}
function forum_print_rating_menu($postid, $userid, $scale) {
-/// Print the menu of ratings as part of a larger form.
+/// Print the menu of ratings as part of a larger form.
/// If the post has already been - set that value.
/// Scale is an array of ratings
}
function forum_move_attachments($discussion, $forumid) {
-/// Given a discussion object that is being moved to forumid,
-/// this function checks all posts in that discussion
-/// for attachments, and if any are found, these are
+/// Given a discussion object that is being moved to forumid,
+/// this function checks all posts in that discussion
+/// for attachments, and if any are found, these are
/// moved to the new forum directory.
global $CFG;
$newfile = $post->attachment;
$post->attachment = "";
- if (! $post->id = insert_record("forum_posts", $post)) {
+ if (! $post->id = insert_record("forum_posts", $post)) {
return false;
}
// Update discussion modified date
set_field("forum_discussions", "timemodified", $post->modified, "id", $post->discussion);
set_field("forum_discussions", "usermodified", $post->userid, "id", $post->discussion);
-
+
return $post->id;
}
}
function forum_add_discussion($discussion) {
-// Given an object containing all the necessary data,
+// 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
+ // The first post is stored as a real post, and linked
// to from the discuss entry.
$post->discussion = 0;
set_field("forum_posts", "attachment", $post->attachment, "id", $post->id); //ignore errors
}
- // Now do the main entry for the discussion,
+ // Now do the main entry for the discussion,
// linking to this first post
$discussion->firstpost = $post->id;
$maxdiscussions = 10;
$countdiscussions = 0;
+ $visible = array();
if ($discussions = forum_get_user_discussions($courseid, $userid, $groupid=0)) {
$user = get_record("user", "id", $userid);
if (($discussion->forumtype == "teacher") and !isteacher($courseid)) {
continue;
}
+ if(!isset($visible[$discussion->forumid])) {
+ $mod = New stdClass;
+ $mod->course = $courseid;
+ $mod->id = $discussion->forumid;
+ $visible[$discussion->forumid] = instance_is_visible('forum', $mod);
+ }
+ if(!$visible[$discussion->forumid] && !isteacheredit($courseid, $USER->id)) {
+ continue;
+ }
if (!empty($replies[$discussion->discussion])) {
$discussion->replies = $replies[$discussion->discussion]->replies;
} else {
}
-function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5,
- $forum_style="plain", $forum_sort="",
+function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5,
+ $forum_style="plain", $forum_sort="",
$currentgroup=0) {
global $CFG, $USER;
-
+
if ($forum_id) {
if (! $forum = get_record("forum", "id", $forum_id)) {
error("Forum ID was incorrect");
echo "</p>\n";
}
- if ((!$forum_numdiscussions) && ($forum_style == "plain")) {
+ if ((!$forum_numdiscussions) && ($forum_style == "plain")) {
$forum_style = "header"; // Abbreviate display by default
}
- if ($forum_style == "minimal") {
+ if ($forum_style == "minimal") {
$forum_sort = "p.modified DESC";
}
$fullpost = false;
- if ($forum_style == "plain") {
+ if ($forum_style == "plain") {
$fullpost = true;
}
}
return;
}
-
+
$replies = forum_count_discussion_replies($forum->id);
$canreply = forum_user_can_post($forum);
if ($forum_style == "header") {
echo "<table width=\"100%\" border=0 cellpadding=3 cellspacing=1 class=\"forumheaderlist\">";
echo "<tr class=\"forumpostheader\">";
- echo "<th>".get_string("discussion", "forum")."</th>";
+ echo "<th>".get_string("discussion", "forum")."</th>";
echo "<th colspan=2>".get_string("startedby", "forum")."</th>";
echo "<th>".get_string("replies", "forum")."</th>";
echo "<th>".get_string("lastpost", "forum")."</th>";
switch ($mode) {
case FORUM_MODE_FLATOLDEST :
case FORUM_MODE_FLATNEWEST :
- default:
+ default:
echo "<ul>";
if (forum_print_posts_flat($post->discussion, $course->id, $mode, $ratings, $reply)) {
$ratingsmenuused = true;
}
}
-function forum_print_posts_flat($discussion, $course, $direction, $ratings, $reply) {
+function forum_print_posts_flat($discussion, $course, $direction, $ratings, $reply) {
global $USER;
$link = false;
return $ratingsmenuused;
}
-function forum_print_posts_threaded($parent, $course, $depth, $ratings, $reply) {
+function forum_print_posts_threaded($parent, $course, $depth, $ratings, $reply) {
global $USER;
$link = false;
return $ratingsmenuused;
}
-function forum_print_posts_nested($parent, $course, $ratings, $reply) {
+function forum_print_posts_nested($parent, $course, $ratings, $reply) {
global $USER;
$link = false;
$tmpactivity->content->discussion = $post->discussion;
$tmpactivity->content->subject = $post->subject;
$tmpactivity->content->parent = $post->parent;
-
+
$tmpactivity->user->userid = $post->userid;
$tmpactivity->user->fullname = fullname($post);
$tmpactivity->user->picture = $post->picture;
$tmpactivity->timestamp = $post->modified;
$activities[] = $tmpactivity;
-
+
$index++;
}
}