<?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;
OpenTable("Offer Vote");
$offerid = (int)$_GET["id"];
$userid = (int)getuserid($btuser);
$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("Don't Cheat!!!");
print("<div align=center>");
?>
<h3>You already have voted to this offer</h3>
<p>You already have voted to this offer, only 1 vote by member is allowed</p><p>Return to <a href=offers.php><b>Offers List</b></a></p>
<?php
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("Thank you for your Vote");
print("<div align=center>");
print("<h3>Vote Accepted</h3>");
print("<p>Your Vote has been counted</p><p>Back to <a href=offers.php><b>Offer List</b></a></p>");
print("</div>");
CloseTable2();

}
//////////////Test Messasge///////////////////
$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 = "Your offer \"$torrent\" have reached 3 votes.\nYou can now upload it to the tracker";
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();

                $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();

}
}
////////////////Test Message////////////////////
CloseTable();
include("footer.php");
die;
?>
