I did a load of work on VIP only torrents (
http://www.torrenttrader.org/index.php?showtopic=3913) a couple of years ago for TT1.x and now that I'm moving to 2.x, I needed to re-engineer it. I noticed that some of the code for Teams was there, but this wasn't working at all. I believe this code is functioning OK so I thought I'd put it up here. I've modded my site in other ways too, but I think I've managed to remove those bits of code.
BACKUP FIRST!
This is the way it works;
- Teams are created via the teams button in Control Panel
- User can be a member of one and only one team
- User cannot change their team membership
- Only Admins (class 7) can change a users' team membership (from the users details page)
- Team torrents are hidden from non-team members
- A user who is a team member can choose to make their upload available to anyone or just their team
- A torrent can only belong to either one team, or no team
- Admins can see all torrents, either public or belonging to any team
- A user can change their torrents team settings after upload
- A supermod who is a team member can change a torrents team settings if they are a member of that team
- A users' team membership can only be seen by Admins and another member of that team
And here is the code....
SQL
ALTER TABLE `torrents` ADD `team` VARCHAR( 10 ) NULL DEFAULT '0';
account.php
Find
<? print("<B>IP:</b> " . $CURUSER["ip"] . "\n"); ?><br>
Below add
<? $res = mysql_query("SELECT name,image FROM teams WHERE id=$CURUSER[team] LIMIT 1") or die(mysql_error());
if (mysql_num_rows($res) == 1) {
$arr = mysql_fetch_assoc($res);
echo "<tr><td colspan=2 align=left><B>Team Member Of:</B><BR>";
echo"<img src='".htmlspecialchars($arr["image"])."'><BR>".sqlesc($arr["name"])."</td></tr>";
} ?><br>
Find and remove (or comment out)
if ($CURUSER["class"] > 1)
print("<TR><TD align=right class=table_col1><B>Team:</b> </td><TD align=left class=table_col1><select name=teams>\n$teams\n</select></td></tr>");
Find
<? print("<B>IP:</b> " . $CURUSER["ip"] . "\n"); ?><br>
Below Add
<? $res = mysql_query("SELECT name,image FROM teams WHERE id=$CURUSER[team] LIMIT 1") or die(mysql_error());
if (mysql_num_rows($res) == 1) {
$arr = mysql_fetch_assoc($res);
echo "<tr><td colspan=2 align=left><B><center>Team Member Of:</B><BR>";
echo"<img src='".htmlspecialchars($arr["image"])."'><BR>".sqlesc($arr["name"])."</center></td></tr>";
} ?><br>
Account-details.php
Find
if ($CURUSER["class"] > $user["class"]){
print("<tr><td>Class</td><td align=left><select name=class>\n");
$maxclass = $CURUSER["class"];
for ($i = 1; $i < $maxclass; ++$i)
print("<option value=$i" . ($user["class"] == $i ? " selected" : "") . ">$prefix" . get_user_class_name($i) . "\n");
print("</select></td></tr>\n");
}
After Add
if ($CURUSER['class'] == 7)
{
$teams = "<option value=0>--- None selected ----</option>\n";
$sashok = mysql_query("SELECT id,name FROM teams ORDER BY name") or die;
while ($sasha = mysql_fetch_array($sashok))
$teams .= "<option value=$sasha[id]" . ($user["team"] == $sasha['id'] ? " selected" : "") . ">$sasha[name]</option>\n";
print("<TR><TD>Team</td><TD align=left><select name=teams>\n$teams\n</select></tr>");
}
else
print("<input type=hidden name=teams value=$user[team]>");
Find
$res = mysql_query("SELECT torrent,uploaded,downloaded FROM peers WHERE userid='$id' AND seeder='yes'");
if (mysql_num_rows($res) > 0)
$seeding = peerstable($res);
$res = mysql_query("SELECT torrent,uploaded,downloaded FROM peers WHERE userid='$id' AND seeder='no'");
if (mysql_num_rows($res) > 0)
$leeching = peerstable($res);
Replace with
$res = mysql_query("SELECT torrent,uploaded,downloaded FROM peers LEFT JOIN torrents ON torrent = torrents.id WHERE userid='$id' AND seeder='yes' AND (torrents.team = 0 OR torrents.team = ".$CURUSER['team']. " OR ".$CURUSER['class']." = 7)");
if (mysql_num_rows($res) > 0)
$seeding = peerstable($res);
$res = mysql_query("SELECT torrent,uploaded,downloaded FROM peers LEFT JOIN torrents ON torrent = torrents.id WHERE userid='$id' AND seeder='no' AND (torrents.team = 0 OR torrents.team = ".$CURUSER['team']. " OR ".$CURUSER['class']." = 7)");
if (mysql_num_rows($res) > 0)
$leeching = peerstable($res);
Find
$res = mysql_query("SELECT COUNT(*) FROM torrents WHERE owner='$id' $where") or die(mysql_error());
Replace With
$res = mysql_query("SELECT COUNT(*) FROM torrents WHERE owner='$id' $where AND (torrents.team = 0 OR torrents.team = ".$CURUSER['team']. " OR ".$CURUSER['class']." = 7)") or die(mysql_error());
Find
$query = "SELECT torrents.id, torrents.category, torrents.leechers, torrents.nfo, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, categories.name AS cat_name, categories.parent_cat AS cat_parent, categories.image AS cat_pic, users.username, users.privacy, torrents.anon, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, torrents.announce FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id WHERE owner = $id $orderby $limit";
Replace with
$query = "SELECT teams.name AS teamname, teams.image AS teamimage, torrents.team, torrents.id, torrents.category, torrents.leechers, torrents.nfo, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, categories.name AS cat_name, categories.parent_cat AS cat_parent, categories.image AS cat_pic, users.username, users.privacy, torrents.anon, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, torrents.announce FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id LEFT JOIN teams ON torrents.team = teams.id WHERE torrents.owner = $id AND (torrents.team = 0 OR torrents.team = ".$CURUSER['team']. " OR ".$CURUSER['class']." = 7) $orderby $limit";
Find
<a href=report.php?user=<?=$user["id"]?>>Report Member</a><BR>
</td>
</tr>
After Add
<?
//team
if (($CURUSER['team'] == $user['team']) OR ($CURUSER['class'] ==7))
{
$res = mysql_query("SELECT name,image FROM teams WHERE id=$user[team] LIMIT 1") or die(mysql_error());
if (mysql_num_rows($res) == 1) {
$arr = mysql_fetch_assoc($res);
echo "<tr><td colspan=2 align=left><B>Team Member Of:</B><BR>";
echo"<img src='".htmlspecialchars($arr["image"])."'><BR>".sqlesc($arr["name"])."<BR><BR><a href=teams-view.php>[View Teams]</a></td></tr>";
}
}
?>
Find
$res = mysql_query("SELECT COUNT(*) FROM torrents WHERE owner=$id") or die(mysql_error());
Replace with
$res = mysql_query("SELECT COUNT(*) FROM torrents WHERE owner=$id AND (torrents.team = 0 OR torrents.team = ".$CURUSER['team']. " OR ".$CURUSER['class']." = 7)") or die(mysql_error());
Admin-modtasks.php
Find
$class = (int)$_POST["class"];
After Add
$teams = $_POST["teams"];
Find
mysql_query("UPDATE users SET title='$title', downloaded='$downloaded', uploaded='$uploaded', signature='$signature', avatar='$avatar', ip='$ip', donated='$donated', forumbanned='$forumbanned', warned='$warned', modcomment='$modcomment', enabled='$enabled', invites='$invites' WHERE id=$userid");
Replace with
mysql_query("UPDATE users SET title='$title', downloaded='$downloaded', uploaded='$uploaded', signature='$signature', avatar='$avatar', ip='$ip', donated='$donated', forumbanned='$forumbanned', warned='$warned', modcomment='$modcomment', enabled='$enabled', invites='$invites', team='$teams' WHERE id=$userid");
Torrents-upload.php
Find
$ret = mysql_query("INSERT INTO torrents (filename, owner, name, descr, image1, image2, category, added, info_hash, size, numfiles, save_as, announce, external, nfo, torrentlang, anon) VALUES (".sqlesc($fname).", '".$CURUSER['id']."', ".sqlesc($name).", ".sqlesc($descr).", '".$inames[0]."', '".$inames[1]."', '".$type."', '" . get_date_time() . "', '".$infohash."', '".$torrentsize."', '".$filecount."', ".sqlesc($fname).", '".$announce."', '".$external."', '".$nfo."', '".$langid."','$anon')");
Replace With
$ret = mysql_query("INSERT INTO torrents (filename, owner, name, descr, image1, image2, category, added, info_hash, size, numfiles, save_as, announce, external, nfo, torrentlang, anon, team) VALUES (".sqlesc($fname).", '".$CURUSER['id']."', ".sqlesc($name).", ".sqlesc($descr).", '".$inames[0]."', '".$inames[1]."', '".$type."', '" . get_date_time() . "', '".$infohash."', '".$torrentsize."', '".$filecount."', ".sqlesc($fname).", '".$announce."', '".$external."', '".$nfo."', '".$langid."','$anon','".$team."')");
Find
$langid = (0 + $_POST["lang"]);
After add
$team = (0 + $_POST["teams"]);
Find
//end requests
After Add
//teams
if ($CURUSER["team"] != 0)
{
$userteam = $CURUSER["team"];
$teams = "<option value=0>--- None selected ----</option>\n";
$sashok = mysql_query("SELECT id,name FROM teams WHERE id = $userteam ORDER BY name") or die;
while ($sasha = mysql_fetch_array($sashok))
$teams .= "<option value=$sasha[id]" . ($user["team"] == $sasha['id'] ? " selected" : "") . ">$sasha[name]</option>\n";
print("<TR><td align=right>Team</td><TD align=left><select name=teams>\n$teams\n</select></tr>");
}
Index.php
Find
$query = "SELECT torrents.id, torrents.anon, torrents.announce, torrents.category, torrents.leechers, torrents.nfo, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, categories.name AS cat_name, categories.image AS cat_pic, categories.parent_cat AS cat_parent, users.username, users.privacy, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id WHERE visible = 'yes' AND banned = 'no' ORDER BY id DESC LIMIT 25";
Replace with
$query = "SELECT users.team AS userteam, teams.id AS teamsid, teams.name AS teamname, teams.image AS teamimage, torrents.team, torrents.id, torrents.anon, torrents.announce, torrents.category, torrents.leechers, torrents.nfo, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, categories.name AS cat_name, categories.image AS cat_pic, categories.parent_cat AS cat_parent, users.username, users.privacy, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN teams ON torrents.team = teams.id LEFT JOIN users ON torrents.owner = users.id WHERE (".$CURUSER['team']." = torrents.team OR torrents.team = 0 OR ".$CURUSER['class']." = 7) AND visible = 'yes' AND banned = 'no' ORDER BY id DESC LIMIT 25";
functions.php
Find
$dispname = "<b>".$smallname."</b>";
Below add
if ($row["team"]!= 0)
$dispname .= " <img src='".$row["teamimage"]."' border='0' alt = '".$row["teamname"]."'>";
Find
function langlist() {
$ret = array();
$res = mysql_query("SELECT id, name, image FROM torrentlang ORDER BY sort_index, id");
while ($row = mysql_fetch_array($res))
$ret[] = $row;
return $ret;
}
Below Add
function teamslist() {
$ret = array();
$res = mysql_query("SELECT id, name FROM teams ORDER BY name");
while ($row = mysql_fetch_array($res))
$ret[] = $row;
return $ret;
}
Mostactivetorrents_block.php
Find
//$where = "WHERE external !='yes'"
Below Add
$where = "WHERE team = 0";
Seedwanted_block.php
Find
$seederswantedquery = mysql_query("SELECT id,name,seeders,leechers FROM torrents WHERE seeders ='0' and external !='yes' ORDER BY leechers DESC LIMIT 5")or die(mysql_error());
Replace with
$seederswantedquery = mysql_query("SELECT id,name,seeders,leechers FROM torrents WHERE seeders ='0' and external !='yes' AND team = 0 ORDER BY leechers DESC LIMIT 5")or die(mysql_error());
Torrents-edit.php
Find
$updateset[] = "torrentlang = " . (0 + $language);
After add
$updateset[] = "team = " . (0 + $team);
Find
/END TORRENTLANG
After Add
//UPDATE TEAM DROPDOWN
$teamsdropdown = "<select name=\"team\"><option value=0>--- None Selected ---</option>\n";
$teams = teamslist();
foreach ($teams as $teams) {
if (($CURUSER['class'] == 7) OR ($teams["id"] == $CURUSER['team']))
{
$teamsdropdown .= "<option value=\"" . $teams["id"] . "\"";
if ($teams["id"] == $row["team"])
$teamsdropdown .= " selected=\"selected\"";
$teamsdropdown .= ">" . htmlspecialchars($teams["name"]) . "</option>\n";
}
}
$teamsdropdown .= "</select>\n";
//END team
Find
echo "<tr><td align=right><B>Language: </b></TD><TD>".$langdropdown."</TD></TR>";
After Add
if (($CURUSER['class'] == 7) OR ($CURUSER['id'] == $row['owner'] AND $CURUSER['team'] != 0))
{
echo "<tr><td align=right><B>Team: </b></TD><TD>".$teamsdropdown."</TD></TR>";
}
rss.php (if you have one)
Find
// by category ?
if (!$cat){
$catvar ="WHERE visible='yes'"; //just show last visible
}else{
$catvar ="WHERE categories.id ='$cat' AND visible='yes'";
}
Replace with
// by category ?
if (!$cat){
$catvar ="WHERE visible='yes' AND torrents.team = 0"; //just show last visible
}else{
$catvar ="WHERE categories.id ='$cat' AND visible='yes' AND torrents.team = 0";
}
Torrents-today.php
Find
$query = "SELECT torrents.id, torrents.category, torrents.leechers, torrents.nfo, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, categories.name AS cat_name, categories.parent_cat AS cat_parent, categories.image AS cat_pic, users.username, users.privacy FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id $where AND torrents.added>='$date_time' $orderby $limit";
Replace With
$query = "SELECT users.team AS userteam, teams.id AS teamsid, teams.name AS teamname, teams.image AS teamimage, torrents.team, torrents.id, torrents.category, torrents.leechers, torrents.nfo, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, categories.name AS cat_name, categories.parent_cat AS cat_parent, categories.image AS cat_pic, users.username, users.privacy FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN teams ON torrents.team = teams.id LEFT JOIN users ON torrents.owner = users.id $where AND torrents.added>='$date_time' $orderby $limit";
torrents.php
Find
if ($where != "")
$where = "WHERE $where";
Replace With
if ($where != "")
$where = "WHERE $where AND (".$CURUSER['team']." = torrents.team OR torrents.team = 0 OR ".$CURUSER['class']."= 7)";
Find
$query = "SELECT torrents.id, torrents.anon, torrents.announce, torrents.category, torrents.leechers, torrents.nfo, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, categories.name AS cat_name, categories.parent_cat AS cat_parent, categories.image AS cat_pic, users.username, users.privacy, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id $where $parent_check $orderby $limit";
Replace with
$query = "SELECT users.team AS userteam, teams.id AS teamsid, teams.name AS teamname, teams.image AS teamimage, torrents.team, torrents.id, torrents.anon, torrents.announce, torrents.category, torrents.leechers, torrents.nfo, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, categories.name AS cat_name, categories.parent_cat AS cat_parent, categories.image AS cat_pic, users.username, users.privacy, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating FROM torrents LEFT JOIN teams ON torrents.team = teams.id LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id $where $parent_check $orderby $limit";
Search.php
find
$wherea[] = "banned = 'no'"
Replace with
$wherea[] = "banned = 'no' AND (".$CURUSER['team']." = torrents.team OR torrents.team = 0 OR ".$CURUSER['class']."= 7)";
Find
$query = "SELECT torrents.id, torrents.anon, torrents.announce, torrents.category, torrents.leechers, torrents.nfo, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, categories.name AS cat_name, categories.parent_cat AS cat_parent, categories.image AS cat_pic, users.username, users.privacy, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id $where $parent_check $orderby $limit";
Replace with
$query = "SELECT users.team AS userteam, teams.id AS teamsid, teams.name AS teamname, teams.image AS teamimage, torrents.team, torrents.id, torrents.anon, torrents.announce, torrents.category, torrents.leechers, torrents.nfo, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, categories.name AS cat_name, categories.parent_cat AS cat_parent, categories.image AS cat_pic, users.username, users.privacy, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN teams ON torrents.team = teams.id LEFT JOIN users ON torrents.owner = users.id $where $parent_check $orderby $limit";
download.php
Find
$res = mysql_query("SELECT filename, external, announce FROM torrents WHERE id =".intval($id));
Replace with
$res = mysql_query("SELECT filename, external, announce, team FROM torrents WHERE id =".intval($id));
Find
show_error_msg("File not found", "The ID and torrent were found, but the torrent is NOT readable!",1);
After add
if (($CURUSER['team'] != $row['team']) AND ($CURUSER['class'] < 7) AND ($row['team'] != 0))
show_error_msg("Restricted torrent", "The torrent you are attempting to download is restricted.",1);
Hope it works for you!
Cheers
Simon