<?php
require 'include/bittorrent.php';
header ( "Content-Type: text/html; charset=Windows-1251" );
dbconn ();
global $CURGROUP, $CURUSER, $tracker_lang, $pic_base_url;
if ($_SERVER ["REQUEST_METHOD"] == "GET" && $_GET ['readmsgs']) {
	/*$res1 = sql_query ( "SELECT COUNT(*) FROM messages WHERE receiver=" . $CURUSER ["id"] . " AND location=1" ) or sqlerr ( __FILE__, __LINE__ );
	$arr1 = mysql_fetch_row ( $res1 );
	$messages = $arr1 [0];
	$res1 = sql_query("SELECT COUNT(*) FROM messages WHERE receiver=" . $CURUSER["id"] . " AND location=1 AND unread='yes'") or sqlerr ( __FILE__, __LINE__ ); 
    $arr1 = mysql_fetch_row($res1);
    $unread = $arr1[0];
	$res1 = sql_query ( "SELECT COUNT(*) FROM messages WHERE sender=" . $CURUSER ["id"] . " AND saved='yes'" ) or sqlerr ( __FILE__, __LINE__ );
	$arr1 = mysql_fetch_row ( $res1 );
	$outmessages = $arr1 [0];*/
	/*$res2 = sql_query ( "SELECT COUNT(*) FROM peers WHERE userid=" . $CURUSER ["id"] . " AND seeder='yes'" ) or sqlerr ( __FILE__, __LINE__ );
		$row = mysql_fetch_row ( $res2 );
		$activeseed = ( int ) $row [0];
		
		$res2 = sql_query ( "SELECT COUNT(*) FROM peers WHERE userid=" . $CURUSER ["id"] . " AND seeder='no'" ) or sqlerr ( __FILE__, __LINE__ );
		$row = mysql_fetch_row ( $res2 );
		$activeleech = ( int ) $row [0];*/
	$messages = 0;
	$unread = 0;
	$outmessages = 0;
	$res1 = sql_query ( "SELECT unread, receiver, sender FROM messages WHERE (receiver=" . $CURUSER ["id"] . " AND location=1) OR (sender=" . $CURUSER ["id"] . " AND saved='yes')" ) or sqlerr ( __FILE__, __LINE__ );
	while ( $arr = mysql_fetch_array ( $res1 ) ) {
		if ($arr ['receiver'] == $CURUSER ['id']) {
			$messages ++;
			if ($arr ['unread'] == 'yes')
				$unread ++;
		} elseif ($arr ['sender'] == $CURUSER ['id'])
			$outmessages ++;
	}
	$activeseed = 0;
	$activeleech = 0;
	$res2 = sql_query ( "SELECT seeder FROM peers WHERE userid=" . $CURUSER ["id"] ) or sqlerr ( __FILE__, __LINE__ );
	while ( $row = mysql_fetch_array ( $res2 ) )
		if ($row ["seeder"] == "yes")
			$activeseed ++;
		else
			$activeleech ++;
	$txlst3 = sql_query ( "SELECT COUNT(*) FROM thanks WHERE touid=" . $CURUSER ["id"] ) or sqlerr ( __FILE__, __LINE__ );
	$list3 = mysql_fetch_row ( $txlst3 );
	$count3 = ( int ) $list3 [0];
	if ($unread)
		$inboxpic = "<img height=\"16px\" style=\"border:none\" alt=\"inbox\" title=\"Есть новые сообщения\" src=\"" . $pic_base_url . "pn_inboxnew.gif\">";
	else
		$inboxpic = "<img height=\"16px\" style=\"border:none\" alt=\"inbox\" title=\"Нет новых сообщений\" src=\"" . $pic_base_url . "pn_inbox.gif\">";
	if ($messages) {
		$message_in = "<span class=\"smallfont\">&nbsp;<a href=\"message.php\">$inboxpic</a> $messages " . sprintf ( $tracker_lang ["new_pm"], $unread ) . "</span>";
		if ($outmessages)
			$message_out = "<span class=\"smallfont\">&nbsp;<a href=\"message.php?action=viewmailbox&box=-1\"><img height=\"16px\" style=\"border:none\" alt=\"" . $tracker_lang ['outbox'] . "\" title=\"" . $tracker_lang ['outbox'] . "\" src=\"" . $pic_base_url . "pn_sentbox.gif\"></a> $outmessages</span>";
		else
			$message_out = "<span class=\"smallfont\">&nbsp;<a href=\"message.php?action=viewmailbox&box=-1\"><img height=\"16px\" style=\"border:none\" alt=\"" . $tracker_lang ['outbox'] . "\" title=\"" . $tracker_lang ['outbox'] . "\" src=\"" . $pic_base_url . "pn_sentbox.gif\"></a> 0</span>";
	} else {
		$message_in = "<span class=\"smallfont\">&nbsp;<a href=\"message.php\"><img height=\"16px\" style=\"border:none\" alt=\"" . $tracker_lang ['inbox'] . "\" title=\"" . $tracker_lang ['inbox'] . "\" src=\"" . $pic_base_url . "pn_inbox.gif\"></a> 0</span>";
		if ($outmessages)
			$message_out = "<span class=\"smallfont\">&nbsp;<a href=\"message.php?action=viewmailbox&box=-1\"><img height=\"16px\" style=\"border:none\" alt=\"" . $tracker_lang ['outbox'] . "\" title=\"" . $tracker_lang ['outbox'] . "\" src=\"" . $pic_base_url . "pn_sentbox.gif\"></a> $outmessages</span>";
		else
			$message_out = "<span class=\"smallfont\">&nbsp;<a href=\"message.php?action=viewmailbox&box=-1\"><img height=\"16px\" style=\"border:none\" alt=\"" . $tracker_lang ['outbox'] . "\" title=\"" . $tracker_lang ['outbox'] . "\" src=\"" . $pic_base_url . "pn_sentbox.gif\"></a> 0</span>";
	}
	?>
<font color="blue"><?=$tracker_lang ['pm']?>:</font>
<?=$message_in?> <?=$message_out?><br />
<?=$tracker_lang ['torrents']?>:
<img alt="<?=$tracker_lang ['seeding']?>"
	title="<?=$tracker_lang ['seeding']?>"
	src="./themes/<?=$ss_uri?>/images/arrowup.gif">
<font color=green><span class="smallfont"><?=$activeseed?></span></font>
<img alt="<?=$tracker_lang ['leeching']?>"
	title="<?=$tracker_lang ['leeching']?>"
	src="./themes/<?=$ss_uri?>/images/arrowdown.gif">
<font color=red><span class="smallfont"><?=$activeleech?></span></font>
<?=($count3 > 0 ? "<br /><font color=\"darkgreen\">" . $tracker_lang ['thanks'] . ": " . $count3 . " шт</font></br>" : "")?>
<?}?>