<?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               -----------*
*------------------------------------------------------------------------------*
*-----------------   Sunday, September 14, 2008 9:05 PM   ---------------------*
*/

include("header.php");
global $db, $db_prefix;

$res = $db->sql_query("SELECT 1 FROM ".$db_prefix."_torrents WHERE id = $id")or die(mysql_error());
$row = $db->sql_fetchrow($res);
if (!$row)
die();

$ras = $db->sql_query("select 1 from ".$db_prefix."_thanks WHERE torid='$id' AND uid ='" .$user->id . "' ") or die(mysql_error());
$raw = $db->sql_fetchrow($ras);
if ($raw)

bterror("You already posted a thankyou on this torrent.","Sorry");

$text = ":thankyou:";

                        $db->sql_query("INSERT INTO ".$db_prefix."_thanks (uid, torid, thank_date) VALUES ('" .$user->id . "',$id, NOW())")or die(mysql_error());
                        $db->sql_query("INSERT INTO ".$db_prefix."_comments (user, torrent, added, text) VALUES ('" .$user->id . "', '".$id."', NOW(), '" . $text . "')")or die(mysql_error());
                        $bon = "SELECT active, comment FROM ".$db_prefix."_bonus_points ;";
                        $bonset = $db->sql_query($bon);
                        list ($active, $comment_point) = $db->sql_fetchrow($bonset);
                        $db->sql_freeresult($bonset);
						if($active=='true')
						{
						$docheck= "SELECT id FROM ".$db_prefix."_comments WHERE torrent = '".$id."' AND user = '" .$user->id . "' LIMIT 1;";
						$res = $db->sql_query($docheck) or btsqlerror($docheck);
                        $has_com = ($db->sql_numrows($res) > 0) ? true : false;
                        $db->sql_freeresult($res);
						$docheck2= "SELECT id FROM ".$db_prefix."_snatched WHERE torrent = '".$id."' AND userid = '" .$user->id . "' LIMIT 1;";
						$res2 = $db->sql_query($docheck2) or btsqlerror($docheck2);
                        $has_sna = ($db->sql_numrows($res2) > 0) ? true : false;
                        $db->sql_freeresult($res2);
						$do="UPDATE ".$db_prefix."_users SET seedbonus = seedbonus + '".$comment_point."' WHERE id= ".$user->id."" ;
                        if (!$has_com AND $has_sna)$db->sql_query($do) or btsqlerror($do);
						}



$db->sql_query("UPDATE ".$db_prefix."_torrents SET comments = comments + 1, thanks = thanks + 1 WHERE id = $id")or die(mysql_error());

header("Refresh: 0; url=details.php?id=$id#comm$newid");

include("footer.php");

?>