I've recoded Farsi from Numeric Character References to Windows-1256
[moodle.git] / mod / forum / view.php
CommitLineData
f93f848a 1<?PHP // $Id$
2
b0e3a925 3 require_once("../../config.php");
4 require_once("lib.php");
8adcb49f 5 require_once("$CFG->dirroot/rss/rsslib.php");
f93f848a 6
3c8a606d 7 optional_variable($id); // Course Module ID
8 optional_variable($f); // Forum ID
9 optional_variable($mode); // Display mode (for single forum)
61e96406 10 optional_variable($search, ""); // search string
3c8a606d 11 optional_variable($showall, ""); // show all discussions on one page
2ab76925 12 optional_variable($group, -1); // choose the current group
f93f848a 13
14 if ($id) {
15 if (! $cm = get_record("course_modules", "id", $id)) {
16 error("Course Module ID was incorrect");
17 }
18 if (! $course = get_record("course", "id", $cm->course)) {
19 error("Course is misconfigured");
20 }
21 if (! $forum = get_record("forum", "id", $cm->instance)) {
22 error("Forum ID was incorrect");
23 }
59c71151 24
25 $strforums = get_string("modulenameplural", "forum");
26 $strforum = get_string("modulename", "forum");
27
09aebc94 28 $buttontext = update_module_button($cm->id, $course->id, $strforum);
f93f848a 29
30 } else if ($f) {
31 if (! $forum = get_record("forum", "id", $f)) {
94361e02 32 error("Forum ID was incorrect or no longer exists");
f93f848a 33 }
34 if (! $course = get_record("course", "id", $forum->course)) {
35 error("Forum is misconfigured - don't know what course it's from");
36 }
59c71151 37
38 $strforums = get_string("modulenameplural", "forum");
39 $strforum = get_string("modulename", "forum");
40
d9bf513d 41 if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
09aebc94 42 $buttontext = update_module_button($cm->id, $course->id, $strforum);
d9bf513d 43 } else {
69d79bc3 44 $cm->id = NULL;
d9bf513d 45 $buttontext = "";
46 }
f93f848a 47
48 } else {
49 error("Must specify a course module or a forum ID");
50 }
51
97485d07 52 if (!$buttontext) {
53 $buttontext = forum_print_search_form($course, $search, true, "plain");
54 }
31d160d3 55
68ddf8bc 56 if ($CFG->forcelogin) {
57 require_login();
58 }
59
f93f848a 60 if ($course->category) {
61 require_login($course->id);
e2c4f8e4 62 $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
63 <a href=\"index.php?id=$course->id\">$strforums</a> ->";
bffb106d 64 } else {
e2c4f8e4 65 $navigation = "<a href=\"index.php?id=$course->id\">$strforums</a> ->";
f93f848a 66 }
67
82aa0e8d 68 if ($forum->type == "teacher") {
69 if (!isteacher($course->id)) {
70 error("You must be a $course->teacher to view this forum");
71 }
72 }
73
e2c4f8e4 74 if ($cm) {
69d79bc3 75 add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id);
e2c4f8e4 76 } else {
77 add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id");
78 }
f93f848a 79
80 print_header("$course->shortname: $forum->name", "$course->fullname",
d897cae4 81 "$navigation $forum->name", "", "", true, $buttontext, navmenu($course, $cm));
f93f848a 82
3a4c2fd0 83 if (!$cm->visible and !isteacher($course->id)) {
84 notice(get_string("activityiscurrentlyhidden"));
85 }
86
9197e147 87
88/// Check to see if groups are being used in this forum
89/// and if so, set $currentgroup to reflect the current group
90
2ab76925 91 $changegroup = isset($_GET['group']) ? $_GET['group'] : -1; // Group change requested?
9197e147 92 $groupmode = groupmode($course, $cm); // Groups are being used
2ab76925 93 $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
9197e147 94
2ab76925 95 if ($groupmode and ($currentgroup === false) and !isteacheredit($course->id)) {
96 print_heading(get_string("notingroup", "forum"));
97 print_footer($course);
9197e147 98 exit;
99 }
100
101
102/// Print settings and things in a table across the top
103
104 echo '<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr valign="top">';
105
106 if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
107 if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
108 echo '<td>';
6ff27f32 109 print_group_menu($groups, $groupmode, $currentgroup, "view.php?id=$cm->id");
9197e147 110 echo '</td>';
111 }
112 }
113
114
f93f848a 115 if ($USER) {
9197e147 116 echo '<td align="right">';
501cdbd8 117 $SESSION->fromdiscussion = "$FULLME";
118 if (forum_is_forcesubscribed($forum->id)) {
31d160d3 119 $streveryoneissubscribed = get_string("everyoneissubscribed", "forum");
120 $strallowchoice = get_string("allowchoice", "forum");
c032b59d 121 helpbutton("subscription", $streveryoneissubscribed, "forum");
122 echo "<font size=1>";
501cdbd8 123 if (isteacher($course->id)) {
c032b59d 124 echo "<a title=\"$strallowchoice\" href=\"subscribe.php?id=$forum->id&force=no\">$streveryoneissubscribed</a>";
501cdbd8 125 } else {
c032b59d 126 echo $streveryoneissubscribed;
501cdbd8 127 }
9197e147 128 echo "</font>";
501cdbd8 129
f93f848a 130 } else {
31d160d3 131 $streveryonecanchoose = get_string("everyonecanchoose", "forum");
132 $strforcesubscribe = get_string("forcesubscribe", "forum");
133 $strshowsubscribers = get_string("showsubscribers", "forum");
c032b59d 134
c032b59d 135 helpbutton("subscription", $streveryonecanchoose, "forum");
136 echo "<font size=1>";
137
501cdbd8 138 if (isteacher($course->id)) {
c032b59d 139 echo "<a title=\"$strforcesubscribe\" href=\"subscribe.php?id=$forum->id&force=yes\">$streveryonecanchoose</a>";
9197e147 140 echo "</font><br /><font size=1>";
c032b59d 141 echo "<a href=\"subscribers.php?id=$forum->id\">$strshowsubscribers</a>";
310da166 142 } else {
c032b59d 143 echo $streveryonecanchoose;
501cdbd8 144 }
9197e147 145 echo "</font>";
c032b59d 146
501cdbd8 147 if (forum_is_subscribed($USER->id, $forum->id)) {
6687be17 148 $subtexttitle = get_string("subscribestop", "forum");
31d160d3 149 $subtext = get_string("unsubscribe", "forum");
501cdbd8 150 } else {
6687be17 151 $subtexttitle = get_string("subscribestart", "forum");
31d160d3 152 $subtext = get_string("subscribe", "forum");
501cdbd8 153 }
9197e147 154 echo "<br />";
6687be17 155 echo "<font size=1><a title=\"$subtexttitle\" href=\"subscribe.php?id=$forum->id\">$subtext</a></font>";
bffb106d 156 }
8adcb49f 157
158 //If rss are activated at site and forum level and this forum has rss defined, show link
159 if ($CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype and $forum->rssarticles) {
160 echo "<br />";
161 if ($forum->rsstype == 1) {
162 $tooltiptext = get_string("rsssubscriberssdiscussions","forum",$forum->name);
163 } else {
164 $tooltiptext = get_string("rsssubscriberssposts","forum",$forum->name);
165 }
166 rss_print_link($course->id, $USER->id, "forum", $forum->id, $tooltiptext);
167 }
168
9197e147 169 echo '</td>';
f93f848a 170 }
171
9197e147 172 echo '</tr></table>';
173
f064a3df 174 $forum->intro = trim($forum->intro);
e07635f4 175
176 switch ($forum->type) {
9197e147 177 case 'single':
501cdbd8 178 if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) {
179 if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) {
180 notify("Warning! There is more than one discussion in this forum - using the most recent");
181 $discussion = array_pop($discussions);
182 } else {
183 error("Could not find the discussion in this forum");
184 }
185 }
11b0c469 186 if (! $post = forum_get_post_full($discussion->firstpost)) {
501cdbd8 187 error("Could not find the first post in this forum");
188 }
5476a93d 189 if ($mode) {
190 set_user_preference("forum_displaymode", $mode);
191 }
192 $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
193 forum_print_discussion($course, $forum, $discussion, $post, $displaymode);
501cdbd8 194 break;
195
9197e147 196 case 'eachuser':
f064a3df 197 if (!empty($forum->intro)) {
51a55508 198 print_simple_box(format_text($forum->intro), 'center');
c6ee38d0 199 }
9197e147 200 echo '<p align="center">';
11b0c469 201 if (forum_user_can_post_discussion($forum)) {
31d160d3 202 print_string("allowsdiscussions", "forum");
e07635f4 203 } else {
9197e147 204 echo '&nbsp';
e07635f4 205 }
9197e147 206 echo '</p>';
c6ee38d0 207 if (!empty($showall)) {
9197e147 208 forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup);
c6ee38d0 209 } else {
9197e147 210 forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup);
c6ee38d0 211 }
212 break;
213
9197e147 214 case 'teacher':
3c8a606d 215 if (!empty($showall)) {
9197e147 216 forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup);
3c8a606d 217 } else {
9197e147 218 forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup);
3c8a606d 219 }
e07635f4 220 break;
221
222 default:
f064a3df 223 if (!empty($forum->intro)) {
51a55508 224 print_simple_box(format_text($forum->intro), 'center');
c6ee38d0 225 }
9197e147 226 echo '<p>&nbsp;</p>';
3c8a606d 227 if (!empty($showall)) {
9197e147 228 forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup);
3c8a606d 229 } else {
9197e147 230 forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup);
3c8a606d 231 }
e07635f4 232 break;
233 }
234
f93f848a 235
236 print_footer($course);
237
238?>