<?php
session_start();
include ('private/mysql.php');
include ('tmp/head.php');

if($uid!=='7'){
header('Location: main.php');exit;
}

$q = mysql_query("SELECT * FROM `cave` WHERE `user`='$uid'");
$e = mysql_num_rows($q);
$w = mysql_fetch_assoc($q);

if($_SESSION['cave']!==""){
    echo $_SESSION['cave'];
    $_SESSION['cave']="";
}


switch($sd){
default:


if($e=='0'){
    echo "Вы находитесь в пещере, где вы можете добыть различные ресурсы.<br>Ресурсы из пещеры могут вам пригодиться для зачарования ваших вещей.<br><br>";
    
	
    echo "<hr><span style='float:left'><img src='img/cave/coal.png' width='55'></span>&nbsp;<font color=white>Уголь (1 ур.)</font><br>&nbsp;Время добычи: 1 час<br>&nbsp;<a href='cave.php?sd=mine&res=coal'>Начать добычу</a><hr>";
    echo "<span style='float:left'><img src='img/cave/kvarc.png' width='55'></span>&nbsp;<font color=white>Кварц (2 ур.)</font><br>&nbsp;Время добычи: 2 часа<br>&nbsp;<a href='cave.php?sd=mine&res=kvarc'>Начать добычу</a><hr>";
    echo "<span style='float:left'><img src='img/cave/dolomit.png' width='55'></span>&nbsp;<font color=grey>Доломит (3 ур.)</font><br>&nbsp;Время добычи: 3 часа<br>&nbsp;<a href='cave.php?sd=mine&res=dolomit'>Начать добычу</a><hr>";
    echo "<span style='float:left'><img src='img/cave/olovo.png' width='55'></span>&nbsp;<font color=grey>Олово (6 ур.)</font><br>&nbsp;Время добычи: 4 часа<br>&nbsp;<a href='cave.php?sd=mine&res=olovo'>Начать добычу</a><hr>";
    echo "<span style='float:left'><img src='img/cave/copper.png' width='55'></span>&nbsp;<font color=lime>Медь (9 ур.)</font><br>&nbsp;Время добычи: 5 часов<br>&nbsp;<a href='cave.php?sd=mine&res=copper'>Начать добычу</a><hr>";
    
    
      
}else{
    
    if($w['time']>time()){
    echo "Вы добываете:<hr>";
    
    if($w['res'] == 'coal'){$nel = 1;$tl = 3600;$fn = "Уголь";$b=1;}
    if($w['res'] == 'kvarc'){$nel = 2;$tl = 7200;$fn = "Кварц";$b=2;}
    if($w['res'] == 'dolomit'){$nel = 3;$tl = 10800;$fn = "Доломит";$b=3;}
    if($w['res'] == 'olovo'){$nel = 6;$tl = 14400;$fn = "Олово";$b=4;}
    if($w['res'] == 'copper'){$nel = 9;$tl = 18000;$fn = "Медь";$b=5;}
    if($w['res'] == 'aktinolit'){$nel = 12;$tl = 21600;$fn = "Актинолит";$b=6;}
    if($w['res'] == 'rozelit'){$nel = 15;$tl = 25200;$fn = "Розелит";$b=7;}
    if($w['res'] == 'silver'){$nel = 18;$tl = 28800;$fn = "Серебро";$b=8;}
    if($w['res'] == 'ametist'){$nel = 21;$tl = 32400;$fn = "Аметист";$b=9;}
    if($w['res'] == 'gold'){$nel = 24;$tl = 36000;$fn = "Золото";$b=10;}
    if($w['res'] == 'almandin'){$nel = 27;$tl = 39600;$fn = "Альмандин";$b=11;}
    if($w['res'] == 'rubin'){$nel = 30;$tl = 43200;$fn = "Рубин";$b=12;}
    
    echo "<span style='float:left'><img src='img/cave/$w[res].png' width='36'></span>&nbsp;$fn<br>&nbsp;Осталось: ".time_left($w['time']-time())."<br><hr>";
    
    echo "← <a href='main.php'>назад</a>";
    
    }else{
    
        if($w['res'] == 'coal'){$nel = 1;$tl = 3600;$fn = "Уголь";}
        if($w['res'] == 'kvarc'){$nel = 2;$tl = 7200;$fn = "Кварц";}
        if($w['res'] == 'dolomit'){$nel = 3;$tl = 10800;$fn = "Доломит";}
        if($w['res'] == 'olovo'){$nel = 6;$tl = 14400;$fn = "Олово";}
        if($w['res'] == 'copper'){$nel = 9;$tl = 18000;$fn = "Медь";}
        if($w['res'] == 'aktinolit'){$nel = 12;$tl = 21600;$fn = "Актинолит";}
        if($w['res'] == 'rozelit'){$nel = 15;$tl = 25200;$fn = "Розелит";}
        if($w['res'] == 'silver'){$nel = 18;$tl = 28800;$fn = "Серебро";}
        if($w['res'] == 'ametist'){$nel = 21;$tl = 32400;$fn = "Аметист";}
        if($w['res'] == 'gold'){$nel = 24;$tl = 36000;$fn = "Золото";}
        if($w['res'] == 'almandin'){$nel = 27;$tl = 39600;$fn = "Альмандин";}
        if($w['res'] == 'rubin'){$nel = 30;$tl = 43200;$fn = "Рубин";}
    
        
        $ss = mysql_num_rows(mysql_query("SELECT * FROM `res` WHERE `user`='$uid' and `res`='$w[res]'"));
        if($ss=='0'){
            mysql_query("INSERT INTO `res` SET `user`='$uid',`name`='$fn',`img`='$w[res].png',`kol`='1',`res`='$w[res]'");
        }else{
            if($user['level']>='3'){$koll=$user['level']+1;}else{$koll=1;}
            mysql_query("UPDATE `res` SET `kol`=`kol`+'$koll' WHERE `user`='$uid' and `res`='$w[res]'");
        }
        
        
        $_SESSION['cave']="<img src='img/cave/$w[res].png' width='30'> <font color=lightgreen>Добыто</font><hr>";
        
        mysql_query("DELETE FROM `cave` WHERE `user`='$uid'");
        
        header('Location: cave.php');
        exit;
        
    }
    
}

break;

case 'mine':

$res = mysql_real_escape_string(htmlspecialchars($_GET['res']));
$q = mysql_query("SELECT * FROM `cave` WHERE `user`='$uid'");
$e = mysql_num_rows($q);
if($e >= '1'){
    header('Location: cave.php');
    exit;
}

if($res == 'coal'){$nel = 1;$tl = 3600;$fn = "Уголь";}
if($res == 'kvarc'){$nel = 2;$tl = 7200;$fn = "Кварц";}
if($res == 'dolomit'){$nel = 3;$tl = 10800;$fn = "Доломит";}
if($res == 'olovo'){$nel = 6;$tl = 14400;$fn = "Олово";}
if($res == 'copper'){$nel = 9;$tl = 18000;$fn = "Медь";}
if($res == 'aktinolit'){$nel = 12;$tl = 21600;$fn = "Актинолит";}
if($res == 'rozelit'){$nel = 15;$tl = 25200;$fn = "Розелит";}
if($res == 'silver'){$nel = 18;$tl = 28800;$fn = "Серебро";}
if($res == 'ametist'){$nel = 21;$tl = 32400;$fn = "Аметист";}
if($res == 'gold'){$nel = 24;$tl = 36000;$fn = "Золото";}
if($res == 'almandin'){$nel = 27;$tl = 39600;$fn = "Альмандин";}
if($res == 'rubin'){$nel = 30;$tl = 43200;$fn = "Рубин";}

if($user['level']<$nel){
    header('Location: cave.php');
    exit;
}

$last = time()+$tl;

mysql_query("INSERT INTO `cave` SET `user`='$uid',`res`='$res',`time`='$last'");

$_SESSION['cave']="<img src='img/cave/$res.png' width='30'> <font color=lightgreen>Вы успешно начали добычу</font><hr>";

header('Location: cave.php');
exit;

break;



}
include ('tmp/foot.php');
?>