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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
<?php
/**
*
* @package acp
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @package acp
*/
class acp_main
{
var $u_action;
function main($id, $mode)
{
global $config, $db, $user, $auth, $template;
global $SID, $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
$action = request_var('action', '');
$mark = (isset($_REQUEST['mark'])) ? implode(', ', request_var('mark', array(0))) : '';
if ($mark)
{
switch ($action)
{
case 'activate':
case 'delete':
if (!$auth->acl_get('a_user'))
{
trigger_error($user->lang['NO_ADMIN']);
}
$sql = 'SELECT username
FROM ' . USERS_TABLE . "
WHERE user_id IN ($mark)";
$result = $db->sql_query($sql);
$user_affected = array();
while ($row = $db->sql_fetchrow($result))
{
$user_affected[] = $row['username'];
}
$db->sql_freeresult($result);
if ($action == 'activate')
{
include($phpbb_root_path . 'includes/functions_user.php');
$mark_ary = explode(', ', $mark);
foreach ($mark_ary as $user_id)
{
user_active_flip($user_id, USER_INACTIVE);
}
set_config('num_users', $config['num_users'] + sizeof($mark_ary), true);
// Get latest username
$sql = 'SELECT user_id, username
FROM ' . USERS_TABLE . '
WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')
ORDER BY user_id DESC';
$result = $db->sql_query_limit($sql, 1);
if ($row = $db->sql_fetchrow($result))
{
set_config('newest_user_id', $row['user_id']);
set_config('newest_username', $row['username']);
}
$db->sql_freeresult($result);
}
else if ($action == 'delete')
{
if (!$auth->acl_get('a_userdel'))
{
trigger_error($user->lang['NO_ADMIN']);
}
$sql = 'DELETE FROM ' . USER_GROUP_TABLE . " WHERE user_id IN ($mark)";
$db->sql_query($sql);
$sql = 'DELETE FROM ' . USERS_TABLE . " WHERE user_id IN ($mark)";
$db->sql_query($sql);
add_log('admin', 'LOG_INDEX_' . strtoupper($action), implode(', ', $user_affected));
}
break;
case 'remind':
if (!$auth->acl_get('a_user'))
{
trigger_error($user->lang['NO_ADMIN']);
}
if (empty($config['email_enable']))
{
trigger_error($user->lang['EMAIL_DISABLED']);
}
$sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type, user_regdate, user_actkey
FROM ' . USERS_TABLE . "
WHERE user_id IN ($mark)";
$result = $db->sql_query($sql);
if ($row = $db->sql_fetchrow($result))
{
// Send the messages
include_once($phpbb_root_path . 'includes/functions_messenger.'.$phpEx);
$messenger = new messenger();
$board_url = generate_board_url() . "/ucp.$phpEx?mode=activate";
$sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']);
$usernames = array();
do
{
$messenger->template('user_remind_inactive', $row['user_lang']);
$messenger->replyto($config['board_email']);
$messenger->to($row['user_email'], $row['username']);
$messenger->im($row['user_jabber'], $row['username']);
$messenger->assign_vars(array(
'EMAIL_SIG' => $sig,
'USERNAME' => $row['username'],
'SITENAME' => $config['sitename'],
'REGISTER_DATE' => $user->format_date($row['user_regdate']),
'U_ACTIVATE' => "$board_url&mode=activate&u=" . $row['user_id'] . '&k=' . $row['user_actkey'])
);
$messenger->send($row['user_notify_type']);
$usernames[] = $row['username'];
}
while ($row = $db->sql_fetchrow($result));
$messenger->save_queue();
add_log('admin', 'LOG_INDEX_REMIND', implode(', ', $usernames));
unset($usernames);
}
$db->sql_freeresult($result);
break;
}
}
switch ($action)
{
case 'online':
if (!$auth->acl_get('a_defaults'))
{
trigger_error($user->lang['NO_ADMIN']);
}
set_config('record_online_users', 1, true);
set_config('record_online_date', time(), true);
add_log('admin', 'LOG_RESET_ONLINE');
break;
case 'stats':
if (!$auth->acl_get('a_defaults'))
{
trigger_error($user->lang['NO_ADMIN']);
}
$sql = 'SELECT COUNT(post_id) AS stat
FROM ' . POSTS_TABLE . '
WHERE post_approved = 1';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
set_config('num_posts', (int) $row['stat'], true);
$sql = 'SELECT COUNT(topic_id) AS stat
FROM ' . TOPICS_TABLE . '
WHERE topic_approved = 1';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
set_config('num_topics', (int) $row['stat'], true);
$sql = 'SELECT COUNT(user_id) AS stat
FROM ' . USERS_TABLE . '
WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
set_config('num_users', (int) $row['stat'], true);
$sql = 'SELECT COUNT(attach_id) as stat
FROM ' . ATTACHMENTS_TABLE;
$result = $db->sql_query($sql);
set_config('num_files', (int) $db->sql_fetchfield('stat'), true);
$db->sql_freeresult($result);
$sql = 'SELECT SUM(filesize) as stat
FROM ' . ATTACHMENTS_TABLE;
$result = $db->sql_query($sql);
set_config('upload_dir_size', (int) $db->sql_fetchfield('stat'), true);
$db->sql_freeresult($result);
add_log('admin', 'LOG_RESYNC_STATS');
break;
case 'user':
if (!$auth->acl_get('a_defaults'))
{
trigger_error($user->lang['NO_ADMIN']);
}
$post_count_ary = $auth->acl_getf('f_postcount');
$forum_read_ary = $auth->acl_getf('f_read');
$forum_ary = array();
foreach ($post_count_ary as $forum_id => $allowed)
{
if ($allowed['f_postcount'] && $forum_read_ary[$forum_id]['f_read'])
{
$forum_ary[] = $forum_id;
}
}
if (!sizeof($forum_ary))
{
$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0');
}
else
{
$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
FROM ' . POSTS_TABLE . '
WHERE poster_id <> ' . ANONYMOUS . '
AND forum_id IN (' . implode(', ', $forum_ary) . ')
GROUP BY poster_id';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$db->sql_query('UPDATE ' . USERS_TABLE . " SET user_posts = {$row['num_posts']} WHERE user_id = {$row['poster_id']}");
}
$db->sql_freeresult($result);
}
add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
break;
case 'date':
if (!$auth->acl_get('a_defaults'))
{
trigger_error($user->lang['NO_ADMIN']);
}
set_config('board_startdate', time() - 1);
add_log('admin', 'LOG_RESET_DATE');
break;
}
// Get forum statistics
$total_posts = $config['num_posts'];
$total_topics = $config['num_topics'];
$total_users = $config['num_users'];
$total_files = $config['num_files'];
$start_date = $user->format_date($config['board_startdate']);
$boarddays = (time() - $config['board_startdate']) / 86400;
$posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
$topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
$users_per_day = sprintf('%.2f', $total_users / $boarddays);
$files_per_day = sprintf('%.2f', $total_files / $boarddays);
$upload_dir_size = ($config['upload_dir_size'] >= 1048576) ? sprintf('%.2f ' . $user->lang['MB'], ($config['upload_dir_size'] / 1048576)) : (($config['upload_dir_size'] >= 1024) ? sprintf('%.2f ' . $user->lang['KB'], ($config['upload_dir_size'] / 1024)) : sprintf('%.2f ' . $user->lang['BYTES'], $config['upload_dir_size']));
$avatar_dir_size = 0;
if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path']))
{
while ($file = readdir($avatar_dir))
{
if ($file{0} != '.')
{
$avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file);
}
}
@closedir($avatar_dir);
// This bit of code translates the avatar directory size into human readable format
// Borrowed the code from the PHP.net annoted manual, origanally written by:
// Jesse (jesse@jess.on.ca)
$avatar_dir_size = ($avatar_dir_size >= 1048576) ? sprintf('%.2f ' . $user->lang['MB'], ($avatar_dir_size / 1048576)) : (($avatar_dir_size >= 1024) ? sprintf('%.2f ' . $user->lang['KB'], ($avatar_dir_size / 1024)) : sprintf('%.2f ' . $user->lang['BYTES'], $avatar_dir_size));
}
else
{
// Couldn't open Avatar dir.
$avatar_dir_size = $user->lang['NOT_AVAILABLE'];
}
if ($posts_per_day > $total_posts)
{
$posts_per_day = $total_posts;
}
if ($topics_per_day > $total_topics)
{
$topics_per_day = $total_topics;
}
if ($users_per_day > $total_users)
{
$users_per_day = $total_users;
}
if ($files_per_day > $total_files)
{
$files_per_day = $total_files;
}
$dbsize = get_database_size();
$s_action_options = build_select(array('online' => 'RESET_ONLINE', 'date' => 'RESET_DATE', 'stats' => 'RESYNC_STATS', 'user' => 'RESYNC_POSTCOUNTS'));
$template->assign_vars(array(
'TOTAL_POSTS' => $total_posts,
'POSTS_PER_DAY' => $posts_per_day,
'TOTAL_TOPICS' => $total_topics,
'TOPICS_PER_DAY' => $topics_per_day,
'TOTAL_USERS' => $total_users,
'USERS_PER_DAY' => $users_per_day,
'TOTAL_FILES' => $total_files,
'FILES_PER_DAY' => $files_per_day,
'START_DATE' => $start_date,
'AVATAR_DIR_SIZE' => $avatar_dir_size,
'DBSIZE' => $dbsize,
'UPLOAD_DIR_SIZE' => $upload_dir_size,
'GZIP_COMPRESSION' => ($config['gzip_compress']) ? $user->lang['ON'] : $user->lang['OFF'],
'U_ACTION' => "{$phpbb_admin_path}index.$phpEx$SID",
'S_ACTION_OPTIONS' => $s_action_options,
)
);
$log_data = array();
$log_count = 0;
if ($auth->acl_get('a_viewlogs'))
{
view_log('admin', $log_data, $log_count, 5);
foreach ($log_data as $row)
{
$template->assign_block_vars('log', array(
'USERNAME' => $row['username'],
'IP' => $row['ip'],
'DATE' => $user->format_date($row['time']),
'ACTION' => $row['action'])
);
}
}
if ($auth->acl_get('a_user'))
{
$sql = 'SELECT user_id, username, user_regdate
FROM ' . USERS_TABLE . '
WHERE user_type = ' . USER_INACTIVE . '
ORDER BY user_regdate ASC';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$template->assign_block_vars('inactive', array(
'DATE' => $user->format_date($row['user_regdate']),
'USER_ID' => $row['user_id'],
'USERNAME' => $row['username'],
'U_USER_ADMIN' => "{$phpbb_admin_path}admin_users.$phpEx$SID&u={$row['user_id']}")
);
}
$option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
if ($config['email_enable'])
{
$option_ary += array('remind' => 'REMIND');
}
$template->assign_vars(array(
'S_INACTIVE_USERS' => true,
'S_INACTIVE_OPTIONS' => build_select($option_ary))
);
}
$this->tpl_name = 'acp_main';
$this->page_title = 'ACP_MAIN';
}
}
?>
|