forked from vignesh-82coder/Foodereum
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sanction.php
226 lines (191 loc) · 8.19 KB
/
sanction.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
<?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/fe.png" type="image/x-icon" />
<link rel="ICON" href="images/fe.png" type="image/ico" />
<!-- 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">
<title>Foodereum - Sanction Items</title>
</head>
<!-- Segregating the roles based on navbar -->
<?php
if( $_SESSION['role']==0 ){
?>
<body class="violetgradient">
<?php include 'navbar.php'; ?>
<center>
<div class="customalert">
<div class="alertcontent"><i><b>Sanction Products</b></i>
<div id="alertText">   </div>
<img id="qrious">
<div id="bottomText" style="margin-top: 10px; margin-bottom: 15px;">   </div>
<a href="mailto:foodereum@googlegroups.com"> <button id="mail" class="formbtn"> Mail QR Code </button> </a>
<button id="closebutton" class="formbtn"> OK </button>
<br><a href="manage.php"> <button id="notif" class="formbtn"> Send Notification </button> </a>
</div>
</div>
</center>
<div class="bgrolesadd">
<center>
<div class="mycardstyle">
<div class="yellowarea">
<h5> Add Food Items </h5>
<form id="form1" autocomplete="off">
<div class="formitem">
<input type="text" size="15" class="forminput" id="prodname" placeholder="Item Name" required>
<input type="number" min="0" max="2000" class="qty" placeholder="Quantity" id="quantity" required>
<select id="qunit" name="qunit1" class="quy" required>
<option value="kg">kg</option>
<option value="ml">ml</option>
<option value="g">g</option>
<option value="l">l</option>
</select>
<div id="my-content" class="content">
</div>
<input type="hidden" class="forminput" id="user" value=<?php echo $_SESSION['username']; ?> required>
</div>
<button class="formbtn" id="mansub" type="submit">Register Items</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 using rpc server id in Ganache
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);
$("#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();
quantity = $('#quantity').val();
qunit = $('#qunit').val();
username = $('#user').val();
prodname = "<b>"+prodname+"<br>Quantity: "+quantity+" " +qunit+"<br>Registered By: "+username+"</b>";
console.log(prodname+quantity);
var today = new Date();
var thisdate = "<b>"+today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate()+"</b>";
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><b>Product ID: </b>"+receipt.events.Added.returnValues[0]+"</p>";
qr.value = receipt.events.Added.returnValues[0];
$bottom="<p style='color: #53D769'> <b>You may download the QR Code Now </b></p>"
$("#alertText").html(msg);
$("#qrious").show();
$("#bottomText").html($bottom);
$("#closebutton").hide();
$("#notif").show();
$(".customalert").show("fast","linear");
});
});
$("#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+"<br>Location: "+prodlocation+"</b>";//the date and the current location is stored here
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("There was no QR code found. Please double-check that the QR code is within the camera's frame before proceeding.");
} 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();
$("#notif").hide();
$("#mail").hide();
$("#closebutton").show();
$(".customalert").show("fast","linear");
}
$("#aboutbtn").on("click", function(){
showAlert("Allows user to Add/Sanction food products, on submitting a QR code and its associated Product ID will be generated which can be downloaded for future use, Once the food products are sanctioned, users must be alerted of the details. Send a Notification by clicking the button below!");
});
</script>
</body>
</html>