<?php
function buyupdate() { // liste des updates a acheter
global $userrow,$numqueries;
$townquery = doquery("SELECT name,itemslistm FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns");
$townrow = mysql_fetch_array($townquery);
$marchelist = explode(",",$townrow["itemslistm"]);
$querystring = "";
foreach($marchelist as $a=>$b) {
$querystring .= "id='$b' OR ";
}
$querystring = rtrim($querystring, " OR ");
$marchequery = doquery("SELECT * FROM {{table}} WHERE $querystring ORDER BY id", "marche");
$page = "<center><img src=\"././images/kaede1.gif\"/></center> <br />";
$page.="<center>Presentation des objet en vente ici :</center><br>";
while ($marcherow = mysql_fetch_array($marchequery)) {
$selection.= "<option value=\"".$marcherow["id"]."\">".$marcherow["name"]."</option>";
$page.="<br><b>Nom </b>: ".$marcherow["name"]."<b> Prix unitaire</b> : ".$marcherow["prix"]."<br>
<b>Description</b> : ".$marcherow["description"]."<br><br>";
}
$page.="<br><form method=\"post\" action=\"index.php?do=buyupdate2\">";
$page.="objet à acheter : <select name=\"nom\">$selection</select>
Qantité<select name=\"nbs\"><option value=\"1\">1</option><option value=\"5\">5</option>
<option value=\"10\">10</option><option value=\"20\">20</option><option value=\"40\">40</option>
<option value=\"50\">50</option><option value=\"60\">60</option>
<option value=\"70\">70</option><option value=\"80\">80</option></select>
<input type=\"submit\" name=\"submit\" value=\"Acheter\"/>
<br>";
$page.="</form>
";
$page .= "<br><br>Si vous avez changé d'avis, vous pouvez également <a href=\"index.php\">retourner à la ville</a>.\n";
$title = "Acheter des objets";
display($page, $title);
}
function buyupdate2() { // Confirm user's intent to purchase item.
global $userrow, $numqueries;
if (isset($_POST["submit"])) {
extract($_POST);
$errors = 0;
$errorlist = "";
$marchequery = doquery("SELECT * FROM {{table}} WHERE id='$nom' LIMIT 1", "marche");
$marcherow = mysql_fetch_array($marchequery);
$prix = ($marcherow["prix"]*$nbs);
if ($prix>>$userrow['gold']){$errors++; $errorlist .= "Vous ne disposer pas d'assez d'argent.<br />";}
if ($errors == 0) {
if ($marcherow["type"] == "exp") {
$page = "<img src=\"././images/kaede3.gif\"/><br>Vous allez acheter ".$marcherow["name"]." pour $prix, vous êtes d'accord?<br /><br /><form action=\"index.php?do=buyupdate3:".$marcherow["id"].":$nbs\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Oui\" /> <input type=\"submit\" name=\"cancel\" value=\"Non\" /></form>";
} elseif ($marcherow["type"] == "mp") {
$page = "<img src=\"././images/kaede3.gif\"/><br>Vous allez acheter ".$marcherow["name"]." pour $prix , vous êtes d'accord?<br /><br /><form action=\"index.php?do=buyupdate3:".$marcherow["id"].":$nbs\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Oui\" /> <input type=\"submit\" name=\"cancel\" value=\"Non\" /></form>";
} elseif ($marcherow["type"] == "hp") {
$page = "<img src=\"././images/kaede3.gif\"/><br>Vous allez acheter ".$marcherow["name"]." pour $prix, vous êtes d'accord?<br /><br /><form action=\"index.php?do=buyupdate3:".$marcherow["id"].":$nbs\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Oui\" /> <input type=\"submit\" name=\"cancel\" value=\"Non\" /></form>";
} elseif ($marcherow["type"] == "tp") {
$page = "<img src=\"././images/kaede3.gif\"/><br>Vous allez acheter ".$marcherow["name"]." pour $prix, vous êtes d'accord?<br /><br /><form action=\"index.php?do=buyupdate3:".$marcherow["id"].":$nbs\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Oui\" /> <input type=\"submit\" name=\"cancel\" value=\"Non\" /></form>";
}
}
}
$title = "Acheter objets";
display($page, $title);
}
function buyupdate3($id,$nbs) { // Update user profile with new item & stats.
if (isset($_POST["cancel"])) { header("Location: index.php"); die(); }
global $userrow;
$marchequery = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "marche");
$marcherow = mysql_fetch_array($marchequery);
$prix = ($marcherow["prix"]*$nbs);
if ($userrow["gold"] < $prix) { display("<img src=\"././images/kaede2.gif\"/><br /><br />Vous pouvez <a href=\"index.php\">retourner à la ville</a>, <a href=\"index.php?do=buyupdate\">au magasin</a>, ou utiliser les boutons directionnel de gauche pour continuer à explorer le monde.", "Acheter objets"); die(); }
if ($marcherow["type"] == "exp") { //experience++
// New stats.
$newgold = $userrow["gold"] - $marcherow["prix"]*$nbs;
$newexp = $userrow["experience"] + $marcherow["attribute"]*$nbs;
// Final update.
$updatequery = doquery("UPDATE {{table}} SET gold='$newgold', experience='$newexp' WHERE id='".$userrow["id"]."'", "users");
} elseif ($marcherow["type"] == "mp") { // Armor
// New stats.
$newgold = $userrow["gold"] - $marcherow["prix"]*$nbs;
$newmp = $userrow["maxmp"] + $marcherow["attribute"]*$nbs;
// Final update.
$updatequery = doquery("UPDATE {{table}} SET gold='$newgold', maxmp='$newmp' WHERE id='".$userrow["id"]."'", "users");
} elseif ($marcherow["type"] == "hp") { // Shield
// New stats.
$newgold = $userrow["gold"] - $marcherow["prix"]*$nbs;
$newhp = $userrow["maxhp"] + $marcherow["attribute"]*$nbs;
// Final update.
$updatequery = doquery("UPDATE {{table}} SET gold='$newgold', maxhp='$newhp' WHERE id='".$userrow["id"]."'", "users");
} elseif ($marcherow["type"] == "tp") { // Armor
// New stats.
$newgold = $userrow["gold"] - $marcherow["prix"]*$nbs;
$newtp = $userrow["maxtp"] + $marcherow["attribute"]*$nbs;
// Final update.
$updatequery = doquery("UPDATE {{table}} SET gold='$newgold', maxtp='$newtp' WHERE id='".$userrow["id"]."'", "users");
}
display("<img src=\"././images/kaede4.gif\"/><br /><br />Vous pouvez maintenant <a href=\"index.php\">retourner à la ville</a>, <a href=\"index.php?do=buyupdate\">au magasin</a>, ou utiliser les boutons directionnel de gauche pour continuer à explorer le monde.", "Acheter objets");
}