-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
251 lines (224 loc) · 11.1 KB
/
index.php
File metadata and controls
251 lines (224 loc) · 11.1 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
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
date_default_timezone_set("America/New_York");
$obj = new program();
class program{
public function __construct() {
session_start();
if(isset($_REQUEST['class'])){
$class = $_REQUEST['class'];
$obj = new $class;
}else{
$obj = new homepage;
}
}
}
class page{
public $menu = '<a href="index.php?class=login">Login</a>
<br><a href="index.php?class=signup">Signup</a>';
public function __construct() {
if($_SERVER['REQUEST_METHOD'] == 'GET'){
$this->get();
}else{
$this->post();
}
}
public function get(){
echo '<a href="index.php?class=homepage">Homepage</a>';
echo '<a href="index.php?class=login">Login</a>';
echo '<a href="index.php?class=signup">Signup</a>';
}
public function post(){
print_r($_POST);
}
}
class homepage extends page {
public function get() {
echo '<body><h3>Welcome to the bank!</h3></body> <br>
<a href="index.php?class=login">Login<br></a> <br>
<a href="index.php?class=signup">Signup</a>';
}
}
class login extends page {
public $form = '<FORM action = "index.php?class=login" method="post">
<fieldset>
<LABEL for = "username">Username:</LABEL>
<INPUT type="text" name="username" id="username" required="required"><br>
<LABEL for = "password">Password:</LABEL>
<INPUT type="password" name="password" id="password" required="required"><br>
<INPUT type="submit" value="Send">
<INPUT type="reset">
</fieldset>
</FORM>';
public function get(){
echo $this->form;
}
public function post() {
$_SESSION['username'] = $_POST['username'];
$obj = new validation();
}
}
class signup extends page {
public $form = '<FORM action = index.php?class=signup method="post">
<fieldset>
<LABEL for = "first_name">First name:</LABEL>
<INPUT type="text" name="first_name" id="first_name" required="required"><BR>
<LABEL for = "last_name">Last name:</LABEL>
<INPUT type="text" name="last_name" id="last_name" required="required"><BR>
<LABEL for = "username">Choose a username:</LABEL>
<INPUT type="text" name="username" id="username" required="required"><BR>
<LABEL for = "password">Choose a password:</LABEL>
<INPUT type="password" name="password" id="password" required="required"><BR>
<LABEL for = "password_confirmation">Confirm your password:</LABEL>
<INPUT type="password" name="password_confirmation" id="password_confirmation" required="required"><BR>
<INPUT type="submit" value="Send">
<INPUT type="reset">
</fieldset>
</FORM>';
public function get(){
echo $this->form;
}
public function post() {
$this->passwdconf();
$handle = fopen('users.csv', 'a+');
$record = fgetcsv($handle, 0, ',');
if($record[0]!="First Name" && $record[1]!="Last Name" && $record[2]!="Username" && $record[3]!="Password" && $record[4]!="Account Number"){
fputcsv($handle, array('First Name', 'Last Name', 'Username', 'Password', 'Account Number'));
}
fclose($handle);
/*$row = 1;
if(($handle= fopen('users.csv', 'r'))!=FALSE){
while(($record = fgetcsv($handle, 0, ','))!=FALSE){
if($row==1){
$keys = $record;
$row++;
}else{
$records[] = array_combine($keys, $record);
}
}
}
fclose($handle);*/
$account_num = mt_rand(1111111, 9999999);
$user_info = array();
$user_info[] = $_POST['first_name'];
$user_info[] = $_POST['last_name'];
$user_info[] = $_POST['username'];
$user_info[] = $_POST['password'];
$user_info[] = $account_num;
$handle = fopen('users.csv', 'a+');
fputcsv($handle, $user_info);
echo 'Welcome, ' . $_POST['first_name'] . '. Your account number is ' . $account_num . '.<br><br>';
echo '<a href="index.php?class=transaction">Enter transactions</a><br><a href="index.php?class=signout">Signout</a>';
fclose($handle);
}
function passwdconf(){
if($_POST['password']!==$_POST['password_confirmation']){
echo 'Passwords don\'t match! <br> <a href="index.php?class=signup">Go back to signup</a>' ;
die();
}
}
}
class validation{
public function __construct() {
$row = 1;
if(($handle=fopen('users.csv', 'r'))!=FALSE){
while (($record = fgetcsv($handle, 0, ','))!=FALSE){
if($row==1){
$keys = $record;
$row++;
}else{
$records[] = array_combine($keys, $record);
}
}
function makePrimaryKey($key_name, $records){
foreach ($records as $record) {
$index_name = $record[$key_name];
unset($record[$key_name]);
$new_records[$index_name] = $record;
}
return($new_records);
}
$sorted_records = makePrimaryKey('Username', $records);
fclose($handle);
print_r($sorted_records);
}
$username_posted = $_POST['username'];
$password_posted = $_POST['password'];
if(array_key_exists($username_posted, $sorted_records) && $password_posted==$sorted_records[$username_posted]['Password']){
echo 'Welcome, ' . $sorted_records[$username_posted]['First Name'] . '!<BR><BR><a href="index.php?class=transaction">Enter transactions</a><BR><BR><a href="index.php?class=signout">Signout</a>';
}elseif (!array_key_exists($username_posted, $sorted_records)) {
echo 'We could not find you in our records. Please sign up <a href="index.php?class=signup">here</a>';
}elseif($password_posted !== $sorted_records[$username_posted]['Password']){
echo 'Username and password don\'t match. Please try again<BR><BR> <a href="index.php?class=login">Login</a>';
}
}
}
class transaction{
public $old_bal;
public $new_bal;
public $form= '<FORM action="index.php?class=transaction" method="post">
<fieldset>
<LABEL for="amount">Amount:</LABEL>
<INPUT type="number" name="amount" id="amount"><BR>
<LABEL for="source">Source:</LABEL>
<INPUT type="text" name="source" id="source"><BR>
<INPUT type="radio" name="type" value="debit">Debit<BR>
<INPUT type="radio" name="type" value="credit">Credit<BR>
<INPUT type="submit" vaule="Send"><INPUT type="reset">
</fieldset>
</FORM>';
public function __construct() {
if($_SERVER['REQUEST_METHOD']=='GET'){
$this->get();
}else{
$this->post();
}
}
public function get(){
echo $this->form . '<BR><BR><a href="index.php?class=signout">Signout</a>';
}
public function post(){
if($_POST['type']=='debit'){
echo $this->form . '<BR><BR>You have spent $' . $_POST['amount'] . ' at ' . $_POST['source'] .'.<BR<BR>';
}else{
echo $this->form . '<BR><BR>You have been credited $' . $_POST['amount'] . ' from ' . $_POST['source'] . '.';
}
$obj = new calculation;
echo '<BR><BR><a href="index.php?class=signout">Signout</a>';
}
}
class calculation{
public function __construct() {
/*if(($handle=fopen($_SESSION['username'] . '.csv', 'a+'))!=FALSE){
while(($record=fgetcsv($handle, 0, ','))!=FALSE){
$data[]=$record;
print_r($data);
}
fclose($handle);
}*/
$this->transaction_data();
}
public function set_old_bal($old_bal){
}
public function transaction_data(){
$data = array($this->old_bal, $this->new_bal, $_POST['amount'], $_POST['source'], $_POST['type'], date('m-d-Y \a\t g:i:s a'));
print_r($data);
$handle = fopen($_SESSION['username'] . '.csv', 'a+');
fputcsv($handle, $data);
}
}
class signout{
public function __construct() {
session_destroy();
header("location:index.php");
}
}
?>
</body>
</html>