<?PHP
$include = 1;
$needed_rang = 2;
include("protection.php");
require("./global.php");
if($_GET['interface'] == "vendor") {
$vendoroption = $db->query_first("SELECT * FROM vendors WHERE id='$_GET[vendorid]'");
if($vendoroption[mapid] == "$user[map]") {
echo "<div id='vendorwindow' style='position:absolute;top:0px;z-index:99;left:0px;height:360px;width:200px;opacity:0.8;filter:Alpha(opacity=80, finishopacity=80, style=3);background-color:#ffffff;overflow:auto;'>
<img align='right' src='images/exit.gif' onclick=\"hide('vendorwindow');\">
<hr>";
if($_GET['mode'] == "browse") {
echo "<table style='width:100%;border:0px;'>";
$vendors_item = mysql_query("SELECT * FROM vendor_items WHERE vendorid='$_GET[vendorid]'");
while ($row = mysql_fetch_array ($vendors_item)) {
$item = $db->query_first("SELECT * FROM items WHERE id='$row[itemid]'");
$iteminfo = "<b>$item[name]</b>";
if($item['class'] == "1")
$iteminfo .= "<br>Waffe";
if($item['class'] == "2")
$iteminfo .= "<br>Schuhe";
if($item['class'] == "3")
$iteminfo .= "<br>Brustschutz";
if($item['class'] == "4")
$iteminfo .= "<br>Kopfbedekung";
if($item['class'] == "5")
$iteminfo .= "<br>Schmuck";
if($item[dmg_min]>0 OR $item[dmg_max]>0)
$iteminfo .= "<br>$item[dmg_min] - $item[dmg_max] Schaden";
if($item[armor]>0)
$iteminfo .= "<br>$item[armor] Ruestung";
if($item[description] !== "")
$iteminfo .= "</font><br><table border=0 width=250><tr><td><font color=00CC00 size=2>$item[description]</font></td></tr></table><font color=FFFFFF>";
$money=$item['price'];
$platin=0; $silber=0; $gold=0;
$money2 = "";
$silber=$money%100;
$gold=(($money-$silber)/100)%100;
$platin=($money-$silber-$gold*100)/10000;
if($money>=10000)
$money2 = "".$platin." Platin ";
if($money>=100)
$money2 .= "".$gold." Gold ";
if($money>0)
$money2 .= " ".$silber." Silber";
else
$money2 = "Kostenlos";
echo "<tr onclick=\"hideddrivetip();include('interface.php?interface=vendor&mode=buy&mode2=ask&vendorid=".$_GET[vendorid]."&vendoritemid=".$row[id]."','include');\"><td bgcolor='#E5E5E5' onmouseover=\"ddrivetip('<font color=000000>$iteminfo</font>')\" onmouseout=\"hideddrivetip()\"><center><img src='images/itemicons/$item[icon]' border='0'></center></td><td onmouseover=\"ddrivetip('<font color=000000>$iteminfo</font>')\" onmouseout=\"hideddrivetip()\"><font size='2'>$item[name]</font></td><td align='center' class='menue_02'><img onmouseover=\"ddrivetip('<font color=000000><b>Preis</b><br>$money2</font>')\" onmouseout=\"hideddrivetip()\" src='images/itemicons/money.gif' alt='Preis'></td></tr>";
}
echo "</table>";
} elseif($_GET['mode'] == "buy") {
$vendoritem = $db->query_first("SELECT itemid FROM vendor_items WHERE id='$_GET[vendoritemid]' AND vendorid='$_GET[vendorid]'");
$item = $db->query_first("SELECT name,price FROM items WHERE id='$vendoritem[itemid]'");
$money=$item['price'];
$platin=0; $silber=0; $gold=0;
$money2 = "";
$silber=$money%100;
$gold=(($money-$silber)/100)%100;
$platin=($money-$silber-$gold*100)/10000;
if($money>=10000)
$money2 = "".$platin." Platin ";
if($money>=100)
$money2 .= "".$gold." Gold ";
if($money>0)
$money2 .= " ".$silber." Silber";
else
$money2 = "Nichts";
if($_GET['mode2'] == "ask")
echo "Willst Du wirklich das Item \"<i>".$item[name]."</i>\" zum Preis von \"<i>$money2</i>\" kaufen?<br>
<button onclick=\"include('interface.php?interface=vendor&mode=buy&mode2=buy&vendorid=".$_GET[vendorid]."&vendoritemid=".$_GET[vendoritemid]."','include');mapstateinclude();\">Ja</button><button onclick=\"include('interface.php?interface=vendor&mode=browse&vendorid=".$_GET[vendorid]."','include');\">Nein</button>";
if($_GET['mode2'] == "buy") {
if($item['price']>$user['money']) {
echo "Du hast leider nicht genug Geld um \"".$item[name]."\" zu kaufen!";
} else {
$useritem = $db->query_first("SELECT id FROM user_items WHERE itemid='$vendoritem[itemid]' AND userid='$user[id]'");
if($useritem['id']>0)
$db->query("UPDATE user_items SET pieces=pieces+1 WHERE id='$useritem[id]'");
else
$db->query("INSERT INTO `user_items` (`userid`,`itemid`,`pieces`) VALUES ('$user[id]','$vendoritem[itemid]','1')");
$db->query("UPDATE user SET money=money-$item[price] WHERE id='$user[id]'");
echo "<i>Du hast das Item erfolgreich gekauft. Es befindet sich nun in deinem Inventar.</i>";
echo "<body onload=\"mapstateinclude();\"></body>";
}
}
}
echo "</div>";
} else {
echo "<div id='vendorwindow' style='position:absolute;top:0px;z-index:99;left:0px;height:360px;width:200px;opacity:0.8;filter:Alpha(opacity=80, finishopacity=80, style=3);background-color:#ffffff;overflow:auto;'><img align='right' src='images/exit.gif' onclick=\"hide('vendorwindow');\"><hr>
<br>Du darfst den Ort nicht verlassen, in dem Du den Verkaeufer angeklickt hast, um mit ihm zu handeln. Haendler haben immer die Kategorie der Items, die diese anbieten in gruener Schrift ueber dem Personenbild.</div>";
}
}
?>