-
Notifications
You must be signed in to change notification settings - Fork 1
/
payout.php
57 lines (57 loc) · 2.3 KB
/
payout.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
<html>
<head>
<link rel="stylesheet" href="style.css">
<title>Chores UI parents page</title>
</head>
<body>
<?php
echo "<form method =\"POST\" id=\"namebutton\" action=\"./\"><input class=\"namebutton\" type=\"submit\" value=\"View today's list\"/>
<input name=\"action\" type=\"hidden\" id=\"i\" value=\"allchores\"/></form>";
include_once ("./config.php");
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($mysqli->connect_errno)
{
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
exit();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && time < $_REQUEST['timestamp'] + 60){
echo "Processing payout<br>";
$statement = $mysqli->prepare("UPDATE activity set paid = 1 where id = ?");
foreach ($_REQUEST['id'] as $aid){
echo "Paying ".$aid."<br>\n";
$statement->bind_param('i', $aid);
$statement->execute();
}
}
echo "<br>";
$statement = $mysqli->prepare("select date(date), u.realname, act.payrate * act.quantity as pay, act.id, ch.name from activity act left join users u on u.id = act.user_id left join assignments asg on act.assignment_id = asg.id left join chores ch on asg.chore_id = ch.id where date >= DATE_SUB(CURDATE(),INTERVAL 21 day) and date != curdate() and paid != 1 order by u.realname, date;");
$statement->execute();
$statement->store_result();
$statement->bind_result($date, $name, $pay, $id, $cname);
$maxid = 0;
if ($statement->num_rows > 0)
{
while ($statement->fetch())
{
$rows[$id]['date'] = $date;
$rows[$id]['name'] = $name;
$rows[$id]['pay'] = $pay;
$rows[$id]['id'] = $id;
$rows[$id]['name'] = $cname;
$pays[$name] = $pays[$name] + $pay;
echo $name." earned ". $pay ." on ".$date." for ".$cname."<br>\n";
}
}
//Print the payout list
foreach ( $pays as $name=>$pay ) {
echo $name . " earned $". money_format('%.2n',$pay). " since last payout.<br>\n";
}
//Build the form for payout
echo "<form method =\"POST\" id=\"namebutton\" action=\"./payout.php\">\n";
foreach ( $rows as $row ) {
echo "<input type=\"hidden\" id=\"id\" name=\"id[]\" value=\"".$row['id']."\"/>\n";
}
echo "<input class=\"namebutton\" type=\"submit\" value=\"Pay all\"/><input id=\"timestamp\" name=\"timestamp\" type=\"hidden\" value=\"".time()."\"/>\n</form>";
?>
</body>
</html>