<?
if($_GET["lot"]==1){
require ('../config.php');
include("../auction/setup.php");

$auc = mysql_query("SELECT * FROM still_aukcion WHERE `tim_end` < '".time()."' and status = '0' and idpk != '0'");
while ($au=mysql_fetch_assoc($auc)){
  $proc = ($con_auc["procent"]*$au["stavok"]*$au["money"])/100;
  $money_u = ($au["stavok"]*$au["money"])-$proc;

  mysql_query("UPDATE `tb_users`
  SET  `money` = `money`+'".$money_u."'
  WHERE `id` = '".$au["idpr"]."'");

  $refer = mysql_query("SELECT `username` FROM `tb_users` WHERE `id` = '".$au["idpk"]."'");
  $rf=mysql_fetch_assoc($refer);

  mysql_query("UPDATE `tb_users`
  SET  `referer` = '".$rf["username"]."', `doxod`='0'
  WHERE `id` = '".$au["idu"]."'");

  $user_refer = mysql_query("SELECT `username` FROM `tb_users` WHERE `id` = '".$au["idu"]."'");
  $u_rf=mysql_fetch_assoc($user_refer);

  mysql_query("UPDATE `tb_users`
  SET  `referer2` = '".$rf["username"]."'
  WHERE `referer` = '".$u_rf["username"]."'");

  mysql_query("UPDATE still_aukcion
  SET status = '1'
  WHERE id='".$au["id"]."'");

}

mysql_query("DELETE FROM still_aukcion WHERE `tim_end` < '".time()."' and idpk = '0'");
}
?>