Gift item script for BlueB.
It happens that 2 friends of mine asked me for a gift function for BlueB website.
So, I see it's pointless to keep it as it's completely nothing.
What I did was just copy paste Dave's buy function, change the INSERT INTO AccountItem query to insert the new AID variable I made which contains the AID of the character name inserted in the box.
template_item.php(adding the gift button that would redirect to ?page=gift&id=
Code:
<?php
if(isset($_POST['buyitem']))
{
if($_SESSION['userid'])
{
$id = clean($_POST['id']);
if(ctype_digit($id))
{
$query = mssql_query("SELECT * FROM Web_ItemShop WHERE ID = '".$id."' AND Active = 1");
if(mssql_num_rows($query) == 1)
{
$row = mssql_fetch_row($query);
$itemid = $row[10];
$price = $row[6];
$coins = $sqlf->getcoins($_SESSION['userid']);
$aid = $sqlf->getaccdata("AID", $_SESSION['userid']);
if($coins >= $price)
{
$sqlf->removecoins($_SESSION['userid'], $price);
$itemid = explode(",", $itemid);
$itemid = array_reverse($itemid);
foreach($itemid as $value)
{
mssql_query("INSERT INTO AccountItem (AID, ItemID, RentDate, RentHourPeriod, Cnt) VALUES ('".$aid."', '".$value."', GETDATE(), NULL, 1)");
}
alert("Successfully bought the item!");
}
else
{
alert("You do not have enough coins!");
redirect("?page=itemshop", 0);
die();
}
}
else
{
alert("This item does not exist or is not active!");
redirect("?page=itemshop", 0);
die();
}
}
else
{
alert("This ID is not a number ; __ ;");
redirect("?page=itemshop", 0);
die();
}
}
else
{
alert("How about you login first?");
redirect("?page=itemshop", 0);
die();
}
}
elseif(isset($_POST['giftitem']))
{
redirect("?page=gift&id=".$_GET['id']."", 0);
die();
}
?>
<div id="content5">
<h1><?php echo $gunzname; ?> - Item</h1><br />
<p style="margin-left:40px;">
<a href="?page=itemshop">Home</a> - <a href="?page=itemshop&cat=armor">Armor</a> - <a href="?page=itemshop&cat=rings">Rings</a> - <a href="?page=itemshop&cat=melee">Melee</a> - <a href="?page=itemshop&cat=ranged">Ranged</a> - <a href="?page=itemshop&cat=meds">Meds</a> - <a href="?page=itemshop&cat=other">Other</a><br />
<?php
if(isset($_GET['id']) && $_GET['id'] != "" && ctype_digit($_GET['id']))
{
$id = clean($_GET['id']);
$query = mssql_query("SELECT * FROM Web_ItemShop WHERE ID = '".$id."' AND Active = 1");
if(mssql_num_rows($query) == 1)
{
$row = mssql_fetch_row($query);
echo '<br /><img src="http://forum.ragezone.com/images/items/'.$row[9].'" border="1" width="92px" height="92px" /><br />
<table border="0">
<tr><td class="titlestrong">Name:</td> <td>'.$row[1].'</td></tr>
<tr><td class="titlestrong">Description:</td> <td>'.$row[2].'</td></tr>
<tr><td class="titlestrong">Stats:</td> <td>'.$row[3].'</td></tr>
<tr><td class="titlestrong">Weight:</td> <td>'.$row[4].'</td></tr>
<tr><td class="titlestrong">Gender:</td> <td>'.$sqlf->convertgender($row[5]).'</td></tr>
<tr><td class="titlestrong">Price:</td> <td>'.$row[6].' T-Coins</td></tr>
<tr><td height="20px"></td><td></td></tr>
<tr><td>';
if($_SESSION['userid'])
{
echo '<form action="" method="post"><input type="hidden" name="id" value="'.$row[0].'" /><input type="submit" name="buyitem" value="Buy" /><input type="submit" value="Gift" name="giftitem" /></form>';
}
else
{
echo 'Login to buy!';
}
echo '</td></tr>
</table>';
}
else
{
echo '<br />This item does not exist or is not active!';
}
}
else
{
echo '<br />ID is empty or not a number!';
}
?>
</p>
</div>
New file, template_gift, containing the copy pasted buy function of Dave, but edited to be used as gift.
Code:
<?php
if(isset($_POST['giftitem']))
{
if($_SESSION['userid'] == "")
{
alert("How about you login first?");
redirect("?page=itemshop", 0);
die();
}
$id = clean($_POST['id']);
if(!ctype_digit($id))
{
alert("This ID is not a number ; __ ;");
redirect("?page=itemshop", 0);
die();
}
if(empty($_POST['gift_user']))
{
alert("Please enter in a character name!");
redirect("?page=gift&id=".$_GET['id']."", 0);
die();
}
$query = mssql_query("SELECT * FROM Web_ItemShop WHERE ID = '".$id."' AND Active = 1");
if(mssql_num_rows($query) != 1)
{
alert("This item does not exist or is not active!");
redirect("?page=itemshop", 0);
die();
}
$row = mssql_fetch_row($query);
$itemid = $row[10];
$price = $row[6];
$coins = $sqlf->getcoins($_SESSION['userid']);
$aid = $sqlf->getaccdata("AID", $_SESSION['userid']);
$query_gift = mssql_query("SELECT * FROM Character WHERE Name = '".clean($_POST['gift_user'])."'");
if(mssql_num_rows($query_gift) != 1)
{
alert("Character name entered was not found!");
redirect("?page=gift&id=".$_GET['id']."", 0);
die();
}
$gift_aid = mssql_result($query_gift, 0, 'AID');
if($coins >= $price)
{
$sqlf->removecoins($_SESSION['userid'], $price);
$itemid = explode(",", $itemid);
$itemid = array_reverse($itemid);
foreach($itemid as $value)
{
mssql_query("INSERT INTO AccountItem (AID, ItemID, RentDate, RentHourPeriod, Cnt) VALUES ('".$gift_aid."', '".$value."', GETDATE(), NULL, 1)");
}
alert("Successfully gifted the item to ".clean($_POST['gift_user'])."!");
redirect("?page=itemshop", 0);
die();
}
else
{
alert("You do not have enough coins!");
redirect("?page=itemshop", 0);
die();
}
}
?>
<div id="content5">
<h1><?php echo $gunzname; ?> - Item</h1><br />
<p style="margin-left:40px;">
<a href="?page=itemshop">Home</a> - <a href="?page=itemshop&cat=armor">Armor</a> - <a href="?page=itemshop&cat=rings">Rings</a> - <a href="?page=itemshop&cat=melee">Melee</a> - <a href="?page=itemshop&cat=ranged">Ranged</a> - <a href="?page=itemshop&cat=meds">Meds</a> - <a href="?page=itemshop&cat=other">Other</a><br />
<?php
if(isset($_GET['id']) && $_GET['id'] != "" && ctype_digit($_GET['id']))
{
$id = clean($_GET['id']);
$query = mssql_query("SELECT * FROM Web_ItemShop WHERE ID = '".$id."' AND Active = 1");
if(mssql_num_rows($query) == 1)
{
$row = mssql_fetch_row($query);
echo '<br /><img src="http://forum.ragezone.com/images/items/'.$row[9].'" border="1" width="92px" height="92px" /><br />
<table border="0">
<tr><td class="titlestrong">Name:</td> <td>'.$row[1].'</td></tr>
<tr><td class="titlestrong">Description:</td> <td>'.$row[2].'</td></tr>
<tr><td class="titlestrong">Stats:</td> <td>'.$row[3].'</td></tr>
<tr><td class="titlestrong">Weight:</td> <td>'.$row[4].'</td></tr>
<tr><td class="titlestrong">Gender:</td> <td>'.$sqlf->convertgender($row[5]).'</td></tr>
<tr><td class="titlestrong">Price:</td> <td>'.$row[6].' T-Coins</td></tr>
<tr><td height="20px"></td><td></td></tr>
<tr><td>';
if($_SESSION['userid'])
{
echo '<form action="" method="post"><input type="hidden" name="id" value="'.$row[0].'" />Character:<input type="text" name="gift_user" /><center><input type="submit" name="giftitem" value="Gift" /></center></form>';
}
else
{
echo 'Login to buy!';
}
echo '</td></tr>
</table>';
}
else
{
echo '<br />This item does not exist or is not active!';
}
}
else
{
echo '<br />ID is empty or not a number!';
}
?>
</p>
</div>
Credits:
SuperWaffle for the nice code.
Me for editing his buy function to work as gift.
Re: Gift item script for BlueB.
Re: Gift item script for BlueB.
It's alright, if you have any suggestions for me to do, I'll gladly do it.
Re: Gift item script for BlueB.
First liked, woot!
Nice job, Vusion
Re: Gift item script for BlueB.
More to come, I'm trying to find designs to code and release, but can't find any :C
Posted via Mobile Device
Re: Gift item script for BlueB.
Re: Gift item script for BlueB.