<?
    
    include './system/common.php';
    
 include './system/functions.php';
        
      include './system/user.php';
    
if(!$user) {

  header('location: /');
    
exit;

}


    $title = 'Набег';    

include './system/h.php';

  $zarm = mysql_query('SELECT * FROM `zarm` WHERE `user` = "'.$user['id'].'"');  
  $zarm = mysql_fetch_array($zarm);
  
  if(!$zarm) {
  
    mysql_query('INSERT INTO `zarm` (`user`) VALUES ("'.$user['id'].'")');
  
  }

?>

<div class='title'><?=$title?></div>
 <div class='line'></div>

<?

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


?>

<div class='menu'>
<li align='center'><img src='http://pbit.mobi/images/town/zarm.png' alt='*'/></li>
  <li class='no_b' align='center'>

<?

  if($zarm['h'] == 0 && $zarm['time'] == 0) {
  
  $h = _string(_num($_POST['h']));
  
    if($h && $user['level'] >= $h * 3) {
    
      $hs = ($h * (60 * 60));
            
      mysql_query('UPDATE `zarm` SET `h` = "'.$h.'", `time` = "'.(time() + $hs).'" WHERE `user` = "'.$user['id'].'"');
    
    header('location: /zarm.php');
    
    }

?>

<font color='#90b0c0'>В набеге ты получишь <img src='/images/icon/gold.png' alt='*'/> золото. Чем дольше набег длиться , тем больше награда!</font><br/>
<font color='#90b0c0'>1 час = 1 <img src='/images/icon/gold.png' alt='*'/> золоту. </font><br/>

<form action='/zarm.php' method='post'>
  <select name='h'>

<?

   for($h = 1; $h < 6; $h++) {

if($user['level'] >= $h * 3) {

?>

<option value='<?=$h?>'><?=$h?> час<?=($h == 1 ? '':($h == 5 ? 'ов':'а'))?></option>

<?

    }

  }

?>

  </select><br/>

<input type='submit' value='Набег!'/>

</form>

<?

  }
  else
  {


if($zarm['time'] > time()) {

  if($_GET['end'] == true) {
    mysql_query('UPDATE `zarm` SET `h` = "0", 
                                `time` = "0" WHERE `user` = "'.$user['id'].'"');
    header('location: /zarm/');
  }
  

?>

<font color='#90b0c0'>Вы в набеге...</font><br/>
Осталось: <?=_time($zarm['time'] - time())?><br/><br/>

<a href='/zarm/?end=true' class='button'>Отменить</a>

<?

  }
  else
  {

     mysql_query('UPDATE `users` SET `g` = `g` + '.($zarm['h'] * 1).' WHERE `id` = "'.$user['id'].'"');  
      mysql_query('UPDATE `zarm` SET `h` = "0",
                                  `time` = "0" WHERE `user` = "'.$user['id'].'"');
    
?>

<font color='#90b0c0'>Набег завершен!</font><br/>
Вы ограбили на : <img src='/images/icon/gold.png' alt='*'/> <?=n_f($zarm['h'] * 1)?> золота<br/><br/>

<a href='/zarm/' class='button'>Обновить</a>


<?

  }

  }

?>
  </li>
</div>

<?

  }
  else
  {
  
?>

<div class='content' align='center'>
  <img src='/images/icon/zarm.png' alt='*'/> Набег доступен с <img src='/images/icon/level.png' alt='*'/> 3 уровня<br/>
</div>

<?

  }
  
include './system/f.php';

?>