Jump to content
MakeWebGames

accept goods sent instead of just auto accept


marvin

Recommended Posts

Anything's possible :)

I'm guessing a new table would have to be created, and then when someone sends an item it gets put into that table instead of the other users inventory. Then once the receiver accepts it, it gets removed from that table and into their inventory. So like this

User1 sends User2 a gun

It gets inserted into the table, lets say 'itemsend' and an event gets created telling them to accept it. A page would probably have to be created where users can see their goods that have to be accepted

User2 accepts the goods and it gets removed from 'itemsend' and inserted into User2's inventory

Link to comment
Share on other sites

Give it a go, and I am sure people will be more then willing to help with any errors. Here is a place to start -> basic new table to store the item sent, who is sending it, the amount, and the receiver. -> send event asking if they want the item. -> basic PHP page that adds item back into one of the two users inventory's.

Link to comment
Share on other sites

I've done what Pitch Black suggested and created 2 new columns in the inventory table - pending, pending_amount.

Here's what I got so far, it works fine for the index(), but the accept is bugged. 1) It doesn't accept the correct item, it accepts 1 item above. 2) It doesn't add the item to the receiver (me)'s inventory. Same with the decline. If someone could work on it and finish it, it would be great.

P.S - Thanks very much Pitch Black for your help on IRC and putting up with me! I came across a lot of bugs when making this and Pitch Black helped me fix them all!

 

itemsend.php:

 

<?php
include "globals.php";
//itemsend
$_GET['ID'] = abs((int) $_GET['ID']);
$_GET['qty'] = abs((int) $_GET['qty']);
if($_GET['qty'] && $_GET['user'])
{
$id=$db->query("SELECT iv.*,it.* FROM inventory iv LEFT JOIN items it ON iv.inv_itemid=it.itmid WHERE iv.inv_id={$_GET['ID']} AND iv.inv_userid=$userid LIMIT 1");
if($db->num_rows($id)==0)
{
print "Invalid item ID";
}
else
{
$r=$db->fetch_row($id);
$m=$db->query("SELECT * FROM users WHERE userid={$_GET['user']} LIMIT 1");
if($_GET['qty'] > $r['inv_qty'])
{
print "You are trying to send more than you have!";
}
else if( $_GET['qty'] <= 0)
{
print "You haven't entered a valid amount to send.";
}
else if($db->num_rows($m) == 0)
{
print "You are trying to send to an invalid user!";
}
else
{
$rm=$db->fetch_row($m);
//are we sending it all
print "You sent {$_GET['qty']} {$r['itmname']}(s) to {$rm['username']}. However, they must accept this item before they can use it.";
event_add($_GET['user'],"You received {$_GET['qty']} {$r['itmname']}(s) from <a href='viewuser.php?u=$userid'>{$ir['username']}</a>. Click <a href='acceptitems.php'>Here</a> to accept this item and view another items you have yet to accept.",$c);
$db->query("INSERT INTO itemxferlogs VALUES('',$userid,{$_GET['user']},{$r['itmid']},{$_GET['qty']},unix_timestamp(), '{$ir['lastip']}', '{$rm['lastip']}')");
$db->query("UPDATE inventory SET pending={$_GET['user']}, pending_amount={$_GET['qty']} WHERE inv_itemid={$r['inv_itemid']}')");
}
}
}
else if($_GET['ID'])
{
$id=$db->query("SELECT iv.*,it.* FROM inventory iv LEFT JOIN items it ON iv.inv_itemid=it.itmid WHERE iv.inv_id={$_GET['ID']} AND iv.inv_userid=$userid LIMIT 1");
if($db->num_rows($id)==0)
{
print "Invalid item ID";
}
else
{
$r=$db->fetch_row($id);
print "<b>Enter who you want to send {$r['itmname']} to and how many you want to send. You have {$r['inv_qty']} to send.</b><br />
<form action='itemsend.php' method='get'>
<input type='hidden' name='ID' value='{$_GET['ID']}' />User ID: <input type='text' name='user' value='' /><br />
Quantity: <input type='text' name='qty' value='' /><br />
<input type='submit' value='Send Items (no prompt so be sure!)' /></form>";
}
}
else
{
print "Invalid use of file.";
}
$h->endpage();
?>

 

acceptitems.php

<?php
include "globals.php";

$_GET['action'] = isset($_GET['action']) && is_string($_GET['action']) ? strtolower(trim($_GET['action'])) : "";

switch($_GET['action'])
{
case "accept":
accept();
break;

case "decline":
decline();
break;

default:
index();
break;
}

