-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddproduct.php
More file actions
158 lines (155 loc) · 7.02 KB
/
addproduct.php
File metadata and controls
158 lines (155 loc) · 7.02 KB
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
<?php require_once ("dbconnect.php"); ?>
<?php require_once ('includes/employee_header.php'); ?>
<?php require_once('function.php'); ?>
<?php
if($_SESSION['job_type'] != "Manager"){
if($_SESSION['type'] != "employee"){
header("Location: logout.php");
}else{
header("Location: employee.php");
}
}
?>
<?php
$msg="";
if(isset($_POST["submit"])){
$target_file = "img/product/" . basename($_FILES['image']['name']);
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if (file_exists($target_file)) {
$msg = "Rename Your file ";
}
elseif($_FILES["image"]["size"] > 500000) {
$msg = "File is too large.";
}
elseif($imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "png") {
$msg = "Only JPG, JPEG, PNG files are allowed.";
}else{
$fullname = $_POST['name'];
$description = $_POST['description'];
$category = $_POST['category'];
$cost = $_POST['cost'];
$image = $_FILES['image']['name'];
$productsql = "SELECT name FROM product WHERE name='$fullname'";
$product_result = $connect->query($productsql);
if($product_result->num_rows == 0){
if(move_uploaded_file($_FILES['image']['tmp_name'], $target_file)){
$sql = "INSERT INTO product (name, description, category, price, image) VALUES ('$fullname', '$description', '$category', '$cost', '$target_file')";
$result = $connect->query($sql);
if($result){
$msg="Product added successfully";
}else{
$msg = "Add error";
}
}else{
$msg = "File saving error. Please try again.";
}
}else{
$msg = "Name is in use";
}
}
}
?>
<!-- Main Menu -->
<div class="side-menu-container">
<ul class="nav navbar-nav">
<li><a href="employee.php"><span class="glyphicon glyphicon-home"></span>Home</a></li>
<li><a href="empcheckorder.php"><span class="glyphicon glyphicon-save"></span>Check Order</a></li>
<?php if($_SESSION['job_type'] == "Manager") { ?>
<li><a href="addemp.php"><span class="glyphicon glyphicon-cloud-upload"></span>Add Employee</a></li>
<li class="active"><a href="addproduct.php"><span class="glyphicon glyphicon-paperclip"></span>Add Product</a></li>
<li><a href="shipmentreq.php"><span class="glyphicon glyphicon-road"></span>Shipment Request</a></li>
<li><a href="emptrackproduct.php"><span class="glyphicon glyphicon-map-marker"></span>Vehicle Location</a></li>
<li><a href="showclient.php"><span class="glyphicon glyphicon-equalizer"></span>Client Graph</a></li>
<li><a href="driverlist.php"><span class="glyphicon glyphicon-user"></span>Driver List</a></li>
<li><a href="warehouseinfo.php"><span class="glyphicon glyphicon-tent"></span>Warehouse Info</a></li>
<?php }elseif($_SESSION['job_type'] == "Supervisor") { ?>
<li><a href="shipmentaccept.php"><span class="glyphicon glyphicon-tent"></span>Accepted Shipment</a></li>
<?php }?>
<li><a href="empsetting.php"><span class="glyphicon glyphicon-cog"></span>Profile Setting</a></li>
<li><a href="logout.php"><span class="glyphicon glyphicon-log-out"></span>Logout</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
</div>
<!-- Main Content -->
<div class="container-fluid">
<div class="side-body">
<br>
<pre> <b>Add Product</b></pre>
<?php if($msg != "") { ?>
<p style="color:red"><?php echo $msg; ?></p>
<?php } ?>
<form method="post" action="#" enctype="multipart/form-data">
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputname">Model Name</label>
<input type="text" class="form-control" id="inputname" name="name" required placeholder="Model name">
<div id="modelmsg">
</div>
</div>
<div class="form-group col-md-6">
<label for="inputcat">Category</label>
<input type="text" class="form-control" id="inputcat" name="category" required placeholder="Category">
</div>
</div>
<div class="form-group col-md-12">
<label for="inputdes">Address</label>
<input type="text" class="form-control" id="inputdes" name="description" required placeholder="Description">
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputcost">Price per unit in BDT</label>
<input type="text" class="form-control" id="inputcost" name="cost" required placeholder="Price" onkeyup="validatephone(this);">
</div>
<div class="form-group col-md-8">
<label for="inputpic">Image</label>
<input type="file" class="form-control" id="inputpic" name="image" required accept="image/jpeg,image/jpg, image/x-png">
<div id="imgmsg">
</div>
</div>
</div>
<div class="form-group col-md-2">
<button type="submit" id="submit" name="submit" class="btn btn-primary">Add Product</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#inputname').keyup(function(){
var user = $(this).val();
dataType = "type=searchpro&product="+user ;
$.ajax({
type: "post",
url: "check_validity.php",
data: dataType,
cache: false,
success: function(result) {
$("#modelmsg").html(result);
}
});
});
$("#inputpic").change(function () {
var fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];
if ($.inArray($(this).val().split('.').pop().toLowerCase(), fileExtension) == -1) {
$("#imgmsg").html("Only formats are allowed : "+fileExtension.join(', '));
}
});
});
function validatephone(phone)
{
var maintainplus = '';
var numval = phone.value;
if ( numval.charAt(0)=='+' )
{
var maintainplus = '';
}
curphonevar = numval.replace(/[\\A-Za-z!"£$%^&\,*+_={};:'@#~,.Š\/<>?|`¬\]\[]/g,'');
phone.value = maintainplus + curphonevar;
var maintainplus = '';
phone.focus;
}
</script>
<?php require_once ('includes/employee_footer.php'); ?>