if (!isset($forum->assessed)) {
$forum->assessed = 0;
}
-
+
if (!empty($forum->ratingtime)) {
$forum->assesstimestart = make_timestamp($forum->startyear, $forum->startmonth, $forum->startday,
$forum->starthour, $forum->startminute, 0);
if (empty($forum->assessed)) {
$forum->assessed = 0;
}
-
+
if (!empty($forum->ratingtime)) {
$forum->assesstimestart = make_timestamp($forum->startyear, $forum->startmonth, $forum->startday,
$forum->starthour, $forum->startminute, 0);
}
}
}
-
+
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); // Cached already
-
+
if ($users = forum_subscribed_users($course, $forum, 0, true)) {
$mailcount=0;
}
}
}
-
+
// make sure we're allowed to see it...
if (!forum_user_can_see_post($forum, $discussion, $post, $userto)) {
continue;
$mailcount++;
/// Mark post as read if forum_usermarksread is set off
- if (!$CFG->forum_usermarksread && forum_tp_can_track_forums($forum, $userto) &&
+ if (!$CFG->forum_usermarksread && forum_tp_can_track_forums($forum, $userto) &&
forum_tp_is_tracked($forum, $userto->id)) {
if (!forum_tp_mark_post_read($userto->id, $post, $forum->id)) {
mtrace("Error: mod/forum/cron.php: Could not mark post $post->id read for user $userto->id".
$posthtml .= forum_make_mail_post($post, $userfrom, $userto, $course, false, $canreply, true, false);
/// Create an array of postid's for this user to mark as read.
- if (!$CFG->forum_usermarksread &&
- forum_tp_can_track_forums($forum, $userto) &&
+ if (!$CFG->forum_usermarksread &&
+ forum_tp_can_track_forums($forum, $userto) &&
forum_tp_is_tracked($forum, $userto->id)) {
$markread[$post->id]->post = $post;
$markread[$post->id]->forumid = $forum->id;
$usermailcount++;
/// Mark post as read if forum_usermarksread is set off
- if (!$CFG->forum_usermarksread &&
- forum_tp_can_track_forums($forum->id, $userto) &&
+ if (!$CFG->forum_usermarksread &&
+ forum_tp_can_track_forums($forum->id, $userto) &&
forum_tp_is_tracked($forum->id, $userto->id)) {
foreach ($markread as $postinfo) {
if (!forum_tp_mark_post_read($userto->id, $postinfo->post, $postinfo->forumid)) {
function forum_make_mail_text($course, $forum, $discussion, $post, $userfrom, $userto, $bare = false) {
global $CFG;
-
+
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) {
error('Course Module ID was incorrect');
}
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext);
-
+
$by = New stdClass;
$by->name = fullname($userfrom, $viewfullnames);
$by->date = userdate($post->modified, "", $userto->timezone);
$sql .= ") AND l.module = 'forum' AND action $LIKE 'add post%' "
." AND userid != ".$USER->id." GROUP BY cmid,l.course,instance";
-
+
if (!$new = get_records_sql($sql)) {
$new = array(); // avoid warnings
}
-
+
// also get all forum tracking stuff ONCE.
$trackingforums = array();
foreach ($forums as $forum) {
$trackingforums[$forum->id] = $forum;
}
}
-
+
if (count($trackingforums) > 0) {
$cutoffdate = isset($CFG->forum_oldpostdays) ? (time() - ($CFG->forum_oldpostdays*24*60*60)) : 0;
$sql = 'SELECT d.forum,d.course,COUNT(p.id) AS count '.
}
$str .= '</div></div>';
}
- if (!empty($str)) {
+ if (!empty($str)) {
if (!array_key_exists($forum->course,$htmlarray)) {
$htmlarray[$forum->course] = array();
}
}
$htmlarray[$forum->course]['forum'] .= $str;
}
- }
+ }
}
function forum_print_recent_activity($course, $isteacher, $timestart) {
&& $post->groupid != -1) { /// Open discussions have groupid -1
$groupmode[$post->forum] = groupmode($course, $cm[$post->forum]);
-
+
if ($groupmode[$post->forum]) {
//hope i didn't break anything
if (!@in_array($mygroupid, $post->groupid))/*$mygroupid != $post->groupid*/{
function forum_get_discussion_posts($discussion, $sort, $forumid) {
/// Gets posts with all info ready for forum_print_post
-/// We pass forumid in because we always know it so no need to make a
+/// We pass forumid in because we always know it so no need to make a
/// complicated join to find it out.
global $CFG;
function forum_get_child_posts($parent, $forumid) {
/// Gets posts with all info ready for forum_print_post
-/// We pass forumid in because we always know it so no need to make a
+/// We pass forumid in because we always know it so no need to make a
/// complicated join to find it out.
global $CFG;
* viewhiddentimedposts
*/
function forum_get_readable_forums($userid, $courseid=0) {
-
+
global $CFG, $USER;
-
+
if (!$forummod = get_record('modules', 'name', 'forum')) {
error('The forum module is not installed');
}
-
+
if ($courseid) {
$courses = get_records('course', 'id', $courseid);
} else {
}
$readableforums = array();
-
+
foreach($courses as $course) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
-
+
if (has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
$selecthidden = ' AND cm.visible = 1';
} else {
$selecthidden = '';
}
-
+
$selectforums = "SELECT f.id AS id,
f.name AS name,
f.type AS type,
AND cm.module = {$forummod->id}
$selecthidden
ORDER BY f.name ASC";
-
+
if ($forums = get_records_sql($selectforums)) {
-
+
$group = user_group($course->id, $userid);
-
+
foreach ($forums as $forum) {
$forumcontext = get_context_instance(CONTEXT_MODULE, $forum->cmid);
-
+
// Evaluate groupmode.
$cm = new object;
$cm->id = $forum->cmid;
$cm->groupmode = $forum->cmgroupmode;
$forum->cmgroupmode = groupmode($course, $cm);
-
+
if ($forum->cmgroupmode == SEPARATEGROUPS
&& !has_capability('moodle/site:accessallgroups', $forumcontext)) {
$forum->accessallgroups = false;
$forum->viewhiddentimedposts
= has_capability('mod/forum:viewhiddentimedposts', $forumcontext);
-
+
if ($forum->type == 'qanda'
&& !has_capability('mod/forum:viewqandawithoutposting', $forumcontext)) {
// We need to check whether the user has posted in the qanda forum.
$forum->onlydiscussions = array(); // Holds discussion ids for the discussions
// the user is allowed to see in this forum.
-
+
if ($discussionspostedin =
forum_discussions_user_has_posted_in($forum->id, $USER->id)) {
foreach ($discussionspostedin as $d) {
}
}
} // End foreach $courses
-
+
//print_object($courses);
//print_object($readableforums);
-
+
return $readableforums;
}
* @param $extrasql
* @return array of posts found
*/
-function forum_search_posts($searchterms, $courseid=0, $limitfrom=0, $limitnum=50,
+function forum_search_posts($searchterms, $courseid=0, $limitfrom=0, $limitnum=50,
&$totalcount, $extrasql='') {
global $CFG, $USER;
require_once($CFG->libdir.'/searchlib.php');
$forums = forum_get_readable_forums($USER->id, $courseid);
-
+
if (count($forums) == 0) {
return false;
}
$messagesearch = '';
$searchstring = '';
-
+
// Need to concat these back together for parser to work.
foreach($searchterms as $searchterm){
if ($searchstring != '') {
if ($log->action == "add post") {
- return get_record_sql("SELECT p.*, f.type AS forumtype, d.forum, d.groupid,
+ return get_record_sql("SELECT p.*, f.type AS forumtype, d.forum, d.groupid,
u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}forum_discussions d,
{$CFG->prefix}forum_posts p,
} else if ($log->action == "add discussion") {
- return get_record_sql("SELECT p.*, f.type AS forumtype, d.forum, d.groupid,
+ return get_record_sql("SELECT p.*, f.type AS forumtype, d.forum, d.groupid,
u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}forum_discussions d,
{$CFG->prefix}forum_posts p,
$timelimit = '';
if (!empty($CFG->forum_enabletimedposts)) {
-
+
if (!$cm = get_coursemodule_from_instance('forum', $forum)) {
error('Course Module ID was incorrect');
}
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
-
+
if (!has_capability('mod/forum:viewhiddentimedposts', $modcontext)) {
$now = time();
$timelimit = " AND ((d.timestart = 0 OR d.timestart <= '$now') AND (d.timeend = 0 OR d.timeend > '$now')";
}
//TODO: there must be a nice way to do this that keeps both postgres and mysql 3.2x happy but I can't find it right now.
- if ($CFG->dbtype == 'postgres7' || $CFG->dbtype == 'mssql' ||
+ if ($CFG->dbtype == 'postgres7' || $CFG->dbtype == 'mssql' ||
$CFG->dbtype == 'mssql_n' || $CFG->dbtype == 'odbc_mssql' || $CFG->dbtype == 'oci8po') {
return get_records_sql("SELECT $postdata, d.name, d.timemodified, d.usermodified, d.groupid,
u.firstname, u.lastname, u.email, u.picture $umfields
$umtable
WHERE d.forum = '$forum'
AND p.parent = 0
- $timelimit $groupselect $userselect
+ $timelimit $groupselect $userselect
ORDER BY $forumsort", $limitfrom, $limitnum);
} else {
return get_records_sql("SELECT $postdata, d.name, d.timemodified, d.usermodified, d.groupid,
}
return $results;
-
+
}
function forum_make_mail_post(&$post, $user, $touser, $course,
$ownpost=false, $reply=false, $link=false, $rate=false, $footer="") {
-
+
// Given the data about a posting, builds up the HTML to display it and
// returns the HTML in a string. This is designed for sending via HTML email.
static $formattedtextid; // The ID number of the post
$post->forum = get_field('forum_discussions', 'forum', 'id', $post->discussion);
-
+
if (!$cm = get_coursemodule_from_instance('forum', $post->forum)) {
mtrace('Course Module ID was incorrect');
}
if ($link) {
$output .= '<div class="link">';
$output .= '<a target="_blank" href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#'.$post->id.'">'.
- get_string('postincontext', 'forum').'</a>';
+ get_string('postincontext', 'forum').'</a>';
$output .= '</div>';
}
if (empty($SESSION->forum_search)) {
// just viewing, return
return;
- }
+ }
echo '<a name="'.$post->id.'"></a>';
echo '<table cellspacing="0" class="forumpost">';
echo '<tr class="header"><td class="picture left">';
echo '<div class="author">';
print_string('forumauthorhidden','forum');
echo '</div></td></tr>';
-
+
echo '<tr><td class="left side">';
echo ' ';
-
+
/// Actual content
-
+
echo '</td><td class="content">'."\n";
echo get_string('forumbodyhidden','forum');
echo '</td></tr></table>';
$strmarkunread = get_string('markunread', 'forum');
if (!empty($post->forum)) {
- $istracked = (forum_tp_can_track_forums($post->forum) &&
+ $istracked = (forum_tp_can_track_forums($post->forum) &&
forum_tp_is_tracked($post->forum));
} else {
$istracked = false;
}
$forumtype = get_field('forum', 'type', 'id', $post->forum);
-
+
$age = time() - $post->created;
/// Hack for allow to edit news posts those are not displayed yet until they are displayed
if (!$post->parent
}
if ($useratings) {
$mypost = ($USER->id == $post->userid);
-
+
$canviewallratings = has_capability('mod/forum:viewanyrating', $modcontext);
-
- if ($canviewallratings and !$mypost) {
+
+ if ($canviewallratings and !$mypost) {
forum_print_ratings_mean($post->id, $ratings->scale, $canviewallratings);
if (!empty($ratings->allow)) {
echo ' ';
* It needs some discussion information and some post information, these
* happen to be combined for efficiency in the $post parameter by the function
* that calls this one: forum_print_latest_discussions()
-*
+*
* @param object $post The post object (passed by reference for speed).
* @param object $forum The forum object.
* @param int $group Current group.
static $rowcount;
static $strmarkalldread;
-
+
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) {
error('Course Module ID was incorrect');
}
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
-
+
if (!isset($rowcount)) {
$rowcount = 0;
global $USER;
- if (empty($post->subscribe) and empty($post->unsubscribe)) {
+ $subscribed=forum_is_subscribed($USER->id, $post->forum);
+ if ((isset($post->subscribe) && $post->subscribe && $subscribed)
+ || (!$post->subscribe && !$subscribed)) {
return "";
}
function forum_user_can_view_post($post, $course, $cm, $forum, $discussion, $user=NULL){
global $CFG, $USER;
-
+
if (!$user){
$user = $USER;
}
-
+
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!has_capability('mod/forum:viewdiscussion', $modcontext)) {
return false;
return false;
}
}
-
+
if (!has_capability('mod/forum:viewdiscussion', $context)) {
return false;
}
-
+
if ($forum->type == 'qanda' &&
!forum_user_has_posted($forum->id, $discussion->id, $user->id) &&
!has_capability('mod/forum:viewqandawithoutposting', $context)) {
}
return true;
}
-
+
function forum_user_can_see_post($forum, $discussion, $post, $user=NULL) {
global $USER;
return false;
}
}
-
+
if (is_numeric($discussion)) {
- if (!$discussion = get_record('forum_discussions','id',$discussion)) {
+ if (!$discussion = get_record('forum_discussions','id',$discussion)) {
return false;
}
}
if (!isset($post->id) && isset($post->parent)) {
$post->id = $post->parent;
}
-
+
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) {
error('Course Module ID was incorrect');
}
if (!has_capability('mod/forum:viewdiscussion', $context, $user->id, false)) {
return false;
}
-
+
if ($forum->type == 'qanda') {
$firstpost = forum_get_firstpost_from_discussion($discussion->id);
-
+
return (forum_user_has_posted($forum->id,$discussion->id,$user->id) ||
$firstpost->id == $post->id ||
has_capability('mod/forum:viewqandawithoutposting', $context, false, $user->id));
/**
* Prints the discussion view screen for a forum.
-*
+*
* @param object $course The current course object.
* @param object $forum Forum to be printed.
* @param int $maxdiscussions The maximum number of discussions per page(optional).
-* @param string $displayformat The display format to use (optional).
+* @param string $displayformat The display format to use (optional).
* @param string $sort Sort arguments for database query (optional).
* @param int $currentgroup Group to display discussions for (optional).
* @param int $groupmode Group mode of the forum (optional).
* @param int $page Page mode, page to display (optional).
-*
+*
*/
function forum_print_latest_discussions($course, $forum, $maxdiscussions=5, $displayformat='plain', $sort='',
$currentgroup=-1, $groupmode=-1, $page=-1) {
global $CFG, $USER;
-
+
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) {
error('Course Module ID was incorrect');
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
+
/// Sort out some defaults
$currentgroup = get_current_group($course->id);
}
- if (!$currentgroup and ($groupmode != SEPARATEGROUPS or
+ if (!$currentgroup and ($groupmode != SEPARATEGROUPS or
has_capability('moodle/site:accessallgroups', $context)) ) {
$visiblegroups = -1;
} else {
/// If the user can post discussions, then this is a good place to put the button for it
//add group mode in there, to test for visible group
if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode) ||
- has_capability('moodle/legacy:guest', $context, NULL, false)) {
+ has_capability('moodle/legacy:guest', $context, NULL, false)) {
echo '<div class="singlebutton forumaddnew">';
echo "<form name=\"newdiscussionform\" method=\"get\" action=\"$CFG->wwwroot/mod/forum/post.php\">";
echo "<input type=\"hidden\" name=\"forum\" value=\"$forum->id\" />";
echo '<input type="submit" value="';
- echo ($forum->type == 'news') ? get_string('addanewtopic', 'forum')
- : (($forum->type == 'qanda')
- ? get_string('addanewquestion','forum')
+ echo ($forum->type == 'news') ? get_string('addanewtopic', 'forum')
+ : (($forum->type == 'qanda')
+ ? get_string('addanewquestion','forum')
: get_string('addanewdiscussion', 'forum'));
echo '" />';
echo '</form>';
$istracking = forum_tp_can_track_forums($forumid) && forum_tp_is_tracked($forumid);
if ($posts = forum_get_child_posts($parent, $forumid)) {
-
+
if (!$cm = get_coursemodule_from_instance('forum', $forumid, $courseid)) {
error('Course Module ID was incorrect');
}
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$canviewfullnames = has_capability('moodle/site:viewfullnames', $modcontext);
-
+
foreach ($posts as $post) {
echo '<div class="indent">';
} else {
$ownpost = ($USER->id == $post->userid);
}
-
+
$post->subject = format_string($post->subject);
if (forum_print_post($post, $courseid, $ownpost, $reply, $link, $ratings,
}
foreach ($posts as $post) {
-
+
$modcontext = get_context_instance(CONTEXT_MODULE, $post->cmid);
$canviewallgroups = has_capability('moodle/site:accessallgroups', $modcontext);
-
+
if ($groupid and ($post->groupid != -1 and $groupid != $post->groupid and !$canviewallgroups)) {
continue;
}
/*
* This function gets run whenever a role is assigned to a user in a context
*
- * @param integer $userid
- * @param object $context
+ * @param integer $userid
+ * @param object $context
* @return bool
*/
function forum_role_assign($userid, $context) {
/*
* This function gets run whenever a role is assigned to a user in a context
*
- * @param integer $userid
- * @param object $context
+ * @param integer $userid
+ * @param object $context
* @return bool
*/
function forum_role_unassign($userid, $context) {
}
}
}
- continue;
+ continue;
}
$subcontext = get_context_instance(CONTEXT_COURSE, $course->id);
forum_add_user_default_subscriptions($userid, $subcontext);
if ($courses = get_records('course', 'category', $context->instanceid)) {
foreach ($courses as $course) {
if ($course->id == SITEID) {
- continue; // temporary workaround for bug MDL-7114
+ continue; // temporary workaround for bug MDL-7114
}
$subcontext = get_context_instance(CONTEXT_COURSE, $course->id);
forum_add_user_default_subscriptions($userid, $subcontext);
}
}
break;
-
+
case CONTEXT_COURSE: // For a whole course
if ($course = get_record('course', 'id', $context->instanceid)) {
}
}
break;
-
+
case CONTEXT_MODULE: // Just one forum
if ($cm = get_coursemodule_from_id('forum', $context->instanceid)) {
- if ($forum = get_record('forum', 'id', $cm->instance)) {
+ if ($forum = get_record('forum', 'id', $cm->instance)) {
if ($forum->forcesubscribe != FORUM_INITIALSUBSCRIBE) {
continue;
}
forum_unsubscribe($userid, $forum->id);
}
}
- }
+ }
}
}
- continue;
+ continue;
}
$subcontext = get_context_instance(CONTEXT_COURSE, $course->id);
forum_remove_user_subscriptions($userid, $subcontext);
}
}
break;
-
+
case CONTEXT_MODULE: // Just one forum
if ($cm = get_coursemodule_from_id('forum', $context->instanceid)) {
- if ($forum = get_record('forum', 'id', $cm->instance)) {
+ if ($forum = get_record('forum', 'id', $cm->instance)) {
if (!has_capability('mod/forum:viewdiscussion', $context, $userid)) {
forum_unsubscribe($userid, $forum->id);
}
if ($CFG->dbtype === 'postgres7') {
// this query takes 20ms, vs several minutes for the one below
- $sql = " SELECT COUNT (DISTINCT u.id ) "
+ $sql = " SELECT COUNT (DISTINCT u.id ) "
. " FROM ( "
- . " SELECT p.id "
+ . " SELECT p.id "
. " FROM {$CFG->prefix}forum_posts p "
. " JOIN {$CFG->prefix}forum_discussions d ON p.discussion = d.id "
. " JOIN {$CFG->prefix}forum_read r ON p.id = r.postid"
}
/**
* Get a list of forums not tracked by the user.
-*
+*
* @param int $userid The id of the user to use.
* @param int $courseid The id of the course being checked (optional).
* @return mixed An array indexed by forum id, or false.
/**
* Tells whether a specific forum is tracked by the user. A user can optionally
* be specified. If not specified, the current user is assumed.
-*
+*
* @param mixed $forum If int, the id of the forum being checked; if object, the forum object
* @param int $userid The id of the user being checked (optional).
* @return boolean
delete_records('forum_read', 'id', $oldreadpost->id);
}
}
-}
+}
/**
* Sets the last post for a given discussion
if (!record_exists('forum_discussions', 'id', $discussionid)) {
return false;
}
-
+
/// Use SQL to find the last post for this discussion
$sql = 'SELECT id, userid, modified '.
'FROM '.$CFG->prefix.'forum_posts '.
global $CFG,$db;
$forummodule = get_record("modules", "name", "forum");
-
+
$sql = 'SELECT f.id, f.id FROM '.$CFG->prefix.'forum f, '.$CFG->prefix.'course_modules cm WHERE
f.id = cm.instance AND cm.module ='.$forummodule->id.' AND cm.visible = 1 AND cm.course = '.$courseid.'
AND cm.groupmode ='.SEPARATEGROUPS;
if (!is_object($forum)) {
return false; // this is broken.
}
-
+
if (empty($forum->blockafter)) {
return true;
}
-
+
if (empty($forum->blockperiod)) {
return true;
}
-
+
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) {
error('Course Module ID was incorrect');
}
// get the number of posts in the last period we care about
$timenow = time();
$timeafter = $timenow - $forum->blockperiod;
-
+
$numposts = count_records_sql('SELECT COUNT(p.id) FROM '.$CFG->prefix.'forum_posts p'
.' JOIN '.$CFG->prefix.'forum_discussions d'
.' ON p.discussion = d.id WHERE d.forum = '.$forum->id
$a->blockafter = $forum->blockafter;
$a->numposts = $numposts;
$a->blockperiod = get_string('secondstotime'.$forum->blockperiod);
-
+
if ($forum->blockafter <= $numposts) {
error(get_string('forumblockingtoomanyposts','error',$a),$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id);
}
notify(get_string('forumblockingalmosttoomanyposts','forum',$a));
}
-
+
}
*/
function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(),
$studentroles=array(), $guestroles=array(), $cmid=NULL) {
-
+
global $CFG;
-
+
if (!isset($forum->open) && !isset($forum->assesspublic)) {
// We assume that this forum has already been converted to use the
// Roles System. Columns forum.open and forum.assesspublic get dropped
// once the forum module has been upgraded to use Roles.
return false;
}
-
+
if ($forum->type == 'teacher') {
// Teacher forums should be converted to normal forums that
}
} else {
// Non-teacher forum.
-
+
if (empty($cmid)) {
// We were not given the course_module id. Try to find it.
if (!$cm = get_coursemodule_from_instance('forum', $forum->id)) {
}
break;
}
-
+
if (empty($cm)) {
$cm = get_record('course_modules', 'id', $cmid);
}
require_once('../../config.php');
require_once('lib.php');
+ require_once('post_form.php');
$reply = optional_param('reply', 0, PARAM_INT);
$forum = optional_param('forum', 0, PARAM_INT);
$edit = optional_param('edit', 0, PARAM_INT);
$delete = optional_param('delete', 0, PARAM_INT);
- $prune = optional_param('prune',0,PARAM_INT);
- $name = optional_param('name','',PARAM_CLEAN);
- $confirm = optional_param('confirm',0,PARAM_INT);
-
- $sitecontext = get_context_instance(CONTEXT_SYSTEM);
+ $prune = optional_param('prune', 0, PARAM_INT);
+ $name = optional_param('name', '', PARAM_CLEAN);
+ $confirm = optional_param('confirm', 0, PARAM_INT);
+
+
+ $page_params=array('reply'=>$reply,
+ 'forum'=>$forum,
+ 'edit'=>$edit); //these page_params will be passed as hidden variables
+ //later in the form.
+
+ $sitecontext = get_context_instance(CONTEXT_SYSTEM);
if (has_capability('moodle/legacy:guest', $sitecontext, NULL, false)) {
$wwwroot = $CFG->wwwroot.'/login/index.php';
if (!empty($CFG->loginhttps)) {
- $wwwroot = str_replace('http','https', $wwwroot);
+ $wwwroot = str_replace('http', 'https', $wwwroot);
}
if (!empty($forum)) { // User is starting a new discussion in a forum
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 {
print_header($course->shortname, $course->fullname,
"<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
<a href=\"../forum/index.php?id=$course->id\">$strforums</a> ->
- <a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>",
+ <a href=\"view.php?f=$forum->id\">".format_string($forum->name, true)."</a>",
'', '', true, "", navmenu($course, $cm));
} else {
print_header($course->shortname, $course->fullname,
print_footer($course);
exit;
}
-
require_login(0, false); // Script is useless unless they're logged in
- if ($post = data_submitted()) {
- if (empty($post->course)) {
- error('No course was defined!');
- }
-
- if (!$course = get_record('course', 'id', $post->course)) {
- 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;
- }
-
- if (empty($SESSION->fromurl)) {
- $errordestination = "$CFG->wwwroot/mod/forum/view.php?f=$post->forum";
- } else {
- $errordestination = $SESSION->fromurl;
- }
-
- $post->subject = clean_param(strip_tags($post->subject, '<lang><span>'), 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
- $post->id = $post->edit;
- $message = '';
-
- //fix for bug #4314
- if (!$realpost = get_record('forum_posts','id',$post->id)) {
- $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)
- || 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)) {
- $updatediscussion->timestart = make_timestamp($post->timestartyear, $post->timestartmonth, $post->timestartday);
- } else {
- $updatediscussion->timestart = 0;
- }
- if (empty($post->timeenddisabled)) {
- $updatediscussion->timeend = make_timestamp($post->timeendyear, $post->timeendmonth, $post->timeendday);
- } else {
- $updatediscussion->timeend = 0;
- }
- if (empty($post->timeenddisabled) && $updatediscussion->timeend <= $updatediscussion->timestart) {
- $post->error = get_string('timestartenderror', 'forum');
- } elseif (!update_record('forum_discussions', $updatediscussion)) {
- error(get_string("couldnotupdate", "forum"), $errordestination);
- }
- }
-
- if (!isset($post->error)) {
-
- if (forum_update_post($post,$message)) {
-
- $timemessage = 2;
- if (!empty($message)) { // if we're printing stuff about the file upload
- $timemessage = 4;
- }
- $message .= '<br />'.get_string("postupdated", "forum");
-
- if ($subscribemessage = forum_post_subscription($post)) {
- $timemessage = 4;
- }
- if ($forum->type == 'single') {
- // Single discussion forums are an exception. We show
- // the forum itself since it only has one discussion
- // thread.
- $discussionurl = "view.php?f=$forum->id";
- } else {
- $discussionurl = "discuss.php?d=$post->discussion#$post->id";
- }
- 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 {
- error(get_string("couldnotupdate", "forum"), $errordestination);
- }
- exit;
- }
-
- } else if ($post->discussion) { // Adding a new post to an existing discussion
- $message = '';
- if ($post->id = forum_add_new_post($post,$message)) {
-
- $timemessage = 2;
- if (!empty($message)) { // if we're printing stuff about the file upload
- $timemessage = 4;
- }
- $message .= '<br />'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
-
- if ($subscribemessage = forum_post_subscription($post)) {
- $timemessage = 4;
- }
-
- if (!empty($post->mailnow)) {
- $message .= get_string("postmailnow", "forum");
- $timemessage = 4;
- }
-
- if ($forum->type == 'single') {
- // Single discussion forums are an exception. We show
- // the forum itself since it only has one discussion
- // thread.
- $discussionurl = "view.php?f=$forum->id";
- } else {
- $discussionurl = "discuss.php?d=$post->discussion";
- }
- add_to_log($course->id, "forum", "add post",
- "$discussionurl&parent=$post->id", "$post->id", $cm->id);
-
- redirect(forum_go_back_to("$discussionurl#$post->id"), $message.$subscribemessage, $timemessage);
-
- } else {
- error(get_string("couldnotadd", "forum"), $errordestination);
- }
- exit;
-
- } 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;
- }
- if ($newstopic && empty($post->timestartdisabled)) {
- $discussion->timestart = make_timestamp($post->timestartyear, $post->timestartmonth, $post->timestartday);
- } else {
- $discussion->timestart = 0;
- }
- if ($newstopic && empty($post->timeenddisabled)) {
- $discussion->timeend = make_timestamp($post->timeendyear, $post->timeendmonth, $post->timeendday);
- } else {
- $discussion->timeend = 0;
- }
- if ($newstopic && empty($post->timeenddisabled) && $discussion->timeend <= $discussion->timestart) {
- $post->error = get_string('timestartenderror', 'forum');
- } else {
- $message = '';
- 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;
- }
- $message .= '<br />'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
-
- if ($post->mailnow) {
- $message .= get_string("postmailnow", "forum");
- $timemessage = 4;
- }
-
- if ($subscribemessage = forum_post_subscription($discussion)) {
- $timemessage = 4;
- }
-
- redirect(forum_go_back_to("view.php?f=$post->forum"), $message.$subscribemessage, $timemessage);
-
- } else {
- error(get_string("couldnotadd", "forum"), $errordestination);
- }
-
- exit;
- }
- }
- }
-
- if ($usehtmleditor = can_use_html_editor()) {
- $defaultformat = FORMAT_HTML;
- } else {
- $defaultformat = FORMAT_MOODLE;
- }
-
- if (isset($post->error)) { // User is re-editing a failed posting
-
- // Set up all the required objects again, and reuse the same $post
-
- if (! $forum = get_record("forum", "id", $post->forum)) {
- error("The forum number was incorrect ($post->forum)");
- }
-
- if (! $course = get_record("course", "id", $forum->course)) {
- error("The course number was incorrect ($forum->course)");
- }
-
- if (!empty($post->parent)) {
- if (! $parent = forum_get_post_full($post->parent)) {
- error("Parent post ID was incorrect ($post->parent)");
- }
- }
-
- if (!empty($post->discussion)) {
- if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
- error("This post is not part of a discussion! ($post->discussion)");
- }
- } else {
- $discussion = new stdClass();
- $newstopic = false;
- if ($forum->type == 'news' && !$post->parent) {
- $newstopic = true;
- }
- if ($newstopic && empty($post->timestartdisabled)) {
- $discussion->timestart = make_timestamp($post->timestartyear, $post->timestartmonth, $post->timestartday);
- } else {
- $discussion->timestart = 0;
- }
- if ($newstopic && empty($post->timeenddisabled)) {
- $discussion->timeend = make_timestamp($post->timeendyear, $post->timeendmonth, $post->timeendday);
- } else {
- $discussion->timeend = 0;
- }
- }
-
- $post->subject = stripslashes_safe($post->subject);
- $post->message = stripslashes_safe($post->message);
-
- } else if (!empty($forum)) { // User is starting a new discussion in a forum
-
- $SESSION->fromurl = $_SERVER["HTTP_REFERER"];
-
+ if (!empty($forum)) { // User is starting a new discussion in a forum
if (! $forum = get_record("forum", "id", $forum)) {
error("The forum number was incorrect ($forum)");
}
error("The course number was incorrect ($forum->course)");
}
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
-
if (! forum_user_can_post_discussion($forum)) {
if (has_capability('moodle/legacy:guest', $coursecontext, NULL, false)) { // User is a guest here!
$SESSION->wantsurl = $FULLME;
print_error('nopostforum', 'forum');
}
}
-
+
if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
error(get_string("activityiscurrentlyhidden"));
}
}
+ $SESSION->fromurl = $_SERVER["HTTP_REFERER"];
+
+
// Load up the $post variable.
$post->course = $course->id;
$post->subject = "";
$post->userid = $USER->id;
$post->message = "";
- $post->format = $defaultformat;
$post->groupid = get_current_group($course->id);
if ($post->groupid == 0) {
}
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
-
if (! forum_user_can_post($forum)) {
if (has_capability('moodle/legacy:guest', $coursecontext, NULL, false)) { // User is a guest here!
$SESSION->wantsurl = $FULLME;
print_error('nopostforum', '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);
$post->subject = $parent->subject;
$post->userid = $USER->id;
$post->message = "";
- $post->format = $defaultformat;
$strre = get_string('re', 'forum');
if (!(substr($post->subject, 0, strlen($strre)) == $strre)) {
}
unset($SESSION->fromdiscussion);
-
} else if (!empty($edit)) { // User is editing their own post
if (! $post = forum_get_post_full($edit)) {
error("Parent post ID was incorrect ($post->parent)");
}
}
+
if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
- error("This post is not part of a discussion! ($reply)");
+ error("This post is not part of a discussion! ($edit)");
}
if (! $forum = get_record("forum", "id", $discussion->forum)) {
error("The forum number was incorrect ($discussion->forum)");
unset($SESSION->fromdiscussion);
- } else if (!empty($delete)) { // User is deleting a post
+ }else if (!empty($delete)) { // User is deleting a post
if (! $post = forum_get_post_full($delete)) {
error("Post ID was incorrect");
}
}
+
$replycount = forum_count_replies($post);
if (!empty($confirm)) { // User has confirmed the delete
add_to_log($discussion->course, "forum", "delete discussion",
"view.php?id=$cm->id", "$forum->id", $cm->id);
- redirect("view.php?f=$discussion->forum",
- get_string("deleteddiscussion", "forum"), 1);
+ redirect("view.php?f=$discussion->forum");
} 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
} 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');
- redirect(forum_go_back_to($discussionurl), $feedback, 1);
+ redirect(forum_go_back_to($discussionurl));
} else {
error("An error occurred while deleting record $post->id");
}
add_to_log($discussion->course, "forum", "prune post",
"discuss.php?d=$newid", "$post->id", $cm->id);
- redirect(forum_go_back_to("discuss.php?d=$newid"), get_string("prunedpost", "forum"), 1);
+ redirect(forum_go_back_to("discuss.php?d=$newid"));
} else { // User just asked to prune something
$strforums = get_string("modulenameplural", "forum");
print_header_simple(format_string($discussion->name).": ".format_string($post->subject), "",
"<a href=\"../forum/index.php?id=$course->id\">$strforums</a> ->
- <a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a> ->
- <a href=\"discuss.php?d=$discussion->id\">".format_string($post->subject,true)."</a> -> ".
+ <a href=\"view.php?f=$forum->id\">".format_string($forum->name, true)."</a> ->
+ <a href=\"discuss.php?d=$discussion->id\">".format_string($post->subject, true)."</a> -> ".
get_string("prune", "forum"), '', "", true, "", navmenu($course, $cm));
print_heading(get_string('pruneheading', 'forum'));
}
print_footer($course);
die;
-
-
} else {
error("No operation specified");
}
+ if (!isset($coursecontext)) {
+ // Has not yet been set by post.php.
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $forum->course);
+ }
+
+ $mform_post = new forum_post_form('post.php', compact('coursecontext', 'forum', 'post'));
+
+ if ($fromform = $mform_post->data_submitted()) {
+
+
+ if (!empty($course->lang)) { // Override current language
+ $CFG->courselang = $course->lang;
+ }
+
+ if (empty($SESSION->fromurl)) {
+ $errordestination = "$CFG->wwwroot/mod/forum/view.php?f=$forum->id";
+ } else {
+ $errordestination = $SESSION->fromurl;
+ }
+
+ // TODO add attachment processing
+ //$fromform->attachment = isset($_FILES['attachment']) ? $_FILES['attachment'] : NULL;
+
+ 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.');
+ }
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ trusttext_after_edit($fromform->message, $modcontext);
+
+ if ($fromform->edit) { // Updating a post
+ $fromform->id = $fromform->edit;
+ $message = '';
+
+ //fix for bug #4314
+ if (!$realpost = get_record('forum_posts', 'id', $fromform->id)) {
+ $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)
+ || has_capability('mod/forum:startdiscussion', $modcontext))) ||
+ has_capability('mod/forum:editanypost', $modcontext)) ) {
+ error("You can not update this post");
+ }
+
+ if ($forum->type == 'news' && !$fromform->parent) {
+ $updatediscussion = new object;
+ $updatediscussion->id = $fromform->discussion;
+ if (empty($fromform->timestartdisabled)) {
+ $updatediscussion->timestart = $fromform->timestart;
+ } else {
+ $updatediscussion->timestart = 0;
+ }
+ if (empty($fromform->timeenddisabled)) {
+ $updatediscussion->timeend = $fromform->timeend;
+ } else {
+ $updatediscussion->timeend = 0;
+ }
+
+ if (!update_record('forum_discussions', $updatediscussion)) {
+ error(get_string("couldnotupdate", "forum"), $errordestination);
+ }
+ }
+
+ $updatepost=$fromform; //realpost
+ $updatepost->forum=$forum->id;
+ if (!forum_update_post($updatepost, $message)) {
+ error(get_string("couldnotupdate", "forum"), $errordestination);
+ }
+
+ $timemessage = 2;
+ if (!empty($message)) { // if we're printing stuff about the file upload
+ $timemessage = 4;
+ }
+ $message .= '<br />'.get_string("postupdated", "forum");
+
+ if ($subscribemessage = forum_post_subscription($fromform)) {
+ $timemessage = 4;
+ }
+ if ($forum->type == 'single') {
+ // Single discussion forums are an exception. We show
+ // the forum itself since it only has one discussion
+ // thread.
+ $discussionurl = "view.php?f=$forum->id";
+ } else {
+ $discussionurl = "discuss.php?d=$discussion->id#$fromform->id";
+ }
+ add_to_log($course->id, "forum", "update post",
+ "$discussionurl&parent=$fromform->id", "$fromform->id", $cm->id);
+
+ redirect(forum_go_back_to("$discussionurl"), $message.$subscribemessage, $timemessage);
+
+ exit;
+
+
+ } else if ($fromform->discussion) { // Adding a new post to an existing discussion
+ $message = '';
+ $addpost=$fromform;
+ $addpost->forum=$forum->id;
+ if ($fromform->id = forum_add_new_post($addpost, $message)) {
+
+ $timemessage = 2;
+ if (!empty($message)) { // if we're printing stuff about the file upload
+ $timemessage = 4;
+ }
+ $message .= '<br />'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
+
+ if ($subscribemessage = forum_post_subscription($fromform)) {
+ $timemessage = 4;
+ }
+
+ if (!empty($fromform->mailnow)) {
+ $message .= get_string("postmailnow", "forum");
+ $timemessage = 4;
+ }
+
+ if ($forum->type == 'single') {
+ // Single discussion forums are an exception. We show
+ // the forum itself since it only has one discussion
+ // thread.
+ $discussionurl = "view.php?f=$forum->id";
+ } else {
+ $discussionurl = "discuss.php?d=$discussion->id";
+ }
+ add_to_log($course->id, "forum", "add post",
+ "$discussionurl&parent=$fromform->id", "$fromform->id", $cm->id);
+
+ redirect(forum_go_back_to("$discussionurl#$fromform->id"), $message.$subscribemessage, $timemessage);
+
+ } else {
+ error(get_string("couldnotadd", "forum"), $errordestination);
+ }
+ exit;
+
+ } else { // Adding a new discussion
+ $fromform->mailnow = empty($fromform->mailnow) ? 0 : 1;
+ $discussion = $fromform;
+ $discussion->name = $fromform->subject;
+ $discussion->intro = $fromform->message;
+ $newstopic = false;
+
+ if ($forum->type == 'news' && !$fromform->parent) {
+ $newstopic = true;
+ }
+ if ($newstopic && empty($fromform->timestartdisabled)) {
+ $discussion->timestart = $fromform->timestart;
+ } else {
+ $discussion->timestart = 0;
+ }
+ if ($newstopic && empty($fromform->timeenddisabled)) {
+ $discussion->timeend = $fromform->timeend;
+ } else {
+ $discussion->timeend = 0;
+ }
+
+ $message = '';
+ 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;
+ }
+ $message .= '<br />'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
+
+ if ($fromform->mailnow) {
+ $message .= get_string("postmailnow", "forum");
+ $timemessage = 4;
+ }
+
+ if ($subscribemessage = forum_post_subscription($discussion)) {
+ $timemessage = 4;
+ }
+
+ redirect(forum_go_back_to("view.php?f=$fromform->forum"), $message.$subscribemessage, $timemessage);
+
+ } else {
+ error(get_string("couldnotadd", "forum"), $errordestination);
+ }
+
+ exit;
+ }
+ }
+
+
// To get here they need to edit a post, and the $post
// variable will be loaded with all the particulars,
get_string("addanewdiscussion", "forum");
}
- if (empty($post->subject)) {
- $formstart = 'theform.subject';
- } else {
- $formstart = '';
- }
+
if ($post->parent) {
- $navtail = ' -> <a href="discuss.php?d='.$discussion->id.'">'.format_string($toppost->subject,true).'</a> -> '.
+ $navtail = ' -> <a href="discuss.php?d='.$discussion->id.'">'.format_string($toppost->subject, true).'</a> -> '.
get_string('editing', 'forum');
} else {
$navtail = ' -> '.format_string($toppost->subject);
$strforums = get_string("modulenameplural", "forum");
- $navmiddle = "<a href=\"../forum/index.php?id=$course->id\">$strforums</a> -> <a href=\"view.php?f=$forum->id\">".format_string($forum->name,true).'</a> ';
+ $navmiddle = "<a href=\"../forum/index.php?id=$course->id\">$strforums</a> -> <a href=\"view.php?f=$forum->id\">".format_string($forum->name, true).'</a> ';
if (empty($discussion->name)) {
if (empty($discussion)) {
print_header("$course->shortname: $strdiscussionname ".
format_string($toppost->subject), "$course->fullname",
"<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
- $navmiddle $navtail", $formstart, "", true, "", navmenu($course, $cm));
+ $navmiddle $navtail", $mform_post->focus(), "", true, "", navmenu($course, $cm));
} else {
print_header("$course->shortname: $strdiscussionname ".
format_string($toppost->subject), "$course->fullname",
- "$navmiddle $navtail", "$formstart", "", true, "", navmenu($course, $cm));
+ "$navmiddle $navtail", $mform_post->focus(), "", true, "", navmenu($course, $cm));
}
}
if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) &&
- !forum_user_has_posted($forum->id,$discussion->id,$USER->id)) {
- notify(get_string('qandanotify','forum'));
+ !forum_user_has_posted($forum->id, $discussion->id, $USER->id)) {
+ notify(get_string('qandanotify', 'forum'));
}
forum_check_throttling($forum);
forum_print_posts_threaded($parent->id, $course->id, 0, false, false, $user_read_array, $discussion->forum);
}
}
- print_heading(get_string("yourreply", "forum").':');
+ $heading=get_string("yourreply", "forum");
} else {
$forum->intro = trim($forum->intro);
if (!empty($forum->intro)) {
print_simple_box(format_text($forum->intro), 'center');
}
if ($forum->type == 'qanda') {
- print_heading(get_string('yournewquestion','forum'));
+ $heading=get_string('yournewquestion', 'forum');
} else {
- print_heading(get_string('yournewtopic', 'forum'));
+ $heading=get_string('yournewtopic', 'forum');
}
}
- echo '<center>';
- if (!empty($post->error)) {
- notify($post->error);
- }
- echo '</center>';
if ($USER->id != $post->userid) { // Not the original author, so add a message to the end
$data->date = userdate($post->modified);
}
}
- print_simple_box_start("center");
- require("post.html");
- print_simple_box_end();
+ //load data into form
+ $subscribe=(isset($post->forum)&&forum_is_subscribed($USER->id, $post->forum)) ||
+ (!empty($USER->autosubscribe));
+
+
+ $mform_post->set_defaults(array('general'=>$heading,
+ 'subject'=>$post->subject,
+ 'message'=>$post->message,
+ 'subscribe'=>$subscribe?1:0,
+ 'mailnow'=>!empty($post->mailnow),
+ 'userid'=>$post->userid,
+ 'parent'=>$post->parent,
+ 'discussion'=>$post->discussion,
+ 'course'=>$course->id)+
+
+ $page_params+
+
+ (isset($post->format)?array(
+ 'format'=>$post->format):
+ array())+
+
+ (isset($post->groupid)?array(
+ 'groupid'=>$post->groupid):
+ array())+
+
+ (isset($discussion->timestart)?
+ array('timestart'=>$discussion->timestart):
+ array('timestart'=>0))+
+
+ (isset($discussion->timeend)?
+ array('timeend'=>$discussion->timeend):
+ array('timeend'=>0))+
+
+ (isset($discussion->timestartdisabled)?
+ array('timestartdisabled'=>$discussion->timestartdisabled):
+ array('timestartdisabled'=>1))+
+
+ (isset($discussion->timeenddisabled)?
+ array('timeenddisabled'=>$discussion->timeenddisabled):
+ array('timeenddisabled'=>1))+
+
+ (isset($discussion->id)?
+ array('discussion'=>$discussion->id):
+ array()));
+
+ $mform_post->trusttext_prepare_edit('message', 'format', $modcontext);
+
+ $mform_post->display();
- if ($usehtmleditor) {
- use_html_editor("message");
- }
print_footer($course);