1<?php
2
3verifyCsrfGetToken();
4
5if ($_GET['option'] == 'deleteinvalidemail') {
6    $status = s('Deleting subscribers with an invalid email').'<br/ >';
7
8    flush();
9    $req = Sql_Query("select id,email from {$tables['user']}");
10    $c = 0;
11    while ($row = Sql_Fetch_Array($req)) {
12        set_time_limit(60);
13        if (!is_email($row['email'])) {
14            ++$c;
15            deleteUser($row['id']);
16        }
17    }
18    $status .= $c.' '.s('subscribers deleted')."<br/>\n";
19} elseif ($_GET['option'] == 'deleteblacklisted') {
20
21    // Delete subscribers who are blacklisted (for any reason)
22    $status = s('Deleting blacklisted subscribers').'<br/ >';
23
24    flush();
25    $req = Sql_Query('
26        SELECT
27            id
28        FROM
29            '.$tables['user'].'
30        WHERE
31            blacklisted = 1'
32    );
33    $c = 0;
34    while ($row = Sql_Fetch_Array($req)) {
35        set_time_limit(60);
36        ++$c;
37        deleteUserIncludeBlacklist($row['id']);
38    }
39    $status .= $c.' '.s('subscribers deleted')."<br/>\n";
40
41} elseif ($_GET['option'] == 'deleteblacklistedunsubscribed') {
42
43    // Delete subscribers who are blacklisted because they unsubscribed
44    $status = s('Deleting blacklisted subscribers').'<br/ >';
45
46    flush();
47    $req = Sql_Query('
48        SELECT
49            *
50        FROM
51            '.$tables['user'].' AS u
52        LEFT JOIN
53            '.$tables['user_blacklist'].' AS bl ON bl.email = u.email
54        LEFT JOIN
55            '.$tables['user_blacklist_data'].' AS bld ON bld.email = u.email
56        WHERE
57            blacklisted = 1
58            AND bld.name = "reason"
59            AND bld.data = \''.s('"Jump off" set, reason not requested').'\''
60    );
61
62    $c = 0;
63    while ($row = Sql_Fetch_Array($req)) {
64        set_time_limit(60);
65        ++$c;
66        deleteUserIncludeBlacklist($row['id']);
67    }
68    $status .= $c.' '.s('subscribers deleted')."<br/>\n";
69} elseif ($_GET['option'] == 'relinksystembounces') {
70    $status = s('Relinking transactional messages that bounced to the related subscriber profile').'<br/ >';
71    $req = Sql_Query(sprintf('select count(id) from %s b where b.status = "bounced system message" and b.comment like "%% marked unconfirmed" and id not in (select distinct bounce from %s)',$tables['bounce'],$tables['user_message_bounce']));
72    $totalRow = Sql_Fetch_Row($req);
73    $total = $totalRow[0];
74    $status .= s('%d to process',$total).'<br/>';
75    flush();
76
77    $cnt = 0;
78    $done = 0;
79    $req = Sql_Query(sprintf('select id,comment,date from %s where status = "bounced system message" and comment like "%% marked unconfirmed" and id not in (select distinct bounce from %s)',$tables['bounce'],$tables['user_message_bounce']));
80    while ($row = Sql_Fetch_Assoc($req)) {
81        ++$cnt;
82        set_time_limit(60);
83        if (preg_match('/([\d]+) marked unconfirmed/',$row['comment'],$regs)) {
84            $exists = Sql_Fetch_Row_Query(sprintf('select count(*) from %s where user = %d and message = -1 and bounce = %d',$tables['user_message_bounce'],$regs[1],$row['id']));
85            if (empty($exists[0])) {
86                Sql_Query(sprintf('insert into %s (user,message,bounce,time) values(%d,-1,%d,"%s")',$tables['user_message_bounce'],$regs[1],$row['id'],$row['date']));
87                ++$done;
88            }
89        }
90    }
91    $status .= s('%d bounces have been associated with a subscriber profile',$done);
92}
93
94