<?php include('site-header.php'); ?>
  <!-- end of LOGO CONTAINER -->
  <!-- - - - - - - - - - - - - -->
  <!-- start of SIDEBAR        -->
  <!-- - - - - - - - - - - - - -->
  <?php include('left-nevigation.php'); ?>
  <!-- - - - - - - - - - - - - -->
  <!-- end of SIDEBAR          -->
  <!-- - - - - - - - - - - - - -->
  <main id="playground">
    <!-- - - - - - - - - - - - - -->
    <!-- start of TOP NAVIGATION -->
    <!-- - - - - - - - - - - - - -->
     <?php include('site-top-header.php'); ?>
    <!-- - - - - - - - - - - - - -->
    <!-- end of TOP NAVIGATION   -->
    <!-- - - - - - - - - - - - - -->
    <!-- PAGE TITLE -->
<?php 
$image_name=$_FILES['banner_image_name']['name']; 
$image_names= time()."_".$image_name;
$himage = $_REQUEST['himage'];
?>
<?php
if(isset($_REQUEST['Insert']))
{
        $banner_name=$_REQUEST['banner_name'];
        $sql_Up = "INSERT INTO `tbl_banner`(`banner_name`, `banner_image_name`, `banner_type`) VALUES ('$banner_name','$image_names','1')";
        if(mysqli_query($link,$sql_Up))
            {
              move_uploaded_file($_FILES['banner_image_name']['tmp_name'],"../header-image/".$image_names);
              $msg = "<p style='color:green;'>Save Banner Successfully!!!</p>";
            }    
}
?> 
<?php
if(isset($_REQUEST['Updt']))
{       
    extract($_POST);
        
        if($_FILES['banner_image_name']['name']!=="")
        {
          $sql_up_ing = "UPDATE `tbl_banner` SET 
                                `banner_name`='$banner_name',
                                `banner_decs`='$banner_decs',
                                `banner_image_name`='$image_names',
                                `banner_link`= '$banner_link'
                                 WHERE banner_id='$img_id'";
            if(mysqli_query($link,$sql_up_ing))
                  {
                    unlink("../header-image/$himage");
                    move_uploaded_file($_FILES['banner_image_name']['tmp_name'],"../header-image/".$image_names);
                    $msg = "<p style='color:Green;'>Update Successfully!!!</p>";
                  }
        }
        else
        {
            $sql_up_ing = "UPDATE `tbl_banner` SET 
                                `banner_name`='$banner_name',
                                `banner_decs`='$banner_decs',
                                `banner_link`= '$banner_link'
                                 WHERE banner_id='$img_id'";
              if(mysqli_query($link,$sql_up_ing))
                  {
                    $msg = "<p style='color:orange;'>Update Successfully!!!</p>";
                  }
        }
               
}
?> 
<?php 
if($_REQUEST['del_banner_id']!="")
{
      $del_banner_id=$_REQUEST['del_banner_id'];
      $sql="delete from tbl_banner where banner_id='$del_banner_id'";
      if(mysqli_query($link,$sql))
                  {
                    unlink("../header-image/$himage");
                    $msg = "<p style='color:red;'>Delete Successfully!!!</p>";
                  }
}
?>
<?php
      $sql="SELECT * FROM `tbl_banner` WHERE `banner_type`='1'";
      $data = mysqli_query($link,$sql);
      $count=mysqli_num_rows($data)
?>
     
    <section id="page-title" class="row">
      <div class="col-md-8">
        <h1>Top Heder</h1>
        <p class="lead">Update your Top Header image </strong>.</p>
        <p style="font-weight: bold;font-size:18px;">
            Image Size(55 x 55)Pixel            
        </p>
        <?=$msg;?>
      </div>
      <div class="col-md-4">
        <ol class="breadcrumb pull-right no-margin-bottom">
         
          <li><a href="dashboard.html">Dashboard</a></li>
          <li class="active">Update Top Top Header</li>
        </ol>
      </div>
    </section>
    <!-- / PAGE TITLE -->
    <div class="container-fluid">
      <div class="row">
      <?php while($result=mysqli_fetch_array($data)){ ?>
      <form enctype="multipart/form-data" method="post">
         <div class="col-md-4">
          <section class="panel tasks-widget"> 
            <img  src="../header-image/<?=$result['banner_image_name']; ?>" class="img-responsive" style="width:55px; height:55px; text-align: center; margin: 0 auto;"> 
          </section>
          <div class="text-center">
            <input type="file" name="banner_image_name">
          </div>
          <input type="text" name="banner_name" placeholder="Name" class="form-control" value="<?=$result['banner_name'];?>">
          <textarea name="banner_decs" placeholder="Description......" class="form-control" style="width: 100%; height: 50px;">
             <?=$result['banner_decs'];?>
          </textarea> 
          <input type="text" name="banner_link" placeholder="banner Linking....." class="form-control" value="<?=$result['banner_link']; ?>" >
          
          <input type="hidden" name="img_id" value="<?php echo $result['banner_id'] ?>">
          <input type="hidden" name="himage" value="<?php echo $result['banner_image_name'] ?>">
          <div class="text-center"><button class="btn btn-primary" name="Updt" style="width:100%;">Update</button></a> </div>
          </form>
          <form method="post">
           <input type="hidden" name="del_banner_id" value="<?php echo $result['banner_id'] ?>">
            <input type="hidden" name="himage" value="<?php echo $result['banner_image_name'] ?>">
          <div class="text-center"><button class="btn btn-primary" name="del" style="width:100%;">Delete</button></a> </div>
         </div>
        </form>
        <?php } ?>
      </div>
      <!-- / row -->
    </div>
    <?php if($count>=10){
	echo "";
	}else{
		
		
		 ?>
    <div class="container-fluid" style="margin-top:80px;">
      <div class="row">
        <div class="col-md-4">
         
        </div>
        <form method="post" enctype="multipart/form-data">
        <div class="col-md-4">
            <div class="text-center"> 
              <input type="file" name="banner_image_name" class="btn btn-primary"> 
              <input type="text"  class="form-control" name="banner_name" style="width:100%;"> 
            </div>
            <br>
          <div class="text-center"> <button type="submit" name="Insert" class="btn btn-primary" style=" width:100%;">Add Banner </button></div>
        </div>
        </form>
        <div class="col-md-4">
          
        </div>
      </div>
      <!-- / row -->
    </div>
    <?php } ?>
    <!-- / container-fluid -->
<?php include('site-footer.php'); ?>


<script type="text/javascript">
  $('document').ready(function()
{
    $('textarea').each(function(){
            $(this).val($(this).val().trim());
        }
    );
});
</script>