-
Notifications
You must be signed in to change notification settings - Fork 1
/
bonus.php
149 lines (146 loc) · 5.55 KB
/
bonus.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
function renderbonus($mysqli)
{
echo "<form method =\"POST\" id=\"namebutton\" action=\"./\"><input class=\"namebutton\" type=\"submit\" value=\"Return to chore list\"/>
<input name=\"action\" type=\"hidden\" id=\"i\" value=\"chorelist\"/>
<input name=\"userid\" type=\"hidden\" id=\"i\" value=\"" . $_REQUEST['userid'] . "\"/>
</form><p>\n";
echo "<form method =\"POST\" id=\"namebutton\" action=\"./\"><input class=\"namebutton\" type=\"submit\" value=\"Return Home\"/></form><p>\n\n";
if (isset($_REQUEST['code']))
{
$statement = $mysqli->prepare("select u.realname, u.id, u.pin from users u where u.id = ?");
$statement->bind_param('i', $_REQUEST['approver']);
if ($statement->execute())
{
$statement->store_result();
$statement->bind_result($approvername, $approver, $code);
if ($statement->num_rows > 0)
{
$statement->fetch();
if ($code == $_REQUEST['code'])
{
echo "Approved by " . $approvername . "<br>";
$statement = $mysqli->prepare("select a.id, (c.pay * ?), c.pay from assignments a join chores c on c.id = a.chore_id where a.id = ?");
$statement->bind_param('ii',$_REQUEST['count'],$_REQUEST['assignment']);
if ($statement->execute())
{
$statement->store_result();
$statement->bind_result($assignment, $pay, $payrate);
if ($statement->num_rows > 0)
{
$statement->fetch();
echo "Pay of $" . $pay . " for ".$_REQUEST['count']." at ".$payrate."<br>";
$statement = $mysqli->prepare("insert into activity (date, timestamp, assignment_id, user_id, payrate, quantity) values (CURDATE(), NOW(), ?, ?, ?, ?)");
$statement->bind_param('iidi', $_REQUEST['assignment'], $_REQUEST['userid'], $payrate, $_REQUEST['count']);
$statement->execute();
$statement->store_result();
echo $statement->num_rows;
}
}
}
}
}
}
else
{
?>
<form id="keyform" action="./" method="POST" action="./">
<input name="action" type="hidden" id="i" value="choreapprove"/>
<?php echo "<input name=\"userid\" type=\"hidden\" id=\"i\" value=\"" . $_REQUEST['userid'] . "\"/>
<input name=\"approver\" type=\"hidden\" id=\"i\" value=\"" . $_REQUEST['approver'] . "\"/>
<input name=\"assignment\" type=\"hidden\" id=\"i\" value=\"" . $_REQUEST['assignment'] . "\"/>" ?>
<table id="keypad" cellpadding="5" cellspacing="3">
<tr>
<td onclick="addCode('1');">1</td>
<td onclick="addCode('2');">2</td>
<td onclick="addCode('3');">3</td>
</tr>
<tr>
<td onclick="addCode('4');">4</td>
<td onclick="addCode('5');">5</td>
<td onclick="addCode('6');">6</td>
</tr>
<tr>
<td onclick="addCode('7');">7</td>
<td onclick="addCode('8');">8</td>
<td onclick="addCode('9');">9</td>
</tr>
<tr>
<td onclick="addCode('*');">*</td>
<td onclick="addCode('0');">0</td>
<td onclick="addCode('#');">#</td>
</tr>
</table>
<input type="password" name="code" value="" maxlength="4" class="display" readonly="readonly" /><br>
<?php
$statement = $mysqli->prepare("select c.name, c.description, c.pay, a.id, a.assigned_user, c.max from chores c join assignments a on a.chore_id = c.id join users u on a.assigned_user = u.id where a.assigned_user = ? and a.id = ?");
$statement->bind_param('ii', $_REQUEST['userid'], $_REQUEST['assignment']);
if ($statement->execute())
{
$statement->store_result();
$statement->bind_result($chore, $description, $pay, $assignment, $user, $max);
if ($statement->num_rows > 0)
{
$statement->fetch();
if ($max > 1)
{
?>
<label for="count">Choose how many you did:</label>
<select name="count" id="count" class="select-css">
<?php
for ($cnt = 1;$cnt <= $max;$cnt++)
{
if ($cnt == $_REQUEST['count'])
{
echo "<option value =\"" . $cnt . "\" selected>" . $cnt . "</option>\n";
}
else
{
echo "<option value =\"" . $cnt . "\">" . $cnt . "</option>\n";
}
}
?></select><br>
<?php
} else {
echo "<input name=\"count\" type=\"hidden\" id=\"i\" value=\"1\"/>";
}
}
}
$statement = $mysqli->prepare("select u.realname, u.id from users u where u.id != ? and u.type < 3");
$statement->bind_param('i', $_REQUEST['userid']);
if ($statement->execute())
{
$statement->store_result();
$statement->bind_result($approvername, $approverid);
if ($statement->num_rows > 0)
{
?>
<label for="approver">Who is approving the chore?</label>
<select name="approver" id="approver" class="select-css"><?php
while ($statement->fetch())
{
echo "<option value =\"" . $approverid . "\">" . $approvername . "</option>\n";
}
?></select><?php
}
}
?>
<p id="message">VERIFYING...</p>
</form>
<script type="text/javascript">
function addCode(key){
var code = document.getElementById("keyform").code;
if(code.value.length < 4){
code.value = code.value + key;
}
if(code.value.length == 4){
document.getElementById("message").style.display = "block";
setTimeout(submitForm,1000);
}
}
function submitForm(){
document.getElementById("keyform").submit();
}
function emptyCode(){
document.getElementById("keyform").code.value = "";
}
</script>