"McGyver, post: 93170":
Ok thank you for the answer, more than to get to work
Ok merci de la réponse, plus qu'a me mettre au travail
SQL:
CREATE TABLE `snatched` (
`id` int(11) NOT NULL auto_increment,
`torrentid` int(11) default '0',
`userid` int(11) default '0',
`ip` varchar(64) NOT NULL default '',
`port` smallint(5) unsigned NOT NULL default '0',
`uploaded` bigint(20) unsigned NOT NULL default '0',
`downloaded` bigint(20) unsigned NOT NULL default '0',
`agent` varchar(60) NOT NULL default '',
`peer_id` varchar(20) NOT NULL default '',
`finished` enum('yes','no') NOT NULL default 'no',
`complete_date` datetime NOT NULL default '0000-00-00 00:00:00',
`start_date` datetime NOT NULL default '0000-00-00 00:00:00',
`last_action` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
ALTER TABLE `snatched` ADD `seed_end` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
Edit and search annouce.php :
function get_date_time($timestamp = 0)
{
if ($timestamp)
return date("Y-m-d H:i:s", $timestamp);
else
return gmdate("Y-m-d H:i:s");
}
Add After :
////////////////////Snatched////////////////////
$dt = gmtime() - 180;
$dt = sqlesc(get_date_time($dt));
////////////////End Snatched////////////////
Find :
if ($event == "stopped") {
Add After :
/////////////////////////////////////////SNATCHED/////////////////////////////////////////
$res_se = SQL_Query_exec("SELECT userid, seed_end, torrentid FROM snatched WHERE torrentid = $torrentid AND userid = $userid");
while ($row_se = mysql_fetch_assoc($res_se)) {
SQL_Query_exec("UPDATE snatched SET seed_end = $dt WHERE finished = 'yes' AND torrentid = ". $row_se[torrentid] ." AND userid = ". $row_se[userid] ."");
}
/////////////////////////////////////////END SNATCHED/////////////////////////////////////////
Find:
$updateset = "times_completed = times_completed + 1";
Add After :
/////////////////////////////////////////SNATCHED/////////////////////////////////////////
SQL_Query_exec("UPDATE snatched SET finished = 'yes', complete_date = $dt WHERE torrentid = $torrentid AND userid = $userid");
/////////////////////////////////////////END SNATCHED/////////////////////////////////////////
Find :
if (isset($self)){
Add After :
/////////////////////////////////////////SNATCHED/////////////////////////////////////////
$res_s = SQL_Query_exec("SELECT uploaded, downloaded FROM snatched WHERE torrentid = $torrentid AND userid = $userid");
$row_s = mysql_fetch_array($res_s);
$downloaded2 = max(0, $downloaded - $self["downloaded"]);
$uploaded2 = max(0, $uploaded - $self["uploaded"]);
SQL_Query_exec("UPDATE snatched SET uploaded = uploaded + $uploaded2, port = $port, agent= " . sqlesc($agent) . ", last_action = $dt WHERE torrentid = $torrentid AND userid = $userid");
SQL_Query_exec("UPDATE snatched SET downloaded = downloaded + $downloaded2 WHERE torrentid = $torrentid AND userid = $userid");
/////////////////////////////////////////END SNATCHED/////////////////////////////////////////
Find :
$updateset[] = "seeders = seeders - 1";
$updateset[] = "leechers = leechers + 1";
}
}
} else {
Add After :
/////////////////////////////////////////SNATCHED/////////////////////////////////////////
$res1_s = SQL_Query_exec("SELECT torrentid, userid FROM snatched WHERE torrentid = $torrentid AND userid = $userid") or err('Tracker error (120)');
$row1_s = mysql_fetch_assoc($res1_s);
if (!$row1_s)
SQL_Query_exec("INSERT INTO snatched (torrentid, userid, port, start_date, agent,ip,peer_id) VALUES ($torrentid, $userid, $port, $dt, " . sqlesc($agent) . "," . sqlesc($ip) . "," . sqlesc($peer_id) . ")");
/////////////////////////////////////////END SNATCHED/////////////////////////////////////////
[size=18px]NOW YOU HAVE TWO CHOISES[/size]
[size=14px]For those who want to have the snatchedlist in torrents detail :[/size]
Edit and search torrents-details.php :
if ($CURUSER) {
echo "<CENTER>";
echo "<form name="comment" method="post" action="torrents-details.php?id=$row[id]&takecomment=yes">";
echo "".textbbcode("comment","body")."<br>";
echo "<input type="submit" class=bouton value="Add Comment" />";
echo "</form></CENTER>";
}
end_frame();
Add After :
/////////////////////////////////////////SNATCHED/////////////////////////////////////////
begin_frame("Snatched List");
if ($CURUSER["edit_torrents"] == "yes"){
$res3 = SQL_Query_exec("SELECT count(snatched.id) from snatched inner join users on snatched.userid = users.id inner join torrents on snatched.torrentid = torrents.id where snatched.torrentid =" . $_GET[id]) or die(mysql_error());
$row = mysql_fetch_array($res3);
$count = $row[0];
$perpage = 15;
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $_SERVER["PHP_SELF"] . "?id=" . $_GET[id] . "&" );
$res6 = SQL_Query_exec("SELECT name, category from torrents where id = $_GET[id]");
$arr6 = mysql_fetch_assoc($res6);
$dt = gmtime() - 180;
$dt = sqlesc(get_date_time($dt));
print("<table width=80% border=1 cellspacing=0 cellpadding=5 align=center>n");
print("<tr><td class=table_table align=center colspan=11>Snatchdetails for: $s</td></tr>");
print("<tr>");
print("<td class=table_head align=center><b>Username</b></td>");
print("<td class=table_head align=center><b>Uploaded</b></td>");
print("<td class=table_head align=center><b>Downloaded</b></td>");
print("<td class=table_head align=center><b>Ratio</b></td>");
if ($CURUSER["edit_torrents"] == "yes"){
print("<td class=table_head align=center><b>Connected</b></td>");
print("<td class=table_head align=center><b>Stats</b></td>");
}
print("<td class=table_head align=center><b>Startdate</b></td>");
print("<td class=table_head align=center><b>Enddate</b></td>");
print("<td class=table_head align=center><b>Last action</b></td>");
print("<td class=table_head align=center><b>Seed end</b></td>");
print("<td class=table_head align=center><b>Seedtime</b></td>");
print("<td class=table_head align=center><b>Finished</b></td>");
print("<td class=table_head align=center><b>Seeding</b></td>");
print("</tr>");
$res = SQL_Query_exec("select users.id, users.username, users.uploaded, users.downloaded, snatched.userid, UNIX_TIMESTAMP(snatched.start_date) AS st, UNIX_TIMESTAMP(snatched.last_action) AS lt, UNIX_TIMESTAMP(snatched.complete_date) AS ct, UNIX_TIMESTAMP(snatched.seed_end) AS se from snatched inner join users on snatched.userid = users.id inner join torrents on snatched.torrentid = torrents.id where snatched.torrentid =" . $_GET[id] . " ORDER BY snatched.id desc $limit");
while ($arr = mysql_fetch_assoc($res)) {
$res2 = SQL_Query_exec("SELECT id,donated,title,enabled,warned,last_access FROM users WHERE id=$arr[userid]") or sqlerr(__FILE__, __LINE__); $arr2 = mysql_fetch_assoc($res2);
$res3 = SQL_Query_exec("SELECT * FROM peers WHERE torrent=$_GET[id] AND userid=$arr[userid]");
$arr3 = mysql_fetch_assoc($res3);
if ($arr["downloaded"] > 0) {
$ratio = number_format($arr["uploaded"] / $arr["downloaded"], 3);
$ratio = "<font color=" . get_ratio_color($ratio) . ">$ratio</font>";
}elseif ($arr["uploaded"] > 0)
$ratio = "Inf.";
else$ratio = "---";
$uploaded =mksize($arr["uploaded"]);
$downloaded = mksize($arr["downloaded"]);
$res5 = SQL_Query_exec("SELECT * FROM snatched WHERE torrentid = " . $_GET[id] . " AND userid = ". $arr[userid] ."");
while ($arr5 = mysql_fetch_assoc($res5)) {
if ($arr5["downloaded"] > 0) {
$ratio1 = number_format($arr5["uploaded"] / $arr5["downloaded"], 3);
$ratio1 = "<font color=" . get_ratio_color($ratio1) . ">$ratio1</font>";
}elseif ($arr5["uploaded"] > 0)$ratio1 = "Inf.";
else
$ratio1 = "---";
$stime = mkprettytime($arr[se] - $arr[ct]);
print("<tr>");
print("<td class=table_col1 align=center><a href=account-details.php?id=$arr[userid]><b>$arr[username]</b></a></td>");
print("<td class=table_col2 align=center><font class=small><font color=green><u>Global:</u></font></font><br>$uploaded<br><font class=small><font color=green><u>Torrent:</u></font></font><br>". mksize($arr5[uploaded]) ."</td>");
print("<td class=table_col1 align=center><font class=small><font color=green><u>Global:</u></font></font><br>$downloaded<br><font class=small><font color=green><u>Torrent:</u></font></font><br>". mksize($arr5[downloaded]) ."</td>");
print("<td class=table_col2 align=center><font class=small><font color=green><u>Global:</u></font></font><br>$ratio<br><font class=small><font color=green><u>Torrent:</u></font></font><br>$ratio1</td>");
if ($CURUSER["edit_torrents"] == "yes"){
print("<td class=table_col1 align=center><font class=small><font color=green><u>Client:</u></font></font><br>". $arr5[agent] ."<br><font class=small><font color=green><u>Peer-ID:</u></font></font><br>". $arr5[peer_id] ."</td>");
print("<td class=table_col2 align=center><font class=small><font color=green><u>IP:</u></font></font><br>". $arr5[ip] ."<br><font class=small><font color=green><u>Port:</u></font></font><br>". $arr5[port] ."</td>");
}
print("<td class=table_col1 align=center>". $arr5[start_date] ."</td>");
print("<td class=table_col2 align=center>". $arr5[complete_date] ."</td>");
print("<td class=table_col1 align=center>". $arr5[last_action] ."</td>");
if ($arr3["seeder"] == "yes")
print("<td class=table_col2 align=center><font color=green>Waiting<br>for<br>stats</font></td>");
else
print("<td class=table_col1 align=center>". $arr5[seed_end] ."</td>");
if ($arr3["seeder"] == "yes")
print("<td class=table_col2 align=center><font color=green>Waiting<br>for<br>stats</font></td>");
else
print("<td class=table_col1 align=center>$stime</td>");
print("<td class=table_col2 align=center>" . ($arr5["finished"] == "yes" ? "<b><font color=green>Yes</font>" : "<font color=red>No</font></b>") . "</td>");
print("<td class=table_col1 align=center>" . ($arr3["seeder"] == "yes" ? "<b><font color=green>Yes</font>" : "<font color=red>No</font></b>") . "</td>");
print("</tr>n");
}
}
print("</table><br>n");
print("$pagertop");
}//// end ////
end_frame();
/////////////////////////////////////////END SNATCHED/////////////////////////////////////////
[size=14px]For Those who prefer see the snatchedlist in a new page (better for the server load)[/size]
Edit and search torrents-details.php :
echo "[<a href='torrents-edit.php?id=$row[id]&returnto=" . urlencode($_SERVER["REQUEST_URI"]) . "'><b>".T_("EDIT_TORRENT")."</b></a>]";
Replace by :
echo " <a href='torrents-edit.php?id=$row[id]'><img border='0' src='images/editer-detail-torrent.png' title='Éditer votre torrent !' width='40' height='40' /></a> ";
echo " <a href='snatched.php?tid=".$row['id']."'><img border='0' src='images/H&R.png' title='Votre H&R !' width='40' height='40' /></a>";
And create viewsnatches.php with the following code, and upload it to root folder :
<?php
require_once("backend/functions.php");
dbconn(false);
loggedinonly();
stdhead("Snatch Details");
$res3 = SQL_Query_exec("select count(snatched.id) from snatched inner join users on snatched.userid = users.id inner join torrents on snatched.torrentid = torrents.id where snatched.torrentid =" . $_GET[id]) or die(mysql_error());
$row = mysql_fetch_array($res3);
$count = $row[0];
$perpage = 50;
$res6 = SQL_Query_exec("select name, category from torrents where id = $_GET[id]");
$arr6 = mysql_fetch_assoc($res6);
$dt = gmtime() - 180;
$dt = sqlesc(get_date_time($dt));
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $_SERVER["PHP_SELF"] . "?id=" . $_GET[id] . "&" );
begin_frame("Snatch Details for <a href=torrents-details.php?id=$_GET[id]><b>" . $arr6["name"] . "</b></a>");
print("<p align=center>The users at the top finished the download most recently</p>");
print("<table width=80% border=1 cellspacing=0 cellpadding=5 align=center class=table_table>n");
print("<tr><td class=table_table align=center colspan=11>Snatchdetails for: $arr6[name]</td></tr>");
print("<tr>");
print("<td class=table_head align=center><b>Username</b></td>");
print("<td class=table_head align=center><b>Uploaded</b></td>");
print("<td class=table_head align=center><b>Downloaded</b></td>");
print("<td class=table_head align=center><b>Ratio</b></td>");
if ($CURUSER["edit_torrents"] == "yes"){
print("<td class=table_head align=center><b>Connected</b></td>");
print("<td class=table_head align=center><b>Stats</b></td>");
}
print("<td class=table_head align=center><b>Startdate</b></td>");
print("<td class=table_head align=center><b>Enddate</b></td>");
print("<td class=table_head align=center><b>Last action</b></td>");
print("<td class=table_head align=center><b>Seed end</b></td>");
print("<td class=table_head align=center><b>Seedtime</b></td>");
print("<td class=table_head align=center><b>Finished</b></td>");
print("<td class=table_head align=center><b>Seeding</b></td>");
print("</tr>");
$res = SQL_Query_exec("select users.id, users.username, users.uploaded, users.downloaded, snatched.userid, UNIX_TIMESTAMP(snatched.start_date) AS st, UNIX_TIMESTAMP(snatched.last_action) AS lt, UNIX_TIMESTAMP(snatched.complete_date) AS ct, UNIX_TIMESTAMP(snatched.seed_end) AS se from snatched inner join users on snatched.userid = users.id inner join torrents on snatched.torrentid = torrents.id where snatched.torrentid =" . $_GET[id] . " ORDER BY snatched.id desc $limit");
while ($arr = mysql_fetch_assoc($res)) {
$res2 = SQL_Query_exec("SELECT id,donated,title,enabled,warned,last_access FROM users WHERE id=$arr[userid]") or sqlerr(__FILE__, __LINE__);
$arr2 = mysql_fetch_assoc($res2);
$res3 = SQL_Query_exec("SELECT * FROM peers WHERE torrent=$_GET[id] AND userid=$arr[userid]");
$arr3 = mysql_fetch_assoc($res3);
if ($arr["downloaded"] > 0) {
$ratio = number_format($arr["uploaded"] / $arr["downloaded"], 3);
$ratio = "<font color=" . get_ratio_color($ratio) . ">$ratio</font>";
} else if ($arr["uploaded"] > 0) $ratio = "Inf.";
else $ratio = "---";
$uploaded =mksize($arr["uploaded"]);
$downloaded = mksize($arr["downloaded"]);
$res5 = SQL_Query_exec("SELECT * FROM snatched WHERE torrentid = " . $_GET[id] . " AND userid = ". $arr[userid] ."");
while ($arr5 = mysql_fetch_assoc($res5)) {
if ($arr5["downloaded"] > 0) {
$ratio1 = number_format($arr5["uploaded"] / $arr5["downloaded"], 3);
$ratio1 = "<font color=" . get_ratio_color($ratio1) . ">$ratio1</font>";
} else if ($arr5["uploaded"] > 0) $ratio1 = "Inf.";
else $ratio1 = "---";
$stime = mkprettytime($arr[se] - $arr[ct]);
print("<tr>");
print("<td class=table_col1 align=center><a href=account-details.php?id=$arr[userid]><b>$arr[username]</b></a></td>");
print("<td class=table_col2 align=center><font class=small><font color=green><u>Global:</u></font></font><br>$uploaded<br><font class=small><font color=green><u>Torrent:</u></font></font><br>". mksize($arr5[uploaded]) ."</td>");
print("<td class=table_col1 align=center><font class=small><font color=green><u>Global:</u></font></font><br>$downloaded<br><font class=small><font color=green><u>Torrent:</u></font></font><br>". mksize($arr5[downloaded]) ."</td>");
print("<td class=table_col2 align=center><font class=small><font color=green><u>Global:</u></font></font><br>$ratio<br><font class=small><font color=green><u>Torrent:</u></font></font><br>$ratio1</td>");
if ($CURUSER["edit_torrents"] == "yes"){
print("<td class=table_col1 align=center><font class=small><font color=green><u>Client:</u></font></font><br>". $arr5[agent] ."<br><font class=small><font color=green><u>Peer-ID:</u></font></font><br>". $arr5[peer_id] ."</td>");
print("<td class=table_col2 align=center><font class=small><font color=green><u>IP:</u></font></font><br>". $arr5[ip] ."<br><font class=small><font color=green><u>Port:</u></font></font><br>". $arr5[port] ."</td>");
}
print("<td class=table_col1 align=center>". $arr5[start_date] ."</td>");
print("<td class=table_col2 align=center>". $arr5[complete_date] ."</td>");
print("<td class=table_col1 align=center>". $arr5[last_action] ."</td>");
if ($arr3["seeder"] == "yes")
print("<td class=table_col2 align=center><font color=green>Waiting<br>for<br>stats</font></td>");
else
print("<td class=table_col1 align=center>". $arr5[seed_end] ."</td>");
if ($arr3["seeder"] == "yes")
print("<td class=table_col2 align=center><font color=green>Waiting<br>for<br>stats</font></td>");
else
print("<td class=table_col1 align=center>$stime</td>");
print("<td class=table_col2 align=center>" . ($arr5["finished"] == "yes" ? "<b><font color=green>Yes</font>" : "<font color=red>No</font></b>") . "</td>");
print("<td class=table_col1 align=center>" . ($arr3["seeder"] == "yes" ? "<b><font color=green>Yes</font>" : "<font color=red>No</font></b>") . "</td>");
print("</tr>n");
print("</tr>");
}
}
print("</table>");
print("$pagerbottom");
end_frame();
stdfoot();
?>
Now Edit account-details.php
And where do you want to display the snatched List put this code :
//////////////////////////////////////SNATCHED/////////////////////////////////
$r = SQL_Query_exec("SELECT snatched.torrentid, snatched.uploaded, snatched.downloaded, snatched.complete_date, snatched.last_action, snatched.start_date, torrents.seeders, torrents.leechers, UNIX_TIMESTAMP(snatched.start_date) AS st, UNIX_TIMESTAMP(snatched.last_action) AS lt, UNIX_TIMESTAMP(snatched.complete_date) AS ct, snatched.start_date FROM snatched JOIN torrents ON torrents.id = snatched.torrentid WHERE snatched.finished='yes' AND userid=$id ORDER BY last_action") or sqlerr();
$completed = "<table class=main border=1 cellspacing=0 cellpadding=3>n" ."<tr>n" ."<td class=table_head align=center>Cat</td>n" ."<td class=table_head align=center>Torrent</td>n" ."<td class=table_head align=center>Upl.</td>n" ."<td class=table_head align=center>Downl.</td>n" ."<td class=table_head align=center>Startdate</td>n" ."<td class=table_head align=center>Enddate</td>n" ."<td class=table_head align=center>Last action</td>n" ."<td class=table_head align=center>Leechtime</td>n" ."<td class=table_head align=center>Seeder</td>n" ."<td class=table_head align=center>Leecher</td>n" ."</tr>n";
while ($a = mysql_fetch_assoc($r)) {
$r1 = SQL_Query_exec("SELECT * FROM torrents WHERE id = ". $a[torrentid] ."") or sqlerr(__FILE__, __LINE__);
$a1 = mysql_fetch_assoc($r1);
$r2 = SQL_Query_exec("SELECT name, image FROM categories WHERE id = ". $a1[category] ."") or sqlerr(__FILE__, __LINE__);
$a2 = mysql_fetch_assoc($r2);
if ($a["downloaded"] > 0) {
$ratio = number_format($a["uploaded"] / $a["downloaded"], 3);
$ratio = "<font color=" . get_ratio_color($ratio) . ">$ratio</font>";
}elseif ($a["uploaded"] > 0)
$ratio = "Inf.";
else
$ratio = "---";
$uploaded =mksize($a["uploaded"]);
$downloaded = mksize($a["downloaded"]);
$cat = "<img src="/images/categories/$a2[image]" alt="$a2[name]">";
$starttime = $a['start_date'];
$endtime = $a['complete_date'];
$last_action = $a['last_action'];
$leechtime = mkprettytime($a[ct] - $a[st]);
$seedtime = mkprettytime($a[lt] - $a[ct]);
$td = mysql_query("SELECT * FROM torrents WHERE id = ". $a[torrentid] ."");
while ($tdl = mysql_fetch_assoc($td)) {
$timesdownloaded = $a["downloaded"] / $tdl["size"];
}
$smallname3 =substr(htmlspecialchars($a1["name"]) , 0, 20);
if ($smallname3 != htmlspecialchars($a1["name"])) {
$smallname3 .= '...';
}
$completed .= "<tr>n" ."<td class=table_col1 align=center><a href=torrents.php?cat=". $a1[category] .">$cat</a></td>n" ."<td class=table_col2><a href=torrents-details.php?id=". $a[torrentid] ."><b>$smallname3</b></a></td>n" ."<td class=table_col1 align=center>$uploaded</td>n" ."<td class=table_col2 align=center>$downloaded</td>n" ."<td class=table_col1 align=center>$starttime</td>n" ."<td class=table_col2 align=center>$endtime</td>n" ."<td class=table_col1 align=center>$last_action</td>n" ."<td class=table_col2 align=center>$leechtime</td>n" ."<td class=table_col1 align=center>". $a[seeders] ."</td>n" ."<td class=table_col1 align=center>". $a[leechers] ."</td>n" ."</tr>n";
}
$completed .= "</table>";
$res_tor_c = SQL_Query_exec("SELECT id FROM snatched WHERE userid = ". $user[id] ." AND finished='yes'");
$tor_c = mysql_num_rows($res_tor_c);
if ($user["id"] == $CURUSER["id"] || $CURUSER["edit_torrents"]=="yes") {
if ($completed)
begin_frame("User's Snatched Torrents");
echo "<b>Completed torrents:</b> <img src='images/plus.gif' id='pic1' onclick='klappe_torrent(1)'> <b>$tor_c Completed Torrent(s)</b><div id='k1' style='display: none;'>$completed</div>";
end_frame();
}
//////////////////////////////////////////////////////////////////////////////
Now the cleaning part..
Edit and search ../backend/functions.php :
SQL_Query_exec("DELETE FROM torrents WHERE id = $id");
Add After :
SQL_Query_exec("DELETE FROM snatched WHERE torrentid = $id");
Find :
SQL_Query_exec("DELETE FROM users WHERE id = $userid");
Add Before :
SQL_Query_exec("DELETE FROM snatched WHERE userid = $userid");
Upload attached file to root folder.
NOTE : This is a backup to me that comes from ValVanDeCamp whom I thank.