-
Notifications
You must be signed in to change notification settings - Fork 0
/
addproduct.php
215 lines (182 loc) · 7.3 KB
/
addproduct.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
<?php
session_start();
$color="navbar-light orange darken-4";
?>
<!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/fibble.png" type="image/x-icon" />
<link rel="ICON" href="images/fibble.png" type="image/ico" />
<title>Fibble - Add New Products</title>
<!-- Bootstrap -->
<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/mdb.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
</head>
<?php
if( $_SESSION['role']==0 ){
?>
<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"> Done </button>
</div>
</div>
</center>
<div class="bgrolesadd">
<center>
<div class="mycardstyle">
<div class="greyarea">
<h5> Please fill product details </h5>
<form id="form1" autocomplete="off">
<div class="formitem">
<label type="text" class="formlabel"> Product Name </label>
<input type="text" class="forminput" id="prodname" required>
<input type="hidden" class="forminput" id="user" value=<?php echo $_SESSION['username']; ?> required>
</div>
<button class="formbtn" id="mansub" type="submit">Register Item</button>
</form>
</div>
</div>
</center>
<?php
}else{
include 'redirection.php';
redirect('index.php');
}
?>
<div class='box'>
<div class='wave -one'></div>
<div class='wave -two'></div>
<div class='wave -three'></div>
</div>
<!-- JQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Material Design Bootstrap-->
<script type="text/javascript" src="js/popper.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/mdb.min.js"></script>
<!-- Web3.js -->
<script src="web3.min.js"></script>
<!-- QR Code Library-->
<script src="./dist/qrious.js"></script>
<!-- QR Code Reader -->
<script src="https://rawgit.com/sitepoint-editors/jsqrcode/master/src/qr_packed.js"></script>
<script src="app.js"></script>
<!-- Web3 Injection -->
<script>
// Initialize Web3
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
web3 = new Web3(new Web3.providers.HttpProvider('HTTP://127.0.0.1:7545'));
} else {
web3 = new Web3(new Web3.providers.HttpProvider('HTTP://127.0.0.1:7545'));
}
// Set the Contract
var contract = new web3.eth.Contract(contractAbi, contractAddress);
$("#manufacturer").on("click", function(){
$("#districard").hide("fast","linear");
$("#manufacturercard").show("fast","linear");
});
$("#distributor").on("click", function(){
$("#manufacturercard").hide("fast","linear");
$("#districard").show("fast","linear");
});
$("#closebutton").on("click", function(){
$(".customalert").hide("fast","linear");
});
$('#form1').on('submit', function(event) {
event.preventDefault(); // to prevent page reload when form is submitted
prodname = $('#prodname').val();
username = $('#user').val();
prodname=prodname+"<br>Registered By: "+username;
console.log(prodname);
var today = new Date();
var thisdate = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
web3.eth.getAccounts().then(async function(accounts) {
var receipt = await contract.methods.newItem(prodname, thisdate).send({ from: accounts[0], gas: 1000000 })
.then(receipt => {
var msg="<h5 style='color: #53D769'><b>Item Added Successfully</b></h5><p>Product ID: "+receipt.events.Added.returnValues[0]+"</p>";
qr.value = receipt.events.Added.returnValues[0];
$bottom="<p style='color: #FECB2E'> You may print the QR Code if required </p>"
$("#alertText").html(msg);
$("#qrious").show();
$("#bottomText").html($bottom);
$(".customalert").show("fast","linear");
});
//console.log(receipt);
});
$("#prodname").val('');
});
$('#form2').on('submit', function(event) {
event.preventDefault(); // to prevent page reload when form is submitted
prodid = $('#prodid').val();
prodlocation = $('#prodlocation').val();
console.log(prodid);
console.log(prodlocation);
var today = new Date();
var thisdate = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var info = "<br><br><b>Date: "+thisdate+"</b><br>Location: "+prodlocation;
web3.eth.getAccounts().then(async function(accounts) {
var receipt = await contract.methods.addState(prodid, info).send({ from: accounts[0], gas: 1000000 })
.then(receipt => {
var msg="Item has been updated ";
$("#alertText").html(msg);
$("#qrious").hide();
$("#bottomText").hide();
$(".customalert").show("fast","linear");
});
});
$("#prodid").val('');
$("#prodlocation").val('');
});
function isInputNumber(evt){
var ch = String.fromCharCode(evt.which);
if(!(/[0-9]/.test(ch))){
evt.preventDefault();
}
}
(function() {
var qr = window.qr = new QRious({
element: document.getElementById('qrious'),
size: 200,
value: '0'
});
})();
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("A Decentralised End to End Logistics Application that stores the whereabouts of product at every freight hub to the Blockchain. At consumer end, customers can easily scan product's QR CODE and get complete information about the provenance of that product hence empowering consumers to only purchase authentic and quality products.");
});
</script>
</body>
</html>