-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathinventory.php
339 lines (316 loc) · 17.3 KB
/
inventory.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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<?php
ob_start();
session_start();
require_once 'server/model/Enum.php';
require_once 'server/model/AdminLevel.php';
require_once 'server/AdminDAO.php';
require_once 'server/CarDAO.php';
require_once 'server/DiagramDAO.php';
require_once 'server/model/Admin.php';
require_once 'server/model/Paging.php';
$num_cars = null;
$rowCarField = null;
if (!isset($_SESSION['authenticated'])) {
header('Location: sign-in.php');
} else {
$p = new Paging();
define('RECORDS_PER_PAGE', 5);
$p->setRecordsPerPage(RECORDS_PER_PAGE);
$p->setPageQueryStr('rowNumber');
$p->setStartingRow($p->getPageRowNumber());
$q = new AdminDAO();
$admin_data = $q->getAdminByUsername($_SESSION['adminUsername']);
$v = new CarDAO();
$all_cars = $v->getAllCars();
$num_cars = $v->countAllCars();
$rowCarField = $v->getCarsLimitByRecPerPage($p->getStartingRow(), $p->getRecordsPerPage());
// adding general car info
if (!empty($_POST['add-car-submit'])) {
$isAddedCondition = $v->isCreated($_POST);
}
// displaying a car photos for deletion with ajax
$d = new DiagramDAO();
if (isset($_GET['action'])) {
if ($_GET['action'] === "getPhotosByCarId") {
$diagram = $d->getPhotosBy_CarId($_GET['id']);
$diagramJson = json_encode($diagram);
echo $diagramJson; // sent to ajax don't remove
exit();
}
}
// deleting a car photo
if (isset($_GET["action"])) {
if ($_GET["action"] === "deleteCarPhoto") {
$isDeletedPhoto = $d->isDeleted($_GET["id"]);
}
}
$adminLevel = $admin_data[0]->getAdminLevel();
$levelArray = AdminLevel::splitAdminLevelArray(intval($adminLevel));
$canRead = $canUpdate = $canInsert = $canDelete = '';
if (is_array($levelArray)) {
$canRead = in_array("READ", $levelArray) ? 'true' : 'false';
$canUpdate = in_array("UPDATE", $levelArray) ? 'true' : 'false';
$canInsert = in_array("INSERT", $levelArray) ? 'true' : 'false';
$canDelete = in_array("DELETE", $levelArray) ? 'true' : 'false';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Primary Meta Tags -->
<title>AutoExpress - Raymart De Guzman</title>
<meta name="title" content="AutoExpress - Raymart De Guzman">
<meta name="description" content="AutoExpress a car dealership app built for both car dealer and car buyer. A car dealer manages the car being viewed on the website by adding, updating, deleting and uploading photos of a car. On the other hand, a car buyer can search for the vehicle he or she desired on the website. If the buyer finds the desired vehicle he or she can contact the seller to get more information of the vehicle. A car buyer can also calculate their monthly or bi-weekly payment.">
<meta name="keywords" content="Raymart De Guzman, tramyardg.co.nf, tramyardg, PHP, car dealership, software engineer, car dealer, car buyer, AutoExpress.co.nf">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:title" content="AutoExpress.co.nf - Raymart De Guzman">
<meta property="og:description" content="AutoExpress a car dealership app built for both car dealer and car buyer. A car dealer manages the car being viewed on the website by adding, updating, deleting and uploading photos of a car. On the other hand, a car buyer can search for the vehicle he or she desired on the website. If the buyer finds the desired vehicle he or she can contact the seller to get more information of the vehicle. A car buyer can also calculate their monthly or bi-weekly payment.">
<meta property="og:image" content="https://raw.githubusercontent.com/tramyardg/autoexpress/master/image/homePage.PNG"/>
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/templatemo_main.css">
<link rel="stylesheet" href="css/datatables.min.css">
</head>
<body>
<div id="main-wrapper">
<div class="loader"></div>
<div class="template-page-wrapper">
<div class="templatemo-content-wrapper">
<div class="templatemo-content">
<ol class="breadcrumb">
<li><a href="dashboard.php">Admin Panel</a></li>
<li class="active">Manage Inventory</li>
</ol>
<input type="text" class="hidden" id="admin-username" name="admin-username" title="admin id"
value="<?php echo $admin_data[0]->getUsername(); ?>">
<h1>Manage Vehicles</h1>
<?php if (isset($isAddedCondition) && $isAddedCondition === 1) { ?>
<div class="loader show"></div>
<?php header("refresh: 1; url=inventory.php");
} ?>
<?php if (isset($isDeletedPhoto) && $isDeletedPhoto === 1) { ?>
<div class="loader show"></div>
<?php header("refresh: 1; url=inventory.php");
} ?>
<?php if (isset($isUpdatedCondition) && $isUpdatedCondition === 1) { ?>
<div class="loader show"></div>
<?php header("refresh: 1; url=inventory.php");
} ?>
<!-- car table -->
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table id="vehicle-table" class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th>Year</th>
<th>Make</th>
<th>Model</th>
<th>Price ($)</th>
<th>Status</th>
<th>Mileage (Kms)</th>
<th>Transmission</th>
<th>Drivetrain</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php while ($row = $rowCarField->fetch()) { ?>
<?php
$carId = $row['vehicleId'];
$toHash = $carId;
$toHash .= date("m.d.y");
$hash = sha1($toHash);
?>
<tr>
<td><?php echo $row['yearMade']; ?></td>
<td><?php echo $row['make'];?></td>
<td><?php echo $row['model']; ?></td>
<td><?php echo $row['price']; ?></td>
<td><?php echo $row['status']; ?></td>
<td><?php echo $row['mileage']; ?></td>
<td><?php echo $row['transmission']; ?></td>
<td><?php echo $row['drivetrain']; ?></td>
<td>
<div class="dropdown">
<button class="btn btn-primary btn-xs dropdown-toggle" type="button"
data-toggle="dropdown">Actions
<span class="caret"></span></button>
<ul class="dropdown-menu">
<?php if ($canUpdate == 'true') { ?>
<li>
<a href="updateCar.php?updateId=<?php echo $row['vehicleId'] . '&h=' . $hash; ?>">Update</a>
</li>
<?php } ?>
<?php if ($canDelete == 'true') { ?>
<li>
<a class="delete-vehicle"
href="?id=<?php echo $row['vehicleId']; ?>"
delete="<?php echo $row['vehicleId']; ?>">Delete</a>
</li>
<?php } ?>
<?php if ($canUpdate == 'true') { ?>
<li>
<a class="upload-car-photos"
href="?id=<?php echo $row['vehicleId']; ?>"
upload-delete-photos="<?php echo $row['vehicleId']; ?>">Manage
photo(s)</a>
</li>
<?php } ?>
</ul>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<nav aria-label="Page navigation example" class="<?php if($num_cars <= $p->getRecordsPerPage()) {echo 'hidden';} ?>">
<ul class="pagination">
<?php if($num_cars > $p->getRecordsPerPage()) { ?>
<?php if($p->getPrev() >= 0) { ?>
<li class="page-item"><a href="inventory.php?rowNumber=<?php echo $p->getPrev(); ?>">Previous</a></li>
<?php } ?>
<?php $pageNumber = 1; ?>
<?php for($i = 0; $i < $num_cars; $i = $i + $p->getRecordsPerPage()) { ?>
<?php if($i != $p->getStartingRow()) { ?>
<li class="page-item"><a href="inventory.php?rowNumber=<?php echo $i; ?>"><?php echo $pageNumber; ?></a></li>
<?php } else { ?>
<li class="page-item active"><a href="inventory.php?rowNumber=<?php echo $i; ?>"><?php echo $pageNumber; ?></a></li>
<?php } ?>
<?php $pageNumber = $pageNumber + 1; ?>
<?php } ?>
<?php if($p->getNext() < $num_cars) { ?>
<li class="page-item"><a href="inventory.php?rowNumber=<?php echo $p->getNext(); ?>">Next</a></li>
<?php } ?>
<?php } ?>
</ul>
</nav>
</div>
</div>
</div>
<!-- add new car button -->
<?php if ($canInsert == 'true') { ?>
<div class="row margin-bottom-15">
<div class="col-sm-12">
<button type="button" class="btn btn-success btn-sm" id="add-new-car-btn" data-toggle="modal"
data-target=".add-new-car-modal-lg">Add new
</button>
</div>
</div>
<?php } ?>
<!-- modal template for adding vehicle info -->
<?php if ($canInsert == 'true') { ?>
<div class="modal fade add-new-car-modal-lg " tabindex="-1" role="dialog"
aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="add-car-info-modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">×</span></button>
<h4 class="modal-title">Add New Vehicle</h4>
</div>
<div style="padding: 1em;" id="addCarContainer"></div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<!-- modal template for uploading and updating photos -->
<?php if ($canUpdate == 'true') { ?>
<div class="modal fade bs-example-modal-sm" id="upload-delete-car-photos-modal" tabindex="-1"
role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Upload or Delete Photos for this Vehicle</h4>
</div>
<div class="row">
<div class="col-md-12 margin-top-15">
<div class="col-md-12">
<div class="panel panel-warning">
<div class="panel-heading">Deleting photos...</div>
<div class="panel-body" id="display-images-by-this-car"></div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<form id="add-car-photos-form" enctype="multipart/form-data">
<div class="panel panel-info">
<div class="panel-heading">Upload photos for this car</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<p><b>Note</b>: Only image file types are allowed to be
uploaded, otherwise it will not work.</p>
<input type="file" id="files" name="files[]" multiple/>
<output id="list"></output>
</div>
<div class="col-md-12">
<input type="submit" name="upload-car-photos-btn" value="Submit" carid="null" />
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<script src="../js/jquery-3.1.1.min.js"></script>
<script src="../js/jquery.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/datatables.min.js"></script>
<script src="js/common/CommonTemplate.js"></script>
<script src="js/common/AdminPageTemplate.js"></script>
<script src="js/common/CommonUtil.js"></script>
<script src="js/routine/common-html.js"></script>
<script src="js/routine/car-actions.js"></script>
<script src="js/app.js"></script>
<script src="js/common/AddOrUpdateTemplate.js"></script>
<script type="text/javascript">
let adminAddCar = new AddOrUpdateTemplate('null');
let addCarContainerDiv = $('#addCarContainer');
addCarContainerDiv.empty();
addCarContainerDiv.append(adminAddCar.addOrUpdateCar_Container());
function previewSelectedImages(evt) {
let files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (let i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
let reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function (theFile) {
return function (e) {
// Render thumbnail.
let span = document.createElement('span');
span.innerHTML = ['<img model="thumb" id="car-image-' + i + '" src="', e.target.result,
'" title="', theFile.name, '"/>'].join('');
document.getElementById('list').insertBefore(span, null);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
document.getElementById('files').addEventListener('change', previewSelectedImages, false);
</script>
</body>
</html>