-
Notifications
You must be signed in to change notification settings - Fork 2
/
orders.php
111 lines (77 loc) · 3.65 KB
/
orders.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
<?php include("header.php"); ?>
<script>
$("#signup").on('shown.bs.modal', function() {
console.log('toggle');
$("#login").modal('toggle');
})
</script>
<?php
var_dump($_POST);
if (isset($_POST["user_address"])) {
try {
$m = new MongoDB\Client("mongodb://vinay0410:[email protected]:23725/pizza");
$collection = $m->selectCollection("pizza", "orders");
$document = ["user_id" => new MongoDB\BSON\ObjectID($_POST["user_id"]), "outlet_id" => new MongoDB\BSON\ObjectID($_POST["outlet_id"]), "user_address" => $_POST["user_address"], "cart_contents" => $_POST["cart_contents"] ];
$collection->insertOne($document);
} catch (MongoDB\Driver\Exception\ConnectionTimeoutException $e) {
//die("Caught Exception failed to Connect".$e->getMessage()."\n");
$error_order_msg = "Couldn't Connect to Database, Please try again";
} catch (Exception $e) {
$error_order_msg = $e->getMessage();
}
}
try {
$m = new MongoDB\Client("mongodb://vinay0410:[email protected]:23725/pizza");
$collection = $m->selectCollection("pizza", "orders");
$orders_cursor = $collection->find([], ['_id' => -1])->toArray();
$order_count = count($orders_cursor);
} catch (MongoDB\Driver\Exception\ConnectionTimeoutException $e) {
//die("Caught Exception failed to Connect".$e->getMessage()."\n");
$error_order_msg = "Couldn't Connect to Database, Please try again";
} catch (Exception $e) {
$error_order_msg = $e->getMessage();
}
?>
<div class="container pb-modalreglog-container">
<div class="panel panel-default">
<div class="panel-heading"><h3>Your Orders</h3>
<?php if (isset($error_order_msg)) {
?>
<div id="error" class="alert alert-danger" role="alert"><?php echo $error_order_msg; ?></div>
<?php
} ?>
</div>
<div class="panel-body" id="accordion">
<div class="panel list-group">
<?php
if (isset($order_count) or isset($orders_cursor)) {
if ($order_count == 0 && empty($error_order_msg)) {
echo "<p>Oh, You haven't ordered anything yet!</p>";
} else {
$index = 0;
?>
<div class="list-group" id="orders">
<?php
foreach ($orders_cursor as $document) {
$collection = $m->selectCollection("pizza", "outlets");
$outlet = $collection->findOne(["_id" => $document["outlet_id"]], ['typeMap' => ['document' => 'array', 'root' => 'array']]);
$collection = $m->selectCollection("pizza", "users");
$user = $collection->findOne(["_id" => $document["user_id"]], ['typeMap' => ['document' => 'array', 'root' => 'array']]);
?>
<a class="list-group-item">
<h4 class="list-group-item-heading"><div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40"
aria-valuemin="0" aria-valuemax="100" style="width:40%">
40% Complete (success)
</div>
</div></h4>
<p class="list-group-item-text"><?php echo $outlet['outlet']; ?></p>
<p class="list-group-item-text"><?php echo $user['fname'] . " " . $row['lname']; ?></p>
</a>
<?php
}
}
}
?>
</div>
<?php include("footer.php"); ?>