Add a script to remove inactive users awaiting email confirmation.
[bugdar.git] / admin / purge_inactive.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c) 2010 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 require_once('./global.php');
23 require_once('./includes/api_user.php');
24 require_once('./includes/class_api_error.php');
25
26 APIError(array(new API_Error_Handler($admin), 'admin_error'));
27
28 NavLinks::usersPages();
29 $navigator->set_focus('tab', 'users', null);
30
31 if (!can_perform('canadminusers'))
32 {
33 admin_login();
34 }
35
36 $thirty_days_ago = time() - (60 * 60 * 24 * 30);
37 $query = "
38 SELECT user.displayname, user.userid, user.email, useractivation.activator, useractivation.dateline FROM " . TABLE_PREFIX . "user AS user
39 LEFT JOIN " . TABLE_PREFIX . "useractivation AS useractivation
40 ON (user.userid = useractivation.userid)
41 WHERE user.usergroupid = 3
42 OR useractivation.dateline <= $thirty_days_ago";
43
44 // ###################################################################
45
46 if (empty($_REQUEST['do']))
47 {
48 $_REQUEST['do'] = 'modify';
49 }
50
51 // ###################################################################
52
53 if ($_REQUEST['do'] == 'kill')
54 {
55 $users = $db->query($query);
56 while ($user = $db->fetch_array($users))
57 {
58 $data = new UserAPI($bugsys);
59 $data->set('userid', $user['userid']);
60 $data->set_condition();
61 $data->delete();
62 }
63
64 $admin->redirect('purge_inactive.php');
65 }
66
67 // ###################################################################
68
69 if ($_REQUEST['do'] == 'delete')
70 {
71 $admin->page_confirm(T('Are you sure you want to remove all users who within the past thirty days have not verified their accounts via email?'), 'purge_inactive.php', 'kill', array());
72 }
73
74 // ###################################################################
75
76 if ($_REQUEST['do'] == 'modify')
77 {
78 NavLinks::usersAdd();
79
80 LoadPaginationFramework();
81 $pagination->setBitProcessor('AdminPageNavigatorBitCallback');
82 $pagination->setNavigatorProcessor('AdminPageNavigatorCallback');
83
84 $admin->page_start(T('Inactive Users'));
85 $admin->table_start();
86 $admin->table_head(T('Users Awaiting Email Confirmation for more than 30 Days'), 4);
87 $admin->table_column_head(array(T('Display Name'), T('Email'), T('User ID'), T('Actions')));
88
89 $count = $db->query_first("SELECT COUNT(*) AS count FROM ($query) AS inactive");
90 $pagination->setTotal($count['count']);
91 $pagination->splitPages();
92
93 $users = $db->query("
94 $query
95 ORDER BY userid ASC LIMIT " . $pagination->fetchLimit($pagination->getPage() - 1) . ", " . $pagination->getPerPage()
96 );
97 while ($user = $db->fetch_array($users))
98 {
99 $admin->row_multi_item(array(
100 $user['displayname'] => 'l',
101 $user['email'] => 'c',
102 $user['userid'] => 'c',
103 '<a href="user.php?do=edit&amp;userid=' . $user['userid'] . '">[' . T('Edit') . ']</a>' => 'c'
104 ));
105 }
106
107 $admin->row_tfoot('<a href="purge_inactive.php?do=delete">[Remove All]</a>', 4);
108
109 $admin->table_end();
110
111 $admin->page_code($pagination->constructPageNav('purge_inactive.php'));
112
113 $admin->page_end();
114 }