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 "
{$content}
";
exit();
}
//-----------------------------------------
// PREVIEW MAIL: JS BOUNCE
//-----------------------------------------
function mail_preview_start()
{
global $ibforums, $DB, $std;
print "
";
}
//-----------------------------------------
// 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 .= "
";
$ibforums->html .= "
";
$ibforums->html .= "
Filters
";
$ibforums->html .= "
|
|
|
";
$ibforums->html .= "
Quick Tags
You may use the following 'quick tags' in your email and they will be converted when the email is sent.
| {board_name} |
The name of your board |
{board_url} |
The URL to your board |
| {reg_total} |
The total number of registered members |
{total_posts} |
The total number of posts |
| {busy_count} |
The most number of users online |
{busy_time} |
The time that the most number of members were online |
| {member_id} |
The member ID of the email recipient |
{member_name} |
The member name of the email recipient |
| {member_joined} |
The member join date of the email recipient |
{member_posts} |
The number of posts for the email recipient |
";
$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 = "
( Sending in progress - base_url}&act=postoffice&code=mail_send_cancel', 'OK to cancel bulk mail?'); return false;\">Cancel )";
}
$ibforums->html .= $ibforums->adskin->add_td_row( array(
"

",
"
{$r['mail_subject']} $inprogress",
$std->get_date( $r['mail_start'], 'SHORT' ),
$std->do_number_format( $r['mail_sentto'] ).' members',
$time_taken,
"
Re-send
Edit
base_url}&act=postoffice&code=mail_delete&id={$r['mail_id']}');return false;\">Delete
"
) );
}
$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;
}
}
?>