-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproductlist.php
187 lines (138 loc) · 5.87 KB
/
productlist.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
<?php
include_once('config/connectdb.php');
session_start();
if($_SESSION['useremail']=="" or $_SESSION['role']=="User") {
header('location:index.php');
} else {
include_once('inc/header.php');
}
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Products.
<small>View / Update / Delete Products</small>
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
<li class="active">Here</li>
</ol>
</section>
<!-- Main content -->
<section class="content container-fluid">
<!--------------------------
| Your Page Content Here |
-------------------------->
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">List of all products with quantitities available. </h3>
</div>
<div class="box-body">
<div style="overflow-x: auto;">
<table class="table table-stripped" id="tableproductlist">
<thead>
<tr>
<th>No.</th>
<th>Name</th>
<th>Model</th>
<th>Category</th>
<th>Purchase Price</th>
<th>Sales Price</th>
<th>Stock</th>
<th>Image</th>
<th>View</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$select = $pdo->prepare("SELECT * FROM tbl_product ORDER BY pid ASC ");
$select->execute();
while($row = $select->fetch(PDO::FETCH_OBJ)) {
echo' <tr>
<td>'.$row->pid.'</td>
<td>'.$row->pname.'</td>
<td>'.$row->pmodel.'</td>
<td>'.$row->pcategory.'</td>
<td>'.$row->purchase_price.'</td>
<td>'.$row->sales_price.'</td>
<td>'.$row->pstock.'</td>
<td>
<img src="productimages/'.$row->pimage.'"class=img-rounded" width="40px" height="40px">
</td>
<td>
<a href="viewproduct.php?id='.$row->pid.'" class="btn btn-success btn-sm" role ="button" name="viewButton"><span class="glyphicon glyphicon-eye-open" style="color:#ffffff" data-toggle="tool-tip" title="View Product"></span></a>
</td>
<td>
<a href="editproduct.php?id='.$row->pid.'" class="btn btn-warning btn-sm" role ="button" name="btnaupdate"><span class="glyphicon glyphicon-edit" style="color:#ffffff" data-toggle="tool-tip" title="Edit Product"></span></a>
</td>
<td>
<button id='.$row->pid.' class="btn btn-danger btn-sm btndanger btndelete"><span class="glyphicon glyphicon-trash" style="color:#ffffff" data-toggle="tool-tip" title="Delete Product"></span></button>
</td>
</tr>
';
}
?>
</tbody>
</table>
</div>
</div>
</section>
<!-- /.content -->
</div>
<!-- /code for data table -->
<script type="text/javascript">
$(document).ready(function () {
$('#tableproductlist').DataTable({
"order":[[0,"desc"]]
});
} );
</script>
<!-- /code for tool tip -->
<script type="text/javascript">
$(document).ready(function () {
$('[data-toggle="tool-tip"]').tooltip();
} );
</script>
<!-- Delete Button Code -->
<script type="text/javascript">
$(document).ready(function(){
$('.btndelete').click(function(){
var tdh = $(this);
var id = $(this).attr("id");
// Sweet Alert Code
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this product data.",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
$.ajax({
url:'deleteproduct.php',
type:'post',
data:{
pidd:id
},
success:function(data) {
tdh.parents('tr').hide();
}
});
swal("Poof! Your product has been deleted.", {
icon: "success",
});
} else {
swal("Your product is not deleted.");
}
});
});
});
</script>
<?php
include_once('inc/footer.php');
?>