function index()
{
global $db,$ir,$c,$userid,$h;	
$q = $db->query("SELECT i.itmid, i.itmname, inv.*, u.username, u.userid 
FROM inventory inv 
LEFT JOIN users u ON inv.pending=u.userid 
LEFT JOIN items i ON i.itmid=inv.inv_itemid
WHERE inv.pending={$ir['userid']}");
$num = mysql_num_rows($q);	
	echo "<h3>Accept Items</h3><br><br>
	The items that you have yet to accept are listed below.<br>";
	if($num==0)
	{
		echo "You do not have any items to accept.<br>> <a href='index.php'>Go home</a>";
	}
	else
	{
		echo "<table width='100%' border='1'>
		<tr>
		<th>From</th>
		<th>Item Name</th>
		<th>Quantity</th>
		<th>Time</th>
		<th>Accept</th>
		<th>Decline</th>
		</tr>";
		while($item = mysql_fetch_array($q))
		{
		$sent=date('F j, Y, g:i:s a',$item['timeSENT']);
			echo "<tr>
			<td>{$item['username']}</td>
			<td>{$item['itmname']}</td>
			<td>{$item['pending_amount']}</td>
			<td>$sent</td>
			<td><a href='acceptitems.php?action=accept'>Accept</a></td>
			<td><a href='acceptitems.php?action=decline'>Decline</a></td>";
		}
		echo "</table>";
	}

}
function accept()
{
global $db,$ir,$c,$userid,$h;
$q = $db->query("SELECT i.itmid, i.itmname, inv.*, u.username, u.userid 
FROM inventory inv 
LEFT JOIN users u ON inv.pending=u.userid 
LEFT JOIN items i ON i.itmid=inv.inv_itemid
WHERE inv.pending={$ir['userid']}");
$num = mysql_num_rows($q);	
$item = mysql_fetch_array($q);
	if($num==0)
	{
		die("Either this is not your item to accept or this has already been accepted.");
	}
	echo "You have <span style=color:green;>accepted</span> the item <span style=color:green;>{$item['itmname']}</span> from <span style=color:green;>{$item['username']}</span>. Click <a href='acceptitems.php'>Here</a> to go back to accept more items.<br>";
	item_add($ir['userid'],$item['inv_itemid'],$item['pending_amount']);	
	mysql_query("DELETE FROM inventory WHERE inv_id={$item['inv_id']}");

}

function decline()
{
global $db,$ir,$c,$userid,$h;
$q = $db->query("SELECT i.itmid, i.itmname, inv.*, u.username, u.userid 
FROM inventory inv 
LEFT JOIN users u ON inv.pending=u.userid 
LEFT JOIN items i ON i.itmid=inv.inv_itemid
WHERE inv.pending={$ir['userid']}");
$num = mysql_num_rows($q);	
$item = mysql_fetch_array($q);

	if($num==0)
	{
		die("Either this is not your item to decline or this has already been declined and sent back to the sender.");
	}
	echo "You have <span style=color:red;>declined</span> the item <span style=color:red;>{$item['itmname']}</span> from  <span style=color:red;>{$item['username']}</span>. Click <a href='acceptitems.php'>Here</a> to go back to accept or decline more items.<br>";
//Needs 2 working queries, 1 to add and 1 to remove
}


?>
Edited by gurpreet
Link to comment
Share on other sites

There are item_add(), and item_remove() functions for mccodes. Use them. ;)

Heh I did, but they messed up.

If you're referring to the UPDATE inventory part in itemsend, then it's necessary. The pending and pending_amount columns are NULL, but when someone sends an item, the null fields get filled. Then once accepted, the original record deletes but the item_add doesn't work (the accept and decline functions are buggeed and I couldn't fix them)

Link to comment
Share on other sites

Heh I did, but they messed up.

If you're referring to the UPDATE inventory part in itemsend, then it's necessary. The pending and pending_amount columns are NULL, but when someone sends an item, the null fields get filled. Then once accepted, the original record deletes but the item_add doesn't work (the accept and decline functions are buggeed and I couldn't fix them)

I looked at the comment that says you need to queries (decline() 2nd page), but anyway why don't your item functions work?

Link to comment
Share on other sites

You would put John's ID. This can be changed but it would take a while

I get it. Ok so here is the error after I sent it.

 

You sent Apple to first. However, they must accept this item before they can use it.QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '')' at line 1

Query was UPDATE inventory SET pending=2, pending_amount=1 WHERE inv_itemid=1')

Edited by marvin
Link to comment
Share on other sites

Change:

$db->query("UPDATE inventory SET pending={$_GET['user']}, pending_amount={$_GET['qty']} WHERE inv_itemid={$r['inv_itemid']}')");

To:

$db->query("UPDATE inventory SET pending={$_GET['user']}, pending_amount={$_GET['qty']} WHERE inv_itemid={$r['inv_itemid']})");

 

You sent 1 Apple to first. However, they must accept this item before they can use it.QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

Query was UPDATE inventory SET pending=2, pending_amount=1 WHERE inv_itemid=1)

Link to comment
Share on other sites

Oops sorry missed that bracket. Try this:

 

$db->query("UPDATE inventory SET pending={$_GET['user']}, pending_amount={$_GET['qty']} WHERE inv_itemid={$r['inv_itemid']}");

 

You sent 1 Apple to first. However, they must accept this item before they can use it.QUERY ERROR: Unknown column 'pending' in 'field list'

Query was UPDATE inventory SET pending=2, pending_amount=1 WHERE inv_itemid=1

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...