<?php include('site-header.php'); ?>
<!-- end of LOGO CONTAINER -->
<!-- - - - - - - - - - - - - -->
<!-- start of SIDEBAR        -->
<!-- - - - - - - - - - - - - -->
<?php include('left-nevigation.php'); ?>
<!-- - - - - - - - - - - - - -->
<!-- end of SIDEBAR          -->
<!-- - - - - - - - - - - - - -->
<main id="playground">
  <script src="ckeditor/ckeditor.js"></script>
  
<!-- - - - - - - - - - - - - -->
<!-- start of TOP NAVIGATION -->
<!-- - - - - - - - - - - - - -->
<?php include('site-top-header.php'); ?>
<!-- - - - - - - - - - - - - -->
<!-- end of TOP NAVIGATION   -->
<!-- - - - - - - - - - - - - -->
<!-- PAGE TITLE -->
<?php 
extract($_POST);
   $image_name=$_FILES['header_image_name']['name']; 
   $image_names= time()."_".$image_name;
   ?>
<?php
   if(isset($_REQUEST['Insert']))
   {
     $sqlinsrt ="INSERT INTO `tbl_small_banner1`(`header_image_name`,`type`) VALUES ('$image_names','1')";
          if(mysqli_query($link,$sqlinsrt))
                 {
                   move_uploaded_file($_FILES['header_image_name']['tmp_name'],"../header-image/".$image_names); 
                   $img = "<p style='color:green;'>Save Banner successfully!!!!!</p>";
                 }
   
   }
   ?> 
<?php
   if(isset($_REQUEST['Updt']))
   {
         if($_FILES['header_image_name']['name']!=="")
          { 
            $sqlUp = "UPDATE `tbl_small_banner1` SET 
                              `header_image_name`='$image_names',
                              `title1`= '$title1',
                              `title2`= '$title2',
                              `title3`= '$title3',
                              `title4`= '$title4',
                              `limking`='$limking'
                              WHERE `header_id`='$_REQUEST[img_id]'";
           
            if(mysqli_query($link,$sqlUp))
                 {
                   unlink("../header-image/$del_image"); 
                   move_uploaded_file($_FILES['header_image_name']['tmp_name'],"../header-image/".$image_names); 
                   $img = "<p style='color:green;'> Upload Banner successfully!!!!!</p>";
                 }
        }
        else
        {
            $sqlUp = "UPDATE `tbl_small_banner1` SET 
                              `title1`= '$title1',
                              `title2`= '$title2',
                              `title3`= '$title3',
                              `title4`= '$title4',
                              `limking`='$limking'
                              WHERE `header_id`='$_REQUEST[img_id]'"; 

            if(mysqli_query($link,$sqlUp))
                    {
                       $img = "<p style='color:green;'>Update Banner successfully!!!!!</p>";
                    }
        }
           
   }
   ?> 
<?php 
   if($_REQUEST['del_logo_id']!="")
   {
         $del_logo_id=$_REQUEST['del_logo_id'];
         $sql="DELETE FROM `tbl_small_banner1` WHERE  header_id='$del_logo_id'";
         if(mysqli_query($link,$sql))
                       {
                        unlink("../header-image/$del_image"); 
                         $img = "<p style='color:green;'>Delete Image  successfully!!!!!</p>";
                       }
   }
   ?>
<?php
   $sql="SELECT * FROM `tbl_small_banner1` WHERE `type`=1";
   $data=mysqli_query($link,$sql);
   $count=mysqli_num_rows($data);
   ?>     
<section id="page-title" class="row">
   <div class="col-md-8">
      <h1>Home Promotions Banner</h1>
      <p class="lead">Update your Home Promotions  Banner in home page</strong>.</p>
      <p style="font-weight: bold;font-size:18px;">Image Size(1117 x 650)Pixel</p>
      <?=$img?>
   </div>
   <div class="col-md-4">
   </div>
</section>
<!-- / PAGE TITLE -->
<div class="container-fluid">
   <div class="row">
      <?php 
      $sn=1;
      while($result=mysqli_fetch_array($data)){ ?>
      <form enctype="multipart/form-data" method="post">
          <div class="col-md-12">
            
             <section class="panel tasks-widget"> <img  src="../header-image/<?php echo $result['header_image_name']; ?>" class="img-responsive" style="height:280px; width:100%;"> </section>
              <div class="text-center">
                <input type="file" name="header_image_name">
              </div>
              <input type="text" name="title1" value="<?php echo $result['title1'] ?>" class="form-control" placeholder="Line 1.........">
              <input type="text" name="title2" value="<?php echo $result['title2'] ?>" class="form-control" placeholder="Line 2......">
             <!-- <input type="text" name="title3" value="<?php echo $result['title3'] ?>" class="form-control" placeholder="Line 3........">-->
              
               <input type="text" name="title4" value="<?php echo $result['title4'] ?>" class="form-control" placeholder="Line 4......."> 
              <input type="text" name="limking" value="<?php echo $result['limking'] ?>" class="form-control" placeholder="limking .........">
              <input type="hidden" name="img_id" value="<?php echo $result['header_id'] ?>">
              <input type="hidden" name="del_image" value="<?php echo $result['header_image_name'] ?>">
               <div class="text-center">
                  <button class="btn btn-primary" name="Updt" style="width:100%; margin-top: 20px;">Update</button> 
                </div>
      </form>
     <form method="post">
          <input type="hidden" name="del_logo_id" value="<?php echo $result['header_id'] ?>">
          <input type="hidden" name="del_image" value="<?php echo $result['header_image_name'] ?>">
          <div class="text-center">
           <!--  <button class="btn btn-primary" name="del" style="width:100%;">Delete</button>  -->
          </div> 
      </form> 
      </div>
      <?php
      $sn++;
       } ?>
   
   <!-- / row -->
</div>
<?php if($count>=1){ 
   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="header_image_name" class="btn btn-primary" > </div>
            <div class="text-center"> <button type="submit" name="Insert" class="btn btn-primary" style=" width:100%;">Add Image </button></div>
         </div>
      </form>
      <div class="col-md-4">
      </div>
   </div>
   <!-- / row -->
</div>
<?php } ?>
<!-- / container-fluid -->
    <script>
      CKEDITOR.replace(ckeditor1);
      CKEDITOR.replace(ckeditor2);
      CKEDITOR.replace(ckeditor3);
        CKEDITOR.replace(ckeditor4);
    </script>

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