PageRenderTime 31ms CodeModel.GetById 15ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/upload/admin/admin_log.php

http://torrentpier2.googlecode.com/
PHP | 416 lines | 310 code | 75 blank | 31 comment | 42 complexity | 275c20878a09051cd4c8ae92becee73d MD5 | raw file
  1<?php
  2
  3// ACP Header - START
  4if (!empty($setmodules))
  5{
  6	$module['Users']['Actions_log'] = basename(__FILE__);
  7	return;
  8}
  9require('./pagestart.php');
 10// ACP Header - END
 11
 12$datastore->enqueue(array(
 13	'moderators',
 14));
 15
 16$log_action->init();
 17
 18$per_page            = 50;
 19$row_class_1         = 'row1';
 20$row_class_2         = 'row2';
 21$def_days            = 3;
 22$def_datetime        = TIMENOW;
 23$max_forum_name_len  = 40;
 24$title_match_max_len = 60;
 25$poster_name_max_len = 25;
 26$select_max_height   = 16;
 27$dt_format           = 'Y-m-d';   // used in one-day filter
 28
 29$url = basename(__FILE__);
 30
 31// Key names
 32$type_key        = 'type';
 33$forum_key       = 'f';
 34$topic_key       = 't';
 35$user_key        = 'u';
 36$datetime_key    = 'dt';   // value should be strtotime() time ("2006-06-25" etc.)
 37$daysback_key    = 'db';
 38$sort_key        = 'sort';
 39$title_match_key = 'tm';
 40
 41// Key values
 42$all_types  = 0;  // =|
 43$all_users  = 0;  //  |> only "0" is a valid value
 44$all_forums = 0;  // =|
 45
 46$sort_asc   = 'ASC';
 47$sort_desc  = 'DESC';
 48
 49// Defaults
 50$def_types  = $all_types;
 51$def_users  = $all_users;
 52$def_forums = $all_forums;
 53$def_sort   = $sort_desc;
 54
 55// Moderators data
 56if (!$mod = $datastore->get('moderators'))
 57{
 58	$datastore->update('moderators');
 59	$mod = $datastore->get('moderators');
 60}
 61array_deep($mod['moderators'], 'html_entity_decode');
 62array_deep($mod['admins'], 'html_entity_decode');
 63
 64$users = array($lang['ACTS_LOG_ALL_ACTIONS'] => $all_users) + array_flip($mod['moderators']) + array_flip($mod['admins']);
 65
 66unset($mod);
 67
 68// Forums data
 69if (!$forums = $datastore->get('cat_forums'))
 70{
 71	$datastore->update('cat_forums');
 72	$forums = $datastore->get('cat_forums');
 73}
 74$f_data = $forums['f'];
 75
 76unset($forums);
 77
 78// Start
 79$start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0;
 80
 81// Type
 82$type_selected = array($def_types);
 83$type_csv = '';
 84
 85if ($var =& $_REQUEST[$type_key])
 86{
 87	$type_selected = get_id_ary($var);
 88
 89	if (in_array($all_types, $type_selected))
 90	{
 91		$type_selected = array($all_types);
 92	}
 93	$type_csv = join(',', $type_selected);
 94	$url = ($type_csv != $def_types) ? url_arg($url, $type_key, $type_csv) : $url;
 95}
 96
 97// User
 98$user_selected = array($def_users);
 99$user_csv = '';
