1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-19 12:11:55 +02:00

Corrected Admin->Mail 'Send now' functionality - replacing old prototype.js code.

This commit is contained in:
Cameron 2014-10-12 02:37:43 -07:00
parent 4fca7b7f12
commit 5e867b378e
7 changed files with 199 additions and 116 deletions

View File

@ -66,7 +66,7 @@ Valid subparameters (where required):
$_GET['m'] - id of mail info in db
$_GET['t'] - id of target info in db
*/
header('Content-Encoding: none'); // turn off gzip.
// header('Content-Encoding: none'); // turn off gzip.
require_once('../class2.php');
if (!getperms('W'))
@ -85,6 +85,73 @@ require_once(e_HANDLER.'mailout_admin_class.php'); // Admin tasks handler
require_once(e_HANDLER.'mail_manager_class.php'); // Mail DB API
/**
* Display Progress-bar of real-time mail-out.
* @return
*/
function sendProgress($id)
{
$pref = e107::getPref();
$mailManager = new e107MailManager();
$mailManager->doEmailTask(varset($pref['mail_workpertick'],5));
$sqld = e107::getDb();
$sqld->select("mail_content","mail_togo_count,mail_sent_count,mail_fail_count","mail_source_id= ".intval($id) );
$row = $sqld->fetch();
$rand = ($row['mail_sent_count'] + $row['mail_fail_count']);
$total = ($row['mail_togo_count'] + $row['mail_sent_count'] + $row['mail_fail_count']);
// $rand = rand(90,100);
// return $rand;
$inc = round(($rand / $total) * 100);
return $inc;
}
if(e_AJAX_REQUEST)
{
$id = intval($_GET['mode']);
// echo rand(92,100);
echo sendProgress($id);
exit;
}
if(vartrue($_GET['mode']) == "progress")
{
// session_write_close();
// sendProgress();
// exit;
}
$mes = e107::getMessage();
$tp = e107::getParser();
/*
if($_GET['mode']=="process")
{
session_write_close(); // allow other scripts to run in parallel.
header('Content-Encoding: none');
ignore_user_abort(true);
set_time_limit(0);
header("Content-Length: $size");
header('Connection: close');
$mailManager = new e107MailManager();
$mailManager->doEmailTask(999999);
echo "Completed Mailout ID: ".$_GET['id'];
exit;
}
*/
class mailout_admin extends e_admin_dispatcher
@ -354,10 +421,10 @@ class mailout_main_ui extends e_admin_ui
{
$ret = $this->processData($new_data);
$ret['mail_create_date'] = time();
$ret['mail_creator'] = USERID;
$ret['mail_create_app'] = 'core';
$ret['mail_content_status'] = 22; // Default status is 'Saved';
$ret['mail_create_date'] = time();
$ret['mail_creator'] = USERID;
$ret['mail_create_app'] = 'core';
$ret['mail_content_status'] = MAIL_STATUS_TEMP;
return $ret;
@ -409,9 +476,15 @@ class mailout_main_ui extends e_admin_ui
}
private function emailSendNow($mailId)
private function emailSendNow($id)
{
e107::getMessage()->addInfo("'Send Now' is Under Construction");
$mes = e107::getMessage();
$text = e107::getForm()->progressBar('mail-progress',1, array('btn-label'=>'Start', 'url'=> e_SELF));
$mes->setTitle('Ready to Process Mail Queue', E_MESSAGE_INFO)->addInfo($text);
return '';
//; e107::getRender()->tablerender("Sending...", $mes->render());
}
@ -1174,7 +1247,7 @@ class mailout_recipients_ui extends e_admin_ui
'mail_recipient_id' => array('title' => LAN_MAILOUT_142, 'thclass' => 'center'),
'mail_recipient_name' => array('title' => LAN_MAILOUT_141, 'forced' => TRUE),
'mail_recipient_email' => array('title' => LAN_MAILOUT_140, 'thclass' => 'left', 'forced' => TRUE),
'mail_status' => array('title' => LAN_MAILOUT_138, 'thclass' => 'left', 'class'=>'left', 'proc' => 'contentstatus'),
'mail_status' => array('title' => LAN_MAILOUT_138, 'type'=>'method', 'thclass' => 'left', 'class'=>'left', 'proc' => 'contentstatus'),
'mail_detail_id' => array('title' => LAN_MAILOUT_137, 'type'=>'dropdown', 'filter'=>true),
'mail_send_date' => array('title' => LAN_MAILOUT_139, 'proc' => 'sdatetime'),
'mail_target_info' => array('title' => LAN_MAILOUT_148, 'proc' => 'array'),
@ -1184,15 +1257,22 @@ class mailout_recipients_ui extends e_admin_ui
protected $fieldpref = array('checkboxes', 'mail_target_id', 'mail_recipient_name', 'mail_recipient_email', 'mail_detail_id', 'mail_status', 'options');
public $mailManager = null;
function init()
{
$this->mailManager = new e107MailManager;
$sql = e107::getDb();
$sql->gen("SELECT r.mail_detail_id,c.mail_title FROM #mail_recipients AS r LEFT JOIN #mail_content as c ON r.mail_detail_id = c.mail_source_id GROUP BY r.mail_detail_id");
while($row = $sql->fetch())
{
$array[] = $row['mail_title'];
$id = $row['mail_detail_id'];
$array[$id] = varset($row['mail_title'], "(No Name)");
}
$this->fields['mail_detail_id']['writeParms'] = $array;
@ -1218,7 +1298,19 @@ class mailout_recipients_ui extends e_admin_ui
class mailout_recipients_form_ui extends e_admin_form_ui
{
public function mail_status($curVal,$mode)
{
if($mode == 'read')
{
return $this->getController()->mailManager->statusToText($curVal);
}
if($mode == 'write')
{
return $curVal;
}
}
}
@ -1241,33 +1333,8 @@ new mailout_admin();
$e_sub_cat = 'mail';
if(vartrue($_GET['mode']) == "progress")
{
session_write_close();
sendProgress();
exit;
}
$mes = e107::getMessage();
$tp = e107::getParser();
if($_GET['mode']=="process")
{
session_write_close(); // allow other scripts to run in parallel.
header('Content-Encoding: none');
ignore_user_abort(true);
set_time_limit(0);
header("Content-Length: $size");
header('Connection: close');
$mailManager = new e107MailManager();
$mailManager->doEmailTask(999999);
echo "Completed Mailout ID: ".$_GET['id'];
exit;
}
@ -1751,6 +1818,7 @@ require_once(e_ADMIN.'footer.php');
* @param integer $id (mailing id)
* @return
*/
/*
function sendImmediately($id)
{
$mes = e107::getMessage();
@ -1794,45 +1862,8 @@ function sendImmediately($id)
e107::getRender()->tablerender("Sending...", $mes->render());
}
*/
/**
* Display Progress-bar of real-time mail-out.
* @return
*/
function sendProgress()
{
$sqld = e107::getDb();
$sqld->db_Select("mail_content","mail_togo_count,mail_sent_count,mail_fail_count","mail_source_id= ".intval($_GET['id']) );
$row = $sqld -> db_Fetch();
$rand = $row['mail_sent_count'] + $row['mail_fail_count'];
$total = $row['mail_togo_count'] + $row['mail_sent_count'] + $row['mail_fail_count'];
// $rand = rand(1,20);
//$total = 20;
$inc = round(($rand / $total) * 100);
if($rand >= $total && $total !=0)
{
echo "<script type='text/javascript'>x.stop();</script>";
echo "<div style='background-image:url(".THEME."images/bar.jpg);color:black;margin-left:auto;margin-right:auto;border:2px inset black;height:16px;width:500px;overflow:hidden;text-align:center'>
Complete </div>";
echo "<div style='text-align:center'>".$rand." / ".$total." </div>";
return;
}
echo "<div style='margin-left:auto;margin-right:auto;border:2px inset black;height:16px;width:500px;overflow:hidden;text-align:left'>";
for($j=1;$j<=$inc;$j++)
{
echo "<img src='".THEME."images/bar.jpg' style='width:5px;height:16px;vertical-align:top'>";
}
echo " $inc % </div>";
echo "<div style='text-align:center'>".$rand." / ".$total." </div>";
return;
}

View File

@ -1104,11 +1104,24 @@ class e_form
}
$class = vartrue($options['class'],'');
$target = $this->name2id($name);
return "<div class='progress ".$class."' id='".$this->name2id($name)."'>
<div class='progress-bar bar' style='width: ".number_format($value,1)."%'></div>
$striped = (vartrue($options['btn-label'])) ? ' progress-striped active' : '';
$text = "<div class='progress ".$class."{$striped}' >
<div id='".$target."' class='progress-bar bar' style='width: ".number_format($value,1)."%'></div>
</div>";
$loading = vartrue($options['loading'],'Please wait...');
if(vartrue($options['btn-label']))
{
$text .= '<a id="mail-progress-start" data-loading-text="'.$loading.'" data-progress-target="'.$target.'" data-progress="' . $options['url'] . '" data-progress-mode="'.$id.'" data-progress-show="'.$nextStep.'" data-progress-hide="'.$thisStep.'" class="btn btn-primary e-progress" >'.$options['btn-label'].'</a>';
}
return $text;
}

