[RevCMS] LIMITED furniture sales in CMS [Phoenix]

thewicard

Member
Nov 4, 2011
41
3
So, I used a few hours figuring this out xP
Hope you enjoy. Sorry about insanely long code.
Price is now configured in DB.

What does this code do?
It allows you to sell furniture in limited quantities.
Is it secure?
It has double money-in-pocket check (1 in whatever page it's placed in AND 1 when delivering furniture)
It has double furniture-not-sold-out check (1 in whatever page it's placed in AND 1 when delivering furniture)
Will not work to refresh page to get another furniture unless there are still available AND you have money for it.
Added POST Filter (Now only allow numeric posts) //Thanks to Leenster for telling me it was needed.

First: Run this queue
PHP:
DROP TABLE IF EXISTS `rev_ltd`;
CREATE TABLE `rev_ltd` (
 `furni_id` int(255) NOT NULL,
 `furni_left` int(255) NOT NULL DEFAULT '100',
 `furni_sold` int(255) NOT NULL DEFAULT '0',
 `furni_price` int(255) NOT NULL DEFAULT '5000',
 PRIMARY KEY (`furni_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `rev_ltd` VALUES ('227', '15', '0', '5000');

Second: Create a file in app/tpl/skins/YOURSKIN/ named buyltd.php
Place this content in the file and save:
PHP:
<?php
$ltd_id = preg_replace('/[^0-9]/', '', $_POST["ltd_id"]);
$user_id = $_SESSION['user']['id'];
$selectfromusers = mysql_query("SELECT * FROM users WHERE id = '".$user_id."'") or die(mysql_error());
while ($getmoney = mysql_fetch_array($selectfromusers))
$money_current = $getmoney['credits'];
$selectfromfurninum = mysql_query("SELECT * FROM rev_ltd WHERE furni_id = '".$ltd_id."'") or die(mysql_error());
while ($getfurninum = mysql_fetch_array($selectfromfurninum))
$furnileft = $getfurninum['furni_left'] and
$furnisold = $getfurninum['furni_sold'] and
$ltd_price = $getfurninum['furni_price'];
if($furnileft > '0')
{
if($money_current < $ltd_price)
{
echo "You don't have enough money for this item";
}
else
{
$newmoney = $money_current - $ltd_price;
mysql_query("UPDATE users SET credits='".$newmoney."' WHERE id='".$user_id."'") or die(mysql_error());
$newfurnileft = $furnileft - '1';
$newfurnisold = $furnisold + '1';
mysql_query("UPDATE rev_ltd SET furni_sold='".$newfurnisold."'") or die(mysql_error());
mysql_query("UPDATE rev_ltd SET furni_left='".$newfurnileft."'") or die(mysql_error());
$highestid = mysql_query("SELECT * from items ORDER BY id DESC LIMIT 1") or die(mysql_error());
while ($checknewid2 = mysql_fetch_array($highestid))
$newid2 = $checknewid2['id'];
$newid = $newid2 + '1';
mysql_query("INSERT INTO items (id, user_id, room_id, base_item, extra_data, x, y, z, rot, wall_pos) VALUES ('".$newid."','".$user_id."',0,'".$ltd_id."',0,0,0,0,0,0)") or die(mysql_error());
echo "Item bough successfully!";
}
}
else
{
echo "All of furniture is already sold, sorry";
}
?>
<meta http-equiv="refresh" content="1; URL=me">

Third:
Goto whatever page you want this in, add this at the top:
PHP:
<?php
$user_id = $_SESSION['user']['id'];
$selectfromusers = mysql_query("SELECT * FROM users WHERE id = '".$user_id."'") or die(mysql_error());
while ($getmoney = mysql_fetch_array($selectfromusers))
$money_current = $getmoney['credits'];
?>

Forth:
Add this wherever you want the output, this is made for Priv theme.
PHP:
<?php
//Furniconfiguration
$ltd_id = "227"; //furni_id in the database
$ltd_name = "Dragonegg"; //The name of your furni
$image_url = "http://habboxwiki.com/wiki/images/1/12/Black_Dino_Egg.png"; //Image URL (optional)
 
 
//Collects data from database
$selectfromltd = mysql_query("SELECT * FROM rev_ltd WHERE furni_id = '".$ltd_id."'") or die(mysql_error());
while ($getltd = mysql_fetch_array($selectfromltd))
$getltd_num = $getltd['furni_left'] and
$getltd_sold = $getltd['furni_sold'] and
$ltd_price = $getltd['furni_price'];
$getltd_total = $getltd_sold + $getltd_num;
$money_lack = $ltd_price - $money_current; ?>
 
<!-- The part that you can see, may need to be changed to fit other theme (currently for Priv theme)   -->
<div class="left page round"><ul> <?php
if($getltd_num == '0') {
$money_lack = $ltd_price - $money_current;
echo "This item is no longer available, sorry.";?>
<br><br><br><h3><?php echo "$ltd_name"?></h3><img src="<?php echo "$image_url" ?>" style="float: right">
<br>Sold out.<br><br>
<?php }
else
{
if($money_current < $ltd_price)
{
echo "You need $money_lack more credits in order to buy this item.";?>
<br><br><br><h3><?php echo "$ltd_name"?></h3><img src="<?php echo "$image_url" ?>" style="float: right">
<br>Out of credits.<br><br>
<?php
} else{ ?>
<img src="<?php echo "$image_url" ?>" style="float: right">
<font size="2" color="white"> <h3>Buy</h3>
<p>Buy your <?php echo "$ltd_name"?> for just <?php echo "$ltd_price"?> credits.<br>
</font><font size="2" color="purple">
Only <?php echo "$getltd_num"; ?> of <?php echo "$getltd_total"; ?> left!</p></font>
<form action="buyltd" method="post">
<input type="hidden" name="ltd_id" value="<?php echo "$ltd_id"; ?>">
<input type="submit" type="submit" name="help" value="Buy" class="button round"> </form></b> <?php }}?>
</div></ul><br><br><br><br><br><br><br><br><br>
This code is made for Priv theme, so if you use other you proberbly need to edit it.

Each time you want to add a new furniture, you have to duplicate this code, edit in database table rev_ltd (insert record for each furniture you want to add), furni_id should be the same as 'id' of the furniture is in table 'furniture'.

Images:
2pQSa
 

Sledmore

Chaturbate Livestreamer
Staff member
FindRetros Moderator
Jul 24, 2010
5,202
3,958
Nice release and effort, however in buyltd.php you should filter the POST data, also you do not need to loop so much, you can just use mysql_fetch_array(mysql_query());

But nice share.
 

thewicard

Member
Nov 4, 2011
41
3
POST data now filtered,
Price is now set in DB.

UPDATE: TOTALY NEEDED third step that got removed by accident, added again.
 

Queef

Some people...
Jul 27, 2012
645
289
Loving this idea, great contribution.

Just did some testing, it doesnt seem to have deducted my credits for buying, It might be cause i put the output in the wrong place.

Where would you suggest putting it?

May i also suggest putting the "Item bought successfully part on the same page? So if the item is bought a box shows up somewhere on the page?
 

thewicard

Member
Nov 4, 2011
41
3
Loving this idea, great contribution.

Just did some testing, it doesnt seem to have deducted my credits for buying, It might be cause i put the output in the wrong place.

Where would you suggest putting it?

May i also suggest putting the "Item bought successfully part on the same page? So if the item is bought a box shows up somewhere on the page?
Check if the credits are deducted in the database, the function from class.template updates really slow.

Here's an alternative that updates immediate!
In the site which you see your money insert the code at part 3. (No need if this is the page with the full code)

Now replace all {coins} with this code
PHP:
<?php echo "$money_current"; ?>
 

Queef

Some people...
Jul 27, 2012
645
289
Oh it did deduct it, i just had to restart NaviCat to see the changes come into effect.​
The <?php echo "$money_current"; ?> didnt work.
 

Users who are viewing this thread

Top