<?
if(!isset($_SESSION['id']))
{
	Header("Location: /");
	exit;
}
?>
<div class="title">Лог событий</div>
<div class="text">
<style>

.activ{
font-weight: 600;
color: green;
background: #E0F4D7;
}
.linkPage{
font-weight: 400;
color: gray;
}
.nav_button{
background: #ebebeb;
padding: 2px 5px;
border: 1px solid #8c8c8c;
}
.point{
margin-left: 10px;
font-weight: 600;
}
</style>
<?
$num = 10;  
if(isset($_GET['str'])){
$page = intval($_GET['str']);  
}else{
$page = 1;
}
$result = $mysql->query("SELECT COUNT(*) AS `qaz` FROM db_log WHERE UserId = '".$_SESSION['id']."'"); 
 $q1 = $result->fetch();
$posts = $q1['qaz'];  
$total = intval(($posts - 1) / $num) + 1;  
$page = intval($page);  
if(empty($page) or $page < 0) $page = 1;  
  if($page > $total) $page = $total;  
$start = $page * $num - $num;  


$q = $mysql->query("SELECT * FROM db_log WHERE UserId = '".$_SESSION['id']."' ORDER BY Uid DESC LIMIT $start, $num");
while($r = $q->fetch())
{
	if($r['Uid'] % 2 == 0) $stil = 'bg-grey'; else $stil = '';
?>
			<div class="log <?=$stil; ?>">
				<div class="control">
					<div class="title pad-not fs9"><img src="/images/moneyin.png"/><?=$r['MoneyIn']; ?></div>
					<div class="title pad-not fs9"><img src="/images/moneyout.png"/><?=$r['MoneyOut']; ?></div>
				</div>
				<span class="date"><?=date("d.m.Y (H:i)", $r['DateAdd']); ?></span>
				
				<?=$r['Text']; ?>		
				
				<div class="clear"></div>
			</div>
		 
			
<? } ?>		

<hr>
<?
					// Проверяем нужны ли стрелки назад 
if($page >= 1){				
$pervpage='';
$page2left='';
$page1left='';
$page1right='';
$page2right='';
$nextpage='';
}					
if ($page != 1) $pervpage = '<a class="nav_button" href= /index.php?page=log&str=1><<</a>  
                               <a class="nav_button" href= /index.php?page=log&str='. ($page - 1) .'><</a> ';  
// Проверяем нужны ли стрелки вперед  
if ($page != $total) $nextpage = ' <a class="nav_button" href= /index.php?page=log&str='. ($page + 1) .'>></a>  
                                   <a class="nav_button" href= /index.php?page=log&str=' .$total. '>>></a>';  

// Находим две ближайшие станицы с обоих краев, если они есть  
if($page - 2 > 0) $page2left = ' <a class="nav_button" href= /index.php?page=log&str='. ($page - 2) .'>'. ($page - 2) .'</a> | ';
if($page - 1 > 0) $page1left = '<a class="nav_button" href= /index.php?page=log&str='. ($page - 1) .'>'. ($page - 1) .'</a> | ';  
if($page + 2 <= $total) $page2right = ' | <a class="nav_button" href= /index.php?page=log&str='. ($page + 2) .'>'. ($page + 2) .'</a>';
if($page + 1 <= $total) $page1right = ' | <a class="nav_button" href= /index.php?page=log&str='. ($page + 1) .'>'. ($page + 1) .'</a>'; 

// Вывод меню  
echo '<center>'.$pervpage.$page2left.$page1left.'<b>'.$page.'</b>'.$page1right.$page2right.$nextpage.'</center>';  
?> 

				<div class="clear"></div>
	</div>