Permalink
Browse files

Display bounces per campaign (#365)

* display bounces per campaign

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>

* Add bounces per campaign page to manage bounces

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>

* add the page title

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>

* add permission check

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>

* add msgbouces to statistics

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>

* remove var_dump and print

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>

* use formatDateTime function

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>

* add option to download addresses

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>

* add select another campaign option

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>

* order by subject

Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>
  • Loading branch information...
xh3n1 authored and samtuke committed Sep 19, 2018
1 parent 779b90c commit cbdd47462c300e9c7cc15d067532fa7aa1ef0232
@@ -0,0 +1,82 @@
<?php
/**
*
*
*/
verifyCsrfGetToken();
$access = accessLevel('msgbounces');
if (isset($_GET['id'])) {
$id = sprintf('%d', $_GET['id']);
} else {
$id = 0;
}
if (isset($_GET['start'])) {
$start = sprintf('%d', $_GET['start']);
} else {
$start = 0;
}
switch ($access) {
case 'owner':
$subselect = ' and owner = '.$_SESSION['logindetails']['id'];
if ($id) {
$allow = Sql_Fetch_Row_query(sprintf('select owner from %s where id = %d %s', $GLOBALS['tables']['message'],
$id, $subselect));
if ($allow[0] != $_SESSION['logindetails']['id']) {
echo $GLOBALS['I18N']->get('You do not have access to this page');
return;
}
}
break;
case 'all':
$subselect = '';
break;
case 'none':
default:
$subselect = ' where id = 0';
echo $GLOBALS['I18N']->get('You do not have access to this page');
return;
break;
}
$status = '';
$req = Sql_Query(sprintf('select msg.id as messageid, msg.subject, count(msgbounce.bounce) as totalbounces from %s msg,%s msgbounce
where msg.id = msgbounce.message %s
group by msg.id order by messageid', $GLOBALS['tables']['message'],
$GLOBALS['tables']['user_message_bounce'], $subselect));
if (!Sql_Affected_Rows()) {
$status .= '<p class="information">'.s('There are currently no data to view').'</p>';
}
$ls = new WebblerListing(s('Choose a campaign'));
$ls->setElementHeading('Campaign name');
$some = 0;
while ($row = Sql_Fetch_Array($req)) {
$messagedata = loadMessageData($row['messageid']);
if (!$download) {
if ($messagedata['subject'] != $messagedata['campaigntitle']) {
$element = '<!--'.$row['messageid'].'-->'.stripslashes($messagedata['campaigntitle']).'<br/><strong>'.shortenTextDisplay($messagedata['subject'],
30).'</strong>';
} else {
$element = '<!--'.$row['messageid'].'-->'.shortenTextDisplay($messagedata['subject'], 30);
}
} else {
$element = $messagedata['subject'];
}
$some = 1;
$ls->addElement($element, PageUrl2('msgbounces&amp;id='.$row['messageid']));
$ls->addColumn($element, s('Total bounces'), number_format($row['totalbounces']));
}
if ($some) {
$status = $ls->display();
} else {
$status = '<p>'.s('None found').'</p>';
}
@@ -7,19 +7,20 @@
echo '<ul style="list-style:none" class="navigation_list">';
echo $spb.PageLink2('bouncerules', $GLOBALS['I18N']->get('List Bounce Rules')).$spe;
echo $spb.PageLink2('bounces', $GLOBALS['I18N']->get('View Bounces')).$spe;
echo $spb.PageLink2('listbounces', $GLOBALS['I18N']->get('View Bounces per list')).$spe;
echo $spb.PageLink2('checkbouncerules', $GLOBALS['I18N']->get('Check Current Bounce Rules')).$spe;
echo $spb.PageLink2('bouncerules', s('List Bounce Rules')).$spe;
echo $spb.PageLink2('bounces', s('View Bounces')).$spe;
echo $spb.PageLink2('listbounces', s('View Bounces per campaign')).$spe;
echo $spb.PageLink2('listbounces', s('View Bounces per list')).$spe;
echo $spb.PageLink2('checkbouncerules', s('Check Current Bounce Rules')).$spe;
echo $spb.PageLink2('processbounces', $GLOBALS['I18N']->get('Process Bounces')).$spe;
echo $spb.PageLink2('processbounces', s('Process Bounces')).$spe;
echo '</ul><br />';
$numrules = Sql_Fetch_Row_Query(sprintf('select count(*) from %s', $GLOBALS['tables']['bounceregex']));
if (!$numrules[0]) {
echo '<p class="information text-info"><big>'.$GLOBALS['I18N']->get('You currently have no rules defined. You can click "Generate Bounce Rules" in order to auto-generate rules from your existing bounces. This will results in a lot of rules which you will need to review and activate. It will however, not catch every single bounce, so it will be necessary to add new rules over time when new bounces come in.').'</big></p>';
echo '<p class="information text-info"><big>'.s('You currently have no rules defined. You can click "Generate Bounce Rules" in order to auto-generate rules from your existing bounces. This will results in a lot of rules which you will need to review and activate. It will however, not catch every single bounce, so it will be necessary to add new rules over time when new bounces come in.').'</big></p>';
} else {
echo '<p class="information text-warning"><big>'.$GLOBALS['I18N']->get('You have already defined bounce rules in your system. Be careful with generating new ones, because these may interfere with the ones that exist.').'</big></p>';
echo '<p class="information text-warning"><big>'.s('You have already defined bounce rules in your system. Be careful with generating new ones, because these may interfere with the ones that exist.').'</big></p>';
}
echo '<br /><p class="button">'.PageLink2('generatebouncerules', $GLOBALS['I18N']->get('Generate Bounce Rules')).'</p>';
echo '<br /><p class="button">'.PageLink2('generatebouncerules', s('Generate Bounce Rules')).'</p>';
@@ -685,13 +685,15 @@ function pageTitle($page)
'statsmgt',
'statsoverview',
'domainstats',
'msgbounces',
),
'menulinks' => array(
'statsoverview',
'mviews',
'mclicks',
'uclicks',
'domainstats',
'msgbounces',
),
),
'system' => array(
@@ -42,6 +42,7 @@
case 'processbounces': $page_title = 'Retrieve bounces from server'; break;
case 'bounces': $page_title = 'View bounces'; break;
case 'bounce': $page_title = 'View a bounce'; break;
case 'msgbounces': $page_title = 'View bounces per campaign'; break;
case 'spageedit': $page_title = 'Edit a subscribe page'; break;
case 'spage': $page_title = 'Subscribe pages'; break;
case 'eventlog': $page_title = 'Log of events'; break;
@@ -1,80 +1,117 @@
<?php
require_once dirname(__FILE__).'/accesscheck.php';
$access = accessLevel('msgbounces');
$msgid = empty($_GET['id']) ? 0 : sprintf('%d', $_GET['id']);
if (!$msgid) {
$req = Sql_Query(sprintf('select message.id as messageid,message.subject,count(distinct user) as numusers from %s message, %s umb where message.id = umb.message and date_add(message.entered,interval 3 month) > now() group by message.id order by message.entered desc',
$GLOBALS['tables']['message'], $GLOBALS['tables']['user_message_bounce']));
$ls = new WebblerListing($GLOBALS['I18N']->get('Choose a message'));
while ($row = Sql_Fetch_Array($req)) {
$element = $GLOBALS['I18N']->get('message').' '.$row['messageid'];
$ls->addElement($element, PageUrl2('msgbounces&amp;id='.$row['messageid']));
$ls->addColumn($element, $GLOBALS['I18N']->get('subject'), $row['subject']);
$ls->addColumn($element, $GLOBALS['I18N']->get('# bounced'), $row['numusers']);
$messageid = empty($_GET['id']) ? 0 : sprintf('%d', $_GET['id']);
$download = isset($_GET['type']) && $_GET['type'] === 'dl';
$isowner_where = '';
switch ($access) {
case 'owner':
if ($messageid) {
$req = Sql_Query(sprintf('select id from '.$tables['message'].' where owner = %d and id = %d',
$_SESSION['logindetails']['id'], $messageid));
if (!Sql_Affected_Rows()) {
echo s('You do not have access to this page');
return;
}
}
break;
case 'all':
case 'view':
break;
case 'none':
default:
if ($messageid) {
echo s('You do not have access to this page');
return;
}
break;
}
if (!$messageid) {
//# for testing the loader allow a delay flag
if (isset($_GET['delay'])) {
$_SESSION['LoadDelay'] = sprintf('%d', $_GET['delay']);
} else {
unset($_SESSION['LoadDelay']);
}
echo $ls->display();
echo '<div id="contentdiv"></div>';
echo asyncLoadContent('./?page=pageaction&action=msgbounces&ajaxed=true&id='.$messageid.addCsrfGetToken());
return;
}
$req = Sql_Query(sprintf('select message.id as messageid,message.subject,umb.user as userid,count(bounce) as numbounces from %s message, %s umb where message.id = umb.message and message.id = %d and date_add(message.entered,interval 3 month) > now() group by umb.user order by message.entered desc',
$GLOBALS['tables']['message'], $GLOBALS['tables']['user_message_bounce'], $msgid));
$userTable = $GLOBALS['tables']['user'];
$messageBounceTable = $GLOBALS['tables']['user_message_bounce'];
$query= "select u.id as userid, u.email, mb.time from $messageBounceTable mb join $userTable u
on u.id = mb.user where mb.message = '$messageid' ";
$req = Sql_Query($query);
$total = Sql_Affected_Rows();
$limit = '';
$numpp = 150;
$s = empty($_GET['s']) ? 0 : sprintf('%d', $_GET['s']);
if ($total > 500 && $_GET['type'] != 'dl') {
// print Paging2('listbounces&amp;id='.$listid,$total,$numpp,'Page');
$listing = sprintf($GLOBALS['I18N']->get('Listing %s to %s'), $s, $s + $numpp);
$limit = "limit $s,".$numpp;
echo $total.' '.$GLOBALS['I18N']->get(' Total').'</p>';
printf('<table class="bouncesListing" border="1"><tr><td colspan=4 align=center>%s</td></tr><tr><td>%s</td><td>%s</td><td>
%s</td><td>%s</td></tr></table><hr/>',
$listing,
PageLink2('msgbounces&amp;id='.$msgid, '&lt;&lt;', 's=0'),
PageLink2('msgbounces&amp;id='.$msgid, '&lt;', sprintf('s=%d', max(0, $s - $numpp))),
PageLink2('msgbounces&amp;id='.$msgid, '&gt;', sprintf('s=%d', min($total, $s + $numpp))),
PageLink2('msgbounces&amp;id='.$msgid, '&gt;&gt;', sprintf('s=%d', $total - $numpp)));
$req = Sql_Query(sprintf('select message.id as messageid,message.subject,umb.user as userid,count(bounce) as numbounces from %s message, %s umb where message.id = umb.message and message.id = %d and date_add(message.entered,interval 3 month) > now() group by umb.user order by message.entered desc %s',
$GLOBALS['tables']['message'], $GLOBALS['tables']['user_message_bounce'], $msgid, $limit));
$chooseAnotherCampaign = new buttonGroup (
new Button(PageUrl2('msgbounces'), s('Select another campaign')
)
);
$listOfCampaigns = Sql_Query(sprintf('select id, subject from %s campaign order by subject ', $tables['message']));
while ($campaign = Sql_Fetch_Assoc($listOfCampaigns)) {
$chooseAnotherCampaign->addButton(new Button
(PageUrl2('msgbounces') . '&amp;id=' . $campaign['id'], htmlentities($campaign['subject']))
);
}
echo $chooseAnotherCampaign->show();
if ($total) {
echo PageLinkButton('msgbounces&amp;type=dl&amp;id='.$messageid, s('Download addresses'),'','btn-primary pull-right btn-lg pull-bottom');
}
echo '<p>'.number_format($total).s(' bounces to campaign %s', campaignTitle($messageid)).'</p>';
$start = empty($_GET['start']) ? 0 : sprintf('%d', $_GET['start']);
if ($total > $numpp && !$download ) {
$limit = "limit $start,".$numpp;
echo simplePaging('msgbounces&amp;id='.$messageid, $start, $total, $numpp);
$query .= $limit;
$req = Sql_Query($query);
echo '<p class="button">'.PageLink2('msgbounces', 'Select another message');
echo '&nbsp;'.PageLink2('msgbounces&type=dl&&amp;id='.$msgid, 'Download emails');
echo '</p>';
if ($_GET['type'] == 'dl') {
ob_end_clean();
header('Content-type: text/plain');
$filename = 'Bounces on message '.$msgid;
header("Content-disposition: attachment; filename=\"$filename\"");
}
$currentmsg = 0;
$ls = new WebblerListing('');
$messagedata = loadMessageData($messageid);
if ($download) {
ob_end_clean();
header('Content-type: text/csv');
$filename = 'Bounces on '.campaignTitle($messageid).'.csv';
header("Content-disposition: attachment; filename={$filename}");
ob_start();
}
$bouncels = new WebblerListing(s('Bounces on').' '.shortenTextDisplay($messagedata['subject'], 30));
$bouncels->noShader();
$bouncels->setElementHeading('Subscriber ID');
while ($row = Sql_Fetch_Array($req)) {
if ($currentmsg != $row['messageid']) {
if ($_GET['type'] != 'dl') {
echo $ls->display();
}
$currentmsg = $row['messageid'];
flush();
$ls = new WebblerListing($row['subject']);
}
$userdata = Sql_Fetch_Array_Query(sprintf('select * from %s where id = %d',
$GLOBALS['tables']['user'], $row['userid']));
if ($_GET['type'] == 'dl') {
echo $userdata['email']."\n";
}
$ls->addElement($row['userid'], PageUrl2('user&amp;id='.$row['userid']));
$ls->addColumn($row['userid'], $GLOBALS['I18N']->get('email'), $userdata['email']);
$ls->addColumn($row['userid'], $GLOBALS['I18N']->get('# bounces'), $row['numbounces']);
$bouncels->addElement($row['userid'], PageUrl2('user&amp;id='.$row['userid']));
$bouncels->addColumn($row['userid'], s('Subscriber address'), PageLink2('user&id='.$row['userid'], $row['email']));
$bouncels->addColumn($row['userid'], s('Time'), formatDateTime($row['time']));
}
if ($_GET['type'] != 'dl') {
echo $ls->display();
} else {
if ($download) {
ob_end_clean();
echo $bouncels->tabDelimited();
exit;
} else {
echo $bouncels->display();
}

0 comments on commit cbdd474

Please sign in to comment.