Commit | Line | Data |
---|---|---|
1adbd2c3 | 1 | <?php |
f93f848a | 2 | |
49a0ba94 | 3 | require_once('../../config.php'); |
4 | require_once('lib.php'); | |
48b29ba4 | 5 | require_once("$CFG->libdir/rsslib.php"); |
f93f848a | 6 | |
49a0ba94 | 7 | |
8 | $id = optional_param('id', 0, PARAM_INT); // Course Module ID | |
9 | $f = optional_param('f', 0, PARAM_INT); // Forum ID | |
10 | $mode = optional_param('mode', 0, PARAM_INT); // Display mode (for single forum) | |
11 | $showall = optional_param('showall', '', PARAM_INT); // show all discussions on one page | |
12 | $changegroup = optional_param('group', -1, PARAM_INT); // choose the current group | |
13 | $page = optional_param('page', 0, PARAM_INT); // which page to show | |
622365d2 | 14 | $search = optional_param('search', '', PARAM_CLEAN);// search string |
49a0ba94 | 15 | |
fbaaeaeb | 16 | $params = array(); |
17 | if ($id) { | |
18 | $params['id'] = $id; | |
19 | } else { | |
20 | $params['f'] = $f; | |
21 | } | |
22 | if ($page) { | |
23 | $params['page'] = $page; | |
24 | } | |
25 | if ($search) { | |
26 | $params['search'] = $search; | |
27 | } | |
28 | $PAGE->set_url('mod/forum/view.php', $params); | |
49a0ba94 | 29 | |
f93f848a | 30 | if ($id) { |
f9d5371b | 31 | if (! $cm = get_coursemodule_from_id('forum', $id)) { |
dde78cb8 | 32 | print_error('invalidcoursemodule'); |
f93f848a | 33 | } |
4e445355 | 34 | if (! $course = $DB->get_record("course", array("id" => $cm->course))) { |
dde78cb8 | 35 | print_error('coursemisconf'); |
f93f848a | 36 | } |
4e445355 | 37 | if (! $forum = $DB->get_record("forum", array("id" => $cm->instance))) { |
dde78cb8 | 38 | print_error('invalidforumid', 'forum'); |
f93f848a | 39 | } |
4cabf99f | 40 | // move require_course_login here to use forced language for course |
41 | // fix for MDL-6926 | |
42 | require_course_login($course, true, $cm); | |
59c71151 | 43 | $strforums = get_string("modulenameplural", "forum"); |
44 | $strforum = get_string("modulename", "forum"); | |
f93f848a | 45 | } else if ($f) { |
49a0ba94 | 46 | |
4e445355 | 47 | if (! $forum = $DB->get_record("forum", array("id" => $f))) { |
dde78cb8 | 48 | print_error('invalidforumid', 'forum'); |
f93f848a | 49 | } |
4e445355 | 50 | if (! $course = $DB->get_record("course", array("id" => $forum->course))) { |
dde78cb8 | 51 | print_error('coursemisconf'); |
f93f848a | 52 | } |
59c71151 | 53 | |
65bcf17b | 54 | if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { |
dde78cb8 | 55 | print_error('missingparameter'); |
d9bf513d | 56 | } |
4cabf99f | 57 | // move require_course_login here to use forced language for course |
58 | // fix for MDL-6926 | |
59 | require_course_login($course, true, $cm); | |
60 | $strforums = get_string("modulenameplural", "forum"); | |
61 | $strforum = get_string("modulename", "forum"); | |
f93f848a | 62 | } else { |
dde78cb8 | 63 | print_error('missingparameter'); |
f93f848a | 64 | } |
65 | ||
385219cb | 66 | if (!$PAGE->button) { |
67 | $PAGE->set_button(forum_search_form($course, $search)); | |
680afe2e | 68 | } |
31d160d3 | 69 | |
83da3d28 | 70 | $context = get_context_instance(CONTEXT_MODULE, $cm->id); |
385219cb | 71 | $PAGE->set_context($context); |
49a0ba94 | 72 | |
73 | ||
74 | /// Print header. | |
95b320e5 MD |
75 | /// Add ajax-related libs for ratings if required MDL-20119 |
76 | $PAGE->requires->yui_lib('event'); | |
77 | $PAGE->requires->yui_lib('connection'); | |
78 | $PAGE->requires->yui_lib('json'); | |
79 | $PAGE->requires->js('mod/forum/rate_ajax.js'); | |
80 | ||
385219cb | 81 | $PAGE->set_title(format_string($forum->name)); |
82 | $PAGE->set_heading(format_string($course->fullname)); | |
393f1615 | 83 | echo $OUTPUT->header(); |
49a0ba94 | 84 | |
83da3d28 | 85 | /// Some capability checks. |
f0da6b85 | 86 | if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) { |
3a4c2fd0 | 87 | notice(get_string("activityiscurrentlyhidden")); |
88 | } | |
65bcf17b | 89 | |
b32c8dda | 90 | if (!has_capability('mod/forum:viewdiscussion', $context)) { |
49a0ba94 | 91 | notice(get_string('noviewdiscussionspermission', 'forum')); |
92 | } | |
65bcf17b | 93 | |
3b27b0fe | 94 | /// find out current groups mode |
f1035deb | 95 | groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/forum/view.php?id=' . $cm->id); |
13534ef7 ML |
96 | $currentgroup = groups_get_activity_group($cm); |
97 | $groupmode = groups_get_activity_groupmode($cm); | |
9197e147 | 98 | |
49a0ba94 | 99 | /// Okay, we can show the discussions. Log the forum view. |
100 | if ($cm->id) { | |
101 | add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id); | |
102 | } else { | |
103 | add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id"); | |
104 | } | |
105 | ||
106 | ||
107 | ||
83da3d28 | 108 | /// Print settings and things across the top |
109 | ||
110 | // If it's a simple single discussion forum, we need to print the display | |
111 | // mode control. | |
112 | if ($forum->type == 'single') { | |
4e445355 | 113 | if (! $discussion = $DB->get_record("forum_discussions", array("forum" => $forum->id))) { |
114 | if ($discussions = $DB->get_records("forum_discussions", array("forum", $forum->id), "timemodified ASC")) { | |
83da3d28 | 115 | $discussion = array_pop($discussions); |
116 | } | |
117 | } | |
118 | if ($discussion) { | |
119 | if ($mode) { | |
120 | set_user_preference("forum_displaymode", $mode); | |
121 | } | |
122 | $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode); | |
123 | forum_print_mode_form($forum->id, $displaymode, $forum->type); | |
124 | } | |
125 | } | |
126 | ||
a4f495bf | 127 | if (!empty($forum->blockafter) && !empty($forum->blockperiod)) { |
128 | $a->blockafter = $forum->blockafter; | |
129 | $a->blockperiod = get_string('secondstotime'.$forum->blockperiod); | |
9146b979 | 130 | echo $OUTPUT->notification(get_string('thisforumisthrottled','forum',$a)); |
a4f495bf | 131 | } |
132 | ||
0468976c | 133 | if ($forum->type == 'qanda' && !has_capability('moodle/course:manageactivities', $context)) { |
9146b979 | 134 | echo $OUTPUT->notification(get_string('qandanotify','forum')); |
098d27d4 | 135 | } |
136 | ||
e07635f4 | 137 | switch ($forum->type) { |
9197e147 | 138 | case 'single': |
4e445355 | 139 | if (! $discussion = $DB->get_record("forum_discussions", array("forum" => $forum->id))) { |
140 | if ($discussions = $DB->get_records("forum_discussions", array("forum" => $forum->id), "timemodified ASC")) { | |
9146b979 | 141 | echo $OUTPUT->notification("Warning! There is more than one discussion in this forum - using the most recent"); |
501cdbd8 | 142 | $discussion = array_pop($discussions); |
143 | } else { | |
dde78cb8 | 144 | print_error('nodiscussions', 'forum'); |
501cdbd8 | 145 | } |
146 | } | |
11b0c469 | 147 | if (! $post = forum_get_post_full($discussion->firstpost)) { |
dde78cb8 | 148 | print_error('cannotfindfirstpost', 'forum'); |
501cdbd8 | 149 | } |
5476a93d | 150 | if ($mode) { |
151 | set_user_preference("forum_displaymode", $mode); | |
152 | } | |
62b04e08 | 153 | |
8b79a625 | 154 | $canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $context); |
155 | $canrate = has_capability('mod/forum:rate', $context); | |
5476a93d | 156 | $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode); |
8b79a625 | 157 | |
8675df6f | 158 | echo ' '; // this should fix the floating in FF |
62b04e08 | 159 | forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate); |
501cdbd8 | 160 | break; |
161 | ||
9197e147 | 162 | case 'eachuser': |
f064a3df | 163 | if (!empty($forum->intro)) { |
698c90d0 | 164 | echo $OUTPUT->box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro'); |
c6ee38d0 | 165 | } |
a6e13ccc | 166 | echo '<p class="mdl-align">'; |
89d35c49 | 167 | if (forum_user_can_post_discussion($forum, null, -1, $cm)) { |
31d160d3 | 168 | print_string("allowsdiscussions", "forum"); |
e07635f4 | 169 | } else { |
e746e4dd | 170 | echo ' '; |
e07635f4 | 171 | } |
9197e147 | 172 | echo '</p>'; |
c6ee38d0 | 173 | if (!empty($showall)) { |
90f4745c | 174 | forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm); |
c6ee38d0 | 175 | } else { |
90f4745c | 176 | forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm); |
c6ee38d0 | 177 | } |
178 | break; | |
179 | ||
9197e147 | 180 | case 'teacher': |
3c8a606d | 181 | if (!empty($showall)) { |
90f4745c | 182 | forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm); |
3c8a606d | 183 | } else { |
90f4745c | 184 | forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm); |
3c8a606d | 185 | } |
e07635f4 | 186 | break; |
187 | ||
1c7b8b93 NC |
188 | case 'blog': |
189 | if (!empty($forum->intro)) { | |
190 | echo $OUTPUT->box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro'); | |
191 | } | |
192 | echo '<br />'; | |
193 | if (!empty($showall)) { | |
194 | forum_print_latest_discussions($course, $forum, 0, 'plain', '', -1, -1, -1, 0, $cm); | |
195 | } else { | |
196 | forum_print_latest_discussions($course, $forum, -1, 'plain', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm); | |
197 | } | |
198 | break; | |
199 | ||
e07635f4 | 200 | default: |
f064a3df | 201 | if (!empty($forum->intro)) { |
698c90d0 | 202 | echo $OUTPUT->box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro'); |
c6ee38d0 | 203 | } |
61242972 | 204 | echo '<br />'; |
3c8a606d | 205 | if (!empty($showall)) { |
90f4745c | 206 | forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm); |
3c8a606d | 207 | } else { |
90f4745c | 208 | forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm); |
3c8a606d | 209 | } |
65bcf17b | 210 | |
211 | ||
e07635f4 | 212 | break; |
213 | } | |
4e781c7b | 214 | $completion=new completion_info($course); |
215 | $completion->set_module_viewed($cm); | |
385219cb | 216 | echo $OUTPUT->footer($course); |
f93f848a | 217 | |
1adbd2c3 | 218 |