<?
include_once "../SYSTEM/include/functions.php";
include_once "../SYSTEM/include/mysql.php";
include_once "../SYSTEM/include/param.php";
include_once "../SYSTEM/include/ban.php";
include_once "../SYSTEM/include/sess.php";
include_once "../SYSTEM/include/ban_2.php";
include_once "../SYSTEM/include/theme.php";
if (!isset($user) || $user['level']==0)
{
header ("Location: ../index.php?".SID."");
exit;
}
$k_post=0;
$k_page=1;
$title='Юзеры';
$mesto='В админке';
head();
if (isset($user))
{
$k_p_str=$user['k_page'];
}
else
{
$k_p_str=$set['k_p_s'];
}
if ($onl['users']!="0")
{
$v_pages_okr=$onl['users']/$k_p_str%100;
$v_pages_tochn=$onl['users']/$k_p_str;
if ($v_pages_okr==$v_pages_tochn)
{
$k_page=$v_pages_okr;
}
else
{
$k_page=$v_pages_okr+1;
}
$page=1;
if (isset($_GET['page']) && $_GET['page']!='')
{
if ($_GET['page']=='end')
{
$page=$k_page;
}
else
{
$page=intval($_GET['page']);
}
}


if (isset($_GET['id']) && isset($_GET['act']))
{
$post_user_id=intval($_GET['id']);
$q = mysql_query("SELECT * FROM `$mysql[pref]users` WHERE `id` = '$post_user_id';");
$post_user = mysql_fetch_array($q);

if (!isset($post_user))
{
echo "<span style=\"color:$color[msg]\"><b>";
echo "Данного юзера не существует\n";
echo "</b></span><br />";
echo "<a href=\"user.php\">&lt;&lt; Юзеры</a><br />\n";
echo "<a href=\"index.php\">&lt;&lt; Админка</a><br />\n";
echo "<a href=\"../index.php\">На главную</a><br />\n";
foot();
}

if ($post_user['level']>=$user['level'] && $post_user['id']!=$user['id'])
{
echo "<span style=\"color:$color[msg]\"><b>";
echo "Вы не можете изменять параметры этого юзера\n";
echo "</b></span><br />";
echo "<a href=\"user.php\">&lt;&lt; Юзеры</a><br />\n";
echo "<a href=\"index.php\">&lt;&lt; Админка</a><br />\n";
echo "<a href=\"../index.php\">На главную</a><br />\n";
foot();
}


if ($_GET['act']=='data')
{
if (isset($_GET['st']) && $_GET['st']=='ok')
{
$level=intval($_POST['level']);
if ($post_user['level']<$user['level'] && $post_user['id']!=$user['id'] && $level<$user['level'])
{
mysql_query("UPDATE `$mysql[pref]users` SET `level` = '$level' WHERE `id` = '$post_user_id';");
action("Смена уровня доступа id=$post_user_id");
}

if (isset($_POST['nick_ch']) && isset($_POST['nick']))
{
$ank_nick=htmlspecialchars($_POST['nick']);
mysql_query("UPDATE `$mysql[pref]users` SET `nickname` = '$ank_nick' WHERE `id` = '$post_user_id';");

action("Смена ника id=$post_user_id");
}
if (isset($_POST['status_ch']) && isset($_POST['status']))
{
$ank_status=htmlspecialchars($_POST['status']);
mysql_query("UPDATE `$mysql[pref]users` SET `status` = '$ank_status' WHERE `id` = '$post_user_id';");
action("Смена статуса id=$post_user_id");
}
if (isset($_POST['balls_ch']) && isset($_POST['balls']))
{
$ank_balls=intval($_POST['balls']);
mysql_query("UPDATE `$mysql[pref]users` SET `balls` = '$ank_balls' WHERE `id` = '$post_user_id';");
action("Изменено количество баллов id=$post_user_id");
}




header ("Location: user.php?".SID."&id=$post_user_id&act=data");
exit;
}
echo "<div class=\"h\">$post_user[nickname]</div>\n";

echo "<form method=\"post\" action=\"user.php?st=ok&amp;act=data&amp;id=$post_user_id\">\n";

if ($post_user['level']==0)
{
echo "Статус на сайте<br />\n<select class=\"form\" name=\"level\"><br />\n";
echo "<option value=\"0\">Юзер</option>\n";
if ($user['level']>1)echo "<option value=\"1\">Модератор</option>\n";
if ($user['level']>2)echo "<option value=\"2\">Супермодератор</option>\n";
if ($user['level']==4)echo "<option value=\"3\">Администратор</option>\n";
//if ($user['level']==4)echo "<option value=\"4\">Главный админ</option>\n";
echo "</select><br />\n";
}
if ($post_user['level']==1)
{
echo "Статус на сайте<br />\n<select class=\"form\" name=\"level\"><br />\n";
echo "<option value=\"1\">Модератор</option>\n";
echo "<option value=\"0\">Юзер</option>\n";
if ($user['level']>2)echo "<option value=\"2\">Супермодератор</option>\n";
if ($user['level']==4)echo "<option value=\"3\">Администратор</option>\n";
//if ($user['level']==4)echo "<option value=\"4\">Главный админ</option>\n";
echo "</select><br />\n";
}
if ($post_user['level']==2)
{
echo "Статус на сайте<br />\n<select class=\"form\" name=\"level\"><br />\n";
echo "<option value=\"2\">Супермодератор</option>\n";
echo "<option value=\"0\">Юзер</option>\n";
if ($user['level']>1)echo "<option value=\"1\">Модератор</option>\n";
if ($user['level']==4)echo "<option value=\"3\">Администратор</option>\n";
//if ($user['level']==4)echo "<option value=\"4\">Главный админ</option>\n";
echo "</select><br />\n";
}
if ($post_user['level']==3)
{
echo "Статус на сайте<br />\n<select class=\"form\" name=\"level\"><br />\n";
echo "<option value=\"3\">Администратор</option>\n";
echo "<option value=\"0\">Юзер</option>\n";
if ($user['level']>1)echo "<option value=\"1\">Модератор</option>\n";
if ($user['level']>2)echo "<option value=\"2\">Супермодератор</option>\n";
//if ($user['level']==4)echo "<option value=\"4\">Главный админ</option>\n";
echo "</select><br />\n";
}
echo "Ник: <input type=\"checkbox\" class=\"form\" name=\"nick_ch\" value=\"1\" /><br />\n<input name=\"nick\" class=\"form\" value=\"$post_user[nickname]\" type=\"text\" /><br />\n";
echo "Особый статус: <input type=\"checkbox\" class=\"form\" name=\"status_ch\" value=\"1\" /><br />\n<input name=\"status\" class=\"form\" value=\"$post_user[status]\" type=\"text\" /><br />\n";
echo "Баллы: <input type=\"checkbox\" class=\"form\" name=\"balls_ch\" value=\"1\" /><br />\n<input name=\"balls\" class=\"form\" value=\"$post_user[balls]\" type=\"text\" /><br />\n";
echo "<br /><input class=\"form\" value=\"Установить\" type=\"submit\" />\n";
echo "</form>\n";



echo "<hr /><a href=\"../info.php?id=$post_user[id]\">Анкета</a><br />\n";
echo "<a href=\"user.php?page=$page\">&lt;&lt; Юзеры</a><br />\n";
echo "<a href=\"index.php\">&lt;&lt; Админка</a><br />\n";
echo "<a href=\"../index.php\">&lt;&lt; На главную</a>\n";
foot();
}
elseif ($_GET['act']=='del')
{
mysql_query("DELETE FROM `$mysql[pref]users` WHERE `id` = '$post_user_id' LIMIT 1;");
header ("Location: user.php?".SID."");
exit;
}
elseif ($_GET['act']=='ban')
{
$check='';
$timeban=0;
if ($post_user['ban_st']==1)
{
$check=' checked="checked"';
}
if ($post_user['ban_st']==1 && $post_user['ban_t']>$time)
{
$prich="$post_user[ban_pr]";
$check=' checked="checked"';
$timeban=$post_user['ban_t'];
}

$ban = $_POST['hist'];

if (isset($_GET['ban_ok']))
{
$msg=$_POST['msg'];
if ((isset($_POST['ban']) && $_POST['ban']==1))
{
$prich=$_POST['msg'];
$check=' checked="checked"';
}
else
{
$prich="";
$ban=0;
$check='';
}

if (isset($_POST['hist']))
$ban = $_POST['hist'];

$timeban=0;
if ($_POST['vremja']=='min')$timeban=intval($_POST['time'])*60;
if ($_POST['vremja']=='chas')$timeban=intval($_POST['time'])*60*60;
if ($_POST['vremja']=='sut')$timeban=intval($_POST['time'])*60*60*24;
if ($_POST['vremja']=='mes')$timeban=intval($_POST['time'])*60*60*24*30;

ban_user($post_user['id'],$timeban,$msg,$ban);
}


echo "<div class=\"h\">Бан $post_user[nickname]</div><hr />\n";

if ($mail_in_new>0)echo "<div class=\"privat\"><img src=\"../SYSTEM/themes/$them/img/mail0.gif\" alt=\"\" /> <a href=\"../mail.php?act=in\">Приват</a> [$mail_in_new]</div><hr />\n";

echo "<form method=\"post\" action=\"user.php?act=ban&amp;id=$post_user[id]&amp;ban_ok\">\n";

echo "Причина:<br />\n<textarea name=\"msg\" class=\"form\" rows=\"3\">$prich</textarea><br />\n";
echo "<input type=\"checkbox\" class=\"form\" name=\"tr\" value=\"1\" /> Транслит<br />\n";
echo "<input type=\"checkbox\" class=\"form\" name=\"ban\"$check value=\"1\" /> Бан";

if ($timeban!=0 && $check!='')
{
if (isset($_GET['ban_ok']))
echo " до <b>".vremja($time+$timeban+$timesdvig)."</b><br />\n";
else
echo " до <b>".vremja($timeban+$timesdvig)."</b><br />\n";
}
else
{
echo "<br />\n";
echo "<input type=\"checkbox\" class=\"form\" name=\"hist\" checked=\"checked\" value=\"1\" /> C занесением в историю<br />\n";
}

echo "Время<br /><input name=\"time\" class=\"form\" value=\"1\" type=\"text\" /><br />\n";
echo "Единица:<br />\n";
echo "<select class=\"form\" name=\"vremja\">\n";
echo "<option value=\"min\">Минуты</option>\n";
echo "<option value=\"chas\">Часы</option>\n";
echo "<option value=\"sut\">Сутки</option>\n";
echo "<option value=\"mes\">Месяцы</option>\n";
echo "</select><br />\n";


echo "<br /><input value=\"Забанить\" class=\"form\" type=\"submit\" />\n";
echo "</form>\n";





echo "<hr /><a href=\"user.php?page=$page\">&lt;&lt; Юзеры</a><br />\n";
echo "<a href=\"index.php\">&lt;&lt; Админка</a><br />\n";
echo "<a href=\"../index.php\">&lt;&lt; На главную</a>\n";

foot();
}


}

echo "<div class=\"h\">Выберите юзера</div><hr />\n\n";

if ($mail_in_new>0)echo "<div class=\"privat\"><img src=\"../SYSTEM/themes/$them/img/mail0.gif\" alt=\"\" /> <a href=\"../mail.php?act=in\">Приват</a> [$mail_in_new]</div><hr />\n";

echo "<form method=\"get\" action=\"user.php\">\n";

echo "Список юзеров:<br />\n";
echo "<select class=\"form\" name=\"id\">\n";

$page=intval($page);
if ($k_page<$page){$page=$k_page;}
if (0>$page){$page=1;}
}

$i=$k_p_str*$page-$k_p_str;
$q = mysql_query("SELECT * FROM `$mysql[pref]users` LIMIT $i, $k_p_str;");
while ($ank = mysql_fetch_array($q)){
echo "<option value=\"$ank[id]\">$ank[nickname]</option>\n";}
echo "</select><br />\n";


echo "<select class=\"form\" name=\"act\">\n";
echo "<option value=\"\">Выберите действие</option>\n";
echo "<option value=\"data\">Изменить</option>\n";
echo "<option value=\"del\">Удалить</option>\n";
echo "<option value=\"ban\">В баню</option>\n";
echo "</select><br />\n";
echo "<input name=\"page\" class=\"form\" value=\"$page\" type=\"hidden\" />";
echo "<input value=\"Далее\" class=\"form\" type=\"submit\" />\n";

echo "</form>\n";

echo "<hr />\n<div class=\"str\">";
str("user.php?",$k_page,$page);
echo "</div>\n";
echo "<hr />\n";

echo "<a href=\"index.php\">&lt;&lt; Админка</a><br />\n";
echo "<a href=\"../index.php\">&lt;&lt; На главную</a>\n";

foot();
?>
