Skip to content

Commit 794fa31

Browse files
xh3n1michield
authored andcommitted
0019204: Add facility for exporting all an individual subscriber's data including history (#313)
* export subscriber data Signed-off-by: Xheni Myrtaj <[email protected]> * replace mysqli_fetch_assoc with the Sql_Fetch_Assoc Signed-off-by: Xheni Myrtaj <[email protected]> * remove unnecessary line Signed-off-by: Xheni Myrtaj <[email protected]> (cherry picked from commit ba4ea2e)
1 parent c9c1086 commit 794fa31

File tree

2 files changed

+225
-2
lines changed

2 files changed

+225
-2
lines changed
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
<?php
2+
require_once dirname(__FILE__).'/accesscheck.php';
3+
if (!defined('PHPLISTINIT')) {
4+
exit;
5+
}
6+
if (!$_GET['id']) {
7+
Fatal_Error(s('no such User'));
8+
9+
return;
10+
} else {
11+
$id = (int)sprintf('%d', $_GET['id']);
12+
}
13+
14+
$result = Sql_query("SELECT * FROM {$tables['user']} where id = $id");
15+
if (!Sql_Affected_Rows()) {
16+
Fatal_Error(s('no such User'));
17+
18+
return;
19+
}
20+
$user = sql_fetch_array($result);
21+
22+
ob_end_clean();
23+
header('Content-Type: text/csv; charset=utf-8');
24+
header('Content-Disposition: attachment; filename=subscriberdata.csv');
25+
// create a file pointer connected to the output stream
26+
ob_start();
27+
$output = fopen('php://output', 'w');
28+
29+
// output the column headings
30+
fputcsv($output, array('','General Subscriber Info'));
31+
fputcsv($output, array('Email', 'Confirmed','Blacklisted', 'Opted in', 'Bounce count','Entered','Modified','Html email','Subscribe Page','rssfrequency','disabled','extradata'));
32+
33+
34+
$userrows = Sql_Query(
35+
sprintf(
36+
'select email, confirmed, blacklisted, optedin, bouncecount, entered, modified, htmlemail, subscribepage, rssfrequency, disabled, extradata
37+
from %s where id = %d'
38+
39+
40+
, $GLOBALS['tables']['user'], $user['id'])
41+
);
42+
43+
44+
// loop over the rows, outputting them
45+
while ($row = Sql_Fetch_Assoc($userrows))
46+
fputcsv($output, $row);
47+
48+
fputcsv($output, array(' '));
49+
// output the column headings
50+
fputcsv($output, array('','User History Info'));
51+
fputcsv($output, array('ip address', 'Summary','Date', 'Details', 'System Information'));
52+
$userhistoryrows = Sql_Query(
53+
sprintf(
54+
'select ip, summary,date, detail, systeminfo
55+
from %s where userid = %d'
56+
57+
58+
, $GLOBALS['tables']['user_history'], $user['id'])
59+
);
60+
61+
62+
// loop over the rows, outputting them
63+
while ($row = Sql_Fetch_Assoc($userhistoryrows))
64+
fputcsv($output, $row);
65+
fputcsv($output, array(' '));
66+
fputcsv($output, array('','Campaign Info'));
67+
fputcsv($output, array('Message ID', 'Entered','Viewed', 'Response time'));
68+
$msgsrows = Sql_Query(sprintf('select messageid,entered,viewed,(viewed = 0 or viewed is null) as notviewed,
69+
abs(unix_timestamp(entered) - unix_timestamp(viewed)) as responsetime from %s where userid = %d and status = "sent" order by entered desc',
70+
$GLOBALS['tables']['usermessage'], $user['id']));
71+
72+
73+
// loop over the rows, outputting them
74+
while ($row = Sql_Fetch_Assoc($msgsrows))
75+
fputcsv($output, $row);
76+
fputcsv($output, array(''));
77+
78+
fputcsv($output, array('','Bounces Info'));
79+
fputcsv($output, array('Bounce ID', 'Bounce message','Time', 'Bounce','F time'));
80+
$bouncesrows = Sql_Query(sprintf('
81+
select
82+
message_bounce.id
83+
, message_bounce.message
84+
, time
85+
, bounce
86+
, date_format(time,"%%e %%b %%Y %%T") as ftime
87+
from
88+
%s as message_bounce
89+
where
90+
user = %d', $GLOBALS['tables']['user_message_bounce'], $user['id']));
91+
92+
while ($row = Sql_Fetch_Assoc($bouncesrows))
93+
fputcsv($output, $row);
94+
95+
fputcsv($output, array(''));
96+
97+
fputcsv($output, array('','Blacklist Info'));
98+
fputcsv($output, array('Email', 'Name','Data','Added'));
99+
$blacklistdata = $GLOBALS['tables']['user_blacklist_data'];
100+
$blacklist = $GLOBALS['tables']['user_blacklist'];
101+
$emailaddress = sql_escape($user['email']);
102+
103+
$blacklistinforows = Sql_Query("select d.email, d.name, d.data, b.added from $blacklistdata as d
104+
left join $blacklist as b on d.email = b.email
105+
where b.email = '$emailaddress';
106+
");
107+
108+
while ($row = Sql_Fetch_Assoc($blacklistinforows))
109+
fputcsv($output, $row);
110+
111+
fputcsv($output, array(''));
112+
fputcsv($output, array('','Subscriber Attribute Info'));
113+
fputcsv($output, array('value','name', 'type','tablename'));
114+
115+
$userattribute = $GLOBALS['tables']['user_attribute'];
116+
$attribute = $GLOBALS['tables']['attribute'];
117+
$userid = (int)$user['id'];
118+
119+
$attributesrows = Sql_Query(
120+
"select u.value, a.name, a.type, a.tablename from $userattribute as u
121+
left join $attribute as a on u.attributeid = a.id
122+
where u.userid = '$userid';
123+
124+
");
125+
126+
127+
while ($row = Sql_Fetch_Assoc($attributesrows))
128+
fputcsv($output, $row);
129+
130+
$list = $GLOBALS['tables']['list'];
131+
$listuser = $GLOBALS['tables']['listuser'];
132+
133+
fputcsv($output, array(''));
134+
135+
136+
fputcsv($output, array('','Lists Membership'));
137+
fputcsv($output, array('List name','description', 'entered','modified'));
138+
139+
$listrows = Sql_Query(
140+
"select l.name, l.description, u.entered, u.modified from $list as l
141+
left join $listuser as u on l.id = u.listid
142+
where u.userid = '$userid';
143+
144+
");
145+
146+
147+
while ($row = Sql_Fetch_Assoc($listrows))
148+
fputcsv($output, $row);
149+
150+
151+
fputcsv($output, array(' '));
152+
// output the column headings
153+
fputcsv($output, array('','Links tracking Info'));
154+
fputcsv($output, array('URL', 'Forward','First Clicked', 'Latest Clicked', 'clicked','Campaign ID'));
155+
$linkrows = Sql_Query(
156+
sprintf(
157+
'select url, forward, firstclick, latestclick, clicked, messageid
158+
from %s where userid = %d'
159+
160+
161+
, $GLOBALS['tables']['linktrack'], $user['id'])
162+
);
163+
164+
while ($row = Sql_Fetch_Assoc($linkrows))
165+
fputcsv($output, $row);
166+
167+
fputcsv($output, array(' '));
168+
// output the column headings
169+
fputcsv($output, array('','UML clicks Info'));
170+
fputcsv($output, array('Message ID', 'Forward ID','First Click', 'Latest Click', 'clicked','Html Clicked', 'Text Clicked'));
171+
$umlrows = Sql_Query(
172+
sprintf(
173+
'select messageid, forwardid, firstclick, latestclick, clicked, htmlclicked, textclicked
174+
from %s where userid = %d'
175+
176+
177+
, $GLOBALS['tables']['linktrack_uml_click'], $user['id'])
178+
);
179+
180+
while ($row = Sql_Fetch_Assoc($umlrows))
181+
fputcsv($output, $row);
182+
183+
fputcsv($output, array(' '));
184+
// output the column headings
185+
fputcsv($output, array(' ','User clicks Info'));
186+
fputcsv($output, array('Link ID', 'Message ID','Name', 'Data', 'Date'));
187+
$userclickrows = Sql_Query(
188+
sprintf(
189+
'select linkid, userid, messageid, name, data, date
190+
from %s where userid = %d'
191+
192+
193+
, $GLOBALS['tables']['linktrack_userclick'], $user['id'])
194+
);
195+
196+
while ($row = Sql_Fetch_Assoc($userclickrows))
197+
fputcsv($output, $row);
198+
199+
fputcsv($output, array(' '));
200+
// output the column headings
201+
fputcsv($output, array(' ','Message Forward Info'));
202+
fputcsv($output, array('Message ID','Forward', 'Status', 'Time'));
203+
$forwardrows = Sql_Query(
204+
sprintf(
205+
'select message, forward, status, time
206+
from %s where user = %d'
207+
208+
209+
, $GLOBALS['tables']['user_message_forward'], $user['id'])
210+
);
211+
212+
while ($row = Sql_Fetch_Assoc($forwardrows))
213+
fputcsv($output, $row);
214+
215+
216+
217+
fclose($output);
218+
exit;
219+
220+
221+
222+

public_html/lists/admin/user.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
} else {
1616
$findby = '';
1717
}
18-
if (isset($_GET['find'])) { //# those notices are driving me nuts ...
18+
if (isset($_GET['find'])) {
1919
$find = $_GET['find']; //# I guess we should check on validity of it as well
2020
} else {
2121
$find = '';
@@ -326,7 +326,8 @@
326326
}
327327

328328
echo '<div class="actions">';
329-
echo PageLinkButton("userhistory&amp;id=$id", s('History'));
329+
echo '&nbsp;&nbsp;'.PageLinkButton("userhistory&amp;id=$id", s('History'));
330+
echo '&nbsp;&nbsp;'.PageLinkButton("exportuserdata&amp;id=$id", s('Download subscriber data'));
330331
echo
331332
'<a
332333
class="confirm btn btn-default"

0 commit comments

Comments
 (0)