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

head('Рюкзак');
reg();
  if (isset($_SESSION['bag'])){?><div style="clear:both;"></div><div class="b-notice trsmgr"><div class="notify-inner"><?=$_SESSION[bag]?></div></div><?   $_SESSION['bag']=NULL; }

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

if($dop['tal_cuz']>0){ $sera_dop = 5*$dop['tal_cuz']; $exp_dop = 1*$dop['tal_cuz']; }else{ $sera_dop=0; $exp_dop=0; }

?><div class="b_tabs font-small mt10">

<div class="b_tabs">
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tbody style="vertical-align: bottom;">  
    <tr>
<td>
<a href="/bag" class="tab first">
Рюкзак

</a>
</td><td>
<span class="tab last active">
Вещи для Питомца

</span>
</td>
</tr></tbody>
</table>
</div>

</div>
<?

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

  $razbor=$dbc->query("SELECT * FROM `razbor`where `level`= '".$dop['razbor_lvl']."' ")->fetch_assoc();

$sql = $dbc->query("SELECT * FROM `art_pet` WHERE `user_id`='".$user['id']."' AND `status` = 1  ");


$total = $dbc->query("SELECT `id` FROM `art_pet` where `user_id` ='".$user['id']."' AND `status` = 1 "); $total =$total->num_rows;


if($total==0){
echo '<div class="main"><div class="block_zero center">Нет вещей для питомца</div></div>';

foot();
exit;
}
if(isset($_GET['sell'])){

    $get = int($_SESSION['idss']);



$pot =$dbc->query("SELECT * FROM `art_pet` WHERE `id`='".$get."' AND `user_id`='".$user['id']."' LIMIT 1")->fetch_assoc();

?><div class="b-panel-new dblue-panel bordered mt2"><div class="panel-inner-2"><div class="font-small text-italic c-verygray">Вы уверены что хотите разобрать:</div></div></div><?




?><div class="sblue-panel"><div class="panel-inner-3"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="37" style="vertical-align: top;"><img width="32"height="32" src="img/item_pet/<?=$pot['img']?>.png" alt="."border="0"></td><td><div><a href="/info_it.php?ids=<?=$pot['id']?>" class="<?=$pot['lite']?>"><center><?=$pot['nik']?></a></center></div><span class="nowrap"></span> <span class="nowrap"></span><span class="clearer"></span></td><td width="60"><a href="/bag_pet.php?go=<?=$pot['id']?><??>&amp;razbor" class="gr-btn center"><span>Разобрать</span></a></td>  <td width="60"><a href="/bag_pet.php" class="gr-btn center"><span>Отменить</span></td></tr></table></div></div><?







foot();

exit();


}
if(isset($_GET['alls'])){


$totalll = $dbc->query("SELECT (id) FROM `art_pet` where `user_id` =  '".$user['id']."' and `status` = 1 and `lite` = 'iEpic'");

$totals= $totalll->num_rows; 

if($totals<=0){ header("Location: bag_pet.php?");exit;}

$sera=500; $exp=10;

$sera=$sera+$sera_dop; $exp=$exp+$exp_dop; 

$sera = $sera*$totals;
$exp = $exp*$totals;



$dbc->query("UPDATE `users` SET `serebro`=`serebro`+'".$sera."' WHERE `id`='".$user['id']."'");
$dbc->query("UPDATE `dop` SET `razbor_exp`=`razbor_exp`+'".$exp."' WHERE `user`='".$user['id']."'");
$dbc->query("delete from `art_pet` where `user_id`='".$user['id']."' and `status` = 1 and `lite`= 'iEpic'");


  $new_dop=$dbc->query("SELECT * FROM `dop`where `user`= '".$user['id']."' ")->fetch_assoc();
if($new_dop['razbor_exp']>=$razbor['exp']){

$dbc->query("UPDATE `users` SET `max_health`=`max_health`+50, `strength`=`strength`+10, `defense`=`defense`+10, `gold`=`gold`+100 WHERE `id`='".$user['id']."'");

$dbc->query("UPDATE `dop` SET `razbor_lvl`=`razbor_lvl`+1 , `razbor_exp`=0 WHERE `user`='".$user['id']."'");
$_SESSION['bag'] = 'Уровень Разбора Повышен! получено 100 золота';

}
$_SESSION['message'] = 'Вещи Разобраны  <img src="img/stat/sera.png">'.$sera.' Опыт разбора: '.$exp.'';




header('location: bag_pet.php?');exit();  } 
if(isset($_GET['all'])){


$totalll = $dbc->query("SELECT (id) FROM `art_pet` where `user_id` =  '".$user['id']."' and `status` = 1 and `lite` = 'iLegendary'");

$totals= $totalll->num_rows; 

if($totals<=0){ header("Location: bag_pet.php?");exit;}

$sera=1000; $exp=20;

$sera=$sera+$sera_dop; $exp=$exp+$exp_dop; 

$sera = $sera*$totals;
$exp = $exp*$totals;



$dbc->query("UPDATE `users` SET `serebro`=`serebro`+'".$sera."' WHERE `id`='".$user['id']."'");
$dbc->query("UPDATE `dop` SET `razbor_exp`=`razbor_exp`+'".$exp."' WHERE `user`='".$user['id']."'");
$dbc->query("delete from `art_pet` where `user_id`='".$user['id']."' and `status` = 1 and `lite`= 'iLegendary'");


  $new_dop=$dbc->query("SELECT * FROM `dop`where `user`= '".$user['id']."' ")->fetch_assoc();
if($new_dop['razbor_exp']>=$razbor['exp']){

$dbc->query("UPDATE `users` SET `max_health`=`max_health`+50, `strength`=`strength`+10, `defense`=`defense`+10, `gold`=`gold`+100 WHERE `id`='".$user['id']."'");

$dbc->query("UPDATE `dop` SET `razbor_lvl`=`razbor_lvl`+1 , `razbor_exp`=0 WHERE `user`='".$user['id']."'");
$_SESSION['bag'] = 'Уровень Разбора Повышен! получено 100 золота';

}
$_SESSION['message'] = 'Вещи Разобраны  <img src="img/stat/sera.png">'.$sera.' Опыт разбора: '.$exp.'';




header('location: bag_pet.php?');exit();  }

