-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathduplicated_users.php
93 lines (78 loc) · 2.91 KB
/
duplicated_users.php
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
<?php
require_once 'include/general_page_base.php';
require_once 'include/pages.php';
define('PAGE_SIZE', USERS_PAGE_SIZE);
class Page extends GeneralPageBase
{
private $email;
private $email_title;
protected function prepare()
{
parent::prepare();
$this->email = NULL;
$this->email_title = NULL;
if (isset($_REQUEST['email']))
{
$this->email_title = $this->email = $_REQUEST['email'];
if ($this->email_title == '')
{
$this->email_title = '[' . get_label('no email') . ']';
}
$this->_title = get_label('Duplicated accounts for [0]', $this->email_title);
}
}
protected function show_body()
{
global $_page, $_lang;
check_permissions(PERMISSION_ADMIN);
if ($this->email_title != NULL)
{
list ($count) = Db::record(get_label('user'), 'SELECT count(*) FROM users WHERE email = ?', $this->email);
show_pages_navigation(PAGE_SIZE, $count);
echo '<table class="bordered light" width="100%">';
echo '<tr class="th darker"><td width="38"></td><td>'.get_label('Players with the same email').'</td><td width="100">Rating</td><td width="100">'.get_label('Games played').'</td></tr>';
$query = new DbQuery(
'SELECT u.id, nu.name, u.rating, u.games, u.flags'.
' FROM users u'.
' JOIN names nu ON nu.id = u.name_id AND (nu.langs & '.$_lang.') <> 0'.
' WHERE u.email = ?'.
' ORDER BY u.games DESC, u.rating DESC, nu.name LIMIT ' . ($_page * PAGE_SIZE) . ',' . PAGE_SIZE, $this->email);
while ($row = $query->next())
{
list ($id, $name, $rating, $games, $flags) = $row;
echo '<tr>';
echo '<td>';
$this->user_pic->set($id, $name, $flags);
$this->user_pic->show(ICONS_DIR, false, 36);
echo '</td>';
echo '<td><a href="merge_user.php?bck=1&id=' . $id . '">' . cut_long_name($name, 80) . '</a></td>';
echo '<td>' . $rating . '</td>';
echo '<td>' . $games . '</td></tr>';
}
echo '</table>';
show_pages_navigation(PAGE_SIZE, $count);
}
else
{
list ($count) = Db::record(get_label('user'), 'SELECT count(*) FROM (SELECT email, count(*) as cnt FROM users GROUP BY email HAVING cnt > 1) x');
show_pages_navigation(PAGE_SIZE, $count);
$query = new DbQuery(
'SELECT email, count(*) as cnt FROM users GROUP BY email HAVING cnt > 1 ORDER BY cnt DESC, email LIMIT ' . ($_page * PAGE_SIZE) . ',' . PAGE_SIZE);
echo '<table class="bordered light" width="100%">';
echo '<tr class="th darker"><td>' . get_label('Email') . '</td><td width="80">' . get_label('Count') . '</td></tr>';
while ($row = $query->next())
{
list ($email, $count) = $row;
echo '<tr>';
echo '<td><a href="duplicated_users.php?bck=1&email=' . $email . '">' . ($email == '' ? '[' . get_label('no email') . ']' : $email) . '</a></td>';
echo '<td>' . $count . '</td>';
echo '</tr>';
}
echo '</table>';
show_pages_navigation(PAGE_SIZE, $count);
}
}
}
$page = new Page();
$page->run('Duplicated accounts');
?>