-
Notifications
You must be signed in to change notification settings - Fork 8
/
job.php
246 lines (242 loc) · 6.05 KB
/
job.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
<?php
declare(strict_types=1);
/**
* MCCodes v2 by Dabomstew & ColdBlooded
*
* Repository: https://github.com/davemacaulay/mccodesv2
* License: MIT License
*/
$jobquery = 1;
global $db, $ir, $userid, $h;
require_once('globals.php');
$_GET['interview'] =
(isset($_GET['interview']) && is_numeric($_GET['interview']))
? abs(intval($_GET['interview'])) : '';
if (!$ir['job'])
{
if (!$_GET['interview'])
{
echo '
You do not yet have a job. A list of jobs is available below.
<br />
';
$q =
$db->query(
'SELECT `jID`,`jDESC`,`jNAME`
FROM `jobs`');
while ($r = $db->fetch_row($q))
{
echo "
> {$r['jNAME']} - {$r['jDESC']} - <a href='job.php?interview={$r['jID']}'>Go to interview</a>
<br />
";
}
$db->free_result($q);
}
else
{
$q =
$db->query(
"SELECT `jOWNER`, `jrID`, `jrIQN`, `jrLABOURN`,
`jrSTRN`
FROM `jobs` AS `j`
INNER JOIN `jobranks` AS `jr`
ON `j`.`jFIRST` = `jr`.`jrID`
WHERE `j`.`jID` = {$_GET['interview']}");
if ($db->num_rows($q) == 0)
{
$db->free_result($q);
print 'Invalid job specified.';
$h->endpage();
exit;
}
$r = $db->fetch_row($q);
$db->free_result($q);
echo "
{$r['jOWNER']}: So {$ir['username']}, you were looking for a job with us?
<br />
{$ir['username']}: Yes please!
<br />
";
if ($ir['strength'] >= $r['jrSTRN']
&& $ir['labour'] >= $r['jrLABOURN']
&& $ir['IQ'] >= $r['jrIQN'])
{
$db->query(
"UPDATE `users`
SET `job` = {$_GET['interview']}, `jobrank` = {$r['jrID']}
WHERE `userid` = $userid");
echo "
{$r['jOWNER']}: Okay {$ir['username']}, we're good to go, see you tomorrow.
<br />
{$ir['username']}: Thanks!
<br />
> <a href='index.php'>Go Home</a>
";
}
else
{
echo "
{$r['jOWNER']}: Sorry {$ir['username']}, you're not far enough in the game to work in this job. You'll need:
";
if ($ir['strength'] < $r['jrSTRN'])
{
$s = $r['jrSTRN'] - $ir['strength'];
echo " $s more strength, ";
}
if ($ir['labour'] < $r['jrLABOURN'])
{
$s = $r['jrLABOURN'] - $ir['labour'];
echo " $s more labour, ";
}
if ($ir['IQ'] < $r['jrIQN'])
{
$s = $r['jrIQN'] - $ir['IQ'];
echo " $s more IQ, ";
}
echo "
before you'll be able to work here!
<br />
> <a href='index.php'>Go Home</a>
";
}
}
}
else
{
if (!isset($_GET['action']))
{
$_GET['action'] = '';
}
switch ($_GET['action'])
{
case 'quit':
quit_job();
break;
case 'promote':
job_promote();
break;
default:
job_index();
break;
}
}
/**
* @return void
*/
function job_index(): void
{
global $db, $ir;
echo "
<h3>Your Job</h3>
You currently work in the {$ir['jNAME']}! You receive "
. money_formatter($ir['jrPAY'])
. " each day at 5pm!
<br />
You also receive {$ir['jrIQG']} IQ, {$ir['jrSTRG']} strength, and {$ir['jrLABOURG']} labour!
<br />
<table width='50%' cellspacing='1' class='table'>
<tr>
<td>Strength: {$ir['strength']}</td>
<td>IQ: {$ir['IQ']}</td>
</tr>
<tr>
<td>Labour: {$ir['labour']}</td>
<td>Job Rank: {$ir['jrNAME']}</td>
</tr>
</table>
<b>Job Ranks</b>
<br />
<table width='75%' cellspacing='1' class='table'>
<tr>
<th>Title</th>
<th>Pay</th>
<th>Strength Reqd</th>
<th>IQ Reqd</th>
<th>Labour Reqd</th>
</tr>
";
$q =
$db->query(
"SELECT `jrNAME`, `jrPAY`, `jrSTRN`, `jrIQN`, `jrLABOURN`
FROM `jobranks`
WHERE `jrJOB` = {$ir['job']}
ORDER BY `jrPAY` ASC");
while ($r = $db->fetch_row($q))
{
echo "
<tr>
<td>{$r['jrNAME']}</td>
<td>" . money_formatter($r['jrPAY'])
. "</td>
<td>{$r['jrSTRN']}</td>
<td>{$r['jrIQN']}</td>
<td>{$r['jrLABOURN']}</td>
</tr>
";
}
$db->free_result($q);
echo "
</table>
<br />
> <a href='job.php?action=promote'>Try To Get Promoted</a>
<br />
> <a href='job.php?action=quit'>Quit</a>
";
}
/**
* @return void
*/
function job_promote(): void
{
global $db, $ir, $userid;
$q =
$db->query(
"SELECT `jrID`,`jrNAME`
FROM `jobranks`
WHERE `jrPAY` > {$ir['jrPAY']}
AND `jrSTRN` <= {$ir['strength']}
AND `jrLABOURN` <= {$ir['labour']}
AND `jrIQN` <= {$ir['IQ']} AND `jrJOB` = {$ir['job']}
ORDER BY `jrPAY` DESC
LIMIT 1");
if ($db->num_rows($q) == 0)
{
echo "
Sorry, you cannot be promoted at this time.
<br />
> <a href='job.php'>Go Back</a>
";
}
else
{
$r = $db->fetch_row($q);
$db->query(
"UPDATE `users`
SET `jobrank` = {$r['jrID']}
WHERE `userid` = $userid");
echo "
Congrats, you have been promoted to {$r['jrNAME']}.
<br />
> <a href='job.php'>Go Back</a>
";
}
$db->free_result($q);
}
/**
* @return void
*/
function quit_job(): void
{
global $db, $userid;
$db->query(
"UPDATE `users`
SET `job` = 0, `jobrank` = 0
WHERE `userid` = $userid");
echo "
You have quit your job!
<br />
> <a href='job.php'>Go Back</a>
";
}
$h->endpage();