<?php
/*
*----------------------------phpMyBitTorrent V 2.0-beta4-----------------------*
*--- The Ultimate BitTorrent Tracker and BMS (Bittorrent Management System) ---*
*--------------   Created By Antonio Anzivino (aka DJ Echelon)   --------------*
*-------------               http://www.p2pmania.it               -------------*
*------------ Based on the Bit Torrent Protocol made by Bram Cohen ------------*
*-------------              http://www.bittorrent.com             -------------*
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
*--   This program is free software; you can redistribute it and/or modify   --*
*--   it under the terms of the GNU General Public License as published by   --*
*--   the Free Software Foundation; either version 2 of the License, or      --*
*--   (at your option) any later version.                                    --*
*--                                                                          --*
*--   This program is distributed in the hope that it will be useful,        --*
*--   but WITHOUT ANY WARRANTY; without even the implied warranty of         --*
*--   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          --*
*--   GNU General Public License for more details.                           --*
*--                                                                          --*
*--   You should have received a copy of the GNU General Public License      --*
*--   along with this program; if not, write to the Free Software            --*
*-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA --*
*--                                                                          --*
*------------------------------------------------------------------------------*
*------              2005 phpMyBitTorrent Development Team              ------*
*-----------               http://phpmybittorrent.com               -----------*
*------------------------------------------------------------------------------*
*/
if (!eregi("mybonus.php",$_SERVER["PHP_SELF"])) die ("You cannot include this file");
global $user, $db, $db_prefix;
include("header.php");
$bonus = $user->seedbonus;
$userid = "".getuserid($btuser)."";
OpenTable("Seeder Bonus Exchange");
print("<table align=center width=600 border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n");
Print("<tr><td class=tabletitle width=600>Seeder Bonus</td></tr></table>");
print("<table class=tableb align=center width=600 border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n");
?>
<tr><td align=center>Here you can exchange your Seeder-Bonus (currently: <? print $user->seedbonus;?>)
<br>
(If the button's deactivated, you do not have enough to trade.)
<br>
<?php

print("<table border=1 cellspacing=0 cellpadding=5 width=500><tr>".
"<td class=tabletitle align=left>Option</td>".
"<td class=tabletitle align=left>What's this about?</td>".
"<td class=tabletitle align=left>Points</td>".
"<td class=tabletitle align=left>Trade</td>".

"</tr>");

$sql = ("SELECT * FROM ".$db_prefix."_bonus order by id");
$res = $db->sql_query($sql);
while ($gets = $db->sql_fetchrow($res))
{
print("<tr class=tableb><td>".$gets["id"]."</td><td align='left'><b>".$gets["bonusname"]."</b><br>".$gets["description"]."</td><td align='right'>".$gets["points"]."</td>");
print("<form action=mybonus.php?action=exchange method=post>\n");
print("<input type=\"hidden\" name=\"bonus\" value=\"".$bonus."\">\n");
print("<input type=\"hidden\" name=\"userid\" value=\"".$userid."\">\n");
print("<input type=\"hidden\" name=\"points\" value=\"".$gets["points"]."\">\n");
print("<input type=\"hidden\" name=\"option\" value=\"".$gets["id"]."\">\n");
print("<input type=\"hidden\" name=\"art\" value=\"".$gets["art"]."\">\n");
if($seedbonus >= $gets["points"]) {
    print("<td><input type=submit name=submit value=\"Exchange!\"></td></form>");
    } else {
    print("<td><input type=submit name=submit value=\"Exchange!\" disabled></td></form>");
    }
}
print("</table><br><br><br>");
?>
<blockquote><p align=left><b>How do I get points?</b><br>
You receive 0.22 points for every 10 minutes the system registers you as being a seeder.<br>
You well receive 50.0 points for uploading a new torrent.<br>
You well receive 10.0 points for leaving a comment on a torrent (that includes a quick thanks).<br>
You well receive 10.0 points for leaving a comment on a news artical.<br>
(Note any comment deleted By you or staff well result in loss of those points so no flooding)
</p></blockquote>
</td></tr>
<tr><td><a href=user.php?op=profile&id=<?php echo $userid?>>Back to your profile</a></td></tr>

</table>
<?php
if ($action == "exchange") {
global $seedbonus, $invites;
$userid = $_POST["userid"];
$option = $_POST["option"];
$points = $_POST["points"];
$bonus = $_POST["bonus"];

$seedbonus2=number_format($user->seedbonus-$points,1);

$art = $_POST["art"];
$modcomment = $user->modcomment;
$upload = $user->uploaded;
$bpoints = $user->seedbonus;
$sql = ("SELECT * FROM ".$db_prefix."_bonus WHERE id='$option'");
$res = $db->sql_query($sql);
$bytes = $db->sql_fetchrow($res);
$up = $user->uploaded+$bytes['menge'];
$invites = $user->invites;
$inv = $invites+$bytes['menge'];
if($seedbonus >= $points) {

    if($art == "traffic") {
          $modcomment = gmdate("Y-m-d") . " - User has traded " .$points. " Points for traffic.\n ".$bytes['menge']."" .$modcomment;
          $complete = $db->sql_query("UPDATE ".$db_prefix."_users SET uploaded = '".$up."', seedbonus = '$seedbonus2', modcomment = '$modcomment' WHERE id = '$userid'") or sqlerr(__FILE__, __LINE__);
          if($complete)bterror("You have Traded " .$points. " Points for traffic","Sucsess");
	} elseif($art == "invite") {
         $modcomment = gmdate("Y-m-d") . " - User has traded " .$points. " Points for invites.\n " .$modcomment;
         $complete = $db->sql_query("UPDATE ".$db_prefix."_users SET invites = '".$inv."', seedbonus = '$seedbonus2', modcomment = '$modcomment' WHERE id = '$userid'") or sqlerr(__FILE__, __LINE__);
		 if($complete)bterror("You have Traded " .$points. " Points for invites","Sucsess");
    }
        else {
        echo "No valid type";
    }

} else {
      echo "Not enough points to trade...";
      }
}

CloseTable();
include("footer.php");
?>