<?
/*****************************

Hannes' ShoutBox v1.0

*****************************/

require_once("include/bittorrent.php");
dbconn(false);

loggedinorreturn();

//deleting messages

if (isset($_GET['del']))
{
if (is_numeric($_GET['del']))
{
$query = "SELECT * FROM shoutbox2 WHERE id=".$_GET['del'];
$result = mysql_query($query);
}
else {echo "invalid msg id STOP TRYING TO INJECT SQL TIT HEAD";exit;
}

$row = mysql_fetch_row($result);

if ( (get_user_class() >= UC_MODERATOR) )
{
$query = "DELETE FROM shoutbox2 WHERE id=".$_GET['del'];
mysql_query($query);
}
}
// EDIT SHOUT ?
if (isset($_GET['edit']) && get_user_class() >= UC_MODERATOR && is_valid_id($_GET['edit']))
{	
	$sql=sql_query("SELECT id,text FROM shoutbox2 WHERE id=".sqlesc($_GET['edit']));
	$res=mysql_fetch_array($sql);
	?>
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	<meta http-equiv="Pragma" content="no-cache">
	<meta http-equiv="expires" content="0">
	<head profile="http://gmpg.org/xfn/11">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<style type="text/css">
	#specialbox{
	border: 1px solid gray;
	width: 600px;
	background: #FBFCFA;
	font: 11px verdana, sans-serif;
	color: #443;
	padding: 3px;	outline: none;
	}

	#specialbox:focus{
	border: 1px solid black;
	}
	.btn {
	cursor:pointer;
	border:outset 1px #ccc;
	background:#999;
	color:#666;
	font-weight:bold;
	padding: 1px 2px;
	background:url(pic/formbg.gif) repeat-x left top;
	}	
	</style>
	</head>
	<body bgcolor=#F5F4EA>
	<?php
	echo '<form method=post action=shoutbox2.php>';
	echo '<input type=hidden name=id value='.(int)$res['id'].'>';
	echo '<textarea name=text rows=3 id=specialbox>'.htmlspecialchars($res['text']).'</textarea>';
	echo '<input type=submit name=save value=save class=btn>';
	echo '</form></body></html>';
	die;
}
// UPDATE SHOUT?
if (isset($_POST['text']) && get_user_class() >= UC_MODERATOR && is_valid_id($_POST['id']))
{
	$text = trim($_POST['text']);
	$id = (int)$_POST['id'];
	if (isset($text) && isset($id) && is_valid_id($id))
		sql_query("UPDATE shoutbox2 SET text = ".sqlesc($text)." WHERE id=".sqlesc($id));
}

?>
<html><head>
<title>ShoutBox</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<meta http-equiv="Content-Type" content="text/html; charset=TIS-602">
<META HTTP-EQUIV=REFRESH CONTENT="1000; URL=shoutbox2.php">
<style type="text/css">
A {color: #FF0000; font-weight: bold; }
A:hover {color: #FFFFFF ;}
.small {background-attachment: fixed; background-image: url(http://www.notoon.com/images/artworks/darkness_wonder_thumb.jpg); font-size: 11pt;font-weight: bold; font-family: Microsoft Sans Serif;color: #999999 ; }
.date {font-size: 8pt;color: #CCCCCC  ;}
</style>
</head>
<body>
<?

/*
if ($CURUSER["chatpost"] == 'no')
{
print("<h2><br><center>You are banned.</center></h2>");
exit;
}
else
{
*/

if($_GET["sent"]=="yes")
{
$userid=$CURUSER["id"];
$username=$CURUSER["username"];
$date=time();
$text=trim($_GET["shbox_text"]);



mysql_query("INSERT INTO shoutbox2 (id, userid, username, date, text) VALUES ('id'," . sqlesc($userid) . ", " . sqlesc($username) . ", $date, " . sqlesc($text) . ")") or sqlerr(__FILE__, __LINE__);
}

$res = mysql_query("SELECT * FROM shoutbox2 ORDER BY date DESC LIMIT 35") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0)
print("\n");
else
{
print("<table border=0 cellspacing=0 cellpadding=2 width='100%' align='left' class='small'>\n");

while ($arr = mysql_fetch_assoc($res))
{
$res2 = mysql_query("SELECT username,class,avatar,donor, title,enabled,warned FROM users WHERE id=$arr[userid]") or sqlerr(__FILE__, __LINE__);
$arr2 = mysql_fetch_assoc($res2);
$resowner = mysql_query("SELECT id, username, class FROM users WHERE id=$arr[userid]") or print(mysql_error());
$rowowner = mysql_fetch_array($resowner);


if ($rowowner["class"] == "96")
$usercolor= "<font color=#FF0000>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "101")
$usercolor= "<font color=#FFFFFF>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "102")
$usercolor= "<font color=#FF0066>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "103")
$usercolor= "<font color=#EEC900>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "100")
$usercolor= "<font color=#ff0000>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "52")
$usercolor= "<font color=#DF8218>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "51")
$usercolor= "<font color=#18849C>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "26")
$usercolor= "<font color=#990033>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "25")
$usercolor= "<font color=#9900FF>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "20")
$usercolor= "<font color=#33CC66>" .htmlspecialchars($rowowner["username"]). "</font>";

elseif ($rowowner["class"] == "15")
$usercolor= "<font color=#0066FF>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "10")
$usercolor= "<font color=#9CDF84>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "5")
$usercolor= "<font color=#8B864E>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "4")
$usercolor= "<font color=#CC66FF>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "1")
$usercolor= "<font color=#00ff99>" .htmlspecialchars($rowowner["username"]). "</font>";
elseif ($rowowner["class"] == "0")
$usercolor= "<font color=#667FFF>" .htmlspecialchars($rowowner["username"]). "</font>";

if (get_user_class() >= UC_MODERATOR) {
$del="[<a href=./shoutbox2.php?del=".$arr[id].">del</a>]";
$edit="<span class='date'>[<a href=shoutbox2.php?edit=".$arr[id].">edit</a>]</span>\n";
}
$pm = "<span class='date'>[<a target=_blank href=messages.php?action=send&receiver=$arr[userid]>pm</a>]</span>\n";
print("<tr><td><font color=gray>|<span class='date'>".strftime("%H:%M",$arr["date"])."|</font>
$del$edit$pm <a href='userdetails.php?id=".$arr["userid"]."' target='_blank'> 
</span>
<a href='userdetails.php?id=".$arr["userid"]."' target='_blank'>$usercolor</a>" .
($arr2["donor"] == "yes" ? "<img src="."pic/star.gif alt='DONOR'>" : "") .
($arr2["class"] == "96" ? "<img src="."pic/sysop_icon.gif alt='SYSOP'>" : "") .
($arr2["class"] == "80" ? "<img src="."pic/admin_icon.gif alt='ADMIN'>" : "") .
($arr2["class"] == "64" ? "<img src="."pic/mod_icon.gif alt='MODERATOR'>" : "") .
($arr2["class"] == "48" ? "<img src="."pic/uploader_icon.gif alt='UPLOADER'>" : "") .
($arr2["class"] == "32" ? "<img src="."pic/vip_icon.gif alt='VIP'>" : "") .
($arr2["class"] == "16" ? "<img src="."pic/power_user_icon.gif alt='POWER USER'>" : "") .
($arr2["class"] == "0" ? "<img src="."pic/user_icon.gif alt='USER'>" : "") .
($arr2["warned"] == "yes" ? "<img src="."pic/warned.gif alt='Warned'>" : "") .
" ".format_comment($arr["text"])."
</td></tr>\n");
}
print("</table>");


}


?>
</body>
</html>