-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcategories_approve.php
78 lines (72 loc) · 3.15 KB
/
categories_approve.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
<?php
require_once 'includes/headx.php';
require_once "includes/classes/admin-class.php";
$admins = new Admins($dbh);
$page = isset($_GET[ 'p' ])?$_GET[ 'p' ]:'';
if($page == 'add'){
$name = htmlentities($_POST['name']);
if (!$admins->addNewCategory($name))
{
echo "Sorry Data could not be inserted !";
}else {
echo " Data inserted !";
}
}else if($page == 'del'){
$id = $_POST['id'];
if (!$admins->deleteCategory($id))
{
echo "Sorry Data could not be deleted !";
}else {
echo "Well! You've successfully deleted a product!";
}
}else if($page == 'edit'){
$name = $_POST['name'];
$price = $_POST['price'];
$id = $_POST['id'];
if (!$admins->updateCategory($id, $name))
{
echo "Sorry Data could not be inserted !";
}else {
$commons->redirectTo(SITE_PATH.'categories.php');
}
}else{
$categories = $admins->getCategories();
if (isset($categories) && sizeof($categories) > 0){
foreach ($categories as $category){
?>
<tr>
<td><?=$category->cat_id?></td>
<td><?=$category->cat_name?></td>
<td>
<button type="button" class="btn btn-success btn-sm" id="edit" data-toggle="modal" data-target="#edit-<?=$category->cat_id?>">EDIT</button>
<!-- Update modal -->
<div class="fade modal" id="edit-<?=$category->cat_id?>">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4>Edit Category</h4>
</div>
<form method="POST" action="categories_approve.php?p=edit">
<div class="modal-body">
<input type="hidden" id="<?=$category->cat_id?>" value="<?=$category->cat_id?>">
<div class="form-group has-success">
<label for="name">Name</label>
<input type="text" class="form-control" id="nm-<?=$category->cat_id?>" value="<?=$category->cat_name?>" required>
</div>
</div>
<div class="modal-footer">
<button type="submit" onclick="upData(<?=$category->cat_id?>)" class="btn btn-primary">Update</button>
<a href="#" class="btn btn-warning" data-dismiss="modal">Cancel</a>
</div>
</form>
</div>
</div>
</div>
<button type="button" id="delete" onclick="delData(<?=$category->cat_id?>)" class="btn btn-warning btn-sm">DELETE</button>
</td>
</tr>
<?php }
}
}
?>