Файл: inc/center/factory.php
Строк: 75
<?
$title='Заводы';
include_once '../system/config.php';
$req_set= mysql_query("SELECT * FROM `set_bonus` WHERE `id` = '1'");
$set = mysql_fetch_array($req_set);
// if($ku['id']!=1 && $ku['id']!=1351) include '../system/foot.php';
$__factories = array('Ателье','Завод Суши','Мясная Лавка','Завод Кормов','Соевый Завод','Пиццерия','Салон Красоты','Фабрика Соусов','Фабрика Напитков','Мельница');
$__max_factories=20;
$__work_time=300;
$q; $_FIELD_NUM; $_TIME = time();
function rq(){
global $q, $_FIELD_NUM, $ku; $q = mysql_query("SELECT * FROM factory WHERE user=".(isset($_GET['user'])?intval($_GET['user']):$ku['id'])); $_FIELD_NUM=mysql_num_rows($q); return $_FIELD_NUM;
}
function top($title = "Завод"){ echo "<div class='rzd2'></div><div class='menuin2'><div class='title'>".$title."</div><div class='content'><div class='div'>"; }
rq();
if($_FIELD_NUM == 0){
mysql_query("INSERT INTO factory (user) VALUES (".$ku['id'].")"); rq();
}
/*--------------*/
if(!isset($_GET['user'])){
if(isset($_GET['startBuild'])){
$id=intval($_GET['startBuild']);
$sel = intval($_GET['ok']);
if(isset($_GET['ok']) && $sel>0 && $sel<=count($__factories)){
$nlvl = 10 * $sel;
if($set['time_zavod'] > time()){
if($ku['boy_rubies'] >= $set['kol_rubine_zavod']){
$minus = (100 * $sel)/100*$set['bonus_zavod'];
}
}else{
$minus = 0;
}
$price = 100 * $sel-$minus;
if($ku['level']>$nlvl){
if($ku['rubies'] >= $price){
mysql_query("UPDATE factory SET time=".($_TIME + 3600 * $sel).", type=".$sel.", built=0 WHERE user=".$ku['id']." and id=".$id);
if(mysql_affected_rows()>0){
mysql_query("UPDATE kolhoz_user SET rubies=".($ku['rubies']-$price)." WHERE id=".$ku['id']);
header("Location:/factory"); exit;
}
}else err_game("Недостаточно рубинов!");
}else err_game("Вам необходимо дойти до ".$nlvl." уровня!");
}else{
top("Выберите завод");
foreach ($__factories as $i => $value) {
echo "<img src='img/factory/".($i+1)."_1.png' class='portrait' width='52'> <b>".$value."</b><br>Доступен с ".(++$i*10)." ур., прибыль: ".($i*1)." <img src='img/icons/ruby.png'><br><a href='factory/startBuild/".$id."/ok/".$i."'>[купить] за ".($set['time_zavod'] > time() ? ($ku['boy_rubies'] >= $set['kol_rubine_zavod'] ? ((100*$i)-(100*$i)/100*$set['bonus_zavod']) : (100*$i)) : (100*$i))." <img src='img/icons/ruby.png'></a><div style='clear:both'></div>";
}
echo "</div></div></div><div class='rzd2'></div>"; include_once '../system/foot.php';
}
}elseif(isset($_GET['buyPlace'])){
if(isset($_GET['ok']) && $_FIELD_NUM < $__max_factories){
$price = 100 * ($_FIELD_NUM+1);
if($ku['rubies']>=$price){
mysql_query("UPDATE kolhoz_user SET rubies=".($ku['rubies']-$price)." WHERE id=".$ku['id']);
mysql_query("INSERT INTO factory (user) VALUES (".$ku['id'].")");
$_SESSION['factory_buyPlace']=$price;
header("Location:/factory"); exit;
}else err_game("Недостаточно рубинов!");
}else{
podtv("factory/buyPlace/ok", "factory"); echo "</div></div></div><div class='rzd2'></div>"; include_once '../system/foot.php';
}
}elseif(isset($_GET['start'])){
mysql_query("UPDATE factory SET time=".($_TIME + $__work_time).", built=1 WHERE built=0 and type>0 and user=".$ku['id']." and id=".intval($_GET['start']));
header("Location:/factory"); exit;
}elseif(isset($_GET['profit'])){
$id = intval($_GET['profit']);
$sf = mysql_result(mysql_query("SELECT type FROM factory WHERE time<".$_TIME." and built=1 and user=".$ku['id']." and id=".$id), 0);
if($sf>0){
$_SESSION['factory_profit']=$sf*1;
$req = mysql_query("SELECT `type` FROM `factory` WHERE `id` = '$id'");
$zav = mysql_fetch_array($req);
if($zav['type'] == 1){
$__work_time = 300;
}elseif($zav['type'] == 2){
$__work_time = 1200;
}elseif($zav['type'] == 3){
$__work_time = 2100;
}elseif($zav['type'] == 4){
$__work_time = 3000;
}elseif($zav['type'] == 5){
$__work_time = 3780;
}elseif($zav['type'] == 6){
$__work_time = 4320;
}elseif($zav['type'] == 7){
$__work_time = 4860;
}elseif($zav['type'] == 8){
$__work_time = 5400;
}elseif($zav['type'] == 9){
$__work_time = 7380;
}elseif($zav['type'] == 10){
$__work_time = 7920;
}
mysql_query("UPDATE kolhoz_user SET rubies=".($ku['rubies']+$_SESSION['factory_profit'])." WHERE id=".$ku['id']);
mysql_query("UPDATE factory SET time=".($_TIME + $__work_time)." WHERE id=".$id);
}
header("Location:/factory"); exit;
}elseif(isset($_GET['sell'])){
$id = intval($_GET['sell']);
if(isset($_GET['ok'])){
$sf = mysql_result(mysql_query("SELECT type FROM factory WHERE built=1 and user=".$ku['id']." and id=".$id), 0);
if($sf>0){
$_SESSION['factory_profit']=50*$sf;
mysql_query("UPDATE kolhoz_user SET rubies=".($ku['rubies']+$_SESSION['factory_profit'])." WHERE id=".$ku['id']);
mysql_query("UPDATE factory SET built=0, time=0, type=0 WHERE id=".$id);
}
header("Location:/factory"); exit;
}else{
podtv("factory/sell/".$id."/ok", "factory/");
echo "</div></div></div><div class='rzd2'></div>"; include_once '../system/foot.php';
}
}
}
/*--------------*/
if(isset($_SESSION['factory_buyPlace'])){ msg_game("Снято ".$_SESSION['factory_buyPlace']." рубинов"); unset($_SESSION['factory_buyPlace']); }
if(isset($_SESSION['factory_profit'])){ msg_game("Получено ".$_SESSION['factory_profit']." рубинов"); unset($_SESSION['factory_profit']); }
top();
while($get = mysql_fetch_assoc($q)){
$get['state']=($get['type']==0 ? 0 : ($get['built']==0 ? ($get['time'] > $_TIME ? 1 : 2) : 3));
// 0 - нет ничего, 1 - строим, 2 - необходимо подтвердить окончание строения, 3 - готов к работе
echo "<img src='img/factory/".($get['state']==0?"0":($get['state']==1?$get['type']:$get['type']."_1")).".png' class='portrait' width='48'>";
if($get['type']>0) echo "<b>".$__factories[$get['type']-1]."</b><br>";
if($get['state']==1) echo "Строительство будет завершено через ".time_left($get['time']-$_TIME);
elseif(!isset($_GET['user'])){
if($get['state']==0) echo "<a href='factory/startBuild/".$get['id']."'><img src='icon/building.png'> Начать строительство</a>";
elseif($get['state']==2) echo "<a href='factory/start/".$get['id']."'><img src='icon/power.png'> Запустить завод</a>";
elseif($get['state']==3){
if($get['time']>$_TIME) echo "Ожидайте прибыль ".time_left($get['time']-$_TIME);
else echo "<a href='/factory/profit/".$get['id']."'><img src='icon/profit.png'> Получить прибыль</a>";
echo "<br><a href='/factory/sell/".$get['id']."'>[продать]</a>";
}
}
echo "<div style='clear:both'></div>";
}
if($_FIELD_NUM==0) echo "Нет заводов...";
if($_FIELD_NUM < $__max_factories && !isset($_GET['user'])) echo "<br><a href='/factory/buyPlace'><img src='icon/box.png'> Купить новое место за ".number_format(100 * ($_FIELD_NUM+1))." <img src='img/icons/ruby.png'></a>";
echo "</div></div></div><div class='rzd2'></div>"; include_once '../system/foot.php';
?>