id, $course->id)) { $buttontext = ""; } else { $cm->id = NULL; $buttontext = ""; } if ($forum->type == "teacher") { if (!isteacher($course->id)) { error("You must be a $course->teacher to view this forum"); } } /// Check to see if groups are being used in this forum /// and if so, set $currentgroup to reflect the current group $changegroup = isset($_GET['group']) ? $_GET['group'] : -1; // Group change requested? if ($forum->type == "teacher") { $groupmode = NOGROUPS; } else { $groupmode = groupmode($course, $cm); // Groups are being used } /// Editing teachers see all users, regardless of groups. if (!isteacheredit($course->id)) { $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup); } else { $currentgroup = false; } if ($groupmode and ($currentgroup === false) and !isteacheredit($course->id)) { print_heading(get_string("notingroup", "forum")); exit; } /// Print settings and things in a table across the top $forum->intro = trim($forum->intro); if (!empty($forum->intro)) { print_simple_box(format_text($forum->intro), 'center'); } echo '
'; if (!empty($showall)) { marking_forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup, $groupmode); } else { marking_forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); } /// Check for users that haven't posted: //Get students from forum_posts $st_posts = get_records_sql("SELECT DISTINCT u.* FROM {$CFG->prefix}user u, {$CFG->prefix}forum_discussions d, {$CFG->prefix}forum_posts p WHERE d.forum = '$forum->id' and p.discussion = d.id and u.id = p.userid"); echo '

'; foreach ($students as $student) { if (!is_array($st_posts) || !array_key_exists($student->id, $st_posts)) { echo 'Student '.fullname($student).' has not yet posted to this forum.
'; } } //------------------------------------------------------------------------------ function marking_forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $forum_style="plain", $forum_sort="", $currentgroup=0, $groupmode=-1, $page=-1) { global $CFG, $USER, $forum, $cm, $course; if ($groupmode == -1) { /// We need to reconstruct groupmode because none was given if ($cm) { $groupmode = groupmode($course, $cm); } else { $groupmode = SEPARATEGROUPS; } } if ((!$forum_numdiscussions) && ($forum_style == "plain")) { $forum_style = "header"; // Abbreviate display by default } if ($forum_style == "minimal") { $forum_sort = "p.modified DESC"; } $fullpost = false; if ($forum_style == "plain") { $fullpost = true; } /// Decides if current user is allowed to see ALL the current discussions or not if (!$currentgroup and ($groupmode != SEPARATEGROUPS or isteacheredit($forum->course)) ) { $visiblegroups = -1; } else { $visiblegroups = $currentgroup; } /// Get all the recent discussions we're allowed to see if (! $discussions = forum_get_discussions($forum->id, $forum_sort, 0, $fullpost, $visiblegroups) ) { if ($forum->type == "news") { echo "

(".get_string("nonews", "forum").")

"; } else { echo "

(".get_string("nodiscussions", "forum").")

"; } return; } //If forum_numdiscussions <= 0 don't paging (to avoid some divided by 0 errors) if ($forum_numdiscussions <= 0) { $page = -1; $forum_numdiscussions = 0; } $replies = forum_count_discussion_replies($forum->id); $canreply = forum_user_can_post($forum); $discussioncount = 0; $olddiscussionlink = false; $strdatestring = get_string("strftimerecentfull"); if ($forum_style == "minimal") { $strftimerecent = get_string("strftimerecent"); $strmore = get_string("more", "forum"); } if ($forum_style == "header") { echo ""; echo ""; echo ""; echo ""; if ($forum->open or $forum->type == "teacher") { echo ""; } echo ""; echo ""; } foreach ($discussions as $discussion) { $discussioncount++; if (isteacheredit($course->id)) { /// If there are no unrated posts in this discussion, skip. if (marking_forum_count_unrated_posts($discussion->id, $USER->id) <= 0) { continue; } } if (!empty($replies[$discussion->discussion])) { $discussion->replies = $replies[$discussion->discussion]->replies; $discussion->lastpostid = $replies[$discussion->discussion]->lastpostid; } else { $discussion->replies = 0; } if (!empty($USER->id)) { $ownpost = ($discussion->userid == $USER->id); } else { $ownpost=false; } // Use discussion name instead of subject of first post $discussion->subject = $discussion->name; switch ($forum_style) { case "minimal": if (!empty($CFG->filterall)) { $discussion->subject = filter_text($discussion->subject, $forum->course); } echo "

". userdate($discussion->modified, $strftimerecent). " - ". fullname($discussion). "
"; echo "$discussion->subject "; echo "wwwroot/mod/forum/discuss.php?d=$discussion->discussion\">"; echo $strmore."..."; echo "

\n"; break; case "header": forum_print_discussion_header($discussion, $forum, $strdatestring); break; default: if ($canreply or $discussion->replies) { $link = true; } else { $link = false; } forum_print_post($discussion, $forum->course, $ownpost, $reply=0, $link, $assessed=false); echo "
\n"; break; } } if ($forum_style == "header") { echo "
".get_string("discussion", "forum")."".get_string("startedby", "forum")."".get_string("replies", "forum")."".get_string("lastpost", "forum")."
"; } } function marking_forum_count_unrated_posts($discussionid, $userid) { // How many unrated posts (including 1st post) are in the given discussion for a given user? global $CFG; if ($posts = get_record_sql("SELECT count(*) as num FROM {$CFG->prefix}forum_posts WHERE discussion = '$discussionid' AND userid <> '$userid' ")) { if ($rated = get_record_sql("SELECT count(*) as num FROM {$CFG->prefix}forum_posts p, {$CFG->prefix}forum_ratings r WHERE p.discussion = '$discussionid' AND p.id = r.post AND r.userid = '$userid'")) { $difference = $posts->num - $rated->num; if ($difference > 0) { return $difference; } else { return 0; // Just in case there was a counting error } } else { return $posts->num; } } else { return 0; } } ?>