Saberman Posted July 28, 2009 Posted July 28, 2009 i am using the rental mod by richard and i have a little bug if anyone could fix it i would be greatful. the bug here is that if a user rents a house he has his name where the original owners name supposed to be and once he rented the house he becomes the owner and if the user trys to return the house to the owner it send the house back to him with an event and the original owner gets striped of the house rentals.php <?php include "globals.php"; print "<center><font size='4' face='Arial, Helvetica, sans-serif'>Rental Market</font> "; switch($_GET['action']) { case "buy": buy_house(); break; case "remove": remove_house(); break; default: market_index(); break; } function market_index() { global $db,$ir,$c,$userid; print "<table width=90% cellspacing=1 class='table'> <tr> <th>Owner</th> <th>House</th> <th>Days</th> <th>Daily Price</th> <th>Links</th> </tr>"; $q=$db->query("SELECT rent.*, h.*, u.* FROM rentalmarket rent LEFT JOIN houses h ON rentHOUSE=h.hID LEFT JOIN users u ON u.userid=rent.rentOWNER ORDER BY rent.rentCOST, rent.rentDAYS ASC",$c); $lt=""; while($r=$db->fetch_row($q)) { if($r['rentOWNER'] == $userid) { $link = "[[url='rentals.php?action=remove&ID={$r[']Remove[/url]]"; } else { $link = "[[url='rentals.php?action=buy&ID={$r[']Rent[/url]]"; } $cost=money_formatter($r['rentCOST']); print "<tr> <td>[url='viewuser.php?u={$r[']{$r['username']}[/url] [{$r['userid']}]</td> <td>{$r['hNAME']}</td> <td>{$r['rentDAYS']}</td> <td>$cost</td> <td>$link</td> </tr>"; } print "</table>"; } function remove_house() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT rent.*, h.*, u.* FROM rentalmarket rent LEFT JOIN houses h ON rentHOUSE=h.hID LEFT JOIN users u ON u.userid=rent.rentOWNER ORDER BY rent.rentCOST, rent.rentDAYS ASC",$c); if(!$db->num_rows($q)) { print "Error, either this house does not exist, or you are not the owner. [url='rentals.php']> Back[/url]"; $h->endpage(); exit; } $r=$db->fetch_row($q); $db->query("INSERT INTO `properties` (`prID`, `prOWNER`, `prHOUSE`) VALUES ('NULL', '$userid', '{$r['hID']}');",$c); $db->query("DELETE FROM rentalmarket WHERE rentID={$_GET['ID']}",$c); print "House removed from market! [url='rentals.php']> Back[/url]"; } function buy_house() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT rent.*, h.*, u.* FROM rentalmarket rent LEFT JOIN houses h ON rentHOUSE=h.hID LEFT JOIN users u ON u.userid=rent.rentOWNER ORDER BY rent.rentCOST, rent.rentDAYS ASC",$c); if(!$db->num_rows($q)) { print "This house is already occupied. [url='rentals.php']> Back[/url]"; $h->endpage(); exit; } $r=$db->fetch_row($q); if($r['reCOST'] > $ir['money']) { print "Error, you do not have the funds to start renting this house. [url='rentals.php']> Back[/url]"; $h->endpage(); exit; } event_add($r['rentOWNER'],"[url='viewuser.php?u=$userid']{$ir['username']}[/url] is now renting your {$r['hNAME']} for {$r['rentCOST']} per day.",$c); $db->query("INSERT INTO `properties` (`prID`, `prOWNER`, `prHOUSE`) VALUES ('{$r['rentPROP']}', '$userid', '{$r['hID']}');",$c); $db->query("INSERT INTO `rentals` (`reID`, `reOWNER`, `rePID`, `reRENTER`, `reDAYS`, `reCOST`) VALUES ('NULL', '$userid', '{$r['rentPROP']}', '$userid', '{$r['rentDAYS']}', '{$r['rentCOST']}');",$c); $db->query("DELETE FROM rentalmarket WHERE rentID={$_GET['ID']}",$c); $db->query("UPDATE users SET rent={$r['rentCOST']} WHERE userid=$userid",$c); print "You are now renting the {$r['hNAME']} for \$".number_format($r['rentCOST'])." per day."; } $h->endpage(); ?> properties.php <?php include "globals.php"; print "<center><font size='4' face='Arial, Helvetica, sans-serif'>Your Properties</font><hr width=75%>"; switch($_GET['action']) { case 'sell': sell_house(); break; case 'market': market_house(); break; case 'rent': rent_house(); break; case 'give': send_house(); break; case 'move': move_house(); break; case 'return': return_house(); break; default: your_houses(); break; } function your_houses() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE pr.prOWNER={$userid} ORDER BY h.hPRICE ASC",$c); if ($db->num_rows($q) == 0) { print "You have no houses."; } else { print "<table width=60% cellspacing=1>"; while($r=$db->fetch_row($q)) { print "<tr>"; $dfi=$db->query("SELECT * FROM users WHERE userid={$r['prOWNER']}",$c); $tb=$db->fetch_row($dfi); print "<td valign='left'> {$r['hsepics']}"; print "<td valign='center'> [b]Property: [/b]{$r['hNAME']} [b]Owner: [/b][url='viewuser.php?u={$tb[']{$tb['username']}[/url] [b]Upkeep: [/b]\${$r['hTAX']} [b]Will: [/b]{$r['hWILL']}</td> <td align='center'> [[url='properties.php?action=move&ID={$r[']Move In[/url]] "; $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$r['prID']}",$c); $zf=$db->fetch_row($yd); $tr=$db->num_rows($yd); if ($r['hWILL'] != '100' && $tr == '0') { print " [[url='properties.php?action=sell&ID={$r[']Sell[/url]] [[url='properties.php?action=market&ID={$r[']Market[/url]] [[url='properties.php?action=rent&ID={$r[']Rent[/url]] [[url='properties.php?action=give&ID={$r[']Give[/url]] "; } $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$r['prID']}",$c); $zf=$db->fetch_row($yd); $tr=$db->num_rows($yd); if ($tr) { print "[[url='properties.php?action=return&ID={$r[']Return[/url]] "; } $hprice=money_formatter($r['hPRICE']); print "</tr><tr><td height='10'></td></tr>"; } print "</table> "; } } function sell_house() { global $db,$ir,$c,$userid,$h; $_GET['ID'] = abs((int) $_GET['ID']); $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$_GET['ID']}",$c); $zf=$db->fetch_row($yd); $tr=$db->num_rows($yd); if ($tr) { die (" This house has been rented! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%> "); } $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE pr.prID={$_GET['ID']} AND pr.prOWNER=$userid LIMIT 1",$c); $r=$db->fetch_row($q); if ($r['prOWNER'] != $ir['userid']) { print " This house does not belong to you. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $db->query("UPDATE users SET money=money+{$r['hPRICE']} WHERE userid=$userid",$c); print " You sold your {$r['hNAME']} for \${$r['hPRICE']}! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; $db->query("DELETE FROM properties WHERE prID={$_GET['ID']}",$c); } } function send_house() { global $db,$ir,$c,$userid,$h; $_GET['ID'] = abs((int) $_GET['ID']); $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$_GET['ID']}",$c); $zf=$db->fetch_row($yd); $tr=$db->num_rows($yd); if ($tr) { die (" This house has been rented! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%> "); } if($_POST['user']) { $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE pr.prID={$_GET['ID']} AND pr.prOWNER=$userid LIMIT 1",$c); if($db->num_rows($q)==0) { print " Invalid house ID <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $r=$db->fetch_row($q); $m=$db->query("SELECT * FROM users WHERE userid={$_POST['user']} LIMIT 1",$c); if($db->num_rows($m) == 0) { print " You are trying to send to an invalid user! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else if (!$_GET['ID']) { print " This user does not exist. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $rm=$db->fetch_row($m); $db->query("UPDATE properties SET prOWNER={$_POST['user']} WHERE prID={$_GET['ID']}",$c); } print " You sent the {$r['hNAME']} to {$rm['username']}. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; event_add($_POST['user'],"You received the {$r['hNAME']} from [url='viewuser.php?u=$userid']{$ir['username']}[/url]",$c,'transfer'); } } else if($_GET['ID']) { $id=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE pr.prID={$_GET['ID']} AND pr.prOWNER=$userid LIMIT 1",$c); if($db->num_rows($id)==0) { print " Invalid house ID. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else if ($_GET['ID']==0) { print " This user does not exist. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $r=$db->fetch_row($id); print " [b]Enter the ID of the user you want to give the {$r['hNAME']} to.[/b] <form action='properties.php?action=give&ID={$_GET['ID']}' method='post'> <input type='hidden' name='ID' value='{$_GET['ID']}' />User ID: <input type='text' name='user' value='' /> <input type='submit' value='Give House' /></form> <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } } else { print " Invalid use of file. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } } function market_house() { global $db,$ir,$c,$userid,$h; $_GET['ID'] = abs((int) $_GET['ID']); $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$_GET['ID']}",$c); $zf=$db->fetch_row($yd); $tr=$db->num_rows($yd); if ($tr) { die (" This house has been rented! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%> "); } $_POST['price'] = abs((int) $_POST['price']); if($_POST['price']) { $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE prID={$_GET['ID']} and prOWNER=$userid",$c); if($db->num_rows($q)==0) { print " Invalid House ID <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $r=$db->fetch_row($q); $db->query("INSERT INTO propertymarket VALUES ('','$userid',{$_POST['price']},'{$r['hID']}')", $c); $db->query("DELETE FROM properties WHERE prID={$_GET['ID']}",$c); print " House added to market. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } } else { $q=$db->query("SELECT * FROM properties WHERE prID={$_GET['ID']} and prOWNER=$userid",$c); if($db->num_rows($q)==0) { print " Invalid House ID <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $r=$db->fetch_row($q); print " Adding a house to the property market... <form action='properties.php?action=market&ID={$_GET['ID']}' method='post'> <input type='hidden' name='ID' value='{$_GET['ID']}' /> Price: <input type='text' name='price' value='0' /> <input type='submit' value='Add' /></form> <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } } } function return_house() { global $db,$ir,$c,$userid,$h; $_GET['ID'] = abs((int) $_GET['ID']); $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE pr.prID={$_GET['ID']} AND pr.prOWNER=$userid LIMIT 1",$c); $r=$db->fetch_row($q); if ($r['prOWNER'] != $ir['userid']) { print " This house does not belong to you. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$_GET['ID']}",$c); $zf=$db->fetch_row($yd); event_add($zf['reOWNER'],"You received the {$r['hNAME']} back from [url='viewuser.php?u=$userid']{$ir['username']}[/url]",$c,'transfer'); print " You returned the {$r['hNAME']}! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; $db->query("DELETE FROM properties WHERE prID={$_GET['ID']}",$c); $db->query("INSERT INTO `properties` (`prID`, `prOWNER`, `prHOUSE`) VALUES ('{$zf['rePID']}', '{$zf['reOWNER']}', '{$r['hID']}');",$c); $db->query("DELETE FROM rentals WHERE rePID={$_GET['ID']}",$c); } } function rent_house() { global $db,$ir,$c,$userid,$h; $_GET['ID'] = abs((int) $_GET['ID']); $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$_GET['ID']}",$c); $zf=$db->fetch_row($yd); $tr=$db->num_rows($yd); if ($tr) { die (" This house has been rented! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%> "); } $_POST['price'] = abs((int) $_POST['price']); $_POST['days'] = abs((int) $_POST['days']); if($_POST['price'] || $_POST['days']) { $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE prID={$_GET['ID']} and prOWNER=$userid",$c); if($db->num_rows($q)==0) { print " Invalid House ID <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $r=$db->fetch_row($q); $db->query("INSERT INTO rentalmarket VALUES ('','{$_GET['ID']}',{$_POST['price']},'{$_POST['days']}','$userid','{$r['hID']}')", $c); $db->query("DELETE FROM properties WHERE prID={$_GET['ID']}",$c); print " House added to market. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } } else { $q=$db->query("SELECT * FROM properties WHERE prID={$_GET['ID']} and prOWNER=$userid",$c); if($db->num_rows($q)==0) { print " Invalid House ID <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $r=$db->fetch_row($q); print " Adding a house to the rental market... <form action='properties.php?action=rent&ID={$_GET['ID']}' method='post'> <input type='hidden' name='ID' value='{$_GET['ID']}' /> Price (Daily): <input type='text' name='price' value='0' /> Days: <input type='text' name='days' value='0' /> <input type='submit' value='Add' /></form> <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } } } function move_house() { global $db,$ir,$c,$userid,$h; $_GET['ID'] = abs((int) $_GET['ID']); $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE pr.prID={$_GET['ID']} AND pr.prOWNER=$userid LIMIT 1",$c); $r=$db->fetch_row($q); if ($r['prOWNER'] != $ir['userid']) { print " This house does not belong to you. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $mpq=$db->query("SELECT * FROM houses WHERE hWILL={$ir['maxwill']}",$c); $mp=$db->fetch_row($mpq); print " You moved into your {$r['hNAME']}! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; $db->query("INSERT INTO `properties` (`prID`, `prOWNER`, `prHOUSE`) VALUES ('', '$userid', '{$mp['hID']}');",$c); $db->query("UPDATE users SET maxwill={$r['hWILL']},will=0 WHERE userid=$userid",$c); $db->query("DELETE FROM properties WHERE prID={$_GET['ID']}",$c); } } $h->endpage(); ?> Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.