
<?php
include 'core/system.php';

reg();
head('Сражение Питомцев');


$pet=$dbc->query("SELECT * FROM `pet_tour` where `user_id`= '".$user['id']."' ")->fetch_assoc(); 




$stat=$dbc->query("SELECT * FROM `alien` where `id`= 1 ")->fetch_assoc(); 

if($pet['war']==1){ header('location:pet_war.php');exit;}

if($pet){  

$mes=$dbc->query("SELECT * FROM `pet_tour` where `bitv`= '".$pet['bitv']."' ");

$mes= $mes->num_rows; 


if($mes>=4){ $dbc->query("update `pet_tour` set `war` = 1 where `bitv` = '".$pet['bitv']."'");  









$sql =$dbc->query("SELECT * FROM `pet_tour` WHERE `bitv`='".$pet['bitv']."' AND `user_id`!='".$user['id']."'"); 





while($inf=$sql->fetch_assoc()){ 


$dbc->query("INSERT INTO `journal` SET `user_id`='".$inf['user_id']."', `text`='Турнир Питомцев Стартовал. <br><a id=\"link_button\" href=\"pet_war.php\">В Бой</a>',




    `time`='".time()."'");
$dbc->query("UPDATE `users` SET `journal`=`journal`+1 WHERE `id`='".$inf['user_id']."'"); }





$dbc->query("update `alien` set `pet_bitv` = `pet_bitv`+1 "); header('location:view_war.php');exit;}

}


if(isset($_GET['history'])){ 




$sqll =$dbc->query("SELECT * FROM `history_pet` order by `id` desc limit 3"); 







?><center><a href="view_war.php?list"><input class="btn big" type="submit" value="Записаться На Бой"></a></center><?

while($kub=$sqll->fetch_assoc()){ 
?><div class="page-title">Битва #<?=$kub['bitv']?></div><? 
 ?><?=$kub['name']?><?  }


foot(); exit;

























}


?><center><img src="img/new/tur.png" width="100%" height="120" alt="*"></center><?


if(!$pet){ 
?><div class="b-panel-new dblue-panel bordered mt2">
<center><div class="panel-inner-2"><div class="font-small text-italic c-verygray">Сражение Доступно с 25 уровня... за победу вы получаете от 100 до 500 славы</div></div></div></center><?








?><center><a href="view_war.php?list"><input class="btn big" type="submit" value="Записаться На Бой"></a></center><? }else{









?><div class="b-panel-new dblue-panel bordered mt2">
<center><div class="panel-inner-2"><div class="font-small text-italic c-verygray">Собрано <?=$mes?>/4</div></div></div></center><?






  ?><center><a href="view_war.php?"><input class="btn big" type="submit" value="Обновить"></a></center><? }


if(isset($_GET['list'])){ 

if($user['level']<25){ header('location:view_war.php');exit;}





if($pet){ header('location:view_war.php');exit;}




$my = $dbc->query("SELECT * FROM `user_pets` WHERE `id_user` = '".$user['id']."'")->fetch_assoc(); $next = $pet['str'];  

if(!$my){ header('location:view_war.php');exit;}

$stat=$dbc->query("SELECT * FROM `alien` where `id`= 1 ")->fetch_assoc(); 

$nix = $my['vit']*5;


$dbc->query("INSERT INTO `pet_tour` (user_id,pet_id,uron,name,hp,max_hp,sila,prot,kil,test,mag,login,komand,bitv,war,crit) values('".$user['id']."','".$my['id_pets']."',0,'".$my['name']."','".$nix."','".$nix."','".$my['str']."','".$my['def']."',0,0,0, '".$user['login']."','".$stat['pet_komand']."','".$stat['pet_bitv']."',0,'".$my['crit']."')");








if($stat['pet_komand']==1){ 



$dbc->query("update `alien` set `pet_komand`=2 where `id`=1"); }


if($stat['pet_komand']==2){  



$dbc->query("update `alien` set `pet_komand`=1 where `id`=1"); }


header('location:view_war.php');exit;







}



?><center><span class="info">Сокровищница Турнира : <img src="img/money/money.png"><?=$stat['limite']?>/50<span></center><?

?><a class="btn" href="view_war.php?history">История Сражений</a><?
include 'next_pet.php';
foot();
