(sorry for not having translated the script in english, but I think is quite understandable)
- Code: Select all
<?
include "header.php";
include_once "class_character.php";
include_once "items.php";
session_start();
isset($_SESSION['check']) ? $check = $_SESSION['check'] : $check = '';
$refsidebar= false;
// clear out any bad database rows
mysql_query("DELETE FROM phaos_char_inventory WHERE item_id='' AND type='' ");
$character=new character($PHP_PHAOS_CHARID);
include_once "location_actions.php";
$dropped= drop_actions($character);
if($refsidebar){
refsidebar();
$refsidebar= false;
}
?>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr>
<td align=center colspan=2>
<big><b><? echo $lang_char["invent"]; ?></b></big>
<br>
<br><a name="inventory"><font color="#FFFFFF">Ordina:</font></a>
<br>
<a href="rigattiere.php">Tutto</a>
| <a href="rigattiere.php?act=weapon#inventory">Armi</a>
| <a href="rigattiere.php?act=armor#inventory">Armature</a>
| <a href="rigattiere.php?act=boots#inventory">Stivali</a>
| <a href="rigattiere.php?act=gloves#inventory">Guanti</a>
| <a href="rigattiere.php?act=helm#inventory">Elmi</a>
| <a href="rigattiere.php?act=shield#inventory">Scudi</a>
| <a href="rigattiere.php?act=potion#inventory">Pozioni</a>
| <a href="rigattiere.php?act=spell_items#inventory">Incantesimi</a>
<table border=0 cellspacing=0 cellpadding=0>
<?php
$wheretype= "";
$item_type= @$_GET['act'];
if(isItemType($item_type)){
$wheretype= " AND type = '$item_type' ";
}
//!PS: be careful with this code, it took some time to write
$items= array();
$list_inventory = mysql_query("SELECT * FROM phaos_char_inventory WHERE username = '$_COOKIE[PHP_PHAOS_USER]' $wheretype ORDER BY type ASC, item_id ASC");
if($list_inventory) {
while ($row = mysql_fetch_assoc($list_inventory)) {
$items[]= $row;
}
$items[]= null;// add an extra empty row to trigger routput
}
if(count($items)>1) {
?>
<tr style="background:#004400;">
<td align=center valign=top><b><? echo $lang_char["amount"]; ?>  </b></td>
<td> </td>
<td valign=top><b><? echo $lang_char["desc"]; ?>  </b></td>
<td align=center valign=top></td>
<td align=center valign=top colspan=3><b>Action  </b></td>
</tr>
<?
}
//end if show header
// begin output loop
$lastrow= null;
$output= null;
foreach($items as $row) {
if($row) {
$id = $row["id"];
$equiped = $row["equiped"];
$item_type = $row["type"];
$item_id = $row["item_id"];
$sell_to_name = $row["sell_to"];
$ask_price = $row["asking_price"];
if(!@$_GET['act'] || $_GET['act'] == $item_type || $_GET['act'] == $item_type.'s' || $_GET['act'].'s' == $item_type) {
if($lastrow && $row['item_id'] == $lastrow['item_id'] && $row['equiped'] == $lastrow['equiped'] && $row['type'] == $lastrow['type'] && $row['sell_to'] == $lastrow['sell_to'] && $row['asking_price'] == $lastrow['asking_price']) {
++$lastrow['itemcount'];
$output= null;
} else {
$output= $lastrow;
$lastrow= $row;
$lastrow['itemcount']= 1;
}
} else {
//ignore item
}
} else {
$output= $lastrow;
}
if(!$output){
//no output
continue;
} else {
$id = $output["id"];
$equiped = $output["equiped"];
$item_type = $output["type"];
$item_id = $output["item_id"];
$sell_to_name = $output["sell_to"];
$ask_price = $output["asking_price"];
$info= fetch_item_additional_info(array('id'=>$item_id,'type'=>$item_type,'number'=>1),&$character);
$description = $info['description'];
$sell_price = $info['sell_price'];
$image_path= $info['image_path'];
$skill_req= $info['skill_req'];
$damage_mess= @$info['damage_mess'];
$skill_need= $info['skill_need'];
$effect= $info['effect'];
$skill_type= $info['skill_type'];
$caso = microtime();
//Calcola Prezzo
$price = intval(($sell_price / 100) * 30);
// start outputting a row
print ("<tr>");
print ("<td align=center valign=top><b>$output[itemcount]</b>x</td>");
?><td align=center valign=top><?= makeImg($image_path) ?></td><?php
print "<td>".ucwords($description)." <br>";
print "Offerta: $price mo";
print ("<p>
<td align=center colspan=7 valign=top>
<form method=\"post\" action=\"rigattiere.php\">
<input type=\"submit\" value=\"Vendi\">
<input type=\"hidden\" name=\"rigattiere\" value=\"yes\">
<input type=\"hidden\" name=\"char_inv_id\" value=\"$id\">
<input type=\"hidden\" name=\"price\" value=\"$price\">
<input type=\"hidden\" name=\"type\" value=\"$item_type\">
<input type =\"hidden\" name = \"check\" value = \"$caso\">
</form>
</td>");
?></tr><?php
?><tr><td colspan="8"><hr width=50%></td></tr><?php
}
// end out put a row
}
// end loop
if($check === MD5(serialize($_POST)) )
{
print "<tr><td align=center colspan=4><b>Ehi! Stai tentando di fregarmi?</b></td></tr>";
exit;
} else {
if(@$_POST['rigattiere'] == "yes")
{
$prezzo_vendita = $_POST['price'];
$tipo_oggetto = $_POST['type'];
$id_oggetto = $_POST['char_inv_id'];
print "<tr><td align=center colspan=4><b> Hai venduto questo oggetto per $prezzo_vendita mo </b><br></td></tr>";
$query = ("UPDATE phaos_characters SET gold = gold +".$prezzo_vendita." WHERE username = '".$PHP_PHAOS_USER."'");
$req = mysql_query($query);
if (!$req) {
echo "<B>Error ".mysql_errno()." :</B> ".mysql_error().""; exit;
}
$req = mysql_query("DELETE FROM phaos_char_inventory WHERE id=$id_oggetto");
if (!$req) {
showError(__FILE__,__LINE__,__FUNCTION__); exit;
}
?>
<script language="JavaScript">
<!--
javascript:parent.side_bar.location.reload();
javascript:window.location.reload();
//-->
</script>
<?
$_SESSION['check'] = MD5(serialize($_POST));
}
}
if(!$output) {
print "<tr><td align=center colspan=4><b>".$lang_char["noitem"].($wheretype?" ($_GET[act])":'')."</b></td></tr>";
}
?>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?
include "footer.php";
?>
It seems to work except that it is possible to click on and sell each item 2 times before it is cancelled from the inventory. I am not able to find the error as I am a very newby to PHP coding... someone can help me?
THX
