<?php
$page_name = 'История операций';
$page_keys = 'история,операции';
$page_desc = 'История финансовых операций';
$online_title = 'На странице истории финансовых операций';
$online_url = '/account/operations';
$page_right = '<div class="header-buttons"><div class="collapse" id="header-buttons"><div class="well"><a href="javascript://" id="stat_open" class="btn btn-primary">Статистика</a></div></div></div>';
include('../wu-engine/wu_header.php');
include('../wu-engine/wu_account_menu.php');
include('../wu-engine/wu-functions/wu_pagination.php');
include('../wu-engine/wu-functions/wu_functions.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 id="modal_stat" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<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-stats"></i> Статистика</h4>
</div>
<div class="modal-body with-padding">
<div id="stat_res"></div>
</div>
<div class="modal-footer">
<button class="btn btn-warning" data-dismiss="modal">Закрыть</button>
</div>
</div>
</div>
</div>

<div class="tabbable">
<ul class="nav nav-tabs">
<li><a href="/account/cashadd">Пополнение баланса</a></li>
<li><a href="/account/cashout">Вывод средств</a></li>
<li class="active"><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">
<?php
$num = 20; //Сколько выводить на странице
if (isset($_GET['page'])) { $page = intval($_GET['page']); if ($page == 0) { $page = 1; } } else { $page = 1; }
$qu = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT count(`id`) AS `cnt` FROM `".DB_PREFIX."_operations` WHERE usr = '$u_id'"));
$co = $qu['cnt'];
$total = intval(($co - 1) / $num) + 1;
$page = intval($page);
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * $num - $num;
$qr = mysqli_query($connect_db, "SELECT id,ty,s,msg,dt FROM `".DB_PREFIX."_operations` WHERE usr = '$u_id' ORDER BY id DESC LIMIT $start, $num");
if ($co > 0) {
while($row = mysqli_fetch_assoc($qr)) {
?>
<div class="fulln">
<span class="alert-notice"><?php echo wudatenorm($row['dt']); ?></span>
<div class="alert alert-<?php if($row['ty'] == 0 || $row['ty'] == 3) { echo 'danger'; } if($row['ty'] == 1 || $row['ty'] == 2) { echo 'success'; } ?> fade in block-inner">
<i class="icon-<?php if($row['ty'] == 0 || $row['ty'] == 3) { echo 'minus'; } if($row['ty'] == 1 || $row['ty'] == 2) { echo 'plus'; } ?>"></i> <?php if($row['ty'] == 0 || $row['ty'] == 3) { echo 'Со счёта списано '; } if($row['ty'] == 1 || $row['ty'] == 2) { echo 'На Ваш счёт зачислено '; } echo $row['s'].' руб. ('.htmlspecialchars($row['msg']).').'; ?>
</div></div>
<?php }
$pageNav = new SimPageNav();
$pages = ceil($co/$num);
echo $pageNav->getLinks($pages, 1, $page, 10, 'page');
} else { echo '<div class="alert alert-info fade in"><i class="icon-info"></i> Операций нет</div>'; }
?>
</div>
</div>

<script src="/wu-static/js/wu_graph.js"></script>
<script src="/wu-static/js/wu_graph_export.js"></script>

<script type='text/javascript'>
$('#stat_open').click(function(){
if ($("#stat_res").text().length == 0) { $("#stat_res").html('<center><i class="icon-spinner7 margloadt spin"></i></center>'); }
$('#modal_stat').modal('show');
var data = {'load': 'ok'};
wu_response('/wu-engine/wu-actions/acc_operations_stat_load.php', data, '', '1', function(wu_result) {
if (wu_result == 'wu-err-3') {
wu_err();
} else {
$("#stat_res").html(wu_result);
}
});
});
</script>

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