<?php
$page_name = 'Пополнение баланса';
$page_keys = 'баланс';
$page_desc = 'Страница пополнения баланса';
$online_title = 'На странице пополнения баланса';
$online_url = '/account/cashadd';
include('../wu-engine/wu_header.php');
include('../wu-engine/wu_account_menu.php');
if(!USER_LOGGED) { header ("Location: /"); exit; }
$label = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT count(`id`) AS `cnt` FROM `".DB_PREFIX."_operations` WHERE usr = '$u_id'"));
?>

<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active"><a href="/account/cashadd">Пополнение баланса</a></li>
<li><a href="/account/cashout">Вывод средств</a></li>
<li><a href="/account/operations">История операций<?php if ($label['cnt'] > 0) { echo ' <span class="label label-info">'.$label['cnt'].'</span>'; } ?></a></li>
</ul>
<div class="tab-content with-padding">
<br />
<center>
<div class="form-group">
<select data-placeholder="Выберите платёжную систему" class="select" tabindex="2" id="paysystems">
<option value=""></option>
<?php
$wu_q = mysqli_query($connect_db, "SELECT id,ti FROM `".DB_PREFIX."_pay_systems` WHERE active_in = '1' ORDER BY pos ASC");
while($row = mysqli_fetch_assoc($wu_q)) {
?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['ti']; ?></option>
<?php } ?>
</select>
<a href="javascript://" class="btn btn-default" id="cashin" data-loading-text="<i class='icon-spinner7 spin'></i> Загружаем" />Пополнить</a>
</div>
</center>
</div>
</div>

<div id="modal_pay" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title"><i class="icon-credit"></i> Пополнение баланса через <font id="topay"></font></h4>
</div>
<div class="modal-body with-padding" id="paysys_result">
</div>
<div class="modal-footer">
<a class="btn btn-success" href="javascript://" id="btn_send">Пополнить</a>
<button class="btn btn-warning" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>

<script type="text/javascript" src="/wu-static/js/select2.min.js"></script>

<script type="text/javascript">
//Оформление селекта
$(document).ready(function() {
$(".select").select2({
minimumResultsForSearch: "-1",
width: 200
});
});

//Загрузка платёжной системы
$('#cashin').click(function(){
if ($('#paysystems').val() > 0) {
var paysys = $('#paysystems').val();
var data = {'id': paysys, 'type':'balance', 'extra':'', 'showsum':'1', 'infotext':''};
wu_response('/wu-engine/wu-pay-systems/wu_payload.php', data, 'cashin', '1', function(wu_result) {
if (wu_result == 'wu-error') {
wu_err();
} else {
$('#paysys_result').html(wu_result);
$('#topay').text($('#paysystems option:selected').text());
$('#modal_pay').modal('show');
}
});
} else { notif_e('Выберите платёжную систему'); }
});

$('#btn_send').click(function(){
var form = document.getElementById('wu-form-send-pay');
for(var i=0; i < form.elements.length; i++){
if(form.elements[i].value === '' && form.elements[i].hasAttribute('required')){
notif_e('Заполните необходимые поля');
return false;
}
}
form.submit();
$('#modal_pay').modal('hide');
});

</script>

<?php include('../wu-engine/wu_footer.php'); ?>