<h1>Пользователи</h1>
<?php
db_connect();
header("Content-type: text/html; charset=windows-1251");

if(isset($_POST["userssub"])){
	db_query("UPDATE `".DBpref."users` SET `status` = ".intval($_POST["status"]).", `balance` = ".round($_POST["balance"]).", `email` = '".db_string($_POST["email"])."', `ref` = '".db_string($_POST["ref"])."', `wmid` = '".db_string($_POST["wmid"])."', `wmr` = '".db_string($_POST["wmr"])."', `rating` = ".round($_POST["rating"], 4).", `genus` = ".intval($_POST["genus"])."  WHERE `login` = '".db_string($_POST["login"])."'");
	echo "<h2>Настройки сохраненны</h2>";
}

if(isset($_GET["login"])){
$res = db_query("SELECT * FROM `".DBpref."users` WHERE `login` = '".db_string($_GET["login"])."'");
$row = db_assoc($res);
echo '
<form action="?p=users" method="post">
<input name="login" type="hidden" value="'.htmlspecialchars($row["login"]).'">
<table width="100%" border="1" cellspacing="0" cellpadding="0" class="table1">
  <tr>
    <td width="180px" align="right">Логин:</td>
    <td>'.htmlspecialchars($row["login"]).'</td>
  </tr>
  <tr>
    <td width="180px" align="right">Статус:</td>
    <td>
		 <select name="status">
		 	<option value="0" '.($row["status"] == 0?' selected="selected" ':'').' >User</option>
			<option value="1" '.($row["status"] == 1?' selected="selected" ':'').' >Admin</option>
		 </select>
	</td>
  </tr>
  <tr>
    <td width="180px" align="right">Баланс:</td>
    <td><input name="balance" type="text" value="'.round($row["balance"],2).'" /></td>
  </tr>
  <tr>
    <td width="180px" align="right">E-mail:</td>
    <td><input name="email" type="text" value="'.htmlspecialchars($row["email"]).'" /></td>
  </tr>
  <tr>
    <td width="180px" align="right">Реферер:</td>
    <td><input name="ref" type="text" value="'.htmlspecialchars($row["ref"]).'" /></td>
  </tr>
  <tr>
    <td width="180px" align="right">Реферер2:</td>
    <td><input name="ref" type="text" value="'.htmlspecialchars($row["ref2"]).'" /></td>
  </tr>
  <tr>
    <td width="180px" align="right">WMID:</td>
    <td><input name="wmid" type="text" value="'.htmlspecialchars($row["wmid"]).'" /></td>
  </tr>
  <tr>
    <td width="180px" align="right">WMR:</td>
    <td><input name="wmr" type="text" value="'.htmlspecialchars($row["wmr"]).'" /></td>
  </tr>
  <tr>
    <td width="180px" align="right">Рейтинг:</td>
    <td><input name="rating" type="text" value="'.round($row["rating"], 4).'" /></td>
  </tr>
  <tr>
    <td width="180px" align="right">Пол:</td>
    <td>
		<select name="genus">
		 	<option value="1" '.($row["genus"] == 1?' selected="selected" ':'').' >Мужской</option>
			<option value="2" '.($row["genus"] == 2?' selected="selected" ':'').' >Женский</option>
		 </select>
	</td>
  </tr>
  <tr>
    <td width="180px" align="right">Побед:</td>
    <td>'.$row["game_win"].'</td>
  </tr>
  <tr>
    <td width="180px" align="right">Поражений:</td>
    <td>'.$row["game_loss"].'</td>
  </tr>
  <tr>
    <td width="180px" align="right">Ничьих:</td>
    <td>'.$row["game_draw"].'</td>
  </tr>
  <tr>
    <td width="180px" align="right">Дата регистрации:</td>
    <td>'.$row["regdat"].'</td>
  </tr>
  <tr>
    <td width="180px" align="right">Последняя активность:</td>
    <td>'.$row["logdat"].'</td>
  </tr>
   <tr>
    <td>Всего введено средств: </td>
    <td>'.round($row["balance_topup"], 2).' руб.</td>
  </tr>
  <tr>
    <td>Всего выведено средств: </td>
    <td>'.round($row["balance_cash"], 2).' руб.</td>
  </tr>
  <tr>
    <td width="180px" align="right"></td>
    <td><input name="userssub" type="submit" value="Сохранить"></td>
  </tr>
</table>
</form>
';
exit();
}

$res = db_query("SELECT * FROM `".DBpref."users` ORDER BY `id` DESC");
db_close();

echo '
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table1">
  <tr>
    <td>Логин</td>
    <td>Баланс</td>
    <td>Рейтинг</td>
    <td>E-mail</td>
    <td>Реферер</td>
	<td>Реферер2</td>
    <td>Группа</td>
    <td>Регистрация</td>
    <td>Активность</td>
	<td></td>
  </tr>
';
while($row = db_assoc($res)){
echo '
  <tr>
    <td>'.htmlspecialchars($row["login"]).'</td>
    <td>'.round($row["balance"],2).'</td>
    <td>'.round($row["rating"],4).'</td>
    <td>'.htmlspecialchars($row["email"]).'</td>
    <td>'.htmlspecialchars($row["ref"]).'</td>
	<td>'.htmlspecialchars($row["ref2"]).'</td>
    <td>'.$userGroup[$row["status"]].'</td>
    <td>'.$row["regdat"].'</td>
    <td>'.$row["logdat"].'</td>
	<td><a href="?p=users&login='.htmlspecialchars($row["login"]).'">Редактировать</a></td>
  </tr>
 ';
}
echo '</table>';
?>