1 | <?php |
---|
2 | defined('SUBSCRIBE_TO_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | if (isset($_GET['delete'])) |
---|
5 | { |
---|
6 | $query = ' |
---|
7 | DELETE FROM '.SUBSCRIBE_TO_TABLE.' |
---|
8 | WHERE email = "'.$_GET['delete'].'" |
---|
9 | ;'; |
---|
10 | pwg_query($query); |
---|
11 | } |
---|
12 | |
---|
13 | // get subscriptions |
---|
14 | $query = ' |
---|
15 | SELECT |
---|
16 | MIN(registration_date) AS min_date, |
---|
17 | MAX(registration_date) AS max_date, |
---|
18 | email |
---|
19 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
20 | GROUP BY email |
---|
21 | ;'; |
---|
22 | $dates = hash_from_query($query, 'email'); |
---|
23 | |
---|
24 | $query = ' |
---|
25 | SELECT |
---|
26 | sub.email, |
---|
27 | sub.type, |
---|
28 | u.'.$conf['user_fields']['username'].' AS username |
---|
29 | FROM '.SUBSCRIBE_TO_TABLE.' AS sub |
---|
30 | LEFT JOIN '.USERS_TABLE.' AS u |
---|
31 | ON u.'.$conf['user_fields']['email'].' = sub.email'; |
---|
32 | if (!empty($_POST['username'])) |
---|
33 | { |
---|
34 | $_POST['username'] = strtolower($_POST['username']); |
---|
35 | $query.= ' |
---|
36 | WHERE LOWER(username) LIKE "%'.$_POST['username'].'%" OR LOWER(email) LIKE "%'.$_POST['username'].'%"'; |
---|
37 | } |
---|
38 | $query.= ' |
---|
39 | ORDER BY email ASC |
---|
40 | ;'; |
---|
41 | $result = pwg_query($query); |
---|
42 | |
---|
43 | $users = array(); |
---|
44 | while ($row = pwg_db_fetch_assoc($result)) |
---|
45 | { |
---|
46 | if (empty($users[ $row['email'] ])) |
---|
47 | { |
---|
48 | $users[ $row['email'] ] = array( |
---|
49 | 'email' => $row['email'], |
---|
50 | 'username' => $row['username'], |
---|
51 | 'url' => make_stc_url('manage', $row['email']), |
---|
52 | 'min_date' => strtotime($dates[ $row['email'] ]['min_date']), |
---|
53 | 'max_date' => strtotime($dates[ $row['email'] ]['max_date']), |
---|
54 | 'nice_min_date' => format_date($dates[ $row['email'] ]['min_date']), |
---|
55 | 'nice_max_date' => format_date($dates[ $row['email'] ]['max_date']), |
---|
56 | 'u_delete' => SUBSCRIBE_TO_ADMIN . '-subscriptions&delete=' . $row['email'], |
---|
57 | 'subs' => array( |
---|
58 | 'image' => 0, |
---|
59 | 'album_images' => 0, |
---|
60 | 'all_images' => 0, |
---|
61 | 'album' => 0, |
---|
62 | 'all_albums' => 0 |
---|
63 | ), |
---|
64 | ); |
---|
65 | } |
---|
66 | |
---|
67 | $row['type'] = str_replace('-', '_', $row['type']); // fields are accessed in Smarty, incompatible with keys containing a '-' |
---|
68 | $users[ $row['email'] ]['subs'][ $row['type'] ]++; |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | // sort results |
---|
73 | if (count($users)) |
---|
74 | { |
---|
75 | if (isset($_POST['filter'])) |
---|
76 | { |
---|
77 | uasort($users, 'stc_sort_'.$_POST['order_by']); |
---|
78 | |
---|
79 | if ($_POST['direction'] == 'DESC') |
---|
80 | { |
---|
81 | $users = array_reverse($users); |
---|
82 | } |
---|
83 | } |
---|
84 | else |
---|
85 | { |
---|
86 | uasort($users, 'stc_sort_user'); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | // filter options |
---|
92 | $page['order_by_items'] = array( |
---|
93 | 'user' => l10n('User'), |
---|
94 | 'min_date' => l10n('First subscription'), |
---|
95 | 'max_date' => l10n('Last subscription'), |
---|
96 | 'image' => l10n('Photos'), |
---|
97 | 'album_images' => l10n('All album photos'), |
---|
98 | 'album' => l10n('Albums'), |
---|
99 | ); |
---|
100 | |
---|
101 | $page['direction_items'] = array( |
---|
102 | 'ASC' => l10n('ascending'), |
---|
103 | 'DESC' => l10n('descending'), |
---|
104 | ); |
---|
105 | |
---|
106 | $template->assign(array( |
---|
107 | 'order_options' => $page['order_by_items'], |
---|
108 | 'order_selected' => isset($_POST['order_by']) ? $_POST['order_by'] : 'user', |
---|
109 | 'direction_options' => $page['direction_items'], |
---|
110 | 'direction_selected' => isset($_POST['direction']) ? $_POST['direction'] : 'ASC', |
---|
111 | |
---|
112 | 'F_USERNAME' => @htmlentities($_POST['username'], ENT_COMPAT, 'UTF-8'), |
---|
113 | 'F_FILTER_ACTION' => SUBSCRIBE_TO_ADMIN . '-subscriptions', |
---|
114 | |
---|
115 | 'USERS' => $users, |
---|
116 | 'COA_ACTIVATED' => defined('COA_ID'), |
---|
117 | )); |
---|
118 | |
---|
119 | $template->set_filename('stc_admin', realpath(SUBSCRIBE_TO_PATH . 'admin/template/subscriptions.tpl')); |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | function stc_sort_image($a, $b) |
---|
124 | { |
---|
125 | if ($a['subs']['all_images']) return 1; |
---|
126 | if ($b['subs']['all_images']) return -1; |
---|
127 | return $a['subs']['image'] - $b['subs']['image']; |
---|
128 | } |
---|
129 | |
---|
130 | function stc_sort_album_images($a, $b) |
---|
131 | { |
---|
132 | if ($a['subs']['all_images']) return 1; |
---|
133 | if ($b['subs']['all_images']) return -1; |
---|
134 | return $a['subs']['album_images'] - $b['subs']['album_images']; |
---|
135 | } |
---|
136 | |
---|
137 | function stc_sort_album($a, $b) |
---|
138 | { |
---|
139 | if ($a['subs']['all_albums']) return 1; |
---|
140 | if ($b['subs']['all_albums']) return -1; |
---|
141 | return $a['subs']['album'] - $b['subs']['album']; |
---|
142 | } |
---|
143 | |
---|
144 | function stc_sort_min_date($a, $b) |
---|
145 | { |
---|
146 | return $a['min_date'] - $b['min_date']; |
---|
147 | } |
---|
148 | |
---|
149 | function stc_sort_max_date($a, $b) |
---|
150 | { |
---|
151 | return $a['max_date'] - $b['max_date']; |
---|
152 | } |
---|
153 | |
---|
154 | function stc_sort_user($a, $b) |
---|
155 | { |
---|
156 | return strcasecmp($a['username'].$a['email'], $b['username'].$b['email']); |
---|
157 | } |
---|