forked from vignesh-82coder/Foodereum
-
Notifications
You must be signed in to change notification settings - Fork 1
/
trackproduct.php
234 lines (198 loc) · 6.78 KB
/
trackproduct.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
<!-- Track product -->
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="SHORTCUT ICON" href="images/fe.png" type="image/x-icon" />
<link rel="ICON" href="images/fe.png" type="image/ico" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/mdbmin.css" rel="stylesheet">
<link href="css/mdb.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<title>Foodereum - Track Products</title>
<style>
.scrollbar{
height: 350px;
width: 40%;
padding: 15px;
border-radius: 20px;
background: #fff;
overflow-y: scroll;
box-shadow: 0 3px 6px rgba(0,0,0,0.20), 0 3px 6px rgba(0,0,0,0.23);
}
.scrollbar-primary::-webkit-scrollbar {
width: 7px;
background-color: #F5F5F5;
}
.scrollbar-primary::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.1);
background-color: #000000;
}
.scrollbar-primary {
scrollbar-color: #000000 #F5F5F5;
}
</style>
</head>
<?php
if(isset($_SESSION['role'])){
?>
<?php if (isset($_SESSION['role']) && $_SESSION['role']) { ?>
<div <?php if($_SESSION['role']!='6') { ?> id="loggedIn" <?php } ?>></div>
<?php } ?>
<body class="violetgradient">
<?php
include "navbar.php"
?>
<center>
<div class="customalert">
<div class="alertcontent"><i><b>Track Products</b></i>
<div id="alertText">   </div>
<img id="qrious">
<div id="bottomText" style="margin-top: 10px; margin-bottom: 15px;">   </div>
<button id="closebutton" class="formbtn"> OK </button>
</div>
</div>
</center>
<div>
<center>
<div class="centered">
<form role="form" autocomplete="off">
<h3 style="margin-top: 80px;">Track Product Here.</h3>
<input type="text" id="searchText" class="searchBox" placeholder="Enter Product ID To Track" onkeypress="isInputNumber(event)" required>
<label class=qrcode-text-btn style="width:4%;display:none;">
<input type=file accept="image/*" id="selectedFile" style="display:none" capture=environment onchange="openQRCamera(this);" tabindex=-1>
</label>
<button type="submit" id="searchButton" class="searchBtn"><i class="fa fa-search"></i></button>
</form>
<br>
<h6>OR </h6>
<button class="qrbutton" onclick="document.getElementById('selectedFile').click();">
<i class='fa fa-qrcode'></i> Scan QR
</button>
<br>
<p id="database" class="scrollbar scrollbar-primary">
No Data to Display
</p>
</div>
</center>
</div>
<div class='box'>
<div class='wave -one'></div>
<div class='wave -two'></div>
<div class='wave -three'></div>
</div>
<?php }else{
include 'redirection.php';
redirect("index.php");
} ?>
<!-- JQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/mdb.min.js"></script>
<script src="web3.min.js"></script>
<script src="app.js"></script>
<!-- QR Code Reader -->
<script src="https://rawgit.com/sitepoint-editors/jsqrcode/master/src/qr_packed.js"></script>
<!-- Web3 Injection -->
<script>
web3 = new Web3(new Web3.providers.HttpProvider('HTTP://127.0.0.1:7545'));
// Set the Contract
var contract = new web3.eth.Contract(contractAbi, contractAddress);
$(".scrollbar").hide();
$('form').on('submit', function(event) {
event.preventDefault(); // to prevent page reload when form is submitted
greeting = $('input').val();
console.log(greeting)
contract.methods.searchProduct(greeting).call(function(err, result) {
console.log(err, result)
$(".scrollbar").show("fast","linear");
$("#database").html(result);
});
});
function isInputNumber(evt){
var ch = String.fromCharCode(evt.which);
if(!(/[0-9]/.test(ch))){
evt.preventDefault();
}
}
$("#closebutton").on("click", function(){
$(".customalert").hide("fast","linear");
});
function openQRCamera(node) {
var reader = new FileReader();
reader.onload = function() {
node.value = "";
qrcode.callback = function(res) {
if(res instanceof Error) {
alert("No QR code found. Please make sure the QR code is within the camera's frame and try again.");
} else {
node.parentNode.previousElementSibling.value = res;
document.getElementById('searchButton').click();
}
};
qrcode.decode(reader.result);
};
reader.readAsDataURL(node.files[0]);
}
function showAlert(message){
$("#alertText").html(message);
$("#qrious").hide();
$("#bottomText").hide();
$(".customalert").show("fast","linear");
}
$("#aboutbtn").on("click", function(){
showAlert("Allow users to Track food products using QR codes or Product IDs.");
});
$(document).ready(function() {
if($('#loggedIn')) {
getNotification();
setInterval(function(){ getNotification(); }, 20000);
}
});
function getNotification() {
if (!Notification) {
$('body').append('<h4 style="color:red">*Browser does not support Web Notification</h4>');
return;
}
if (Notification.permission !== "granted") {
Notification.requestPermission();
} else {
$.ajax({
url : "notification.php",
type: "POST",
success: function(response, textStatus, jqXHR) {
var response = jQuery.parseJSON(response);
if(response.result == true) {
var notificationDetails = response.notif;
for (var i = notificationDetails.length - 1; i >= 0; i--) {
var notificationUrl = notificationDetails[i]['url'];
var notificationObj = new Notification(notificationDetails[i]['title'], {
icon: notificationDetails[i]['icon'],
body: notificationDetails[i]['message'],
});
notificationObj.onclick = function () {
window.open(notificationUrl);
notificationObj.close();
};
setTimeout(function(){
notificationObj.close();
}, 10000);
};
} else {
}
},
error: function(jqXHR, textStatus, errorThrown) {}
});
}
};
</script>
</body>
</html>