~azzar1/unity/add-show-desktop-key

443 by dcoles
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0
1
<?php
2
/**
3
*
4
* @package acp
5
* @version $Id: acp_main.php,v 1.52 2007/11/27 15:13:50 kellanved Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8
*
9
*/
10
11
/**
12
* @ignore
13
*/
14
if (!defined('IN_PHPBB'))
15
{
16
	exit;
17
}
18
19
/**
20
* @package acp
21
*/
22
class acp_main
23
{
24
	var $u_action;
25
26
	function main($id, $mode)
27
	{
28
		global $config, $db, $user, $auth, $template;
29
		global $phpbb_root_path, $phpbb_admin_path, $phpEx;
30
31
		// Show restore permissions notice
32
		if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm'))
33
		{
34
			$this->tpl_name = 'acp_main';
35
			$this->page_title = 'ACP_MAIN';
36
37
			$sql = 'SELECT user_id, username, user_colour
38
				FROM ' . USERS_TABLE . '
39
				WHERE user_id = ' . $user->data['user_perm_from'];
40
			$result = $db->sql_query($sql);
41
			$user_row = $db->sql_fetchrow($result);
42
			$db->sql_freeresult($result);
43
44
			$perm_from = '<strong' . (($user_row['user_colour']) ? ' style="color: #' . $user_row['user_colour'] . '">' : '>');
45
			$perm_from .= ($user_row['user_id'] != ANONYMOUS) ? '<a href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $user_row['user_id']) . '">' : '';
46
			$perm_from .= $user_row['username'];
47
			$perm_from .= ($user_row['user_id'] != ANONYMOUS) ? '</a>' : '';
48
			$perm_from .= '</strong>';
49
50
			$template->assign_vars(array(
51
				'S_RESTORE_PERMISSIONS'		=> true,
52
				'U_RESTORE_PERMISSIONS'		=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm'),
53
				'PERM_FROM'					=> $perm_from,
54
				'L_PERMISSIONS_TRANSFERRED_EXPLAIN'	=> sprintf($user->lang['PERMISSIONS_TRANSFERRED_EXPLAIN'], $perm_from, append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm')),
55
			));
56
57
			return;
58
		}
59
60
		$action = request_var('action', '');
61
62
		if ($action)
63
		{
64
			if (!confirm_box(true))
65
			{
66
				switch ($action)
67
				{
68
					case 'online':
69
						$confirm = true;
70
						$confirm_lang = 'RESET_ONLINE_CONFIRM';
71
					break;
72
					case 'stats':
73
						$confirm = true;
74
						$confirm_lang = 'RESYNC_STATS_CONFIRM';
75
					break;
76
					case 'user':
77
						$confirm = true;
78
						$confirm_lang = 'RESYNC_POSTCOUNTS_CONFIRM';
79
					break;
80
					case 'date':
81
						$confirm = true;
82
						$confirm_lang = 'RESET_DATE_CONFIRM';
83
					break;
84
					case 'db_track':
85
						$confirm = true;
86
						$confirm_lang = 'RESYNC_POST_MARKING_CONFIRM';
87
					break;
88
					case 'purge_cache':
89
						$confirm = true;
90
						$confirm_lang = 'PURGE_CACHE_CONFIRM';
91
					break;
92
93
					default:
94
						$confirm = true;
95
						$confirm_lang = 'CONFIRM_OPERATION';
96
				}
97
98
				if ($confirm)
99
				{
100
					confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array(
101
						'i'			=> $id,
102
						'mode'		=> $mode,
103
						'action'	=> $action,
104
					)));
105
				}
106
			}
107
			else
108
			{
109
				switch ($action)
110
				{
111
					case 'online':
112
						if (!$auth->acl_get('a_board'))
113
						{
114
							trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
115
						}
116
117
						set_config('record_online_users', 1, true);
118
						set_config('record_online_date', time(), true);
119
						add_log('admin', 'LOG_RESET_ONLINE');
120
					break;
121
122
					case 'stats':
123
						if (!$auth->acl_get('a_board'))
124
						{
125
							trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
126
						}
127
128
						$sql = 'SELECT COUNT(post_id) AS stat
129
							FROM ' . POSTS_TABLE . '
130
							WHERE post_approved = 1';
131
						$result = $db->sql_query($sql);
132
						set_config('num_posts', (int) $db->sql_fetchfield('stat'), true);
133
						$db->sql_freeresult($result);
134
135
						$sql = 'SELECT COUNT(topic_id) AS stat
136
							FROM ' . TOPICS_TABLE . '
137
							WHERE topic_approved = 1';
138
						$result = $db->sql_query($sql);
139
						set_config('num_topics', (int) $db->sql_fetchfield('stat'), true);
140
						$db->sql_freeresult($result);
141
142
						$sql = 'SELECT COUNT(user_id) AS stat
143
							FROM ' . USERS_TABLE . '
144
							WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')';
145
						$result = $db->sql_query($sql);
146
						set_config('num_users', (int) $db->sql_fetchfield('stat'), true);
147
						$db->sql_freeresult($result);
148
149
						$sql = 'SELECT COUNT(attach_id) as stat
150
							FROM ' . ATTACHMENTS_TABLE . '
151
							WHERE is_orphan = 0';
152
						$result = $db->sql_query($sql);
153
						set_config('num_files', (int) $db->sql_fetchfield('stat'), true);
154
						$db->sql_freeresult($result);
155
156
						$sql = 'SELECT SUM(filesize) as stat
157
							FROM ' . ATTACHMENTS_TABLE . '
158
							WHERE is_orphan = 0';
159
						$result = $db->sql_query($sql);
160
						set_config('upload_dir_size', (int) $db->sql_fetchfield('stat'), true);
161
						$db->sql_freeresult($result);
162
						
163
						if (!function_exists('update_last_username'))
164
						{
165
							include($phpbb_root_path . "includes/functions_user.$phpEx");
166
						}
167
						update_last_username();
168
169
						add_log('admin', 'LOG_RESYNC_STATS');
170
					break;
171
172
					case 'user':
173
						if (!$auth->acl_get('a_board'))
174
						{
175
							trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
176
						}
177
178
						$sql = 'SELECT COUNT(p.post_id) AS num_posts, u.user_id
179
							FROM ' . USERS_TABLE . ' u
180
							LEFT JOIN  ' . POSTS_TABLE . ' p ON (u.user_id = p.poster_id AND p.post_postcount = 1)
181
							GROUP BY u.user_id';
182
						$result = $db->sql_query($sql);
183
184
						while ($row = $db->sql_fetchrow($result))
185
						{
186
							$db->sql_query('UPDATE ' . USERS_TABLE . " SET user_posts = {$row['num_posts']} WHERE user_id = {$row['user_id']}");
187
						}
188
						$db->sql_freeresult($result);
189
190
						add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
191
192
					break;
193
			
194
					case 'date':
195
						if (!$auth->acl_get('a_board'))
196
						{
197
							trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
198
						}
199
200
						set_config('board_startdate', time() - 1);
201
						add_log('admin', 'LOG_RESET_DATE');
202
					break;
203
				
204
					case 'db_track':
205
						switch ($db->sql_layer)
206
						{
207
							case 'sqlite':
208
							case 'firebird':
209
								$db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
210
							break;
211
212
							default:
213
								$db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
214
							break;
215
						}
216
217
						// This can get really nasty... therefore we only do the last six months
218
						$get_from_time = time() - (6 * 4 * 7 * 24 * 60 * 60);
219
220
						// Select forum ids, do not include categories
221
						$sql = 'SELECT forum_id
222
							FROM ' . FORUMS_TABLE . '
223
							WHERE forum_type <> ' . FORUM_CAT;
224
						$result = $db->sql_query($sql);
225
				
226
						$forum_ids = array();
227
						while ($row = $db->sql_fetchrow($result))
228
						{
229
							$forum_ids[] = $row['forum_id'];
230
						}
231
						$db->sql_freeresult($result);
232
233
						// Any global announcements? ;)
234
						$forum_ids[] = 0;
235
236
						// Now go through the forums and get us some topics...
237
						foreach ($forum_ids as $forum_id)
238
						{
239
							$sql = 'SELECT p.poster_id, p.topic_id
240
								FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
241
								WHERE t.forum_id = ' . $forum_id . '
242
									AND t.topic_moved_id = 0
243
									AND t.topic_last_post_time > ' . $get_from_time . '
244
									AND t.topic_id = p.topic_id
245
									AND p.poster_id <> ' . ANONYMOUS . '
246
								GROUP BY p.poster_id, p.topic_id';
247
							$result = $db->sql_query($sql);
248
249
							$posted = array();
250
							while ($row = $db->sql_fetchrow($result))
251
							{
252
								$posted[$row['poster_id']][] = $row['topic_id'];
253
							}
254
							$db->sql_freeresult($result);
255
256
							$sql_ary = array();
257
							foreach ($posted as $user_id => $topic_row)
258
							{
259
								foreach ($topic_row as $topic_id)
260
								{
261
									$sql_ary[] = array(
262
										'user_id'		=> (int) $user_id,
263
										'topic_id'		=> (int) $topic_id,
264
										'topic_posted'	=> 1,
265
									);
266
								}
267
							}
268
							unset($posted);
269
270
							if (sizeof($sql_ary))
271
							{
272
								$db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
273
							}
274
						}
275
			
276
						add_log('admin', 'LOG_RESYNC_POST_MARKING');
277
					break;
278
279
					case 'purge_cache':
280
						if ((int) $user->data['user_type'] !== USER_FOUNDER)
281
						{
282
							trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
283
						}
284
285
						global $cache;
286
						$cache->purge();
287
288
						// Clear permissions
289
						$auth->acl_clear_prefetch();
290
						cache_moderators();
291
292
						add_log('admin', 'LOG_PURGE_CACHE');
293
					break;
294
				}
295
			}
296
		}
297
298
		// Get forum statistics
299
		$total_posts = $config['num_posts'];
300
		$total_topics = $config['num_topics'];
301
		$total_users = $config['num_users'];
302
		$total_files = $config['num_files'];
303
304
		$start_date = $user->format_date($config['board_startdate']);
305
306
		$boarddays = (time() - $config['board_startdate']) / 86400;
307
308
		$posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
309
		$topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
310
		$users_per_day = sprintf('%.2f', $total_users / $boarddays);
311
		$files_per_day = sprintf('%.2f', $total_files / $boarddays);
312
313
		$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']));
314
315
		$avatar_dir_size = 0;
316
317
		if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path']))
318
		{
319
			while (($file = readdir($avatar_dir)) !== false)
320
			{
321
				if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false)
322
				{
323
					$avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file);
324
				}
325
			}
