<?
    
    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='title'><?=$title?></div>
 <div class='line'></div>
<div class='line'></div>
<div class='list'>
  <li><a href='/trade/exchange/'><img src='/images/icon/gold.png' alt='*'/> Обменник</a></li>
<div class='content' align='center'>Купить рубли</div>
<li><a href='/pay/'><img src='/images/icon/gold.png' alt='*'/> WebMoney Merchant</a></li>
</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 OR $g<0) {
    
        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='title'><?=$title?></div>
 <div class='line'></div>

<div class='content' align='center'>
  <img src='/images/town/gold.png' alt='*'/>
</div>
<div class='line'></div>

<div class='list'>
<div class='content' align='center'><font color='#9bc'>Обмен <img src='/images/icon/silver.png' alt='*'/> сигарет на <img src='/images/icon/gold.png' alt='*'/> рубли</font></div>

<div class='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>

<?

  }
  
  }
  
  }

?>

<li class='no_b'></li>


</div>

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

<div class='list'>
<div class='content' align='center'><font color='#9bc'>Купить <img src='/images/icon/silver.png' alt='*'/> сигареты</font></div>

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


<?

  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>

<?

  }

  }
  
  }

?>

<li class='no_b'></li>


</div>



<?

include './system/f.php';

break;

}

?>