Index: post.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/forum/post.php,v retrieving revision 1.114 diff -u -r1.114 post.php --- post.php 18 Oct 2006 07:50:22 -0000 1.114 +++ post.php 18 Oct 2006 10:16:24 -0000 @@ -4,6 +4,9 @@ require_once('../../config.php'); require_once('lib.php'); + include_once $CFG->libdir.'/formslib.php'; + + include("post_form.php"); $reply = optional_param('reply', 0, PARAM_INT); $forum = optional_param('forum', 0, PARAM_INT); @@ -12,7 +15,13 @@ $prune = optional_param('prune',0,PARAM_INT); $name = optional_param('name','',PARAM_CLEAN); $confirm = optional_param('confirm',0,PARAM_INT); - + + + + $mform_post = new forum_post_form('post.php',compact('forum','reply','edit')); + + + if (isguest()) { $wwwroot = $CFG->wwwroot.'/login/index.php'; @@ -38,7 +47,7 @@ if (! $course = get_record('course', 'id', $forum->course)) { error('The course number was incorrect'); } - + if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { // For the logs error('Could not get the course module for the forum instance.'); } else { @@ -66,7 +75,13 @@ require_login(0, false); // Script is useless unless they're logged in - if ($post = data_submitted()) { + + //print_object($mform_post); + + if ($post = $mform_post->data_submitted()) { + + + if (empty($post->course)) { error('No course was defined!'); } @@ -75,12 +90,15 @@ error('Could not find specified course!'); } + if (!empty($forum)) { // Check the forum id and change it to a full object if (! $forum = get_record('forum', 'id', $forum)) { error('The forum number was incorrect'); } } - + + + if (!empty($course->lang)) { // Override current language $CFG->courselang = $course->lang; } @@ -91,22 +109,32 @@ $errordestination = $SESSION->fromurl; } + + $post->subject = clean_param(strip_tags($post->subject, ''), PARAM_CLEAN); // Strip all tags except multilang //$post->message will be cleaned later before display $post->attachment = isset($_FILES['attachment']) ? $_FILES['attachment'] : NULL; + + if (!$cm = get_coursemodule_from_instance("forum", $post->forum, $course->id)) { // For the logs error('Could not get the course module for the forum instance.'); } + + + $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); trusttext_after_edit($post->message, $modcontext); if (!$post->subject or !$post->message) { $post->error = get_string("emptymessage", "forum"); - } else if ($post->edit) { // Updating a post + } else if ($post->edit) { + + + // Updating a post $post->id = $post->edit; $message = ''; @@ -115,19 +143,22 @@ $realpost = new object; $realpost->userid = -1; } - - + + // if user has edit any post capability // or has either startnewdiscussion or reply capability and is editting own post // then he can proceed // MDL-7066 - if ( !(($realpost->userid == $USER->id && (has_capability('mod/forum:replypost', $modcontext) + if ( !(($realpost->userid == $USER->id && (has_capability('mod/forum:replypost', $modcontext) || has_capability('mod/forum:startdiscussion', $modcontext))) || has_capability('mod/forum:editanypost', $modcontext)) ) { error("You can not update this post"); } if ($forum->type == 'news' && !$post->parent) { + + + $updatediscussion = new object; $updatediscussion->id = $post->discussion; if (empty($post->timestartdisabled)) { @@ -170,7 +201,7 @@ } add_to_log($course->id, "forum", "update post", "$discussionurl&parent=$post->id", "$post->id", $cm->id); - + redirect(forum_go_back_to("$discussionurl#$post->id"), $message.$subscribemessage, $timemessage); } else { @@ -178,7 +209,7 @@ } exit; } - + } else if ($post->discussion) { // Adding a new post to an existing discussion $message = ''; if ($post->id = forum_add_new_post($post,$message)) { @@ -216,13 +247,17 @@ } exit; - } else { // Adding a new discussion + } else { + + // Adding a new discussion $post->mailnow = empty($post->mailnow) ? 0 : 1; $discussion = $post; $discussion->name = $post->subject; $discussion->intro = $post->message; $newstopic = false; + + if ($forum->type == 'news' && !$post->parent) { $newstopic = true; } @@ -236,15 +271,26 @@ } else { $discussion->timeend = 0; } + + + if ($newstopic && empty($post->timeenddisabled) && $discussion->timeend <= $discussion->timestart) { $post->error = get_string('timestartenderror', 'forum'); } else { + $message = ''; + //$discussion->attachment=0; + + /*echo $discussion->id = forum_add_discussion($discussion,$message); + exit;*/ + if ($discussion->id = forum_add_discussion($discussion,$message)) { add_to_log($course->id, "forum", "add discussion", "discuss.php?d=$discussion->id", "$discussion->id", $cm->id); + + $timemessage = 2; if (!empty($message)) { // if we're printing stuff about the file upload $timemessage = 4; @@ -256,10 +302,14 @@ $timemessage = 4; } + + if ($subscribemessage = forum_post_subscription($discussion)) { $timemessage = 4; } + + redirect(forum_go_back_to("view.php?f=$post->forum"), $message.$subscribemessage, $timemessage); } else { @@ -270,12 +320,10 @@ } } } + /* else{ + $mform_post->display(); + }*/ - if ($usehtmleditor = can_use_html_editor()) { - $defaultformat = FORMAT_HTML; - } else { - $defaultformat = FORMAT_MOODLE; - } if (isset($post->error)) { // User is re-editing a failed posting @@ -331,11 +379,11 @@ error("The course number was incorrect ($forum->course)"); } $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); - + if (! forum_user_can_post_discussion($forum)) { error("Sorry, but you can not post a new discussion in this forum."); } - + if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { if (!$cm->visible and !has_capability('moodle/course:manageactivities', $coursecontext)) { error(get_string("activityiscurrentlyhidden")); @@ -351,6 +399,11 @@ $post->subject = ""; $post->userid = $USER->id; $post->message = ""; + if(isset($defaultformat)){ + $defaultformat=$defaultformat; + }else{ + $defaultformat=''; + } $post->format = $defaultformat; $post->groupid = get_current_group($course->id); @@ -375,11 +428,11 @@ error("The course number was incorrect ($discussion->course)"); } $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); - + if (! forum_user_can_post($forum)) { error("Sorry, but you can not post in this forum."); } - + if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { if (groupmode($course, $cm)) { // Make sure user can post here $mygroupid = mygroupid($course->id); @@ -393,7 +446,11 @@ } // Load up the $post variable. - + if(isset($defaultformat)){ + $defaultformat =$defaultformat ; + }else{ + $defaultformat=''; + } $post->course = $course->id; $post->forum = $forum->id; $post->discussion = $parent->discussion; @@ -412,6 +469,12 @@ } else if (!empty($edit)) { // User is editing their own post + + if(isset($modcontext)){ + $modcontext=$modcontext; + }else{ + $modcontext=''; + } if (! $post = forum_get_post_full($edit)) { error("Post ID was incorrect"); } @@ -435,6 +498,8 @@ if (! $course = get_record("course", "id", $discussion->course)) { error("The course number was incorrect ($discussion->course)"); } + + if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { error('Could not get the course module for the forum instance.'); } else { @@ -509,7 +574,7 @@ get_string("deleteddiscussion", "forum"), 1); } else if (forum_delete_post($post, has_capability('mod/forum:deleteanypost', $modcontext))) { - + if ($forum->type == 'single') { // Single discussion forums are an exception. We show // the forum itself since it only has one discussion @@ -518,7 +583,7 @@ } else { $discussionurl = "discuss.php?d=$post->discussion"; } - + add_to_log($discussion->course, "forum", "delete post", $discussionurl, "$post->id", $cm->id); $feedback = $replycount ? get_string('deletedposts', 'forum') : get_string('deletedpost', 'forum'); @@ -639,9 +704,7 @@ print_heading(get_string('pruneheading', 'forum')); echo '
'; - include('prune.html'); - forum_print_post($post, $forum->course, $ownpost=false, $reply=false, $link=false); echo '
'; } @@ -650,6 +713,7 @@ } else { + error("No operation specified"); } @@ -784,15 +848,10 @@ } } - print_simple_box_start("center"); - require("post.html"); - print_simple_box_end(); + $mform_post->display(); - if ($usehtmleditor) { - use_html_editor("message"); - } - print_footer($course); + ///print_footer($course); ?>