-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckproduct.php
152 lines (128 loc) · 4.53 KB
/
checkproduct.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
<?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">
<title>Grp61 - Supply Chain DAPP</title>
<link rel="SHORTCUT ICON" href="images/fibble.png" type="image/x-icon" />
<link rel="ICON" href="images/fibble.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">
</head>
<?php
if(isset($_SESSION['role'])){
?>
<body class="violetgradient">
<?php
include "navbar.php"
?>
<center>
<div class="customalert">
<div class="alertcontent">
<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">
<input type="text" id="searchText" class="searchBox" placeholder="Enter Product Code" 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>
<button class="qrbutton" onclick="document.getElementById('selectedFile').click();">
<i class='fa fa-qrcode'></i> Scan QR
</button>
<br><br>
<p id="database" class="cardstyle">
Fake Product
</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);
$(".cardstyle").hide();
// Change the Data
$('form').on('submit', function(event) {
event.preventDefault(); // to prevent page reload when form is submitted
greeting = $('input').val();
console.log(greeting)
//$("#database").text(greeting);
contract.methods.searchProduct(greeting).call(function(err, result) {
console.log(err, result)
$(".cardstyle").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("P2P Ownership Verification against Fake Products ");
});
</script>
</body>
</html>