326
			closedir($avatar_dir);
327
328
			// This bit of code translates the avatar directory size into human readable format
329
			// Borrowed the code from the PHP.net annoted manual, origanally written by:
330
			// Jesse (jesse@jess.on.ca)
331
			$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));
332
		}
333
		else
334
		{
335
			// Couldn't open Avatar dir.
336
			$avatar_dir_size = $user->lang['NOT_AVAILABLE'];
337
		}
338
339
		if ($posts_per_day > $total_posts)
340
		{
341
			$posts_per_day = $total_posts;
342
		}
343
344
		if ($topics_per_day > $total_topics)
345
		{
346
			$topics_per_day = $total_topics;
347
		}
348
349
		if ($users_per_day > $total_users)
350
		{
351
			$users_per_day = $total_users;
352
		}
353
354
		if ($files_per_day > $total_files)
355
		{
356
			$files_per_day = $total_files;
357
		}
358
359
		if ($config['allow_attachments'] || $config['allow_pm_attach'])
360
		{
361
			$sql = 'SELECT COUNT(attach_id) AS total_orphan
362
				FROM ' . ATTACHMENTS_TABLE . '
363
				WHERE is_orphan = 1
364
					AND filetime < ' . (time() - 3*60*60);
365
			$result = $db->sql_query($sql);
366
			$total_orphan = (int) $db->sql_fetchfield('total_orphan');
367
			$db->sql_freeresult($result);
368
		}
