997 lines
32 KiB
PHP
997 lines
32 KiB
PHP
<?php
|
|
|
|
/*
|
|
+--------------------------------------------------------------------------
|
|
| Invision Power Board v2.0.0
|
|
| =============================================
|
|
| by Matthew Mecham
|
|
| (c) 2001 - 2004 Invision Power Services, Inc.
|
|
| http://www.invisionpower.com
|
|
| =============================================
|
|
| Web: http://www.invisionboard.com
|
|
| Time: Tue, 21 Sep 2004 16:34:28 GMT
|
|
| Release: 150aa7a702c3c8b6f6eb90ad49305d2f
|
|
| Licence Info: http://www.invisionboard.com/?license
|
|
+---------------------------------------------------------------------------
|
|
|
|
|
| > POST OFFICE Stuff
|
|
| > Module written by Matt Mecham
|
|
| > Date started: 1st April 2004 (April Fools!)
|
|
|
|
|
| > Module Version Number: 1.0.0
|
|
| > DBA Checked: Tue 25th May 2004
|
|
+--------------------------------------------------------------------------
|
|
*/
|
|
|
|
|
|
if ( ! defined( 'IN_ACP' ) )
|
|
{
|
|
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
|
|
exit();
|
|
}
|
|
|
|
|
|
class ad_postoffice
|
|
{
|
|
var $base_url;
|
|
var $colours = array();
|
|
var $root_path = './';
|
|
|
|
function auto_run()
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
$ibforums->admin->nav[] = array( 'act=postoffice', 'IPB Post Office' );
|
|
|
|
$ibforums->admin->page_detail = "You may manage previous bulk emails and create new bulk emails in this section.";
|
|
$ibforums->admin->page_title = "IPB Post Office";
|
|
|
|
//-----------------------------------------
|
|
// Kill globals - globals bad, Homer good.
|
|
//-----------------------------------------
|
|
|
|
$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
|
|
|
|
foreach ( $tmp_in as $k => $v )
|
|
{
|
|
unset($$k);
|
|
}
|
|
|
|
switch($ibforums->input['code'])
|
|
{
|
|
case 'mail_new':
|
|
$this->mail_form('add');
|
|
break;
|
|
case 'mail_edit':
|
|
$this->mail_form('edit');
|
|
break;
|
|
case 'mail_save':
|
|
$this->mail_save();
|
|
break;
|
|
case 'mail_preview':
|
|
$this->mail_preview_start();
|
|
break;
|
|
case 'mail_preview_do':
|
|
$this->mail_preview_complete();
|
|
break;
|
|
case 'mail_send_start':
|
|
$this->mail_send_start();
|
|
break;
|
|
case 'mail_send_complete':
|
|
$this->mail_send_complete();
|
|
break;
|
|
case 'mail_send_cancel':
|
|
$this->mail_send_cancel();
|
|
break;
|
|
case 'mail_delete':
|
|
$this->mail_delete();
|
|
break;
|
|
//-----------------------------------------
|
|
// Default
|
|
//-----------------------------------------
|
|
|
|
default:
|
|
$this->mail_start();
|
|
break;
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// DELETE MAIL - WOT IS SAYZ ON TEH TIN
|
|
//-----------------------------------------
|
|
|
|
function mail_delete()
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
$id = intval( $ibforums->input['id'] );
|
|
|
|
$DB->do_update( 'bulk_mail', array( 'mail_active' => 0,
|
|
'mail_updated' => time(),
|
|
), "mail_active=1" );
|
|
|
|
$DB->do_update( 'task_manager', array( 'task_enabled' => 0 ), "task_key='bulkmail'" );
|
|
|
|
$DB->simple_exec_query( array( 'delete' => 'bulk_mail', 'where' => 'mail_id='.$id ) );
|
|
|
|
$ibforums->main_msg = "Bulk email deleted";
|
|
$this->mail_start();
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// SEND MAIL: Cancel sending in progress
|
|
//-----------------------------------------
|
|
|
|
function mail_send_cancel()
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
$DB->do_update( 'bulk_mail', array( 'mail_active' => 0,
|
|
'mail_updated' => time(),
|
|
), "mail_active=1" );
|
|
|
|
$DB->do_update( 'task_manager', array( 'task_enabled' => 0 ), "task_key='bulkmail'" );
|
|
|
|
$ibforums->main_msg = "Bulk email cancelled";
|
|
$this->mail_start();
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// SEND MAIL: Send the mail mah-boy
|
|
//-----------------------------------------
|
|
|
|
function mail_send_process( $root_path="" )
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
//-----------------------------------------
|
|
// Set up
|
|
//-----------------------------------------
|
|
|
|
if ( $root_path )
|
|
{
|
|
$this->root_path = $root_path;
|
|
}
|
|
else if ( ROOT_PATH )
|
|
{
|
|
$this->root_path = ROOT_PATH;
|
|
}
|
|
|
|
require_once( $this->root_path."sources/classes/class_email.php");
|
|
|
|
$this->email = new emailer( $this->root_path );
|
|
|
|
$done = 0;
|
|
$sent = 0;
|
|
|
|
//-----------------------------------------
|
|
// Get it from the db
|
|
//-----------------------------------------
|
|
|
|
$mail = $DB->simple_exec_query( array( 'select' => '*', 'from' => 'bulk_mail', 'where' => 'mail_active=1' ) );
|
|
|
|
if ( ! $mail['mail_subject'] and ! $mail['mail_content'] )
|
|
{
|
|
$done = 1;
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// Per go...
|
|
//-----------------------------------------
|
|
|
|
$pergo = intval($mail['mail_pergo']);
|
|
|
|
if ( ! $pergo or $pergo > 1000 )
|
|
{
|
|
$pergo = 50;
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// So far...
|
|
//-----------------------------------------
|
|
|
|
$sofar = intval($mail['mail_sentto']);
|
|
|
|
$mail['mail_content'] = $std->txt_stripslashes( $mail['mail_content'] );
|
|
$mail['mail_subject'] = $std->txt_stripslashes( $mail['mail_subject'] );
|
|
|
|
//-----------------------------------------
|
|
// Unconvert options
|
|
//-----------------------------------------
|
|
|
|
$opts = unserialize(stripslashes( $mail['mail_opts'] ) );
|
|
|
|
foreach( $opts as $k => $v )
|
|
{
|
|
$mail[ $k ] = $v;
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// Format the query
|
|
//-----------------------------------------
|
|
|
|
$query = $this->_build_members_query( $mail );
|
|
|
|
//-----------------------------------------
|
|
// Get members....
|
|
//-----------------------------------------
|
|
|
|
$DB->simple_construct( array( 'select' => '*',
|
|
'from' => 'members',
|
|
'where' => $query,
|
|
'order' => 'id',
|
|
'limit' => array( $sofar, $pergo ) ) );
|
|
|
|
$o = $DB->simple_exec();
|
|
|
|
if ( $mail['mail_html_on'] )
|
|
{
|
|
$this->email->html_email = 1;
|
|
}
|
|
|
|
while ( $r = $DB->fetch_row( $o ) )
|
|
{
|
|
$sent++;
|
|
|
|
$contents = $this->_convert_quick_tags( $mail['mail_content'], $r );
|
|
|
|
$this->email->from = $ibforums->vars['email_in'];
|
|
$this->email->to = $r['email'];
|
|
$this->email->message = str_replace( "\r\n", "\n", $contents);
|
|
$this->email->subject = $mail['mail_subject'];
|
|
|
|
$this->email->send_mail();
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// Did we send any?
|
|
//-----------------------------------------
|
|
|
|
if ( ! $sent )
|
|
{
|
|
$done = 1;
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// Save out..
|
|
//-----------------------------------------
|
|
|
|
if ( $done )
|
|
{
|
|
$DB->do_update( 'bulk_mail', array( 'mail_active' => 0,
|
|
'mail_updated' => time(),
|
|
'mail_sentto' => $sofar + $sent ), 'mail_id='.$mail['mail_id'] );
|
|
|
|
$DB->do_update( 'task_manager', array( 'task_enabled' => 0 ), "task_key='bulkmail'" );
|
|
}
|
|
else
|
|
{
|
|
$DB->do_update( 'bulk_mail', array( 'mail_updated' => time(),
|
|
'mail_sentto' => $sofar + $sent ), 'mail_id='.$mail['mail_id'] );
|
|
}
|
|
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// SEND MAIL: Complete
|
|
//-----------------------------------------
|
|
|
|
function mail_send_complete()
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
$pergo = intval($ibforums->input['pergo']);
|
|
$id = intval($ibforums->input['id']);
|
|
|
|
if ( ! $id )
|
|
{
|
|
$ibforums->main_msg = "There was no ID passed to this function";
|
|
$this->mail_start();
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// Get it from the db
|
|
//-----------------------------------------
|
|
|
|
$mail = $DB->simple_exec_query( array( 'select' => '*', 'from' => 'bulk_mail', 'where' => 'mail_id='.$id ) );
|
|
|
|
if ( ! $mail['mail_subject'] and ! $mail['mail_content'] )
|
|
{
|
|
$ibforums->main_msg = "Cannot send - the email doesn't have a subject and content";
|
|
$this->mail_start();
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// Update mail
|
|
//-----------------------------------------
|
|
|
|
if ( ! $pergo or $pergo > 1000 )
|
|
{
|
|
$pergo = 50;
|
|
}
|
|
|
|
$DB->do_update( 'bulk_mail', array( 'mail_active' => 1, 'mail_pergo' => $pergo, 'mail_sentto' => 0, 'mail_start' => time() ), 'mail_id='.$id );
|
|
$DB->do_update( 'bulk_mail', array( 'mail_active' => 0 ) , 'mail_id != '.$id );
|
|
|
|
//-----------------------------------------
|
|
// Wake up task manager
|
|
//-----------------------------------------
|
|
|
|
require_once( ROOT_PATH.'sources/lib/task_functions.php' );
|
|
$task = new task_functions();
|
|
|
|
$DB->do_update( 'task_manager', array( 'task_enabled' => 1 ), "task_key='bulkmail'" );
|
|
|
|
$this_task = $DB->simple_exec_query( array( 'select' => '*', 'from' => 'task_manager', 'where' => "task_key='bulkmail'" ) );
|
|
$newdate = $task->generate_next_run($this_task);
|
|
|
|
$DB->do_update( 'task_manager', array( 'task_next_run' => $newdate ), "task_id=".$this_task['task_id'] );
|
|
|
|
$task->save_next_run_stamp();
|
|
|
|
//-----------------------------------------
|
|
// Sit back and watch the show
|
|
//-----------------------------------------
|
|
|
|
$ibforums->main_msg = "Bulk Mail Initiated";
|
|
|
|
$this->mail_start();
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// SEND MAIL: Start
|
|
//-----------------------------------------
|
|
|
|
function mail_send_start()
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
$id = intval($ibforums->input['id']);
|
|
|
|
if ( ! $id )
|
|
{
|
|
$ibforums->main_msg = "There was no ID passed to this function";
|
|
$this->mail_start();
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// Get it from the db
|
|
//-----------------------------------------
|
|
|
|
$mail = $DB->simple_exec_query( array( 'select' => '*', 'from' => 'bulk_mail', 'where' => 'mail_id='.$id ) );
|
|
|
|
if ( ! $mail['mail_subject'] and ! $mail['mail_content'] )
|
|
{
|
|
$ibforums->main_msg = "Cannot send - the email doesn't have a subject and content";
|
|
$this->mail_start();
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// Unconvert options
|
|
//-----------------------------------------
|
|
|
|
$opts = unserialize(stripslashes( $mail['mail_opts'] ) );
|
|
|
|
foreach( $opts as $k => $v )
|
|
{
|
|
$mail[ $k ] = $v;
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// Format the query
|
|
//-----------------------------------------
|
|
|
|
$query = $this->_build_members_query( $mail );
|
|
|
|
//-----------------------------------------
|
|
// Count how many matches
|
|
//-----------------------------------------
|
|
|
|
$count = $DB->simple_exec_query( array( 'select' => 'count(*) as cnt', 'from' => 'members', 'where' => $query ) );
|
|
|
|
$the_count = intval( $count['cnt'] );
|
|
|
|
//-----------------------------------------
|
|
// Print 'continue' screen
|
|
//-----------------------------------------
|
|
|
|
$ibforums->html .= $ibforums->adskin->start_form( array( 1 => array( 'code' , 'mail_send_complete' ),
|
|
2 => array( 'act' , 'postoffice' ),
|
|
4 => array( 'id' , $ibforums->input['id'] ),
|
|
) );
|
|
|
|
$ibforums->html .= "<div class='tableborder'><div class='maintitle'>Sending the bulk mail to {$the_count} members</div>";
|
|
$ibforums->html .= "<div class='tdrow2' style='padding:4px'>
|
|
<fieldset>
|
|
<legend><strong>Email Details</strong></legend>
|
|
<strong>Subject: {$mail['mail_subject']}</strong>
|
|
<br />
|
|
<br />
|
|
<div style='height:200px;overflow:auto;white-space:pre'>{$mail['mail_content']}</div>
|
|
<br />
|
|
<div align='center'><span class='fauxbutton'><a href='{$ibforums->base_url}&act=postoffice&code=mail_edit&id={$id}'>Edit This Email</a></span></div>
|
|
<br />
|
|
Sending to <b>{$the_count}</b> members.
|
|
</fieldset>
|
|
<br />
|
|
<fieldset>
|
|
<legend><strong>Sending the Email</strong></legend>
|
|
Clicking the 'Start Sending The Emails' button below will activate the task manager's send bulk email function which will send the email in batches until the all the mail
|
|
has been sent. You can watch the progress from the main Post Office screen and cancel the email from being sent.
|
|
<br />
|
|
We strongly recommend that you opt to send 50 emails per cycle as a maximum. Any more per cycle could severly affect performance of your server while the mail is being sent out.
|
|
<br />
|
|
<br />
|
|
As the mail is sent out in cycles of <em><b>n</b></em> per minute, it can take a while to process all the mail.
|
|
<br />
|
|
<br />
|
|
<div align='center'><b>Emails sent per cycle</b> <input type='text' class='realbutton' size='5' name='pergo' value='50' /> <input type='submit' value='Start Sending The Emails' class='realbutton' /></form></div>
|
|
</fieldset>
|
|
</div>
|
|
</div>";
|
|
|
|
$ibforums->admin->output();
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// PREVIEW MAIL: Show it - yo!
|
|
//-----------------------------------------
|
|
|
|
function mail_preview_complete()
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
$content = nl2br($this->_convert_quick_tags( $std->txt_stripslashes($_POST['text']), $ibforums->member ));
|
|
|
|
print "<html>
|
|
<body>
|
|
<div style='padding:6px;text-align:left;font-family:courier, monospace;font-size:12px'>
|
|
{$content}
|
|
</body></html>
|
|
";
|
|
|
|
exit();
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// PREVIEW MAIL: JS BOUNCE
|
|
//-----------------------------------------
|
|
|
|
function mail_preview_start()
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
print "<html><body onload='doitdude()'><script type='text/javascript'>
|
|
posty = opener.thisval;
|
|
function doitdude()
|
|
{
|
|
document.peekaboo.method = 'post';
|
|
document.peekaboo.action = '{$ibforums->base_url}&act=postoffice&code=mail_preview_do';
|
|
document.peekaboo.text.value = posty;
|
|
document.peekaboo.submit();
|
|
}
|
|
</script>
|
|
<form name='peekaboo' >
|
|
<input type='hidden' name='text' />
|
|
</form>
|
|
</body></html>
|
|
";
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// SAVE MAIL
|
|
//-----------------------------------------
|
|
|
|
function mail_save()
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
//-----------------------------------------
|
|
// Set up
|
|
//-----------------------------------------
|
|
|
|
$ids = array();
|
|
$ibforums->input['id'] = intval($ibforums->input['id']);
|
|
|
|
//-----------------------------------------
|
|
// Start
|
|
//-----------------------------------------
|
|
|
|
$type = $ibforums->input['type'];
|
|
|
|
if ( ! $ibforums->input['mail_subject'] or ! $ibforums->input['mail_content'] )
|
|
{
|
|
$ibforums->main_msg = "You must enter an email subject and email content before submitting.";
|
|
$this->mail_form( $type );
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// Groups...
|
|
//-----------------------------------------
|
|
|
|
foreach ($ibforums->input as $key => $value)
|
|
{
|
|
if ( preg_match( "/^sg_(\d+)$/", $key, $match ) )
|
|
{
|
|
if ($ibforums->input[ $match[0] ])
|
|
{
|
|
$ids[] = $match[1];
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( ! count( $ids ) )
|
|
{
|
|
$ibforums->main_msg = "You must select at least one group to send this email message to.";
|
|
$this->mail_form( $type );
|
|
}
|
|
|
|
$ibforums->input['mail_groups'] = implode( ",", $ids );
|
|
|
|
//-----------------------------------------
|
|
// Format the query
|
|
//-----------------------------------------
|
|
|
|
$query = $this->_build_members_query( array( 'mail_post_ltmt' => $_POST['mail_post_ltmt'],
|
|
'mail_filter_post' => $_POST['mail_filter_post'],
|
|
'mail_visit_ltmt' => $_POST['mail_visit_ltmt'],
|
|
'mail_filter_visit' => $_POST['mail_filter_visit'],
|
|
'mail_joined_ltmt' => $_POST['mail_joined_ltmt'],
|
|
'mail_filter_joined' => $_POST['mail_filter_joined'],
|
|
'mail_honor' => $_POST['mail_honor'],
|
|
'group_id_string' => implode( ",", $ids )
|
|
) );
|
|
|
|
//-----------------------------------------
|
|
// Count how many matches
|
|
//-----------------------------------------
|
|
|
|
$count = $DB->simple_exec_query( array( 'select' => 'count(*) as cnt', 'from' => 'members', 'where' => $query ) );
|
|
|
|
if ( ! $count['cnt'] )
|
|
{
|
|
$ibforums->main_msg = "Your criteria didn't match any members - please adjust your current criteria";
|
|
$this->mail_form( $type );
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// Save
|
|
//-----------------------------------------
|
|
|
|
$save_array = array(
|
|
'mail_subject' => str_replace( "'", "'", $std->txt_stripslashes( $_POST['mail_subject'] ) ),
|
|
'mail_content' => $std->txt_stripslashes( $_POST['mail_content'] ),
|
|
'mail_groups' => implode( ",", $ids ),
|
|
'mail_honor' => $ibforums->input['mail_honor'],
|
|
'mail_start' => time(),
|
|
'mail_updated' => time(),
|
|
'mail_sentto' => 0,
|
|
'mail_opts' => serialize( array( 'mail_post_ltmt' => $_POST['mail_post_ltmt'],
|
|
'mail_filter_post' => $_POST['mail_filter_post'],
|
|
'mail_visit_ltmt' => $_POST['mail_visit_ltmt'],
|
|
'mail_filter_visit' => $_POST['mail_filter_visit'],
|
|
'mail_joined_ltmt' => $_POST['mail_joined_ltmt'],
|
|
'mail_filter_joined' => $_POST['mail_filter_joined'],
|
|
'mail_html_on' => $_POST['mail_html_on'],
|
|
) )
|
|
);
|
|
|
|
if ( $type == 'add' )
|
|
{
|
|
//-----------------------------------------
|
|
// Save to DB
|
|
//-----------------------------------------
|
|
|
|
$DB->do_insert( 'bulk_mail', $save_array );
|
|
|
|
$ibforums->input['id'] = $DB->get_insert_id();
|
|
|
|
$ibforums->admin->save_log("Bulk mail ({$ibforums->input['mail_subject']}) added");
|
|
$this->mail_send_start();
|
|
}
|
|
else
|
|
{
|
|
if ( ! $ibforums->input['id'] )
|
|
{
|
|
$ibforums->main_msg = "Cannot save, no ID returned";
|
|
$this->mail_form($type);
|
|
}
|
|
|
|
$DB->do_update( 'bulk_mail', $save_array, 'mail_id='.$ibforums->input['id'] );
|
|
|
|
$ibforums->admin->save_log("Bulk mail ({$ibforums->input['mail_subject']}) edited");
|
|
|
|
$ibforums->main_msg = "Bulk mail edited";
|
|
$this->mail_start();
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// SHOW MAIN MAIL SCREENIE-POOS
|
|
//-----------------------------------------
|
|
|
|
function mail_form($type='add')
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
$ibforums->input['id'] = intval($ibforums->input['id']);
|
|
|
|
$dd_ltmt = array(
|
|
0 => array( 'lt' , "less than" ),
|
|
1 => array( 'mt' , "more than" )
|
|
);
|
|
|
|
if ( $type == 'add' )
|
|
{
|
|
$mail = array();
|
|
$title = "Step 1: Start New Bulk Email";
|
|
$button = "Proceed...";
|
|
$honour_checked = 'checked="checked"';
|
|
$html_checked = '';
|
|
}
|
|
else
|
|
{
|
|
$mail = $DB->simple_exec_query( array( 'select' => '*', 'from' => 'bulk_mail', 'where' => 'mail_id='.$ibforums->input['id'] ) );
|
|
$title = "Editing Stored Mail";
|
|
$button = "Edit Mail";
|
|
|
|
//-----------------------------------------
|
|
// Unpack more..
|
|
//-----------------------------------------
|
|
|
|
$tmp = unserialize( stripslashes( $mail['mail_opts'] ) );
|
|
|
|
if ( is_array( $tmp ) and count ( $tmp ) )
|
|
{
|
|
foreach( $tmp as $k => $v )
|
|
{
|
|
if ( ! $mail[ $k ] )
|
|
{
|
|
$mail[ $k ] = $v;
|
|
}
|
|
}
|
|
}
|
|
|
|
$honour_checked = $mail['mail_honor'] == 1 ? 'checked="checked"' : '';
|
|
$html_checked = $mail['mail_html_on'] == 1 ? 'checked="checked"' : '';
|
|
|
|
}
|
|
|
|
$ibforums->html .= $ibforums->adskin->start_form( array( 1 => array( 'code' , 'mail_save' ),
|
|
2 => array( 'act' , 'postoffice' ),
|
|
3 => array( 'type' , $type ),
|
|
4 => array( 'id' , $ibforums->input['id'] ),
|
|
) );
|
|
|
|
$mail_subject = $_POST['mail_subject'] ? $std->txt_stripslashes($_POST['mail_subject']) : $mail['mail_subject'];
|
|
$mail_content = $_POST['mail_content'] ? $std->txt_stripslashes($_POST['mail_content']) : $mail['mail_content'];
|
|
$mail_subject = str_replace( "'", "'", $mail_subject );
|
|
|
|
$mail_content = preg_replace( "[^\r]\n", "\r\n", $mail_content );
|
|
|
|
if ( ! $mail_content and $type == 'add' )
|
|
{
|
|
$mail_content = $this->_get_default_mail_contents();
|
|
}
|
|
|
|
if ( $ibforums->input['mail_groups'] )
|
|
{
|
|
$mail['mail_groups'] = $ibforums->input['mail_groups'];
|
|
}
|
|
|
|
$ibforums->html .= "<script type='text/javascript'>
|
|
function runpreview()
|
|
{
|
|
thisval = document.theAdminForm.mail_content.value
|
|
myWin = window.open('{$ibforums->base_url}&act=postoffice&code=mail_preview','newWin','width=500,height=500,resizable=yes,scrollbars=yes');
|
|
}
|
|
</script>
|
|
";
|
|
|
|
$ibforums->html .= "<div class='tableborder'><div class='maintitle'>{$title}</div>";
|
|
$ibforums->html .= "<div class='tdrow2' style='padding:4px'>
|
|
<fieldset>
|
|
<legend><strong>Email Subject</strong></legend>
|
|
<input type='text' size='60' maxsize='250' class='textinput' style='width:100%' name='mail_subject' value='{$mail_subject}' />
|
|
</fieldset>
|
|
<br />
|
|
<fieldset>
|
|
<legend><strong>Email Content</strong></legend>
|
|
<textarea cols='60' rows='20' class='textinput' style='width:100%' name='mail_content'>{$mail_content}</textarea>
|
|
<br />
|
|
<fieldset>
|
|
<legend><strong>Mail Sending Options</strong></legend>
|
|
<input type='checkbox' name='mail_honor' value='1' {$honour_checked} /> Honor 'Allow admin to email me' member setting to only email those who have opted in?
|
|
<br/ >
|
|
<input type='checkbox' name='mail_html_on' value='1' {$html_checked} /> Send email in HTML format (full HTML formatting & tags allowed)
|
|
</fieldset>
|
|
</fieldset>";
|
|
|
|
$ibforums->html .= "</div></div><br />";
|
|
|
|
$ibforums->html .= "<div class='tableborder'><div class='maintitle'>Filters</div>";
|
|
$ibforums->html .= "<div class='tdrow2' style='padding:4px'>
|
|
<table width='100%' cellpadding='2' cellspacing='0' border='0'>
|
|
<tr>
|
|
<td width='30%'>
|
|
<fieldset>
|
|
<legend><strong>Send to Groups:</strong></legend>";
|
|
|
|
foreach( $ibforums->cache['group_cache'] as $bleh => $g )
|
|
{
|
|
if ( $g['g_id'] == $ibforums->vars['guest_group'] )
|
|
{
|
|
continue;
|
|
}
|
|
|
|
$checked = "";
|
|
|
|
if ( $mail['mail_groups'] )
|
|
{
|
|
if ( strstr( ','.$mail['mail_groups'].',', ','.$g['g_id'].',' ) )
|
|
{
|
|
$checked = 'checked="checked"';
|
|
}
|
|
}
|
|
|
|
$ibforums->html .= "<input type='checkbox' name='sg_{$g['g_id']}' value='1' $checked /> <b>{$g['g_title']}</b><br />";
|
|
}
|
|
|
|
$ibforums->html .= " </fieldset>
|
|
</td>
|
|
<td width='70%' valign='top'>
|
|
<fieldset>
|
|
<legend><strong>Additional Filters</strong></legend>
|
|
<table width='100%' cellpadding='4' cellspacing='0' border='0'>
|
|
<tr>
|
|
<td width='60%'>Send to members with <em><b>n</b></em> posts<div class='graytext'>Leave blank to not filter</div></td>
|
|
<td width='40%'>". $ibforums->adskin->form_dropdown('mail_post_ltmt', $dd_ltmt, $_POST['mail_post_ltml'] ? $_POST['mail_post_ltml'] : $mail['mail_post_ltmt'] ).' '.
|
|
$ibforums->adskin->form_simple_input( "mail_filter_post", $_POST['mail_filter_post'] ? $_POST['mail_filter_post'] : $mail['mail_filter_post'], 7 )."</td>
|
|
</tr>
|
|
<tr>
|
|
<td width='60%'>Send to members who's last visit was <em><b>n</b></em> days ago<div class='graytext'>Leave blank to not filter</div></td>
|
|
<td width='40%'>". $ibforums->adskin->form_dropdown('mail_visit_ltmt', $dd_ltmt, $_POST['mail_visit_ltml'] ? $_POST['mail_visit_ltml'] : $mail['mail_visit_ltmt'] ).' '.
|
|
$ibforums->adskin->form_simple_input( "mail_filter_visit", $_POST['mail_filter_visit'] ? $_POST['mail_filter_visit'] : $mail['mail_filter_visit'], 7 )."</td>
|
|
</tr>
|
|
<tr>
|
|
<td width='60%'>Send to members who joined <em><b>n</b></em> days ago<div class='graytext'>Leave blank to not filter</div></td>
|
|
<td width='40%'>". $ibforums->adskin->form_dropdown('mail_joined_ltmt', $dd_ltmt, $_POST['mail_joined_ltml'] ? $_POST['mail_joined_ltml'] : $mail['mail_joined_ltmt'] ).' '.
|
|
$ibforums->adskin->form_simple_input( "mail_filter_joined", $_POST['mail_filter_joined'] ? $_POST['mail_filter_joined'] : $mail['mail_filter_joined'], 7 )."</td>
|
|
</tr>
|
|
</table>
|
|
</fieldset>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div align='center' class='pformstrip'><input class='realbutton' onclick='runpreview()' type='button' value='Preview' /> <input class='realdarkbutton' type='submit' value='$button' /></form></div>
|
|
</div>";
|
|
|
|
$ibforums->html .= "<br />
|
|
<div class='tableborder'>
|
|
<div class='pformstrip'>Quick Tags</div>
|
|
<div class='tdrow1' style='padding:4px'>You may use the following 'quick tags' in your email and they will be converted when the email is sent.</div>
|
|
<table cellpadding='2' class='tdrow1' width='100%' cellspacing='0' border='0'>
|
|
<tr>
|
|
<td><strong>{board_name}</strong></td>
|
|
<td><em>The name of your board</em></td>
|
|
<td><strong>{board_url}</strong></td>
|
|
<td><em>The URL to your board</em></td>
|
|
</tr>
|
|
<tr>
|
|
<td><strong>{reg_total}</strong></td>
|
|
<td><em>The total number of registered members</em></td>
|
|
<td><strong>{total_posts}</strong></td>
|
|
<td><em>The total number of posts</em></td>
|
|
</tr>
|
|
<tr>
|
|
<td><strong>{busy_count}</strong></td>
|
|
<td><em>The most number of users online</em></td>
|
|
<td><strong>{busy_time}</strong></td>
|
|
<td><em>The time that the most number of members were online</em></td>
|
|
</tr>
|
|
<tr>
|
|
<td><strong>{member_id}</strong></td>
|
|
<td><em>The member ID of the email recipient</em></td>
|
|
<td><strong>{member_name}</strong></td>
|
|
<td><em>The member name of the email recipient</em></td>
|
|
</tr>
|
|
<tr>
|
|
<td><strong>{member_joined}</strong></td>
|
|
<td><em>The member join date of the email recipient</em></td>
|
|
<td><strong>{member_posts}</strong></td>
|
|
<td><em>The number of posts for the email recipient</em></td>
|
|
</tr>
|
|
</table>
|
|
</div>";
|
|
|
|
$ibforums->admin->output();
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// SHOW MAIN MAIL SCREENIE-POOS
|
|
//-----------------------------------------
|
|
|
|
function mail_start()
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
$ibforums->adskin->td_header[] = array( " " , "1%" );
|
|
$ibforums->adskin->td_header[] = array( "Subject" , "30%" );
|
|
$ibforums->adskin->td_header[] = array( "Sent On" , "15%" );
|
|
$ibforums->adskin->td_header[] = array( "Sent To" , "15%" );
|
|
$ibforums->adskin->td_header[] = array( "Time Taken" , "15%" );
|
|
$ibforums->adskin->td_header[] = array( "Options" , "25%" );
|
|
|
|
$ibforums->html .= $ibforums->adskin->start_table( "Your stored bulk email" );
|
|
|
|
//-----------------------------------------
|
|
// Get mail from DB
|
|
//-----------------------------------------
|
|
|
|
$DB->simple_construct( array( 'select' => '*', 'from' => 'bulk_mail', 'order' => 'mail_start DESC' ) );
|
|
$DB->simple_exec();
|
|
|
|
while( $r = $DB->fetch_row() )
|
|
{
|
|
|
|
$inprogress = "";
|
|
|
|
if ( $r['mail_updated'] == $r['mail_start'] )
|
|
{
|
|
$time_taken = 'Not yet sent';
|
|
}
|
|
else
|
|
{
|
|
$time_taken = intval($r['mail_updated'] - $r['mail_start']);
|
|
|
|
if ( $time_taken < 0 )
|
|
{
|
|
$time_taken = 0;
|
|
}
|
|
|
|
if ( $time_taken )
|
|
{
|
|
$time_taken = ceil( $time_taken / 60 );
|
|
}
|
|
|
|
$time_taken .= ' minutes';
|
|
}
|
|
|
|
if ( $r['mail_active'] )
|
|
{
|
|
$inprogress = " <em>( Sending in progress - <a href='#' onclick=\"maincheckdelete('{$ibforums->base_url}&act=postoffice&code=mail_send_cancel', 'OK to cancel bulk mail?'); return false;\">Cancel</a> )</em>";
|
|
}
|
|
|
|
$ibforums->html .= $ibforums->adskin->add_td_row( array(
|
|
"<img src='{$ibforums->adskin->img_url}/skin_icon_email.gif' border='0' />",
|
|
"<b>{$r['mail_subject']}</b> $inprogress",
|
|
$std->get_date( $r['mail_start'], 'SHORT' ),
|
|
$std->do_number_format( $r['mail_sentto'] ).' members',
|
|
$time_taken,
|
|
"<div align='center'><span class='fauxbutton'><a href='{$ibforums->base_url}&act=postoffice&code=mail_send_start&id={$r['mail_id']}'>Re-send</a></span>
|
|
<span class='fauxbutton'><a href='{$ibforums->base_url}&act=postoffice&code=mail_edit&id={$r['mail_id']}'>Edit</a></span>
|
|
<span class='fauxbutton'><a href='#' onclick=\"maincheckdelete('{$ibforums->base_url}&act=postoffice&code=mail_delete&id={$r['mail_id']}');return false;\">Delete</a></span>
|
|
</center>"
|
|
) );
|
|
}
|
|
|
|
|
|
$ibforums->html .= $ibforums->adskin->end_table();
|
|
|
|
$ibforums->admin->output();
|
|
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// INTERNAL: build members query
|
|
//-----------------------------------------
|
|
|
|
function _build_members_query( $args = array() )
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
$DB->load_cache_file( $this->root_path.'sources/sql/'.SQL_DRIVER.'_extra_queries.php', 'sql_extra_queries' );
|
|
|
|
$query = array();
|
|
|
|
if ( $args['mail_filter_post'] )
|
|
{
|
|
$ltmt = $args['mail_post_ltmt'] == 'lt' ? '<' : '>';
|
|
$query[] = "posts ".$ltmt." ".$args['mail_filter_post'];
|
|
}
|
|
|
|
if ( $args['mail_filter_visit'] )
|
|
{
|
|
$ltmt = $args['mail_visit_ltmt'] == 'lt' ? '<' : '>';
|
|
$time = time() - ( $args['mail_filter_visit'] * 86400 );
|
|
$query[] = "last_visit ".$ltmt." ". $time;
|
|
}
|
|
|
|
if ( $args['mail_filter_visit'] )
|
|
{
|
|
$ltmt = $args['mail_joined_ltmt'] == 'lt' ? '<' : '>';
|
|
$time = time() - ( $args['mail_filter_joined'] * 86400 );
|
|
$query[] = "joined ".$ltmt." ". $time;
|
|
}
|
|
|
|
if ( $args['mail_honor'] )
|
|
{
|
|
$query[] = "allow_admin_mails=1";
|
|
}
|
|
|
|
if ( $args['mail_groups'] )
|
|
{
|
|
$tmp_q = 'mgroup IN ('. $args['mail_groups'] .')';
|
|
|
|
$temp = explode( ',', $args['mail_groups'] );
|
|
|
|
if ( is_array( $temp ) and count( $temp ) )
|
|
{
|
|
$tmp = array();
|
|
|
|
foreach( $temp as $id )
|
|
{
|
|
$DB->cache_add_query( 'acp_postoffice_concat_bit', array( 'gid' => $id ), 'sql_extra_queries' );
|
|
$tmp[] = $DB->cur_query;
|
|
$DB->cur_query = "";
|
|
}
|
|
|
|
$tmp_q .= " OR ( ".implode( ' OR ', $tmp ). " )";
|
|
}
|
|
|
|
$query[] = $tmp_q;
|
|
}
|
|
|
|
return implode( ' AND ', $query );
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// INTERNAL: convert quick tags
|
|
//-----------------------------------------
|
|
|
|
function _convert_quick_tags( $contents="", $member=array() )
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
$contents = str_replace( "{board_name}" , str_replace( "'", "'", $ibforums->vars['board_name'] ) , $contents );
|
|
$contents = str_replace( "{board_url}" , $ibforums->vars['board_url']."/index.".$ibforums->vars['php_ext'] , $contents );
|
|
$contents = str_replace( "{reg_total}" , $ibforums->cache['stats']['mem_count'] , $contents );
|
|
$contents = str_replace( "{total_posts}" , $ibforums->cache['stats']['total_topics'] + $ibforums->cache['stats']['total_replies'] , $contents );
|
|
$contents = str_replace( "{busy_count}" , $ibforums->cache['stats']['most_count'] , $contents );
|
|
$contents = str_replace( "{busy_time}" , $std->get_date( $ibforums->cache['stats']['most_date'], 'SHORT' ), $contents );
|
|
$contents = str_replace( "{member_id}" , $member['id'], $contents );
|
|
$contents = str_replace( "{member_name}" , $member['name'], $contents );
|
|
$contents = str_replace( "{member_joined}", date( 'j-F y', $member['joined'] ), $contents );
|
|
$contents = str_replace( "{member_posts}" , $member['posts'], $contents );
|
|
|
|
return $contents;
|
|
}
|
|
|
|
//-----------------------------------------
|
|
// INTERNAL: get default mail
|
|
//-----------------------------------------
|
|
|
|
function _get_default_mail_contents()
|
|
{
|
|
global $ibforums, $DB, $std;
|
|
|
|
$mail = "{member_name},\n\n\n\n-------------------------------------\n{board_name} Statistics:\n"
|
|
."-------------------------------------\nRegistered Users: {reg_total}\nTotal Posts: {total_posts}\n"
|
|
."Busiest Time: {busy_count} users were online on {busy_time}\n\n"
|
|
."-------------------------------------\nHandy Links\n"
|
|
."-------------------------------------\nBoard Address: {board_url}\nLog In: {board_url}?act=Login&CODE=00\n"
|
|
."Lost Password Recovery: {board_url}?act=Reg&CODE=10\n\n"
|
|
."-------------------------------------\nHow to unsubscribe\n"
|
|
."-------------------------------------\nVisit your email preferences ({board_url}?act=UserCP&CODE=02) and ensure "
|
|
."that the box for 'Send me any updates sent by the board administrator' is unchecked and submit the form";
|
|
|
|
return $mail;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|