100
101if ($var =& $_REQUEST[$user_key])
102{
103	$user_selected = get_id_ary($var);
104
105	if (in_array($all_users, $user_selected))
106	{
107		$user_selected = array($all_users);
108	}
109	$user_csv = join(',', $user_selected);
110	$url = ($user_csv != $def_users) ? url_arg($url, $user_key, $user_csv) : $url;
111}
112
113// Forum
114$forum_selected = array($def_forums);
115$forum_csv = '';
116
117if ($var =& $_REQUEST[$forum_key])
118{
119	$forum_selected = get_id_ary($var);
120
121	if (in_array($all_forums, $forum_selected))
122	{
123		$forum_selected = array($all_forums);
124	}
125	$forum_csv = join(',', $forum_selected);
126	$url = ($forum_csv != $def_forums) ? url_arg($url, $forum_key, $forum_csv) : $url;
127}
128
129// Topic
130$topic_selected = null;
131$topic_csv = '';
132
133if ($var =& $_REQUEST[$topic_key])
134{
135	$topic_selected = get_id_ary($var);
136	$topic_csv = join(',', $topic_selected);
137	$url = ($topic_csv) ? url_arg($url, $topic_key, $topic_csv) : $url;
138}
139
140// Order
141$order_val = 'log_time';
142
143// Sort
144$sort_val = $def_sort;
145
146if ($var =& $_REQUEST[$sort_key] AND $var != $def_sort)
147{
148	$sort_val = ($var == $sort_asc) ? $sort_asc : $sort_desc;
149	$url = url_arg($url, $sort_key, $sort_val);
150}
151
152// Time
153$datetime_val = $def_datetime;
154$daysback_val = $def_days;
155
156if ($var =& $_REQUEST[$daysback_key] AND $var != $def_days)
157{
158	$daysback_val = max(intval($var), 1);
159	$url = url_arg($url, $daysback_key, $daysback_val);
160}
161if ($var =& $_REQUEST[$datetime_key] AND $var != $def_datetime)
162{
163	$tz = TIMENOW + (3600 * $bb_cfg['board_timezone']);
164	if (($tmp_timestamp = strtotime($var, $tz)) > 0)
165	{
166		$datetime_val = $tmp_timestamp;
167		$url = url_arg($url, $datetime_key, date($dt_format, $datetime_val));
168	}
169}
170
171$time_end_val = 86400 + mktime(0, 0, 0, date('m', $datetime_val), date('d', $datetime_val), date('Y', $datetime_val));
172$time_start_val = $time_end_val - 86400*$daysback_val;
173
174// First log time
175$row = DB()->fetch_row("SELECT MIN(log_time) AS first_log_time FROM ". BB_LOG);
176$first_log_time = (int) $row['first_log_time'];
177
178// Title match
179$title_match_val = $title_match_sql = '';
180
181if ($var =& $_REQUEST[$title_match_key])
182{
183	if ($tmp_title_match = substr(urldecode(trim($var)), 0, $title_match_max_len))
184	{
185		$title_match_sql = DB()->escape($tmp_title_match);
186		$url = url_arg($url, $title_match_key, urlencode($tmp_title_match));
187	}
188}
189
190//
191// SQL
192//
193$select = "SELECT *";
194
195$from = "FROM ". BB_LOG;
196
197$where = "
198	WHERE log_time BETWEEN $time_start_val AND $time_end_val
199";
200$where .= ($type_csv) ? "
201		AND log_type_id IN($type_csv)
202" :	'';
203$where .= ($user_csv) ? "
204		AND log_user_id IN($user_csv)
205" :	'';
206$where .= ($forum_csv) ? "
207		AND log_forum_id IN($forum_csv)
208" :	'';
209$where .= ($topic_csv) ? "
210		AND log_topic_id IN($topic_csv)
211" :	'';
212$where .= ($title_match_sql) ? "
213		AND MATCH (log_topic_title) AGAINST ('$title_match_sql' IN BOOLEAN MODE)
214" :	'';
215
216$order = "ORDER BY $order_val";
217
218$sort = $sort_val;
219
220$limit = "LIMIT $start, ". ($per_page + 1);
221
222$sql = "
223	$select
224	$from
225	$where
226	$order
227		$sort
228	$limit
229";
230
231$log_rowset = DB()->fetch_rowset($sql);
232$log_count = count($log_rowset);
233
234if ($log_count == $per_page + 1)
235{
236	$items_count = $start + ($per_page * 2);
237	$pages = '?';
238	array_pop($log_rowset);
239}
240else
241{
242	$items_count = $start + $log_count;
243	$pages = (!$log_count) ? 1 : ceil($items_count / $per_page);
244}
245
246generate_pagination($url, $items_count, $per_page, $start);
247
248
249$filter = array();
250
251if ($log_rowset)
252{
253	$log_type = $log_action->log_type;
254	$log_type_flip = array_flip($log_type);
255
256	foreach ($log_rowset as $row_num => $row)
257	{
258		$msg = '';
259		$forum_name = $forum_name_new = '';
260		$topic_title = $topic_title_new = '';
261
262		$topic_deleted = ($row['log_type_id'] == $log_type['mod_topic_delete']);
263
264		switch ($row['log_type_id'])
265		{
266			case $log_type['mod_topic_delete']:
267			case $log_type['mod_topic_move']:
268			case $log_type['mod_topic_lock']:
269			case $log_type['mod_topic_unlock']:
270			case $log_type['mod_post_delete']:
271			case $log_type['mod_topic_split']:
272				// topic_title
273				if (!empty($row['log_topic_title']))
274				{
275					$topic_title = $row['log_topic_title'];
276				}
277				// topic_title_new
278				if (!empty($row['log_topic_title_new']))
279				{
280					$topic_title_new = $row['log_topic_title_new'];
281				}
282				// forum_name
283				if ($fid =& $row['log_forum_id'])
284				{
285					$forum_name = ($fname =& $f_data[$fid]['forum_name']) ? $fname : 'id:'. $row['log_forum_id'];
286				}
287				// forum_name_new
288				if ($fid =& $row['log_forum_id_new'])
289				{
290					$forum_name_new = ($fname =& $f_data[$fid]['forum_name']) ? $fname : 'id:'. $row['log_forum_id'];
291				}
292
293			break;
294		}
295
296		$msg .= " $row[log_msg]";
297
298		$row_class = !($row_num & 1) ? $row_class_1 : $row_class_2;
299
300		$datetime_href_s = url_arg($url, $datetime_key, date($dt_format, $row['log_time']));
301		$datetime_href_s = url_arg($datetime_href_s, $daysback_key, 1);
302
303		$template->assign_block_vars('log', array(
304			'ACTION_DESC'      => $lang['LOG_ACTION']['LOG_TYPE'][$log_type_flip[$row['log_type_id']]],
305			'ACTION_HREF_S'    => url_arg($url, $type_key, $row['log_type_id']),
306
307			'USER_ID'          => $row['log_user_id'],
308			'USERNAME'         => $row['log_username'],
309			'USER_HREF_S'      => url_arg($url, $user_key, $row['log_user_id']),
310			'USER_IP'          => decode_ip($row['log_user_ip']),
311
312			'FORUM_ID'         => $row['log_forum_id'],
313			'FORUM_HREF'       => BB_ROOT . FORUM_URL . $row['log_forum_id'],
314			'FORUM_HREF_S'     => url_arg($url, $forum_key, $row['log_forum_id']),
315			'FORUM_NAME'       => htmlCHR($forum_name),
316
317			'FORUM_ID_NEW'     => $row['log_forum_id_new'],
318			'FORUM_HREF_NEW'   => BB_ROOT . FORUM_URL . $row['log_forum_id_new'],
319			'FORUM_HREF_NEW_S' => url_arg($url, $forum_key, $row['log_forum_id_new']),
320			'FORUM_NAME_NEW'   => htmlCHR($forum_name_new),
321
322			'TOPIC_ID'         => $row['log_topic_id'],
323			'TOPIC_HREF'       => (!$topic_deleted) ? BB_ROOT . TOPIC_URL . $row['log_topic_id'] : '',
324			'TOPIC_HREF_S'     => url_arg($url, $topic_key, $row['log_topic_id']),
325			'TOPIC_TITLE'      => $topic_title,
326
327			'TOPIC_ID_NEW'     => $row['log_topic_id_new'],
328			'TOPIC_HREF_NEW'   => BB_ROOT . TOPIC_URL . $row['log_topic_id_new'],
329			'TOPIC_HREF_NEW_S' => url_arg($url, $topic_key, $row['log_topic_id_new']),
330			'TOPIC_TITLE_NEW'  => $topic_title_new,
331
332			'DATE'             => bb_date($row['log_time'], 'j-M'),
333			'TIME'             => bb_date($row['log_time'], 'H:i'),
334			'DATETIME_HREF_S'  => $datetime_href_s,
335			'MSG'              => $msg,
336			'ROW_CLASS'        => $row_class,
337
338		));
339
340		// Topics
341		if ($topic_csv && empty($filter['topics'][$row['log_topic_title']]))
342		{
343			$template->assign_block_vars('topics', array(
344				'TOPIC_TITLE' => $row['log_topic_title'],
345			));
346			$filter['topics'][$row['log_topic_title']] = true;
347		}
348		// Forums
349		if ($forum_csv && empty($filter['forums'][$forum_name]))
350		{
351			$template->assign_block_vars('forums', array(
352				'FORUM_NAME' => htmlCHR($forum_name),
353			));
354			$filter['forums'][$forum_name] = true;
355		}
356		// Users
357		if ($user_csv && empty($filter['users'][$row['log_username']]))
358		{
359			$template->assign_block_vars('users', array(
360				'USERNAME' => $row['log_username'],
361			));
362			$filter['users'][$row['log_username']] = true;
363		}
364	}
365
366	$template->assign_vars(array(
367		'FILTERS'       => ($topic_csv || $forum_csv || $user_csv),
368		'FILTER_TOPICS' => !empty($filter['topics']),
369		'FILTER_FORUMS' => !empty($filter['forums']),
370		'FILTER_USERS'  => !empty($filter['users']),
371	));
372}
373else
374{
375	$template->assign_block_vars('log_not_found', array());
376}
377
378//
379// Selects
380//
381$log_type_select = array($lang['ACTS_LOG_ALL_ACTIONS'] => $all_types) + $log_action->log_type_select;
382
383// Order select
384$order_options = '<option value="">&nbsp;'.$lang['ACTS_LOG_TIME'].'&nbsp;</option>';
385
386$template->assign_vars(array(
387	'LOG_COLSPAN'       => 4,
388
389	'DATETIME_NAME'     => $datetime_key,
390	'DATETIME_VAL'      => date('Y-m-d', $datetime_val),
391	'DAYSBACK_NAME'     => $daysback_key,
392	'DAYSBACK_VAL'      => $daysback_val,
393	'FIRST_LOG_TIME'    => ($first_log_time) ? date('Y-m-d', $first_log_time) : $lang['ACC_NONE'],
394
395	'TITLE_MATCH_MAX'   => $title_match_max_len,
396	'TITLE_MATCH_NAME'  => $title_match_key,
397	'TITLE_MATCH_VAL'   => $title_match_val,
398
399	'ORDER_NAME'        => '',
400	'ORDER_OPTIONS'     => $order_options,
401
402	'SORT_NAME'         => $sort_key,
403	'SORT_ASC'          => $sort_asc,
404	'SORT_DESC'         => $sort_desc,
405	'SORT_ASC_CHECKED'  => ($sort_val == $sort_asc) ? HTML_CHECKED : '',
406	'SORT_DESC_CHECKED' => ($sort_val == $sort_desc) ? HTML_CHECKED : '',
407
408	'SEL_FORUM'         => get_forum_select('admin', "{$forum_key}[]", $forum_selected, $max_forum_name_len, $select_max_height, '', $all_forums),
409	'SEL_LOG_TYPE'      => build_select("{$type_key}[]", $log_type_select, $type_selected, 60, $select_max_height),
410	'SEL_USERS'         => build_select("{$user_key}[]", $users, $user_selected, 16, $select_max_height),
411
412	'S_LOG_ACTION'      => "admin_log.php",
413	'TOPIC_CSV'         => $topic_csv,
414));
415
416print_page('admin_log.tpl', 'admin');