if (!check_perms('users_mod')) { error(403); }
if (isset($_REQUEST['addtokens'])) {
authorize();
$Tokens = $_REQUEST['numtokens'];
if (!is_number($Tokens) || ($Tokens < 0)) { error("Please enter a valid number of tokens."); }
$sql = "UPDATE users_main SET FLTokens = FLTokens + $Tokens WHERE Enabled = '1'";
if (!isset($_REQUEST['leechdisabled'])) {
$sql .= " AND can_leech = 1";
}
$DB->query($sql);
$message = "$Tokens freeleech tokens added to all enabled users" . (!isset($_REQUEST['leechdisabled'])?' with enabled leeching privs':'') . '.
';
} elseif (isset($_REQUEST['expire'])) {
$Tokens = $_REQUEST['tokens'];
foreach ($Tokens as $Token) {
list($UserID, $TorrentID) = explode(',', $Token);
if (empty($UserID) || empty($TorrentID)) { continue; }
$DB->query("SELECT info_hash FROM torrents where ID = $TorrentID");
if (list($InfoHash) = $DB->next_record()) {
$DB->query("UPDATE users_freeleeches SET Expired=TRUE WHERE UserID=$UserID AND TorrentID=$TorrentID");
$Cache->delete_value('users_tokens_'.$UserID);
if (!isset($_REQUEST['ocelot'])) { update_tracker('remove_token', array('info_hash' => rawurlencode($InfoHash), 'userid' => $UserID)); }
}
}
}
if (empty($_GET['showabusers'])) {
show_header('Add tokens sitewide');
?>