PHP Code:
// promote power users
$maxdt = sqlesc(get_date_time(gmtime() - $ap_time));
$res = mysql_query("SELECT id FROM users WHERE class = ".UC_USER." AND uploaded >= $ap_limit AND uploaded / downloaded >= $ap_ratio AND added < $maxdt") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) > 0)
{
$dt = sqlesc(get_date_time());
$msg = sqlesc("Congratulations, you have been auto-promoted to [b]Power User[/b]. :)\n");
while ($arr = mysql_fetch_assoc($res))
{
mysql_query("UPDATE users SET class = ".UC_POWER_USER." WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__);
mysql_query("INSERT INTO messages (sender, receiver, added, msg, poster) VALUES(0, $arr[id], $dt, $msg, 0)") or sqlerr(__FILE__, __LINE__);
}
}
// demote power users
$res = mysql_query("SELECT id FROM users WHERE class = ".UC_POWER_USER." AND uploaded / downloaded < $ad_ratio") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) > 0)
{
$dt = sqlesc(get_date_time());
$msg = sqlesc("You have been auto-demoted from [b]Power User[/b] to [b]User[/b] because your share ratio has dropped below $ad_ratio.\n");
while ($arr = mysql_fetch_assoc($res))
{
mysql_query("UPDATE users SET class = ".UC_USER." WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__);
mysql_query("INSERT INTO messages (sender, receiver, added, msg, poster) VALUES(0, $arr[id], $dt, $msg, 0)") or sqlerr(__FILE__, __LINE__);
}
}