";
exit;
}
require_once(e_PLUGIN.$mailer."/mailout_class.php");
if (varset($mailer_include_with_default,TRUE) || ($mail_plugin == $mailer))
{ // Definitely need this plugin
$mail_class = 'mailout_'.$mailer;
$temp = new $mail_class;
if ($temp->mailer_enabled)
{
$mail_handlers[] = &$temp;
if (($mail_plugin !== FALSE) && varset($mailer_exclude_default,FALSE))
{
$mail_handlers[0]->mailer_enabled = FALSE; // Don't need default handler
}
}
else
{
unset($temp);
}
}
}
}
}
//----------------------------------------
// Send test email - uses standard 'single email' handler
//----------------------------------------
if (isset($_POST['testemail']) && getperms("0"))
{
if(trim($_POST['testaddress']) == "")
{
$message = LAN_MAILOUT_19;
}
else
{
$mailheader_e107id = USERID;
require_once(e_HANDLER."mail.php");
$add = ($pref['mailer']) ? " (".strtoupper($pref['mailer']).")" : " (PHP)";
$sendto = trim($_POST['testaddress']);
if (!sendemail($sendto, LAN_MAILOUT_113." ".SITENAME.$add, LAN_MAILOUT_114,LAN_MAILOUT_125))
{
$message = ($pref['mailer'] == "smtp") ? LAN_MAILOUT_67 : LAN_MAILOUT_106;
}
else
{
$message = LAN_MAILOUT_81. "(".$sendto.")";
}
}
}
/*
// Delete any mailout entries that have hung around for a day or more (intentionally commented out - done manually now)
$sql->db_Delete("generic", "gen_type='sendmail' AND gen_datestamp < ".(time()-86400));
*/
//----------------------------------------
// Saved emails
//----------------------------------------
if (isset($_POST['save_email']))
{
$qry = "0,'massmail', '".time()."', '".USERID."', '".$tp->toDB($_POST['email_subject'])."', '0', \"".$tp->toDB($_POST['email_body'])."\" ";
$message = $sql -> db_Insert("generic", $qry) ? LAN_SAVED : LAN_ERROR;
}
if (isset($_POST['update_email']))
{
$qry = "gen_user_id = '".USERID."', gen_datestamp = '".time()."', gen_ip = '".$tp->toDB($_POST['email_subject'])."', gen_chardata= \"".$tp->toDB($_POST['email_body'])."\" WHERE gen_id = '".$_POST['update_id']."' ";
$message = $sql -> db_Update("generic", $qry) ? LAN_UPDATED : LAN_UPDATED_FAILED;
}
/*
if (isset($_POST['delete']))
{
$d_idt = array_keys($_POST['delete']);
$message = ($sql -> db_Delete("generic", "gen_id='".$d_idt[0]."'")) ? LAN_DELETED : LAN_DELETED_FAILED;
$action = 'list';
}
if (isset($_POST['edit']))
{
$e_idt = array_keys($_POST['edit']);
if($sql -> db_Select("generic", "*", "gen_id='".$e_idt[0]."' "))
{
$foo = $sql -> db_Fetch();
}
}
*/
if (($action == 'savedmail') && $sub_par && $mail_id)
{
// echo "Dealing with saved emails {$sub_par} ID {$mail_id} ";
switch($sub_par)
{
case 'edit' :
if($sql -> db_Select("generic", "*", "gen_id='".$mail_id."' "))
{
$foo = $sql -> db_Fetch();
$action = 'makemail';
}
break;
case 'delete' :
$message = ($sql -> db_Delete("generic", "gen_id='".$mail_id."'")) ? LAN_DELETED : LAN_DELETED_FAILED;
$action = 'list';
break;
default :
$action = 'makemail';
}
}
$_POST['mail_id'] = time(); // Unique ID for email - used to select our run of emails (as opposed to any other that might be going on)
// if (!is_object($sql2)) $sql2 = new db; // Should be OK in 0.8
function ret_extended_field_list($list_name, $add_blank = FALSE)
{
global $sql;
$ret = "\n";
return $ret;
}
// ---------------------------------------------
// Find a block of emails to send
// ---------------------------------------------
if (isset($_POST['submit']))
{
$c = 0; // Record count
$dups = 0; // Counter for duplicates
$email_subject = $tp->toDB($_POST['email_subject']);
$mail_id = intval(varset($_POST['mail_id'],0));
/* Save the actual email, so we aren't reliant on passing $_POST data for immediate use
Format is as follows:
gen_id int(10) unsigned NOT NULL auto_increment, - set to zero (auto assigned)
gen_type varchar(80) NOT NULL default '', - record type being added ('savemail')
gen_datestamp int(10) unsigned NOT NULL default '0', - Mail ID code - to match the destination address records
gen_user_id int(10) unsigned NOT NULL default '0', - User ID of current author
gen_ip varchar(80) NOT NULL default '', - Email subject
gen_intdata int(10) unsigned NOT NULL default '0', - Initially set to zero - set to number of emails initially added
gen_chardata text NOT NULL, - 'From' email address and name, Email body
*/
$email_data = array('sender_email' => $email_address,
'sender_name' => $email_name,
'copy_to' => $tp->toDB($_POST['email_cc']),
'bcopy_to' => $tp->toDB($_POST['email_bcc']),
'attach' => $tp->toDB(trim($_POST['email_attachment'])),
'email_subject' => $tp->toDB(trim($_POST['email_subject'])),
'email_body' => $tp->toDB($_POST['email_body']),
'use_theme' => intval(varset($_POST['use_theme'],0))
);
$qry = "0,'savemail', '".$mail_id."', '".USERID."', '".$tp->toDB($_POST['email_subject'])."', '0', '".serialize($email_data)."' ";
$message = ($mail_text_id = $sql -> db_Insert("generic", $qry)) ? LAN_SAVED : LAN_ERROR;
$mail_text_id = intval($mail_text_id);
if ($mail_text_id == 0)
{
Echo "Email not saved. ";
echo $message;
require_once(FOOTERF);
exit;
}
foreach ($mail_handlers as $m)
{ // Get email addresses from each handler in turn. Do them one at a time, so that all can use the $sql data object
if ($m->mailer_enabled)
{
// Initialise
$m->select_init();
// Get email addresses - add to list, strip duplicates
while ($row = $m->select_add())
{ // Add email addresses to the database ready for sending (the body is never saved in the DB - it gets passed as a $_POST value)
$email_address = trim($row['user_email']);
$email_name = $row['user_name'];
if ($email_name == '') { $email_name = 'unknown'; }
$email_target = serialize(array('user_email' => $email_address,
'user_name' => $email_name,
'user_signup' => varset($row['user_signup'],'')));
/*
Table data:
gen_id int(10) unsigned NOT NULL auto_increment, - set to zero (auto assigned)
gen_type varchar(80) NOT NULL default '', - record type being added - 'sendmail'
gen_datestamp int(10) unsigned NOT NULL default '0', - Mail ID code (matches the stored email)
gen_user_id int(10) unsigned NOT NULL default '0', - User ID - zero if not a registered user
gen_ip varchar(80) NOT NULL default '', - User email address (so we can search for duplicates)
gen_intdata int(10) unsigned NOT NULL default '0', - ID number of email text in 'generic' table (previous version used zero here)
gen_chardata text NOT NULL, - User email address, name, signup link ID (previous version stored subject here)
*/
$qry = "0,'sendmail', '".$_POST['mail_id']."', '".$row['user_id']."', '".$email_address."', '".$mail_text_id."', '".$email_target."' ";
if ($sql2->db_Select('generic', 'gen_ip', "`gen_datestamp`= '{$_POST['mail_id']}' AND `gen_ip`='{$email_address}'"))
{
$dups++; // Found second entry with same email address
}
else
{
if($sql2 -> db_Insert("generic", $qry))
{
$c++;
}
else
{
echo "Error on insert: ".$qry." ";
}
}
}
// Close
$m->select_close();
}
}
$sql->db_Update('generic',"`gen_intdata`={$c} WHERE `gen_id`={$mail_text_id}");
// We've got all the email addresses here - display a confirmation form
$debug = (e_MENU == "debug") ? "?[debug]" : "";
$text = "
";
$ns->tablerender(LAN_MAILOUT_39." ({$c}) ", $text);
require_once(e_ADMIN."footer.php");
exit;
} // End of previewed email
//. Update Preferences.
if (isset($_POST['updateprefs']) && getperms("0"))
{
$pref['mailer'] = $_POST['mailer'];
// Allow qmail as an option as well - works much as sendmail
if ((strpos($_POST['sendmail'],'sendmail') !== FALSE) || (strpos($_POST['sendmail'],'qmail') !== FALSE)) $pref['sendmail'] = $_POST['sendmail'];
$pref['smtp_server'] = $tp->toDB($_POST['smtp_server']);
$pref['smtp_username'] = $tp->toDB($_POST['smtp_username']);
$pref['smtp_password'] = $tp->toDB($_POST['smtp_password']);
$smtp_opts = array();
switch (trim($_POST['smtp_options']))
{
case 'smtp_ssl' :
$smtp_opts[] = 'secure=SSL';
break;
case 'smtp_tls' :
$smtp_opts[] = 'secure=TLS';
break;
case 'smtp_pop3auth' :
$smtp_opts[] = 'pop3auth';
break;
}
if (varsettrue($_POST['smtp_keepalive'])) $smtp_opts[] = 'keepalive';
if (varsettrue($_POST['smtp_useVERP'])) $smtp_opts[] = 'useVERP';
$pref['smtp_pop3auth'] = in_array('pop3auth',$smpt_opts); // This will go!
$pref['smtp_keepalive'] = $_POST['smtp_keepalive']; // This will go!
$pref['smtp_options'] = implode(',',$smtp_opts);
$pref['mail_pause'] = $_POST['mail_pause'];
$pref['mail_pausetime'] = $_POST['mail_pausetime'];
$pref['mail_bounce_email'] = $_POST['mail_bounce_email'];
$pref['mail_bounce_pop3'] = $_POST['mail_bounce_pop3'];
$pref['mail_bounce_user'] = $_POST['mail_bounce_user'];
$pref['mail_bounce_pass'] = $_POST['mail_bounce_pass'];
$pref['mail_bounce_type'] = $_POST['mail_bounce_type'];
$pref['mail_bounce_delete'] = $_POST['mail_bounce_delete'];
$pref['mailout_enabled'] = implode(',',$_POST['mail_mailer_enabled']);
$pref['mail_log_options'] = intval($_POST['mail_log_option']).','.intval($_POST['mail_log_email']);
save_prefs();
$message = LAN_SETSAVED;
}
if (isset($message))
{
$ns->tablerender("", "
".$message."
");
}
// ----------------- Actions ----------------------------------------------->
//if((!e_QUERY && !$_POST['delete']) || $_POST['edit']) $action = 'makemail';
if (!varsettrue($action)) $action = 'makemail';
switch ($action)
{
case "prefs" :
if (getperms("0"))
{
show_prefs();
}
break;
case 'makemail' :
show_mailform($foo);
break;
case "list" :
showList();
break;
case 'debug' :
showList($sub_par);
break;
case 'mailouts' :
showMailouts($sub_par,$mail_id);
}
require_once(e_ADMIN."footer.php");
//---------------------------------------------
// List of incomplete mailouts
//---------------------------------------------
function showMailouts($sub_par,$mail_id)
{
global $sql,$ns,$tp, $images_path;
// gen_datestamp int(10) unsigned NOT NULL default '0', - Mail ID code - to match the destination address records
// gen_user_id int(10) unsigned NOT NULL default '0', - User ID of current author
// gen_ip varchar(80) NOT NULL default '', - Email subject
// gen_intdata int(10) unsigned NOT NULL default '0', - Initially set to zero - set to number of emails initially added
$message = '';
if ($sub_par && $mail_id)
{
switch ($sub_par)
{
case 'delete' :
if ($sql->db_Select('generic','gen_datestamp',"`gen_datestamp`={$mail_id} AND `gen_type`='savemail'"))
{
$message = $sql->db_Delete('generic',"`gen_datestamp`={$mail_id} AND (`gen_type`='sendmail' OR `gen_type`='savemail')") ? LAN_DELETED : LAN_DELETED_FAILED;
}
else
{ // Should only happen if people fiddle!
$message = "Error - database record not found";
echo "DB error ";
}
break;
case 'detail' : // Show the detail of an email run above the main list
if ($sql->db_Select('generic','gen_id,gen_datestamp,gen_chardata',"`gen_datestamp`={$mail_id} AND `gen_type`='savemail'"))
{
$row = $sql->db_Fetch();
// Display a little bit of the email
$mail = unserialize($row['gen_chardata']);
$text = "
";
$ns->tablerender(LAN_MAILOUT_102,$text);
}
else
{ // Should only happen if people fiddle!
$message = "Error - database record not found";
echo "DB error ";
}
break;
case 'resend' :
// Echo "resend: {$mail_id} ";
if ($sql->db_Select('generic','gen_id,gen_datestamp,gen_chardata',"`gen_datestamp`={$mail_id} AND `gen_type`='savemail'"))
{ // Put up confirmation
$row = $sql->db_Fetch();
$debug = (e_MENU == "debug") ? "[debug]" : "";
$mailer_url = e_HANDLER."phpmailer/mailout_process.php?".$debug."{$row['gen_datestamp']}.{$row['gen_id']}";
$c = $sql->db_Count('generic','(*)',"WHERE `gen_datestamp`={$mail_id} AND `gen_type`='sendmail'"); // Count of mails to go
$text = "
";
$ns->tablerender(LAN_MAILOUT_99,$text);
// Display a little bit of the email
$mail = unserialize($row['gen_chardata']);
$text = "
\n
".LAN_MAILOUT_51."
".$mail['email_subject']."
\n
".LAN_MAILOUT_100."
".$mail['email_body']."
\n
";
$ns->tablerender(LAN_MAILOUT_101,$text);
return;
}
else
{ // Should only happen if people fiddle!
$message = "Error - database record not found";
echo "DB error ";
}
break;
case 'orphans' : // Delete any orphaned emails
if ($sql->db_Select('generic','gen_datestamp',"`gen_datestamp`={$mail_id} AND `gen_type`='sendmail'"))
{
$message = $sql->db_Delete('generic',"`gen_datestamp`={$mail_id} AND `gen_type`='sendmail'") ? LAN_DELETED : LAN_DELETED_FAILED;
}
else
{ // Should only happen if people fiddle!
$message = "Error - database record not found";
echo "DB error ";
}
break;
default :
echo "Invalid parameter: {$sub_par} ";
}
}
if ($message) $ns -> tablerender("
".LAN_MAILOUT_78."
", $message);
// Need to select main email entries; count number of addresses attached to each
$gen = new convert;
$qry = "SELECT
u.user_name, g.*,
COUNT(m.gen_datestamp) AS pending
FROM `#generic` AS g
LEFT JOIN `#user` as u ON g.gen_user_id=u.user_id
LEFT JOIN `#generic` AS m ON m.gen_datestamp = g.gen_datestamp AND m.gen_type='sendmail'
WHERE g.gen_type='savemail'
GROUP BY g.gen_datestamp
ORDER BY g.gen_id ASC";
$count = $sql -> db_Select_gen($qry);
$emails_found = array(); // Log ID and count for later
$text = "
", $text);
// Now see if we can find any 'orphaned' mailout entries
$qry = "SELECT
g.gen_datestamp,
COUNT(g.gen_datestamp) AS pending
FROM `#generic` AS g
WHERE g.gen_type='sendmail'
GROUP BY g.gen_datestamp
ORDER BY g.gen_id ASC";
$count = $sql -> db_Select_gen($qry);
// Echo "There are {$count} groups of unsent emails: ".count($emails_found)." in previous table ";
if ($count > count($emails_found))
{
$text = "
";
$ns->tablerender(LAN_MAILOUT_15, $text);
}
//----------------------------------------------------
// MAILER OPTIONS
//----------------------------------------------------
function show_prefs()
{
global $pref,$ns;
$text = "
";
$caption = LAN_PREFS;
$ns->tablerender($caption, $text);
}
//--------------------------------------------------------
// Show list of saved emails
//--------------------------------------------------------
// Default is what the user wants - saved emails
// Debug modes list any type of data in the generic table - don't believe the column headings!
function showList($type='massmail')
{
global $sql,$ns,$tp, $images_path;
$gen = new convert;
if (!(trim($type))) $type = 'massmail';
$qry ="SELECT g.*,u.* FROM #generic AS g LEFT JOIN #user AS u ON g.gen_user_id = u.user_id WHERE g.gen_type = '{$type}' ORDER BY g.gen_datestamp DESC";
$count = $sql -> db_Select_gen($qry);
$text = "