<?php include("includes/css.php")?>
<?php
if(isset($_POST['submit']))
{
extract($_POST);
$sql=mysqli_query($con, "INSERT INTO `video`(`vcat_id`,`video_link`) VALUES ('$video_category','$video')")or die(mysqli_error($con));

if($sql)
{
header("location:video.php");
}
}
if(isset($_GET['deleteid']))
{
$deleteid=$_GET['deleteid'];
$ss=mysqli_query($con, "delete from video where id='$deleteid'");
header("location:video.php");
}
if(isset($_POST['delete']))
{
  $delete = $_POST['deletegallery'];
  for($i=0;$i<count($delete); $i++)
  {
    $deleteid=$_POST['deletegallery'][$i];
    mysqli_query($con, "delete from video where id='$deleteid'");
  }
}
?>
<body class="hold-transition skin-blue sidebar-mini">
  <div class="wrapper">
    <?php include("includes/header.php")?>
    <?php include("includes/aside.php")?>
    <div class="content-wrapper">
      <section class="content">
        <div class="row">
          <div class="col-md-7">
            <div class="box box-success">
              <div class="box-header with-border">
                <h3 class="box-title">Gallery </h3>
              </div>
              <!-- /.box-header -->
              <div class="box-body">
                <div class="table-responsive">
                  <form action="" method="post" id="firstform">
                  <table class="table table-bordered example1">
                    
                      <thead>
                        <tr>
                          <th>
                            <label class="checkbox-inline">
                              <input type="checkbox" class="checkAll" value="">All
                            </label>
                          </th>
                          <th>S. No</th>
                          <th>Category</th>
                          <th>Video </th>
                         <!--  <th>Type</th>-->
                          <th>Edit</th> 
                          <th>Delete</th>
                        </tr>
                      </thead>
                      
                      <tbody>
                        <?php $n=1; $sql=mysqli_query($con, "select * from video order by id desc")or die(mysqli_error($con));while($row=mysqli_fetch_array($sql)){ ?>
                        <tr>
                          <td><input type="checkbox" name="deletegallery[]" class="WeAreDelete" value="<?php echo $row['id']; ?>"></td>
                          <td><?php echo $n; ?>.</td>
                          <td>
                            <?php  $cat_id=$row['vcat_id']; $sql0=mysqli_query($con, "select * from video_category where id='$cat_id'")or die(mysqli_error($con));$row1=mysqli_fetch_array($sql0); ?>
                            <?php echo $row1['vcat_name']; ?>
                            <?php //} ?>
                          </td>
                          <td><?php echo ($row['video_link']); ?></td>
                          <td>
                          <a href="edit-video.php?id=<?php echo $row['id'] ?>"><i class="fa fa-pencil-square"></i></a>
                         </td>
                    
                          <td>
                            <a href="video.php?deleteid=<?php echo $row['id'] ?>"><i class="fa fa-trash-o"></i></a>
                          </td>
                        </tr>
                        <?php  $n++; } ?>
                      </tbody>
                      <tfoot>
                      <tr>
                        <td>
                          <input type="submit" name="delete" class="btn btn-danger deletegallery" value="Delete Selected">
                        </td>
                      </tr>
                      </tfoot>
                    
                  </table>
                </form>
                </div>
              </div>
            </div>
          </div>
          <div class="col-md-5">
            <div class="box box-success">
              <div class="box-header">
                <h3 class="box-title">Add Video</h3>
              </div>
              <div class="box-body">
                <form action="" method="post" enctype="multipart/form-data">
           
                  <div class="form-group show-me" >
                    <label>Video Category: <strong style="color: red"></strong></label>
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-suitcase"></i>
                      </div>
                      <select class="form-control" name="video_category">
                        <option value=""></option>
                        <?php $sql=mysqli_query($con, "SELECT * FROM `video_category`");while($row=mysqli_fetch_array($sql)){ ?>
                          <option value="<?php echo $row['id'] ?>"><?php echo $row['vcat_name'] ?></option>
                        <?php } ?>
                      </select>
                    </div>
                  </div>
              
                  <div class="form-group">
                    <label>Video Link: <strong style="color: red"></strong></label>
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-suitcase"></i>
                      </div>
                      <input type="text" name="video" class="form-control" required="">
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="input-group">
                      <input type="submit" name="submit" class="btn btn-success btn-md" value="Submit">
                    </div>
                  </div>
                </form>
              </div>
              <!-- /.box-body -->
            </div>
          </div>
        </div>
      </section>
    </div>
    <?php include("includes/footer.php")?>
  </div>
  <?php include("includes/js.php")?>
  <script>
    $('.type').change(function(){
      if($(this).val()==2)
      {
        $('.hide-me').remove();
        $('.show-me').show();
      }
    })
  $(function () {
  $('#example1').DataTable()
  $('#example2').DataTable({
  'paging'      : true,
  'lengthChange': false,
  'searching'   : false,
  'ordering'    : true,
  'info'        : true,
  'autoWidth'   : false
  })
  })
  $('.checkAll').click(function(){
    $('.WeAreDelete').prop('checked', $(this).prop('checked'));
  })
  </script>
</body>
</html>