| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: post.php,v 1.154.2.14 2008/10/07 08:13:01 scyrma Exp $ 2 3 // Edit and save a new post to a discussion 4 5 require_once('../../config.php'); 6 require_once ('lib.php'); 7 require_once ('post_form.php'); 8 9 $reply = optional_param('reply', 0, PARAM_INT); 10 $forum = optional_param('forum', 0, PARAM_INT); 11 $edit = optional_param('edit', 0, PARAM_INT); 12 $delete = optional_param('delete', 0, PARAM_INT); 13 $prune = optional_param('prune', 0, PARAM_INT); 14 $name = optional_param('name', '', PARAM_CLEAN); 15 $confirm = optional_param('confirm', 0, PARAM_INT); 16 $groupid = optional_param('groupid', null, PARAM_INT); 17 18 19 //these page_params will be passed as hidden variables later in the form. 20 $page_params = array('reply'=>$reply, 'forum'=>$forum, 'edit'=>$edit); 21 22 $sitecontext = get_context_instance(CONTEXT_SYSTEM); 23 24 if (has_capability('moodle/legacy:guest', $sitecontext, NULL, false)) { 25 26 $wwwroot = $CFG->wwwroot.'/login/index.php'; 27 if (!empty($CFG->loginhttps)) { 28 $wwwroot = str_replace('http:', 'https:', $wwwroot); 29 } 30 31 if (!empty($forum)) { // User is starting a new discussion in a forum 32 if (! $forum = get_record('forum', 'id', $forum)) { 33 error('The forum number was incorrect'); 34 } 35 } else if (!empty($reply)) { // User is writing a new reply 36 if (! $parent = forum_get_post_full($reply)) { 37 error('Parent post ID was incorrect'); 38 } 39 if (! $discussion = get_record('forum_discussions', 'id', $parent->discussion)) { 40 error('This post is not part of a discussion!'); 41 } 42 if (! $forum = get_record('forum', 'id', $discussion->forum)) { 43 error('The forum number was incorrect'); 44 } 45 } 46 if (! $course = get_record('course', 'id', $forum->course)) { 47 error('The course number was incorrect'); 48 } 49 50 if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { // For the logs 51 error('Could not get the course module for the forum instance.'); 52 } else { 53 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); 54 } 55 56 if (!get_referer()) { // No referer - probably coming in via email See MDL-9052 57 require_login(); 58 } 59 60 $navigation = build_navigation('', $cm); 61 print_header($course->shortname, $course->fullname, $navigation, '' , '', true, "", navmenu($course, $cm)); 62 63 notice_yesno(get_string('noguestpost', 'forum').'<br /><br />'.get_string('liketologin'), 64 $wwwroot, get_referer(false)); 65 print_footer($course); 66 exit; 67 } 68 69 require_login(0, false); // Script is useless unless they're logged in 70 71 if (!empty($forum)) { // User is starting a new discussion in a forum 72 if (! $forum = get_record("forum", "id", $forum)) { 73 error("The forum number was incorrect ($forum)"); 74 } 75 if (! $course = get_record("course", "id", $forum->course)) { 76 error("The course number was incorrect ($forum->course)"); 77 } 78 if (! $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { 79 error("Incorrect course module"); 80 } 81 82 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); 83 84 if (! forum_user_can_post_discussion($forum, $groupid, -1, $cm)) { 85 if (has_capability('moodle/legacy:guest', $coursecontext, NULL, false)) { // User is a guest here! 86 $SESSION->wantsurl = $FULLME; 87 $SESSION->enrolcancel = $_SERVER['HTTP_REFERER']; 88 redirect($CFG->wwwroot.'/course/enrol.php?id='.$course->id, get_string('youneedtoenrol')); 89 } else { 90 print_error('nopostforum', 'forum'); 91 } 92 } 93 94 if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) { 95 print_error("activityiscurrentlyhidden"); 96 } 97 98 if (isset($_SERVER["HTTP_REFERER"])) { 99 $SESSION->fromurl = $_SERVER["HTTP_REFERER"]; 100 } else { 101 $SESSION->fromurl = ''; 102 } 103 104 105 // Load up the $post variable. 106 107 $post = new object(); 108 $post->course = $course->id; 109 $post->forum = $forum->id; 110 $post->discussion = 0; // ie discussion # not defined yet 111 $post->parent = 0; 112 $post->subject = ''; 113 $post->userid = $USER->id; 114 $post->message = ''; 115 116 if (isset($groupid)) { 117 $post->groupid = $groupid; 118 } else { 119 $post->groupid = groups_get_activity_group($cm); 120 } 121 122 forum_set_return(); 123 124 } else if (!empty($reply)) { // User is writing a new reply 125 126 if (! $parent = forum_get_post_full($reply)) { 127 error("Parent post ID was incorrect"); 128 } 129 if (! $discussion = get_record("forum_discussions", "id", $parent->discussion)) { 130 error("This post is not part of a discussion!"); 131 } 132 if (! $forum = get_record("forum", "id", $discussion->forum)) { 133 error("The forum number was incorrect ($discussion->forum)"); 134 } 135 if (! $course = get_record("course", "id", $discussion->course)) { 136 error("The course number was incorrect ($discussion->course)"); 137 } 138 if (! $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { 139 error("Incorrect cm"); 140 } 141 142 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); 143 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); 144 145 if (! forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext)) { 146 if (has_capability('moodle/legacy:guest', $coursecontext, NULL, false)) { // User is a guest here! 147 $SESSION->wantsurl = $FULLME; 148 $SESSION->enrolcancel = $_SERVER['HTTP_REFERER']; 149 redirect($CFG->wwwroot.'/course/enrol.php?id='.$course->id, get_string('youneedtoenrol')); 150 } else { 151 print_error('nopostforum', 'forum'); 152 } 153 } 154 155 // Make sure user can post here 156 if (groupmode($course, $cm) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $modcontext)) { 157 if ($discussion->groupid == -1) { 158 print_error('nopostforum', 'forum'); 159 } else { 160 if (!groups_is_member($discussion->groupid)) { 161 print_error('nopostforum', 'forum'); 162 } 163 } 164 } 165 166 if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) { 167 print_error("activityiscurrentlyhidden"); 168 } 169 170 // Load up the $post variable. 171 172 $post = new object(); 173 $post->course = $course->id; 174 $post->forum = $forum->id; 175 $post->discussion = $parent->discussion; 176 $post->parent = $parent->id; 177 $post->subject = $parent->subject; 178 $post->userid = $USER->id; 179 $post->message = ''; 180 181 $post->groupid = ($discussion->groupid == -1) ? 0 : $discussion->groupid; 182 183 $strre = get_string('re', 'forum'); 184 if (!(substr($post->subject, 0, strlen($strre)) == $strre)) { 185 $post->subject = $strre.' '.$post->subject; 186 } 187 188 unset($SESSION->fromdiscussion); 189 190 } else if (!empty($edit)) { // User is editing their own post 191 192 if (! $post = forum_get_post_full($edit)) { 193 error("Post ID was incorrect"); 194 } 195 if ($post->parent) { 196 if (! $parent = forum_get_post_full($post->parent)) { 197 error("Parent post ID was incorrect ($post->parent)"); 198 } 199 } 200 201 if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) { 202 error("This post is not part of a discussion! ($edit)"); 203 } 204 if (! $forum = get_record("forum", "id", $discussion->forum)) { 205 error("The forum number was incorrect ($discussion->forum)"); 206 } 207 if (! $course = get_record("course", "id", $discussion->course)) { 208 error("The course number was incorrect ($discussion->course)"); 209 } 210 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { 211 error('Could not get the course module for the forum instance.'); 212 } else { 213 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); 214 } 215 if (!($forum->type == 'news' && !$post->parent && $discussion->timestart > time())) { 216 if (((time() - $post->created) > $CFG->maxeditingtime) and 217 !has_capability('mod/forum:editanypost', $modcontext)) { 218 error( get_string("maxtimehaspassed", "forum", format_time($CFG->maxeditingtime)) ); 219 } 220 } 221 if (($post->userid <> $USER->id) and 222 !has_capability('mod/forum:editanypost', $modcontext)) { 223 error("You can't edit other people's posts!"); 224 } 225 226 227 // Load up the $post variable. 228 $post->edit = $edit; 229 $post->course = $course->id; 230 $post->forum = $forum->id; 231 $post->groupid = ($discussion->groupid == -1) ? 0 : $discussion->groupid; 232 233 trusttext_prepare_edit($post->message, $post->format, can_use_html_editor(), $modcontext); 234 235 unset($SESSION->fromdiscussion); 236 237 238 }else if (!empty($delete)) { // User is deleting a post 239 240 if (! $post = forum_get_post_full($delete)) { 241 error("Post ID was incorrect"); 242 } 243 if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) { 244 error("This post is not part of a discussion!"); 245 } 246 if (! $forum = get_record("forum", "id", $discussion->forum)) { 247 error("The forum number was incorrect ($discussion->forum)"); 248 } 249 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) { 250 error('Could not get the course module for the forum instance.'); 251 } 252 if (!$course = get_record('course', 'id', $forum->course)) { 253 error('Incorrect course'); 254 } 255 256 require_login($course, false, $cm); 257 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); 258 259 if ( !(($post->userid == $USER->id && has_capability('mod/forum:deleteownpost', $modcontext)) 260 || has_capability('mod/forum:deleteanypost', $modcontext)) ) { 261 error("You can't delete this post!"); 262 } 263 264 265 $replycount = forum_count_replies($post); 266 267 if (!empty($confirm)) { // User has confirmed the delete 268 269 if ($post->totalscore) { 270 notice(get_string("couldnotdeleteratings", "forum"), 271 forum_go_back_to("discuss.php?d=$post->discussion")); 272 273 } else if ($replycount && !has_capability('mod/forum:deleteanypost', $modcontext)) { 274 print_error("couldnotdeletereplies", "forum", 275 forum_go_back_to("discuss.php?d=$post->discussion")); 276 277 } else { 278 if (! $post->parent) { // post is a discussion topic as well, so delete discussion 279 if ($forum->type == 'single') { 280 notice("Sorry, but you are not allowed to delete that discussion!", 281 forum_go_back_to("discuss.php?d=$post->discussion")); 282 } 283 forum_delete_discussion($discussion); 284 285 add_to_log($discussion->course, "forum", "delete discussion", 286 "view.php?id=$cm->id", "$forum->id", $cm->id); 287 288 redirect("view.php?f=$discussion->forum"); 289 290 } else if (forum_delete_post($post, has_capability('mod/forum:deleteanypost', $modcontext))) { 291 292 if ($forum->type == 'single') { 293 // Single discussion forums are an exception. We show 294 // the forum itself since it only has one discussion 295 // thread. 296 $discussionurl = "view.php?f=$forum->id"; 297 } else { 298 $discussionurl = "discuss.php?d=$post->discussion"; 299 } 300 301 add_to_log($discussion->course, "forum", "delete post", $discussionurl, "$post->id", $cm->id); 302 303 redirect(forum_go_back_to($discussionurl)); 304 } else { 305 error("An error occurred while deleting record $post->id"); 306 } 307 } 308 309 310 } else { // User just asked to delete something 311 312 forum_set_return(); 313 314 if ($replycount) { 315 if (!has_capability('mod/forum:deleteanypost', $modcontext)) { 316 print_error("couldnotdeletereplies", "forum", 317 forum_go_back_to("discuss.php?d=$post->discussion")); 318 } 319 print_header(); 320 notice_yesno(get_string("deletesureplural", "forum", $replycount+1), 321 "post.php?delete=$delete&confirm=$delete", 322 $CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id); 323 324 forum_print_post($post, $discussion, $forum, $cm, $course, false, false, false); 325 326 if (empty($post->edit)) { 327 $forumtracked = forum_tp_is_tracked($forum); 328 $posts = forum_get_all_discussion_posts($discussion->id, "created ASC", $forumtracked); 329 forum_print_posts_nested($course, $cm, $forum, $discussion, $post, false, false, $forumtracked, $posts); 330 } 331 } else { 332 print_header(); 333 notice_yesno(get_string("deletesure", "forum", $replycount), 334 "post.php?delete=$delete&confirm=$delete", 335 $CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id); 336 forum_print_post($post, $discussion, $forum, $cm, $course, false, false, false); 337 } 338 339 } 340 print_footer($course); 341 die; 342 343 344 } else if (!empty($prune)) { // Pruning 345 346 if (!$post = forum_get_post_full($prune)) { 347 error("Post ID was incorrect"); 348 } 349 if (!$discussion = get_record("forum_discussions", "id", $post->discussion)) { 350 error("This post is not part of a discussion!"); 351 } 352 if (!$forum = get_record("forum", "id", $discussion->forum)) { 353 error("The forum number was incorrect ($discussion->forum)"); 354 } 355 if ($forum->type == 'single') { 356 error('Discussions from this forum cannot be split'); 357 } 358 if (!$post->parent) { 359 error('This is already the first post in the discussion'); 360 } 361 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) { // For the logs 362 error('Could not get the course module for the forum instance.'); 363 } else { 364 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); 365 } 366 if (!has_capability('mod/forum:splitdiscussions', $modcontext)) { 367 error("You can't split discussions!"); 368 } 369 370 if (!empty($name)) { // User has confirmed the prune 371 372 $newdiscussion = new object(); 373 $newdiscussion->course = $discussion->course; 374 $newdiscussion->forum = $discussion->forum; 375 $newdiscussion->name = $name; 376 $newdiscussion->firstpost = $post->id; 377 $newdiscussion->userid = $discussion->userid; 378 $newdiscussion->groupid = $discussion->groupid; 379 $newdiscussion->assessed = $discussion->assessed; 380 $newdiscussion->usermodified = $post->userid; 381 $newdiscussion->timestart = $discussion->timestart; 382 $newdiscussion->timeend = $discussion->timeend; 383 384 if (!$newid = insert_record('forum_discussions', $newdiscussion)) { 385 error('Could not create new discussion'); 386 } 387 388 $newpost = new object(); 389 $newpost->id = $post->id; 390 $newpost->parent = 0; 391 $newpost->subject = $name; 392 393 if (!update_record("forum_posts", $newpost)) { 394 error('Could not update the original post'); 395 } 396 397 forum_change_discussionid($post->id, $newid); 398 399 // update last post in each discussion 400 forum_discussion_update_last_post($discussion->id); 401 forum_discussion_update_last_post($newid); 402 403 add_to_log($discussion->course, "forum", "prune post", 404 "discuss.php?d=$newid", "$post->id", $cm->id); 405 406 redirect(forum_go_back_to("discuss.php?d=$newid")); 407 408 } else { // User just asked to prune something 409 410 $course = get_record('course', 'id', $forum->course); 411 412 $navlinks = array(); 413 $navlinks[] = array('name' => format_string($post->subject, true), 'link' => "discuss.php?d=$discussion->id", 'type' => 'title'); 414 $navlinks[] = array('name' => get_string("prune", "forum"), 'link' => '', 'type' => 'title'); 415 $navigation = build_navigation($navlinks, $cm); 416 print_header_simple(format_string($discussion->name).": ".format_string($post->subject), "", $navigation, '', "", true, "", navmenu($course, $cm)); 417 418 print_heading(get_string('pruneheading', 'forum')); 419 echo '<center>'; 420 421 include ('prune.html'); 422 423 forum_print_post($post, $discussion, $forum, $cm, $course, false, false, false); 424 echo '</center>'; 425 } 426 print_footer($course); 427 die; 428 } else { 429 error("No operation specified"); 430 431 } 432 433 if (!isset($coursecontext)) { 434 // Has not yet been set by post.php. 435 $coursecontext = get_context_instance(CONTEXT_COURSE, $forum->course); 436 } 437 438 if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { // For the logs 439 error('Could not get the course module for the forum instance.'); 440 } 441 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); 442 443 $mform_post = new mod_forum_post_form('post.php', array('course'=>$course, 'cm'=>$cm, 'coursecontext'=>$coursecontext, 'modcontext'=>$modcontext, 'forum'=>$forum, 'post'=>$post)); 444 445 if ($fromform = $mform_post->get_data()) { 446 447 448 require_login($course, false, $cm); 449 450 if (empty($SESSION->fromurl)) { 451 $errordestination = "$CFG->wwwroot/mod/forum/view.php?f=$forum->id"; 452 } else { 453 $errordestination = $SESSION->fromurl; 454 } 455 456 // TODO add attachment processing 457 //$fromform->attachment = isset($_FILES['attachment']) ? $_FILES['attachment'] : NULL; 458 459 trusttext_after_edit($fromform->message, $modcontext); 460 461 if ($fromform->edit) { // Updating a post 462 unset($fromform->groupid); 463 $fromform->id = $fromform->edit; 464 $message = ''; 465 466 //fix for bug #4314 467 if (!$realpost = get_record('forum_posts', 'id', $fromform->id)) { 468 $realpost = new object; 469 $realpost->userid = -1; 470 } 471 472 473 // if user has edit any post capability 474 // or has either startnewdiscussion or reply capability and is editting own post 475 // then he can proceed 476 // MDL-7066 477 if ( !(($realpost->userid == $USER->id && (has_capability('mod/forum:replypost', $modcontext) 478 || has_capability('mod/forum:startdiscussion', $modcontext))) || 479 has_capability('mod/forum:editanypost', $modcontext)) ) { 480 error("You can not update this post"); 481 } 482 483 $updatepost = $fromform; //realpost 484 $updatepost->forum = $forum->id; 485 if (!forum_update_post($updatepost, $message)) { 486 print_error("couldnotupdate", "forum", $errordestination); 487 } 488 489 // MDL-11818 490 if (($forum->type == 'single') && ($updatepost->parent == '0')){ // updating first post of single discussion type -> updating forum intro 491 $forum->intro = $updatepost->message; 492 $forum->timemodified = time(); 493 if (!update_record("forum", $forum)) { 494 print_error("couldnotupdate", "forum", $errordestination); 495 } 496 } 497 498 $timemessage = 2; 499 if (!empty($message)) { // if we're printing stuff about the file upload 500 $timemessage = 4; 501 } 502 $message .= '<br />'.get_string("postupdated", "forum"); 503 504 if ($subscribemessage = forum_post_subscription($fromform, $forum)) { 505 $timemessage = 4; 506 } 507 if ($forum->type == 'single') { 508 // Single discussion forums are an exception. We show 509 // the forum itself since it only has one discussion 510 // thread. 511 $discussionurl = "view.php?f=$forum->id"; 512 } else { 513 $discussionurl = "discuss.php?d=$discussion->id#p$fromform->id"; 514 } 515 add_to_log($course->id, "forum", "update post", 516 "$discussionurl&parent=$fromform->id", "$fromform->id", $cm->id); 517 518 redirect(forum_go_back_to("$discussionurl"), $message.$subscribemessage, $timemessage); 519 520 exit; 521 522 523 } else if ($fromform->discussion) { // Adding a new post to an existing discussion 524 unset($fromform->groupid); 525 $message = ''; 526 $addpost=$fromform; 527 $addpost->forum=$forum->id; 528 if ($fromform->id = forum_add_new_post($addpost, $message)) { 529 530 $timemessage = 2; 531 if (!empty($message)) { // if we're printing stuff about the file upload 532 $timemessage = 4; 533 } 534 535 if ($subscribemessage = forum_post_subscription($fromform, $forum)) { 536 $timemessage = 4; 537 } 538 539 if (!empty($fromform->mailnow)) { 540 $message .= get_string("postmailnow", "forum"); 541 $timemessage = 4; 542 } else { 543 $message .= '<p>'.get_string("postaddedsuccess", "forum") . '</p>'; 544 $message .= '<p>'.get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime)) . '</p>'; 545 } 546 547 if ($forum->type == 'single') { 548 // Single discussion forums are an exception. We show 549 // the forum itself since it only has one discussion 550 // thread. 551 $discussionurl = "view.php?f=$forum->id"; 552 } else { 553 $discussionurl = "discuss.php?d=$discussion->id"; 554 } 555 add_to_log($course->id, "forum", "add post", 556 "$discussionurl&parent=$fromform->id", "$fromform->id", $cm->id); 557 558 redirect(forum_go_back_to("$discussionurl#p$fromform->id"), $message.$subscribemessage, $timemessage); 559 560 } else { 561 print_error("couldnotadd", "forum", $errordestination); 562 } 563 exit; 564 565 } else { // Adding a new discussion 566 if (!forum_user_can_post_discussion($forum, $fromform->groupid, -1, $cm, $modcontext)) { 567 error('Can not add discussion, sorry.'); 568 } 569 if (empty($fromform->groupid)) { 570 $fromform->groupid = -1; 571 } 572 573 $fromform->mailnow = empty($fromform->mailnow) ? 0 : 1; 574 $discussion = $fromform; 575 $discussion->name = $fromform->subject; 576 $discussion->intro = $fromform->message; 577 $newstopic = false; 578 579 if ($forum->type == 'news' && !$fromform->parent) { 580 $newstopic = true; 581 } 582 $discussion->timestart = $fromform->timestart; 583 $discussion->timeend = $fromform->timeend; 584 585 $message = ''; 586 if ($discussion->id = forum_add_discussion($discussion, $message)) { 587 588 add_to_log($course->id, "forum", "add discussion", 589 "discuss.php?d=$discussion->id", "$discussion->id", $cm->id); 590 591 $timemessage = 2; 592 if (!empty($message)) { // if we're printing stuff about the file upload 593 $timemessage = 4; 594 } 595 596 if ($fromform->mailnow) { 597 $message .= get_string("postmailnow", "forum"); 598 $timemessage = 4; 599 } else { 600 $message .= '<p>'.get_string("postaddedsuccess", "forum") . '</p>'; 601 $message .= '<p>'.get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime)) . '</p>'; 602 } 603 604 if ($subscribemessage = forum_post_subscription($discussion, $forum)) { 605 $timemessage = 4; 606 } 607 608 redirect(forum_go_back_to("view.php?f=$fromform->forum"), $message.$subscribemessage, $timemessage); 609 610 } else { 611 print_error("couldnotadd", "forum", $errordestination); 612 } 613 614 exit; 615 } 616 } 617 618 619 620 // To get here they need to edit a post, and the $post 621 // variable will be loaded with all the particulars, 622 // so bring up the form. 623 624 // $course, $forum are defined. $discussion is for edit and reply only. 625 626 $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id); 627 628 require_login($course->id, false, $cm); 629 630 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); 631 632 if ($post->discussion) { 633 if (! $toppost = get_record("forum_posts", "discussion", $post->discussion, "parent", 0)) { 634 error("Could not find top parent of post $post->id"); 635 } 636 } else { 637 $toppost->subject = ($forum->type == "news") ? get_string("addanewtopic", "forum") : 638 get_string("addanewdiscussion", "forum"); 639 } 640 641 if (empty($post->edit)) { 642 $post->edit = ''; 643 } 644 645 if (empty($discussion->name)) { 646 if (empty($discussion)) { 647 $discussion = new object; 648 } 649 $discussion->name = $forum->name; 650 } 651 if ($forum->type == 'single') { 652 // There is only one discussion thread for this forum type. We should 653 // not show the discussion name (same as forum name in this case) in 654 // the breadcrumbs. 655 $strdiscussionname = ''; 656 } else { 657 // Show the discussion name in the breadcrumbs. 658 $strdiscussionname = format_string($discussion->name).':'; 659 } 660 661 $forcefocus = empty($reply) ? NULL : 'message'; 662 663 $navlinks = array(); 664 if ($post->parent) { 665 $navlinks[] = array('name' => format_string($toppost->subject, true), 'link' => "discuss.php?d=$discussion->id", 'type' => 'title'); 666 $navlinks[] = array('name' => get_string('editing', 'forum'), 'link' => '', 'type' => 'title'); 667 } else { 668 $navlinks[] = array('name' => format_string($toppost->subject), 'link' => '', 'type' => 'title'); 669 } 670 $navigation = build_navigation($navlinks, $cm); 671 672 print_header("$course->shortname: $strdiscussionname ". 673 format_string($toppost->subject), $course->fullname, 674 $navigation, $mform_post->focus($forcefocus), "", true, "", navmenu($course, $cm)); 675 676 // checkup 677 if (!empty($parent) && !forum_user_can_see_post($forum, $discussion, $post, null, $cm)) { 678 error("You cannot reply to this post"); 679 } 680 if (empty($parent) && empty($edit) && !forum_user_can_post_discussion($forum, $groupid, -1, $cm, $modcontext)) { 681 error("You cannot start a new discussion in this forum"); 682 } 683 684 if ($forum->type == 'qanda' 685 && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) 686 && !empty($discussion->id) 687 && !forum_user_has_posted($forum->id, $discussion->id, $USER->id)) { 688 notify(get_string('qandanotify','forum')); 689 } 690 691 forum_check_throttling($forum, $cm); 692 693 if (!empty($parent)) { 694 if (! $discussion = get_record('forum_discussions', 'id', $parent->discussion)) { 695 error('This post is not part of a discussion!'); 696 } 697 698 forum_print_post($parent, $discussion, $forum, $cm, $course, false, false, false); 699 if (empty($post->edit)) { 700 if ($forum->type != 'qanda' || forum_user_can_see_discussion($forum, $discussion, $modcontext)) { 701 $forumtracked = forum_tp_is_tracked($forum); 702 $posts = forum_get_all_discussion_posts($discussion->id, "created ASC", $forumtracked); 703 forum_print_posts_threaded($course, $cm, $forum, $discussion, $parent, 0, false, false, $forumtracked, $posts); 704 } 705 } 706 $heading = get_string("yourreply", "forum"); 707 } else { 708 $forum->intro = trim($forum->intro); 709 if (!empty($forum->intro)) { 710 print_box(format_text($forum->intro), 'generalbox', 'intro'); 711 } 712 if ($forum->type == 'qanda') { 713 $heading = get_string('yournewquestion', 'forum'); 714 } else { 715 $heading = get_string('yournewtopic', 'forum'); 716 } 717 } 718 719 if ($USER->id != $post->userid) { // Not the original author, so add a message to the end 720 $data->date = userdate($post->modified); 721 if ($post->format == FORMAT_HTML) { 722 $data->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&course='.$post->course.'">'. 723 fullname($USER).'</a>'; 724 $post->message .= '<p>(<span class="edited">'.get_string('editedby', 'forum', $data).'</span>)</p>'; 725 } else { 726 $data->name = fullname($USER); 727 $post->message .= "\n\n(".get_string('editedby', 'forum', $data).')'; 728 } 729 } 730 731 //load data into form 732 733 if (forum_is_subscribed($USER->id, $forum->id)) { 734 $subscribe = true; 735 736 } else if (forum_user_has_posted($forum->id, 0, $USER->id)) { 737 $subscribe = false; 738 739 } else { 740 // user not posted yet - use subscription default specified in profile 741 $subscribe = !empty($USER->autosubscribe); 742 } 743 744 // HACK ALERT: this is very wrong, the defaults should be always initialized before calling $mform->get_data() !!! 745 $mform_post->set_data(array( 'general'=>$heading, 746 'subject'=>$post->subject, 747 'message'=>$post->message, 748 'subscribe'=>$subscribe?1:0, 749 'mailnow'=>!empty($post->mailnow), 750 'userid'=>$post->userid, 751 'parent'=>$post->parent, 752 'discussion'=>$post->discussion, 753 'course'=>$course->id)+ 754 755 $page_params+ 756 757 (isset($post->format)?array( 758 'format'=>$post->format): 759 array())+ 760 761 (isset($discussion->timestart)?array( 762 'timestart'=>$discussion->timestart): 763 array())+ 764 765 (isset($discussion->timeend)?array( 766 'timeend'=>$discussion->timeend): 767 array())+ 768 769 (isset($post->groupid)?array( 770 'groupid'=>$post->groupid): 771 array())+ 772 773 (isset($discussion->id)? 774 array('discussion'=>$discussion->id): 775 array())); 776 777 778 $mform_post->display(); 779 780 781 print_footer($course); 782 783 784 ?>
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 |