fwrite ($bf,full_tag("NAME",6,false,$for_dis->name));
fwrite ($bf,full_tag("FIRSTPOST",6,false,$for_dis->firstpost));
fwrite ($bf,full_tag("USERID",6,false,$for_dis->userid));
+ fwrite ($bf,full_tag("GROUPID",6,false,$for_dis->groupid));
fwrite ($bf,full_tag("ASSESSED",6,false,$for_dis->assessed));
fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$for_dis->timemodified));
//Now print posts to xml
}
}
}
+
+ if ($oldversion < 2004012200) {
+ table_column("forum_discussions", "", "groupid", "integer", "10", "unsigned", "0", "", "userid");
+ }
return true;
name varchar(255) NOT NULL default '',
firstpost int(10) unsigned NOT NULL default '0',
userid int(10) unsigned NOT NULL default '0',
+ groupid int(10) unsigned NOT NULL default '0',
assessed tinyint(1) NOT NULL default '1',
timemodified int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id)
}
}
}
+ if ($oldversion < 2004012200) {
+ table_column("forum_discussions", "", "groupid", "integer", "10", "unsigned", "0", "", "userid");
+ }
return true;
name varchar(255) NOT NULL default '',
firstpost integer NOT NULL default '0',
userid integer NOT NULL default '0',
+ groupid integer NOT NULL default '0',
assessed integer NOT NULL default '1',
timemodified integer NOT NULL default '0'
);
$groupmode = groupmode($course, $cm);
if ($groupmode and !isteacheredit($course->id)) { // Groups must be kept separate
- if (!$toppost = get_record("forum_posts", "id", $discussion->firstpost)) {
- error("Could not find the top post of the discussion");
- }
- if (!$group = user_group($course->id, $toppost->userid)) { // Find the topic's group
- error("Could not find the appropriate group of this discussion");
- }
-
if ($groupmode == SEPARATEGROUPS) {
require_login();
- if (mygroupid($course->id) == $group->id) {
+ if (mygroupid($course->id) == $discussion->groupid) {
$canreply = true;
} else {
print_heading("Sorry, you can't see this discussion because you are not in this group");
}
} else if ($groupmode == VISIBLEGROUPS) {
- if (mygroupid($course->id) == $group->id) {
- $canreply = true;
- }
+ $canreply = (mygroupid($course->id) == $discussion->groupid);
}
}
} else {
$userselect = "";
}
+ if ($currentgroup) {
+ $groupselect = " AND d.groupid = '$currentgroup' ";
+ } else {
+ $groupselect = "";
+ }
if (empty($forumsort)) {
$forumsort = "d.timemodified DESC";
}
} else {
$postdata = "p.*";
}
- if ($currentgroup) {
- $grouptable = ", {$CFG->prefix}groups_members gm ";
- $groupselect = " AND gm.groupid = '$currentgroup' AND u.id = gm.userid ";
- } else {
- $grouptable = "";
- $groupselect = "";
- }
return get_records_sql("SELECT $postdata, d.timemodified, u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}forum_discussions d,
{$CFG->prefix}forum_posts p,
- {$CFG->prefix}user u $grouptable
+ {$CFG->prefix}user u
WHERE d.forum = '$forum'
AND p.discussion = d.id
AND p.parent = 0
if ($ownpost) {
$output .= "<a href=\"$CFG->wwwroot/mod/forum/post.php?delete=$post->id\">".get_string("delete", "forum")."</a>";
if ($reply) {
- $output .= " | <a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."</a>";
+ $output .= " | <a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("replyforum", "forum")."</a>";
}
$output .= " ";
} else {
if ($reply) {
- $output .= "<a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."</a> ";
+ $output .= "<a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("replyforum", "forum")."</a> ";
}
}
set_field("forum_posts", "attachment", $post->attachment, "id", $post->id); //ignore errors
}
- // Now do the real module entry
+ // Now do the main entry for the discussion,
+ // linking to this first post
$discussion->firstpost = $post->id;
$discussion->timemodified = $timenow;
<input type="hidden" name=discussion value="<?php p($post->discussion) ?>">
<input type="hidden" name=parent value="<?php p($post->parent) ?>">
<input type="hidden" name=userid value="<?php p($post->userid) ?>">
+ <input type="hidden" name=groupid value="<?php p($post->groupid) ?>">
<input type="hidden" name=edit value="<?php p($post->edit) ?>">
<input type="submit" value="<?php print_string("savechanges"); ?>">
</td>
$post->parent = 0;
$post->subject = "";
$post->userid = $USER->id;
+ $post->groupid = get_current_group($course->id);
$post->message = "";
$post->format = $defaultformat;
if (! forum_user_can_post($forum)) {
error("Sorry, but you can not post in this forum.");
}
+
+ if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
+ if (groupmode($course, $cm) and !isteacheredit($course->id)) { // Make sure user can post here
+ if (mygroupid($course->id) != $discussion->groupid) {
+ error("Sorry, but you can not post in this discussion.");
+ }
+ }
+ }
+
// Load up the $post variable.
$post->course = $course->id;
$discussion->name = backup_todb($dis_info['#']['NAME']['0']['#']);
$discussion->firstpost = backup_todb($dis_info['#']['FIRSTPOST']['0']['#']);
$discussion->userid = backup_todb($dis_info['#']['USERID']['0']['#']);
+ $discussion->groupid = backup_todb($dis_info['#']['GROUPID']['0']['#']);
$discussion->assessed = backup_todb($dis_info['#']['ASSESSED']['0']['#']);
$discussion->timemodified = backup_todb($dis_info['#']['TIMEMODIFIED']['0']['#']);
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2004011404;
+$module->version = 2004012200;
$module->cron = 60;
?>