369
		else
370
		{
371
			$total_orphan = false;
372
		}
373
374
		$dbsize = get_database_size();
375
376
		$template->assign_vars(array(
377
			'TOTAL_POSTS'		=> $total_posts,
378
			'POSTS_PER_DAY'		=> $posts_per_day,
379
			'TOTAL_TOPICS'		=> $total_topics,
380
			'TOPICS_PER_DAY'	=> $topics_per_day,
381
			'TOTAL_USERS'		=> $total_users,
382
			'USERS_PER_DAY'		=> $users_per_day,
383
			'TOTAL_FILES'		=> $total_files,
384
			'FILES_PER_DAY'		=> $files_per_day,
385
			'START_DATE'		=> $start_date,
386
			'AVATAR_DIR_SIZE'	=> $avatar_dir_size,
387
			'DBSIZE'			=> $dbsize,
388
			'UPLOAD_DIR_SIZE'	=> $upload_dir_size,
389
			'TOTAL_ORPHAN'		=> $total_orphan,
390
			'S_TOTAL_ORPHAN'	=> ($total_orphan === false) ? false : true,
391
			'GZIP_COMPRESSION'	=> ($config['gzip_compress']) ? $user->lang['ON'] : $user->lang['OFF'],
392
			'DATABASE_INFO'		=> $db->sql_server_info(),
393
			'BOARD_VERSION'		=> $config['version'],
394
395
			'U_ACTION'			=> append_sid("{$phpbb_admin_path}index.$phpEx"),
396
			'U_ADMIN_LOG'		=> append_sid("{$phpbb_admin_path}index.$phpEx", 'i=logs&amp;mode=admin'),
397
			'U_INACTIVE_USERS'	=> append_sid("{$phpbb_admin_path}index.$phpEx", 'i=inactive&amp;mode=list'),
398
399
			'S_ACTION_OPTIONS'	=> ($auth->acl_get('a_board')) ? true : false,
400
			'S_FOUNDER'			=> ($user->data['user_type'] == USER_FOUNDER) ? true : false,
401
			)
402
		);
