Bravo List
Register
Go Back   > Bravo List > Source Code > Archived Trackers > Torrent Strike
Reply
  #1  
Old 28th September 2010, 10:53
kolo kolo is offline
Member
 
Join Date: Jul 2009
P2P
Posts: 2
Default Help SQL Error
SQL Error

HTML Code:
<?

require_once("bittorrent.php");

function docleanup($full_cleanup=false) {
    global $torrent_dir, $signup_timeout, $max_dead_torrent_time, $autoclean_interval, $max_dead_user_time, $max_dead_topic_time, $ad_ratio, $ap_time, $ap_limit, $ap_ratio, $torrent_ttl, $minratio, $warndown;
    
    // include needed to purge also phpbb accounts (not done by autocleanup)
    if ($full_cleanup==true)
    {
        global $share_phpbb2_users_with_TBDev,$activate_phpbb2_forum,$phpbb2_folder,$db;
        if(($share_phpbb2_users_with_TBDev==true)&&($activate_phpbb2_forum==true))
        {
                require_once("include/phpbb2Bridge.php");
        }
    }

    set_time_limit(0);
    ignore_user_abort(1);

    do {
        $res = mysql_query("SELECT id FROM torrents");
        $ar = array();
        while ($row = mysql_fetch_array($res)) {
            $id = $row[0];
            $ar[$id] = 1;
        }

        if (!count($ar))
            break;

        $dp = @opendir($torrent_dir);
        if (!$dp)
            break;

        $ar2 = array();
        while (($file = readdir($dp)) !== false) {
            if (!preg_match('/^(\d+)\.torrent$/', $file, $m))
                continue;
            $id = $m[1];
            $ar2[$id] = 1;
            if (isset($ar[$id]) && $ar[$id])
                continue;
            $ff = $torrent_dir . "/$file";
            unlink($ff);
        }
        closedir($dp);

        if (!count($ar2))
            break;

        $delids = array();
        foreach (array_keys($ar) as $k) {
            if (isset($ar2[$k]) && $ar2[$k])
                continue;
            $delids[] = $k;
            unset($ar[$k]);
        }
        if (count($delids))
            mysql_query("DELETE FROM torrents WHERE id IN (" . join(",", $delids) . ")");

        $res = mysql_query("SELECT torrent FROM peers GROUP BY torrent");
        $delids = array();
        while ($row = mysql_fetch_array($res)) {
            $id = $row[0];
            if (isset($ar[$id]) && $ar[$id])
                continue;
            $delids[] = $id;
        }
        if (count($delids))
            mysql_query("DELETE FROM peers WHERE torrent IN (" . join(",", $delids) . ")");

        $res = mysql_query("SELECT torrent FROM files GROUP BY torrent");
        $delids = array();
        while ($row = mysql_fetch_array($res)) {
            $id = $row[0];
            if ($ar[$id])
                continue;
            $delids[] = $id;
        }
        if (count($delids))
            mysql_query("DELETE FROM files WHERE torrent IN (" . join(",", $delids) . ")");
    } while (0);
///started torrents//set at 6 unfinished torrents
// issues a warning
$res = mysql_query("SELECT COUNT(userid) AS started,users.id,users.username,users.modcomment,users.startedmsg FROM users LEFT JOIN snatched on snatched.userid=users.id LEFT JOIN torrents ON torrents.id = snatched.torrent WHERE torrents.owner != users.id AND snatched.finished = 'no' AND users.enabled = 'yes' AND users.startedmsg = 'no' GROUP BY `userid` ORDER BY started");
while ($row = mysql_fetch_assoc($res)) {
$msg = sqlesc("This is a automatic message from the System because you have $row[started] started torrents\n Please be advised you will be automatically warned The next time you don't complete a torrent you have started !\n You may contact a mod to discuss the situation !");
$modcomment = htmlspecialchars($row["modcomment"]);
$modcomment = "$dt -Automatic started torrent Warning-By System-Warning has been sent $row[started] started torrent\n". $modcomment;
$modcom = sqlesc($modcomment);
if($row['started'] > 6){///set point here
mysql_query("UPDATE users SET startedmsg='yes', modcomment = $modcom WHERE id=$row[id]") or sqlerr(__FILE__, __LINE__);
mysql_query("INSERT INTO messages (sender, receiver, added, msg, poster) VALUES(0, $row[id], $dt, $msg, 0)") or sqlerr(__FILE__, __LINE__);
write_log("User account <a href=$DEFAULTBASEURL/userdetails.php?id=$row[id] >$row[id] </a> ($row[username]) Has Been Sent A started torrent Warning by System- $row[started] torrents");
}
}
//zappes their downloads// this has to be set 2 above the other
///set for 8 unfinished torrents
$res = mysql_query("SELECT COUNT(userid) AS started,users.id,users.username,users.modcomment,users.startedmsg FROM users LEFT JOIN snatched on snatched.userid=users.id LEFT JOIN torrents ON torrents.id = snatched.torrent WHERE torrents.owner != users.id AND snatched.finished = 'no' AND users.enabled = 'yes' AND users.startedmsg = 'yes' GROUP BY `userid` ORDER BY started");
while ($row = mysql_fetch_assoc($res)) {
$modcomment = htmlspecialchars($row["modcomment"]);
$modcomment = "$dt -Automatic started torrent Warning-By System-Warning issued downloads disabled \n". $modcomment;
$modcom = sqlesc($modcomment);
$msg = sqlesc("This is a automatic warning message from the System because you have $row[started] started torrents\n Your downloads have been removed and you have been warned \nYou may contact a mod to discuss the situation !");
if($row['started'] >= 8){///set point here
mysql_query("UPDATE users SET startedmsg='done',downloadpos = 'no',warned = 'yes',modcomment = $modcom WHERE id=$row[id]") or sqlerr(__FILE__, __LINE__);
mysql_query("INSERT INTO messages (sender, receiver, added, msg, poster) VALUES(0, $row[id], $dt, $msg, 0)") or sqlerr(__FILE__, __LINE__);
write_log("User account <a href=$DEFAULTBASEURL/userdetails.php?id=$row[id] >$row[id] </a> ($row[username]) Has Been warned and downloads are disabled for starting too many torrents by System- $row[started] started torrents");
}
}
// START LOTTERY - THADON
$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, subject, msg, poster) VALUES(0, $arr[user], NOW(), 'You have won the Lottery', $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: <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 WHERE id = $arr[user]") or sqlerr();
mysql_query("INSERT INTO messages (sender, receiver, added, subject, msg, poster) VALUES(0, $arr[user], NOW(), 'You have won the Lottery', $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 - THADON
/////////Update Seederbonus/////////
   $res = mysql_query("SELECT DISTINCT userid FROM peers WHERE seeder = 'yes'") or sqlerr(__FILE__, __LINE__);
   if (mysql_num_rows($res) > 0)
   {
       while ($arr = mysql_fetch_assoc($res))
       {
       mysql_query("UPDATE users SET seedbonus = seedbonus+0.125 WHERE id = $arr[userid]") or sqlerr(__FILE__, __LINE__);
       }
   }
/////////Update Money/////////
   $res = mysql_query("SELECT DISTINCT userid FROM peers WHERE seeder = 'yes'") or sqlerr(__FILE__, __LINE__);
   if (mysql_num_rows($res) > 0)
   {
       while ($arr = mysql_fetch_assoc($res))
       {
       mysql_query("UPDATE users SET money = money+1.0 WHERE id = $arr[userid]") or sqlerr(__FILE__, __LINE__);
       }
   }
    $deadtime = deadtime();
    mysql_query("DELETE FROM peers WHERE last_action < FROM_UNIXTIME($deadtime)");

    $deadtime -= $max_dead_torrent_time;
    mysql_query("UPDATE torrents SET visible='no' WHERE visible='yes' AND last_action < FROM_UNIXTIME($deadtime)");

      $deadtime = deadtime();
      mysql_query("UPDATE snatched SET seeder='no' WHERE seeder='yes' AND last_action < FROM_UNIXTIME($deadtime)");

    
    // ---- delete unconfirmed invites -----
    
    $deadtime = time() - $signup_timeout;
    $user = mysql_query("SELECT invited_by FROM users WHERE status = 'pending' AND added < FROM_UNIXTIME($deadtime) AND last_access = '0000-00-00 00:00:00'");
    $arr = mysql_fetch_assoc($user);
    if (mysql_num_rows($user) > 0)
    {
        $invites = mysql_query("SELECT invites FROM users WHERE id = $arr[invited_by]");
        $arr2 = mysql_fetch_assoc($invites);
        if ($arr2[invites] < 10)
        {
            $invites = $arr2[invites] +1;
            mysql_query("UPDATE users SET invites='$invites' WHERE id = $arr[invited_by]");
        }
        if ($arr2)
            mysql_query("DELETE FROM users WHERE status = 'pending' AND added < FROM_UNIXTIME($deadtime) AND last_login < FROM_UNIXTIME($deadtime) AND last_access < FROM_UNIXTIME($deadtime) AND last_access = '0000-00-00 00:00:00'");
    }
    //delete old login attempts
           $secs = 1*86400; // Delete failed login attempts per one day.
           $dt = sqlesc(get_date_time(gmtime() - $secs)); // calculate date.
       mysql_query("DELETE FROM loginattempts WHERE banned='no' AND added < $dt"); // do job.
    // ---- delete unconfirmed user accounts including phpbb accounts (not done by autocleanup, use manual Cleanup from the control panel to call this)
    if ($full_cleanup==true)
    {
        $deadtime = time() - $signup_timeout;
        $res = mysql_query("SELECT id,username FROM users WHERE status = 'pending' AND added < FROM_UNIXTIME($deadtime) AND last_login < FROM_UNIXTIME($deadtime) AND last_access < FROM_UNIXTIME($deadtime)");
      while ($row = mysql_fetch_assoc($res))
      {
          mysql_query("DELETE FROM users WHERE id=".$row["id"]);
          delete_phpBB2user($row["username"],"nopasswordcheck",false);
      }
    }


    $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"];
    }

    $res = mysql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent");
    while ($row = mysql_fetch_assoc($res)) {
        $torrents[$row["torrent"]]["comments"] = $row["c"];
    }

    $fields = explode(":", "comments:leechers:seeders");
    $res = mysql_query("SELECT id, seeders, leechers, comments FROM torrents");
    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");
    }

    // ---- delete inactive user accounts including phpbb accounts (not done by autocleanup, use manual Cleanup from the control panel to call this)
    if ($full_cleanup==true)
    {
        $dt = sqlesc(get_date_time(gmtime() - $max_dead_user_time));
        $maxclass = UC_POWER_USER;
        $res = mysql_query("SELECT id,username FROM users WHERE parked='no' AND status = 'confirmed' AND class <= $maxclass AND last_access < $dt");
      while ($row = mysql_fetch_assoc($res))
      {
          mysql_query("DELETE FROM users WHERE id=".$row["id"]);
          delete_phpBB2user($row["username"],"nopasswordcheck",false);
      }
    }
      //delete parked user accounts
       $secs = 175*86400; // change the time to fit your needs
       $dt = sqlesc(get_date_time(gmtime() - $secs));
       $maxclass = UC_POWER_USER;
       mysql_query("DELETE FROM users WHERE parked='yes' AND status='confirmed' AND class <= $maxclass AND last_access < $dt");

    // lock topics where last post was made more than x days ago
    /*$res = mysql_query("SELECT topics.id FROM topics LEFT JOIN posts ON topics.lastpost = posts.id AND topics.sticky = 'no' WHERE " . gmtime() . " - UNIX_TIMESTAMP(posts.added) >     $secs = $max_dead_topic_time") or sqlerr(__FILE__, __LINE__);
    while ($arr = mysql_fetch_assoc($res))
        mysql_query("UPDATE topics SET locked='yes' WHERE id=$arr[id]") or sqlerr(__FILE__, __LINE__);*/

  //remove expired warnings
  $res = mysql_query("SELECT id FROM users WHERE warned='yes' AND warneduntil < NOW() AND warneduntil <> '0000-00-00 00:00:00'") or sqlerr(__FILE__, __LINE__);
  if (mysql_num_rows($res) > 0)
  {
    $dt = sqlesc(get_date_time());
    $msg = sqlesc("Your warning has been removed. Please keep in your best behaviour from now on.\n");
    while ($arr = mysql_fetch_assoc($res))
    {
      mysql_query("UPDATE users SET warned = 'no', warneduntil = '0000-00-00 00:00:00' 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__);
    }
  }

    // promote JUNUOR
    $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("ขอแสดงความยินดีด้วยคุณสอบได้และได้เลื่อนชั้นเป็น [b]ประถมYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND uploaded / downloaded >= AND added < '2010-09-28 19:12:54'' at line 1in /var/www/virtual/xxxxxx.com/htdocs/include/cleanup.php, line 341


MY cleanup.php
. :)\n");
        while ($arr = mysql_fetch_assoc($res))
        {
            mysql_query("UPDATE users SET class = ".UC_JUNUOR." 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 JUNUOR
    $res = mysql_query("SELECT id FROM users WHERE class = ".UC_JUNUOR." AND uploaded / downloaded < $ad_ratio") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0)
    {
        $dt = sqlesc(get_date_time());
        $msg = sqlesc("เสียใจด้วยเธอสอบตกจาก [b]ประถม[/b] มาอยู่ [b]อนุบาล[/b]เพราะว่าคะแนนเฉลี่ยของเธอน้อยเหลือเกิน $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__);
        }
    }
    // promote power users
    $maxdt1 = sqlesc(get_date_time(gmtime() - $ap_time1));
    $res = mysql_query("SELECT id FROM users WHERE class = ".UC_JUNUOR." AND uploaded >= $ap_limit1 AND uploaded / downloaded >= $ap_ratio1 AND added < $maxdt1") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0)
    {
        $dt = sqlesc(get_date_time());
        $msg = sqlesc("ขอแสดงความยินดีด้วยคุณสอบได้และได้เลื่อนชั้นเป็น [b]มัธยมต้น[/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_ratio1") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0)
    {
        $dt = sqlesc(get_date_time());
        $msg = sqlesc("เสียใจด้วยเธอสอบตกจาก [b]มัธยมต้น[/b] มาอย [b]ประถม[/b] เพราะว่าคะแนนเฉลี่ยของเธอน้อยเหลือเกิน $ad_ratio1.\n");
        while ($arr = mysql_fetch_assoc($res))
        {
            mysql_query("UPDATE users SET class = ".UC_JUNUOR." 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__);
        }
    }
     // promote UC_SUPER_USER
    $maxdt2 = sqlesc(get_date_time(gmtime() - $ap_time1));
    $res = mysql_query("SELECT id FROM users WHERE class = ".UC_POWER_USER." AND uploaded >= $ap_limit2 AND uploaded / downloaded >= $ap_ratio2 AND added < $maxdt2") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0)
    {
        $dt = sqlesc(get_date_time());
        $msg = sqlesc("ขอแสดงความยินดีด้วยคุณสอบได้และได้เลื่อนชั้นเป็น [b]มัธยมปลาย[/b]. :)\n");
        while ($arr = mysql_fetch_assoc($res))
        {
            mysql_query("UPDATE users SET class = ".UC_SUPER_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 UC_SUPER_USER
    $res = mysql_query("SELECT id FROM users WHERE class = ".UC_SUPER_USER." AND uploaded / downloaded < $ad_ratio2") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0)
    {
        $dt = sqlesc(get_date_time());
        $msg = sqlesc("เสียใจด้วยเธอสอบตกจาก [b]มัธยมปลาย[/b] มาอย [b]มัธยมต้น[/b] เพราะว่าคะแนนเฉลี่ยของเธอน้อยเหลือเกิน $ad_ratio2.\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__);
        }
    }
    // Update stats
    $seeders = get_row_count("peers", "WHERE seeder='yes'");
    $leechers = get_row_count("peers", "WHERE seeder='no'");
    mysql_query("UPDATE avps SET value_u=$seeders WHERE arg='seeders'") or sqlerr(__FILE__, __LINE__);
    mysql_query("UPDATE avps SET value_u=$leechers WHERE arg='leechers'") or sqlerr(__FILE__, __LINE__);

    // update forum post/topic count
    $forums = mysql_query("select id from forums");
    while ($forum = mysql_fetch_assoc($forums))
    {
        $postcount = 0;
        $topiccount = 0;
        $topics = mysql_query("select id from topics where forumid=$forum[id]");
        while ($topic = mysql_fetch_assoc($topics))
        {
            $res = mysql_query("select count(*) from posts where topicid=$topic[id]");
            $arr = mysql_fetch_row($res);
            $postcount += $arr[0];
            ++$topiccount;
        }
        mysql_query("update forums set postcount=$postcount, topiccount=$topiccount where id=$forum[id]");
    }
    
    // delete old torrents
    $dt = sqlesc(get_date_time(gmtime() - $torrent_ttl));
    $res = mysql_query("SELECT id, name FROM torrents WHERE added < $dt AND seeders=0 AND leechers=0 ");
    while ($arr = mysql_fetch_assoc($res))
    {
        @unlink("$torrent_dir/$arr[id].torrent");
        mysql_query("DELETE FROM torrents WHERE id=$arr[id]");
        mysql_query("DELETE FROM peers WHERE torrent=$arr[id]");
        mysql_query("DELETE FROM comments WHERE torrent=$arr[id]");
        mysql_query("DELETE FROM files WHERE torrent=$arr[id]");
            mysql_query("DELETE FROM snatched WHERE torrentid =$arr[id]");
        write_log("Torrent $arr[id] ($arr[name]) was deleted by system (older than $days days)");
    }

    
    // --- Manage invits
    
    autoinvites(10,1,4,.90,1);
    autoinvites(10,4,7,.95,2);
    autoinvites(10,7,10,1.00,3);
    autoinvites(10,10,100000,1.05,4);
    
}

// $lenght:   (in days) number of days to wait before giving new invits
// $minlimit: (in GigaBytes) minimum of downloaded GigaBytes to receive the new invits
// $maxlimit: (in GigaBytes) maximum of downloaded GigaBytes to receive the new invits
// $minratio: Minimal ratio needed to receive the new invits
// $invites:  Number of invite to give

function autoinvites($length, $minlimit, $maxlimit, $minratio, $invites)
{
    $time = sqlesc(get_date_time(gmtime() - (($length)*86400)));
    $minlimit = $minlimit*1024*1024*1024;
    $maxlimit = $maxlimit*1024*1024*1024;
    $res = mysql_query("SELECT id, invites FROM users WHERE class > 0 AND enabled = 'yes' AND downloaded >= $minlimit AND downloaded < $maxlimit AND uploaded / downloaded >= $minratio AND warned = 'no' AND invites < 10 AND invitedate < $time") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0)
    {
        while ($arr = mysql_fetch_assoc($res))
        {
            if ($arr[invites] == 9)
            $invites = 1;
            elseif ($arr[invites] == 8 && $invites == 3)
            $invites = 2;
            mysql_query("UPDATE users SET invites = invites+$invites, invitedate = NOW() WHERE id=$arr[id]") or sqlerr(__FILE__, __LINE__);
        }
    }
}
// Auto warn on low ratio
//Warn
if (($minratio)&&($warndown)){
$modcomment = gmdate("Y-m-d") . " - Ratio-warned by AutoSystem.\n". $modcomment;
mysql_query("UPDATE users SET warned = 'yes', ratiowarn = 'yes', warneduntil = '0000-00-00 00:00:00', modcomment = $modcom WHERE enabled = 'yes' AND uploaded / downloaded < $minratio AND downloaded > $warndown");

//Unwarn
$modcomment = gmdate("Y-m-d") . " - Ratio-warn removed by AutoSystem.\n". $modcomment;
mysql_query("UPDATE users SET warned = 'no', ratiowarn = 'no', warneduntil = '0000-00-00 00:00:00', modcomment = $modcom WHERE ratiowarn = 'yes' AND enabled = 'yes' AND uploaded / downloaded > $minratio AND downloaded > $warndown");
}
// End
?>
Reply With Quote
  #2  
Old 28th September 2010, 11:40
Timisoreanul's Avatar
Timisoreanul Timisoreanul is offline
Senior Member
 
Join Date: Apr 2008
P2P
Posts: 211
Default
More info please:

tell use what steps you do?
which file you posted?
__________________
only me
Reply With Quote
  #3  
Old 28th September 2010, 11:48
kolo kolo is offline
Member
 
Join Date: Jul 2009
P2P
Posts: 2
Default
Quote:
Originally Posted by Timisoreanul View Post
More info please:

tell use what steps you do?
which file you posted?
Sorry I have not read
Reply With Quote
  #4  
Old 7th October 2010, 14:34
Tony's Avatar
Tony Tony is offline
Senior Member
 
Join Date: Mar 2008
P2P
Posts: 182
Default
whats the sql error as that would help alot lol
Reply With Quote
Reply

Tags
error , sql

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT +2. The time now is 20:25. vBulletin skin by ForumMonkeys. Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.