battles/shop.php
2018-01-28 18:40:49 +02:00

360 lines
15 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
ob_start();
session_start();
if(!isset($_SESSION['uid'])) { header("Location: index.php"); }
include("config.php");
include("functions.php");
$d = mysql_fetch_array(mysql_query("SELECT SUM(`massa`) FROM `inventory` WHERE `owner` = '{$user['id']}' AND `dressed` = 0 AND `setsale` = 0"));
if($user['room'] != 22) { header("Location: main.php"); die(); }
if($user['battle'] != 0) { header('location: fbattle.php'); die(); }
if($_GET['sort'] == 1) {
$_SESSION['type_sort'] = 1;
} elseif($_GET['sort'] == 2) {
$_SESSION['type_sort'] = 2;
}
if($_GET['sed']) {
$dress = mysql_fetch_array(mysql_query("SELECT `id`, `name`, `cost`, `type`, `duration`, `maxdur`, `goden`, `dategoden`, `koll` FROM `inventory` WHERE `dressed` = 0 AND `id` = '".(int)$_GET['sed']."' AND `owner` = '{$user['id']}' LIMIT 1"));
$price = $dress['cost']*1;
$kols = '';
if($dress['koll']) {
$price*$dress['koll'];
$kols = '(x'.$dress['koll'].')';
}
destructitem($dress['id']);
if($dress['type'] == 12) {
$allcost = round($price*(1-$dress['duration']/$dress['maxdur']), 2);
} else {
$allcost = round($price-$dress['duration']*($dress['cost']/($dress['maxdur']*10)), 2);
}
if($dress['goden'] != 0) {
$goden_max = $dress['goden']*24*60;
$goden_left = ($dress['dategoden']-time())/60;
$per = $goden_left/$goden_max;
$allcost = round(($allcost*$per), 2);
}
$user['money'] += $allcost;
mysql_query("UPDATE `users` SET `money` = '".$user['money']."' WHERE `id` = {$user['id']} LIMIT 1");
mysql_query("INSERT INTO `delo` (`author`, `pers`, `text`, `type`, `date`) VALUES ('0', '{$user['id']}', '\"".$user['login']."\" продал в магазин товар : \"".$dress['name']."\" $kols id:(cap".$dress['id'].") [".$dress['duration']."/".$dress['maxdur']."] за ".$allcost." кр. ', '1', '".time()."')");
echo "<font color=red><b>Вы продали \"{$dress['name']}\" $kols за ".$allcost." кр.</b></font>";
}
if(($_GET['set'] || $_POST['set'])) {
if($_GET['set']) { $set = $_GET['set']; }
if($_POST['set']) { $set = $_POST['set']; }
if(!$_GET['count']) { $_GET['count'] = 1; }
if(!is_numeric($_GET['count']) || $_GET['count'] != ((int)$_GET['count'])) {
$_GET['count'] = 0;
$count_ok = 0;
} elseif($_GET['count'] < 1) {
$_GET['count'] = 0; $count_ok = 0;
} else {
$count_ok = 1;
}
$dress = mysql_fetch_array(mysql_query("SELECT * FROM `shop` WHERE `id` = '".(int)$set."' LIMIT 1"));
if($count_ok == 0) {
echo "<font color=red><b>Неправильно введено количество</b></font>";
} elseif(($dress['massa']*$_GET['count']+$d[0]) > (get_meshok())) {
echo "<font color=red><b>Недостаточно места в рюкзаке.</b></font>";
} elseif($count_ok == 1 && ($user['money'] >= ($dress['cost']*$_GET['count'])) && ($dress['count'] >= $_GET['count'])) {
if($user['first'] == 7 && ($dress['name'] == 'Короткий Готический Меч' || $dress['name'] == 'Дубина' || $dress['name'] == 'Церемониальный Топор')) {
mysql_query("UPDATE `users` SET `kwest_shop_buy` = `kwest_shop_buy`+'1' WHERE `id` = '".$user['id']."' LIMIT 1");
}
for($k = 1; $k <= $_GET['count']; $k++) {
if(mysql_query("INSERT INTO `inventory` (`prototype`,`owner`,`name`,`type`,`massa`,`cost`,`img`,`maxdur`,`isrep`,`gsila`,`glovk`,`ginta`,`gintel`,`ghp`,`gnoj`,`gtopor`,`gdubina`,`gmech`,`gfire`,`gwater`,`gair`,`gearth`,`glight`,`ggray`,`gdark`,`needident`,`nsila`,`nlovk`,`ninta`,`nintel`,`nmudra`,`nvinos`,`nnoj`,`ntopor`,`ndubina`,`nmech`,`nfire`,`nwater`,`nair`,`nearth`,`nlight`,`ngray`,`ndark`,`mfkrit`,`mfakrit`,`mfuvorot`,`mfauvorot`,`bron1`,`bron2`,`bron3`,`bron4`,`maxu`,`minu`,`magic`,`nlevel`,`nalign`,`dategoden`,`goden`,`otdel`,`gmp`,`gmeshok`,`encicl`,`artefact`,`koll`) VALUES ('{$dress['id']}','{$user['id']}','{$dress['name']}','{$dress['type']}',{$dress['massa']},{$dress['cost']},'{$dress['img']}',{$dress['maxdur']},{$dress['isrep']},'{$dress['gsila']}','{$dress['glovk']}','{$dress['ginta']}','{$dress['gintel']}','{$dress['ghp']}','{$dress['gnoj']}','{$dress['gtopor']}','{$dress['gdubina']}','{$dress['gmech']}','{$dress['gfire']}','{$dress['gwater']}','{$dress['gair']}','{$dress['gearth']}','{$dress['glight']}','{$dress['ggray']}','{$dress['gdark']}','{$dress['needident']}','{$dress['nsila']}','{$dress['nlovk']}','{$dress['ninta']}','{$dress['nintel']}','{$dress['nmudra']}','{$dress['nvinos']}','{$dress['nnoj']}','{$dress['ntopor']}','{$dress['ndubina']}','{$dress['nmech']}','{$dress['nfire']}','{$dress['nwater']}','{$dress['nair']}','{$dress['nearth']}','{$dress['nlight']}','{$dress['ngray']}','{$dress['ndark']}','{$dress['mfkrit']}','{$dress['mfakrit']}','{$dress['mfuvorot']}','{$dress['mfauvorot']}','{$dress['bron1']}','{$dress['bron2']}','{$dress['bron3']}','{$dress['bron4']}','{$dress['maxu']}','{$dress['minu']}','{$dress['magic']}','{$dress['nlevel']}','{$dress['nalign']}','".(($dress['goden'])?($dress['goden']*24*60*60+time()):"")."','{$dress['goden']}','{$dress['razdel']}','{$dress['gmp']}','{$dress['gmeshok']}','{$dress['encicl']}','{$dress['artefact']}','{$dress[koll]}')")) {
$good = 1;
} else {
$good = 0;
}
}
if($good) {
mysql_query("UPDATE `shop` SET `count` = (`count`-'".(int)$_GET['count']."') WHERE `id` = '{$set}' LIMIT 1");
echo "<font color=red><b>Вы купили {$_GET['count']} шт. \"{$dress['name']}\".</b></font>";
$user['money'] -= (int)$_GET['count']*$dress['cost'];
mysql_query("UPDATE `users` set `money` = '".$user['money']."' WHERE `id` = {$user['id']} LIMIT 1");
$limit = (int)$_GET['count'];
$invdb = mysql_query("SELECT `id` FROM `inventory` WHERE `name` = '".$dress['name']."' ORDER BY `id` DESC LIMIT ".$limit."");
if($limit == 1) {
$dressinv = mysql_fetch_array($invdb);
$dressid = "cap".$dressinv['id'];
$dresscount = " ";
} else {
$dressid = "";
while($dressinv = mysql_fetch_array($invdb)) {
$dressid .= "cap".$dressinv['id'].",";
}
$dresscount = "(x".$_GET['count'].") ";
}
$allcost = (int)$_GET['count']*$dress['cost'];
mysql_query("INSERT INTO `delo` (`author`, `pers`, `text`, `type`, `date`) VALUES ('0', '{$user['id']}', '\"".$user['login']."\" купил товар : \"".$dress['name']."\" ".$dresscount." id:(".$dressid.") [0/".$dress['maxdur']."] за ".$allcost." кр.', '1', '".time()."')");
}
} else {
echo "<font color=red><b>Недостаточно денег или нет вещей в наличии.</b></font>";
}
}
?>
<HTML>
<HEAD>
<link rel=stylesheet type="text/css" href="css/main.css">
<meta content="text/html; charset=utf-8" http-equiv=Content-type>
<META Http-Equiv=Cache-Control Content=no-cache>
<meta http-equiv=PRAGMA content=NO-CACHE>
<META Http-Equiv=Expires Content=0>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery.simplemodal.js"></script>
<script src="js/jquery.ui.js?100"></script>
<script src="js/mi.js"></script>
<link rel="stylesheet" href="css/bkstyle.css?101" />
<link rel="stylesheet" href="css/mi.css" />
<script>
function proverka(input) {
input.value = input.value.replace(/[^\d]/g, '');
}
function addCountItems(name, txt) {
new miDialog({title : 'Купить неск. штук'}, {byu : 1}, function() {
document.location = '/shop.php?'+$.param(this.data);
},
$('<div style="text-align: center;"><b>'+txt+'</b></div>').append(miDialog._oneInput({name : 'count', onkeyup : 'return proverka(this);', onchange : 'return proverka(this);'}), miDialog._hiddenInput({name : 'set', value : name})), {width : 250});
}
function check(val) {
var otdel = '<?=$_GET['otdel'];?>';
if(val == 0) {
location.href = 'shop.php?otdel='+otdel+'&sort=1';
} else if(val == 1) {
location.href = 'shop.php?otdel='+otdel+'&sort=2';
}
}
</script>
</HEAD>
<style>
.row {
font-family: Tahoma; font-size: 13px;
}
</style>
<body leftmargin=5 topmargin=5 marginwidth=5 marginheight=5 bgcolor=#d4d4d4>
<TABLE border=0 width=100% cellspacing="0" cellpadding="0">
<FORM action="city.php" method=GET>
<tr><td><h3>Государственный магазин Capital City</td><td align=right>
<INPUT TYPE="button" value="Подсказка" style="background-color:#A9AFC0" onclick="window.open('help/shop.html', 'help', 'height=300,width=500,location=no,menubar=no,status=no,toolbar=no,scrollbars=yes')">
<INPUT TYPE="submit" value="Вернуться" name="cp"></td></tr>
</FORM>
</table>
<TABLE border=0 width=100% cellspacing="0" cellpadding="4">
<TR>
<FORM METHOD=POST ACTION="shop.php">
<INPUT TYPE="hidden" name="sid" value="">
<INPUT TYPE="hidden" name="id" value="1">
<TD valign=top align=left>
<!--Магазин-->
<TABLE border=0 width=100% cellspacing="0" cellpadding="0" bgcolor="#A5A5A5">
<TR>
<TD align=center><B>Отдел "<?php
if ($_POST['sale']) {
echo "Скупка";
} else
switch ($_GET['otdel']) {
case null:
echo "Оружие: кастеты,ножи";
$_GET['otdel'] = 1;
break;
case 1:
echo "Оружие: кастеты,ножи";
break;
case 11:
echo "Оружие: топоры";
break;
case 12:
echo "Оружие: дубины,булавы";
break;
case 13:
echo "Оружие: мечи";
break;
case 14:
echo "Оружие: луки и арбалеты";
break;
case 2:
echo "Одежда: сапоги";
break;
case 21:
echo "Одежда: перчатки";
break;
case 22:
echo "Одежда: легкая броня";
break;
case 23:
echo "Одежда: тяжелая броня";
break;
case 24:
echo "Одежда: шлемы";
break;
case 3:
echo "Щиты";
break;
case 4:
echo "Ювелирные товары: серьги";
break;
case 41:
echo "Ювелирные товары: ожерелья";
break;
case 42:
echo "Ювелирные товары: кольца";
break;
case 5:
echo "Заклинания: нейтральные";
break;
case 51:
echo "Заклинания: боевые и защитные";
break;
case 6:
echo "Амуниция";
break;
case 52:
echo "Руны";
break;
}
?>"</B>
<span style="float: right; padding-right: 15px;"><select style="width: 215px;" onchange="check(this.selectedIndex);"><option value="1" <? if($_SESSION['type_sort'] == 1) { echo "selected='selected'"; } ?> onclick="location.href='shop.php?razdel=<?=$_GET['otdel'];?>&sort=1';">Показывать все вещи</option><option value="2" <? if($_SESSION['type_sort'] == 2) { echo "selected='selected'"; } ?> onclick="location.href='shop.php?razdel=<?=$_GET['otdel'];?>&sort=2';">Показывать вещи только моего уровня</option></select><br /></span>
</TD>
</TR>
<TR><TD>
<TABLE BORDER=0 WIDTH=100% CELLSPACING="1" CELLPADDING="2" BGCOLOR="#A5A5A5">
<?
if($_REQUEST['sale']) {
$data = mysql_query("SELECT * FROM `inventory` WHERE `owner` = '{$user['id']}' AND `dressed` = 0 AND `setsale` = 0 AND `cost` > 0 AND `present` = '' AND `tradesale` = 0 AND `podzem` = 0 ORDER BY `update` DESC");
while($row = mysql_fetch_array($data)) {
$row['count'] = 1;
if($i == 0) {
$i = 1; $color = '#C7C7C7';
} else {
$i = 0; $color = '#D5D5D5';
}
echo "<tr bgcolor={$color}><td align=center style='width: 150px;'><img src=\"i/sh/{$row['img']}\" border=0 />";
$price = $row['cost']*1;
if($data['koll']) {
$price*$data['koll'];
}
if($row['type'] == 12) {
$allcost = round($price*(1-$row['duration']/$row['maxdur']), 2);
} else {
$allcost = round($price-$row['duration']*($row['cost']/($row['maxdur']*10)), 2);
}
if($row['goden'] != 0) {
$goden_max = $row['goden']*24*60;
$goden_left = ($row['dategoden']-time())/60;
$per = $goden_left/$goden_max;
$allcost = round(($allcost*$per), 2);
}
?>
<br /><a href="shop.php?sed=<?=$row['id']?>&sid=&sale=1">продать за <?=$allcost?></a>
</td>
<?php
echo "<td valign=top class=\"row\">";
showitem ($row);
echo "</TD></TR>";
}
} else {
if(!isset($_SESSION['type_sort'])) {
$_SESSION['type_sort'] = 1;
$where = '';
} elseif($_SESSION['type_sort'] == 1) {
$where = '';
} elseif($_SESSION['type_sort'] == 2) {
$where = ' AND `nlevel` = "'.$user['level'].'"';
}
$arr_sort = array(11, 13, 12); #$item
$data = mysql_query("SELECT `id`, `img`, `name` FROM `shop` WHERE `count` > 0 AND `razdel` = '{$_GET['otdel']}' $where ORDER by `nlevel` ASC, `id` ASC");
while($row = mysql_fetch_array($data)) {
if ($i==0) { $i = 1; $color = '#C7C7C7';} else { $i = 0; $color = '#D5D5D5'; }
echo "<TR bgcolor={$color}><TD align=center style='width:150px'><IMG SRC=\"i/sh/{$row['img']}\" BORDER=0>";
?>
<BR><A HREF="shop.php?otdel=<?=$_GET['otdel']?>&set=<?=$row['id']?>&sid=<? echo rand(10000, 1000000);?>">купить</A>
<IMG SRC="i/up.gif" WIDTH=11 HEIGHT=11 BORDER=0 ALT="Купить несколько штук" style="cursor:hand" onclick="addCountItems('<?=$row['id']?>', '<?=$row['name']?>')"></TD>
<?php
echo "<TD valign=top>";
echo show_shop_items($row['id']);
//showitem ($row);
echo "</TD></TR>";
}
}
?>
</TABLE>
</TD></TR>
</TABLE>
</TD>
<TD valign=top width=280>
<div style="MARGIN-LEFT:15px; MARGIN-TOP: 10px;">
<CENTER><B>Масса всех ваших вещей: <?php
echo $d[0];
?>/<?=get_meshok()?><BR>
У вас в наличии: <FONT COLOR="#339900"><?=$user['money']?></FONT> кр.</B></CENTER><hr>
<INPUT TYPE="submit" value="Продать вещи" name="sale"><BR><br />
<div class="filter-title" style="padding: 3px 0px 3px 3px; background-color: #ebebeb; color: #595959; font-weight: bold;">Оружие</div>
<A HREF="shop.php?otdel=1&sid=&0.162486541405194">&nbsp;&nbsp;Кастеты, ножи</A><BR>
<A HREF="shop.php?otdel=11&sid=&0.337606814894404">&nbsp;&nbsp;Топоры</A><BR>
<A HREF="shop.php?otdel=12&sid=&0.286790872806733">&nbsp;&nbsp;Дубины, булавы</A><BR>
<A HREF="shop.php?otdel=13&sid=&0.0943516060419363">&nbsp;&nbsp;Мечи</A><BR>
<div class="filter-title" style="padding: 3px 0px 3px 3px; background-color: #ebebeb; color: #595959; font-weight: bold;">Обмундирование</div>
<A HREF="shop.php?otdel=2&sid=&0.76205958316951">&nbsp;&nbsp;Сапоги</A><BR>
<A HREF="shop.php?otdel=21&sid=&0.648260824682342">&nbsp;&nbsp;Перчатки</A><BR>
<A HREF="shop.php?otdel=22&sid=&0.520447517792988">&nbsp;&nbsp;Легкая броня</A><BR>
<A HREF="shop.php?otdel=23&sid=&0.99133839275569">&nbsp;&nbsp;Тяжелая броня</A><BR>
<A HREF="shop.php?otdel=24&sid=&0.567932791291376">&nbsp;&nbsp;Шлемы</A><BR>
<A HREF="shop.php?otdel=3&sid=&0.725667864710179">&nbsp;&nbsp;Щиты</A><BR>
<A HREF="shop.php?otdel=4&sid=&0.321709306035984">&nbsp;&nbsp;Серьги</A><BR>
<A HREF="shop.php?otdel=41&sid=&0.902093651333512">&nbsp;&nbsp;Ожерелья</A><BR>
<A HREF="shop.php?otdel=42&sid=&0.510210803380268">&nbsp;&nbsp;Кольца</A><BR>
<div class="filter-title" style="padding: 3px 0px 3px 3px; background-color: #ebebeb; color: #595959; font-weight: bold;">Заклинания</div>
<A HREF="shop.php?otdel=51&sid=&0.722009624500359">&nbsp;&nbsp;Боевые</A><BR>
<A HREF="shop.php?otdel=5&sid=&0.648834385828923">&nbsp;&nbsp;Разные</A><BR>
<div class="filter-title" style="padding: 3px 0px 3px 3px; background-color: #ebebeb; color: #595959; font-weight: bold;">Прочее</div>
<A HREF="shop.php?otdel=6&sid=&0.925798340638547">&nbsp;&nbsp;Амуниция</A><BR>
</div>
<div id="hint3" class="ahint" style="width: 305px;"></div>
</TD>
</FORM>
</TR>
</TABLE>
</BODY>
</HTML>