<?php
### Крон повышения уровня клана каждые 5 минут
include 'core/sys.php';
#$levels = array(5000,15000,25000,35000,55000,75000,95000,105000,125000);
$clans_q = mysql_query("SELECT * FROM `clan`");
	while($clans = mysql_fetch_assoc($clans_q)){
	$level = mysql_fetch_assoc(mysql_query("SELECT * FROM `clan_level` WHERE `oput2`>='".$clans['clan_oput']."' ORDER BY `id` LIMIT 1"));
	if($clans['level'] < $level['id']){
	#echo $clans['id'].'.'.$clans['level'];
	$bonus_level = 500*($clans['level']+1);
	mysql_query("UPDATE `clan` SET 
		`level`=`level`+1,
		`clan_mp`=`clan_mp`+30,
		`clan_max_mp`=`clan_max_mp`+30,
		`kazna`=`kazna`+".$bonus_level."		WHERE `id`='".$clans['id']."'");
	
	mysql_query("INSERT INTO `clan_stena` SET
	`clan_id`='".$clans['id']."',
	`user_id`='".$clans['komandir']."',
	`text`='<b>Новый уровень клана!Награда за достижение нового уровня +<img src=\"img/money/money.png\"> ".$bonus_level." в казну клана.</b>',
	`time`='".time()."'");
	}
		/* Клан уровни */
		/*if($clans['clan_oput']>= 5000 and $clans['level'] < 2){
		mysql_query("UPDATE `clan` SET 
		`level`=2,
		`clan_mp`=`clan_mp`+30,
		`clan_max_mp`=`clan_max_mp`+30	WHERE `id`='".$clans['id']."'");
		}elseif($clans['clan_oput']>= 15000 AND $clans['level']<3){
		mysql_query("UPDATE `clan` SET 
		`level`=3,
		`clan_mp`=`clan_mp`+30,
		`clan_max_mp`=`clan_max_mp`+30	WHERE `id`='".$clans['id']."'");	
		
		}elseif($clans['clan_oput']>= 25000 AND $clans['level'] <4){
		mysql_query("UPDATE `clan` SET 
		`level`=4,
		`clan_mp`=`clan_mp`+30,
		`clan_max_mp`=`clan_max_mp`+30	WHERE `id`='".$clans['id']."'");	
		
		}elseif($clans['clan_oput']>= 35000 AND $clans['level'] <5){
		mysql_query("UPDATE `clan` SET 
		`level`=5,
		`clan_mp`=`clan_mp`+30,
		`clan_max_mp`=`clan_max_mp`+30	WHERE `id`='".$clans['id']."'");	
		
		}elseif($clans['clan_oput']>= 55000 AND $clans['level'] <6){
		mysql_query("UPDATE `clan` SET 
		`level`=6,
		`clan_mp`=`clan_mp`+30,
		`clan_max_mp`=`clan_max_mp`+30	WHERE `id`='".$clans['id']."'");	
		
		}elseif($clans['clan_oput']>= 75000  AND $clans['level'] <7){
		mysql_query("UPDATE `clan` SET 
		`level`=7,
		`clan_mp`=`clan_mp`+30,
		`clan_max_mp`=`clan_max_mp`+30	WHERE `id`='".$clans['id']."'");	
		
		}elseif($clans['clan_oput']>= 95000 AND $clans['level'] <8){
		mysql_query("UPDATE `clan` SET 
		`level`=8,
		`clan_mp`=`clan_mp`+30,
		`clan_max_mp`=`clan_max_mp`+30	WHERE `id`='".$clans['id']."'");	
		
		}elseif($clans['clan_oput']>= 105000 AND $clans['level'] <9){
		mysql_query("UPDATE `clan` SET 
		`level`=9,
		`clan_mp`=`clan_mp`+30,
		`clan_max_mp`=`clan_max_mp`+30	WHERE `id`='".$clans['id']."'");	
		
		}elseif($clans['clan_oput']>= 125000 AND $clans['level'] <10){
		mysql_query("UPDATE `clan` SET 
		`level`=10,
		`clan_mp`=`clan_mp`+30,
		`clan_max_mp`=`clan_max_mp`+30	WHERE `id`='".$clans['id']."'");	
		
		}
		*/
		/* ---- */
		
			#mysql_query("UPDATE `clan` SET `level`='".$level['id']."' WHERE `id`='".$clans['id']."'");
			}
	
	
	mysql_query("UPDATE `clan` SET `clan_mp`=`clan_max_mp`");

?>