<?php
// @copyright (c) 2005 KTUK Group
// @license http://opensource.org/licenses/gpl-license.php GNU Public License
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('');
//some essentail variables being set
$username = request_var('username', '');
$count = request_var('count', 0);
$submit = request_var('submit', '');
$done = false;
//define some variables
$row_user = '';
$warning = '';
$warning_new = '';
//are you an Admin, if not throw an error ;)
if(!$auth->acl_get('a_') || !$auth->acl_get('m_'))
{
trigger_error('Only Administrators or Moderators can remove a warning.');
}
//Has the form been submitted? If not display form.
if(!$submit)
{
print "<form action=\"".$_SERVER['SCRIPT_NAME']."\" method=\"post\" />
Username: <input type=\"text\" name=\"username\" />
Count: <input type=\"text\" name=\"count\" maxlength=\"2\" size=\"2\" />
<input type=\"submit\" value=\"submit\" name=\"submit\" />
</form>";
}
//fetch user info
$sql = "SELECT * FROM " . USERS_TABLE . "
WHERE username = '$username'";
$result = $db->sql_query($sql);
$row_user = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
//assign warning count so we can change it in the loop
$warning_count = $row_user['user_warnings'];
for($i=1;$i<=$count;$i++)
{
//does the user exist?
if (isset($row_user['user_id']))
{
//fetch warning info
$sql = "SELECT * FROM " . WARNINGS_TABLE . "
WHERE user_id = ".$row_user['user_id']."
ORDER BY warning_time DESC LIMIT 1";
$result = $db->sql_query($sql);
$warning = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
}
//is there a warning to remove?
if (isset($warning['warning_id']))
{
//result printing
$result = '';
//remove warning log
$sql = "DELETE FROM " . LOG_TABLE . "
WHERE log_id = ".$warning['log_id'];
$db->sql_query($sql);
print $result = ($db->sql_query($sql)) ? "Warning log removed.<br />" : '';
//remove last warning
$sql = "DELETE FROM " . WARNINGS_TABLE . "
WHERE warning_id = ".$warning['warning_id'];
$db->sql_query($sql);
//success
print $result = ($db->sql_query($sql)) ? "Last warning removed.<br />" : '';
//lets reduce the warning count for the user
$warning_count = ($warning_count - 1);
$sql = "UPDATE " . USERS_TABLE ."
SET user_warnings = ".$warning_count."
WHERE user_id = ".$row_user['user_id'];
$db->sql_query($sql);
//success
print $result = ($db->sql_query($sql)) ? "User warning count reduced.<br />" : '';
//Now we need the new last warning time to be able to update the user table last warning time
$sql = "SELECT warning_time FROM " . WARNINGS_TABLE . "
WHERE user_id = ".$row_user['user_id']."
ORDER BY warning_time DESC LIMIT 1";
$result = $db->sql_query($sql);
$warning_new = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$warning_new['warning_time'] = ($warning_new['warning_time']) ? $warning_new['warning_time'] : 0;
//lets update that last warning time
$sql = "UPDATE " . USERS_TABLE . "
SET user_last_warning = ".$warning_new['warning_time']."
WHERE user_id = ".$row_user['user_id'];
$db->sql_query($sql);
//success
print $result = ($db->sql_query($sql)) ? "Users last warning time updated if there are previous warnings.<br /><br />" : '';
//add admin log about removal
add_log('admin', 'Removed user warning', $user_row['username']);
//yay complete success
$done = true;
}
}
if($submit)
{
//suppose we better let them know the warning has been removed
mail($row_user['user_email'], 'Warning Removal', 'A Moderator on the Paper Forum has removed a board warning or warnings which they believe were issued incorrectly or by mistake.');
//did it work?
print $done = ($done) ? "Finished and warning or warnings removed." : "Finished but no actions carried out.";
//get form ready for another submit
unset($submit);
print "<br /><a href=\"./remove_warning.php\">BACK</a>";
}
?>