403
404
		$log_data = array();
405
		$log_count = 0;
406
407
		if ($auth->acl_get('a_viewlogs'))
408
		{
409
			view_log('admin', $log_data, $log_count, 5);
410
411
			foreach ($log_data as $row)
412
			{
413
				$template->assign_block_vars('log', array(
414
					'USERNAME'	=> $row['username_full'],
415
					'IP'		=> $row['ip'],
416
					'DATE'		=> $user->format_date($row['time']),
417
					'ACTION'	=> $row['action'])
418
				);
419
			}
420
		}
421
422
		if ($auth->acl_get('a_user'))
423
		{
424
			$inactive = array();
425
			$inactive_count = 0;
426
427
			view_inactive_users($inactive, $inactive_count, 10);
428
429
			foreach ($inactive as $row)
430
			{
431
				$template->assign_block_vars('inactive', array(
432
					'INACTIVE_DATE'	=> $user->format_date($row['user_inactive_time']),
433
					'JOINED'		=> $user->format_date($row['user_regdate']),
434
					'LAST_VISIT'	=> (!$row['user_lastvisit']) ? ' - ' : $user->format_date($row['user_lastvisit']),
435
					'REASON'		=> $row['inactive_reason'],
436
					'USER_ID'		=> $row['user_id'],
437
					'USERNAME'		=> $row['username'],
438
					'U_USER_ADMIN'	=> append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;mode=overview&amp;u={$row['user_id']}"))
439
				);
440
			}
441
442
			$option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
443
			if ($config['email_enable'])
444
			{
445
				$option_ary += array('remind' => 'REMIND');
446
			}
447
448
			$template->assign_vars(array(
449
				'S_INACTIVE_USERS'		=> true,
450
				'S_INACTIVE_OPTIONS'	=> build_select($option_ary))
451
			);
452
		}
453
454
		// Warn if install is still present
455
		if (file_exists($phpbb_root_path . 'install'))
456
		{
457
			$template->assign_var('S_REMOVE_INSTALL', true);
458
		}
459
460
		$this->tpl_name = 'acp_main';
461
		$this->page_title = 'ACP_MAIN';
462
	}
463
}
464
465
?>