From 41547057cc0283f999a5f7d0083f96379bb28441 Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Thu, 19 Jan 2006 23:52:08 +0000 Subject: [PATCH] Merged Patrick's mailnow patch. This allows admin users the ability to override maxediting time and have forum posts mailed out immediately. --- lang/en/forum.php | 2 ++ mod/forum/backuplib.php | 1 + mod/forum/db/mysql.php | 4 ++++ mod/forum/db/mysql.sql | 1 + mod/forum/db/postgres7.php | 4 ++++ mod/forum/db/postgres7.sql | 3 ++- mod/forum/lib.php | 6 ++++-- mod/forum/post.html | 11 +++++++++++ mod/forum/post.php | 11 +++++++++++ mod/forum/restorelib.php | 1 + mod/forum/version.php | 2 +- 11 files changed, 42 insertions(+), 4 deletions(-) diff --git a/lang/en/forum.php b/lang/en/forum.php index e2ae7f28027..7a66e3532da 100644 --- a/lang/en/forum.php +++ b/lang/en/forum.php @@ -85,6 +85,7 @@ $string['introsocial'] = 'An open forum for chatting about anything you want to' $string['introteacher'] = 'A forum for teacher-only notes and discussion'; $string['lastpost'] = 'Last post'; $string['learningforums'] = 'Learning forums'; +$string['mailnow'] = 'Mail now'; $string['markalldread'] = 'Mark all posts in this discussion read.'; $string['markallread'] = 'Mark all posts in this forum read.'; $string['markread'] = 'Mark read'; @@ -142,6 +143,7 @@ $string['postincontext'] = 'See this post in context'; $string['postmailinfo'] = 'This is a copy of a message posted on the $a website. To add your reply via the website, click on this link:'; +$string['postmailnow'] = '

This post will be mailed out immediately to all forum subscribers.

