<?php if(!defined('FastCore')){exit('Opss!');}
# Заголовок
$opt['title'] = 'Обменник';
# Значения
$min_sum = '1';
$db->query("SELECT * FROM db_conf WHERE id = '1' LIMIT 1");
$cnf = $db->fetchArray();
/* конец проверки IP*/
?>
<br>
<!-- Page content -->
<div class="container-fluid mt--6">
<?PHP
# Обменник
if(isset($_POST["change"])){
$sum = (float)$_POST["change"];
if($sum >= $min_sum){
if($user['money_p'] >= $sum){
$add_sum = sprintf("%.2f",($cnf['p_swap'] > 0) ? ( ($cnf['p_swap'] / 100) * $sum) + $sum : $sum);
$db->query('UPDATE db_users SET money_b = money_b + ?, money_p = money_p - ? WHERE id = ?',array($add_sum,$sum, $uid));
echo '<center class="alert alert-success">Обмен произведен (+'.$add_sum.' RUB)</center>';
}else echo '<center class="alert alert-warning">Недостаточно средств</center>';
}else echo '<center class="alert alert-danger">Минимум '.$min_sum.' RUB</center>';
}
?>
<br><br><br><br>
<div class="row mb-5">
<div class="col-lg-4"></div>
<div class="col-lg-4">
<div class="card">
<div class="card-body"style="box-shadow: 0px 22px 20px 0px rgb(41 26 85 / 27%);">
<form action="" method="post" onsubmit="submitfromexchange(this);return false">
<div class="text-left h5 text-uppercase">Сумма обмена:</div>
<div class="input-group mb-2">
<div class="input-group-prepend"><span class="input-group-text">RUB</span></div>
<input type="text" class="form-control" onkeyup="GetSumPer(this.value);" id="amount" name="change" value="10" />
</div>
<div class="text-center">
<h4 id="res_sum">Минимум для обмена <?=$min_sum; ?> RUB</h4>
<input type="hidden" name="per" id="percent" value="<?=$cnf['p_swap']; ?>" disabled="disabled"/>
<button class="btn btn-primaryz mb-2" type="submit"><i class="fa fa-exchange-alt"></i> <span class="btn btn-primaryz mb-2">Обменять</span> </button>
</div>
</form>
<script language="javascript">GetSumPer();</script>
<script type="text/javascript">
function GetSumPer(st_q) {
if (st_q) {
var sum_insert = parseFloat(st_q);
$('#res_sum').html("Вы получите [+<?=$cnf['p_swap']; ?>%]: <span class='text-danger'> " + (sum_insert + (sum_insert * <?=$cnf['p_swap']/100; ?>)).toFixed(2) + "</span> RUB");
if (sum_insert < <?=$min_sum; ?>) {
$('button').attr("disabled", "disabled");
return false;
} else {
$('button').removeAttr("disabled");
}
} else {
$('#res_sum').html("");
}
}
</script>
</div>
</div>
</div>
</div>
</div>
</div>