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

  header('location: /');
    
exit;

}

switch($_GET['action']) {

  default:

    $title = 'Получить золото';    

include './system/h.php';

?>

<div class='main'>
<div class='block' align='center'>
  <font color='#9bc'>Золото самый ценный ресурс!</font>
</div></div>
<div class='mini-line'></div>
<div class='main'>
<div class='menuList'>
  <li><a href='/trade/exchange/'><img src='/images/icon/gold.png' alt='*'/> Обменник золота</a></li>
<div class='title' align='center'>Купить золото</div>
</div>
<div class='mini-line'></div>
<div class='main'>
<div class='block_zero'>
<li>В настоящий момент купить золото можно только через <a href='/mail/1'>администрацию</a></li></div>
</div>
</div>

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

          break;

case 'exchange':

    $title = 'Обменник';    

include './system/h.php';

  $course = 500;

$g = _string(_num($_GET['g']));
  if($g) {
  
  if($_GET['buy'] == true) {

    if($user['s'] < $course * $g) {
    
        header('location: /trade/exchange/');
    
    exit;
    
    }
  
  mysql_query('UPDATE `users` SET `g` = "'.($user['g'] + $g).'", `s` = "'.($user['s'] - $course * $g).'" WHERE `id` = "'.$user['id'].'"');
    
  }
  else
  {

    if($user['g'] < $g) {
    
        header('location: /trade/exchange/');
    
    exit;
    
    }
    
  mysql_query('UPDATE `users` SET `g` = "'.($user['g'] - $g).'", `s` = "'.($user['s'] + $course * $g).'" WHERE `id` = "'.$user['id'].'"');
  
  }
  
        header('location: /trade/exchange/');
  
  }

?>

<div class='main'>
<div class='block_zero' align='center'>
  <img src='/images/town/gold.png' alt='*'/>
</div>
<div class='mini-line'></div>
<div class='main'>
<div class='menuList'>
<div class='block_zero' align='center'><font color='#9bc'>Обмен <img src='/images/icon/silver.png' alt='*'/> серебра на <img src='/images/icon/gold.png' alt='*'/> золото</font></div>

<div class='mini-line'></div>


<?
  
  for($i = 1; $i <= ($user['level'] > 10 ? 10:$user['level']); $i++) {

  if($i == 1 OR $i == 5 OR $i == 10) {

  if($user['s'] > $course * $i) {

?>

<li><a href='/trade/exchange/<?=$i?>/?buy=true'><img src='/images/icon/arrow.png' alt='*'/> <img src='/images/icon/silver.png' alt='*'/> <font color='#ffffff'><?=n_f($course * $i)?> → <img src='/images/icon/gold.png' alt='*'/> <?=$i?>            </font></a></li>

<?

  }
  
  }
  
  }

?>

</div>

<div class='mini-line'></div></div>

<div class='main'>
<div class='block_zero' align='center'><font color='#9bc'>Купить <img src='/images/icon/silver.png' alt='*'/> серебро</font></div>

<div class='mini-line'></div>

<div class='menuList'>
<?

  for($i = 1; $i <= ($user['level'] > 10 ? 10:$user['level']); $i++) {

  if($i == 1 OR $i == 5 OR $i == 10) {

  if($user['g'] >= $i) {

?>

<li><a href='/trade/exchange/<?=$i?>/'><img src='/images/icon/arrow.png' alt='*'/> <font color='#ffffff'><img src='/images/icon/gold.png' alt='*'/> <?=$i?> → <img src='/images/icon/silver.png' alt='*'/> <?=n_f($course * $i)?></font></a></li>

<?

  }

  }
  
  }

?>

</div>
</div>
</div>


<?

include './system/f.php';

break;

}

?>