View File

@ -138,7 +138,7 @@ define('MAIL_LOG_PATH',e_LOG);
class e107Email extends PHPMailer
{
private $general_opts = array();
private $logEnable = 0; // 0 = log disabled, 1 = 'dry run' (debug and log, no send). 2 = 'log all' (send, and log result)
private $logEnable = 1; // 0 = log disabled, 1 = 'dry run' (debug and log, no send). 2 = 'log all' (send, and log result)
private $logHandle = FALSE; // Save handle of log file if opened
private $localUseVerp = FALSE; // Use our own variable - PHPMailer one doesn't work with all mailers
@ -601,8 +601,6 @@ class e107Email extends PHPMailer
*/
public function arraySet($eml)
{
$tp = e107::getParser();
if(vartrue($eml['template'])) // @see e107_core/templates/email_template.php
@ -637,6 +635,8 @@ class e107Email extends PHPMailer
{
echo "<h4>Couldn't find email template: ".$eml['template']."</h4>";
}
$emailBody = $eml['email_body'];
if (vartrue($eml['email_subject'])) $this->Subject = $tp->parseTemplate($eml['email_subject'], true, varset($eml['shortcodes'],null));
e107::getMessage()->addDebug("Couldn't find email template: ".$eml['template']);
}
@ -645,6 +645,7 @@ class e107Email extends PHPMailer
else
{
if (vartrue($eml['email_subject'])) $this->Subject = $tp->parseTemplate($eml['email_subject'], true, varset($eml['shortcodes'],null));
// $eml['email_body'] = ($tp->toEmail($tmpl['header']). str_replace('{BODY}', $eml['email_body'], $tmpl['body']). $tp->toEmail($tmpl['footer']));
}
@ -695,6 +696,8 @@ class e107Email extends PHPMailer
if (varset($eml['wordwrap'])) $this->WordWrap = $eml['wordwrap'];
if (vartrue($eml['split'])) $this->SingleTo = ($eml['split'] != FALSE);
$this->logLine("ArraySet Data:".print_r($eml,true));
return 0; // No error
}
@ -741,7 +744,7 @@ class e107Email extends PHPMailer
{
if (count($eml))
{ // Set parameters from list
$ret = $this->arraySet($eml);
$ret = $this->arraySet($eml); // returns error on fail and nothing if all is okay.
if ($ret) return $ret;
}
@ -785,6 +788,12 @@ class e107Email extends PHPMailer
$this->logLine("Send to {$to_name} at {$send_to} Mail-ID={$this->MessageID} - ".($result ? 'Success' : 'Fail'));
if(!$result)
{
$this->logLine(print_r($eml,true));
}
$this->ClearAddresses(); // In case we send another email
$this->ClearCustomHeaders();

View File

@ -422,10 +422,9 @@ class e107MailManager
}
// Now array fields
$array = new ArrayData;
if (isset($data['mail_other']))
{
$tmp = $array->ReadArray(str_replace('\\\'', '\'',$data['mail_other'])); // May have escaped data
$tmp = e107::unserialize(str_replace('\\\'', '\'',$data['mail_other'])); // May have escaped data
if (is_array($tmp))
{
$res = array_merge($res,$tmp);
@ -441,7 +440,7 @@ class e107MailManager
}
if (isset($data['mail_target_info']))
{
$tmp = $array->ReadArray(str_replace('\\\'', '\'',$data['mail_target_info'])); // May have escaped data
$tmp = e107::unserialize(str_replace('\\\'', '\'',$data['mail_target_info'])); // May have escaped data
$res['mail_target_info'] = $tmp;
}
return $res;
@ -853,6 +852,9 @@ class e107MailManager
}
}
if (isset($email['mail_overrides']) && is_array($email['mail_overrides'])) $result = array_merge($result, $email['mail_overrides']);
e107::getAdminLog()->addDebug(print_a($email,true),false);
return $result;
}
@ -878,6 +880,10 @@ class e107MailManager
$this->mailer->allSent(); // Tidy up on completion
}
}
else
{
e107::getAdminLog()->addDebug("Couldn't select emails", false);
}
}
@ -902,8 +908,7 @@ class e107MailManager
{
unset($dbData['mail_source_id']); // Just in case - there are circumstances where might be set
$result = $this->db2->db_Insert('mail_content', array('data' => $dbData,
'_FIELD_TYPES' => $this->dbTypes['mail_content'],
'_NOTNULL' => $this->dbNull['mail_content']));
'_FIELD_TYPES' => $this->dbTypes['mail_content'], '_NOTNULL' => $this->dbNull['mail_content']));
}
else
{
@ -1483,30 +1488,47 @@ class e107MailManager
public function sendEmails($templateName, $emailData, $recipientData, $extra = FALSE)
{
if (!is_array($emailData)) return FALSE;
$log = e107::getAdminLog();
$log->addDebug(print_a($emailData, true),false);
$log->addDebug(print_a($recipientData, true),false);
$log->toFile('mail_manager','Main Manager Log',true);
if (!is_array($emailData))
{
return FALSE;
}
if (!is_array($recipientData))
{
$recipientData = array('mail_recipient_email' => $recipientData, 'mail_recipient_name' => $recipientData);
}
$emailData['mail_content_status'] = MAIL_STATUS_TEMP;
if ($templateName == '')
{
$templateName = varset($email['mail_send_style'], 'textonly'); // Safest default if nothing specified
$templateName = varset($emailData['mail_send_style'], 'textonly'); // Safest default if nothing specified
}
$templateName = trim($templateName);
if ($templateName == '') return FALSE;
// Get template data, override email settings as appropriate
require_once(e_HANDLER.'mail_template_class.php');
$ourTemplate = new e107MailTemplate();
if (!$ourTemplate->setNewTemplate($templateName) && empty($emailData['template'])) return FALSE; // Probably template not found if error
if (!$ourTemplate->makeEmailBody($emailData['mail_body'], varset($emailData['mail_include_images'], TRUE))) return FALSE; // Create body text
$emailData['mail_body_templated'] = $ourTemplate->mainBodyText;
$this->currentMailBody = $emailData['mail_body_templated']; // In case we send immediately
$emailData['mail_body_alt'] = $ourTemplate->altBodyText;
$this->currentTextBody = $emailData['mail_body_alt'];
// require_once(e_HANDLER.'mail_template_class.php');
// $ourTemplate = new e107MailTemplate();
// if (!$ourTemplate->setNewTemplate($templateName) && empty($emailData['template'])) return FALSE; // Probably template not found if error
// if (!$ourTemplate->makeEmailBody($emailData['mail_body'], varset($emailData['mail_include_images'], TRUE))) return FALSE; // Create body text
// $emailData['mail_body_templated'] = $ourTemplate->mainBodyText;
$this->currentMailBody = $emailData['mail_body']; // In case we send immediately
// $emailData['mail_body_alt'] = $ourTemplate->altBodyText;
$this->currentTextBody = strip_tags($emailData['mail_body']);
if (!isset($emailData['mail_overrides']))
{
$emailData['mail_overrides'] = $ourTemplate->lastTemplateData['email_overrides'];
@ -1522,9 +1544,13 @@ class e107MailManager
echo "<h4>".$emailData['template']." Template detected</h4>";
}
}
$forceQueue = FALSE;
if (is_array($extra) && isset($extra['mail_force_queue']))
{
$forceQueue = $extra['mail_force_queue'];

View File

@ -1470,6 +1470,7 @@ class mailoutAdminClass extends e107MailManager
else
{
// Start by saving the email
/*
$mailData['mail_content_status'] = MAIL_STATUS_TEMP;
$mailData['mail_create_app'] = 'core';
$result = $this->saveEmail($mailData, TRUE);
@ -1482,11 +1483,11 @@ class mailoutAdminClass extends e107MailManager
{
e107::getMessage()->addDebug("Couldn't save email. (".__FILE__." Line: ".__LINE__.")");
}
*/
$mailMainID = $mailData['mail_source_id'];
$this->mailInitCounters($mailMainID);
// Initialise counters for emails added
$this->mailInitCounters($mailMainID); // Initialise counters for emails added
foreach($this->mailHandlers as $key => $m)
{
@ -1494,16 +1495,15 @@ class mailoutAdminClass extends e107MailManager
// all can use the $sql data object
if($m->mailerEnabled && isset($mailData['mail_selectors'][$key]))
{
// Initialise
$mailerCount = $m->selectInit($mailData['mail_selectors'][$key]);
$mailerCount = $m->selectInit($mailData['mail_selectors'][$key]); // Initialise
if($mailerCount > 0)
{
// Get email addresses - add to list, strip duplicates
while($row = $m->selectAdd())
{
// Add email addresses to the database ready for sending (the body is never saved
// in the DB - it gets passed as a $_POST value)
$result = $this->mailAddNoDup($mailMainID, $row, MAIL_STATUS_TEMP);
while($row = $m->selectAdd()) // Get email addresses - add to list, strip duplicates
{
$result = $this->mailAddNoDup($mailMainID, $row, MAIL_STATUS_TEMP); // Add email addresses to the database ready for sending (the body is never saved // in the DB - it gets passed as a $_POST value)
if($result === FALSE)
{
// Error
@ -1660,6 +1660,7 @@ class mailoutAdminClass extends e107MailManager
return e107::getForm()->datepicker($calName, $calVal, $options);
}
/**
* Show recipients of an email
*
@ -1667,6 +1668,7 @@ class mailoutAdminClass extends e107MailManager
* @param $nextPage - 'mode' specification for page to return to following delete
* @return text for display
*/
/*
public function showmailRecipients($mailID, $nextPage = 'saved')
{
$gen = new convert;
@ -1804,7 +1806,9 @@ class mailoutAdminClass extends e107MailManager
$ns->tablerender(ADLAN_136 . SEP . LAN_MAILOUT_181, $mes->render() . $text);
}
*/
/**
* Clean up mailout DB
* Dump array of results to admin log

View File

@ -547,7 +547,7 @@ function renderProgress($caption, $step)
<div class="bar" id="progress"></div>
</div>
<a id="'.$thisStep.'" data-loading-text="Please wait..." data-progress="' . e_SELF . '" data-progress-mode="'.$step.'" data-progress-show="'.$nextStep.'" data-progress-hide="'.$thisStep.'" class="btn btn-primary e-progress" >'.$caption.'</a>
<a id="'.$thisStep.'" data-loading-text="Please wait..." data-progress="' . e_SELF . '" data-progress-target="progress" data-progress-mode="'.$step.'" data-progress-show="'.$nextStep.'" data-progress-hide="'.$thisStep.'" class="btn btn-primary e-progress" >'.$caption.'</a>
</div>
</div>';

View File

@ -205,12 +205,12 @@ $(document).ready(function()
$('.e-progress').on('click', function(e)
{
// alert('Process Started');
var target = 'progress';
var target = $(this).attr('data-progress-target');
var script = $(this).attr('data-progress');
var show = $(this).attr('data-progress-show');
var hide = $(this).attr('data-progress-hide');
@ -235,8 +235,8 @@ $(document).ready(function()
if(data > 99.999) {
clearInterval(progresspump);
$("#progressouter").removeClass("active");
$("#"+target).closest('.progress').removeClass("active");
$("#"+target).html("Done");
if(hide !== 'undefined')