<?php
session_start();
if(isset($_SESSION['loggedin']))
{
	include('connection.php');
	$logid=$_SESSION['loggedin'];
	$res=mysqli_query($con,"select * from admin where id='$logid'");
	$row=mysqli_fetch_assoc($res);
	
	if(isset($_POST['save']))
{
$head=$_POST["head"];	
$des=$_POST["des"];
if(is_uploaded_file($_FILES['photo']['tmp_name']))
	{
		$filename=$_FILES['photo']['name'];
		//$filename1=md5($filename).".png";
		move_uploaded_file($_FILES['photo']['tmp_name'],"upload/$filename");
	} 
date_default_timezone_set("Asia/Calcutta");
$date=date('Y-m-d H:i:s');
$sql="insert into slider(head,des,photo,created_at)values('$head','$des','$filename','$date')"; 
$result=mysqli_query($con,$sql);
if(mysqli_affected_rows($con)==1)
{
	header("location:slider.php?status=true");
}
else{
	echo "<script>alert('sorry! unable to insert..');</script>";
}

}
	
?>


  <!-- Navbar -->
<?php include('header.php');?>
  <!-- /.navbar -->

  <!-- Main Sidebar Container -->
<?php include('sidebar.php');?>

  <!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
         
          
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
	<div class="row">
             <div class="col-md-6">
           
               <div class="card card-info">
              <div class="card-header"style="background-color:rgb(27 125 151);color:white;">
                <h3 class="card-title"><b>Add Banner</b></h3>
              </div>
              
              <form method="post" method="post" enctype="multipart/form-data">
                <div class="card-body">
				<div class="form-group">
                    <label for="exampleInputEmail1">Heading</label>
                    <input type="text" name="head" class="form-control" id="exampleInputEmail1" placeholder="Enter Heading" required>
                  </div>                 
                 <!-- <div class="form-group">
                    <label for="exampleInputPassword1">Description</label>
                    <input type="text" name="des" class="form-control" id="exampleInputPassword1" placeholder="Enter Description" required>
                  </div>    -->
                 <div class="form-group">
                    <label for="exampleInputPassword1">Banner</label>
                    <input type="file" name="photo" class="form-control" id="exampleInputPassword1" placeholder="Enter No of Seats" required>
                  </div>    				  
               
                   				  
                </div>
              
                <div class="card-footer" style="text-align:right">
                  <button type="submit" name="save" class="btn btn-info">Submit</button>
                </div>
              </form>
            </div>           
          </div>
		 
      </div>
	  <div class="row">
	    <div class="col-12">       
            <div class="card">
              <div class="card-header"style="background-color:rgb(27 125 151);color:white;">
                <h3 class="card-title"><b>Banner List</b></h3>
              </div>
              <!-- /.card-header -->
              <div class="card-body" >
                <table id="example2" class="table table-bordered table-striped">
                  <thead>
                  <tr>
                    <th>Sr. No.</th>
					<th>Banner</th> 
					<th>Heading</th> 
                    <th>Action</th>
                  </tr>
                  </thead>
                  <tbody>
                       <?php

	$sql="select * from slider ";
	$result11=mysqli_query($con,$sql);

if(mysqli_num_rows($result11))
						{
							  
									$i=1;
									while($rows11=mysqli_fetch_assoc($result11))
									{
										?> 
                  <tr>
                    <td><?php echo $i;?></td>
				
					<td><img src="upload/<?php echo $rows11['photo'];?>" style="width:100%;height:20%"></td>
					<td><?php echo $rows11['head'];?></td>	
					<td>
					<button type="button" class="btn btn-info"><a href="slider_update.php?bid=<?php echo $rows11['id']?>">
                          <i class="fas fa-edit" style="color:white"></i>
                        </button>
                      <button type="button" class="btn btn-danger"><a onclick="deleteRecord('<?php echo $rows11['id'];?>')" href="javascript:void(0)">
                          <i class="fas fa-trash" style="color:white"></i>
                        </button>
					</td>
                  </tr>
                  	<?php
									$i++;
									
									}
								?>
								
							<?php
							
						}
						else
						{
						?>
						<div style=" padding:15px; margin-top:10px;">
				        
				        <h4 style="text-align:center;color:red;"><b>Sorry ! No result found..!</b></h4>
						 </div>
						 <?php
						}
			?>
                  </tbody>             
                </table>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
	  </div>
	  </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
   <script>
					function deleteRecord(id)
					{
						var x=confirm("do you want to Delete?")
						if(x==true)
						{
							window.location="slider_delete.php?did="+id;
						}
						
					}
	</script>
 <?php include('footer.php');?>
<?php
}
else
{
	header("location:login.php");
}
?>