// social.php - course format featuring social forum
// included from view.php
- include("../mod/discuss/lib.php");
+ include("../mod/forum/lib.php");
include("../mod/reading/lib.php");
?>
// courses that aren't so rigidly defined by time.
// Included from "view.php"
- include("../mod/discuss/lib.php");
+ include("../mod/forum/lib.php");
if (! $rawweeks = get_records("course_weeks", "course", $course->id) ) {
$week->course = $course->id; // Create a default week.
}
// remove some other things
- delete_records("discuss_subscriptions", "user", $user->id);
+ delete_records("forum_subscriptions", "user", $user->id);
add_to_log($course->id, "course", "unenrol", "view.php?id=$course->id", "$user->id");
// Display the whole course as "weeks" made of of modules
// Included from "view.php"
- include("../mod/discuss/lib.php");
+ include("../mod/forum/lib.php");
if (! $rawweeks = get_records("course_weeks", "course", $course->id) ) {
$week->course = $course->id; // Create a default week.
require("config.php");
include("course/lib.php");
include("mod/reading/lib.php");
- include("mod/discuss/lib.php");
+ include("mod/forum/lib.php");
if (! $site = get_record("course", "category", 0)) {
redirect("$CFG->wwwroot/admin/");
}
+function print_object($object) {
+// Mostly just for debugging
+
+ $array = (array)$object;
+ foreach ($array as $key => $item) {
+ echo "$key -> $item <BR>";
+ }
+}
+
+
/// USER DATABASE ////////////////////////////////////////////////
--- /dev/null
+#
+# Table structure for table `forum`
+#
+
+CREATE TABLE forum (
+ id int(10) unsigned NOT NULL auto_increment,
+ course int(10) unsigned NOT NULL default '0',
+ type enum('discussion','news','general','social') NOT NULL default 'general',
+ name varchar(255) NOT NULL default '',
+ intro tinytext NOT NULL,
+ open tinyint(1) unsigned NOT NULL default '0',
+ assessed tinyint(1) unsigned NOT NULL default '0',
+ timemodified int(10) unsigned NOT NULL default '0',
+ PRIMARY KEY (id),
+ UNIQUE KEY id (id)
+) TYPE=MyISAM COMMENT='Discussion Forums';
+# --------------------------------------------------------
+
+#
+# Table structure for table `forum_subscriptions`
+#
+
+CREATE TABLE forum_subscriptions (
+ id int(10) unsigned NOT NULL auto_increment,
+ user int(10) unsigned NOT NULL default '0',
+ 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';
+
+
+#
+# Dumping data for table `log_display`
+#
+
+INSERT INTO log_display VALUES ('discuss', 'view forum', 'forum', 'name');
+INSERT INTO log_display VALUES ('discuss', 'subscribe', 'forum', 'name');
+INSERT INTO log_display VALUES ('discuss', 'unsubscribe', 'forum', 'name');
--- /dev/null
+<?PHP // $Id$
+
+ require("../../config.php");
+ require("lib.php");
+
+ optional_variable($id); // course
+
+ if ($id) {
+ if (! $course = get_record("course", "id", $id)) {
+ error("Course ID is incorrect");
+ }
+ } else {
+ if (! $course = get_record("course", "category", 0)) {
+ error("Could not find a top-level course!");
+ }
+ }
+
+ if ($course->category) {
+ require_login($course->id);
+ }
+
+ unset($SESSION->fromdiscuss);
+
+ add_to_log($course->id, "forum", "view forums", "index.php?id=$course->id", "");
+
+ if ($course->category) {
+ print_header("$course->shortname: Forums", "$course->fullname",
+ "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> -> Forums", "");
+ } else {
+ print_header("$course->shortname: Forums", "$course->fullname", "Forums", "");
+ }
+
+ $can_subscribe = (isstudent($course->id) || isteacher($course->id) || isadmin());
+ if ($can_subscribe) {
+ $table->head = array ("Forum", "Description", "Topics", "Subscribed");
+ } else {
+ $table->head = array ("Forum", "Description", "Topics");
+ }
+ $table->align = array ("LEFT", "LEFT", "CENTER", "CENTER");
+
+ if ($forums = get_records("forum", "course", $id, "name ASC")) {
+ foreach ($forums as $forum) {
+ $count = count_records("discuss", "forum", "$forum->id");
+
+ if ($can_subscribe) {
+ if (is_subscribed($USER->id, $forum->id)) {
+ $subscribed = "YES";
+ } else {
+ $subscribed = "NO";
+ }
+ $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>");
+ } else {
+ $table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
+ "$forum->intro",
+ "$count");
+ }
+ }
+ }
+
+ print_table($table);
+
+ print_footer($course);
+
+?>
--- /dev/null
+<?PHP // $Id$
+
+
+include("$CFG->dirroot/mod/discuss/lib.php");
+
+// 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");
+
+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'");
+}
+
+
+function get_all_topics($forum="0", $forum_sort="DESC") {
+ 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
+ ORDER BY p.created $forum_sort");
+}
+
+
+function get_course_news_forum($courseid) {
+ if ($forum = get_record_sql("SELECT * from forum WHERE course = '$courseid' AND type = 'news'")) {
+ return $forum;
+ } else {
+ // Doesn't exist, so create one now.
+ $forum->course = $courseid;
+ $forum->type = "news";
+ $forum->name = "News";
+ $forum->intro= "General news about this course";
+ $forum->open = 0;
+ $forum->assessed = 0;
+ $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;
+ } else {
+ // Doesn't exist, so create one now.
+ $forum->course = $courseid;
+ $forum->type = "social";
+ $forum->name = "Social";
+ $forum->intro= "A forum to socialise and talk about anything you like";
+ $forum->open = 1;
+ $forum->assessed = 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= "Discussions about course content";
+ $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 forum_latest_topics($forum_id=0, $forum_numtopics=5, $forum_style="plain", $forum_sort="DESC") {
+ global $CFG, $USER;
+
+ if ($forum_id) {
+ if (! $forum = get_record("forum", "id", $forum_id)) {
+ error("Forum ID was incorrect");
+ }
+ if (! $course = get_record("course", "id", $forum->course)) {
+ error("Could not find the course this forum belongs to!");
+ }
+
+ if ($course->category) {
+ require_login($course->id);
+ }
+
+ } else {
+ if (! $course = get_record("course", "category", 0)) {
+ error("Could not find a top-level course!");
+ }
+ if (! $forum = get_course_news_forum($course->id)) {
+ error("Could not find or create a main forum in this course (id $course->id)");
+ }
+ }
+
+ if (! $topics = get_all_topics($forum->id, $forum_sort) ) {
+ echo "<P><B>There are no discussion topics yet in this forum.</B></P>";
+
+ } else {
+
+ $replies = count_discussion_replies($forum->id);
+
+ $topiccount = 0;
+
+ foreach ($topics as $topic) {
+ $topiccount++;
+
+ if ($forum_numtopics && ($topiccount > $forum_numtopics)) {
+ echo "<P ALIGN=right><A HREF=\"$CFG->wwwroot/mod/discuss/index.php?forum=$forum->id\">Older topics</A> ...</P>";
+ break;
+ }
+ if ($replies[$topic->discuss]) {
+ $topic->replies = $replies[$topic->discuss]->replies;
+ } else {
+ $topic->replies = 0;
+ }
+ $ownpost = ($topic->userid == $USER->id);
+ switch ($forum_style) {
+ case "minimal":
+ echo "<P><FONT COLOR=#555555>".userdate($topic->modified, "j M H:i")."</FONT>";
+ echo "<BR>$topic->subject ";
+ echo "<A HREF=\"$CFG->wwwroot/mod/discuss/view.php?d=$topic->discuss\">more...</A>";
+ echo "</P>\n";
+ break;
+ default:
+ print_post($topic, $forum->course, $ownpost, $reply=0, $link=1, $assessed=false);
+ echo "<BR>\n";
+ break;
+ }
+ }
+ }
+ if ($forum->open || $USER->editing) {
+ echo "<P ALIGN=right>";
+ echo "<A HREF=\"$CFG->wwwroot/mod/discuss/post.php?forum=$forum->id\">Add a new topic...</A>";
+ echo "</P>";
+ }
+
+}
+
+
+?>
--- /dev/null
+<form name="form" method="post" action="<?=$ME ?>">
+<table cellpadding=5>
+<tr>
+<tr valign=top>
+ <td align=right><P><B>Forum Name:</B></P></TD>
+ <td>
+ <input type="text" name="name" size=30 value="<? p($form->name) ?>">
+ </td>
+</tr>
+<tr valign=top>
+ <td align=right><P><B>Type of Forum:</B></P></TD>
+ <td>
+ <?
+ $student = strtolower($course->student);
+ require("$CFG->dirroot/mod/forum/lib.php");
+ asort($FORUM_TYPE);
+ choose_from_menu($FORUM_TYPE, "type", $form->type);
+ ?>
+
+ </td>
+</tr>
+<tr valign=top>
+ <td align=right><P><B>Forum Introduction:</B></P></TD>
+ <td>
+ <textarea name="intro" rows=4 cols=50 wrap="virtual"><? p($form->intro) ?></textarea>
+ </td>
+</tr>
+
+<tr valign=top>
+ <td align=right><P><B>Can <?=$course->student?>s start new discussions?:</B></P></TD>
+ <td>
+ <input type=radio name=open value=1 <? if ($form->open == 1) echo "CHECKED"; ?> >Yes
+ <input type=radio name=open value=0 <? if ($form->open == 0) echo "CHECKED"; ?> >No
+ </td>
+</tr>
+<tr>
+ <td align=right><P><B>Will this forum contain assessments?:</B></P></TD>
+ <td>
+ <input type=radio name=assessed value=1 <? if ($form->assessed == 1) echo "CHECKED"; ?> >Yes
+ <input type=radio name=assessed value=0 <? if ($form->assessed == 0) echo "CHECKED"; ?> >No
+ </td>
+</tr>
+</table>
+<CENTER>
+<input type="hidden" name=course value="<? p($form->course) ?>">
+<input type="hidden" name=coursemodule value="<? p($form->coursemodule) ?>">
+<input type="hidden" name=week value="<? p($form->week) ?>">
+<input type="hidden" name=module value="<? p($form->module) ?>">
+<input type="hidden" name=modulename value="<? p($form->modulename) ?>">
+<input type="hidden" name=instance value="<? p($form->instance) ?>">
+<input type="hidden" name=mode value="<? p($form->mode) ?>">
+<input type="submit" value="Save these settings">
+</CENTER>
+</FORM>
--- /dev/null
+<?PHP // $Id$
+
+/////////////////////////////////////////////////////////////
+//
+// MOD.PHP - contains functions to add, update and delete
+// an instance of this module
+//
+// Generally called from /course/mod.php
+//
+/////////////////////////////////////////////////////////////
+
+function add_instance($forum) {
+// Given an object containing all the necessary data,
+// (defined by the form in mod.html) this function
+// will create a new instance and return the id number
+// of the new instance.
+
+ $forum->timemodified = time();
+
+ return insert_record("forum", $forum);
+}
+
+
+function update_instance($forum) {
+// Given an object containing all the necessary data,
+// (defined by the form in mod.html) this function
+// will update an existing instance with new data.
+
+ $forum->timemodified = time();
+ $forum->id = $forum->instance;
+
+ return update_record("forum", $forum);
+}
+
+
+function 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.
+
+ global $CFG;
+
+ include("$CFG->dirroot/mod/discuss/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)) {
+ $result = false;
+ }
+ }
+ }
+
+ if (! delete_records("forum_subscriptions", "forum", "$forum->id")) {
+ $result = false;
+ }
+
+ if (! delete_records("forum", "id", "$forum->id")) {
+ $result = false;
+ }
+
+ return $result;
+}
+
+
+?>
--- /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 = "";
+
+?>
+
--- /dev/null
+<?PHP // $Id$
+
+// Subscribe to or unsubscribe from a forum.
+
+ require("../../config.php");
+ require("lib.php");
+
+ require_variable($id); // The forum to subscribe or unsubscribe to
+
+ if (isguest()) {
+ error("Guests are not allowed to subscribe to posts.", $HTTP_REFERER);
+ }
+
+ if (! $forum = get_record("forum", "id", $id)) {
+ error("Forum ID was incorrect");
+ }
+
+ if (! $course = get_record("course", "id", $forum->course)) {
+ error("Forum doesn't belong to a course!");
+ }
+
+ if ($course->category) {
+ require_login($forum->course);
+ } else {
+ require_login();
+ }
+
+ $returnto = go_back_to("index.php?id=$course->id");
+
+ if ( 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);
+ } else {
+ error("Could not unsubscribe you from that forum", "$HTTP_REFERER");
+ }
+
+ } else { // subscribe
+ if (forum_subscribe($USER->id, $forum->id) ) {
+ add_to_log($course->id, "forum", "subscribe", "index.php?id=$course->id", "$forum->id");
+ redirect($returnto, "You are now subscribed to recieve '$forum->name' by email.", 1);
+ } else {
+ error("Could not subscribe you to that forum", "$HTTP_REFERER");
+ }
+ }
+
+?>
--- /dev/null
+<?PHP // $Id$
+
+ require("../../config.php");
+ require("lib.php");
+
+ optional_variable($id); // Course Module ID
+ optional_variable($f); // Forum ID
+
+
+ if ($id) {
+ if (! $cm = get_record("course_modules", "id", $id)) {
+ error("Course Module ID was incorrect");
+ }
+ if (! $course = get_record("course", "id", $cm->course)) {
+ error("Course is misconfigured");
+ }
+ if (! $forum = get_record("forum", "id", $cm->instance)) {
+ error("Forum ID was incorrect");
+ }
+ $buttontext = update_module_icon($cm->id);
+
+ } else if ($f) {
+ if (! $forum = get_record("forum", "id", $f)) {
+ error("Forum ID was incorrect");
+ }
+ if (! $course = get_record("course", "id", $forum->course)) {
+ error("Forum is misconfigured - don't know what course it's from");
+ }
+ $buttontext = "";
+
+ } else {
+ error("Must specify a course module or a forum ID");
+ }
+
+ if ($course->category) {
+ require_login($course->id);
+ $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->
+ <A HREF=\"index.php?id=$course->id\">Forums</A> ->";
+ }
+
+ add_to_log($course->id, "forum", "view forum", "index.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 from this forum";
+ } else {
+ $subtext = "Subscribe to this forum";
+ }
+ echo "<DIV ALIGN=RIGHT><FONT SIZE=1><A HREF=\"subscribe.php?id=$forum->id\">$subtext</A></FONT></P>";
+ }
+
+ forum_latest_topics($forum->id, 0);
+
+ print_footer($course);
+
+?>