<?php
/*
*----------------------------phpMyBitTorrent V 2.0.4---------------------------*
*--- The Ultimate BitTorrent Tracker and BMS (Bittorrent Management System) ---*
*--------------   Created By Antonio Anzivino (aka DJ Echelon)   --------------*
*-------------------   And Joe Robertson (aka joeroberts)   -------------------*
*-------------               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 --*
*--                                                                          --*
*------------------------------------------------------------------------------*
*------              ©2010 phpMyBitTorrent Development Team              ------*
*-----------               http://phpmybittorrent.com               -----------*
*------------------------------------------------------------------------------*
*--------------------   Sunday, May 17, 2009 1:05 AM   ------------------------*
*/
if (defined('IN_PMBT'))die ("You can't include this file");
define('IN_PMBT', true);
include("header.php");
global $db, $db_prefix;
if(!checkaccess("offers")){
OpenErrTable(_btaccdenied);
echo "<p>".str_replace("**page**",_bt_offers_offers,_btnoautherized)."</p>\n";
CloseErrTable();
die();
}
OpenTable(_btaddrating);
$offerid = (int)$_GET["id"];
$userid = $user->id;
$res_offer = "SELECT * FROM ".$db_prefix."_offervotes WHERE offerid=$offerid and userid=$userid;";
$res = $db->sql_query($res_offer);
$arr = $db->sql_fetchrow($res);
$db->sql_freeresult($res_offer);
$voted = $arr;
if ($voted) {
OpenTable2(_bt_nocheat);
print("<div align=center>");
echo _bt_Offer_voted;
print("</div>");
CloseTable2();
}
else {
$sql = "UPDATE ".$db_prefix."_offers SET `votes` = `votes` + 1 WHERE id=$offerid;";
$db->sql_query($sql);
$sql = "INSERT INTO ".$db_prefix."_offervotes (offerid, userid) VALUES($offerid, $userid);";
$db->sql_query($sql);
OpenTable2(_bt_off_vote_th);
print("<div align=center>");
echo _bt_off_take_vote;
print("</div>");
CloseTable2();

}
$res1 = "SELECT ".$db_prefix."_offers.votes, ".$db_prefix."_offers.name FROM ".$db_prefix."_offers WHERE `id` = $id;";
$res = $db->sql_query($res1);
$arr = $db->sql_fetchrow($res);
$db->sql_freeresult($res1);
$torrent = "$arr[name]";
$zvote = "$arr[votes]";

if ( $zvote > 3) {
$res_user = "SELECT userid FROM ".$db_prefix."_offers WHERE id = $id;";
$res_id = $db->sql_query($res_user);
$pn_msg = _bt_off_canupload;
while($row = $db->sql_fetchrow($res_id)) {

                $sql = "INSERT INTO ".$db_prefix."_private_messages (sender, recipient, subject, text, sent) VALUES ('1','$row[userid]','Your Offered Torrent','".$pn_msg."',NOW());";

                $db->sql_query($sql) or btsqlerror($sql);
                $mid2 = $db->sql_nextid();
                include_once("language/mailtexts.php");
                $notify_mail = new eMail();
                $notify_mail->add($email);
                $notify_mail->sender = $admin_email;
                $notify_mail->subject = $newpmemailsub[$language];
                $search = Array("**user**","**sender**","**sitename**","**siteurl**","**mid2**");
                $replace = Array($name,$user->name,$sitename,$siteurl,$mid2);
                $notify_mail->body = str_replace($search,$replace,$newpmemailbody[$language]);
                $notify_mail->send();

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