From: martin Date: Thu, 1 Aug 2002 03:50:27 +0000 (+0000) Subject: A big clean up of all the forum functions (including renaming them all X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=11b0c469715d411399f609aa3cc52b8c312b5662;p=moodle.git A big clean up of all the forum functions (including renaming them all to start with forum_ ) and all the follow-on effects that caused Some miscellaneous bug fixes and code clean-ups along the way --- diff --git a/course/lib.php b/course/lib.php index bff3e98da1..97e160fc2d 100644 --- a/course/lib.php +++ b/course/lib.php @@ -425,4 +425,222 @@ function print_log_graph($course, $userid=0, $type="course.png", $date=0) { echo "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; + } + } +} + + ?> diff --git a/course/mod.php b/course/mod.php index c8db9c45d4..d392d1f4c8 100644 --- a/course/mod.php +++ b/course/mod.php @@ -237,224 +237,4 @@ 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; - } - } -} - ?> - - diff --git a/course/social.php b/course/social.php index e6b70c2359..95f23f2142 100644 --- a/course/social.php +++ b/course/social.php @@ -10,8 +10,8 @@ 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 "

"; @@ -71,35 +71,28 @@ print_side_block("", $admindata, "", $adminicon); } - ?> - + echo ""; - - id)) { - error("Could not find or create a social forum here"); - } + echo ""; + 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 = "
Social Forum - Current Topicsid\">$subtext
"; + print_simple_box("$headertext", $align="CENTER", $width="100%", $color="$THEME->cellheading"); + echo "\"\"
"; + + 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 = "
Social Forum - Current Topicsid\">$subtext
"; - print_simple_box("$headertext", $align="CENTER", $width="100%", $color="$THEME->cellheading"); ?> -
- - id)) { - print_forum_latest_topics($social->id, 10, "plain", "DESC", false); - } else { - error("Could not find or create a social forum here"); - } ?> - - - + + diff --git a/course/topics.php b/course/topics.php index e271a6493c..e91c724950 100644 --- a/course/topics.php +++ b/course/topics.php @@ -85,7 +85,7 @@ } else { $admindata[]="id&edit=on\">Turn editing on"; } - if ($teacherforum = get_course_teacher_forum($course->id)) { + if ($teacherforum = forum_get_course_forum($course->id, "teacher")) { $admindata[]="id\">Teacher Forum..."; $adminicon[]="\"Teacher"; } @@ -201,11 +201,11 @@ // 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 ""; - print_forum_latest_topics($news->id, $course->newsitems, "minimal", "DESC", false); + forum_print_latest_discussions($news->id, $course->newsitems, "minimal", "DESC", false); echo ""; print_simple_box_end(); } diff --git a/course/weeks.php b/course/weeks.php index 2692c03c05..bbf93a68dd 100644 --- a/course/weeks.php +++ b/course/weeks.php @@ -68,7 +68,7 @@ $admindata[]="id&edit=on\">Turn editing on"; } - if ($teacherforum = get_course_teacher_forum($course->id)) { + if ($teacherforum = forum_get_course_forum($course->id, "teacher")) { $admindata[]="id\">Teacher Forum..."; $adminicon[]="\"Teacher"; } @@ -189,11 +189,11 @@ // 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 ""; - print_forum_latest_topics($news->id, $course->newsitems, "minimal", "DESC", false); + forum_print_latest_discussions($news->id, $course->newsitems, "minimal", "DESC", false); echo ""; print_simple_box_end(); } diff --git a/index.php b/index.php index abf8edf32f..354acd4dea 100644 --- a/index.php +++ b/index.php @@ -71,8 +71,8 @@ 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)) { @@ -92,7 +92,7 @@ } print_simple_box($headertext, "CENTER", "100%", $THEME->cellheading); echo "\"\"
"; - print_forum_latest_topics($newsforum->id, $site->newsitems); + forum_print_latest_discussions($newsforum->id, $site->newsitems); } ?> diff --git a/mod/forum/discuss.php b/mod/forum/discuss.php index 753811ca48..85e13d00a8 100644 --- a/mod/forum/discuss.php +++ b/mod/forum/discuss.php @@ -41,7 +41,7 @@ $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"); } @@ -66,7 +66,7 @@ "$navmiddle -> $navtail", "", "", true, $updatebutton); } - print_discussion($course, $discussion, $post, $USER->mode); + forum_print_discussion($course, $discussion, $post, $USER->mode); print_footer($course); diff --git a/mod/forum/lib.php b/mod/forum/lib.php index c3f0c4ee50..3027b9f033 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -9,8 +9,9 @@ $FORUM_DISCUSS_MODES = array ( "1" => "Display replies flat, with oldest first" "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", @@ -22,58 +23,43 @@ $FORUM_LONG_POST = 600; /// 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'"); @@ -81,7 +67,8 @@ function get_course_teacher_forum($courseid) { } -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. @@ -153,7 +140,7 @@ function make_mail_post(&$post, $user, $touser, $course, $ownpost=false, $reply= } -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) { @@ -215,9 +202,9 @@ function print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false echo "

"; 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); } } @@ -255,7 +242,7 @@ function forum_shorten_post($message) { } -function print_ratings($post) { +function print_forum_ratings($post) { global $CFG, $PHPSESSID; @@ -280,7 +267,7 @@ function print_ratings($post) { } } -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'")) { @@ -297,7 +284,7 @@ function print_rating($post, $user) { } } -function print_mode_form($discussion, $mode) { +function print_forum_mode_form($discussion, $mode) { GLOBAL $FORUM_DISCUSS_MODES; echo "

"; @@ -318,7 +305,7 @@ function print_forum_search_form($course, $search="") { } -function count_discussion_replies($forum="0") { +function forum_count_discussion_replies($forum="0") { if ($forum) { $forumselect = " AND d.forum = '$forum'"; } @@ -329,7 +316,7 @@ function count_discussion_replies($forum="0") { } -function set_fromdiscussion() { +function forum_set_return() { global $SESSION, $HTTP_REFERER; if (! $SESSION->fromdiscussion) { @@ -338,7 +325,7 @@ function set_fromdiscussion() { } -function go_back_to($default) { +function forum_go_back_to($default) { global $SESSION; if ($SESSION->fromdiscussion) { @@ -350,7 +337,7 @@ function go_back_to($default) { } } -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 @@ -358,7 +345,7 @@ function get_forum_post_full($postid) { } -function add_new_post_to_database($post) { +function forum_add_new_post($post) { $timenow = time(); $post->created = $timenow; @@ -368,7 +355,7 @@ function add_new_post_to_database($post) { return insert_record("forum_posts", $post); } -function update_post_in_database($post) { +function forum_update_post($post) { global $db; $timenow = time(); @@ -447,28 +434,27 @@ function forum_delete_discussion($discussion) { -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 "


"; 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 "
\n"; } } @@ -515,7 +501,7 @@ function forum_user_complete($course, $user, $mod, $forum) { $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 { @@ -587,7 +573,7 @@ function forum_cron () { "wwwroot/mod/forum/index.php?id=$course->id\">Forums ->". "wwwroot/mod/forum/view.php?f=$forum->id\">$forum->name ->". "wwwroot/mod/forum/discuss.php?d=$discussion->id\">$discussion->name

"; - $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 = ""; } @@ -636,20 +622,20 @@ function forum_unsubscribe($userid, $forumid) { } -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)) { @@ -660,7 +646,7 @@ function user_can_post_discussion($forum) { } -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 { @@ -675,7 +661,7 @@ function get_all_topics($forum="0", $forum_sort="DESC", $user=0) { -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) { @@ -694,48 +680,48 @@ function print_forum_latest_topics($forum_id=0, $forum_numtopics=5, $forum_style 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 "

"; - echo "wwwroot/mod/forum/post.php?forum=$forum->id\">Add a new topic..."; + echo "wwwroot/mod/forum/post.php?forum=$forum->id\">Add a new discussion topic..."; echo "

\n"; } - if (! $topics = get_all_topics($forum->id, $forum_sort) ) { + if (! $discussions = forum_get_discussions($forum->id, $forum_sort) ) { echo "

There are no discussion topics yet in this forum.

"; } 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 "

wwwroot/mod/forum/view.php?f=$forum->id\">Older topics ...

"; + if ($forum_numdiscussions && ($discussioncount > $forum_numdiscussions)) { + echo "

wwwroot/mod/forum/view.php?f=$forum->id\">Older discussions ...

"; 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 "

".userdate($topic->modified, "%e %B, %H:%M").""; - echo "
$topic->subject "; - echo "wwwroot/mod/forum/discuss.php?d=$topic->discussion\">more..."; + echo "

".userdate($discussion->modified, "%e %b, %H:%M")." - $discussion->firstname"; + echo "
$discussion->subject "; + echo "wwwroot/mod/forum/discuss.php?d=$discussion->discussion\">more..."; echo "

\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 "
\n"; break; } @@ -743,15 +729,15 @@ function print_forum_latest_topics($forum_id=0, $forum_numtopics=5, $forum_style } } -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 "
"; @@ -763,16 +749,16 @@ function print_discussion($course, $discussion, $post, $mode) { case -1 : // Flat descending default: echo "
    "; - print_posts_flat($post->discussion, $course->id, $mode, $discussion->assessed); + forum_print_posts_flat($post->discussion, $course->id, $mode, $discussion->assessed); echo "
"; 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; } @@ -782,7 +768,7 @@ function print_discussion($course, $discussion, $post, $mode) { } } -function print_posts_flat($discussion, $course, $direction, $assessed) { +function forum_print_posts_flat($discussion, $course, $direction, $assessed) { global $USER; $reply = true; @@ -800,14 +786,14 @@ function print_posts_flat($discussion, $course, $direction, $assessed) { 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; @@ -822,13 +808,13 @@ function print_posts_threaded($parent, $course, $depth, $assessed) { echo "
    "; 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 "
    "; } else { echo "
  • discussion&parent=$post->id\">$post->subject by $post->firstname $post->lastname, ".userdate($post->created)."

    "; } - print_posts_threaded($post->id, $course, $depth-1, $assessed); + forum_print_posts_threaded($post->id, $course, $depth-1, $assessed); echo "
\n"; } } else { @@ -836,7 +822,7 @@ function print_posts_threaded($parent, $course, $depth, $assessed) { } } -function print_posts_nested($parent, $course, $assessed) { +function forum_print_posts_nested($parent, $course, $assessed) { global $USER; $reply = true; @@ -852,9 +838,9 @@ function print_posts_nested($parent, $course, $assessed) { $ownpost = ($USER->id == $post->user); echo "
    "; - print_post($post, $course, $ownpost, $reply, $link, $assessed); + forum_print_post($post, $course, $ownpost, $reply, $link, $assessed); echo "
    "; - print_posts_nested($post->id, $course, $assessed); + forum_print_posts_nested($post->id, $course, $assessed); echo "
\n"; } } else { diff --git a/mod/forum/post.php b/mod/forum/post.php index c1ed084fb5..ad6789139c 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -20,20 +20,20 @@ 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.

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"); @@ -47,7 +47,7 @@ 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.

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."); @@ -69,7 +69,7 @@ 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."); } @@ -83,11 +83,11 @@ $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)) { @@ -113,11 +113,11 @@ $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) { @@ -127,7 +127,7 @@ 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)"); } } @@ -148,12 +148,12 @@ $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) { @@ -167,12 +167,12 @@ 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 @@ -185,7 +185,7 @@ } 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"); @@ -195,7 +195,7 @@ } 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?", @@ -203,7 +203,7 @@ $HTTP_REFERER); echo "


