Размер файла: 6.47Kb
<?php
$set['title']='Ферма!';
include_once ('sys/index.php');
head($set['title']);
if(isset($user)){
$int=intval($_GET['id']);
# проверим на коректность
if(!$int){
echo '<div class="ferma_menu">Пустые параметры!</div>';
echo "<div class='ferma_rekl'>";
echo "« <a href='fermers.php'>Фермеры</a><br/>";
echo "« <a href='index.php'>На главную</a><br/>";
echo "</div>";
foot();
exit;
}
# проверим товар
$sql=mysql_query("SELECT `id` FROM `user` 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='fermers.php'>Фермеры</a><br/>";
echo "« <a href='index.php'>На главную</a><br/>";
echo "</div>";
foot();
exit;
}
if($int==$user['id'])header('Location: my.php');
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id`='$int' LIMIT 1"));
if(isset($_GET['vor'])){
$vor=intval($_GET['vor']);
# проверим на коректность
if(!$vor){
echo '<div class="ferma_menu">Пустые параметры!</div>';
echo "<div class='ferma_rekl'>";
echo "« <a href='fermers.php'>Фермеры</a><br/>";
echo "« <a href='index.php'>На главную</a><br/>";
echo "</div>";
foot();
exit;
}
# проверим товар
$sql=mysql_query("SELECT `id` FROM `fermer_gr` WHERE `id`='$vor' ");
$row=mysql_fetch_assoc($sql);
if(!mysql_num_rows($sql)){
echo '<div class="ferma_menu">Нет такой грядки.</div>';
echo "<div class='ferma_rekl'>";
echo "« <a href='fermers.php'>Фермеры</a><br/>";
echo "« <a href='index.php'>На главную</a><br/>";
echo "</div>";
foot();
exit;
}
$gr = mysql_fetch_array(mysql_query("select * from `fermer_gr` WHERE `id` ='$vor' "));
$semen = mysql_fetch_array(mysql_query("select * from `fermer_name` WHERE `id` = '$gr[semen]' "));
$qi = mysql_fetch_assoc(mysql_query("SELECT * FROM `fermer_vor` WHERE `id_user` = '$user[id]' AND `gr` = '$vor' LIMIT 1"));
if($qi['time']<$time){
$rand1=floor($semen['rand1']/5);
$rand2=floor($semen['rand2']/5);
$rand=rand($rand1,$rand2);
$dog=mysql_fetch_array(mysql_query("select * from `fermer_dog` WHERE `id_user` = '$ank[id]' "));
if($dog['time']<$time){
$t=$time+86400;
mysql_query("INSERT INTO `fermer_vor` (`id_user` , `gr`, `time`) VALUES ('".$user['id']."', '".$vor."', '".$t."') ");
mysql_query("UPDATE `user` SET `fermer_oput` = `fermer_karma`- '1' WHERE `id` = $user[id] LIMIT 1");
if($gr['kol']>$rand){
mysql_query("UPDATE `fermer_gr` SET `kol` = `kol`- $rand WHERE `id` = $vor LIMIT 1");
$remils = mysql_result(mysql_query("SELECT COUNT(*) FROM `fermer_sclad` WHERE `id_user` = '$user[id]' AND `semen` = '$gr[semen]'"),0);
if($remils>0) mysql_query("UPDATE `fermer_sclad` SET `kol` = `kol`+ '".$rand."' WHERE `id_user` = $user[id] AND `semen` = '$gr[semen]' LIMIT 1");
else mysql_query("INSERT INTO `fermer_sclad` (`kol` , `semen`, `id_user`) VALUES ('".$rand."', '".$gr['semen']."', '".$user['id']."') ");
}else{
$rand=mysql_result(mysql_query("SELECT `kol` FROM `fermer_gr` WHERE `id` = $_GET[vor] "),0);
mysql_query("UPDATE `fermer_gr` SET `semen` = '0' WHERE `id` = $vor LIMIT 1");
mysql_query("UPDATE `fermer_gr` SET `time` = NULL WHERE `id` = $vor LIMIT 1");
mysql_query("UPDATE `fermer_gr` SET `kol` = NULL WHERE `id` = $vor LIMIT 1");
$remils = mysql_result(mysql_query("SELECT COUNT(*) FROM `fermer_sclad` WHERE `id_user` = '$user[id]' AND `semen` = '$gr[semen]'"),0);
if($remils>0) mysql_query("UPDATE `fermer_sclad` SET `kol` = `kol`+ '".$rand."' WHERE `id_user` = $user[id] AND `semen` = '$gr[semen]' LIMIT 1");
else mysql_query("INSERT INTO `fermer_sclad` (`kol` , `semen`, `id_user`) VALUES ('".$rand."', '".$gr['semen']."', '".$user['id']."') ");
}
msg('Украдено '.$rand.'!');
}else{
$rand=rand(1,100);
mysql_query("UPDATE `user` SET `fermer_money` = `fermer_money` - $rand WHERE `id` = $user[id] LIMIT 1");
mysql_query("UPDATE `user` SET `fermer_money` = `fermer_money` + $rand WHERE `id` = $ank[id] LIMIT 1");
echo '<div class="err">На вас напала собака фермера! При побеге вы потеряли '.$rand.' монет!</div>';
echo "<div class='ferma_rekl'>";
echo "« <a href='fermers.php'>Фермеры</a><br/>";
echo "« <a href='index.php'>На главную</a><br/>";
echo "</div>";
foot();
exit;
}
}else{echo "<div class='err'>С этой грядки больше воровать нелзя!!!</div>";}
}
$k=mysql_result(mysql_query("SELECT COUNT(*) FROM `fermer_gr` WHERE `id_user` = '".$int."'"),0);
$k_page = ceil($k / $SET['p_str']);
$page = page();
$start=$SET['p_str']*$page-$SET['p_str'];
$res = mysql_query("select * from `fermer_gr` WHERE `id_user` = '".$int."' LIMIT $start, $SET[p_str];");
echo'<div class="ferma_menu"><img src="/img/neighbors.gif"/></div>';
while ($post = mysql_fetch_array($res)){
$p = mysql_fetch_array(mysql_query("select * from `fermer_gr` WHERE `id` = '$post[id]' LIMIT 1"));
if($p['semen']!=0 && $time>$p['time'] && $p['kol']==0)
{
$pt=rand($semen['rand1'],$semen['rand2']);
if($post['woter']==0)$pt=floor($pt/2);
mysql_query("UPDATE `fermer_gr` SET `kol` = $pt WHERE `id` = '$post[id]' LIMIT 1");
}
$semen=mysql_fetch_array(mysql_query("select * from `fermer_name` WHERE `id` = '$post[semen]' LIMIT 1"));
if($post['semen']==0){$name_gr='Пустая грядка';}else{$name_gr=$semen['name'];}
echo '<div class="ferma_menu"><img src="img/product/'.$post['semen'].'.jpg" alt="*" class="portrait"/> <span class="oil">'.htmlspecialchars($name_gr).'</span><br/>
';
if($post['semen']==0) echo'<br/>';
if($post['semen']!=0 && $post['time']<$time){
echo "Количество: ".$post['kol']."<br/>";
$qi = mysql_fetch_array(mysql_query("SELECT * FROM `fermer_vor` WHERE `id_user` = '$user[id]' AND `gr` = '$post[id]' LIMIT 1"));
if($qi['time']<$time)
echo "<img src=\"img/icon/harvest.png\" alt=\"*\" /><a href='?id=".$int."&vor=".$post['id']."'>Воровать!</a>";
}else{if($post['semen']!=0)echo "Созревает<br/>";}
echo '<br/></div>';
}
if ($k_page>1)str('fermer_gr.php?id='.$int.'&',$k_page,$page);
echo "<div class='ferma_rekl'>";
echo "« <a href='fermers.php'>Фермеры</a><br/>";
echo "« <a href='index.php'>На главную</a><br/>";
echo "</div>";
}else{
msg('Только для авторизованых пользователей!');
echo "<div class='ferma_rekl'>";
echo "« <a href='index.php'>На главную</a><br/>";
echo "</div>";
}
foot();
?>