<?php
include_once '../../sys/inc/start.php';
include_once '../../sys/inc/compress.php';
include_once '../../sys/inc/sess.php';
include_once '../../sys/inc/home.php';
include_once '../../sys/inc/settings.php';
include_once '../../sys/inc/db_connect.php';
include_once '../../sys/inc/ipua.php';
include_once '../../sys/inc/fnc.php';
include_once '../../sys/inc/user.php';
$set['title']='Кактусомания';
include_once '../../sys/inc/thead.php';
title();
aut();

if(!isset($user)){
header("Location:/aut.php");
break;
}
function sictime($timediff){
$oneMinute=60;
$oneHour=60*60;
$oneDay=60*60*24;
$dayfield=floor($timediff/$oneDay);
$hourfield=floor(($timediff-$dayfield*$oneDay)/$oneHour);
$minutefield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour)/$oneMinute);
$secondfield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour-$minutefield*$oneMinute));
$time_1=" $dayfield д. $hourfield ч. $minutefield м. $secondfield c. ";
return $time_1;
}
################################################################################
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kaktuz` WHERE `id_u`='".$user['id']."'"),0)=='0'){
mysql_query("INSERT INTO `kaktuz`(`id_u`, `time_l`, `date_r`) VALUES('".$user['id']."', '".time()."', '".time()."')");
header("location:index.php?".$passgen."");
exit;
}
$kaktuz_kol=mysql_result(mysql_query("SELECT COUNT(*) FROM `kaktuz` WHERE `id_u`='".$user['id']."'"),0);
$k_page=k_page($kaktuz_kol,1);
$page=page($k_page);
$start=1*$page-1;
$all_kaktuz=mysql_fetch_array(mysql_query("SELECT * FROM `kaktuz` WHERE `id_u`='".$user['id']."' LIMIT $start,1"));
if($all_kaktuz['zdor']>='80'){
$ras='.png';
}
elseif($all_kaktuz['zdor']<='79' && $all_kaktuz['zdor']>='50'){
$ras='_n.png';
}
elseif($all_kaktuz['zdor']<='49'){
$ras='_y.png';
}
if(time()-$all_kaktuz['time_l']>='172800'){
mysql_query("UPDATE `kaktuz` SET `zdor`=`zdor`-20 WHERE `id`='".$all_kaktuz['id']."' LIMIT 1");
}
elseif(time()-$all_kaktuz['time_l']>='691200'){
mysql_query("UPDATE `kaktuz` SET `zdor`=`zdor`-100 WHERE `id`='".$all_kaktuz['id']."' LIMIT 1");
}
mysql_query("UPDATE `kaktuz` SET `time_l`='".time()."' WHERE `id`='".$all_kaktuz['id']."' LIMIT 1");

if($all_kaktuz['zdor']<='0'){
mysql_query("DELETE FROM `kaktuz` WHERE `id`='".$all_kaktuz['id']."' LIMIT 1");
header("location:index.php?$passgen");
exit;
}
################################################################################
echo "<div class='aut2'>\n";
if($all_kaktuz['time_p']<time()){
echo "<a href='poliv.php?id=".$all_kaktuz['id']."'><img src='img/pol.png' alt='полив'/></a>";
}else{
echo "<a href='poliv.php?id=".$all_kaktuz['id']."'><img src='img/pol_isp.png' alt='полив'/></a>";
}
if($all_kaktuz['time_y']<time()){
echo "<a href='ydob.php?id=".$all_kaktuz['id']."'><img src='img/yd.png' alt='удоб'/></a>";
}else{
echo "<a href='ydob.php?id=".$all_kaktuz['id']."'><img src='img/yd_isp.png' alt='удоб'/></a>";
}
if($all_kaktuz['time_r']<time()){
echo "<a href='rez.php?id=".$all_kaktuz['id']."'><img src='img/rez.png' alt='подстричь'/></a>";
}else{
echo "<a href='rez.php?id=".$all_kaktuz['id']."'><img src='img/rez_isp.png' alt='подстричь'/></a>";
}
if($all_kaktuz['tekila']!='0'){
echo "<a href='tekila.php?id=".$all_kaktuz['id']."'><img src='img/tek.png' alt='текила'/></a>";
}
else
{
echo "<a href='tekila.php?id=".$all_kaktuz['id']."'><img src='img/tek_isp.png' alt='текила'/></a>";
}
if($all_kaktuz['vitamin']!='0'){
echo "<a href='v.php?id=".$all_kaktuz['id']."'><img src='img/vit.png' alt='витамин'/></a>";
}
else
{
echo "<a href='v.php?id=".$all_kaktuz['id']."'><img src='img/vit_isp.png' alt='витамин'/></a>";
}
################################################################################
echo "<span style='float : right;'>";
echo "<a href='top.php'><img src='img/top.png' alt='kaktuz'/></a>";
echo "<a href='new.php'><img src='img/add.png' alt='kaktuz'/></a>";
echo "<a href='buy.php?id=".$all_kaktuz['id']."'><img src='img/buy.png' alt='kaktuz'/></a>";
################################################################################
echo "</span>";
echo "</div>";
echo "<div class='aut2'>\n";
################################################################################
$chas=date("H",time());
if($chas>24){$chas=round($chas-24);}
if($chas<0){$chas=round($chas+24);}
if($chas<=4 || $chas>=23){
##########################
if($all_kaktuz['rost']<='10'){
echo '<center><table width="210" height="155" style="color: white; background-image: url(img/background.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_small_small".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
elseif($all_kaktuz['rost']>'10' && $all_kaktuz['rost']<='100'){
echo '<center><table width="210" height="155" style="color: white; background-image: url(img/background.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_small".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
elseif($all_kaktuz['rost']>'100' && $all_kaktuz['rost']<='200'){
echo '<center><table width="210" height="155" style="color: white; background-image: url(img/background.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_normal".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
elseif($all_kaktuz['rost']>'200'){
echo '<center><table width="210" height="155" style="color: white; background-image: url(img/background.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_big".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
##########################
}
if($chas>=5 && $chas<=10){
##########################
if($all_kaktuz['rost']<='10'){
echo '<center><table width="216" height="119" style="color: white; background-image: url(img/background4.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_small_small".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
elseif($all_kaktuz['rost']>'10' && $all_kaktuz['rost']<='100'){
echo '<center><table width="216" height="119" style="color: white; background-image: url(img/background4.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_small".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
elseif($all_kaktuz['rost']>'100' && $all_kaktuz['rost']<='200'){
echo '<center><table width="216" height="119" style="color: white; background-image: url(img/background4.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_normal".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
elseif($all_kaktuz['rost']>'200'){
echo '<center><table width="216" height="119" style="color: white; background-image: url(img/background4.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_big".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
##########################
}
if($chas>=11 && $chas<=17){
##########################
if($all_kaktuz['rost']<='10'){
echo '<center><table width="216" height="123" style="color: white; background-image: url(img/background3.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_small_small".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
elseif($all_kaktuz['rost']>'10' && $all_kaktuz['rost']<='100'){
echo '<center><table width="216" height="123" style="color: white; background-image: url(img/background3.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_small".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
elseif($all_kaktuz['rost']>'100' && $all_kaktuz['rost']<='200'){
echo '<center><table width="216" height="123" style="color: white; background-image: url(img/background3.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_normal".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
elseif($all_kaktuz['rost']>'200'){
echo '<center><table width="216" height="123" style="color: white; background-image: url(img/background3.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_big".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
##########################
}
if($chas>=18 && $chas<=22){
##########################
if($all_kaktuz['rost']<='10'){
echo '<center><table width="216" height="119" style="color: white; background-image: url(img/background2.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_small_small".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
elseif($all_kaktuz['rost']>'10' && $all_kaktuz['rost']<='100'){
echo '<center><table width="216" height="119" style="color: white; background-image: url(img/background2.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_small".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
elseif($all_kaktuz['rost']>'100' && $all_kaktuz['rost']<='200'){
echo '<center><table width="216" height="119" style="color: white; background-image: url(img/background2.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_normal".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
elseif($all_kaktuz['rost']>'200'){
echo '<center><table width="216" height="119" style="color: white; background-image: url(img/background2.png);" border="0">';
echo "<td valign='bottom'><img src='img/kaktuz_big".$ras."' alt='kaktuz'/><br/></td></table></center>";
}
##########################
}
echo "</div>";
echo "<div class='aut2'>\n";
echo "Высота вашего кактуса: ".$all_kaktuz['rost']." см.<br />Ему уже ".sictime(time()-$all_kaktuz['date_r'])."";
echo "</div>";




################################################################################
if($k_page>1)str('?',$k_page,$page);
################################################################################
include_once '../../sys/inc/tfoot.php';
?>