-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhouses.php
473 lines (464 loc) · 18.6 KB
/
houses.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<?php
include_once('globals.php');
switch ($_GET['page'])
{
case 'move': move_house(); break;
case 'move_out': move_out(); break;
case 'estate': estate_agent(); break;
case 'sell': sell_house(); break;
case 'rentals': rental_market(); break;
case 'rent': rent_house(); break;
case 'your_rents': your_rents(); break;
case 'upgrade': upgrade_house(); break;
default: houses_index(); break;
}
function houses_index()
{
echo '<p class="heading"><b>Your Houses</b></p>';
global $ir, $dbh;
$houses = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseOwner` = '%u' || `uhouseTenant` = '%u') AND `uhouseId` != '%d'", $ir['userid'], $ir['userid'], $ir['house']));
echo '<table width="600">
<tr>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=estate">Estate agent</a></td>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=your_rents">Your rentals</a></td>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=rentals">Rent a house</a></td>
</tr>
</table>
';
if($ir['house'])
{
$fetch = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) WHERE (`uhouseId` = '%u')", $ir['house']));
$h = mysql_fetch_assoc($fetch);
echo '<b>Current house:</b>
<table width="300" class="table">
<tr>
<th width="50%">Current house</th>
<th width="50%">Move out</th>
</tr>
<tr>
<td>'.stripslashes($h['hNAME']).'</td>
<td><a href="'.$_SERVER['PHP_SELF'].'?page=move_out">Move out</a></td>
</tr>
</table>
';
}
echo '<table width="600" class="table">
<tr>
<th width="15%">House name</th>
<th width="20%">Owner</th>
<th width="25%">Tenant</th>
<th width="15%">Will value</th>
<th width="25%">Manage</th>
</tr>';
if(!mysql_num_rows($houses))
{
echo '<tr>
<td colspan="5">You have no houses at this time, purchase one at the estate agent\'s.</td>
</tr>';
}
while($r = mysql_fetch_assoc($houses))
{
if ($r['uhouseTenant']) {
$sql = $dbh->prepare("SELECT username from users where userid=?");
$sql->bindParam(1, $r['uhouseTenant']);
$sql->execute();
$tenant_info = $sql->fetch();
$tenant = '<a href=viewuser.php?u='.$r['uhouseTenant'].'>'.stripslashes($tenant_info['username']).'</a><br>
'.$r['uhouseRTime'].' days left<br>
for $'.number_format($r['uhouseRent']).' a day';
} else {
$tenant = 'N/A';
}
echo '<tr>
<td>'.stripslashes($r['hNAME']).'</td>
<td><a href=viewuser.php?u='.$r['userid'].'>'.stripslashes($r['username']).'</a></td>
<td>'.$tenant.'</td>
<td>'.number_format($r['uhouseMood']).' Will</td>
<td><a href='.$_SERVER['PHP_SELF'].'?page=move&id='.$r['uhouseId'].'>Move in </a>
<p><a href='.$_SERVER['PHP_SELF'].'?page=sell&id='.$r['uhouseId'].'>Sell house </a>
<p><a href='.$_SERVER['PHP_SELF'].'?page=rent&id='.$r['uhouseId'].'>Rent house </a>
<p><a href='.$_SERVER['PHP_SELF'].'?page=upgrade&id='.$r['uhouseId'].'>Add upgrades </a></td>
</tr>';
}
echo '</table>';
}
function move_house()
{
global $ir;
$fetch = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseId` = '%u')", abs((int) $_GET['id'])));
if(!isset($_GET['id']))
{
echo 'You did not select a house to move in to.';
}
else if(!mysql_num_rows($fetch))
{
echo 'You cannot move into a non-existant house.';
}
else
{
$r = mysql_fetch_assoc($fetch);
if($r['uhouseOwner'] != $ir['userid'] AND $r['uhouseTenant'] != $ir['userid'])
{
echo 'You are not permitted to move into this house.';
}
else if($r['uhouseRTime'] AND $r['uhouseOwner'] == $ir['userid'])
{
echo 'You cannot move into a house while it is being rented to another member.';
}
else
{
mysql_query(sprintf("UPDATE `users` SET `house` = '%d', `maxwill` = '%d' WHERE (`userid` = '%u')", abs((int) $_GET['id']), $r['uhouseMood'], $ir['userid']));
echo 'You have moved into the '.stripslashes($r['hNAME']).', You now have a maximum Will bar of '.number_format($r['uhouseMood']).'.';
}
}
}
function move_out()
{
global $ir;
$fetch = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseId` = '%u')", $ir['house']));
if(!mysql_num_rows($fetch))
{
echo 'You cannot move out of a non-existant house.';
}
else
{
$r = mysql_fetch_assoc($fetch);
if($r['uhouseOwner'] != $ir['userid'] AND $r['uhouseTenant'] != $ir['userid'])
{
echo 'You are not permitted to move out of this house.';
}
else
{
mysql_query(sprintf("UPDATE `users` SET `house` = '0', `maxwill` = '100', `will` = '100' WHERE (`userid` = '%u')", $ir['userid']));
echo 'You have moved out of the '.stripslashes($r['hNAME']).', You now have a maximum Will bar of 100.';
}
}
}
function sell_house()
{
global $ir;
$fetch = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseOwner` = '%u') AND (`uhouseId` = '%u')", $ir['userid'], abs((int) $_GET['id'])));
if(!isset($_GET['id']))
{
echo 'You did not select a house to sell.';
}
else if(!mysql_num_rows($fetch))
{
echo 'You cannot attempt to sell a non-existant house.';
}
else
{
$r = mysql_fetch_assoc($fetch);
if($r['uhouseOwner'] != $ir['userid'])
{
echo 'You do not own this house, so don\'t attempt to sell it.';
}
else if($r['uhouseTenant'])
{
echo 'You cannot sell a house while it is being rented to another member.';
}
else
{
mysql_query(sprintf("UPDATE `users` SET `money` = `money` + '%d' WHERE (`userid` = '%u')", $r['hPRICE'], $ir['userid']));
mysql_query(sprintf("DELETE FROM `owned_houses` WHERE (`uhouseId` = '%u')", abs((int) $_GET['id'])));
echo 'You have sold the '.stripslashes($r['hNAME']).' for a total of $'.number_format($r['hPRICE']).'.';
}
}
}
function estate_agent()
{
echo '<p class="heading"><b>Estate Agent</b></p>';
echo '<table width="600">
<tr>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=estate">Estate agent</a></td>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=your_rents">Your rentals</a></td>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=rentals">Rent a house</a></td>
</tr>
</table>';
global $ir;
if(isset($_GET['id']))
{
$house = mysql_query(sprintf("SELECT * FROM `houses` WHERE (`hID` = '%u')", abs((int) $_GET['id'])));
$r = mysql_fetch_assoc($house);
if(!mysql_num_rows($house))
{
echo 'You cannot attempt to purchase a non-existant house.';
}
else if($ir['money'] < $r['hPRICE'])
{
echo 'You cannot afford to purchase this house right now, come back another time.';
}
else
{
mysql_query(sprintf("UPDATE `users` SET `money` = `money` - '%d' WHERE (`userid` = '%u')", $r['hPRICE'], $ir['userid']));
mysql_query(sprintf("INSERT INTO `owned_houses` (`uhouseId`, `uhouseOwner`, `uhouseHouse`, `uhouseMood`) VALUES ('NULL','%u', '%d', '%d')", $ir['userid'], $r['hID'], $r['hWILL']));
echo 'You have purchased the '.stripslashes($r['hNAME']).' for a total of $'.number_format($r['hPRICE']).'!';
}
}
else
{
$houses = mysql_query(sprintf("SELECT * FROM `houses` ORDER BY `hWILL` ASC"));
echo '<table width="600" class="table">
<tr>
<th>House name</th>
<th>Will value</th>
<th>Cost</th>
</tr>';
while($r = mysql_fetch_assoc($houses))
{
echo '<tr>
<td><a href='.$_SERVER['PHP_SELF'].'?page=estate&id='.$r['hID'].'>'.stripslashes($r['hNAME']).'</a></td>
<td>'.number_format($r['hWILL']).' Will bar</td>
<td>$'.number_format($r['hPRICE']).'</td>
</tr>';
}
print '</table>';
}
}
function rental_market()
{
echo '<p class="heading"><b>Rental Market</b></p>';
echo '<table width="600">
<tr>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=estate">Estate agent</a></td>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=your_rents">Your rentals</a></td>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=rentals">Rent a house</a></td>
</tr>
</table>';
global $ir, $dbh;
if(isset($_GET['id']))
{
$houses = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `users` ON (`userid` = `uhouseTenant`) WHERE `uhouseTenant` > '0'"));
$house = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseId` = '%u')", abs((int) $_GET['id'])));
$r = mysql_fetch_assoc($house);
if(!mysql_num_rows($house))
{
echo 'You cannot rent a house that does not exist.';
}
else if($ir['money'] < $owned_houses['uhouseRent']*$owned_houses['uhouseRTime'])
{
echo 'You cannot afford this house.';
}
else if($ir['money'] > $owned_houses['uhouseRent']*$owned_houses['uhouseRTime'])
{
$sql = $dbh->prepare("update users set will=will+? where userid=?");;
$sql->bindParam(1, $r['uhouseMood']);
$sql->bindParam(2, $ir['userid']);
$sql->execute();
mysql_query(sprintf("UPDATE `users` SET `money` = `money` - '%d' WHERE `userid` = '%u'", $r['uhouseRent'], $r['uhouseTenant']));
mysql_query(sprintf("UPDATE `owned_houses` SET `uhouseTenant` = '%d' WHERE (`uhouseId` = '%u')", $ir['userid'], abs((int) $_GET['id'])));
echo 'You are now renting the '.stripslashes($r['hNAME']).' for a total of $'.number_format($r['uhouseRent']).' each night!';
}
}
else
{
$houses = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE `uhouseTenant` = '0' AND `uhouseRent` > '0' ORDER BY `uhouseRent` ASC"));
echo '<table width="600" class="table">
<tr>
<th>House name</th>
<th>Owner</th>
<th>Will value</th>
<th>Cost each night</th>
<th>Rental time</th>
<th>Manage</th>
</tr>';
while($r = mysql_fetch_assoc($houses))
{
echo '<tr>
<td>'.stripslashes($r['hNAME']).'</td>
<td><a href=viewuser.php?id='.$r['userid'].'
>'.stripslashes($r['username']).'</a></td>
<td>'.number_format($r['uhouseMood']).' Will bar</td>
<td>$'.number_format($r['uhouseRent']).'</td>
<td>'.number_format($r['uhouseRTime']).' nights</td>
<td><a href='.$_SERVER['PHP_SELF'].'?page=rentals&id='.$r['uhouseId'].'>Rent house</a></td>
</tr>';
}
print '</table>';
}
}
function rent_house()
{
echo '<p class="heading"><b>Rent Your House</b></p>';
echo '<table width="600">
<tr>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=estate">Estate agent</a></td>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=your_rents">Your rentals</a></td>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=rentals">Rent a house</a></td>
</tr>
</table>';
global $ir;
$fetch = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseOwner` = '%u') AND (`uhouseId` = '%u')", $ir['userid'], abs((int) $_GET['id'])));
if(!isset($_GET['id']))
{
echo 'You did not select a house to rent out to members.';
}
else if(!mysql_num_rows($fetch))
{
echo 'You cannot attempt to rent out a non-existant house.';
}
else
{
$r = mysql_fetch_assoc($fetch);
if($r['uhouseOwner'] != $ir['userid'])
{
echo 'You do not own this house, so don\'t attempt to rent it out to people.';
}
else if($r['uhouseTenant'])
{
echo 'You cannot rent out a house while it is being rented to another member.';
}
else
{
if(isset($_POST['time']) AND isset($_POST['cost']))
{
mysql_query(sprintf("UPDATE `owned_houses` SET `uhouseRent` = '%d', `uhouseRTime` = '%d' WHERE (`uhouseId` = '%u')", abs((int) $_POST['cost']), abs((int) $_POST['time']), abs((int) $_GET['id'])));
echo 'You have added the '.stripslashes($r['hNAME']).' the the rental market at a cost of $'.number_format($_POST['cost']).' per night.';
}
else
{
echo '<form action="'.$_SERVER['PHP_SELF'].'?page=rent&id='.$_GET['id'].'" method="post">
<table width="600">
<tr>
<td><b>Amount of nights:</b></td>
<td><input type="text" name="time" value="30" /></td>
</tr>
<tr>
<td><b>Cost per nights:</b></td>
<td><input type="text" name="cost" value="250" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit rental" /></td>
</tr>
</table>
</form>';
}
}
}
}
function your_rents()
{
echo '<p class="heading"><b>Your Current Rentals</b></p>';
echo '<table width="600">
<tr>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=estate">Estate agent</a></td>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=your_rents">Your rentals</a></td>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=rentals">Rent a house</a></td>
</tr>
</table>';
global $ir, $dbh;
error_reporting(E_ALL);
$sql = $dbh->prepare("SELECT * FROM owned_houses
LEFT JOIN houses ON (hID=uhouseHouse)
LEFT JOIN users ON (userid=uhouseOwner)
WHERE uhouseTenant=?");
$sql->bindParam(1, $ir['userid']);
$sql->execute();
echo '<table width="600" class="table">
<tr>
<th>House name</th>
<th>Owner</th>
<th>Will value</th>
<th>Cost each night</th>
<th>Nights left</th>
</tr>';
while($r = $sql->fetch())
{
echo '<tr>
<td>'.stripslashes($r['hNAME']).'</td>
<td><a href=viewuser.php?id='.$r['userid'].'>'.stripslashes($r['username']).'</a></td>
<td>'.number_format($r['uhouseMood']).' Will bar</td>
<td>$'.number_format($r['uhouseRent']).'</td>
<td>'.number_format($r['uhouseRTime']).' nights</td>
</tr>';
}
print '</table>';
}
function upgrade_house()
{
echo '<p class="heading"><b>House Upgrades</b></p>';
echo '<table width="600">
<tr>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=estate">Estate agent</a></td>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=your_rents">Your rentals</a></td>
<td width="33%" align="center"><a href="'.$_SERVER['PHP_SELF'].'?page=rentals">Rent a house</a></td>
</tr>
</table>';
global $ir;
if(!isset($_POST['id']))
{
if(isset($_GET['id']))
{
echo '<form action="'.$_SERVER['PHP_SELF'].'?page=upgrade&id='.$_GET['id'].'" method="post" name="upgrades">
<table class="table" width="600">
<tr>
<th width="45%">Upgrade name</th>
<th width="25%">Will gain</th>
<th width="25%">Cost</th>
<th width="5%"></th>
</tr>';
$fetch = mysql_query("SELECT * FROM `house_upgrades` ORDER BY `upgradeMood` ASC");
while ($r = mysql_fetch_assoc($fetch))
{
echo '<tr>
<td>'.stripslashes($r['upgradeName']).'</td>
<td>'.number_format($r['upgradeMood']).' Will</td>
<td>$'.number_format($r['upgradeCost']).'</td>
<td><input type="radio" name="id" value="'.$r['upgradeId'].'" onClick="document.upgrades.submit();" /></td>
</tr>';
}
echo '</table>';
}
else
{
echo 'You did not select a house to add upgrades to.';
}
}
else
{
$upgrade = mysql_query(sprintf("SELECT * FROM `house_upgrades` WHERE `upgradeId` = '%u'", abs((int) $_POST['id'])));
if(!mysql_num_rows($upgrade))
{
echo 'This upgrade does not exist at this time, if this problem continues report it to staff.';
}
else if(!isset($_GET['id']))
{
echo 'You did not select a house to add upgrades to.';
}
else
{
$house = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseId` = '%u')", abs((int) $_GET['id'])));
$h = mysql_fetch_assoc($house);
$r = mysql_fetch_array($upgrade);
if(!mysql_num_rows($house))
{
echo 'You cannot add upgrades to a non-existant house.';
}
else if($h['uhouseOwner'] != $ir['userid'])
{
echo 'You are not permitted to add upgrades to this house.';
}
else if($ir['money'] < $r['upgradeCost'])
{
echo 'You do not have enough cash to purchase this upgrade right now.';
}
else
{
$check = mysql_query(sprintf("SELECT * FROM `owned_upgrades` WHERE (`ownupHouse` = '%u') AND (`ownupUpgrade` = '%d')", abs((int) $_GET['id']), abs((int) $_POST['id'])));
if(mysql_num_rows($check))
{
echo 'This house has this upgrade at this time, it cannot be bought again.';
}
else
{
mysql_query(sprintf("UPDATE `users` SET `money` = `money` - '%d' WHERE `userid` = '%u'", $r['upgradeCost'], $ir['userid']));
mysql_query(sprintf("UPDATE `owned_houses` SET `uhouseMood` = `uhouseMood` + '%d' WHERE `uhouseId` = '%u'", $r['upgradeMood'], abs((int) $_GET['id'])));
mysql_query(sprintf("INSERT INTO `owned_upgrades` (`ownupId`, `ownupHouse`, `ownupUpgrade`) VALUES ('NULL','%u', '%d')", abs((int) $_GET['id']), abs((int) $_POST['id'])));
echo 'You have purchased the '.stripslashes($r['upgradeName']).' for $'.number_format($r['upgradeCost']).'.';
}
}
}
}
}
$h->endpage();
?>