"; - print_post($post, 0, $ownpost=false, $reply=false, $link=false); + forum_print_post($post, 0, $ownpost=false, $reply=false, $link=false); } @@ -260,7 +260,7 @@ echo "
"; 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 "

Your reply:

"; } else { echo "

Your new discussion topic:

"; diff --git a/mod/forum/search.php b/mod/forum/search.php index e9bd5287f2..9be619d277 100644 --- a/mod/forum/search.php +++ b/mod/forum/search.php @@ -64,7 +64,7 @@ $post->message = highlight("$search", $post->message); $fulllink = "

discussion&parent=$post->id\">See this post in context

"; - print_post($post, $course->id, false, false, false, false, $fulllink); + forum_print_post($post, $course->id, false, false, false, false, $fulllink); echo "
"; } diff --git a/mod/forum/subscribe.php b/mod/forum/subscribe.php index 63806bb8c0..12acc32eb9 100644 --- a/mod/forum/subscribe.php +++ b/mod/forum/subscribe.php @@ -32,7 +32,7 @@ } } - $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)) { diff --git a/mod/forum/view.php b/mod/forum/view.php index 84a5a4c62d..1b5462ea98 100644 --- a/mod/forum/view.php +++ b/mod/forum/view.php @@ -100,29 +100,29 @@ 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 "

"; - 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 "

"; - 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 "

 

"; - print_forum_latest_topics($forum->id, 0); + forum_print_latest_discussions($forum->id, 0); break; } diff --git a/user/view.php b/user/view.php index 1a810dee99..2c4d02f1e3 100644 --- a/user/view.php +++ b/user/view.php @@ -138,7 +138,7 @@ } echo "
\n"; - print_user_discussions($course, $user); + forum_print_user_discussions($course->id, $user->id); print_footer($course);