Permalink
Browse files

centralise asynchronised loading and load open async as well

  • Loading branch information...
michield committed Dec 5, 2016
1 parent f5b2b26 commit f9b85a32447e8368a6da696ea0eae7e226d0276b
@@ -0,0 +1,110 @@
<?php
verifyCsrfGetToken();
if (isset($_GET['id'])) {
$id = sprintf('%d', $_GET['id']);
} else {
$id = 0;
}
$some = 0;
$status = '';
$access = accessLevel('mclicks');
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']) {
print $GLOBALS['I18N']->get('You do not have access to this page');
return;
}
}
break;
case 'all':
$subselect = '';
break;
case 'none':
default:
$subselect = ' where id = 0';
print $GLOBALS['I18N']->get('You do not have access to this page');
return;
break;
}
$download = !empty($_GET['dl']);
if ($download) {
ob_end_clean();
# header("Content-type: text/plain");
header('Content-type: text/csv');
header('Content-disposition: attachment; filename="phpList Campaign click statistics.csv"');
ob_start();
}
/* $req = Sql_Query(sprintf('select distinct messageid, subject, sum(clicked) as totalclicks, count(distinct userid) as users, count(distinct linkid) as linkcount from %s as linktrack, %s as message
where clicked and linktrack.messageid = message.id %s group by messageid order by entered desc limit 50',
$GLOBALS['tables']['linktrack'],$GLOBALS['tables']['message'],$subselect));*/
$req = Sql_Query(sprintf('select distinct messageid, subject,
sum(total) as total, count(forwardid) as linkcount,sum(clicked) as totalclicks,
sum(htmlclicked) as htmlclicked,sum(textclicked) as textclicked from %s as linktrack_ml, %s as message
where clicked and linktrack_ml.messageid = message.id %s group by messageid order by entered desc limit 50',
$GLOBALS['tables']['linktrack_ml'], $GLOBALS['tables']['message'], $subselect));
if (!Sql_Affected_Rows()) {
$status .= '<p class="information">' . $GLOBALS['I18N']->get('There are currently no messages to view') . '</p>';
}
$ls = new WebblerListing($GLOBALS['I18N']->get('Available Messages'));
while ($row = Sql_Fetch_Array($req)) {
$some = 1;
$messagedata = loadMessageData($row['messageid']);
$totalusers = Sql_Fetch_Row_Query(sprintf('select count(userid) from %s where messageid = %d and status = "sent"',
$GLOBALS['tables']['usermessage'], $row['messageid']));
$totalclicked = Sql_Fetch_Row_Query(sprintf('select count(distinct userid) from %s where messageid = %d',
$GLOBALS['tables']['linktrack_uml_click'], $row['messageid']));
if ($totalusers[0] > 0) {
$clickrate = sprintf('%0.2f', ($totalclicked[0] / $totalusers[0] * 100));
} else {
$clickrate = $GLOBALS['I18N']->get('N/A');
}
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'];
}
$ls->addElement($element, PageURL2('mclicks&amp;id=' . $row['messageid']));
$ls->setClass($element, 'row1');
$ls->addColumn($element, s('links'), $row['linkcount']);
# $ls->addColumn($element,$GLOBALS['I18N']->get('sent'),$totalusers[0]);
$ls->addColumn($element, s('subscribers'), $totalclicked[0]);
$ls->addColumn($element, s('clickrate'), $clickrate);
$ls->addColumn($element, s('clicks'), PageLink2('userclicks&msgid=' . $row['messageid'], $row['totalclicks']));
# $ls->addColumn($element,$GLOBALS['I18N']->get('total'),$row['total']);
# $ls->addColumn($element,$GLOBALS['I18N']->get('users'),$row['users']);
$ls->addRow($element, '',
'<div class="content listingsmall fright gray">' . $GLOBALS['I18N']->get('html') . ': ' . $row['htmlclicked'] . '</div><div class="content listingsmall fright gray">' . $GLOBALS['I18N']->get('text') . ': ' . $row['textclicked'] . '</div>');
/* this one is the percentage of total links versus clicks. I guess that's too detailed for most people.
* besides it'll be low
$perc = sprintf('%0.2f',($row['totalclicks'] / $row['total'] * 100));
$ls->addColumn($element,$GLOBALS['I18N']->get('rate'),$perc.' %');
*/
}
if ($some) {
$status .= '<div class="action">';
$status .= '<p>' . PageLinkButton('mclicks&dl=true', $GLOBALS['I18N']->get('Download as CSV file')) . '</p>';
$status .= '</div>';
# print '<p>'.$GLOBALS['I18N']->get('Select Message to view').'</p>';
$status .= $ls->display();
}
if ($download) {
ob_end_clean();
$status .= $ls->tabDelimited();
}
@@ -0,0 +1,124 @@
<?php
verifyCsrfGetToken();
if (isset($_GET['id'])) {
$id = sprintf('%d', $_GET['id']);
} else {
$id = 0;
}
if (isset($_GET['start'])) {
$start = sprintf('%d', $_GET['start']);
} else {
$start = 0;
}
$addcomparison = 0;
$access = accessLevel('mviews');
#print "Access level: $access";
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']) {
print $GLOBALS['I18N']->get('You do not have access to this page');
return;
}
}
$addcomparison = 1;
break;
case 'all':
$subselect = '';
break;
case 'none':
default:
$subselect = ' where id = 0';
print $GLOBALS['I18N']->get('You do not have access to this page');
return;
break;
}
$status = '';
$download = !empty($_GET['dl']);
if (!$id) {
if ($download) {
ob_end_clean();
# header("Content-type: text/plain");
header('Content-type: text/csv');
header('Content-disposition: attachment; filename="phpList Message open statistics.csv"');
ob_start();
}
$status .= '<p>' . PageLinkButton('page=pageaction&action=mviews&dl=true', s('Download as CSV file')) . '</p>';
# print '<p>'.$GLOBALS['I18N']->get('Select Message to view').'</p>';
$timerange = ' and msg.entered > date_sub(now(),interval 12 month)';
$timerange = '';
$limit = 'limit 10';
$req = Sql_Query(sprintf('select msg.id as messageid,count(um.viewed) as views, count(um.status) as total,
subject,date_format(sent,"%%e %%b %%Y") as sent,bouncecount as bounced from %s um,%s msg
where um.messageid = msg.id and um.status = "sent" %s %s
group by msg.id order by msg.entered desc limit 50', $GLOBALS['tables']['usermessage'],
$GLOBALS['tables']['message'], $subselect, $timerange));
if (!Sql_Affected_Rows()) {
$status .= '<p class="information">' . $GLOBALS['I18N']->get('There are currently no messages to view') . '</p>';
}
$ls = new WebblerListing($GLOBALS['I18N']->get('Available Messages'));
while ($row = Sql_Fetch_Array($req)) {
# $element = $row['messageid'].' '.substr($row['subject'],0,50);
$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'];
}
$ls->addElement($element, PageUrl2('mviews&amp;id=' . $row['messageid']));
$ls->setClass($element, 'row1');
if (!empty($row['sent'])) {
$ls->addRow($element,
'<div class="listingsmall gray">' . $GLOBALS['I18N']->get('date') . ': ' . $row['sent'] . '</div>', '');
} else {
$ls->addRow($element,
'<div class="listingsmall gray">' . $GLOBALS['I18N']->get('date') . ': ' . $GLOBALS['I18N']->get('in progress') . '</div>',
'');
}
$ls->addColumn($element, $GLOBALS['I18N']->get('sent'), $row['total']);
# $ls->addColumn($element,$GLOBALS['I18N']->get('bounced'),$row['bounced']);
$ls->addColumn($element, $GLOBALS['I18N']->get('views'), $row['views'],
$row['views'] ? PageURL2('mviews&amp;id=' . $row['messageid']) : '');
$openrate = sprintf('%0.2f', ($row['views'] / $row['total'] * 100));
$ls->addColumn($element, $GLOBALS['I18N']->get('rate'), $openrate . ' %');
/*
$bouncerate = sprintf('%0.2f',($row['bounced'] / $row['total'] * 100));
$ls->addColumn($element,$GLOBALS['I18N']->get('bounce rate'),$bouncerate.' %');
*/
}
if ($addcomparison) {
$total = Sql_Fetch_Array_Query(sprintf('select count(entered) as total from %s um where um.status = "sent"',
$GLOBALS['tables']['usermessage']));
$viewed = Sql_Fetch_Array_Query(sprintf('select count(viewed) as viewed from %s um where um.status = "sent"',
$GLOBALS['tables']['usermessage']));
$overall = $GLOBALS['I18N']->get('Comparison to other admins');
$ls->addElement($overall);
$ls->addColumn($overall, $GLOBALS['I18N']->get('views'), $viewed['viewed']);
$perc = sprintf('%0.2f', ($viewed['viewed'] / $total['total'] * 100));
$ls->addColumn($overall, $GLOBALS['I18N']->get('rate'), $perc . ' %');
}
if ($download) {
ob_end_clean();
$status .= $ls->tabDelimited();
}
$status .= $ls->display();
}
@@ -10,18 +10,4 @@
}
print '<div id="contentdiv"></div>';
print '<script type="text/javascript">
var loadMessage = \''.sjs('Please wait, your request is being processed. Do not refresh this page.').'\';
var loadMessages = new Array();
loadMessages[5] = \''.sjs('Still loading the statistics').'\';
loadMessages[30] = \''.sjs('It may seem to take a while, but there is a lot of data to crunch<br/>if you have a lot of subscribers and campaigns').'\';
loadMessages[60] = \''.sjs('It should be soon now, your stats are almost there.').'\';
loadMessages[90] = \''.sjs('This seems to take longer than expected, looks like there is a lot of data to work on.').'\';
loadMessages[120] = \''.sjs('Still loading, please be patient, your statistics will show shortly.').'\';
loadMessages[150] = \''.sjs('It will really be soon now until your statistics are here.').'\';
loadMessages[180] = \''.sjs('Maybe get a coffee instead, otherwise it is like watching paint dry.').'\';
loadMessages[210] = \''.sjs('Still not here, let\'s have another coffee then.').'\';
loadMessages[240] = \''.sjs('Too much coffee, I\'m trembling.').'\';
var contentdivcontent = "./?page=pageaction&action=domainstats&ajaxed=true'. addCsrfGetToken() . '";
</script>';
print asyncLoadContent('./?page=pageaction&action=domainstats&ajaxed=true'. addCsrfGetToken());
@@ -2151,3 +2151,21 @@ function arrayKeyHasNotValue(array $array, $requiredKey, $forbiddenValue)
return false;
}
}
function asyncLoadContent($url)
{
return '<script type="text/javascript">
var loadMessage = \'' . sjs('Please wait, your request is being processed. Do not refresh this page.') . '\';
var loadMessages = new Array();
loadMessages[30] = \'' . sjs('Still loading') . '\';
loadMessages[90] = \'' . sjs('It may seem to take a while, but there is a lot of data to crunch<br/>if you have a lot of subscribers and campaigns') . '\';
loadMessages[150] = \'' . sjs('It should be soon now, your page content is almost here.') . '\';
loadMessages[210] = \'' . sjs('This seems to take longer than expected, looks like there is a lot of data to work on.') . '\';
loadMessages[240] = \'' . sjs('Still loading, please be patient, your page content will show shortly.') . '\';
loadMessages[300] = \'' . sjs('It will really be soon now until the page will display.') . '\';
loadMessages[360] = \'' . sjs('Still loading, please wait') . '\';
loadMessages[420] = \'' . sjs('The loading has been just over seven minutes. We can wait just a little longer.') . '\';
loadMessages[500] = \'' . sjs('If the page does not load soon, please report this in the user forums.') . '\';
var contentdivcontent = "'.$url.'";
</script>';
}
@@ -44,21 +44,7 @@
unset($_SESSION['LoadDelay']);
}
print '<div id="contentdiv"></div>';
print '<script type="text/javascript">
var loadMessage = \''.sjs('Please wait, your request is being processed. Do not refresh this page.').'\';
var loadMessages = new Array();
loadMessages[5] = \''.sjs('Still loading the breakdown of bounces per list').'\';
loadMessages[30] = \''.sjs('It may seem to take a while, but there is a lot of data to crunch<br/>if you have a lot of subscribers and campaigns').'\';
loadMessages[60] = \''.sjs('It should be soon now, your data is almost here.').'\';
loadMessages[90] = \''.sjs('This seems to take longer than expected, looks like there is a lot of data to work on.').'\';
loadMessages[120] = \''.sjs('Still loading, please be patient, your page will show shortly.').'\';
loadMessages[150] = \''.sjs('It will really be soon now.').'\';
loadMessages[180] = \''.sjs('Maybe get a coffee instead, otherwise it is like watching paint dry.').'\';
loadMessages[210] = \''.sjs('Still not here, let\'s have another coffee then.').'\';
loadMessages[240] = \''.sjs('Too much coffee, I\'m trembling.').'\';
var contentdivcontent = "./?page=pageaction&action=listbounces&ajaxed=true&id='.$listid. addCsrfGetToken() . '";
</script>';
print asyncLoadContent('./?page=pageaction&action=listbounces&ajaxed=true&id='.$listid. addCsrfGetToken());
return;
}
$query = sprintf('select lu.userid, count(umb.bounce) as numbounces from %s lu join %s umb on lu.userid = umb.user
@@ -46,71 +46,9 @@
}
if (!$id) {
/* $req = Sql_Query(sprintf('select distinct messageid, subject, sum(clicked) as totalclicks, count(distinct userid) as users, count(distinct linkid) as linkcount from %s as linktrack, %s as message
where clicked and linktrack.messageid = message.id %s group by messageid order by entered desc limit 50',
$GLOBALS['tables']['linktrack'],$GLOBALS['tables']['message'],$subselect));*/
$req = Sql_Query(sprintf('select distinct messageid, subject,
sum(total) as total, count(forwardid) as linkcount,sum(clicked) as totalclicks,
sum(htmlclicked) as htmlclicked,sum(textclicked) as textclicked from %s as linktrack_ml, %s as message
where clicked and linktrack_ml.messageid = message.id %s group by messageid order by entered desc limit 50',
$GLOBALS['tables']['linktrack_ml'], $GLOBALS['tables']['message'], $subselect));
if (!Sql_Affected_Rows()) {
print '<p class="information">' . $GLOBALS['I18N']->get('There are currently no messages to view') . '</p>';
}
$ls = new WebblerListing($GLOBALS['I18N']->get('Available Messages'));
while ($row = Sql_Fetch_Array($req)) {
$some = 1;
$messagedata = loadMessageData($row['messageid']);
$totalusers = Sql_Fetch_Row_Query(sprintf('select count(userid) from %s where messageid = %d and status = "sent"',
$GLOBALS['tables']['usermessage'], $row['messageid']));
$totalclicked = Sql_Fetch_Row_Query(sprintf('select count(distinct userid) from %s where messageid = %d',
$GLOBALS['tables']['linktrack_uml_click'], $row['messageid']));
if ($totalusers[0] > 0) {
$clickrate = sprintf('%0.2f', ($totalclicked[0] / $totalusers[0] * 100));
} else {
$clickrate = $GLOBALS['I18N']->get('N/A');
}
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'];
}
$ls->addElement($element, PageURL2('mclicks&amp;id=' . $row['messageid']));
$ls->setClass($element, 'row1');
$ls->addColumn($element, s('links'), $row['linkcount']);
# $ls->addColumn($element,$GLOBALS['I18N']->get('sent'),$totalusers[0]);
$ls->addColumn($element, s('subscribers'), $totalclicked[0]);
$ls->addColumn($element, s('clickrate'), $clickrate);
$ls->addColumn($element, s('clicks'), PageLink2('userclicks&msgid=' . $row['messageid'], $row['totalclicks']));
# $ls->addColumn($element,$GLOBALS['I18N']->get('total'),$row['total']);
# $ls->addColumn($element,$GLOBALS['I18N']->get('users'),$row['users']);
$ls->addRow($element, '',
'<div class="content listingsmall fright gray">' . $GLOBALS['I18N']->get('html') . ': ' . $row['htmlclicked'] . '</div><div class="content listingsmall fright gray">' . $GLOBALS['I18N']->get('text') . ': ' . $row['textclicked'] . '</div>');
/* this one is the percentage of total links versus clicks. I guess that's too detailed for most people.
* besides it'll be low
$perc = sprintf('%0.2f',($row['totalclicks'] / $row['total'] * 100));
$ls->addColumn($element,$GLOBALS['I18N']->get('rate'),$perc.' %');
*/
}
if ($some) {
print '<div class="action">';
print '<p>' . PageLinkButton('mclicks&dl=true', $GLOBALS['I18N']->get('Download as CSV file')) . '</p>';
print '</div>';
# print '<p>'.$GLOBALS['I18N']->get('Select Message to view').'</p>';
print $ls->display();
}
if ($download) {
ob_end_clean();
print $ls->tabDelimited();
}
print '<div id="contentdiv"></div>';
print asyncLoadContent('./?page=pageaction&action=mclicks&ajaxed=true&id='.$id. addCsrfGetToken());
return;
}
Oops, something went wrong.

0 comments on commit f9b85a3

Please sign in to comment.