"TorrentialStorm, post: 39989": $gigs = 25*1073741824; // 25 GB
$res = mysql_query("SELECT id FROM users WHERE class = 1 AND uploaded >= $gigs AND uploaded >= downloaded");
$time = get_date_time();
while ($arr = mysql_fetch_assoc($res)) {
mysql_query("UPDATE users SET class = 2 WHERE id = $arr[id]");
mysql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, $arr[id], '$time', 'You have been automatically promoted from User to Power User, If your ratio drops below 1.00 you will be demoted.', 'You have been promoted to: Power User')");
}
$res = mysql_query("SELECT id FROM users WHERE class = 2 AND uploaded >= $gigs AND uploaded < downloaded");
while ($arr = mysql_fetch_assoc($res)) {
mysql_query("UPDATE users SET class = 1 WHERE id = $arr[id]");
mysql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, $arr[id], '$time', 'You have been automatically demoted from Power User to User.', 'You have been demoted to User')");
}
I try with 250GB, promote works fine, but demote dont work ;) . Any help?
Are you sure that this code counting upload gigs, because its feels like it count only ratio?
// promote to power users
$gigs = 250*1073741824; // 250 GB
$res = mysql_query("SELECT id FROM users WHERE class = 1 AND uploaded >= $gigs AND uploaded >= downloaded");
$time = get_date_time();
while ($arr = mysql_fetch_assoc($res)) {
mysql_query("UPDATE users SET class = 2 WHERE id = $arr[id]");
mysql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, $arr[id], '$time', 'You have been automatically promoted from User to Power User. If your ratio drops below 1.00 you will be demoted.', 'You have been promoted to: Power User')");
}
$res = mysql_query("SELECT id FROM users WHERE class = 2 AND uploaded >= $gigs AND uploaded < downloaded");
while ($arr = mysql_fetch_assoc($res)) {
mysql_query("UPDATE users SET class = 1 WHERE id = $arr[id]");
mysql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, $arr[id], '$time', 'You have been automatically demoted from Power User to User.', 'You have been demoted to User')");
}
mu cleanup.php:
<?php
function do_cleanup() {
global $site_config;
//LOCAL TORRENTS - GET PEERS DATA AND UPDATE BROWSE STATS
$torrents = array();
$res = mysql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder");
while ($row = mysql_fetch_assoc($res)) {
if ($row["seeder"] == "yes")
$key = "seeders";
else
$key = "leechers";
$torrents[$row["torrent"]][$key] = $row["c"];
}
$fields = explode(":", "comments:leechers:seeders");
$res = mysql_query("SELECT id, seeders, leechers FROM torrents WHERE external !='yes'");
while ($row = mysql_fetch_assoc($res)) {
$id = $row["id"];
$torr = $torrents[$id];
foreach ($fields as $field) {
if (!isset($torr[$field]))
$torr[$field] = 0;
}
$update = array();
foreach ($fields as $field) {
if ($torr[$field] != $row[$field])
$update[] = "$field = " . $torr[$field];
}
if (count($update))
mysql_query("UPDATE torrents SET " . implode(",", $update) . " WHERE id = $id AND external !='yes'");
}
//LOCAL TORRENTS - MAKE NON-ACTIVE/OLD TORRENTS INVISIBLE
$deadtime = gmtime() - $site_config["max_dead_torrent_time"];
mysql_query("UPDATE torrents SET visible='no' WHERE visible='yes' AND last_action < FROM_UNIXTIME($deadtime) AND external !='yes'");
////////Update Seederbonus/////////
$res = mysql_query("SELECT DISTINCT userid FROM peers WHERE seeder = 'yes'") or die (mysql_error());
if (mysql_num_rows($res) > 0)
{
while ($arr = mysql_fetch_assoc($res))
{
mysql_query("UPDATE users SET seedbonus = seedbonus+0.5 WHERE id = $arr[userid]") or die (mysql_error());
}
}
/////////////////////////////////////////
//DELETE OLD NON-ACTIVE PEERS
$res = mysql_query("DELETE FROM peers WHERE ".gmtime()."-UNIX_TIMESTAMP(last_action) >= 2400");
//DELETE PENDING USER ACCOUNTS OVER TIMOUT AGE
$deadtime = gmtime() - $site_config["signup_timeout"];
mysql_query("DELETE FROM users WHERE status = 'pending' AND added < FROM_UNIXTIME($deadtime)");
// promote to power users
$gigs = 250*1073741824; // 250 GB
$res = mysql_query("SELECT id FROM users WHERE class = 1 AND uploaded >= $gigs AND uploaded >= downloaded");
$time = get_date_time();
while ($arr = mysql_fetch_assoc($res)) {
mysql_query("UPDATE users SET class = 2 WHERE id = $arr[id]");
mysql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, $arr[id], '$time', 'You have been automatically promoted from User to Power User. If your ratio drops below 1.00 you will be demoted.', 'You have been promoted to: Power User')");
}
$res = mysql_query("SELECT id FROM users WHERE class = 2 AND uploaded >= $gigs AND uploaded < downloaded");
while ($arr = mysql_fetch_assoc($res)) {
mysql_query("UPDATE users SET class = 1 WHERE id = $arr[id]");
mysql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, $arr[id], '$time', 'You have been automatically demoted from Power User to User.', 'You have been demoted to User')");
}
//LEECHWARN USERS WITH LOW RATIO
if ($site_config["ratiowarn_enable"]){
$minratio = $site_config["ratiowarn_minratio"];
$downloaded = $site_config["ratiowarn_mingigs"]*1024*1024*1024;
$length = $site_config["ratiowarn_daystowarn"];
//ADD WARNING
$res = mysql_query("SELECT id,username FROM users WHERE class = 1 AND warned = 'no' AND enabled='yes' AND uploaded / downloaded < $minratio AND downloaded >= $downloaded");
if (mysql_num_rows($res) > 0){
$timenow = get_date_time();
$reason = "You have been warned because of having low ratio. You need to get a ".$minratio." before next ".$length." days or your account may be banned.";
$expiretime = gmdate("Y-m-d H:i:s", gmtime() + (86400 * $length));
while ($arr = mysql_fetch_assoc($res)){
mysql_query("INSERT INTO warnings (userid, reason, added, expiry, warnedby, type) VALUES ('".$arr["id"]."','".$reason."','".$timenow."','".$expiretime."','0','Poor Ratio')");
mysql_query("UPDATE users SET warned='yes' WHERE id='".$arr["id"]."'");
mysql_query("INSERT INTO messages (sender, receiver, added, msg, poster) VALUES ('0', '".$arr["id"]."', '".$timenow."', '".$reason."', '0')");
write_log("Auto Leech warning has been <B>added</B> for: <a href=account-details.php?id=".$arr["id"].">".$arr["username"]."</a>");
}
}
//REMOVE WARNING
$res1 = mysql_query("SELECT id,username FROM users WHERE warned = 'yes' AND enabled='yes' AND uploaded / downloaded >= $minratio AND downloaded >= $downloaded");
if (mysql_num_rows($res1) > 0){
$timenow = get_date_time();
$reason = "Your warning of low ratio has been removed. We highly recommend you to keep a your ratio up to not be warned again.\n";
while ($arr1 = mysql_fetch_assoc($res1)){
write_log("Auto Leech warning has been removed for: <a href=account-details.php?id=".$arr1["id"].">".$arr1["username"]."</a>");
mysql_query("UPDATE users SET warned = 'no' WHERE id = '".$arr1["id"]."'");
mysql_query("UPDATE warnings SET expiry = '".$timenow."' WHERE userid = '".$arr1["id"]."'");
mysql_query("INSERT INTO messages (sender, receiver, added, msg, poster) VALUES ('0', '".$arr1["id"]."', '".$timenow."', '".$reason."', '0')");
}
}
//BAN WARNED USERS
$res = mysql_query("SELECT id,username FROM users WHERE class = 1 AND enabled='yes' AND warned = 'yes' AND uploaded / downloaded < $minratio AND downloaded >= $downloaded");
if (mysql_num_rows($res) > 0){
$timenow = get_date_time();
$expires = (86400 * $length);
while ($arr = mysql_fetch_assoc($res)){
$r = mysql_query("SELECT id, UNIX_TIMESTAMP(expiry) as expiry FROM warnings WHERE userid=$arr[id]");
$row = mysql_fetch_assoc($r);
if (gmtime() - $row["expiry"] >= 0) {
mysql_query("UPDATE users SET enabled='no', warned='no' WHERE id='".$arr["id"]."'");
write_log("User <a href=account-details.php?id=".$arr["id"].">".$arr["username"]."</a> has been banned (Auto Leech warning).");
}
}
}
}//check if warning system is on
//END//
//OPTIMISE TABLES
mysql_query("OPTIMIZE TABLE `peers` , `torrents` , `tasks` , `guests` , `users` , `messages` , `comments` , `addedrequests` , `bookmarks` , `blackjack`; ");
}//end func
// START LOTTERY
dbconn();
$res = mysql_query("SELECT * FROM lottery_config") or sqlerr(__FILE__, __LINE__);
while ($arr = mysql_fetch_assoc($res))
$arr_config[$arr['name']] = $arr['value'];
if ($arr_config['enable'] == 1)
{
if (get_date_time() > $arr_config['end_date'])
{
if ($arr_config["ticket_amount_type"] == GB)
$arr_config['ticket_amount'] = 1024 * 1024 * 1024 * $arr_config['ticket_amount'];
else if ($arr_config["ticket_amount_type"] == MB)
$arr_config['ticket_amount'] = 1024 * 1024 * $arr_config['ticket_amount'];
$size = $arr_config['ticket_amount'];
if ($arr_config["ticket_amount_type"] == GB)
$arr_config['prize_fund'] = 1024 * 1024 * 1024 * $arr_config['prize_fund'];
else if ($arr_config["ticket_amount_type"] == MB)
$arr_config['prize_fund'] = 1024 * 1024 * $arr_config['prize_fund'];
$prize_fund = $arr_config['prize_fund'];
$total = mysql_num_rows(mysql_query("SELECT * FROM tickets"));
if ($arr_config["use_prize_fund"])
{
$pot = $prize_fund / $arr_config['total_winners'];
$res = mysql_query("SELECT user FROM tickets ORDER BY RAND() LIMIT $arr_config[total_winners]") or sqlerr();
$who_won = array();
$msg = sqlesc("Congratulations, You have won: <b>".mksize($pot)."</b>.<br /><br />This has been added to your upload amount<br /><br />Thanks for playing Lottery.");
while ($arr = mysql_fetch_assoc($res))
{
$res2 = mysql_query("SELECT modcomment FROM users WHERE id = $arr[user]") or sqlerr(__FILE__, __LINE__);
$arr2 = mysql_fetch_assoc($res2);
$modcomment = $arr2['modcomment'];
$modcom = sqlesc("User won the lottery: " . mksize($pot) . " at " . get_date_time() . "\n" . $modcomment);
mysql_query("UPDATE users SET uploaded = uploaded + $pot, modcomment = $modcom WHERE id = $arr[user]") or sqlerr();
mysql_query("INSERT INTO messages (sender, receiver, added, msg, poster) VALUES(0, $arr[user], NOW(), $msg, 0)") or sqlerr(__FILE__, __LINE__);
$who_won[] = $arr['user'];
}
}
else
{
$pot = $total * $size / $arr_config['total_winners'];
$res = mysql_query("SELECT user FROM tickets ORDER BY RAND() LIMIT $arr_config[total_winners]") or sqlerr();
$who_won = array();
$msg = sqlesc("Congratulations, You have won: ".mksize($pot).".\n\nThis has been added to your upload amount.\n\nThanks for playing Lottery.");
while ($arr = mysql_fetch_assoc($res))
{
$res2 = mysql_query("SELECT modcomment FROM users WHERE id = $arr[user]") or sqlerr(__FILE__, __LINE__);
$arr2 = mysql_fetch_assoc($res2);
$modcomment = $arr2['modcomment'];
$modcom = sqlesc("User won the lottery: " . mksize($pot) . " at " . get_date_time() . "\n" . $modcomment);
mysql_query("UPDATE users SET uploaded = uploaded + $pot WHERE id = $arr[user]") or sqlerr();
mysql_query("INSERT INTO messages (sender, receiver, added, msg, poster) VALUES(0, $arr[user], NOW(), $msg, 0)") or sqlerr(__FILE__, __LINE__);
$who_won[] = $arr['user'];
}
}
$who_won = implode("|", $who_won);
$who_won_date = get_date_time();
$who_won_prize = $pot;
mysql_query("TRUNCATE TABLE tickets") or sqlerr(__FILE__, __LINE__);
if ($who_won != '')
{
mysql_query("UPDATE lottery_config SET value = '$who_won' WHERE name = 'lottery_winners'") or sqlerr(__FILE__, __LINE__);
mysql_query("UPDATE lottery_config SET value = '$who_won_prize' WHERE name = 'lottery_winners_amount'") or sqlerr(__FILE__, __LINE__);
mysql_query("UPDATE lottery_config SET value = '$who_won_date' WHERE name = 'lottery_winners_time'") or sqlerr(__FILE__, __LINE__);
}
mysql_query("UPDATE lottery_config SET value = '0' WHERE name = 'enable'") or sqlerr(__FILE__, __LINE__);
}
}
// END LOTTERY
//UPDATE CASINO TRYS
$deadtimec = gmtime() - 18000;
mysql_query("UPDATE casino SET trys='0' WHERE date < FROM_UNIXTIME($deadtimec)");
?>