<?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) || !isset($_GET['id'])){
  header("Location:/index.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="$hourfield ч. $minutefield м. $secondfield ";
return $time_1;
}
$id=abs(intval($_GET['id']));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kaktuz` WHERE `id_u`='".$user['id']."' AND `id`='".$id."'"),0)!='0'){
  $prov=mysql_result(mysql_query("SELECT `time_p` FROM `kaktuz` WHERE `id`='".$id."'"),0);
  if($prov<=time()){
    $rand=rand(1,2);
    $r_rand=rand(1,9);
    $ntime=time()+43200;
    $podros="".$rand.".".$r_rand."";
     mysql_query("UPDATE `kaktuz` SET `rost`=`rost`+$podros, `time_p`=".$ntime." WHERE `id`='".$id."' LIMIT 1");
     echo "Вы успешно полили кактус! Ваш кактус подрос на ".$podros." см.<br/><a href='index.php'>Назад</a><br/>";
  }
  else
  {
    $sic=$prov-time();
    echo "Вы не можете так часто поливать кактус! Следуйщий полив будет доступен через ".sictime($sic)."<br/><a href='index.php'>Назад</a><br/>";
  }
  
}
else
{
  echo 'аяяй!';
}


include_once '../sys/inc/tfoot.php';
?>