<?php
/***************************************************************************
* copyright            : (C) 2001-2003 Advanced Internet Designs Inc.
* email                : forum@prohost.org
* $Id: admlog.php,v 1.1.1.1.8.1 2004/11/24 14:25:29 kazuyan Exp $
*
* This program is free software; you can redistribute it and/or modify it 
* under the terms of the GNU General Public License as published by the 
* Free Software Foundation; either version 2 of the License, or 
* (at your option) any later version.
***************************************************************************/

	require('./GLOBALS.php'); fud_phpgw();
	fud_use('adm.inc', true);

	if (isset($_GET['clear'])) {
		q('DELETE FROM '.$GLOBALS['DBHOST_TBL_PREFIX'].'action_log');
	}

function check_data_avl($data)
{
	$data = trim($data);
	if (empty($data) && !strlen($data)) {
		return lang('no longer in the system');
	}

	return $data;
}

function return_thread_subject($id)
{
	$res = q_singleval('SELECT m.subject FROM '.$GLOBALS['DBHOST_TBL_PREFIX'].'thread t INNER JOIN '.$GLOBALS['DBHOST_TBL_PREFIX'].'msg m ON t.root_msg_id=m.id WHERE t.id='.$id);
	return check_data_avl($res);
}

function return_msg_subject($id)
{
	return check_data_avl(q_singleval('SELECT subject FROM '.$GLOBALS['DBHOST_TBL_PREFIX'].'msg WHERE id='.$id));
}

function return_forum_name($id)
{
	return check_data_avl(q_singleval('SELECT name FROM '.$GLOBALS['DBHOST_TBL_PREFIX'].'forum WHERE id='.$id));
}

	include('admpanel.php');
?>
<h2><?php echo lang('Admin Log') ?></h2>
<a href="admlog.php?clear=1&<?php echo _rsidl; ?>"><?php echo lang('Clear Log') ?></a>
<table border=1 cellspacing=1 cellpadding=3>
<tr bgcolor="#bff8ff"><td><?php echo lang('User') ?></td><td><?php echo lang('Action') ?></td><td><?php echo lang('Object') ?></td><td><?php echo lang('Time') ?> (<b>GMT</b>)</td></tr>
<?php
	$c = q('SELECT u.users_opt, u.alias, al.* FROM '.$DBHOST_TBL_PREFIX.'action_log al LEFT JOIN '.$DBHOST_TBL_PREFIX.'users u ON al.user_id=u.id ORDER BY logtime DESC');

	while ($obj = db_rowobj($c)) {
		if ($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] != 'ja')
			$logtime = '<td>'.gmdate('D, d M Y H:i:s', $obj->logtime).'</td>';
		else
		{
			$locale = file_get_contents($GLOBALS['DATA_DIR'].'thm/default/i18n/japanese/locale');
			setlocale(LC_TIME, $locale);
			$logtime = '<td>'.gmstrftime('%Y/%m/%d (%a) %H:%M:%S', $obj->logtime).'</td>';
		}

		if ($obj->users_opt == null) {
			$user_info = lang('User is no longer in the system.');
		} else if ($obj->users_opt & 1048576) {
			$user_info = '<a href="../'.__fud_index_name__.'?t=usrinfo&id='.$obj->user_id.'&'._rsidl.'">'.$obj->alias.'</a> <font size="-2">['.lang('Administrator').']</font>';
		} else if ($obj->users_opt & 524288) {
			$user_info = '<a href="../'.__fud_index_name__.'?t=usrinfo&id='.$obj->user_id.'&'._rsidl.'">'.$obj->alias.'</a> <font size="-2">['.lang('Moderator').']</font>';
		} else {
			$user_info = '<a href="../'.__fud_index_name__.'?t=usrinfo&id='.$obj->user_id.'&'._rsidl.'">'.$obj->alias.'</a> <font size="-2">['.lang('Priveleged User').']</font>';
		}
		echo '<tr><td>'.$user_info.'</td>';

		switch ($obj->a_res) {
			case "THRMOVE":
				echo '<td>'.lang('Moved Topic').'</td><td>'.lang('thread').': '.return_thread_subject($obj->a_res_id).'</td>';
				break;
			case "DELREPORT":
				echo '<td>'.lang('Deleted Report').'</td><td>'.lang('msg').': '.return_msg_subject($obj->a_res_id).'</td>';
				break;
			case "THRLOCK":
				echo '<td>'.lang('Locked Topic').'</td><td>'.lang('thread').': '.return_thread_subject($obj->a_res_id).'</td>';
				break;
			case "THRUNLOCK":
				echo '<td>'.lang('Unlocked Topic').'</td><td>'.lang('thread').': '.return_thread_subject($obj->a_res_id).'</td>';
				break;
			case "THRXREQUEST":
				echo '<td>'.lang('Requested Topic-X-Change').'</td><td>'.lang('thread').': '.return_thread_subject($obj->a_res_id).'</td>';
				break;
			case "THRXAPPROVE":
				echo '<td>'.lang('Approved Topic-X-Change').'</td><td>'.lang('thread').': '.return_thread_subject($obj->a_res_id).'</td>';
				break;
			case "THRXDECLINE":
				echo '<td>'.lang('Declined Topic-X-Change').'</td><td>'.lang('thread').': '.return_thread_subject($obj->a_res_id).'</td>';
				break;
			case "THRSPLIT":
				echo '<td>'.lang('Split Topic').'</td><td>'.lang('thread').': '.return_thread_subject($obj->a_res_id).'</td>';
				break;
			case "THRMERGE":
				echo '<td>'.lang('Merged Topic').'</td><td>'.lang('thread').': "'.return_thread_subject($obj->a_res_id).'" is a result of merging "'.$obj->logaction.'" topics.</td>';
				break;
			case "MSGEDIT":
				echo '<td>'.lang('Edited Message').'</td><td>'.lang('msg').': '.return_msg_subject($obj->a_res_id).'</td>';
				break;
			case "DELMSG":
				echo '<td>'.lang('Deleted Message').'</td><td>'.$obj->logaction.'</td>';
				break;
			case "DELTHR":
				echo '<td>'.lang('Deleted Topic').'</td><td>'.$obj->logaction.'</td>';
				break;
			case "ADDFORUM":
				echo '<td>'.lang('Created Forum').'</td><td>'.lang('forum').': '.return_forum_name($obj->a_res_id).'</td>';
				break;
			case "SYNCFORUM":
				echo '<td>'.lang('Updated Forum').'</td><td>'.lang('forum').': '.return_forum_name($obj->a_res_id).'</td>';
				break;
			case "FRMMARKDEL":
				echo '<td>'.lang('Deleted Forum').'</td><td>'.lang('forum').': '.$obj->logaction.'</td>';
				break;
			case "CHCATFORUM":
				echo '<td>'.lang('Changed Forum Category').'</td><td>'.lang('forum').': '.return_forum_name($obj->a_res_id).'</td>';
				break;
			case "WRONGPASSWD":
				echo '<td>'.lang('Failed login attempt for admin').'</td><td>From '.$obj->logaction.'</td>';
				break;
			case "DELETE_USER":
				echo '<td>'.lang('Removed user account').'</td><td>'.$obj->logaction.'</td>';
				break;
			default:
				echo '<td colspan="2">'.lang('Unknown').'</td>';
				break;
		}

		echo $logtime.'</tr>';
	}
	unset($c);
?>
</table>
<?php require('admclose.php'); ?>