if(isset($_GET['razbor']) and !empty($_GET['go'])){    
$it = int($_GET['go']);

$pet = $dbc->query("SELECT * FROM `art_pet` WHERE `id`='".$it."' AND `user_id`='".$user['id']."' LIMIT 1")->fetch_assoc();


    if(!$pet){    header("Location: bag_pet.php"); }


            if($pet['status']==2){    header("Location: index.php");exit; }
if($pet['lite']==iLegendary){ $sera=100; $exp=20;} if($pet['lite']==iSuperior){ $sera=20; $exp=2;} if($pet['lite']==iEpic){ $sera=50; $exp=5;}

//$sera=$sera+$sera_dop; $exp=$exp+$exp_dop;



$dbc->query("UPDATE `users` SET `serebro`=`serebro`+'".$sera."' WHERE `id`='".$user['id']."'");
$dbc->query("UPDATE `dop` SET `razbor_exp`=`razbor_exp`+'".$exp."' WHERE `user`='".$user['id']."'");
$dbc->query("delete from `art_pet` where `id`='".$pet['id']."'");


  $new_dop=$dbc->query("SELECT * FROM `dop`where `user`= '".$user['id']."' ")->fetch_assoc();
if($new_dop['razbor_exp']>=$razbor['exp']){

$dbc->query("UPDATE `users` SET `max_health`=`max_health`+50, `strength`=`strength`+10, `defense`=`defense`+10, `gold`=`gold`+100 WHERE `id`='".$user['id']."'");

$dbc->query("UPDATE `dop` SET `razbor_lvl`=`razbor_lvl`+1 , `razbor_exp`=0 WHERE `user`='".$user['id']."'");
$_SESSION['bag'] = 'Уровень Разбора Повышен! получено 100 золота';

}
$_SESSION['message'] = 'Вещь разобрана  <img src="img/stat/sera.png">'.$sera.' Опыт разбора: '.$exp.'';


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


}
while($row = $sql->fetch_assoc()){

if($row['mag']==1){ $mag =' style="box-shadow: 0px 0px 20px blue; margin: 2px;">';}




elseif($row['mag']==2){ $mag =' style="box-shadow: 0px 0px 20px violet; margin: 2px;">';}




elseif($row['mag']==3){ $mag =' style="box-shadow: 0px 0px 20px gold; margin: 2px;">';}

elseif($row['mag']==0){ $mag ='>';}
if($row['craft']>0){ $fla = '<span class="info">+'.$row['craft'].''; }else{ $fla = '';}  


?><div class="sblue-panel"><div class="panel-inner-3"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="37" style="vertical-align: top;"><img width="32"height="32" src="img/item_pet/<?=$row['img']?>.png" alt="."border="0" <?=$mag?>




</td><td><div><a href="/info_it.php?ids=<?=$row['id']?>" class="<?=$row['lite']?>"><center><?=$row['nik']?></a><?=$fla?></center></div><span class="nowrap"></span> <span class="nowrap"></span><span class="clearer"></span></td><td width="60"><a href="/bag_pet.php?id=<?=$row['id']?><??>&amp;ok" class="gr-btn center"><span>Надеть</span></a></td>  <td width="60"><a href="/bag_pet.php?ids=<?=$row['id']?><??>&amp;sel" class="gr-btn center"><span>Разбор</span></td></tr></table></div></div><?







if(isset($_GET['sel']) and !empty($_GET['ids'])){


    $_SESSION['idss'] = int($_GET['ids']);


header('location:bag_pet.php?sell');exit;



}
echo' </div>';
if(isset($_GET['ok']) and !empty($_GET['id'])){
    $pet_id = int($_GET['id']);
$pet = $dbc->query("SELECT * FROM `art_pet` WHERE `id`='".$pet_id."' AND `user_id`='".$user['id']."' LIMIT 1")->fetch_assoc();

if(!$my_pet){

  header("Location: bag_pet.php");}


if(!$pet){
        header("Location: bag_pet.php");

        exit;
        }

        if($pet['status']==2){
        header("Location: index.php");
        exit;
        }
        if($pet['tip']==1 and $my_pet['weapon']==1){ $prov= $dbc->query("SELECT * FROM `art_pet` WHERE `tip`=1 AND `status`=2 AND `user_id`='".$user['id']."' LIMIT 1")->fetch_assoc(); 

$dbc->query("UPDATE `user_pets` SET `str`=`str`-'".$prov['strong']."',`vit`=`vit`-'".$prov['hp']."',`def`=`def`-'".$prov['prot']."',`weapon`=0 WHERE `id_user`='".$user['id']."'");



      $dbc->query("UPDATE `art_pet` SET `status`=1 WHERE `id`='".$prov['id']."'");  }


        if($pet['tip']==2 and $my_pet['head']==1){ $prov= $dbc->query("SELECT * FROM `art_pet` WHERE `tip`=2 AND `status`=2 AND `user_id`='".$user['id']."' LIMIT 1")->fetch_assoc(); 

$dbc->query("UPDATE `user_pets` SET `str`=`str`-'".$prov['strong']."',`vit`=`vit`-'".$prov['hp']."',`def`=`def`-'".$prov['prot']."',`head`=0 WHERE `id_user`='".$user['id']."'");



      $dbc->query("UPDATE `art_pet` SET `status`=1 WHERE `id`='".$prov['id']."'");  }



        if($pet['tip']==3 and $my_pet['armor']==1){ $prov= $dbc->query("SELECT * FROM `art_pet` WHERE `tip`=3 AND `status`=2 AND `user_id`='".$user['id']."' LIMIT 1")->fetch_assoc(); 

$dbc->query("UPDATE `user_pets` SET `str`=`str`-'".$prov['strong']."',`vit`=`vit`-'".$prov['hp']."',`def`=`def`-'".$prov['prot']."',`armor`=0 WHERE `id_user`='".$user['id']."'");



      $dbc->query("UPDATE `art_pet` SET `status`=1 WHERE `id`='".$prov['id']."'");  }


        
if($pet['tip']==1){    $dbc->query("UPDATE `user_pets` SET `str`=`str`+'".$pet['strong']."',`vit`=`vit`+'".$pet['hp']."',`def`=`def`+'".$pet['prot']."',`weapon`=1 WHERE `id_user`='".$user['id']."'");}



if($pet['tip']==2){    $dbc->query("UPDATE `user_pets` SET `str`=`str`+'".$pet['strong']."',`vit`=`vit`+'".$pet['hp']."',`def`=`def`+'".$pet['prot']."',`head`=1 WHERE `id_user`='".$user['id']."'");}



if($pet['tip']==3){    $dbc->query("UPDATE `user_pets` SET `str`=`str`+'".$pet['strong']."',`vit`=`vit`+'".$pet['hp']."',`def`=`def`+'".$pet['prot']."',`armor`=1 WHERE `id_user`='".$user['id']."'");}




$dbc->query("UPDATE `art_pet` SET `status`=2 WHERE `id`='".$pet_id."'");

$_SESSION['message'] = 'На вашего питомца одета вещь '.$pet[nik].'';

header('Location: bag_pet.php?');exit();

        foot();
}
}
$totalll2 = $dbc->query("SELECT (id) FROM `art_pet` where `user_id` =  '".$user['id']."' and `status` = 1 and `lite` = 'iLegendary'");
$totals2= $totalll2->num_rows; 



if($totals2>0 and $user['level'] >44){




?><a class="btn" href="bag_pet.php?all" onclick="return confirm ('Вы уверены? все вещи будут разобраны')">Разобрать все легендарные вещи</a><?}




$totalll22 = $dbc->query("SELECT (id) FROM `art_pet` where `user_id` =  '".$user['id']."' and `status` = 1 and `lite` = 'iEpic'");
$totals22= $totalll22->num_rows; 



if($totals22>0 and $user['level'] >44){




?><a class="btn" href="bag_pet.php?alls" onclick="return confirm ('Вы уверены? все вещи будут разобраны')">Разобрать все эпические вещи</a><?}





foot();
?>


