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);
$sql = "SELECT ID FROM users_main WHERE Enabled = '1'";
if (!isset($_REQUEST['leechdisabled'])) {
$sql .= " AND can_leech = 1";
}
$DB->query($sql);
while (list($UserID) = $DB->next_record()) {
$Cache->delete_value('user_info_heavy_'.$UserID);
}
$message = "$Tokens freeleech tokens added to all enabled users" . (!isset($_REQUEST['leechdisabled'])?' with enabled leeching privs':'') . '.
';
} elseif (isset($_REQUEST['cleartokens'])) {
authorize();
$Tokens = $_REQUEST['numtokens'];
if (!is_number($Tokens) || ($Tokens < 0)) { error("Please enter a valid number of tokens."); }
if (isset($_REQUEST['onlydrop'])) {
$Where = "WHERE FLTokens > $Tokens";
} elseif (!isset($_REQUEST['leechdisabled'])) {
$Where = "WHERE (Enabled = '1' AND can_leech = 1) OR FLTokens > $Tokens";
} else {
$Where = "WHERE Enabled = '1' OR FLTokens > $Tokens";
}
$DB->query("SELECT ID FROM users_main $Where");
$Users = $DB->to_array();
$DB->query("UPDATE users_main SET FLTokens = $Tokens $Where");
foreach ($Users as $UserID) {
list($UserID) = $UserID;
$Cache->delete_value('user_info_heavy_'.$UserID);
}
$where = "";
} elseif (isset($_REQUEST['expire'])) {
$Tokens = $_REQUEST['tokens'];
foreach ($Tokens as $Token) {
list($UserID, $TorrentID) = explode(',', $Token);
if (empty($UserID) || empty($TorrentID) || !is_number($UserID)) { 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);
update_tracker('remove_token', array('info_hash' => rawurlencode($InfoHash), 'userid' => $UserID));
}
}
}
if (empty($_GET['showabusers'])) {
show_header('Add tokens sitewide');
?>