Размер файла: 2.88Kb
<?php
$int=intval($_GET['id']);
# проверим на коректность
if(!$int){
echo '<div class="ferma_menu">Пустые параметры!</div>';
echo "<div class='ferma_rekl'>";
echo "« <a href='shop_udobr.php'>Магазин удобрений</a><br/>";
echo "« <a href='index.php'>На главную</a><br/>";
echo "</div>";
foot();
exit;
}
# проверим товар
$sql=mysql_query("SELECT `id` FROM `fermer_udobr_name` WHERE `id`='$int' ");
$row=mysql_fetch_assoc($sql);
if(!mysql_num_rows($sql)){
echo '<div class="ferma_menu">Такого удобрения не существует!</div>';
echo "<div class='ferma_rekl'>";
echo "« <a href='shop_udobr.php'>Магазин удобрений</a><br/>";
echo "« <a href='index.php'>На главную</a><br/>";
echo "</div>";
foot();
exit;
}
$post = mysql_fetch_array(mysql_query("select * from `fermer_udobr_name` WHERE `id` = '$int' LIMIT 1"));
$timediff=$post['time'];
$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));
if($dayfield>0)$day=$dayfield.'д. ';
if($minutefield>0)$minutefield=$minutefield."м.";else$minutefield='';
$time_1=$day.$hourfield."ч. ".$minutefield;
echo '<div class="ferma_menu"><img src="img/udobr/ud'.$post['id'].'.png" alt="*" /> '.htmlspecialchars($post['name']).'</div>';
echo '<div class="ferma_menu"> Цена: <b> '.$post['cena'].'</b> монет</div>';
echo '<div class="ferma_menu">Сокращает на <b> '.$time_1.'</b> рост растения</div><div class="ferma_menu">';
echo "<form method='post' action='?id=".$int."&$passgen'>\n";
echo '<input type="text" name="kupit" size="4"/><input type="submit" name="save" value="Купить" />';
echo '</form>';
echo '</div>';
$kup=$post['cena']*$_POST['kupit'];
if(isset($_POST['kupit']) && $user['fermer_money']>=$kup && $_POST['kupit']>0)
{
$remils = mysql_result(mysql_query("SELECT COUNT(*) FROM `fermer_udobr` WHERE `id_user` = '$user[id]' AND `udobr` = '$int'"),0);
if($remils>0) mysql_query("UPDATE `fermer_udobr` SET `kol` = `kol`+ '".$_POST['kupit']."' WHERE `id_user` = $user[id] AND `udobr` = '$int' LIMIT 1");
else mysql_query("INSERT INTO `fermer_udobr` (`kol` , `udobr`, `id_user`) VALUES ('".$_POST['kupit']."', '".$int."', '".$user['id']."') ");
mysql_query("UPDATE `user` SET `fermer_money` = `fermer_money`- $kup WHERE `id` = $user[id] LIMIT 1");
header('Location: shop_udobr.php?buy_ok');
}
if(isset($_POST['kupit']) && strlen($_POST['kupit'])==0 || isset($_POST['kupit']) && $_POST['kupit']<1) msg("Поле не заполнено!");
if(isset($_POST['kupit']) && $user['fermer_money']<$kup)header('Location: shop_udobr.php?buy_no');
?>