-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-category.php
110 lines (68 loc) · 2.88 KB
/
add-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
<?php include_once __DIR__ . "/assets/php/app.php" ?>
<?php
define("PARENT_DIR", __DIR__);
if ( !chechkIfLoggedIn() )
{
header("location: login.php?returnUrl=" . htmlspecialchars($_SERVER['PHP_SELF']) );
}
$userDetails = getUserDetailsUsingUsername($dbConn, $_SESSION["SSID-USERNAME"] );
if ( $userDetails['user_role'] != 'super-admin' && $userDetails['user_role'] != 'product-manager' )
{
load404Page();
exit;
}
?>
<?php
if( $_SERVER["REQUEST_METHOD"] === "POST" )
{
if ( !isset( $_POST["addCategory"] ) ){ exit; }
$category_name = trim($_POST["category_name"]);
$category_slug = strtolower($category_name);
$category_slug = preg_replace("/\s+/", "-", $category_slug);
$category_details = array (
"category_name" => $category_name,
"category_slug" => $category_slug,
);
if ( createNewCategory( $dbConn, $category_details ) )
{
$_SESSION["error_msg"] = "Registration Success";
$_SESSION["error_bg"] = "bg-success";
header("Location:" . htmlspecialchars($_SERVER['PHP_SELF']) . "?respCode=200&msg=success");
}
else
{
$_SESSION["error_msg"] = "Registration Failed";
$_SESSION["error_bg"] = "bg-failure";
}
}
?>
<?php require_once 'assets/pages/admin/head.php' ?>
<title> Create New Category - <?php echo $site_titile ?> </title>
</head>
<body>
<div class="container-fluid">
<?php require_once 'assets/pages/admin/navigation.php' ?>
<div class="contents container-fluid">
<?php require_once 'assets/pages/admin/sidebar.php' ?>
<div class="page-contents">
<section class="product-category">
<div class="heading">
<div class="details">
<h2> <i class="fa fa-add"></i> Create <span>New</span> Category </h2>
</div>
</div>
<form method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" class="add-new-product-form ">
<div class="form-group mt-3 mb-3">
<label class="mb-3" for="category_name">Category Name <span>*</span></label>
<input type="text" class="form-control" name="category_name" id="category_name" itemid="category_name" itemtype="input" placeholder="Ex. Category 1, Category 2, Category 3, ... " autofocus required>
</div>
<div class="form-group mt-3 mb-3 text-end">
<button type="submit" name="addCategory" class="btn btn-primary" > <i class="fas fa-add"></i> Create New Category</button>
</div>
</form>
</section>
</div>
</div>
</div>
</body>
</html>