echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">";
}
+
+
+/// MODULE FUNCTIONS /////////////////////////////////////////////////////////////////
+
+function add_course_module($mod) {
+ GLOBAL $db;
+
+ $timenow = time();
+
+ if (!$rs = $db->Execute("INSERT into course_modules
+ SET course = '$mod->course',
+ module = '$mod->module',
+ instance = '$mod->instance',
+ section = '$mod->section',
+ added = '$timenow' ")) {
+ return 0;
+ }
+
+ // Get it out again - this is the most compatible way to determine the ID
+ if ($rs = $db->Execute("SELECT id FROM course_modules
+ WHERE module = $mod->module AND added = $timenow")) {
+ return $rs->fields[0];
+ } else {
+ return 0;
+ }
+
+}
+
+function add_mod_to_section($mod) {
+// Returns the course_sections ID where the mod is inserted
+ GLOBAL $db;
+
+ if ($cw = get_record_sql("SELECT * FROM course_sections
+ WHERE course = '$mod->course' AND section = '$mod->section'") ) {
+
+ if ($cw->sequence) {
+ $newsequence = "$cw->sequence,$mod->coursemodule";
+ } else {
+ $newsequence = "$mod->coursemodule";
+ }
+ if (!$rs = $db->Execute("UPDATE course_sections SET sequence = '$newsequence' WHERE id = '$cw->id'")) {
+ return 0;
+ } else {
+ return $cw->id; // Return course_sections ID that was used.
+ }
+
+ } else { // Insert a new record
+ if (!$rs = $db->Execute("INSERT into course_sections
+ SET course = '$mod->course',
+ section = '$mod->section',
+ summary = '',
+ sequence = '$mod->coursemodule' ")) {
+ return 0;
+ }
+ // Get it out again - this is the most compatible way to determine the ID
+ if ($rs = $db->Execute("SELECT id FROM course_sections
+ WHERE course = '$mod->course' AND section = '$mod->section'")) {
+ return $rs->fields[0];
+ } else {
+ return 0;
+ }
+ }
+}
+
+function delete_course_module($mod) {
+ return set_field("course_modules", "deleted", 1, "id", $mod);
+}
+
+function delete_mod_from_section($mod, $section) {
+ GLOBAL $db;
+
+ if ($cw = get_record("course_sections", "id", "$section") ) {
+
+ $modarray = explode(",", $cw->sequence);
+
+ if ($key = array_keys ($modarray, $mod)) {
+ array_splice($modarray, $key[0], 1);
+ $newsequence = implode(",", $modarray);
+ return set_field("course_sections", "sequence", $newsequence, "id", $cw->id);
+ } else {
+ return false;
+ }
+
+ } else {
+ return false;
+ }
+}
+
+
+function move_module($id, $move) {
+ GLOBAL $db;
+
+ if (!$move) {
+ return true;
+ }
+
+ if (! $cm = get_record("course_modules", "id", $id)) {
+ error("This course module doesn't exist");
+ }
+
+ if (! $thissection = get_record("course_sections", "id", $cm->section)) {
+ error("This course section doesn't exist");
+ }
+
+ $mods = explode(",", $thissection->sequence);
+
+ $len = count($mods);
+ $pos = array_keys($mods, $cm->id);
+ $thepos = $pos[0];
+
+ if ($len == 0 || count($pos) == 0 ) {
+ error("Very strange. Could not find the required module in this section.");
+ }
+
+ if ($len == 1) {
+ $first = true;
+ $last = true;
+ } else {
+ $first = ($thepos == 0);
+ $last = ($thepos == $len - 1);
+ }
+
+ if ($move < 0) { // Moving the module up
+
+ if ($first) {
+ if ($thissection->section == 1) { // First section, do nothing
+ return true;
+ } else { // Push onto end of previous section
+ $prevsectionnumber = $thissection->section - 1;
+ if (! $prevsection = get_record_sql("SELECT * FROM course_sections
+ WHERE course='$thissection->course'
+ AND section='$prevsectionnumber' ")) {
+ error("Previous section ($prevsection->id) doesn't exist");
+ }
+
+ if ($prevsection->sequence) {
+ $newsequence = "$prevsection->sequence,$cm->id";
+ } else {
+ $newsequence = "$cm->id";
+ }
+
+ if (! set_field("course_sections", "sequence", $newsequence, "id", $prevsection->id)) {
+ error("Previous section could not be updated");
+ }
+
+ if (! set_field("course_modules", "section", $prevsection->id, "id", $cm->id)) {
+ error("Module could not be updated");
+ }
+
+ array_splice($mods, 0, 1);
+ $newsequence = implode(",", $mods);
+ if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
+ error("Module could not be updated");
+ }
+
+ return true;
+
+ }
+ } else { // move up within this section
+ $swap = $mods[$thepos-1];
+ $mods[$thepos-1] = $mods[$thepos];
+ $mods[$thepos] = $swap;
+
+ $newsequence = implode(",", $mods);
+ if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
+ error("This section could not be updated");
+ }
+ return true;
+ }
+
+ } else { // Moving the module down
+
+ if ($last) {
+ $nextsectionnumber = $thissection->section + 1;
+ if ($nextsection = get_record_sql("SELECT * FROM course_sections
+ WHERE course='$thissection->course'
+ AND section='$nextsectionnumber' ")) {
+
+ if ($nextsection->sequence) {
+ $newsequence = "$cm->id,$nextsection->sequence";
+ } else {
+ $newsequence = "$cm->id";
+ }
+
+ if (! set_field("course_sections", "sequence", $newsequence, "id", $nextsection->id)) {
+ error("Next section could not be updated");
+ }
+
+ if (! set_field("course_modules", "section", $nextsection->id, "id", $cm->id)) {
+ error("Module could not be updated");
+ }
+
+ array_splice($mods, $thepos, 1);
+ $newsequence = implode(",", $mods);
+ if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
+ error("This section could not be updated");
+ }
+ return true;
+
+ } else { // There is no next section, so just return
+ return true;
+
+ }
+ } else { // move down within this section
+ $swap = $mods[$thepos+1];
+ $mods[$thepos+1] = $mods[$thepos];
+ $mods[$thepos] = $swap;
+
+ $newsequence = implode(",", $mods);
+ if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
+ error("This section could not be updated");
+ }
+ return true;
+ }
+ }
+}
+
+
?>
print_footer($course);
- exit;
-
-
-/// FUNCTIONS //////////////////////////////////////////////////////////////////////
-
-function add_course_module($mod) {
- GLOBAL $db;
-
- $timenow = time();
-
- if (!$rs = $db->Execute("INSERT into course_modules
- SET course = '$mod->course',
- module = '$mod->module',
- instance = '$mod->instance',
- section = '$mod->section',
- added = '$timenow' ")) {
- return 0;
- }
-
- // Get it out again - this is the most compatible way to determine the ID
- if ($rs = $db->Execute("SELECT id FROM course_modules
- WHERE module = $mod->module AND added = $timenow")) {
- return $rs->fields[0];
- } else {
- return 0;
- }
-
-}
-
-function add_mod_to_section($mod) {
-// Returns the course_sections ID where the mod is inserted
- GLOBAL $db;
-
- if ($cw = get_record_sql("SELECT * FROM course_sections
- WHERE course = '$mod->course' AND section = '$mod->section'") ) {
-
- if ($cw->sequence) {
- $newsequence = "$cw->sequence,$mod->coursemodule";
- } else {
- $newsequence = "$mod->coursemodule";
- }
- if (!$rs = $db->Execute("UPDATE course_sections SET sequence = '$newsequence' WHERE id = '$cw->id'")) {
- return 0;
- } else {
- return $cw->id; // Return course_sections ID that was used.
- }
-
- } else { // Insert a new record
- if (!$rs = $db->Execute("INSERT into course_sections
- SET course = '$mod->course',
- section = '$mod->section',
- summary = '',
- sequence = '$mod->coursemodule' ")) {
- return 0;
- }
- // Get it out again - this is the most compatible way to determine the ID
- if ($rs = $db->Execute("SELECT id FROM course_sections
- WHERE course = '$mod->course' AND section = '$mod->section'")) {
- return $rs->fields[0];
- } else {
- return 0;
- }
- }
-}
-
-function delete_course_module($mod) {
- return set_field("course_modules", "deleted", 1, "id", $mod);
-}
-
-function delete_mod_from_section($mod, $section) {
- GLOBAL $db;
-
- if ($cw = get_record("course_sections", "id", "$section") ) {
-
- $modarray = explode(",", $cw->sequence);
-
- if ($key = array_keys ($modarray, $mod)) {
- array_splice($modarray, $key[0], 1);
- $newsequence = implode(",", $modarray);
- return set_field("course_sections", "sequence", $newsequence, "id", $cw->id);
- } else {
- return false;
- }
-
- } else {
- return false;
- }
-}
-
-
-function move_module($id, $move) {
- GLOBAL $db;
-
- if (!$move) {
- return true;
- }
-
- if (! $cm = get_record("course_modules", "id", $id)) {
- error("This course module doesn't exist");
- }
-
- if (! $thissection = get_record("course_sections", "id", $cm->section)) {
- error("This course section doesn't exist");
- }
-
- $mods = explode(",", $thissection->sequence);
-
- $len = count($mods);
- $pos = array_keys($mods, $cm->id);
- $thepos = $pos[0];
-
- if ($len == 0 || count($pos) == 0 ) {
- error("Very strange. Could not find the required module in this section.");
- }
-
- if ($len == 1) {
- $first = true;
- $last = true;
- } else {
- $first = ($thepos == 0);
- $last = ($thepos == $len - 1);
- }
-
- if ($move < 0) { // Moving the module up
-
- if ($first) {
- if ($thissection->section == 1) { // First section, do nothing
- return true;
- } else { // Push onto end of previous section
- $prevsectionnumber = $thissection->section - 1;
- if (! $prevsection = get_record_sql("SELECT * FROM course_sections
- WHERE course='$thissection->course'
- AND section='$prevsectionnumber' ")) {
- error("Previous section ($prevsection->id) doesn't exist");
- }
-
- if ($prevsection->sequence) {
- $newsequence = "$prevsection->sequence,$cm->id";
- } else {
- $newsequence = "$cm->id";
- }
-
- if (! set_field("course_sections", "sequence", $newsequence, "id", $prevsection->id)) {
- error("Previous section could not be updated");
- }
-
- if (! set_field("course_modules", "section", $prevsection->id, "id", $cm->id)) {
- error("Module could not be updated");
- }
-
- array_splice($mods, 0, 1);
- $newsequence = implode(",", $mods);
- if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
- error("Module could not be updated");
- }
-
- return true;
-
- }
- } else { // move up within this section
- $swap = $mods[$thepos-1];
- $mods[$thepos-1] = $mods[$thepos];
- $mods[$thepos] = $swap;
-
- $newsequence = implode(",", $mods);
- if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
- error("This section could not be updated");
- }
- return true;
- }
-
- } else { // Moving the module down
-
- if ($last) {
- $nextsectionnumber = $thissection->section + 1;
- if ($nextsection = get_record_sql("SELECT * FROM course_sections
- WHERE course='$thissection->course'
- AND section='$nextsectionnumber' ")) {
-
- if ($nextsection->sequence) {
- $newsequence = "$cm->id,$nextsection->sequence";
- } else {
- $newsequence = "$cm->id";
- }
-
- if (! set_field("course_sections", "sequence", $newsequence, "id", $nextsection->id)) {
- error("Next section could not be updated");
- }
-
- if (! set_field("course_modules", "section", $nextsection->id, "id", $cm->id)) {
- error("Module could not be updated");
- }
-
- array_splice($mods, $thepos, 1);
- $newsequence = implode(",", $mods);
- if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
- error("This section could not be updated");
- }
- return true;
-
- } else { // There is no next section, so just return
- return true;
-
- }
- } else { // move down within this section
- $swap = $mods[$thepos+1];
- $mods[$thepos+1] = $mods[$thepos];
- $mods[$thepos] = $swap;
-
- $newsequence = implode(",", $mods);
- if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
- error("This section could not be updated");
- }
- return true;
- }
- }
-}
-
?>
-
-
<TR>
<TD WIDTH="15%" VALIGN="TOP">
<?
- //if ($news = get_course_news_forum($course->id)) {
- //print_forum_latest_topics($news->id, 5, "minimal", "DESC", false);
+ //if ($news = forum_get_course_forum($course->id, "news")) {
+ //forum_print_latest_discussions($news->id, 5, "minimal", "DESC", false);
//}
//echo "<BR><BR>";
print_side_block("", $admindata, "", $adminicon);
}
- ?>
- </TD>
+ echo "</TD>";
- <TD WIDTH="55%" VALIGN="TOP">
- <?
- if (!$social = get_course_social_forum($course->id)) {
- error("Could not find or create a social forum here");
- }
+ echo "<TD WIDTH=\"55%\" VALIGN=\"TOP\">";
+ if ($social = forum_get_course_forum($course->id, "social")) {
+ if (forum_is_subscribed($USER->id, $social->id)) {
+ $subtext = "Unsubscribe";
+ } else {
+ $subtext = "Subscribe me by mail";
+ }
+ $headertext = "<TABLE BORDER=0 WIDTH=100% CELLPADDING=0 CELLSPACING=0><TR><TD>Social Forum - Current Topics<TD ALIGN=RIGHT><FONT SIZE=1><A HREF=\"../mod/forum/subscribe.php?id=$social->id\">$subtext</A></TD></TR></TABLE>";
+ print_simple_box("$headertext", $align="CENTER", $width="100%", $color="$THEME->cellheading");
+ echo "<IMG ALT=\"\" HEIGHT=7 SRC=\"../pix/spacer.gif\"><BR>";
+
+ forum_print_latest_discussions($social->id, 10, "plain", "DESC", false);
+ $SESSION->fromdiscussion = "$CFG->wwwroot/course/view.php?id=$course->id";
- $SESSION->fromdiscussion = "$CFG->wwwdir/course/view.php?id=$course->id";
- if (forum_is_subscribed($USER->id, $social->id)) {
- $subtext = "Unsubscribe";
} else {
- $subtext = "Subscribe me by mail";
+ notify("Could not find or create a social forum here");
}
- $headertext = "<TABLE BORDER=0 WIDTH=100% CELLPADDING=0 CELLSPACING=0><TR><TD>Social Forum - Current Topics<TD ALIGN=RIGHT><FONT SIZE=1><A HREF=\"../mod/forum/subscribe.php?id=$social->id\">$subtext</A></TD></TR></TABLE>";
- print_simple_box("$headertext", $align="CENTER", $width="100%", $color="$THEME->cellheading"); ?>
- <IMG ALT="" HEIGHT=7 SRC="../pix/spacer.gif"><BR>
-
- <?
- if ($social = get_course_social_forum($course->id)) {
- print_forum_latest_topics($social->id, 10, "plain", "DESC", false);
- } else {
- error("Could not find or create a social forum here");
- }
?>
-
- </TD>
- </TR>
+ </TD>
+ </TR>
</TABLE>
} else {
$admindata[]="<A HREF=\"view.php?id=$course->id&edit=on\">Turn editing on</A>";
}
- if ($teacherforum = get_course_teacher_forum($course->id)) {
+ if ($teacherforum = forum_get_course_forum($course->id, "teacher")) {
$admindata[]="<A HREF=\"../mod/forum/view.php?f=$teacherforum->id\">Teacher Forum...</A>";
$adminicon[]="<IMG SRC=\"../mod/forum/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"Teacher Forum\">";
}
// Print all the news items.
- if ($news = get_course_news_forum($course->id)) {
+ if ($news = forum_get_course_forum($course->id, "news")) {
print_simple_box("Latest News", $align="CENTER", $width="100%", $color="$THEME->cellheading");
print_simple_box_start("CENTER", "100%", "#FFFFFF", 3, 0);
echo "<FONT SIZE=1>";
- print_forum_latest_topics($news->id, $course->newsitems, "minimal", "DESC", false);
+ forum_print_latest_discussions($news->id, $course->newsitems, "minimal", "DESC", false);
echo "</FONT>";
print_simple_box_end();
}
$admindata[]="<A HREF=\"view.php?id=$course->id&edit=on\">Turn editing on</A>";
}
- if ($teacherforum = get_course_teacher_forum($course->id)) {
+ if ($teacherforum = forum_get_course_forum($course->id, "teacher")) {
$admindata[]="<A HREF=\"../mod/forum/view.php?f=$teacherforum->id\">Teacher Forum...</A>";
$adminicon[]="<IMG SRC=\"../mod/forum/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"Teacher Forum\">";
}
// Print all the news items.
- if ($news = get_course_news_forum($course->id)) {
+ if ($news = forum_get_course_forum($course->id, "news")) {
print_simple_box("Latest News", $align="CENTER", $width="100%", $color="$THEME->cellheading");
print_simple_box_start("CENTER", "100%", "#FFFFFF", 3, 0);
echo "<FONT SIZE=1>";
- print_forum_latest_topics($news->id, $course->newsitems, "minimal", "DESC", false);
+ forum_print_latest_discussions($news->id, $course->newsitems, "minimal", "DESC", false);
echo "</FONT>";
print_simple_box_end();
}
print_all_courses();
} else {
- if (! $newsforum = get_course_news_forum($site->id)) {
- error("Could not find or create a main forum for the site");
+ if (! $newsforum = forum_get_course_forum($site->id, "news")) {
+ error("Could not find or create a main news forum for the site");
}
if (isset($USER->id)) {
}
print_simple_box($headertext, "CENTER", "100%", $THEME->cellheading);
echo "<IMG HEIGHT=8 SRC=\"pix/spacer.gif\" ALT=\"\"><BR>";
- print_forum_latest_topics($newsforum->id, $site->newsitems);
+ forum_print_latest_discussions($newsforum->id, $site->newsitems);
}
?>
$navtail = "$discussion->name";
}
- if (! $post = get_forum_post_full($parent)) {
+ if (! $post = forum_get_post_full($parent)) {
error("Discussion no longer exists", "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
}
"$navmiddle -> $navtail", "", "", true, $updatebutton);
}
- print_discussion($course, $discussion, $post, $USER->mode);
+ forum_print_discussion($course, $discussion, $post, $USER->mode);
print_footer($course);
"2" => "Display replies in threaded form",
"3" => "Display replies in nested form");
+// These are course content forums that can be added to the course manually
$FORUM_TYPE = array ("general" => "General forum",
- "eachuser" => "Each $student posts a topic",
+ "eachuser" => "Each $student posts one discussion",
"single" => "A single simple discussion");
$FORUM_POST_RATINGS = array ("3" => "Outstanding",
/// 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'")) {
- 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->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'")) {
+function forum_get_course_forum($courseid, $type) {
+// How to set up special 1-per-course forums
+ if ($forum = get_record_sql("SELECT * from forum WHERE course = '$courseid' AND type = '$type'")) {
return $forum;
} else {
// Doesn't exist, so create one now.
$forum->course = $courseid;
- $forum->type = "social";
- $forum->name = "Social";
- $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'");
- }
-}
-
+ $forum->type = "$type";
+ switch ($forum->type) {
+ case "news":
+ $forum->name = "News";
+ $forum->intro= "General news about this course";
+ $forum->open = 0;
+ $forum->assessed = 0;
+ $forum->forcesubscribe = 1;
+ break;
+ case "social":
+ $forum->name = "Social";
+ $forum->intro= "A forum for general socialising. Talk about anything you like!";
+ $forum->open = 1;
+ $forum->assessed = 0;
+ $forum->forcesubscribe = 0;
+ break;
+ case "teacher":
+ $forum->name = "Teacher Forum";
+ $forum->intro= "For teacher-only notes and discussion";
+ $forum->open = 0;
+ $forum->assessed = 0;
+ $forum->forcesubscribe = 0;
+ break;
+ default:
+ notify("That forum type doesn't exist!");
+ return false;
+ break;
-function get_course_teacher_forum($courseid) {
- if ($forum = get_record_sql("SELECT * from forum WHERE course = '$courseid' AND type = 'teacher'")) {
- return $forum;
- } else {
- // Doesn't exist, so create one now.
- $forum->course = $courseid;
- $forum->type = "teacher";
- $forum->name = "Teacher Forum";
- $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="") {
+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
// returns the HTML in a string. This is designed for sending via HTML email.
}
-function print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false, $rate=false, $footer="") {
+function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false, $rate=false, $footer="") {
global $THEME, $USER, $CFG, $FORUM_LONG_POST;
if ($post->parent) {
echo "<DIV ALIGN=right><P ALIGN=right>";
if ($rate && $USER->id) {
if ($USER->id == $post->userid) {
- print_ratings($post->id);
+ print_forum_ratings($post->id);
} else {
- print_rating($post->id, $USER->id);
+ print_forum_rating($post->id, $USER->id);
}
}
}
-function print_ratings($post) {
+function print_forum_ratings($post) {
global $CFG, $PHPSESSID;
}
}
-function print_rating($post, $user) {
+function print_forum_rating($post, $user) {
global $FORUM_POST_RATINGS;
if ($rs = get_record_sql("SELECT rating from forum_ratings WHERE user='$user' AND post='$post'")) {
}
}
-function print_mode_form($discussion, $mode) {
+function print_forum_mode_form($discussion, $mode) {
GLOBAL $FORUM_DISCUSS_MODES;
echo "<CENTER><P>";
}
-function count_discussion_replies($forum="0") {
+function forum_count_discussion_replies($forum="0") {
if ($forum) {
$forumselect = " AND d.forum = '$forum'";
}
}
-function set_fromdiscussion() {
+function forum_set_return() {
global $SESSION, $HTTP_REFERER;
if (! $SESSION->fromdiscussion) {
}
-function go_back_to($default) {
+function forum_go_back_to($default) {
global $SESSION;
if ($SESSION->fromdiscussion) {
}
}
-function get_forum_post_full($postid) {
+function forum_get_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
}
-function add_new_post_to_database($post) {
+function forum_add_new_post($post) {
$timenow = time();
$post->created = $timenow;
return insert_record("forum_posts", $post);
}
-function update_post_in_database($post) {
+function forum_update_post($post) {
global $db;
$timenow = time();
-function print_user_discussions($course, $user) {
- global $CFG;
+function forum_print_user_discussions($courseid, $userid) {
+ global $USER;
- $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");
+ $discussions = 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.course = '$courseid' AND p.discussion = d.id AND
+ p.parent = 0 AND p.user = u.id AND u.id = '$userid'
+ ORDER BY p.created DESC");
- if ($topics) {
+ if ($discussions) {
echo "<HR>";
print_heading("Discussion topics");
- $replies = count_discussion_replies();
- foreach ($topics as $topic) {
- if ($replies[$topic->discussion]) {
- $topic->replies = $replies[$topic->discussion]->replies;
+ $replies = forum_count_discussion_replies();
+ foreach ($discussions as $discussion) {
+ if ($replies[$discussion->discussion]) {
+ $discussion->replies = $replies[$discussion->discussion]->replies;
} else {
- $topic->replies = 0;
+ $discussion->replies = 0;
}
- $ownpost = ($topic->userid == $USER->id);
- print_post($topic, $course->id, $ownpost, $reply=0, $link=1, $assessed=false);
+ $ownpost = ($discussion->userid == $USER->id);
+ forum_print_post($discussion, $course->id, $ownpost, $reply=0, $link=1, $assessed=false);
echo "<BR>\n";
}
}
$footer = "";
}
- print_post($post, $course->id, $ownpost=false, $reply=false, $link=false, $rate=false, $footer);
+ pirint_post($post, $course->id, $ownpost=false, $reply=false, $link=false, $rate=false, $footer);
}
} else {
"<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);
+ $posthtml .= forum_make_mail_post($post, $userfrom, $userto, $course, false, true, false, false);
} else {
$posthtml = "";
}
}
-function user_has_posted_discussion($forumid, $userid) {
- if ($topics = get_all_topics($forumid, "DESC", $userid)) {
+function forum_user_has_posted_discussion($forumid, $userid) {
+ if ($discussions = forum_get_discussions($forumid, "DESC", $userid)) {
return true;
} else {
return false;
}
}
-function user_can_post_discussion($forum) {
+function forum_user_can_post_discussion($forum) {
// $forum is an object
global $USER;
if ($forum->type == "eachuser") {
- return (! user_has_posted_discussion($forum->id, $USER->id));
+ return (! forum_user_has_posted_discussion($forum->id, $USER->id));
} else if ($forum->type == "teacher") {
return isteacher($forum->course);
} else if (isteacher($forum->course)) {
}
-function get_all_topics($forum="0", $forum_sort="DESC", $user=0) {
+function forum_get_discussions($forum="0", $forum_sort="DESC", $user=0) {
if ($user) {
$userselect = " AND u.id = '$user' ";
} else {
-function print_forum_latest_topics($forum_id=0, $forum_numtopics=5, $forum_style="plain", $forum_sort="DESC") {
+function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $forum_style="plain", $forum_sort="DESC") {
global $CFG, $USER;
if ($forum_id) {
if (! $course = get_record("course", "category", 0)) {
error("Could not find a top-level course!");
}
- if (! $forum = get_course_news_forum($course->id)) {
+ if (! $forum = forum_get_course_news_forum($course->id)) {
error("Could not find or create a main forum in this course (id $course->id)");
}
}
- if (user_can_post_discussion($forum)) {
+ if (forum_user_can_post_discussion($forum)) {
echo "<P ALIGN=right>";
- echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?forum=$forum->id\">Add a new topic...</A>";
+ echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?forum=$forum->id\">Add a new discussion topic...</A>";
echo "</P>\n";
}
- if (! $topics = get_all_topics($forum->id, $forum_sort) ) {
+ if (! $discussions = forum_get_discussions($forum->id, $forum_sort) ) {
echo "<P ALIGN=CENTER><B>There are no discussion topics yet in this forum.</B></P>";
} else {
- $replies = count_discussion_replies($forum->id);
+ $replies = forum_count_discussion_replies($forum->id);
- $topiccount = 0;
+ $discussioncount = 0;
- foreach ($topics as $topic) {
- $topiccount++;
+ foreach ($discussions as $discussion) {
+ $discussioncount++;
- if ($forum_numtopics && ($topiccount > $forum_numtopics)) {
- echo "<P ALIGN=right><A HREF=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">Older topics</A> ...</P>";
+ if ($forum_numdiscussions && ($discussioncount > $forum_numdiscussions)) {
+ echo "<P ALIGN=right><A HREF=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">Older discussions</A> ...</P>";
break;
}
- if ($replies[$topic->discussion]) {
- $topic->replies = $replies[$topic->discussion]->replies;
+ if ($replies[$discussion->discussion]) {
+ $discussion->replies = $replies[$discussion->discussion]->replies;
} else {
- $topic->replies = 0;
+ $discussion->replies = 0;
}
- $ownpost = ($topic->userid == $USER->id);
+ $ownpost = ($discussion->userid == $USER->id);
switch ($forum_style) {
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/forum/discuss.php?d=$topic->discussion\">more...</A>";
+ echo "<P><FONT COLOR=#555555>".userdate($discussion->modified, "%e %b, %H:%M")." - $discussion->firstname</FONT>";
+ echo "<BR>$discussion->subject ";
+ echo "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->discussion\">more...</A>";
echo "</P>\n";
break;
default:
- print_post($topic, $forum->course, $ownpost, $reply=0, $link=1, $assessed=false);
+ forum_print_post($discussion, $forum->course, $ownpost, $reply=0, $link=1, $assessed=false);
echo "<BR>\n";
break;
}
}
}
-function print_discussion($course, $discussion, $post, $mode) {
+function forum_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);
+ forum_print_post($post, $course->id, $ownpost, $reply=true, $link=false, $rate=false);
- print_mode_form($discussion->id, $mode);
+ print_forum_mode_form($discussion->id, $mode);
if ($discussion->assessed && $USER->id) {
echo "<FORM NAME=form METHOD=POST ACTION=rate.php>";
case -1 : // Flat descending
default:
echo "<UL>";
- print_posts_flat($post->discussion, $course->id, $mode, $discussion->assessed);
+ forum_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);
+ forum_print_posts_threaded($post->id, $course->id, 0, $discussion->assessed);
break;
case 3 : // Nested
- print_posts_nested($post->id, $course->id, $discussion->assessed);
+ forum_print_posts_nested($post->id, $course->id, $discussion->assessed);
break;
}
}
}
-function print_posts_flat($discussion, $course, $direction, $assessed) {
+function forum_print_posts_flat($discussion, $course, $direction, $assessed) {
global $USER;
$reply = true;
foreach ($posts as $post) {
$ownpost = ($USER->id == $post->user);
- print_post($post, $course, $ownpost, $reply, $link, $assessed);
+ forum_print_post($post, $course, $ownpost, $reply, $link, $assessed);
}
} else {
return;
}
}
-function print_posts_threaded($parent, $course, $depth, $assessed) {
+function forum_print_posts_threaded($parent, $course, $depth, $assessed) {
global $USER;
$reply = true;
echo "<UL>";
if ($depth > 0) {
$ownpost = ($USER->id == $post->user);
- print_post($post, $course, $ownpost, $reply, $link, $assessed); // link=true?
+ forum_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);
+ forum_print_posts_threaded($post->id, $course, $depth-1, $assessed);
echo "</UL>\n";
}
} else {
}
}
-function print_posts_nested($parent, $course, $assessed) {
+function forum_print_posts_nested($parent, $course, $assessed) {
global $USER;
$reply = true;
$ownpost = ($USER->id == $post->user);
echo "<UL>";
- print_post($post, $course, $ownpost, $reply, $link, $assessed);
+ forum_print_post($post, $course, $ownpost, $reply, $link, $assessed);
echo "<BR>";
- print_posts_nested($post->id, $course, $assessed);
+ forum_print_posts_nested($post->id, $course, $assessed);
echo "</UL>\n";
}
} else {
if ($post->edit) { // Updating a post
$post->id = $post->edit;
- if (update_post_in_database($post) ) {
+ if (forum_update_post($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);
+ redirect(forum_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 ($post->id = forum_add_new_post($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"),
+ redirect(forum_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");
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"),
+ redirect(forum_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.");
error("The course number was incorrect ($forum)");
}
- if (! user_can_post_discussion($forum)) {
+ if (! forum_user_can_post_discussion($forum)) {
error("Sorry, but you can not post a new discussion in this forum.");
}
$post->user = $USER->id;
$post->message = "";
- set_fromdiscussion();
-
+ forum_set_return();
+
} else if (isset($reply)) { // User is writing a new reply
- if (! $parent = get_forum_post_full($reply)) {
+ if (! $parent = forum_get_post_full($reply)) {
error("Parent post ID was incorrect ($reply)");
}
if (! $discussion = get_record("forum_discussions", "id", $parent->discussion)) {
$post->subject = "Re: ".$post->subject;
}
- set_fromdiscussion();
+ forum_set_return();
} else if (isset($edit)) { // User is editing their own post
- if (! $post = get_forum_post_full($edit)) {
+ if (! $post = forum_get_post_full($edit)) {
error("Post ID was incorrect");
}
if ($post->user <> $USER->id) {
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)) {
+ if (! $parent = forum_get_post_full($post->parent)) {
error("Parent post ID was incorrect ($post->parent)");
}
}
$post->course = $course->id;
$post->forum = $forum->id;
- set_fromdiscussion();
+ forum_set_return();
} else if (isset($delete)) { // User is deleting a post
- if (! $post = get_forum_post_full($delete)) {
+ if (! $post = forum_get_post_full($delete)) {
error("Post ID was incorrect");
}
if ($post->user <> $USER->id) {
if ($post->totalscore) {
notice("Sorry, that cannot be deleted as people have already rated it",
- go_back_to("discuss.php?d=$post->discussion"));
+ forum_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"));
+ forum_go_back_to("discuss.php?id=$post->discussion"));
} else {
if (! $post->parent) { // post is a discussion topic as well, so delete discussion
} 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"),
+ redirect(forum_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();
+ forum_set_return();
print_header();
notice_yesno("Are you sure you want to delete this post?",
$HTTP_REFERER);
echo "<CENTER><HR>";
- print_post($post, 0, $ownpost=false, $reply=false, $link=false);
+ forum_print_post($post, 0, $ownpost=false, $reply=false, $link=false);
}
echo "<CENTER>";
if (isset($parent)) {
- print_post($parent, $course->id, $ownpost=false, $reply=false, $link=false);
+ forum_print_post($parent, $course->id, $ownpost=false, $reply=false, $link=false);
echo "<H2>Your reply:</H2>";
} else {
echo "<H2>Your new discussion topic:</H2>";
$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);
+ forum_print_post($post, $course->id, false, false, false, false, $fulllink);
echo "<BR>";
}
}
}
- $returnto = go_back_to("index.php?id=$course->id");
+ $returnto = forum_go_back_to("index.php?id=$course->id");
if ($force and isteacher($course->id)) {
if (forum_is_forcesubscribed($forum->id)) {
error("Could not find the discussion in this forum");
}
}
- if (! $post = get_forum_post_full($discussion->firstpost)) {
+ if (! $post = forum_get_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);
+ forum_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)) {
+ if (forum_user_can_post_discussion($forum)) {
echo "This forum allows one discussion topic to be posted per person.";
} else {
echo " ";
}
echo "</P>";
- print_forum_latest_topics($forum->id, 0);
+ forum_print_latest_discussions($forum->id, 0);
break;
default:
print_simple_box(text_to_html($forum->intro), "CENTER");
echo "<P> </P>";
- print_forum_latest_topics($forum->id, 0);
+ forum_print_latest_discussions($forum->id, 0);
break;
}
}
echo "</TR></TABLE></CENTER>\n";
- print_user_discussions($course, $user);
+ forum_print_user_discussions($course->id, $user->id);
print_footer($course);