-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.php
135 lines (129 loc) · 4.61 KB
/
index.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
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script src="JsBarcode.all.min.js">
</script>
<title> Barcodes Generator
</title>
</head>
<body>
<br>
<div class="container">
<div class="col-md-6 mx-auto text-center">
<div class="header-title">
<h2 class="wv-heading--subtitle">
Barcodes Generator
</h2>
</div>
</div>
</div>
<br>
<div class="cotainer">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#barcodeModal">New Barcode
</button>
</div>
<div class="card-body">
<?php
//Connect to egm_barcodes database.
$connection=mysqli_connect('localhost:3306','homenetw_eg','123456789','homenetw_barcodes');
$sql="SELECT * FROM tbl_products";
$result=mysqli_query($connection,$sql);
//data selected from the database.
$arrayBarcodes=array();
?>
<div class="row">
<div class="col-sm-12">
<table class="table table-sm">
<tr>
<th scope="col">#</th>
<th scope="col">Prodcut Name</th>
<th scope="col">Barcode</th>
<th scope="col">Created Date</th>
</tr>
<?php
//get back rows of results
while($row=mysqli_fetch_row($result)):
$arrayBarcodes[]=(string)$row[2];
?>
<tr>
<td><?php echo $row[0] ?></td>
<td><?php echo $row[1] ?></td>
<td>
<svg id='<?php echo "barcode".$row[2]; ?>'>
</td>
<td><?php echo $row[3] ?></td>
</tr>
<?php endwhile; ?>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--Add new product Modal -->
<div class="modal fade" id="barcodeModal" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="barcodeModalLabel">New barcode
</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×
</span>
</button>
</div>
<div class="modal-body">
<form action="php/insert.php" method="post">
<div class="form-group">
<label for="recipient-name" class="col-form-label" required>Product name:
</label>
<input type="text" class="form-control" id="name" name="name" maxlength="20" required>
</div>
<hr>
<button type="submit" class="btn btn-primary">Generate barcode
</button>
</form>
</div>
</div>
</div>
</div>
<!--End add new product Modal -->
</body>
</html>
<!--Bootstrap JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script type="text/javascript">
//convert json to JS array data.
function arrayjsonbarcode(j) {
json = JSON.parse(j);
arr = [];
for (var x in json) {
arr.push(json[x]);
}
return arr;
}
//convert PHP array to json data.
jsonvalue = '<?php echo json_encode($arrayBarcodes) ?>';
values = arrayjsonbarcode(jsonvalue);
//generate barcodes using values data.
for (var i = 0; i < values.length; i++) {
JsBarcode("#barcode" + values[i], values[i].toString(), {
format: "codabar",
lineColor: "#000",
width: 2,
height: 30,
displayValue: true
}
);
}
</script>