<?session_start();

if(!(isset($_SESSION["username"]) && isset($_SESSION["password"])))
{
	?>

	<?
	exit();
}
?>

<h3>Получили бонус</h3>
<br>
<br>
На одной странице отображается 30 бонусов!<br>

<?
if($_POST["action"]=="delmess")
{
	$id=$_POST["id"];
	require('config.php');
	mysql_query("delete from tb_bonus where id='$id'");
	mysql_close($con);
	echo "<font color=#00cc00><b>Сообщение удалено</b></font><br>";
}

require('config.php');
$res=mysql_query("select count(*) as kolvo from tb_bonus");
$res=mysql_fetch_array($res);
$allmess=$res["kolvo"];

if($allmess=='0')
{
	echo "Бонусов не получали";
	exit();
}

$pages=$allmess/30;
$pages1=floor($pages);

if($pages>$pages1)
{
	$pages=$pages1+1;
}

if($_POST["page"]!="")
{
	$page=$_POST["page"];
}else{
	$page='1';
}

echo "<b>Текущая страница $page из $pages</b><br>";
?>
<form action='' method=post>
<select name='page'>
<?
	for($i=1;$i<=$pages;$i++)
	{
		echo "<option value='$i'>$i</option>";
	}
?>
</select>
<input type=submit value='Перейти'>
</form>
<br><br>
<?

$p1=30*($page-1);
$p2=30*$page-1;

function smile($message)
{
	$smiles[]="angel"; $smiles[]="smile"; $smiles[]="sadness"; $smiles[]="wink"; $smiles[]="tongue";
	$smiles[]="glasses"; $smiles[]="laugh"; $smiles[]="shy"; $smiles[]="wonder"; $smiles[]="kiss";
	$smiles[]="tears"; $smiles[]="anger"; $smiles[]="music"; $smiles[]="flower";
	$smiles[]="THUMBS UP"; $smiles[]="cool"; $smiles[]="DONT_KNOW";

	for($i=0;$i<=16;$i++)
	{
		$message=str_ireplace("*".$smiles[$i]."*","<img src=\"smilies/".$smiles[$i].".gif\" align=\"middle\" border=\"0\">",$message);
	}

	return $message;
}

$user=$_SESSION["username"];
$res=mysql_query("select chatmoder from tb_users where username='$user'");
$res=mysql_fetch_array($res);
$moder=$res["chatmoder"];

$res=mysql_query("select * from tb_bonus order by id desc limit $p1,$p2");

while($row=mysql_fetch_array($res))
{
	$id=$row["id"];
	$user=$row["user"];
	$res1=mysql_query("select count(id) from tb_chatban where user='$user'");
	$res1=mysql_result($res1,0,0);
	if($res1<1)
	{
		$mess=$row["message"];
		$mess=smile($mess);
		$dt=date("d.m.Y H:i", $row["data"]);
		$res2=mysql_query("select user_status,chatmoder from tb_users where username='$user'");
		$res2=mysql_fetch_array($res2);
		$us=$res2["user_status"];
		$cm=$res2["chatmoder"];
		
		if($us=='user') if($cm=='0') { $cvet='333333'; }else{ $cvet='0000ff'; }
		if($us=='admin') $cvet='ff0000';
		if($us=='') $cvet='cccccc';
		
		if($moder=='0')
		{
			echo "<table align=left><tr><td><span style=\"font-size: 12px; color: #$cvet\"><b>$user </b></span>($dt)</td>
			<td><span style=\"font-size: 12px; color: black;\">Пожелание: </span>			
                  <td><span style=\"font-size: 12px; color: blue;\">$mess</span>
			</table><br></td>
			!</td></tr></table>";
		}else{
			echo "<table align=left><tr><td><span style=\"font-size: 14px; color: #$cvet\"><b>$user </b></span></td>
			<td><span style=\"font-size: 10px; color: #333;\"><b>($dt)</b></span></td><td><form action=\"\" method=post>
			<input type=hidden value=\"delmess\" name=\"action\">
			<input type=hidden value=\"$id\" name=\"id\">
			<input type=submit value=\"Удалить сообщение\">
			</form></td>
			<span style=\"font-size: 12px; color: #000000\">
			$mess</span>";
		}
	}
}

mysql_close($con);
?>

<? include('footer.php');?>