-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbudget.php
More file actions
150 lines (118 loc) · 3.58 KB
/
budget.php
File metadata and controls
150 lines (118 loc) · 3.58 KB
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
<?php
session_start();
include('functions.php');
if (!isset($_SESSION['auth'])) {
$_SESSION['msg'] = "You must log in first";
header('location: login.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['auth']);
header("location: login.php");
}
$user = $_SESSION['User'];
update_accounts();
$query = "SELECT 1 FROM Budget.Target_$user LIMIT 1";
$val = mysqli_query($db, $query);
if($val == FALSE)
{
create_default_target();
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css">
</head>
<body>
<div class="header" style="border-bottom: 8px solid #f2e711;">
<h2 class="Welcome">Nigga rigged accounting (beta)</h2>
<div class="relative">
<style>
a {
text-decoration: none;
color: #ffffff;
}
</style>
</div>
<?php $site = basename(__FILE__, '.php');
include('server.php');
home_bar($site);
?>
<!-- Test table with db data -->
<table style="margin-left:10%; width: 80%; border-radius:0px;" border="2">
<tbody>
<tr>
<strong>
<td><strong>Category </strong></td>
<td><strong>Current set budget</strong></td>
</tr>
<?php
summary_budget();
?>
</tbody>
</table>
<form style="height:100%; width:90%; margin: auto;" method="post" action="budget.php" enctype="multipart/form-data">
<?php include('errors.php'); ?>
<?php
$bills = calc_bills($user);
$query = "UPDATE Budget.Target_$user SET Amount = '$bills' WHERE Category = 'Bills'";
mysqli_query($db,$query);
// second loop taking all incomes matching account number
$query = "SELECT * FROM Budget.Budget_$user";
$result = mysqli_query($db, $query);
while($row = mysqli_fetch_assoc($result)) {
$set_amount = $row['Created'];
// $amount = number_format($set_amount, 2, '.', '');
$amount = convert_number($set_amount);
$budget_total += $amount;
// printf("$budget_total \n");
}
echo "<H2> Changing your budget? Your current cycle budget is: $budget_total </H2>";
?>
<div>
<!-- event head -->
<form style="height:100%; width:90%; margin: auto;" method="post" action="bills.php" enctype="multipart/form-data">
<?php include('errors.php'); ?>
<?php
$array = category_array();
foreach ($array as $value) {
if ( $value != 'Bills' ) {
$tmp = convert_number(fetch_target($value));
$san_value = sanatize_category($value);
echo "<div class=\"input-group\" style=\"width:50%; margin:auto;\"> ";
echo "<lable> $value </lable>";
echo "<input type=\"number\" placeholder=\"$tmp\" value=\"$tmp\" name=\"amount_$san_value\" step=\"0.25\" min=\"0\" >";
echo "</div>";
}
}
?>
<div class="input-group">
<button style="margin-left:25%;" type="submit" class="btn-login" name="budget_update">Submit Change</button>
</div>
</form>
</body>
</html>
<?php
if (isset($_POST['budget_update'])) {
$array = category_array();
foreach ($array as $value) {
$san_value = sanatize_category($value);
$tmp = convert_number(mysqli_real_escape_string($db, $_POST["amount_$san_value"]));
$query0 = "UPDATE Budget.Target_$user SET Amount = '$tmp' WHERE Category = '$san_value'";
reset_budget();
$query1 = "UPDATE Budget.Bills SET Bill_stus = '0' WHERE Bill_owner = '$user'";
// var_dump($query0);
// var_dump($query1);
mysqli_query($db, $query0);
mysqli_query($db, $query1);
category_bills($user);
echo '<script type="text/javascript">';
echo "alert('Budget set for ".$value." !');";
echo 'window.location.href = "bills.php";';
echo '</script>';
}
}
?>