<?php include('session.php')?>
<?php include('header.php')?>
<link href="vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">
<style>
img.banner {
width: 145px;
height: 86px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.filesizecheck').on('change',function(){
for(var i=0; i< $(this).get(0).files.length; ++i){
var file1 = $(this).get(0).files[i].size;
if(file1){
var file_size = $(this).get(0).files[i].size;
if(file_size > 500000){
$('#error-message').html("File upload size is larger than 500KB");
$('#error-message').css("display","block");
$('#error-message').css("color","red");
$( ".dis-data" ).prop( "disabled", true );
}else{
$('#error-message').css("display","none");
$( ".dis-data" ).prop( "disabled", false );
}
}
}
});
});
</script>
<script>
function show_confirm() {
return confirm("Are You Sure");
}
</script>
<?php
if(isset($_POST['submit']))
{
$category=$_POST['category'];
$image="img/".$_FILES['image']['name'];
move_uploaded_file($_FILES['image']['tmp_name'],$image);
$sql=mysqli_query($conn, "INSERT INTO menucategory (image,category) VALUES ('$image','$category')");
if($sql)
{
echo "<Script>alert('Details Inserted Successfully')</script>";
}
else
{
echo "<Script>alert('Insertion Failed')</script>";
}
}
?>
<body id="page-top">
<!-- Page Wrapper -->
<div id="wrapper">
<!-- Sidebar -->
<?php include('sidebar.php')?>
<!-- End of Sidebar -->
<!-- Content Wrapper -->
<div id="content-wrapper" class="d-flex flex-column">
<!-- Main Content -->
<div id="content">
<!-- Topbar -->
<?php include('topbar.php')?>
<!-- End of Topbar -->
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Menu</h1>
</div>
<div class="card shadow mb-4">
<div class="col-lg-7">
<div class="p-5">
<div class="text-center">
</div>
<form action="" class="user" method="post" enctype="multipart/form-data">
<div class="form-group row">
<div class="col-sm-12 mb-3 mb-sm-0">
<label for="exampleInputFile">Menu Category</label>
<input type="text" class="form-control" id="exampleFirstName" placeholder="Category" name="category">
</div>
</div>
<div class="form-group">
<label for="exampleInputFile">Upload Image</label></br>
<input class="form-control filesizecheck" type="file" name="image" id="otherAnswer">
<span id="error-message" class="validation-error-label"></span>
</div>
<input type="submit" class="btn btn-primary btn-user btn-block dis-data" name="submit" value="ADD" style=" background-color: #c21b16;
border: 1px solid #c21b16;">
</form>
</div>
</div>
</div>
<!-- DataTales Example -->
<!-- DataTales Example -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">DataTable</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>S.No</th>
<th>Category</th>
<th>Image</th>
<th>Delete</th>
</tr>
</thead>
<tfoot>
<tr>
<th>S.No</th>
<th>Category</th>
<th>Image</th>
<th>Delete</th>
</tr>
</tfoot>
<tbody>
<?php
$x = 1;
$sql=mysqli_query($conn,"SELECT * FROM menucategory");
while($row=mysqli_fetch_array($sql))
{
?>
<tr>
<td><?php echo $x; ?></td>
<td><?php echo $row['category']; ?></td>
<td><img class="banner" src="<?php echo $row['image']; ?>" /></td>
<td> <a title="Delete" href="menucatdelete.php?id=<?php echo $row['id']; ?>" class="" onclick='return show_confirm();'><img class="" src="img/del.png"></a></td>
</tr>
<?php
$x++;
}
echo '<script type="text/javascript"> drawChart(); </script>';
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
<!-- End of Main Content -->
<?php include('footer.php')?>