print_header("Setting up database", "Setting up database", "Setting up databases for the first time", "");
if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) {
+ $db->debug = true;
if (modify_database("$CFG->libdir/db/$CFG->dbtype.sql")) {
+ $db->debug = false;
notify("Main databases set up successfully");
} else {
+ $db->debug = false;
error("Error: Main databases NOT set up successfully");
}
} else {
if ($dversion = get_field("config", "value", "name", "version")) {
if ($version > $dversion) { // upgrade
notify("Upgrading databases from version $dversion to $version...");
+ $db->debug=true;
if (upgrade_moodle($dversion)) {
+ $db->debug=false;
if (set_field("config", "value", "$version", "name", "version")) {
notify("Databases were successfully upgraded");
print_heading("<A HREF=\"index.php\">Continue</A>");
notify("Upgrade failed! (Could not update version in config table)");
}
} else {
+ $db->debug=false;
notify("Upgrade failed! See /version.php");
}
} else if ($version < $dversion) {
print_heading("<A HREF=\"index.php\">Continue</A>");
die;
} else {
+ $db->debug=true;
if (upgrade_moodle(0)) {
print_heading("<A HREF=\"index.php\">Continue</A>");
} else {
error("A problem occurred inserting current version into databases");
}
+ $db->debug=false;
}
}
+
// Find and check all modules and load them up.
$dir = opendir("$CFG->dirroot/mod");
while ($mod = readdir($dir)) {
unset($module);
- include_once("$CFG->dirroot/mod/$mod/module.php"); # defines $module
+ include_once("$CFG->dirroot/mod/$mod/version.php"); # defines $module with version etc
if (!isset($module)) {
continue;
notify("$module->name module needs upgrading");
$upgrade_function = $module->name."_upgrade";
if (function_exists($upgrade_function)) {
+ $db->debug=true;
if ($upgrade_function($currmodule->version, $module)) {
+ $db->debug=false;
// OK so far, now update the modules record
$module->id = $currmodule->id;
if (! update_record("modules", $module)) {
}
notify("$module->name module was successfully upgraded");
} else {
+ $db->debug=false;
notify("Upgrading $module->name from $currmodule->version to $module->version FAILED!");
}
}
$info = split(" ", $log->info);
$modname = get_field($info[0], "name", "id", $info[1]);
- if ($info[0] == "discuss") {
- $info[0] = "discussion"; // nasty hack, really.
- }
-
switch ($log->action) {
case "add mod":
$changelist["$log->info"] = array ("operation" => "add", "text" => "Added a ".$info[0].":<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
$heading = false;
foreach ($logs as $log) {
- if ($log->module == "discuss") {
+ if ($log->module == "forum") {
$post = NULL;
- if ($log->action == "add post") {
+ if ($log->action == "add post" or $log->action == "add discussion") {
$post = get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname,
u.email, u.picture, u.id as userid
- FROM discuss d, discuss_posts p, user u
- WHERE p.id = '$log->info' AND d.id = p.discuss AND p.user = u.id");
+ FROM forum_discussions d, forum_posts p, user u
+ WHERE p.id = '$log->info' AND d.id = p.discussion AND p.user = u.id");
} else if ($log->action == "add") {
$post = get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname,
u.email, u.picture, u.id as userid
- FROM discuss d, discuss_posts p, user u
+ FROM forum_discussions d, forum_posts p, user u
WHERE d.id = '$log->info' AND d.firstpost = p.id AND p.user = u.id");
}
$content = true;
}
echo "<P><FONT SIZE=1 $teacherpost>$post->firstname $post->lastname:<BR>";
- echo "\"<A HREF=\"$CFG->wwwroot/mod/discuss/$log->url\">";
+ echo "\"<A HREF=\"$CFG->wwwroot/mod/forum/$log->url\">";
if ($log->action == "add") {
echo "<B>$post->subject</B>";
} else {
error("This course doesn't exist");
}
+ require_login($course->id);
+
+ if (!isteacher($course->id)) {
+ error("You can't modify this course!");
+ }
+
if (! $module = get_record("modules", "id", $cm->module)) {
error("This module doesn't exist");
}
if (! $instance = get_record($module->name, "id", $cm->instance)) {
- error("The required instance of this module doesn't exist");
+ // Delete this module from the course right away
+ if (! delete_course_module($cm->id)) {
+ notify("Could not delete the $module->name (coursemodule)");
+ }
+ if (! delete_mod_from_section($cm->id, $cm->section)) {
+ notify("Could not delete the $module->name from that section");
+ }
+ error("The required instance of this module didn't exist. Module deleted.",
+ "$CFG->wwwroot/course/view.php?id=$course->id");
}
- require_login($course->id);
-
- if (!isteacher($course->id)) {
- error("You can't modify this course!");
- }
$form->coursemodule = $cm->id;
$form->section = $cm->section;
echo "</TD></TR></TABLE>";
echo "<BR>";
- // Print a form to search discussions
+ // Print a form to search forums
print_simple_box("Search Discussions", $align="CENTER", $width="100%", $color="$THEME->cellheading");
echo "<DIV ALIGN=CENTER>";
- print_discussion_search_form($course);
+ print_forum_search_form($course);
echo "</DIV>";
// Print Admin links for teachers and admin.
error("Could not find or create a social forum here");
}
- $SESSION->fromdiscuss = "$CFG->wwwdir/course/view.php?id=$course->id";
+ $SESSION->fromdiscussion = "$CFG->wwwdir/course/view.php?id=$course->id";
if (is_subscribed($USER->id, $social->id)) {
$subtext = "Unsubscribe";
} else {
print_simple_box("Activities", $align="CENTER", $width="100%", $color="$THEME->cellheading");
print_side_block("", $moddata, "", $modicon);
- // Print a form to search discussions
+ // Print a form to search forums
print_simple_box("Search Discussions", $align="CENTER", $width="100%", $color="$THEME->cellheading");
echo "<DIV ALIGN=CENTER>";
- print_discussion_search_form($course);
+ print_forum_search_form($course);
echo "</DIV>";
// Admin links and controls
get_all_mods($course->id, $mods, $modtype);
- if (isset($modtype["forum"]) and isset($modtype["discuss"])) { // Only need to display one
- unset($modtype["discuss"]);
- }
-
switch ($course->format) {
case "weeks":
include("weeks.php");
print_simple_box("Activities", $align="CENTER", $width="100%", $color="$THEME->cellheading");
print_side_block("", $moddata, "", $modicon);
- // Print a form to search discussions
+ // Print a form to search forums
print_simple_box("Search Discussions", $align="CENTER", $width="100%", $color="$THEME->cellheading");
echo "<DIV ALIGN=CENTER>";
- print_discussion_search_form($course);
+ print_forum_search_form($course);
echo "</DIV>";
// Admin links and controls
4.0.6 or better), including the <A HREF="http://www.boutell.com/gd/">GD</A> \r
library for manipulating images.</LI>\r
<LI>a working database server (<A HREF="http://www.mysql.com/">MySQL</A>, PostgreSQL, \r
- MSSQL, Oracle, Interbase, Foxpro, Access, ADO, Sybase, DB2 or ODBC)</LI>\r
+ MSSQL, Oracle, Interbase, Foxpro, Access, ADO, Sybase, DB2 or ODBC).</LI>\r
</UL>\r
<P>The quickest way to satisfy these requirements on Windows platforms is to download \r
<A HREF="http://www.phpgeek.com/">PHPTriad</A> or <A HREF="http://www.foxserv.net/">FoxServ</A>, \r
}
if (isset($USER->id)) {
- $SESSION->fromdiscuss = "$CFG->wwwroot";
+ $SESSION->fromdiscussion = "$CFG->wwwroot";
if (is_subscribed($USER->id, $newsforum->id)) {
$subtext = get_string("unsubscribe", "forum");
} else {
$result = $db->Execute("$command");
if ($result) {
- echo "<P><FONT COLOR=green>SUCCESS: $command</FONT></P>";
+ echo "<P><FONT COLOR=green>SUCCESS</FONT></P>";
return true;
} else {
- echo "<P><FONT COLOR=red>ERROR: $command </FONT></P>";
+ echo "<P><FONT COLOR=red>ERROR</FONT></P>";
return false;
}
}
// any particular student has been doing.
//
// course = the course id
-// module = discuss, journal, reading, course, user etc
+// module = forum, journal, reading, course, user etc
// action = view, edit, post (often but not always the same as the file.php)
// url = the file and parameters used to see the results of the action
// info = additional description information
timemodified int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY id (id)
-) TYPE=MyISAM COMMENT='Discussion Forums';
+) COMMENT='Forums contain and structure discussion';
+# --------------------------------------------------------
+
+#
+# Table structure for table `forum_discussions`
+#
+
+CREATE TABLE forum_discussions (
+ id int(10) unsigned NOT NULL auto_increment,
+ course int(10) unsigned NOT NULL default '0',
+ forum int(10) unsigned NOT NULL default '0',
+ name varchar(255) NOT NULL default '',
+ firstpost 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)
+) COMMENT='Forums are composed of discussions';
+# --------------------------------------------------------
+
+#
+# Table structure for table `forum_posts`
+#
+
+CREATE TABLE forum_posts (
+ id int(10) unsigned NOT NULL auto_increment,
+ discuss int(10) unsigned NOT NULL default '0',
+ parent int(10) unsigned NOT NULL default '0',
+ user int(10) unsigned NOT NULL default '0',
+ created int(10) unsigned NOT NULL default '0',
+ modified int(10) unsigned NOT NULL default '0',
+ mailed tinyint(1) unsigned NOT NULL default '0',
+ subject varchar(255) NOT NULL default '',
+ message text NOT NULL,
+ totalscore tinyint(4) NOT NULL default '0',
+ PRIMARY KEY (id)
+) COMMENT='All posts are stored in this table';
+# --------------------------------------------------------
+
+#
+# Table structure for table `forum_ratings`
+#
+
+CREATE TABLE forum_ratings (
+ id int(10) unsigned NOT NULL auto_increment,
+ user int(10) unsigned NOT NULL default '0',
+ post int(10) unsigned NOT NULL default '0',
+ time int(10) unsigned NOT NULL default '0',
+ rating tinyint(4) NOT NULL default '0',
+ PRIMARY KEY (id)
+) COMMENT='Contains user ratings for individual posts';
# --------------------------------------------------------
#
forum int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY id (id)
-) TYPE=MyISAM COMMENT='keeps track of who is subscribed to what forum';
-
+) COMMENT='Keeps track of who is subscribed to what forum';
+# --------------------------------------------------------
#
# Dumping data for table `log_display`
#
+INSERT INTO log_display VALUES ('forum', 'add', 'forum', 'name');
+INSERT INTO log_display VALUES ('forum', 'add discussion', 'forum_discuss', 'name');
+INSERT INTO log_display VALUES ('forum', 'add post', 'forum_posts', 'subject');
+INSERT INTO log_display VALUES ('forum', 'update post', 'forum_posts', 'subject');
+INSERT INTO log_display VALUES ('forum', 'view discussion', 'forum_discuss', 'name');
INSERT INTO log_display VALUES ('forum', 'view forum', 'forum', 'name');
INSERT INTO log_display VALUES ('forum', 'subscribe', 'forum', 'name');
INSERT INTO log_display VALUES ('forum', 'unsubscribe', 'forum', 'name');
--- /dev/null
+<?PHP // $Id$
+
+// Displays a post, and all the posts below it.
+// If no post is given, displays all posts in a discussion
+
+ require("../../config.php");
+ require("lib.php");
+
+ require_variable($d); // Discussion ID
+ optional_variable($parent); // If set, then display this post and all children.
+ optional_variable($mode); // If set, changes the layout of the thread
+
+ if (! $discussion = get_record("forum_discussions", "id", $d)) {
+ error("Discussion ID was incorrect");
+ }
+
+ if (! $course = get_record("course", "id", $discussion->course)) {
+ error("Course ID is incorrect - discussion is faulty");
+ }
+
+ if (! $forum = get_record("forum", "id", $discussion->forum)) {
+ notify("Bad forum ID stored in this discussion");
+ }
+
+ if ($course->category) {
+ require_login($course->id);
+ }
+
+ add_to_log($course->id, "forum", "view discussion", "view.php?".$_SERVER["QUERY_STRING"], "$discussion->id");
+
+ unset($SESSION->fromdiscussion);
+
+ forum_set_display_mode($mode);
+
+ if (abs($USER->mode) == 1) { // If flat display then display the lot.
+ $parent = 0;
+ }
+
+ if (!$parent) {
+ $parent = $discussion->firstpost;
+ $navtail = "$discussion->name";
+ }
+
+ if (! $post = get_forum_post_full($parent)) {
+ error("Discussion no longer exists", "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
+ }
+
+ if (!$navtail) {
+ $navtail = "<A HREF=\"discuss.php?d=$discussion->id\">$discussion->name</A> -> $post->subject";
+ }
+
+ $navmiddle = "<A HREF=\"../forum/index.php?id=$course->id\">Forums</A> -> <A HREF=\"../forum/view.php?f=$forum->id\">$forum->name</A>";
+
+ if ($cm->id) {
+ $updatebutton = update_module_icon($cm->id, $course->id);
+ } else {
+ $updatebutton = "";
+ }
+
+ if ($course->category) {
+ print_header("$course->shortname: $discussion->name", "$course->fullname",
+ "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> ->
+ $navmiddle -> $navtail", "", "", true, $updatebutton);
+ } else {
+ print_header("$course->shortname: $discussion->name", "$course->fullname",
+ "$navmiddle -> $navtail", "", "", true, $updatebutton);
+ }
+
+ print_discussion($course, $discussion, $post, $USER->mode);
+
+ print_footer($course);
+
+?>
require_login($course->id);
}
- unset($SESSION->fromdiscuss);
+ unset($SESSION->fromdiscussion);
add_to_log($course->id, "forum", "view forums", "index.php?id=$course->id", "");
if ($forums = get_records("forum", "course", $id, "name ASC")) {
foreach ($forums as $forum) {
switch ($forum->type) {
- case "discussion":
+ case "single":
case "general":
case "eachuser":
$contentforums[] = $forum;
if ($generalforums) {
foreach ($generalforums as $forum) {
- $count = count_records("discuss", "forum", "$forum->id");
+ $count = count_records("forum_discussions", "forum", "$forum->id");
if ($can_subscribe) {
- if (is_subscribed($USER->id, $forum->id)) {
- $subscribed = "YES";
+ if (forum_is_forcesubscribed($forum->id)) {
+ $sublink = "YES";
} else {
- $subscribed = "NO";
+ if (forum_is_subscribed($USER->id, $forum->id)) {
+ $subscribed = "YES";
+ } else {
+ $subscribed = "NO";
+ }
+ $sublink = "<A TITLE=\"Change your subscription\" HREF=\"subscribe.php?id=$forum->id\">$subscribed</A>";
}
$table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
- "$forum->intro",
- "$count",
- "<A HREF=\"subscribe.php?id=$forum->id\">$subscribed</A>");
+ "$forum->intro", "$count", "$sublink");
} else {
$table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
- "$forum->intro",
- "$count");
+ "$forum->intro", "$count");
}
}
print_heading("General Forums");
if ($contentforums) {
foreach ($contentforums as $forum) {
- $count = count_records("discuss", "forum", "$forum->id");
+ $count = count_records("forum_discussions", "forum", "$forum->id");
if ($can_subscribe) {
- if (is_subscribed($USER->id, $forum->id)) {
- $subscribed = "YES";
+ if (forum_is_forcesubscribed($forum->id)) {
+ $sublink = "YES";
} else {
- $subscribed = "NO";
+ if (forum_is_subscribed($USER->id, $forum->id)) {
+ $subscribed = "YES";
+ } else {
+ $subscribed = "NO";
+ }
+ $sublink = "<A TITLE=\"Change your subscription\" HREF=\"subscribe.php?id=$forum->id\">$subscribed</A>";
}
$table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
- "$forum->intro",
- "$count",
- "<A HREF=\"subscribe.php?id=$forum->id\">$subscribed</A>");
+ "$forum->intro", "$count", "$sublink");
} else {
$table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
- "$forum->intro",
- "$count");
+ "$forum->intro", "$count");
}
}
print_heading("Course content");
}
echo "<DIV ALIGN=CENTER>";
- print_discussion_search_form($course, $search);
+ print_forum_search_form($course, $search);
echo "</DIV>";
print_footer($course);
<?PHP // $Id$
+/// CONSTANTS ///////////////////////////////////////////////////////////
-include_once("$CFG->dirroot/mod/discuss/lib.php");
+$FORUM_DEFAULT_DISPLAY_MODE = 3;
-// These are non-special forum types ie the ones that aren't automatically created
-$FORUM_TYPE = array ("general" => "General Forum",
- "eachuser" => "Each $student posts a topic");
+$FORUM_DISCUSS_MODES = array ( "1" => "Display replies flat, with oldest first",
+ "-1" => "Display replies flat, wth newest first",
+ "2" => "Display replies in threaded form",
+ "3" => "Display replies in nested form");
-function is_subscribed($user, $forum) {
- global $db;
-
- return record_exists_sql("SELECT * FROM forum_subscriptions WHERE user='$user' AND forum='$forum'");
-}
-
-function forum_subscribe($user, $forum) {
- global $db;
-
- return $db->Execute("INSERT INTO forum_subscriptions SET user = '$user', forum = '$forum'");
-}
-
-function forum_unsubscribe($user, $forum) {
- global $db;
-
- return $db->Execute("DELETE FROM forum_subscriptions WHERE user = '$user' AND forum = '$forum'");
-}
+$FORUM_TYPE = array ("general" => "General forum",
+ "eachuser" => "Each $student posts a topic",
+ "single" => "A single simple discussion");
+$FORUM_POST_RATINGS = array ("3" => "Outstanding",
+ "2" => "Satisfactory",
+ "1" => "Not satisfactory");
-function user_has_posted_discussion($forumid, $userid) {
- if ($topics = get_all_topics($forumid, "DESC", $userid)) {
- return true;
- } else {
- return false;
- }
-}
-
-function user_can_post_discussion($forum) {
-// $forum is an object
- global $USER;
-
- if ($forum->type == "eachuser") {
- return (! user_has_posted_discussion($forum->id, $USER->id));
- } else if ($forum->type == "teacher") {
- return isteacher($forum->course);
- } else if (isteacher($forum->course)) {
- return true;
- } else {
- return $forum->open;
- }
-}
+$FORUM_LONG_POST = 600;
-function get_all_topics($forum="0", $forum_sort="DESC", $user=0) {
- if ($user) {
- $userselect = " AND u.id = '$user' ";
- } else {
- $userselect = "";
- }
- return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture, u.id as userid
- FROM discuss d, discuss_posts p, user u
- WHERE d.forum = '$forum' AND p.discuss = d.id AND
- p.parent= 0 AND p.user = u.id $userselect
- ORDER BY p.created $forum_sort");
-}
+/// FUNCTIONS ///////////////////////////////////////////////////////////
+// How to set up special 1-per-course forums
function get_course_news_forum($courseid) {
if ($forum = get_record_sql("SELECT * from forum WHERE course = '$courseid' AND type = 'news'")) {
$forum->intro= "General news about this course";
$forum->open = 0;
$forum->assessed = 0;
+ $forum->forcesubscribe = 1;
$forum->timemodified = time();
$forum->id = insert_record("forum", $forum);
return get_record_sql("SELECT * from forum WHERE id = '$forum->id'");
}
}
+
function get_course_social_forum($courseid) {
if ($forum = get_record_sql("SELECT * from forum WHERE course = '$courseid' AND type = 'social'")) {
return $forum;
$forum->course = $courseid;
$forum->type = "social";
$forum->name = "Social";
- $forum->intro= "A forum to socialise and talk about anything you like";
+ $forum->intro= "A forum for general socialising. Talk about anything you like!";
$forum->open = 1;
$forum->assessed = 0;
+ $forum->forcesubscribe = 0;
$forum->timemodified = time();
$forum->id = insert_record("forum", $forum);
return get_record_sql("SELECT * from forum WHERE id = '$forum->id'");
}
}
-function get_course_discussion_forum($courseid) {
- if ($forum = get_record_sql("SELECT * from forum WHERE course = '$courseid' AND type = 'discussion'")) {
- return $forum;
- } else {
- // Doesn't exist, so create one now.
- $forum->course = $courseid;
- $forum->type = "discussion";
- $forum->name = "Course Discussion";
- $forum->intro= "General discussions about course topics";
- $forum->open = 0;
- $forum->assessed = 1;
- $forum->timemodified = time();
- $forum->id = insert_record("forum", $forum);
- return get_record_sql("SELECT * from forum WHERE id = '$forum->id'");
- }
-}
function get_course_teacher_forum($courseid) {
if ($forum = get_record_sql("SELECT * from forum WHERE course = '$courseid' AND type = 'teacher'")) {
$forum->intro= "For teacher-only notes and discussion";
$forum->open = 0;
$forum->assessed = 0;
+ $forum->forcesubscribe = 0;
$forum->timemodified = time();
$forum->id = insert_record("forum", $forum);
return get_record_sql("SELECT * from forum WHERE id = '$forum->id'");
}
+function 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
+// returns the HTML in a string. This is designed for sending via HTML email.
+
+ global $THEME, $CFG;
+
+ $output = "";
+
+ if ($post->parent) {
+ $output .= "<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=1><TR><TD BGCOLOR=#888888>";
+ $output .= "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0>";
+ } else {
+ $output .= "<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=1 WIDTH=100%><TR><TD BGCOLOR=#888888>";
+ $output .= "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 WIDTH=100%>";
+ }
+
+ $output .= "<TR><TD BGCOLOR=\"$THEME->body\" WIDTH=35 VALIGN=TOP>";
+ $output .= print_user_picture($user->id, $course->id, $user->picture, false, true);
+ $output .= "</TD>";
+
+ if ($post->parent) {
+ $output .= "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\">";
+ } else {
+ $output .= "<TD NOWRAP BGCOLOR=\"$THEME->cellheading2\">";
+ }
+ $output .= "<P>";
+ $output .= "<FONT SIZE=3><B>$post->subject</B></FONT><BR>";
+ $output .= "<FONT SIZE=2>by <A HREF=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A>";
+ $output .= " on ".userdate($post->created, "", $touser->timezone);
+ $output .= "</FONT></P></TD></TR>";
+ $output .= "<TR><TD BGCOLOR=\"$THEME->body\" WIDTH=10>";
+ $output .= " ";
+ $output .= "</TD><TD BGCOLOR=\"#FFFFFF\">\n";
+
+ $output .= text_to_html($post->message);
+
+ $output .= "<P ALIGN=right><FONT SIZE=-1>";
+
+ $age = time() - $post->created;
+ if ($ownpost) {
+ $output .= "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?delete=$post->id\">Delete</A>";
+ if ($reply) {
+ $output .= "| <A HREF=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">Reply</A>";
+ }
+ $output .= " ";
+ } else {
+ if ($reply) {
+ $output .= "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">Reply</A> ";
+ }
+ }
+
+ $output .= "<DIV ALIGN=right><P ALIGN=right>";
+
+ if ($link) {
+ if ($post->replies == 1) {
+ $replystring = "reply";
+ } else {
+ $replystring = "replies";
+ }
+ $output .= "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion\"><B>Discuss this topic</B></A> ($post->replies $replystring so far) ";
+ }
+ $output .= "</P></DIV>";
+ if ($footer) {
+ $output .= "<P>$footer</P>";
+ }
+ $output .= "</TD></TR></TABLE>\n";
+ $output .= "</TD></TR></TABLE>\n\n";
+
+ return $output;
+}
+
+
+function print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false, $rate=false, $footer="") {
+ global $THEME, $USER, $CFG, $FORUM_LONG_POST;
+
+ if ($post->parent) {
+ echo "<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=1><TR><TD BGCOLOR=#888888>";
+ echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0>";
+ } else {
+ echo "<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=1 WIDTH=100%><TR><TD BGCOLOR=#888888>";
+ echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 WIDTH=100%>";
+ }
+
+ echo "<TR><TD BGCOLOR=\"$THEME->body\" WIDTH=35 VALIGN=TOP>";
+ print_user_picture($post->userid, $courseid, $post->picture);
+ echo "</TD>";
+
+ if ($post->parent) {
+ echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\">";
+ } else {
+ echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading2\">";
+ }
+ echo "<P>";
+ echo "<FONT SIZE=3><B>$post->subject</B></FONT><BR>";
+ echo "<FONT SIZE=2>by <A HREF=\"$CFG->wwwroot/user/view.php?id=$post->userid&course=$courseid\">$post->firstname $post->lastname</A>";
+ echo " on ".userdate($post->created);
+ echo "</FONT></P></TD></TR>";
+ echo "<TR><TD BGCOLOR=\"$THEME->body\" WIDTH=10>";
+ echo " ";
+ echo "</TD><TD BGCOLOR=\"#FFFFFF\">\n";
+
+ if ($link && (strlen($post->message) > $FORUM_LONG_POST)) {
+ // Look for the first return between 50 and $FORUM_LONG_POST
+ $shortmessage = substr($post->message, 50, $FORUM_LONG_POST);
+ if ($pos = strpos($shortmessage, "\n")) {
+ $shortmessage = substr($post->message, 0, 50 + $pos);
+ } else {
+ $shortmessage = substr($post->message, 0, $FORUM_LONG_POST). "...";
+ }
+ echo text_to_html($shortmessage);
+ $numwords = count_words($post->message);
+ echo "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion\">Read the rest of this topic</A> ($numwords words)...";
+ } else {
+ // Just print the whole thing
+ echo text_to_html($post->message);
+ }
+
+ echo "<P ALIGN=right><FONT SIZE=-1>";
+
+ $age = time() - $post->created;
+ if ($ownpost) {
+ if ($age < $CFG->maxeditingtime) {
+ echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?edit=$post->id\">Edit</A> | ";
+ }
+ echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?delete=$post->id\">Delete</A>";
+ if ($reply) {
+ echo "| <A HREF=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">Reply</A>";
+ }
+ echo " ";
+ } else {
+ if ($reply) {
+ echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">Reply</A> ";
+ }
+ }
+
+
+ echo "<DIV ALIGN=right><P ALIGN=right>";
+ if ($rate && $USER->id) {
+ if ($USER->id == $post->userid) {
+ print_ratings($post->id);
+ } else {
+ print_rating($post->id, $USER->id);
+ }
+ }
+
+ if ($link) {
+ if ($post->replies == 1) {
+ $replystring = "reply";
+ } else {
+ $replystring = "replies";
+ }
+ echo "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion\"><B>Discuss this topic</B></A> ($post->replies $replystring so far) ";
+ }
+ echo "</P>";
+ if ($footer) {
+ echo "<P>$footer</P>";
+ }
+ echo "</DIV>";
+ echo "</TD></TR></TABLE>";
+ echo "</TD></TR>\n</TABLE>\n\n";
+}
+
+
+function print_ratings($post) {
+
+ global $CFG, $PHPSESSID;
+
+ $notsatisfactory = 0;
+ $satisfactory = 0;
+ $outstanding = 0;
+ if ($ratings = get_records_sql("SELECT * from forum_ratings WHERE post='$post'")) {
+ foreach ($ratings as $rating) {
+ switch ($rating->rating) {
+ case 1: $notsatisfactory++; break;
+ case 2: $satisfactory++; break;
+ case 3: $outstanding++; break;
+ }
+ }
+ $summary = "$outstanding/$satisfactory/$notsatisfactory";
+
+ echo "Ratings: ";
+ link_to_popup_window ("/mod/forum/report.php?id=$post", "ratings", $summary, 400, 550);
+
+ } else {
+ echo "";
+ }
+}
+
+function print_rating($post, $user) {
+ global $FORUM_POST_RATINGS;
+
+ if ($rs = get_record_sql("SELECT rating from forum_ratings WHERE user='$user' AND post='$post'")) {
+ echo "<FONT SIZE=-1>You rated this: <FONT COLOR=green>";
+ if ($FORUM_POST_RATINGS[$rs->rating]) {
+ echo $FORUM_POST_RATINGS[$rs->rating];
+ } else {
+ echo "Error";
+ }
+ echo "</FONT></FONT>";
+
+ } else {
+ choose_from_menu($FORUM_POST_RATINGS, $post, "", "Rate...");
+ }
+}
+
+function print_mode_form($discussion, $mode) {
+ GLOBAL $FORUM_DISCUSS_MODES;
+
+ echo "<CENTER><P>";
+ popup_form("discuss.php?d=$discussion&mode=", $FORUM_DISCUSS_MODES, "mode", $mode, "");
+ echo "</P></CENTER>\n";
+}
+
+function print_forum_search_form($course, $search="") {
+ global $CFG;
+
+ echo "<TABLE BORDER=0 CELLPADDING=10 CELLSPACING=0><TR><TD ALIGN=CENTER>";
+ echo "<FORM NAME=search ACTION=\"$CFG->wwwroot/mod/forum/search.php\">";
+ echo "<INPUT NAME=search TYPE=text SIZE=15 VALUE=\"$search\"><BR>";
+ echo "<INPUT VALUE=\"".get_string("search", "forum")."\" TYPE=submit>";
+ echo "<INPUT NAME=id TYPE=hidden VALUE=\"$course->id\">";
+ echo "</FORM>";
+ echo "</TD></TR></TABLE>";
+}
+
+
+function count_discussion_replies($forum="0") {
+ if ($forum) {
+ $forumselect = " AND d.forum = '$forum'";
+ }
+ return get_records_sql("SELECT p.discussion, (count(*)) as replies
+ FROM forum_posts p, forum_discussions d
+ WHERE p.parent > 0 AND p.discussion = d.id
+ GROUP BY p.discussion");
+}
+
+
+function set_fromdiscussion() {
+ global $SESSION, $HTTP_REFERER;
+
+ if (! $SESSION->fromdiscussion) {
+ $SESSION->fromdiscussion = $HTTP_REFERER;
+ }
+}
+
+
+function go_back_to($default) {
+ global $SESSION;
+
+ if ($SESSION->fromdiscussion) {
+ $returnto = $SESSION->fromdiscussion;
+ unset($SESSION->fromdiscussion);
+ return $returnto;
+ } else {
+ return $default;
+ }
+}
+
+function get_forum_post_full($postid) {
+ return get_record_sql("SELECT p.*, u.firstname, u.lastname,
+ u.email, u.picture, u.id as userid
+ FROM forum_posts p, user u
+ WHERE p.id = '$postid' AND p.user = u.id");
+}
+
+
+function add_new_post_to_database($post) {
+
+ $timenow = time();
+ $post->created = $timenow;
+ $post->modified = $timenow;
+ $post->mailed = "0";
+
+ return insert_record("forum_posts", $post);
+}
+
+function update_post_in_database($post) {
+ global $db;
+
+ $timenow = time();
+
+ $rs = $db->Execute("UPDATE forum_posts
+ SET message='$post->message', subject='$post->subject', modified='$timenow'
+ WHERE id = '$post->id'");
+ return $rs;
+}
+
+function forum_add_discussion($discussion) {
+// Given an object containing all the necessary data,
+// create a new discussion and return the id
+
+ GLOBAL $USER;
+
+ $timenow = time();
+
+ // The first post is stored as a real post, and linked
+ // to from the discuss entry.
+
+ $post->discussion = 0;
+ $post->parent = 0;
+ $post->user = $USER->id;
+ $post->created = $timenow;
+ $post->modified = $timenow;
+ $post->mailed = 0;
+ $post->subject = $discussion->name;
+ $post->message = $discussion->intro;
+
+ if (! $post->id = insert_record("forum_posts", $post) ) {
+ return 0;
+ }
+
+ // Now do the real module entry
+
+ $discussion->firstpost = $post->id;
+ $discussion->timemodified = $timenow;
+
+ if (! $discussion->id = insert_record("forum_discussions", $discussion) ) {
+ return 0;
+ }
+
+ // Finally, set the pointer on the post.
+ if (! set_field("forum_posts", "discussion", $discussion->id, "id", $post->id)) {
+ return 0;
+ }
+
+ return $discussion->id;
+}
+
+
+function forum_delete_discussion($discussion) {
+// $discussion is a discussion record object
+
+ $result = true;
+
+ if ($posts = get_records("forum_posts", "discussion", $discussion->id)) {
+ foreach ($posts as $post) {
+ if (! delete_records("forum_ratings", "post", "$post->id")) {
+ $result = false;
+ }
+ }
+ }
+
+ if (! delete_records("forum_posts", "discussion", "$discussion->id")) {
+ $result = false;
+ }
+
+ if (! delete_records("forum_discussions", "id", "$discussion->id")) {
+ $result = false;
+ }
+
+ return $result;
+}
+
+
+
+function print_user_discussions($course, $user) {
+ global $CFG;
+
+ $topics = get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture, u.id as userid
+ FROM forum_discussions d, forum_posts p, user u, forum f
+ WHERE d.course = '$course->id' AND p.discussion = d.id AND
+ p.parent = 0 AND p.user = u.id AND u.id = '$user->id'
+ AND d.forum = f.id AND f.type = 'eachuser'
+ ORDER BY p.created DESC");
+
+ if ($topics) {
+ echo "<HR>";
+ print_heading("Discussion topics");
+ $replies = count_discussion_replies();
+ foreach ($topics as $topic) {
+ if ($replies[$topic->discussion]) {
+ $topic->replies = $replies[$topic->discussion]->replies;
+ } else {
+ $topic->replies = 0;
+ }
+ $ownpost = ($topic->userid == $USER->id);
+ print_post($topic, $course->id, $ownpost, $reply=0, $link=1, $assessed=false);
+ echo "<BR>\n";
+ }
+ }
+}
+
+
+function forum_user_summary($course, $user, $mod, $forum) {
+ global $CFG;
+}
+
+
+function forum_user_outline($course, $user, $mod, $forum) {
+
+///XXX
+ global $CFG;
+ if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture
+ FROM forum_posts p, user u
+ WHERE p.discussion='$discussion->id' AND p.user = '$user->id' AND p.user = u.id
+ ORDER BY p.modified ASC")) {
+
+ $result->info = count($posts)." posts";
+
+ $lastpost = array_pop($posts);
+ $result->time = $lastpost->modified;
+ return $result;
+ }
+ return NULL;
+}
+
+
+function forum_user_complete($course, $user, $mod, $forum) {
+ global $CFG;
+
+///XXX
+ if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture
+ FROM forum_posts p, user u
+ WHERE p.discussion='$discussion->id' AND p.user = '$user->id' AND p.user = u.id
+ ORDER BY p.modified")) {
+
+ foreach ($posts as $post) {
+ if ($post->parent) {
+ $footer = "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion&parent=$post->parent\">Parent of this post</A>";
+ } else {
+ $footer = "";
+ }
+
+ print_post($post, $course->id, $ownpost=false, $reply=false, $link=false, $rate=false, $footer);
+ }
+
+ } else {
+ echo "<P>No posts</P>";
+ }
+
+}
+
+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;
+
+ echo "Processing posts...\n";
+
+ $cutofftime = time() - $CFG->maxeditingtime;
+
+ if ($posts = get_records_sql("SELECT p.*, d.course FROM forum_posts p, forum_discussions d
+ WHERE p.mailed = '0' AND p.created < '$cutofftime' AND p.discussion = d.id")) {
+
+ $timenow = time();
+
+ foreach ($posts as $post) {
+
+ echo "Processing post $post->id\n";
+
+ if (! $userfrom = get_record("user", "id", "$post->user")) {
+ echo "Could not find user $post->user\n";
+ continue;
+ }
+
+ if (! $course = get_record("course", "id", "$post->course")) {
+ echo "Could not find course $post->course\n";
+ continue;
+ }
+
+ if (! $discussion = get_record("forum_discussions", "id", "$post->discussion")) {
+ echo "Could not find discussion $post->discussion\n";
+ continue;
+ }
+
+ if (! $forum = get_record("forum", "id", "$discussion->forum")) {
+ echo "Could not find forum $discussion->forum\n";
+ continue;
+ }
+
+
+ if ($users = get_records_sql("SELECT u.* FROM user u, forum_subscriptions s
+ WHERE s.user = u.id AND s.forum = '$discussion->forum'")) {
+
+ foreach ($users as $userto) {
+ $postsubject = "$course->shortname: $post->subject";
+ $posttext = "$course->shortname -> Forums -> $forum->name -> $discussion->name\n";
+ $posttext .= "---------------------------------------------------------------------\n";
+ $posttext .= "$post->subject\n";
+ $posttext .= "by $userfrom->firstname $userfrom->lastname, on ".userdate($post->created, "", $userto->timezone)."\n";
+ $posttext .= "---------------------------------------------------------------------\n";
+ $posttext .= strip_tags($post->message);
+ $posttext .= "\n\n";
+ $posttext .= "---------------------------------------------------------------------\n";
+ $posttext .= "This is a copy of a message posted on the $course->shortname website.\n";
+ $posttext .= "To add your reply via the website, click on this link:\n";
+ $posttext .= "$CFG->wwwroot/mod/forum/post.php?reply=$post->id";
+
+ if ($userto->mailformat == 1) { // HTML
+ $posthtml = "<P><FONT FACE=sans-serif>".
+ "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->".
+ "<A HREF=\"$CFG->wwwroot/mod/forum/index.php?id=$course->id\">Forums</A> ->".
+ "<A HREF=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">$forum->name</A> ->".
+ "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id\">$discussion->name</A></FONT></P>";
+ $posthtml .= make_mail_post($post, $userfrom, $userto, $course, false, true, false, false);
+ } else {
+ $posthtml = "";
+ }
+
+ if (! email_to_user($userto, $userfrom, $postsubject, $posttext, $posthtml)) {
+ echo "Error: mod/forum/cron.php: Could not send out mail for id $post->id to user $userto->id ($userto->email)\n";
+ }
+ }
+ }
+
+ if (! set_field("forum_posts", "mailed", "1", "id", "$post->id")) {
+ echo "Could not update the mailed field for id $post->id\n";
+ }
+ }
+ }
+
+ return true;
+}
+
+
+function forum_forcesubscribe($forumid, $value=1) {
+ return set_field("forum", "forcesubscribe", $value, "id", $forumid);
+}
+
+function forum_is_forcesubscribed($forumid) {
+ return get_field("forum", "forcesubscribe", "id", $forumid);
+}
+
+function forum_is_subscribed($userid, $forumid) {
+ if (forum_is_forcesubscribed($forumid)) {
+ return true;
+ }
+ return record_exists_sql("SELECT * FROM forum_subscriptions WHERE user='$userid' AND forum='$forumid'");
+}
+
+function forum_subscribe($userid, $forumid) {
+ global $db;
+
+ return $db->Execute("INSERT INTO forum_subscriptions SET user = '$userid', forum = '$forumid'");
+}
+
+function forum_unsubscribe($userid, $forumid) {
+ global $db;
+
+ return $db->Execute("DELETE FROM forum_subscriptions WHERE user = '$userid' AND forum = '$forumid'");
+}
+
+
+function user_has_posted_discussion($forumid, $userid) {
+ if ($topics = get_all_topics($forumid, "DESC", $userid)) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+function user_can_post_discussion($forum) {
+// $forum is an object
+ global $USER;
+
+ if ($forum->type == "eachuser") {
+ return (! user_has_posted_discussion($forum->id, $USER->id));
+ } else if ($forum->type == "teacher") {
+ return isteacher($forum->course);
+ } else if (isteacher($forum->course)) {
+ return true;
+ } else {
+ return $forum->open;
+ }
+}
+
+
+function get_all_topics($forum="0", $forum_sort="DESC", $user=0) {
+ if ($user) {
+ $userselect = " AND u.id = '$user' ";
+ } else {
+ $userselect = "";
+ }
+ return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture, u.id as userid
+ FROM forum_discussions d, forum_posts p, user u
+ WHERE d.forum = '$forum' AND p.discussion = d.id AND
+ p.parent= 0 AND p.user = u.id $userselect
+ ORDER BY p.created $forum_sort");
+}
+
+
+
function print_forum_latest_topics($forum_id=0, $forum_numtopics=5, $forum_style="plain", $forum_sort="DESC") {
global $CFG, $USER;
if (user_can_post_discussion($forum)) {
echo "<P ALIGN=right>";
- echo "<A HREF=\"$CFG->wwwroot/mod/discuss/post.php?forum=$forum->id\">Add a new topic...</A>";
- echo "</P>";
+ echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?forum=$forum->id\">Add a new topic...</A>";
+ echo "</P>\n";
}
if (! $topics = get_all_topics($forum->id, $forum_sort) ) {
echo "<P ALIGN=right><A HREF=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">Older topics</A> ...</P>";
break;
}
- if ($replies[$topic->discuss]) {
- $topic->replies = $replies[$topic->discuss]->replies;
+ if ($replies[$topic->discussion]) {
+ $topic->replies = $replies[$topic->discussion]->replies;
} else {
$topic->replies = 0;
}
case "minimal":
echo "<P><FONT COLOR=#555555>".userdate($topic->modified, "%e %B, %H:%M")."</FONT>";
echo "<BR>$topic->subject ";
- echo "<A HREF=\"$CFG->wwwroot/mod/discuss/view.php?d=$topic->discuss\">more...</A>";
+ echo "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$topic->discussion\">more...</A>";
echo "</P>\n";
break;
default:
}
}
+function print_discussion($course, $discussion, $post, $mode) {
+
+ global $USER;
+
+ $ownpost = ($USER->id == $post->user);
+
+ print_post($post, $course->id, $ownpost, $reply=true, $link=false, $rate=false);
+
+ print_mode_form($discussion->id, $mode);
+
+ if ($discussion->assessed && $USER->id) {
+ echo "<FORM NAME=form METHOD=POST ACTION=rate.php>";
+ echo "<INPUT TYPE=hidden NAME=id VALUE=\"$course->id\">";
+ }
+
+ switch ($mode) {
+ case 1 : // Flat ascending
+ case -1 : // Flat descending
+ default:
+ echo "<UL>";
+ print_posts_flat($post->discussion, $course->id, $mode, $discussion->assessed);
+ echo "</UL>";
+ break;
+
+ case 2 : // Threaded
+ print_posts_threaded($post->id, $course->id, 0, $discussion->assessed);
+ break;
+
+ case 3 : // Nested
+ print_posts_nested($post->id, $course->id, $discussion->assessed);
+ break;
+ }
+
+ if ($discussion->assessed && $USER->id) {
+ echo "<CENTER><P ALIGN=center><INPUT TYPE=submit VALUE=\"Send in my latest ratings\"></P></CENTER>";
+ echo "</FORM>";
+ }
+}
+
+function print_posts_flat($discussion, $course, $direction, $assessed) {
+ global $USER;
+
+ $reply = true;
+ $link = false;
+
+ if ($direction < 0) {
+ $sort = "ORDER BY created DESC";
+ } else {
+ $sort = "ORDER BY created ASC";
+ }
+
+ if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture
+ FROM forum_posts p, user u
+ WHERE p.discussion = $discussion AND p.parent > 0 AND p.user = u.id $sort")) {
+
+ foreach ($posts as $post) {
+ $ownpost = ($USER->id == $post->user);
+ print_post($post, $course, $ownpost, $reply, $link, $assessed);
+ }
+ } else {
+ return;
+ }
+}
+
+function print_posts_threaded($parent, $course, $depth, $assessed) {
+ global $USER;
+
+ $reply = true;
+ $link = false;
+
+ if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture
+ FROM forum_posts p, user u
+ WHERE p.parent = '$parent' AND p.user = u.id")) {
+
+ foreach ($posts as $post) {
+
+ echo "<UL>";
+ if ($depth > 0) {
+ $ownpost = ($USER->id == $post->user);
+ print_post($post, $course, $ownpost, $reply, $link, $assessed); // link=true?
+ echo "<BR>";
+ } else {
+ echo "<LI><P><B><A HREF=\"discuss.php?d=$post->discussion&parent=$post->id\">$post->subject</A></B> by $post->firstname $post->lastname, ".userdate($post->created)."</P>";
+ }
+
+ print_posts_threaded($post->id, $course, $depth-1, $assessed);
+ echo "</UL>\n";
+ }
+ } else {
+ return;
+ }
+}
+
+function print_posts_nested($parent, $course, $assessed) {
+ global $USER;
+
+ $reply = true;
+ $link = false;
+
+ if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture
+ FROM forum_posts p, user u
+ WHERE p.parent = $parent AND p.user = u.id
+ ORDER BY p.created ASC ")) {
+
+ foreach ($posts as $post) {
+
+ $ownpost = ($USER->id == $post->user);
+
+ echo "<UL>";
+ print_post($post, $course, $ownpost, $reply, $link, $assessed);
+ echo "<BR>";
+ print_posts_nested($post->id, $course, $assessed);
+ echo "</UL>\n";
+ }
+ } else {
+ return;
+ }
+}
+
+function forum_set_display_mode($mode=0) {
+ global $USER;
+
+ if ($mode) {
+ $USER->mode = $mode;
+ } else if (!$USER->mode) {
+ $USER->mode = $FORUM_DEFAULT_DISPLAY_MODE;
+ }
+}
?>
<input type=radio name=assessed value=0 <? if ($form->assessed == 0) echo "CHECKED"; ?> >No
</td>
</tr>
+<tr>
+ <td align=right><P><B>Force everyone to be subscribed to this forum?:</B></P></TD>
+ <td>
+ <input type=radio name=forcesubscribe value=1 <? if ($form->forcesubscribe == 1) echo "CHECKED"; ?> >Yes
+ <input type=radio name=forcesubscribe value=0 <? if ($form->forcesubscribe == 0) echo "CHECKED"; ?> >No
+ </td>
+</tr>
</table>
<CENTER>
<input type="hidden" name=course value="<? p($form->course) ?>">
// will create a new instance and return the id number
// of the new instance.
+ global $CFG;
+
$forum->timemodified = time();
- return insert_record("forum", $forum);
+ if (! $forum->id = insert_record("forum", $forum)) {
+ return false;
+ }
+
+ if ($forum->type == "single") { // Create related discussion.
+ include_once("$CFG->dirroot/mod/forum/lib.php");
+
+ $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");
+ }
+ }
+
+ return $forum->id;
}
$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");
+ }
+ }
+
return update_record("forum", $forum);
}
global $CFG;
- include("$CFG->dirroot/mod/discuss/lib.php");
+ include_once("$CFG->dirroot/mod/forum/lib.php");
if (! $forum = get_record("forum", "id", "$id")) {
return false;
$result = true;
- if ($discussions = get_records("discuss", "forum", $forum->id)) {
- foreach ($discussions as $discuss) {
- if (! delete_discussion($discuss)) {
+ if ($discussions = get_records("forum_discussions", "forum", $forum->id)) {
+ foreach ($discussions as $discussion) {
+ if (! forum_delete_discussion($discussion)) {
$result = false;
}
}
+++ /dev/null
-<?PHP // $Id$
-
-////////////////////////////////////////////////////////////////////////////////
-// Code fragment to define the module version etc.
-// This fragment is called by /admin/index.php
-////////////////////////////////////////////////////////////////////////////////
-
-$module->fullname = "Forum";
-$module->version = 20020801;
-$module->cron = 0;
-$module->search = "";
-
-function forum_upgrade($oldversion) {
-// This function does anything necessary to upgrade
-// older versions to match current functionality
-
- return true;
-}
-
-
-?>
-
--- /dev/null
+<form name="form" method="post" action="post.php">
+<table cellpadding=5>
+<tr valign=top>
+ <td align=right><P><B><? print_string("subject", "forum"); ?>:</B></P></TD>
+ <td>
+ <input type="text" name="subject" size=60 value="<? p($post->subject) ?>">
+ </td>
+ <td>
+
+ </td>
+</tr>
+<tr valign=top>
+ <td align=right><P><B><? print_string("message", "forum"); ?>:</B><BR><BR><? helpbutton("text", get_string("helptext")) ?></P></TD>
+ <td>
+ <textarea name=message rows=15 cols=50 wrap="virtual"><? p($post->message) ?></textarea>
+ <BR><BR>
+ <input type="hidden" name=course value="<? p($post->course) ?>">
+ <input type="hidden" name=forum value="<? p($post->forum) ?>">
+ <input type="hidden" name=discussion value="<? p($post->discussion) ?>">
+ <input type="hidden" name=parent value="<? p($post->parent) ?>">
+ <input type="hidden" name=user value="<? p($post->user) ?>">
+ <input type="hidden" name=edit value="<? p($post->edit) ?>">
+ <input type="submit" value=" Save my post ">
+ </td>
+ <td>
+ <FONT SIZE=1>
+ <? print_string("postingtip", "forum"); ?>
+ <DIV ALIGN=RIGHT><? helpbutton("questions", get_string("helpquestions"), "moodle", false) ?></DIV>
+ </FONT>
+ </td>
+</tr>
+</table>
+</FORM>
--- /dev/null
+<?PHP // $Id$
+
+// Edit and save a new post to a discussion
+
+
+ require("../../config.php");
+ require("lib.php");
+
+ if (isguest()) {
+ error("Guests are not allowed to post.", $HTTP_REFERER);
+ }
+
+ if (match_referer() && isset($HTTP_POST_VARS)) { // form submitted
+ $post = (object)$HTTP_POST_VARS;
+
+ $post->subject = strip_tags($post->subject); // Strip all tags
+ $post->message = cleantext($post->message); // Clean up any bad tags
+
+ require_login();
+
+ if ($post->edit) { // Updating a post
+ $post->id = $post->edit;
+ if (update_post_in_database($post) ) {
+ add_to_log($post->course, "forum", "update post", "discuss.php?d=$post->discussion&parent=$post->id", "$post->id");
+ redirect(go_back_to("discuss.php?d=$post->discussion"), "Your post was updated", 1);
+ } else {
+ error("Could not update your post due to an unknown error");
+ }
+ } else if ($post->discussion) { // Adding a new post to an existing discussion
+ if ($post->id = add_new_post_to_database($post)) {
+ if ( ! forum_is_subscribed($USER->id, $post->forum) ) {
+ forum_subscribe($USER->id, $post->forum);
+ }
+
+ add_to_log($post->course, "forum", "add post", "discuss.php?d=$post->discussion&parent=$post->id", "$post->id");
+ redirect(go_back_to("discuss.php?d=$post->discussion"),
+ "Your post was successfully added.<P>You have ".format_time($CFG->maxeditingtime)." to edit it if you want to make any changes.", 3);
+ } else {
+ error("Could not add the post due to an unknown error");
+ }
+ } else { // Adding a new discussion
+ $discussion = $post;
+ $discussion->name = $post->subject;
+ $discussion->intro = $post->message;
+ if ($discussion->id = forum_add_discussion($discussion)) {
+ if ( ! forum_is_subscribed($USER->id, $post->forum) ) {
+ forum_subscribe($USER->id, $post->forum);
+ }
+ add_to_log($post->course, "forum", "add discussion", "discuss.php?d=$discussion->id", "$discussion->id");
+ redirect(go_back_to("view.php?f=$post->forum"),
+ "Your post was successfully added.<P>You have ".format_time($CFG->maxeditingtime)." to edit it if you want to make any changes.", 5);
+ } else {
+ error("Could not insert the new discussion.");
+ }
+ }
+ die;
+ }
+
+
+
+ if (isset($forum)) { // User is starting a new discussion in a forum
+
+ $SESSION->fromurl = $HTTP_REFERER;
+
+ if (! $forum = get_record("forum", "id", $forum)) {
+ error("The forum number was incorrect ($forum)");
+ }
+ if (! $course = get_record("course", "id", $forum->course)) {
+ error("The course number was incorrect ($forum)");
+ }
+
+ if (! user_can_post_discussion($forum)) {
+ error("Sorry, but you can not post a new discussion in this forum.");
+ }
+
+ // Load up the $post variable.
+
+ $post->course = $course->id;
+ $post->forum = $forum->id;
+ $post->discussion = 0; // ie discussion # not defined yet
+ $post->parent = 0;
+ $post->subject = "";
+ $post->user = $USER->id;
+ $post->message = "";
+
+ set_fromdiscussion();
+
+ } else if (isset($reply)) { // User is writing a new reply
+
+ if (! $parent = get_forum_post_full($reply)) {
+ error("Parent post ID was incorrect ($reply)");
+ }
+ if (! $discussion = get_record("forum_discussions", "id", $parent->discussion)) {
+ error("This post is not part of a discussion! ($reply)");
+ }
+ if (! $forum = get_record("forum", "id", $discussion->forum)) {
+ error("The forum number was incorrect ($discussion->forum)");
+ }
+ if (! $course = get_record("course", "id", $discussion->course)) {
+ error("The course number was incorrect ($discussion->course)");
+ }
+ // Load up the $post variable.
+
+ $post->course = $course->id;
+ $post->forum = $forum->id;
+ $post->discussion = $parent->discussion;
+ $post->parent = $parent->id;
+ $post->subject = $parent->subject;
+ $post->user = $USER->id;
+ $post->message = "";
+
+ if (!(substr($post->subject, 0, 3) == "Re:")) {
+ $post->subject = "Re: ".$post->subject;
+ }
+
+ set_fromdiscussion();
+
+ } else if (isset($edit)) { // User is editing their own post
+
+ if (! $post = get_forum_post_full($edit)) {
+ error("Post ID was incorrect");
+ }
+ if ($post->user <> $USER->id) {
+ error("You can't edit other people's posts!");
+ }
+ if ((time() - $post->created) > $CFG->maxeditingtime) {
+ error("Sorry, but the maximum time for editing this post (".format_time($CFG->maxeditingtime).") has passed!");
+ }
+ if ($post->parent) {
+ if (! $parent = get_forum_post_full($post->parent)) {
+ error("Parent post ID was incorrect ($post->parent)");
+ }
+ }
+ if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
+ error("This post is not part of a discussion! ($reply)");
+ }
+ if (! $forum = get_record("forum", "id", $discussion->forum)) {
+ error("The forum number was incorrect ($discussion->forum)");
+ }
+ if (! $course = get_record("course", "id", $discussion->course)) {
+ error("The course number was incorrect ($discussion->course)");
+ }
+
+ // Load up the $post variable.
+
+ $post->edit = $edit;
+
+ $post->course = $course->id;
+ $post->forum = $forum->id;
+
+ set_fromdiscussion();
+
+
+ } else if (isset($delete)) { // User is deleting a post
+
+ if (! $post = get_forum_post_full($delete)) {
+ error("Post ID was incorrect");
+ }
+ if ($post->user <> $USER->id) {
+ error("You can't delete other people's posts!");
+ }
+ if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
+ error("This post is not part of a discussion!");
+ }
+
+ if (isset($confirm)) { // User has confirmed the delete
+
+ if ($post->totalscore) {
+ notice("Sorry, that cannot be deleted as people have already rated it",
+ go_back_to("discuss.php?d=$post->discussion"));
+
+ } else if (record_exists("forum_posts", "parent", $delete)) {
+ error("Sorry, that cannot be deleted as people have
+ already responded to it",
+ go_back_to("discuss.php?id=$post->discussion"));
+
+ } else {
+ if (! $post->parent) { // post is a discussion topic as well, so delete discussion
+ forum_delete_discussion($discussion);
+
+ add_to_log($discussion->course, "forum", "delete discussion", "view.php?id=$discussion->forum", "$post->id");
+ redirect("view.php?f=$discussion->forum",
+ "Your discussion topic was deleted", 1);
+
+ } else if (delete_records("forum_posts", "id", $post->id)) {
+
+ add_to_log($discussion->course, "forum", "delete post", "discuss.php?d=$post->discussion", "$post->id");
+ redirect(go_back_to("discuss.php?d=$post->discussion"),
+ "Your post was deleted", 1);
+ } else {
+ error("An error occurred while deleting record $post->id");
+ }
+ }
+
+
+ } else { // User just asked to delete something
+
+ set_fromdiscussion();
+
+ print_header();
+ notice_yesno("Are you sure you want to delete this post?",
+ "post.php?delete=$delete&confirm=$delete",
+ $HTTP_REFERER);
+
+ echo "<CENTER><HR>";
+ print_post($post, 0, $ownpost=false, $reply=false, $link=false);
+
+ }
+
+ die;
+
+
+ } else {
+ error("No operation specified");
+
+ }
+
+
+ // To get here they need to edit a post, and the $post
+ // variable will be loaded with all the particulars,
+ // so bring up the form.
+
+ // $course, $forum are defined. $discussion is for edit and reply only.
+
+ require_login($course->id);
+
+ if ($post->discussion) {
+ if (! $toppost = get_record_sql("SELECT * FROM forum_posts
+ WHERE discussion='$post->discussion'
+ AND parent = 0")) {
+ error("Could not find top parent of post $post->id");
+ }
+ } else {
+ $toppost->subject = "New discussion topic";
+ }
+
+ if ($post->subject) {
+ $formstart = "form.message";
+ } else {
+ $formstart = "form.subject";
+ }
+
+ if ($post->parent) {
+ $navtail = "<A HREF=\"discuss.php?d=$discussion->id\">$toppost->subject</A> -> Editing";
+ } else {
+ $navtail = "$toppost->subject";
+ }
+
+ $navmiddle = "<A HREF=\"../forum/index.php?id=$course->id\">Forums</A> -> <A HREF=\"view.php?f=$forum->id\">$forum->name</A>";
+
+ if ($course->category) {
+ print_header("$course->shortname: $discussion->name: $toppost->subject", "$course->fullname",
+ "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> ->
+ $navmiddle -> $navtail", "$forumstart");
+ } else {
+ print_header("$course->shortname: $discussion->name: $toppost->subject", "$course->fullname",
+ "$navmiddle -> $navtail", "");
+
+ }
+
+ echo "<CENTER>";
+ if (isset($parent)) {
+ print_post($parent, $course->id, $ownpost=false, $reply=false, $link=false);
+ echo "<H2>Your reply:</H2>";
+ } else {
+ echo "<H2>Your new discussion topic:</H2>";
+ }
+ echo "</CENTER>";
+
+ print_simple_box_start("center", "", "$THEME->cellheading");
+ require("post.html");
+ print_simple_box_end();
+
+ print_footer($course);
+
+
+?>
--- /dev/null
+<?PHP // $Id$
+
+// Collect ratings, store them, then return to where we came from
+// Need to do some tricky business and store variables in the
+// SESSION variable, just in case
+
+
+ require("../../config.php");
+ require("lib.php");
+
+ if (isguest()) {
+ error("Guests are not allowed to rate posts.", $HTTP_REFERER);
+ }
+
+ require_variable($id); // The course these ratings are part of
+
+ if (! $course = get_record("course", "id", $id)) {
+ error("Course ID was incorrect");
+ }
+
+ require_login($course->id);
+
+ if (isset($HTTP_POST_VARS)) { // form submitted
+
+ foreach ($HTTP_POST_VARS as $post => $rating) {
+ if ($post == "id") {
+ continue;
+ }
+ if ($rating) {
+ if ($check = get_record_sql("SELECT COUNT(*) as count FROM forum_ratings
+ WHERE user='$USER->id' AND post='$post'")){
+ if ($check->count == 0) {
+ $timenow = time();
+ if (!$rs = $db->Execute("INSERT DELAYED INTO forum_ratings
+ SET user='$USER->id', post='$post', time='$timenow', rating='$rating'")){
+ error("Could not insert a new rating ($post = $rating)");
+ }
+
+ } else {
+ error("You've rated this question before ($post)");
+ }
+ }
+ }
+ }
+ redirect($HTTP_REFERER, "Ratings saved");
+
+ } else {
+ error("This page was not accessed correctly");
+ }
+
+?>
--- /dev/null
+<?PHP // $Id$
+
+// For a given post, shows a report of all the ratings it has
+
+ require("../../config.php");
+ require("lib.php");
+
+ require_variable($id);
+
+ if (! $post = get_record("forum_posts", "id", $id)) {
+ error("Post ID was incorrect");
+ }
+
+ if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
+ error("Forum ID was incorrect");
+ }
+
+ if ($USER->id <> $post->user) {
+ error("You can only look at results for posts you own");
+ }
+
+ if (!isset($sort)) {
+ $sort = "r.time";
+ }
+
+ print_header("(Ratings for) $post->subject");
+
+ if (!$ratings = get_records_sql("SELECT u.*, r.rating, r.time FROM forum_ratings r, user u
+ WHERE r.post='$post->id' AND r.user=u.id ORDER BY $sort")) {
+ echo "No ratings for this post: \"$post->subject\"";
+ die;
+ } else {
+ echo "<TABLE BORDER=0 CELLPADDING=2>";
+ echo "<TR>";
+ echo "<TH> </TH>";
+ echo "<TH><A HREF=report.php?id=$post->id&sort=u.firstname>Name</A>";
+ echo "<TH><A HREF=report.php?id=$post->id&sort=r.rating>Rating</A>";
+ echo "<TH><A HREF=report.php?id=$post->id&sort=r.time>Date</A>";
+ foreach ($ratings as $rating) {
+ if (isteacher($discussion->course, $rating->id)) {
+ echo "<TR BGCOLOR=\"$THEME->cellcontent2\">";
+ } else {
+ echo "<TR BGCOLOR=\"$THEME->cellcontent\">";
+ }
+ echo "<TD>";
+ if ($rating->picture) {
+ echo "<IMG SRC=\"$CFG->wwwroot/user/pix.php/".$rating->picture."/f2.jpg\" ALIGN=left BORDER=0>";
+ } else {
+ echo "<IMG SRC=\"$CFG->wwwroot/user/pix.php/0/f2.jpg\" ALIGN=left BORDER=0>";
+ }
+ echo "<TD NOWRAP><P><FONT SIZE=-1>$rating->firstname $rating->lastname</P>";
+ echo "<TD NOWRAP><P><FONT SIZE=-1>".$FORUM_POST_RATINGS[$rating->rating]."</P>";
+ echo "<TD NOWRAP><P><FONT SIZE=-1>".userdate($rating->time)."</P>";
+ echo "</TR>\n";
+ }
+ echo "</TABLE>";
+ }
+
+ close_window_button();
+
+?>
--- /dev/null
+<?PHP // $Id$
+
+ require("../../config.php");
+ require("lib.php");
+
+ require_variable($id); // course id
+ optional_variable($search, ""); // user id
+
+ $search = strip_tags($search);
+
+ if (! $course = get_record("course", "id", $id)) {
+ error("Course id is incorrect.");
+ }
+
+ require_login($course->id);
+
+ add_to_log($course->id, "course", "search", "search.php?id=$course->id&search=$search", "$search");
+
+ if ($search) {
+ print_header("$course->shortname: Search Results", "$course->fullname",
+ "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->
+ <A HREF=\"index.php?id=$course->id\">Forums</A> ->
+ <A HREF=\"search.php?id=$course->id\">Search</A> -> \"$search\"", "search.search");
+ } else {
+ print_header("$course->shortname: Search", "$course->fullname",
+ "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->
+ <A HREF=\"index.php?id=$course->id\">Forums</A> -> Search", "search.search");
+ }
+
+ echo "<DIV ALIGN=CENTER>";
+ print_forum_search_form($course, $search);
+ echo "</DIV>";
+
+ if ($search) {
+
+ if (!isteacher($course->id)) {
+ $notteacherforum = "AND f.type <> 'teacher'";
+ } else {
+ $notteacherforum = "";
+ }
+
+ $posts = get_records_sql("SELECT p.*,u.firstname,u.lastname,u.email,u.picture,u.id as userid
+ FROM forum_posts p, forum_discussions d, user u, forum f
+ WHERE message LIKE '%$search%' AND p.user = u.id
+ AND p.discussion = d.id AND d.course = '$course->id'
+ AND d.forum = f.id $notteacherforum
+ ORDER BY p.modified DESC LIMIT 0, 50 ");
+
+ if (!$posts) {
+ print_heading("<BR>No posts found containing \"$search\"");
+
+ } else {
+ foreach ($posts as $post) {
+ if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
+ error("Discussion ID was incorrect");
+ }
+ if (! $forum = get_record("forum", "id", "$discussion->forum")) {
+ error("Could not find forum $discussion->forum");
+ }
+ $post->subject = "<A HREF=\"index.php?id=$course->id&forum=$forum->id\">$forum->name</A> -> ".
+ "<A HREF=\"discuss.php?d=$discussion->id\">$discussion->name</A> -> ".
+ "<A HREF=\"discuss.php?d=$post->discussion&parent=$post->id\">$post->subject</A>";
+
+ $post->message = highlight("$search", $post->message);
+
+ $fulllink = "<P ALIGN=right><A HREF=\"discuss.php?d=$post->discussion&parent=$post->id\">See this post in context</A></P>";
+ print_post($post, $course->id, false, false, false, false, $fulllink);
+
+ echo "<BR>";
+ }
+ }
+ }
+
+ print_footer($course);
+
+?>
+
require("../../config.php");
require("lib.php");
- require_variable($id); // The forum to subscribe or unsubscribe to
+ require_variable($id); // The forum to subscribe or unsubscribe to
+ optional_variable($force); // Force everyone to be subscribed to this forum?
if (isguest()) {
error("Guests are not allowed to subscribe to posts.", $HTTP_REFERER);
}
}
-
$returnto = go_back_to("index.php?id=$course->id");
- if ( is_subscribed($USER->id, $forum->id) ) {
+ if ($force and isteacher($course->id)) {
+ if (forum_is_forcesubscribed($forum->id)) {
+ forum_forcesubscribe($forum->id, 0);
+ redirect($returnto, "Everyone can choose their own subscription to this forum", 1);
+ } else {
+ forum_forcesubscribe($forum->id, 1);
+ redirect($returnto, "Everyone is now subscribed to this forum", 1);
+ }
+ }
+
+ if (forum_is_forcesubscribed($forum->id)) {
+ redirect($returnto, "Everyone is subscribed to this forum", 1);
+ }
+
+ if ( forum_is_subscribed($USER->id, $forum->id) ) {
if (forum_unsubscribe($USER->id, $forum->id) ) {
add_to_log($course->id, "forum", "unsubscribe", "index.php?id=$course->id", "$forum->id");
redirect($returnto, "You are now NOT subscribed to receive '$forum->name' by email.", 1);
error("This page is for teachers only");
}
- unset($SESSION->fromdiscuss);
+ unset($SESSION->fromdiscussion);
add_to_log($course->id, "forum", "view subscribers", "subscribers.php?id=$forum->id", "");
echo "<TABLE ALIGN=CENTER>";
$count = 0;
foreach ($users as $user) {
- if (is_subscribed($user->id, $forum->id)) {
+ if (forum_is_subscribed($user->id, $forum->id)) {
echo "<TR><TD>";
print_user_picture($user->id, $course->id, $user->picture);
echo "</TD><TD>";
--- /dev/null
+<?PHP // $Id$
+
+////////////////////////////////////////////////////////////////////////////////
+// Code fragment to define the module version etc.
+// This fragment is called by /admin/index.php
+////////////////////////////////////////////////////////////////////////////////
+
+$module->fullname = "Forum";
+$module->version = 2002073008;
+$module->cron = 60;
+$module->search = "";
+
+function forum_upgrade($oldversion) {
+// This function does anything necessary to upgrade
+// older versions to match current functionality
+
+ if ($oldversion < 2002073008) {
+ execute_sql("DELETE FROM modules WHERE name = 'discuss' ");
+ execute_sql("ALTER TABLE `discuss` RENAME `forum_discussions` ");
+ execute_sql("ALTER TABLE `discuss_posts` RENAME `forum_posts` ");
+ execute_sql("ALTER TABLE `discuss_ratings` RENAME `forum_ratings` ");
+ execute_sql("ALTER TABLE `forum` CHANGE `intro` `intro` TEXT NOT NULL ");
+ execute_sql("ALTER TABLE `forum` ADD `forcesubscribe` TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL AFTER `assessed`");
+ execute_sql("ALTER TABLE `forum` CHANGE `type` `type` ENUM( 'single', 'news', 'social', 'general',
+ 'eachuser', 'teacher' ) DEFAULT 'general' NOT NULL ");
+ execute_sql("ALTER TABLE `forum_posts` CHANGE `discuss` `discussion` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL ");
+ execute_sql("INSERT INTO log_display VALUES ('forum', 'add', 'forum', 'name') ");
+ execute_sql("INSERT INTO log_display VALUES ('forum', 'add discussion', 'forum_discussions', 'name') ");
+ execute_sql("INSERT INTO log_display VALUES ('forum', 'add post', 'forum_posts', 'subject') ");
+ execute_sql("INSERT INTO log_display VALUES ('forum', 'update post', 'forum_posts', 'subject') ");
+ execute_sql("INSERT INTO log_display VALUES ('forum', 'view discussion', 'forum_discussions', 'name') ");
+ execute_sql("DELETE FROM log_display WHERE module = 'discuss' ");
+ execute_sql("UPDATE log SET action = 'view discussion' WHERE module = 'discuss' AND action = 'view' ");
+ execute_sql("UPDATE log SET action = 'add discussion' WHERE module = 'discuss' AND action = 'add' ");
+ execute_sql("UPDATE log SET module = 'forum' WHERE module = 'discuss' ");
+ notify("Renamed all the old discuss tables (now part of forum) and created new forum_types");
+ }
+
+ return true;
+
+}
+
+
+
+?>
+
optional_variable($id); // Course Module ID
optional_variable($f); // Forum ID
+ optional_variable($mode); // Display mode (for single forum)
if ($id) {
}
}
-
add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id");
print_header("$course->shortname: $forum->name", "$course->fullname",
"$navigation $forum->name", "", "", true, $buttontext);
if ($USER) {
- $SESSION->fromdiscuss = "$FULLME";
- if (is_subscribed($USER->id, $forum->id)) {
- $subtext = "Unsubscribe me from this forum";
+ $SESSION->fromdiscussion = "$FULLME";
+ if (forum_is_forcesubscribed($forum->id)) {
+ $subtext = "Everyone is subscribed to this forum";
+ if (isteacher($course->id)) {
+ echo "<DIV ALIGN=RIGHT><FONT SIZE=1>";
+ echo "<A TITLE=\"Allow people to choose\" HREF=\"subscribe.php?id=$forum->id&force=no\">$subtext</A>";
+ echo "</FONT></DIV>";
+ } else {
+ echo "<DIV ALIGN=RIGHT><FONT SIZE=1>$subtext</FONT></DIV>";
+ }
+
} else {
- $subtext = "Subscribe me to this forum";
- }
- echo "<DIV ALIGN=RIGHT><FONT SIZE=1><A HREF=\"subscribe.php?id=$forum->id\">$subtext</A></FONT></DIV>";
- if (isteacher($course->id)) {
- echo "<DIV ALIGN=RIGHT><FONT SIZE=1><A HREF=\"subscribers.php?id=$forum->id\">Show subscribers</A></FONT></DIV>";
+ $subtext = "Everyone can choose to be subscribed";
+ if (isteacher($course->id)) {
+ echo "<DIV ALIGN=RIGHT><FONT SIZE=1>";
+ echo "<A TITLE=\"Force everyone to subscribe\" HREF=\"subscribe.php?id=$forum->id&force=yes\">$subtext</A>";
+ echo "</FONT></DIV>";
+ $subtext = "<A HREF=\"subscribers.php?id=$forum->id\">Show subscribers</A>";
+ echo "<DIV ALIGN=RIGHT><FONT SIZE=1>$subtext</FONT></DIV>";
+ }
+ if (forum_is_subscribed($USER->id, $forum->id)) {
+ $subtext = "Unsubscribe me";
+ } else {
+ $subtext = "Subscribe me";
+ }
+ $subtext = "<A TITLE=\"For this forum only\" HREF=\"subscribe.php?id=$forum->id\">$subtext</A>";
+ echo "<DIV ALIGN=RIGHT><FONT SIZE=1>$subtext</FONT></DIV>";
}
}
- print_simple_box(text_to_html($forum->intro), "CENTER");
switch ($forum->type) {
+ case "single":
+ 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_forum_post_full($discussion->firstpost)) {
+ error("Could not find the first post in this forum");
+ }
+ forum_set_display_mode($mode);
+ print_discussion($course, $discussion, $post, $USER->mode);
+ break;
+
case "eachuser":
+ print_simple_box(text_to_html($forum->intro), "CENTER");
echo "<P ALIGN=CENTER>";
if (user_can_post_discussion($forum)) {
echo "This forum allows one discussion topic to be posted per person.";
echo " ";
}
echo "</P>";
+ print_forum_latest_topics($forum->id, 0);
break;
default:
+ print_simple_box(text_to_html($forum->intro), "CENTER");
echo "<P> </P>";
+ print_forum_latest_topics($forum->id, 0);
break;
}
- print_forum_latest_topics($forum->id, 0);
print_footer($course);
require("../config.php");
require("../lib/countries.php");
+ require("../mod/forum/lib.php");
require("lib.php");
- require("../mod/discuss/lib.php");
require_variable($id);
require_variable($course);
// If there's something it cannot do itself, it
// will tell you what you need to do.
-$version = 2002072801;
+$version = 2002073100;
function upgrade_moodle($oldversion=0) {
`value` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
- ) TYPE=MyISAM COMMENT='Moodle configuration variables';");
+ ) COMMENT='Moodle configuration variables';");
notify("Created a new table 'config' to hold configuration data");
}
- if ($oldversion < 2002072801) {
-
+ if ($oldversion < 2002073100) {
+ execute_sql("DELETE FROM `modules` WHERE `name` = 'chat' ");
}
+
return true;
}