'; $string['postrating1'] = 'Mostly Separate Knowing'; $string['postrating2'] = 'Separate and Connected'; $string['postrating3'] = 'Mostly Connected Knowing'; diff --git a/mod/forum/backuplib.php b/mod/forum/backuplib.php index 1dfc2f407f4..06f4f51dc01 100644 --- a/mod/forum/backuplib.php +++ b/mod/forum/backuplib.php @@ -268,6 +268,7 @@ fwrite ($bf,full_tag("FORMAT",8,false,$for_pos->format)); fwrite ($bf,full_tag("ATTACHMENT",8,false,$for_pos->attachment)); fwrite ($bf,full_tag("TOTALSCORE",8,false,$for_pos->totalscore)); + fwrite ($bf,full_tag("MAILNOW",8,false,$for_pos->mailnow)); //Now print ratings to xml $status = backup_forum_ratings($bf,$preferences,$for_pos->id); diff --git a/mod/forum/db/mysql.php b/mod/forum/db/mysql.php index 4b2fac97aaa..85a0499149e 100644 --- a/mod/forum/db/mysql.php +++ b/mod/forum/db/mysql.php @@ -220,6 +220,10 @@ function forum_upgrade($oldversion) { table_column('forum','','blockperiod'); } + if ($oldversion < 2006011700) { + table_column('forum_posts','','mailnow','integer'); + } + return true; } diff --git a/mod/forum/db/mysql.sql b/mod/forum/db/mysql.sql index 490ea97bd0d..d83197149e9 100644 --- a/mod/forum/db/mysql.sql +++ b/mod/forum/db/mysql.sql @@ -69,6 +69,7 @@ CREATE TABLE prefix_forum_posts ( format tinyint(2) NOT NULL default '0', attachment VARCHAR(100) NOT NULL default '', totalscore tinyint(4) NOT NULL default '0', + mailnow int(10) unsigned NOT NULL default '0', PRIMARY KEY (id), KEY prefix_forum_posts_parent_idx (parent), KEY prefix_forum_posts_discussion_idx (discussion), diff --git a/mod/forum/db/postgres7.php b/mod/forum/db/postgres7.php index 8bec1be6117..f91bb088bae 100644 --- a/mod/forum/db/postgres7.php +++ b/mod/forum/db/postgres7.php @@ -166,6 +166,10 @@ function forum_upgrade($oldversion) { table_column('forum','','blockperiod'); } + if ($oldversion < 2006011700) { + table_column('forum_posts','','mailnow','integer'); + } + return true; } diff --git a/mod/forum/db/postgres7.sql b/mod/forum/db/postgres7.sql index 3a5d13d28d5..3059afc93b8 100644 --- a/mod/forum/db/postgres7.sql +++ b/mod/forum/db/postgres7.sql @@ -68,7 +68,8 @@ CREATE TABLE prefix_forum_posts ( message text NOT NULL default '', format integer NOT NULL default '0', attachment VARCHAR(100) NOT NULL default '', - totalscore integer NOT NULL default '0' + totalscore integer NOT NULL default '0', + mailnow integer NOT NULL default '0' ); CREATE INDEX prefix_forum_posts_discussion_idx ON prefix_forum_posts (discussion); diff --git a/mod/forum/lib.php b/mod/forum/lib.php index bda660ea3ee..fa7e6dc9504 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -115,6 +115,7 @@ function forum_add_instance($forum) { $discussion->intro = $forum->intro; $discussion->assessed = $forum->assessed; $discussion->format = $forum->format; + $discussion->mailnow = false; if (! forum_add_discussion($discussion, $discussion->intro)) { error('Could not add the discussion for this forum'); @@ -1205,7 +1206,7 @@ function forum_get_unmailed_posts($starttime, $endtime) { {$CFG->prefix}forum_discussions d WHERE p.mailed = 0 AND (p.created >= '$starttime' OR d.timestart > 0) - AND p.created < '$endtime' + AND (p.created < '$endtime' OR p.mailnow = 1) AND p.discussion = d.id AND ((d.timestart = 0 OR d.timestart <= '$now') AND (d.timeend = 0 OR d.timeend > '$now')) @@ -1233,7 +1234,7 @@ function forum_mark_old_posts_as_mailed($endtime) { } return execute_sql("UPDATE {$CFG->prefix}forum_posts SET mailed = '1' - WHERE id NOT IN (".implode(',',$delayed_ids).") AND created < '$endtime' AND mailed ='0'"); + WHERE id NOT IN (".implode(',',$delayed_ids).") AND (created < '$endtime' OR mailnow = 1) AND mailed ='0'"); } function forum_get_user_posts($forumid, $userid) { @@ -2517,6 +2518,7 @@ function forum_add_discussion($discussion,&$message) { $post->forum = $discussion->forum; $post->course = $discussion->course; $post->format = $discussion->format; + $post->mailnow = $discussion->mailnow; if (! $post->id = insert_record("forum_posts", $post) ) { return 0; diff --git a/mod/forum/post.html b/mod/forum/post.html index 78d65143b9a..c085f2d5b67 100644 --- a/mod/forum/post.html +++ b/mod/forum/post.html @@ -102,6 +102,17 @@ if (!isset($discussion->timeend)) { +id)) { ?> + + + : + mailnow)); ?> + + + + + + type == 'news' && !$post->parent) { // This is the first post of a discussion in news forum ?> diff --git a/mod/forum/post.php b/mod/forum/post.php index 8476e082997..9976c87642d 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -165,6 +165,11 @@ $timemessage = 4; } + if ($post->mailnow) { + $message .= get_string("postmailnow", "forum"); + $timemessage = 4; + } + redirect(forum_go_back_to("discuss.php?d=$post->discussion#$post->id"), $message.$subscribemessage, $timemessage); } else { @@ -173,6 +178,7 @@ exit; } else { // Adding a new discussion + $post->mailnow = empty($post->mailnow) ? 0 : 1; $discussion = $post; $discussion->name = $post->subject; $discussion->intro = $post->message; @@ -206,6 +212,11 @@ } $message .= '
'.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; } diff --git a/mod/forum/restorelib.php b/mod/forum/restorelib.php index dbb1323dacc..b0acc8942ae 100644 --- a/mod/forum/restorelib.php +++ b/mod/forum/restorelib.php @@ -402,6 +402,7 @@ $post->format = backup_todb($pos_info['#']['FORMAT']['0']['#']); $post->attachment = backup_todb($pos_info['#']['ATTACHMENT']['0']['#']); $post->totalscore = backup_todb($pos_info['#']['TOTALSCORE']['0']['#']); + $post->mailnow = backup_todb($pos_info['#']['MAILNOW']['0']['#']); //We have to recode the userid field $user = backup_getid($restore->backup_unique_code,"user",$post->userid); diff --git a/mod/forum/version.php b/mod/forum/version.php index bbf80d0009f..ce9a521651d 100644 --- a/mod/forum/version.php +++ b/mod/forum/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2006011601; +$module->version = 2006011700; $module->requires = 2005031000; // Requires this Moodle version $module->cron = 60;