<?
//
//
require_once($_SERVER['DOCUMENT_ROOT']."/jquery/inc/system.php"); 
//
//
if(!$user){
header('location:/login/');
exit();
}
//
//
head([]);
//
//
echo logs();
//
//
$rudnik = DB::$dbs->queryFetch('SELECT * FROM `rudnik` WHERE `id` = ? LIMIT 1', [1]);
//
//
$sum_name = array('','Медная кирка','Серебряная кирка','Золотая кирка');
$sum_name2 = array('','Медную кирку','Серебряную кирку','Золотую кирку');
$sum_coll = array('','15','50','100');
$sum_case = array('','10','35','70');
//
//
if(isset($_GET['shop']) && $user['kirka'] <= 0){
    $coll = num($_GET['pay']);
//
//
if($coll >= 1 && $coll <= 3){
if($user['diamond'] < $sum_case[$coll]){
err2("У вас недостаточно алмазов");
header('location:?');
exit();
}
//
//
DB::$dbs->query('UPDATE `users` SET `diamond` = `diamond` - ?, `kirka` = `kirka` + ?, `kirka_price` = ? WHERE `id` = ? LIMIT 1', array($sum_case[$coll],$sum_coll[$coll],$coll,$user['id']));//
//
ok2("Вы купили ".$sum_name2[$coll]." за <img src='/css/img/diamond.png'> ".$sum_case[$coll]." алмазов ");
header('location:?');
exit();
//
//
}
//
//
?>
<div class="poster -gas">
		    <div class="start">
		        <center>
		            <span class="title-wqi">Рудники</span>
		        </center>
<?
//
//
for($i=1;$i<=3;$i++) {
?>
<div class="menu-not2">
<img src="/css/img/kirka.png" width="16" height="16"> <?=$sum_name[$i];?><br>

<font color="#777777">
Прочность <?=$sum_coll[$i];?> ударов
</font>
</div>
<a href="?shop&pay=<?=$i;?>"><div class="click">Купить за <img src="/css/img/diamond.png"> <?=$sum_case[$i];?></div></a>
<div class="stats2"></div>
<?
}
?>
<a href="?">Вернуться назад</a>
</div></div>
<?
    //
    //
foot([]);
exit();
}
//
//
//
if(isset($_GET['kirka'])){
//
//
if($user['kirka'] <= 0){
err2("У вас нет кирки");
header('location:?');
exit();
}
//
//
$rand = rand(1,12);
$rand_gold = rand(3,6);
$rand_gold2 = 7;
$rand_gold3 = 15;
if($rand == 2){
DB::$dbs->query('UPDATE `users` SET `gold` = `gold` + ?, `gold_rudnik` = `gold_rudnik` + ? WHERE `id` = ? LIMIT 1', array($rand_gold,$rand_gold,$user['id']));
$res = 'gold';
DB::$dbs->query('INSERT INTO `rudnik_logs` SET `res` = ?,`coll` = ?,`id_user` = ?',array($res,$rand_gold,$user['id']));
//
//
//
DB::$dbs->query("UPDATE `titul_user` SET `coll` = `coll` + ? WHERE `id_titul` = ? AND `id_user` = ? LIMIT 1", array($rand_gold,2,$user['id']));
//
//
//
$task = DB::$dbs->queryFetch("SELECT * FROM `task_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(3,$user['id']));
if($task['check'] == 0)DB::$dbs->query("UPDATE `task_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array($rand_gold,$task['id']));
//
//
ok2('Вы добыли золото');
}elseif($rand == 4){
DB::$dbs->query('UPDATE `users` SET `gold` = `gold` + ?, `gold_rudnik` = `gold_rudnik` + ? WHERE `id` = ? LIMIT 1', array($rand_gold2,$rand_gold2,$user['id']));
$res = 'gold';
DB::$dbs->query('INSERT INTO `rudnik_logs` SET `res` = ?,`coll` = ?,`id_user` = ?',array($res,$rand_gold2,$user['id']));
//
//
//
//
DB::$dbs->query("UPDATE `titul_user` SET `coll` = `coll` + ? WHERE `id_titul` = ? AND `id_user` = ? LIMIT 1", array($rand_gold2,2,$user['id']));
//
//
$task = DB::$dbs->queryFetch("SELECT * FROM `task_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(3,$user['id']));
if($task['check'] == 0)DB::$dbs->query("UPDATE `task_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array($rand_gold2,$task['id']));
//
//
ok2('Вы добыли золото');
}elseif($rand == 8){
DB::$dbs->query('UPDATE `users` SET `gold` = `gold` + ?, `gold_rudnik` = `gold_rudnik` + ? WHERE `id` = ? LIMIT 1', array($rand_gold3,$rand_gold3,$user['id']));
$res = 'gold';
DB::$dbs->query('INSERT INTO `rudnik_logs` SET `res` = ?,`coll` = ?,`id_user` = ?',array($res,$rand_gold3,$user['id']));
//
//
//
//
DB::$dbs->query("UPDATE `titul_user` SET `coll` = `coll` + ? WHERE `id_titul` = ? AND `id_user` = ? LIMIT 1", array($rand_gold3,2,$user['id']));
//
//
$task = DB::$dbs->queryFetch("SELECT * FROM `task_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(3,$user['id']));
if($task['check'] == 0)DB::$dbs->query("UPDATE `task_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array($rand_gold3,$task['id']));
//
//
ok2('Вы добыли золото');
}else{
err2("Не повезло, попробуйте еще раз");
}
//
//
DB::$dbs->query('UPDATE `users` SET `kirka` = `kirka` - ? WHERE `id` = ? LIMIT 1', array(1,$user['id']));
//
//
header('location:?');
exit();
}
//
//
?>
<div class="poster -gas">
		    <div class="start">
		        <center>
		            <span class="title-wqi">Рудники</span>
		        </center>

<div class="menu-not2">
Золотой рудник		        
<br>
<font color="#999999">
Вы сегодня добыли: 
<img src = "/css/img/gold.png" width="16" height="16"> <?=$user['gold_rudnik'];?>
</font>
<br>

</div>
<a href="?kirka"><div class="click">Добыть за <img src = "/css/img/kirka.png" width="16" height="16"> 1</div></a>
<div class="stats2"></div>




<?
if($user['kirka'] <= 0){
?>
<a href="?shop"><div class="click">Магазин кладоискателя</div></a>
<?
}else{
?>
<center><small><font color="#777777">У вас <?=$sum_name[$user['kirka_price']];?>, <img src = "/css/img/kirka.png" width="16" height="16"> <?=$user['kirka'];?> ударов</font></small></center>
<?
}
?>
<div class="stats2"></div>

<center>Список добытчиков</center>
<div class="stats2"></div>

<?
                $coll = DB::$dbs->querySingle('SELECT COUNT(id) FROM `rudnik_logs` WHERE `id` != "0"');
		$num = 10;
		$total = intval(($coll - 1) / $num) + 1;
		$page = isset($_GET['page'])?intval($_GET['page']):1;
		if(empty($page) or $page < 0) $page = 1;
		if($page > $total) $page = $total;
		$start = $page * $num - $num; 

$sql = DB::$dbs->query("SELECT `id`,`id_user`,`coll`,`res` FROM `rudnik_logs` WHERE `id` != '0' ORDER BY `id` DESC LIMIT $start, $num")->fetchAll(PDO::FETCH_BOTH);

			foreach ($sql as $sqlls => $im): ?>


<div class="menu-us">
<font color="#999999">
<?=user_info($im['id_user']);?>
<span style="float: right;"><img src="/css/img/<?=$im['res'];?>.png"> <?=$im['coll'];?></span>
</font>
</div>


			<?php endforeach;
			?>
			</div>
			<?
			echo page('?',$page,$total); ?>
			</div>



<?
//
//
foot([]);
//
//
?>