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

  header('location: /');
    
exit;

}


    $title = 'Работа';    

include './system/h.php';

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

?>

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

<?

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


?>

<div class='menu'>
  <li align='center'><img src='/images/town/farm.png' alt='*'/></li>
  <li class='no_b' align='center'>

<?

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

?>

<font color='#90b0c0'>Работая в канализации ты получишь <img src='/images/icon/silver.png' alt='*'/> сигареты. </font><br/>

<form action='/farm.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($farm['time'] > time()) {

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

?>

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

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

<?

  }
  else
  {

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

<font color='#90b0c0'>Вы вернулись с работы!</font><br/>
Заработал: <img src='/images/icon/silver.png' alt='*'/> <?=n_f($farm['h'] * 1000)?> сигарет<br/><br/>

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


<?

  }

  }

?>
  </li>
</div>

<?

  }
  else
  {
  
?>

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

<?

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

?>