/
index.php
188 lines (156 loc) · 8.29 KB
/
index.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
<?php
require 'UsersDatabase.php';
require 'PropertiesDatabase.php';
require 'helpers/adminManager.php';
session_start();
// Array to store login errors if they occur
$loginerrors = isset($_SESSION['loginerrors']) ? $_SESSION['loginerrors'] : [];
$fields= isset($_SESSION['fields']) ? $_SESSION['fields'] : [];
// Database connections
$usersData = new UsersDatabase('data/users.json');
$propertiesData = new PropertiesDatabase('data/properties.json');
if ( isset($_SESSION['username']) ) {
$username = $_SESSION['username'];
$name= $usersData->userFullName($username);
$properties = $propertiesData->buyableProperties($username);
}
?>
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>100Acres - Buy Sell Properties</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<!-- <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700' rel='stylesheet' type='text/css'> -->
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div class="container">
<?php if( !empty($_SESSION['buyingConfirmation'])): ?>
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<strong><?php echo $_SESSION['buyingConfirmation']; ?></strong>
</div>
<?php endif; ?>
<?php if( !isset($_SESSION['username']) ): ?>
<center><h1 class ="loginBox__topHeading">Welcome to 100acres!</h1></center>
<?php if ( !empty($loginerrors) ) : ?>
<div class="alert alert-danger loginBox__errorbox">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<?php echo $loginerrors[0];?>
</div>
<?php endif; ?>
<div class="loginBox">
<form action="login.php" method="POST" role="form">
<div class="form-group">
<input type="text" class="form-control loginBox__input" id="" placeholder="Username" name = "username" <?php echo !empty($fields) ? 'value="'. $fields['username'] .'"' : ''; ?>>
<input type="password" class="form-control loginBox__input" id="" placeholder="Password" name="password">
</div>
<center><button type="submit" class="btn btn-lg btn-primary loginBox__button">Login</button></center>
</form>
</div>
<?php endif; ?>
<?php if( isset($_SESSION['username']) ): ?>
<div class="header">
<div class="row">
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4 header__userinfo">
<i class="fa fa-user"></i> <a href="#"><?php echo $name; ?></a>
</div>
<div class="col-xs-8 col-sm-8 col-md-8 col-lg-8">
<button type="button" class="btn btn-danger header__button--logout" onclick="location.href='./logout.php'"><i class="fa fa-sign-out"></i> LOG OUT</button>
<?php if( isAdmin($username) ): ?>
<button type="button" class="btn btn-primary header__button" data-toggle="modal" data-target="#modal_adduser"><i class="fa fa-user-plus"></i> ADD USER</button>
<button type="button" class="btn btn-primary header__button--report" onclick="location.href='./report.php'"><i class="fa fa-file"></i> SALES REPORT</button>
<?php endif; ?>
<button type="button" class="btn btn-success header__button--sell" data-toggle="modal" data-target="#modal_addproperty"><i class="fa fa-plus"></i> SELL</button>
</div>
</div>
</div>
<div class="content">
<center><h4><?php if( empty($properties) ) echo "There are no properties available to buy :-( Check back soon"; ?></h4></center>
<?php foreach($properties as $id => $property): ?>
<a href= <?php echo "buyproperty.php?propertyId=". $id . "&buyer=" . $username; ?> class = "propertyCard">
<!-- <div class="propertyCard"> -->
<div class="propertyCard__buyIndicator">BUY THIS PROPERTY</div>
<span class="propertyCard__name"><?php echo $property['name'] ?></span><br/>
<span class="propertyCard__location"><?php echo $property['location'] ?></span><br/>
<span class = "propertyCard__price">₹<?php echo $property['price'] ?></span>
<!-- </div> -->
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<!-- Modal window to add new user -->
<div class="modal fade" id="modal_adduser">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Add New User</h4>
</div>
<div class="modal-body">
<form action="adduser.php" method="POST" role="form">
<div class="form-group">
<label for="">Username</label>
<input type="text" class="form-control" id="" placeholder="Must be unique" name="username">
<label for="">First Name</label>
<input type="text" class="form-control" id="" placeholder="e.g. John" name="firstname">
<label for="">Last Name</label>
<input type="text" class="form-control" id="" placeholder="e.g. Doe" name = "lastname">
<label for="">Password</label>
<input type="password" class="form-control" id="" placeholder="" name="password">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Modal window to sell new property -->
<div class="modal fade" id="modal_addproperty">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Add new Property for sale</h4>
</div>
<div class="modal-body">
<form action="addproperty.php" method="POST" role="form">
<div class="form-group">
<label for="">Name</label>
<input type="text" class="form-control" id="" placeholder="e.g. Sea side quarters" name="name">
<label for="">Location</label>
<input type="text" class="form-control" id="" placeholder="e.g. Icchanath, Surat" name="location">
<label for="">Price</label>
<input type="text" class="form-control" id="" placeholder="in INR" name = "price">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script src = "js/jquery.min.js"></script>
<script src = "js/bootstrap.min.js"></script>
</body>
</html>
<?php
unset($_SESSION['loginerrors']);
unset($_SESSION['buyingConfirmation']);
?>