| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id$ 2 3 // Displays a post, and all the posts below it. 4 // If no post is given, displays all posts in a discussion 5 6 require_once('../../config.php'); 7 require_once ('lib.php'); 8 9 $d = required_param('d', PARAM_INT); // Discussion ID 10 $parent = optional_param('parent', 0, PARAM_INT); // If set, then display this post and all children. 11 $mode = optional_param('mode', 0, PARAM_INT); // If set, changes the layout of the thread 12 $move = optional_param('move', 0, PARAM_INT); // If set, moves this discussion to another forum 13 $mark = optional_param('mark', '', PARAM_ALPHA); // Used for tracking read posts if user initiated. 14 $postid = optional_param('postid', 0, PARAM_INT); // Used for tracking read posts if user initiated. 15 16 if (!$discussion = get_record('forum_discussions', 'id', $d)) { 17 error("Discussion ID was incorrect or no longer exists"); 18 } 19 20 if (!$course = get_record('course', 'id', $discussion->course)) { 21 error("Course ID is incorrect - discussion is faulty"); 22 } 23 24 if (!$forum = get_record('forum', 'id', $discussion->forum)) { 25 notify("Bad forum ID stored in this discussion"); 26 } 27 28 if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { 29 error('Course Module ID was incorrect'); 30 } 31 32 require_course_login($course, true, $cm); 33 34 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); 35 require_capability('mod/forum:viewdiscussion', $modcontext, NULL, true, 'noviewdiscussionspermission', 'forum'); 36 37 if ($forum->type == 'news') { 38 if (!($USER->id == $discussion->userid || (($discussion->timestart == 0 39 || $discussion->timestart <= time()) 40 && ($discussion->timeend == 0 || $discussion->timeend > time())))) { 41 error('Discussion ID was incorrect or no longer exists', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id"); 42 } 43 } 44 45 /// move discussion if requested 46 if ($move > 0 and confirm_sesskey()) { 47 $return = $CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->id; 48 49 require_capability('mod/forum:movediscussions', $modcontext); 50 51 if ($forum->type == 'single') { 52 error('Cannot move discussion from a simple single discussion forum', $return); 53 } 54 55 if (!$forumto = get_record('forum', 'id', $move)) { 56 error('You can\'t move to that forum - it doesn\'t exist!', $return); 57 } 58 59 if (!$cmto = get_coursemodule_from_instance('forum', $forumto->id, $course->id)) { 60 error('Target forum not found in this course.', $return); 61 } 62 63 if (!coursemodule_visible_for_user($cmto)) { 64 error('Forum not visible', $return); 65 } 66 67 if (!forum_move_attachments($discussion, $forumto->id)) { 68 notify("Errors occurred while moving attachment directories - check your file permissions"); 69 } 70 set_field('forum_discussions', 'forum', $forumto->id, 'id', $discussion->id); 71 set_field('forum_read', 'forumid', $forumto->id, 'discussionid', $discussion->id); 72 add_to_log($course->id, 'forum', 'move discussion', "discuss.php?d=$discussion->id", $discussion->id, $cmto->id); 73 74 require_once($CFG->libdir.'/rsslib.php'); 75 require_once ('rsslib.php'); 76 77 // Delete the RSS files for the 2 forums because we want to force 78 // the regeneration of the feeds since the discussions have been 79 // moved. 80 if (!forum_rss_delete_file($forum) || !forum_rss_delete_file($forumto)) { 81 error('Could not purge the cached RSS feeds for the source and/or'. 82 'destination forum(s) - check your file permissionsforums', $return); 83 } 84 85 redirect($return.'&moved=-1&sesskey='.sesskey()); 86 } 87 88 $logparameters = "d=$discussion->id"; 89 if ($parent) { 90 $logparameters .= "&parent=$parent"; 91 } 92 93 add_to_log($course->id, 'forum', 'view discussion', "discuss.php?$logparameters", $discussion->id, $cm->id); 94 95 unset($SESSION->fromdiscussion); 96 97 if ($mode) { 98 set_user_preference('forum_displaymode', $mode); 99 } 100 101 $displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode); 102 103 if ($parent) { 104 // If flat AND parent, then force nested display this time 105 if ($displaymode == FORUM_MODE_FLATOLDEST or $displaymode == FORUM_MODE_FLATNEWEST) { 106 $displaymode = FORUM_MODE_NESTED; 107 } 108 } else { 109 $parent = $discussion->firstpost; 110 } 111 112 if (! $post = forum_get_post_full($parent)) { 113 error("Discussion no longer exists", "$CFG->wwwroot/mod/forum/view.php?f=$forum->id"); 114 } 115 116 117 if (!forum_user_can_view_post($post, $course, $cm, $forum, $discussion)) { 118 error('You do not have permissions to view this post', "$CFG->wwwroot/mod/forum/view.php?id=$forum->id"); 119 } 120 121 if ($mark == 'read' or $mark == 'unread') { 122 if ($CFG->forum_usermarksread && forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) { 123 if ($mark == 'read') { 124 forum_tp_add_read_record($USER->id, $postid); 125 } else { 126 // unread 127 forum_tp_delete_read_records($USER->id, $postid); 128 } 129 } 130 } 131 132 $searchform = forum_search_form($course); 133 134 $navlinks = array(); 135 $navlinks[] = array('name' => format_string($discussion->name), 'link' => "discuss.php?d=$discussion->id", 'type' => 'title'); 136 if ($parent != $discussion->firstpost) { 137 $navlinks[] = array('name' => format_string($post->subject), 'type' => 'title'); 138 } 139 140 $navigation = build_navigation($navlinks, $cm); 141 print_header("$course->shortname: ".format_string($discussion->name), $course->fullname, 142 $navigation, "", "", true, $searchform, navmenu($course, $cm)); 143 144 145 /// Check to see if groups are being used in this forum 146 /// If so, make sure the current person is allowed to see this discussion 147 /// Also, if we know they should be able to reply, then explicitly set $canreply for performance reasons 148 149 if (isguestuser() or !isloggedin() or has_capability('moodle/legacy:guest', $modcontext, NULL, false)) { 150 // allow guests and not-logged-in to see the link - they are prompted to log in after clicking the link 151 $canreply = ($forum->type != 'news'); // no reply in news forums 152 153 } else { 154 $canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext); 155 } 156 157 /// Print the controls across the top 158 159 echo '<table width="100%" class="discussioncontrols"><tr><td>'; 160 161 // groups selector not needed here 162 163 echo "</td><td>"; 164 forum_print_mode_form($discussion->id, $displaymode); 165 echo "</td><td>"; 166 167 if ($forum->type != 'single' 168 && has_capability('mod/forum:movediscussions', $modcontext)) { 169 170 // Popup menu to move discussions to other forums. The discussion in a 171 // single discussion forum can't be moved. 172 $modinfo = get_fast_modinfo($course); 173 if (isset($modinfo->instances['forum'])) { 174 if ($course->format == 'weeks') { 175 $strsection = get_string("week"); 176 } else { 177 $strsection = get_string("topic"); 178 } 179 $section = -1; 180 $forummenu = array(); 181 foreach ($modinfo->instances['forum'] as $forumcm) { 182 if (!$forumcm->uservisible) { 183 continue; 184 } 185 186 if (!empty($forumcm->sectionnum) and $section != $forumcm->sectionnum) { 187 $forummenu[] = "-------------- $strsection $forumcm->sectionnum --------------"; 188 } 189 $section = $forumcm->sectionnum; 190 if ($forumcm->instance != $forum->id) { 191 $url = "discuss.php?d=$discussion->id&move=$forumcm->instance&sesskey=".sesskey(); 192 $forummenu[$url] = format_string($forumcm->name); 193 } 194 } 195 if (!empty($forummenu)) { 196 echo "<div style=\"float:right;\">"; 197 echo popup_form("$CFG->wwwroot/mod/forum/", $forummenu, "forummenu", "", 198 get_string("movethisdiscussionto", "forum"), "", "", true); 199 echo "</div>"; 200 } 201 } 202 } 203 echo "</td></tr></table>"; 204 205 if (!empty($forum->blockafter) && !empty($forum->blockperiod)) { 206 $a = new object(); 207 $a->blockafter = $forum->blockafter; 208 $a->blockperiod = get_string('secondstotime'.$forum->blockperiod); 209 notify(get_string('thisforumisthrottled','forum',$a)); 210 } 211 212 if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) && 213 !forum_user_has_posted($forum->id,$discussion->id,$USER->id)) { 214 notify(get_string('qandanotify','forum')); 215 } 216 217 if ($move == -1 and confirm_sesskey()) { 218 notify(get_string('discussionmoved', 'forum', format_string($forum->name,true))); 219 } 220 221 $canrate = has_capability('mod/forum:rate', $modcontext); 222 forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate); 223 224 print_footer($course); 225 226 227 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |