-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcategory.php
317 lines (301 loc) · 12.2 KB
/
category.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
if (!isset($_SESSION)) {
session_start();
}
if(isset($_SESSION["login_usertype"]))
{//some one is logon
$system_usertype=$_SESSION["login_usertype"];
$system_username=$_SESSION["login_username"];
$system_userid=$_SESSION["login_userid"];
}
else
{//guest
$system_usertype="Guest";
}
if($system_usertype=="Admin"||$system_usertype=="Clerk")
{//Admin,Clerk Can Access This Page
include "config.php";
//insert sql start
if (isset($_POST["btnsave"])) {
$sqlinsert = "INSERT INTO category(category_id,category_name)
VALUES('" . mysqli_real_escape_string($con, $_POST["txtcategoryid"]) . "',
'" . mysqli_real_escape_string($con, $_POST["txtcategoryname"]) . "')";
$resultinsert = mysqli_query($con, $sqlinsert) or die("sql error in sqlinsert" . mysqli_error($con));
if ($resultinsert)
{
echo '<script> alert("Data stored successfully");
window.location.href="index.php?pg=subcategory.php&option=add&categoryid='.$_POST["txtcategoryid"].'"; </script>';
}
}
//insert sql end
//update code start
if(isset($_POST["btnsavechanges"]))
{
$sqlupdate="UPDATE category SET
category_name='".mysqli_real_escape_string($con,$_POST["txtcategoryname"])."'
WHERE category_id='".mysqli_real_escape_string($con,$_POST["txtcategoryid"])."'";
$resultupdate=mysqli_query($con,$sqlupdate) or die ("error in sqledit" . mysqli_error($con));
if($resultupdate)
{
echo '<script> alert("Successfully Updated");
window.location.href="index.php?pg=category.php&option=fullview&pk='.$_POST["txtcategoryid"].'";</script>';
}
}
//update code end
?>
<body>
<?php
if (isset($_GET["option"]))
{
if ($_GET["option"] == "add")
{
?>
<!-- form section start -->
<section class="feature_part padding_top">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="card">
<form class="form-horizontal" method="POST" action="">
<div class="card-body">
<center>
<h4 class="card-title">Add Category</h4>
</center>
<!-- field start -->
<div class="form-group row">
<label for="fname" class="col-sm-3 text-right control-label col-form-label">Category ID</label>
<div class="col-sm-3">
<?php
$sqlgenerateid="SELECT category_id FROM category ORDER BY category_id DESC LIMIT 1";
$resultgenerateid=mysqli_query($con,$sqlgenerateid) or die ("Error in sqlgenerateid". mysqli_error($con));
$n=mysqli_num_rows($resultgenerateid);//count the number of records
if($n==1)
{//for other than 1st time
$rowgenerateid=mysqli_fetch_assoc($resultgenerateid);
$generateid=++$rowgenerateid["category_id"];
}
else
{//For 1st time
$generateid="CAT01";
}
?>
<input type="text" class="form-control" id="txtcategoryid" name="txtcategoryid"
placeholder="Category ID Here" value="<?php echo $generateid; ?>" readonly required>
</div>
<label for="fname" class="col-sm-3 text-right control-label col-form-label"> Category Name</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="txtcategoryname" name="txtcategoryname"
placeholder="Category Name Here" required onkeypress="return TextValidation(event)">
</div>
</div>
<!-- field end -->
<!-- button start -->
<div class="form-group row">
<div class="col-sm-12">
<center>
<a href="index.php?pg=category.php&option=view"><input type="button" class="btn btn-primary"
id="btngoback" name="btngoback" value="Go back"></a>
<input type="reset" class="btn btn-danger" id="btnclear" name="btnclear" value="Clear">
<input type="submit" class="btn btn-success" id="btnsave" name="btnsave" value="Save">
</center>
</div>
</div>
<!-- button end -->
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<!-- form section end -->
<?php
}
else if ($_GET["option"] == "view")
{
?>
<div class="card">
<div class="card-body">
<center>
<h5 class="card-title">Category View</h5>
</center>
<div class="table-responsive">
<table id="zero_config" class="table table-striped table-bordered">
<a href="index.php?pg=category.php&option=add"><button class="btn btn-primary">Add Record</button></a>
<br><br>
<thead>
<tr>
<th>Category ID</th>
<th>Category Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$sqlview = "SELECT category_id,category_name FROM category";
$resultview = mysqli_query($con, $sqlview) or die("Error in sqlview " . mysqli_error($con));
while ($rowview = mysqli_fetch_assoc($resultview))
{
echo '<tr>';
echo '<td>' . $rowview["category_id"] . '</td>';
echo '<td>' . $rowview["category_name"] . '</td>';
echo '<td>';
echo '<a href="index.php?pg=category.php&option=fullview&pk='.$rowview["category_id"].'"><button class="btn btn-success">View</button></a> ';
echo '<a href="index.php?pg=category.php&option=edit&pk='.$rowview["category_id"].'"><button class="btn btn-info">Edit</button></a> ';
echo '<a onclick="return confirmdelete()" href="index.php?pg=category.php&option=delete&pk='.$rowview["category_id"].'"><button class="btn btn-danger">Delete</button></a> ';
echo '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php
}
else if ($_GET["option"] == "fullview")
{
$get_categoryid =$_GET["pk"];
$sqlfullview = "SELECT * FROM category WHERE category_id ='$get_categoryid'";
$resultfullview = mysqli_query($con,$sqlfullview) or die("Sqlfullview error ".mysqli_error($con));
$rowfullview=mysqli_fetch_assoc($resultfullview);
?>
<div class="card">
<div class="card-body">
<center><h5 class="card-title">Category Full View</h5></center>
<div class="table-responsive">
<table id="zero_config" class="table table-striped table-bordered">
<tr><th>Category ID</th><td><?php echo $rowfullview["category_id"]; ?></td></tr>
<tr><th>Category Name</th><td><?php echo $rowfullview["category_name"]; ?></td></tr>
<tr>
<td colspan="2">
<center>
<a href="index.php?pg=category.php&option=view"><button class="btn btn-primary">Go Back</button></a>
<a href="index.php?pg=category.php&option=edit&pk=<?php echo $rowfullview["category_id"]; ?>"><button class="btn btn-info">Edit</button></a>
</center>
</td>
</tr>
</table>
</div>
</div>
</div>
<!--sub categorylist -->
<div class="card">
<div class="card-body">
<center> <h5 class="card-title">Subcategory View</h5></center>
<div class="table-responsive">
<table id="zero_config" class="table table-striped table-bordered">
<a href="index.php?pg=subcategory.php&option=add&categoryid=<?php echo $rowfullview["category_id"]; ?>"><button class="btn btn-primary">Add Record</button></a>
<br><br>
<thead>
<tr>
<th>Subcategory ID</th>
<th>Category ID</th>
<th>Subcategory Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$sqlview="SELECT * FROM subcategory WHERE category_id='$get_categoryid'";
$resultview = mysqli_query($con,$sqlview) or die ("Error in sqlview ".mysqli_error($con));
while($rowview=mysqli_fetch_assoc($resultview))
{
$sqlcategoryname="SELECT category_name FROM category WHERE category_id='$rowview[category_id]'";
$resultcategoryname=mysqli_query($con,$sqlcategoryname) or die ("Error in sqlcategoryname" . mysqli_error($con));
$rowcategoryname=mysqli_fetch_assoc($resultcategoryname);
echo'<tr>';
echo '<td>'.$rowview["subcategory_id"].'</td>';
echo '<td>'.$rowcategoryname["category_name"].'</td>';
echo '<td>'.$rowview["subcategory_name"].'</td>';
echo '<td>';
echo '<a href="index.php?pg=subcategory.php&option=edit&pk='.$rowview["subcategory_id"].'"><button class="btn btn-info">Edit</button></a> ';
// for after Deletion of subcategory have to come back to category so it's ---> &categoryid='.$rowview["category_id"]. needed
echo '<a onclick="return confirmdelete()" href="index.php?pg=subcategory.php&option=delete&pk='.$rowview["subcategory_id"].'&categoryid='.$rowview["category_id"].'"><button class="btn btn-danger">Delete</button></a> ';
echo '</td>';
echo'</tr>';
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php
}
else if ($_GET["option"] == "edit")
{
$get_categoryid =$_GET["pk"];
$sqledit = "SELECT * FROM category WHERE category_id ='$get_categoryid'";
$resultedit = mysqli_query($con,$sqledit) or die("Sqlfullview error ".mysqli_error($con));
$rowedit=mysqli_fetch_assoc($resultedit);
?>
<!-- form section start -->
<section class="feature_part padding_top">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="card">
<form class="form-horizontal" method="POST" action="">
<div class="card-body">
<center>
<h4 class="card-title">Edit Category</h4>
</center>
<!-- field start -->
<div class="form-group row">
<label for="fname" class="col-sm-3 text-right control-label col-form-label">Category ID</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="txtcategoryid" name="txtcategoryid"placeholder="Category ID Here" required readonly value= "<?php echo $rowedit["category_id"]; ?>"></div>
<label for="fname" class="col-sm-3 text-right control-label col-form-label"> Category Name</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="txtcategoryname" name="txtcategoryname"
placeholder="Category Name Here" required value= "<?php echo $rowedit["category_name"]; ?>" onkeypress="return TextValidation(event)">
</div>
</div>
<!-- field end -->
<!-- button start -->
<div class="form-group row">
<div class="col-sm-12">
<center>
<a href="index.php?pg=category.php&option=view"><input type="button" class="btn btn-primary"
id="btngoback" name="btngoback" value="Go back"></a>
<input type="reset" class="btn btn-danger" id="btncancel" name="btncancel" value="Cancel">
<input type="submit" class="btn btn-success" id="btnsavechanges" name="btnsavechanges" value="Save Changes">
</center>
</div>
</div>
<!-- button end -->
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<!-- form section end -->
<?php
}
else if ($_GET["option"] == "delete")
{
$get_categoryid=$_GET["pk"];
$sqldelete = "DELETE FROM category WHERE category_id = '$get_categoryid'";
$resultdelete = mysqli_query($con,$sqldelete) or die ("Error in sqldelete ".mysqli_error($con));
$sqldelete = "DELETE FROM subcategory WHERE category_id = '$get_categoryid'";
$resultdelete = mysqli_query($con,$sqldelete) or die ("Error in sqldelete ".mysqli_error($con));
if ($resultdelete)
{
echo '<script> alert("Record is Deleted");
window.location.href="index.php?pg=category.php&option=view";</script>';
}
}
}
?>
</body>
<?php
}
else
{//Others Will Redirect to Index Page
echo '<script>window.location.href="index.php";</script>';
}
?>