<?
if (!defined('webid')) {
    exit();
}

if ($user_status != 'admin') {
    exit();
}

if (isset($_POST['back'])) {
    $sql = mysql_fetch_array(mysql_query("SELECT userid, money FROM masref WHERE id = '$_POST[back]'")) or die(mysql_query());
    mysql_query("UPDATE tb_users SET money = money + '$sql[money]' WHERE id = '$sql[userid]'") or die(mysql_query());
    mysql_query("DELETE FROM masref WHERE id = '$_POST[back]'") or die(mysql_query());
}

if (isset($_POST['ok'])) {
    mysql_query("UPDATE masref SET active = 1 WHERE id = '$_POST[ok]'") or die(mysql_query());
    $sql = mysql_fetch_array(mysql_query("SELECT money FROM masref WHERE id = '$_POST[ok]'")) or die(mysql_query());
    mysql_query("INSERT INTO tb_viruchka (ident, money, month, year) VALUES (8, '$sql[money]', '" . date('m', time()) . "', '" . date('Y', time()) . "')");
}

if (isset($_POST['del'])) {
    $sql = mysql_fetch_array(mysql_query("SELECT money FROM masref WHERE id = '$_POST[del]'")) or die(mysql_query());
    mysql_query("INSERT INTO tb_viruchka (ident, money, month, year) VALUES (8, '$sql[money]', '" . date('m', time()) . "', '" . date('Y', time()) . "')");
    mysql_query("DELETE FROM masref WHERE id = '$_POST[del]'") or die(mysql_query());
}
?>
<style type="text/css">
form {
    float: left;
    margin-right: 3px;
}
</style>
<table width="70%" border="0" cellpadding="0" cellspacing="1" class="tab">
<thead style="background: #ebebeb;">
    <th width="30" align="center" style="padding: 3px;">ID</th>
    <th align="center" style="padding: 3px;">Текст</th>
    <th width="230" align="center" style="padding: 3px;">Действия</th>
</thead>
<?
$sql = mysql_query("SELECT * FROM masref WHERE active = 0");
while ($row = mysql_fetch_array($sql)) {
    ?>
    <tr>
        <td align="center" class="lt"><?=$row['id']?></td>
        <td align="left" class="lt"><?=$row['mess']?></td>
        <td align="center" class="lt"><form action="" method="post"><input type="hidden" name="back" value="<?=$row['id']?>" /><input type="submit" id="save" value="Вернуть" /></form><form action="" method="post"><input type="hidden" name="ok" value="<?=$row['id']?>" /><input type="submit" id="save" value="Одобрить" /></form><form action="" method="post"><input type="hidden" name="del" value="<?=$row['id']?>" /><input type="submit" id="save" value="Удалить" /></form></td>
    </tr>
    <?
}
?>
</table>