<?php
defined('PROTECTOR') OR die('Ошибка: нет доступа');
$clan = mysql_fetch_array(mysql_query("SELECT * FROM `clan` WHERE `lider` = '$udata[clan]'"));
if($clan['exp']>=750000 && $clan['level']=="0"){$new_lvl='yes';}
if($clan['exp']>=2500000 && $clan['level']=="1"){$new_lvl='yes';}
if($clan['exp']>=4000000 && $clan['level']=="2"){$new_lvl='yes';}
if($clan['exp']>=6000000 && $clan['level']=="3"){$new_lvl='yes';}
if($clan['exp']>=10000000 && $clan['level']=="4"){$new_lvl='yes';}
if($clan['exp']>=15000000 && $clan['level']=="5"){$new_lvl='yes';}
if($clan['exp']>=21000000 && $clan['level']=="6"){$new_lvl='yes';}
if($clan['exp']>=28000000 && $clan['level']=="7"){$new_lvl='yes';}
if($clan['exp']>=36000000 && $clan['level']=="8"){$new_lvl='yes';}
if($clan['exp']>=45000000 && $clan['level']=="9"){$new_lvl='yes';}
if($clan['exp']>=100000000 && $clan['level']=="10"){$new_lvl='no';}
//-----
if($new_lvl=='yes'){$calan=$clan['level']+1;
if($clan['level']<=2 AND $clan['level']>=0){$updata['money']=$clan['money']+rand(30000,60000);}
if($clan['level']<=4 AND $clan['level']>2){$updata['money']=$clan['money']+rand(60000,120000);}
if($clan['level']<=6 AND $clan['level']>4){$updata['money']=$clan['money']+rand(120000,240000);}
if($clan['level']<=8 AND $clan['level']>6){$updata['money']=$clan['money']+rand(240000,480000);}
if($clan['level']<=10 AND $clan['level']>8){$updata['money']=$clan['money']+rand(480000,800000);}

if($clan['level']<=2 AND $clan['level']>=0){$updata['almaz']=$clan['almaz']+rand(3000,6000);}
if($clan['level']<=4 AND $clan['level']>2){$updata['almaz']=$clan['almaz']+rand(6000,12000);}
if($clan['level']<=6 AND $clan['level']>4){$updata['almaz']=$clan['almaz']+rand(12000,24000);}
if($clan['level']<=8 AND $clan['level']>6){$updata['almaz']=$clan['almaz']+rand(24000,48000);}
if($clan['level']<=10 AND $clan['level']>8){$updata['almaz']=$clan['almaz']+rand(48000,80000);}


$avtor="Гильдия";
$bon = $updata['money']-$clan['money'];
$bon2 = $updata['almaz']-$clan['almaz'];
$time = date("H:i d.m.y");
$text = "Ваш клан достиг $clan[level] уровня! сумма $bon серебра и $bon2 золота была успешно перечислена в казну!";
 mysql_query("INSERT INTO `msg_r` SET `user_from` = '$avtor', `user_to` = '$clan[lider]', `time` = '$time', `read` = 1, `mail_msg` = '$text'");
 
mysql_query("UPDATE `clan` SET `level` = '$calan', `money` ='$updata[money]', `almaz` ='$updata[almaz]' WHERE `lider` = '$clan[lider]' LIMIT 1");
}
?>