-
-
Notifications
You must be signed in to change notification settings - Fork 287
Expand file tree
/
Copy pathmclicks.php
More file actions
195 lines (168 loc) · 7.28 KB
/
Copy pathmclicks.php
File metadata and controls
195 lines (168 loc) · 7.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
// click stats per message
require_once dirname(__FILE__).'/accesscheck.php';
if (isset($_GET['id'])) {
$id = sprintf('%d', $_GET['id']);
} else {
$id = 0;
}
$some = 0;
$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']) {
echo s('You do not have access to this page');
return;
}
}
break;
case 'all':
$subselect = '';
break;
case 'none':
default:
$subselect = ' where id = 0';
echo s('You do not have access to this page');
return;
break;
}
$download = !empty($_GET['dl']);
if ($download) {
ob_end_clean();
header('Content-type: text/csv');
header('Content-disposition: attachment; filename="phpList Campaign click statistics.csv"');
ob_start();
}
// If and ID is provided, and we're viewing details for a specific campaign, load an ajaxed page version
if (!$id) {
echo '<div id="contentdiv"></div>';
echo asyncLoadContent('./?page=pageaction&action=mclicks&ajaxed=true&id='.$id.addCsrfGetToken());
return;
}
echo
'<div class="actions pull-right">'.PageLinkButton(
'mclicks&id='.$id.'&dl=1'
, s('Download as CSV file')
).'</div><div class="clearfix"></div>';
echo '<h3>'.s('Click Details for a Message').'</h3>';
$messagedata = Sql_Fetch_Array_query("SELECT * FROM {$tables['message']} where id = $id $subselect");
$totalusers = Sql_Fetch_Row_Query(sprintf('select count(userid) from %s where messageid = %d and status = "sent"',
$GLOBALS['tables']['usermessage'], $id));
$totalbounced = Sql_Fetch_Row_Query(sprintf('select count(userid) from %s where message = %d',
$GLOBALS['tables']['user_message_bounce'], $id));
//unique clicks
$totalclicked = Sql_Fetch_Row_Query(sprintf('select count(distinct userid) from %s where messageid = %d',
$GLOBALS['tables']['linktrack_uml_click'], $id));
//total clicks
$totalclicks = Sql_Fetch_Row_Query(sprintf('select sum(clicked) from %s where messageid = %d',
$GLOBALS['tables']['linktrack_ml'], $id));
if (($totalusers[0] - $totalbounced[0]) > 0) {
$clickperc = sprintf('%0.2f', ($totalclicked[0] / ($totalusers[0] - $totalbounced[0]) * 100));
} else {
$clickperc = $GLOBALS['I18N']->get('N/A');
}
echo '<table class="mclicksDetails">
<tr><td>' .s('Subject').'</td><td>'.$messagedata['subject'].'</td></tr>
<tr><td>' .s('Entered').'</td><td>'.formatDateTime($messagedata['entered']).'</td></tr>
<tr><td>' .s('Date sent').'</td><td>'.formatDateTime($messagedata['sent']).'</td></tr>
<tr><td>' .s('Sent to').'</td><td>'.number_format($totalusers[0]).' '.s('Subscribers').'</td></tr>';
if ($totalusers[0] > 0) {
echo '<tr><td>'.s('Bounced').'</td><td>'.number_format($totalbounced[0]).' (';
echo sprintf('%0.2f', ($totalbounced[0] / $totalusers[0] * 100));
echo '%)</td></tr>';
}
echo '<tr><td>'.s('Unique subscribers who clicked').'</td><td>'.number_format($totalclicked[0]).' <span style="margin-left:10px">'.PageLinkButton('userclicks&msgid='.$id,
s('View subscribers')).'</span></td></tr>
<tr><td>' .s('Total clicks').'</td><td>'.number_format($totalclicks[0]).' </td></tr>
<tr><td>' .s('Click rate').'</td><td>'.$clickperc.' %</td></tr>
</table><hr/>';
$ls = new WebblerListing(s('Campaign click statistics'));
$ls->setElementHeading(s('Link URL'));
$query = '
SELECT
url,
firstclick,
latestclick,
total,
clicked,
htmlclicked,
textclicked,
forwardid
FROM
'.$GLOBALS['tables']['linktrack_ml'].' ml,
'.$GLOBALS['tables']['linktrack_forward'].' forward
WHERE
ml.messageid = '.sprintf($id, '%d').'
AND ml.forwardid = forward.id';
$req = Sql_Query($query);
//# put a limit on (when there are too many distinct URLs, eg when personalised URLs have been used)
$num = Sql_Affected_Rows();
if ($num > 50) {
$query .= ' and total > 0 limit 50';
$req = Sql_Query($query);
}
$summary = array();
$summary['totalclicks'] = 0;
$summary['totalsent'] = 0;
$summary['uniqueclicks'] = 0;
while ($row = Sql_Fetch_Array($req)) {
$uniqueclicks = Sql_Fetch_Array_Query('
SELECT
COUNT(DISTINCT userid) AS users
FROM
'.$GLOBALS['tables']['linktrack_uml_click'].'
WHERE
messageid = '.sprintf($id, '%d').'
AND forwardid = '.sprintf($row['forwardid'], '%d')
);
if (!$download) {
$element = shortenUrlDisplay($row['url']);
} else {
$element = $row['url'];
}
$ls->addElement($element, PageURL2('uclicks&id='.$row['forwardid']));
$ls->setClass($element, 'row1');
// $ls->addColumn($element,$GLOBALS['I18N']->get('firstclick'),formatDateTime($row['firstclick'],1));
// $ls->addColumn($element,$GLOBALS['I18N']->get('latestclick'),$row['latestclick']);
//# set is confusing, as it is total links sent, not total users sent, https://mantis.phplist.com/view.php?id=17057
//# remove
// $ls->addColumn($element,$GLOBALS['I18N']->get('sent'),$row['total']);
//$ls->addColumn($element,$GLOBALS['I18N']->get('clicks'),$row['clicked'].'<span class="viewusers"><a class="button" href="'.PageUrl2('userclicks&msgid='.$id.'&fwdid='.$row['forwardid']).'" title="'.$GLOBALS['I18N']->get('view users').'"></a></span>');
//$perc = sprintf('%0.2f',($row['clicked'] / $row['total'] * 100));
//$ls->addColumn($element,$GLOBALS['I18N']->get('clickrate'),$perc.'%');
// if (CLICKTRACK_SHOWDETAIL) {
$ls->addColumn(
$element
, s('unique clicks')
, number_format($uniqueclicks['users']).'<span class="viewusers"><a class="button" href="'.PageUrl2('userclicks&msgid='.$id.'&fwdid='.$row['forwardid']).'" title="'.s('view subscribers who clicked').'"></a></span>');
$perc = sprintf('%0.2f', ($uniqueclicks['users'] / $totalusers[0] * 100));
$ls->addColumn($element, s('clickrate'), $perc.'%');
$summary['uniqueclicks'] += $uniqueclicks['users'];
$moreInfo1 = '
<div class="content listingsmall fright gray">' .s('html').': '.number_format($row['htmlclicked']).'</div>'.'
<div class="content listingsmall fright gray">' .s('text').': '.number_format($row['textclicked']).'</div>'.'
';
$moreInfo2 = '
<div class="content listingsmall fright gray">' .s('firstclick').': '.formatDateTime($row['firstclick']).'</div>'.'
<div class="content listingsmall fright gray">' .s('latestclick').': '.formatDateTime($row['latestclick']).'</div>'.'
';
//# @@TODO the totals for HTML+text will now not match the total clicks
$ls->addRow($element, $moreInfo1, $moreInfo2);
// }
$summary['totalclicks'] += $row['clicked'];
$summary['totalsent'] += $row['total'];
}
$ls->addElement('Total');
$ls->setClass('Total', 'rowtotal');
$ls->addColumn('Total', s('unique clicks'), number_format($summary['uniqueclicks']));
$perc = sprintf('%0.2f', ($summary['uniqueclicks'] / $totalusers[0] * 100));
$ls->addColumn('Total', s('clickrate'), $perc.'%');
if ($download) {
ob_end_clean();
$status .= $ls->tabDelimited();
}
echo $ls->display();