/home/hdwebsolution/public_html/ns-interior/admin-pages/update-conversions.php
<?php include('site-header.php'); ?>
<!-- end of LOGO CONTAINER -->
<!-- - - - - - - - - - - - - -->
<!-- start of SIDEBAR        -->
<!-- - - - - - - - - - - - - -->
<?php include('left-nevigation.php'); ?>
<!-- - - - - - - - - - - - - -->
<!-- end of SIDEBAR          -->
<!-- - - - - - - - - - - - - -->
<script src="ckeditor/ckeditor.js"></script>  

<main id="playground">
<?php include('site-top-header.php'); ?>

<?php 
   $image_name = $_FILES['header_image_name']['name']; 
   $image_names = time()."_".$image_name;
?>
<?php
   if (isset($_REQUEST['Insert'])) {
       $sqlinsrt = "INSERT INTO `header_flash4`(`header_image_name`) VALUES ('$image_names')";
      
      if (mysqli_query($link, $sqlinsrt)) {
          move_uploaded_file($_FILES['header_image_name']['tmp_name'], "../header-image/".$image_names);
          $img = "<p style='color:green;'>Update Image successfully!!!!!</p>";
      }
   }
?>
<?php
   if (isset($_REQUEST['Updt'])) {
       $flash_title = $_REQUEST['flash_title'];
       $flash_sub_title = $_REQUEST['flash_sub_title'];
       $flash_sub_sub_title = $_REQUEST['flash_sub_sub_title'];
       $flash_link = $_REQUEST['flash_link'];
       
       if ($_FILES['header_image_name']['name'] == "") { 
           $sqlu = "SELECT * FROM header_flash4 WHERE header_id='$_REQUEST[img_id]'";
           $datau = mysqli_query($link, $sqlu);
           $resultu = mysqli_fetch_array($datau);
           $image_names = $resultu['header_image_name'];
       }

       $sqlinsrt = "UPDATE `header_flash4` SET
           `flash_title` = '$flash_title',
           `flash_sub_title` = '$flash_sub_title', 
           `flash_sub_sub_title` = '$flash_sub_sub_title',
           `flash_link` = '$flash_link',
           `header_image_name` = '$image_names'
           WHERE header_id = '$_REQUEST[img_id]'";
       
       if (mysqli_query($link, $sqlinsrt)) {
           move_uploaded_file($_FILES['header_image_name']['tmp_name'], "../header-image/".$image_names);
           $img = "<p style='color:green;'>Update successfully!!!!!</p>";
       }
   }
?>
<?php 
   if ($_REQUEST['del_logo_id'] != "") {
       $del_logo_id = $_REQUEST['del_logo_id'];
       $sql = "DELETE FROM header_flash4 WHERE header_id='$del_logo_id'";
       
       if (mysqli_query($link, $sql)) {
           move_uploaded_file($_FILES['header_image_name']['tmp_name'], "../header-image/".$image_names);
           $img = "<p style='color:green;'>Delete Image successfully!!!!!</p>";
       }
   }
?>

<?php
   $sql = "SELECT * FROM `header_flash4` ORDER BY `header_id`";
   $data = mysqli_query($link, $sql);
   $count = mysqli_num_rows($data);
?>
<section id="page-title" class="row">
   <div class="col-md-8">
      <h1>Conversion Image</h1>
      <p class="lead">Update your page</strong>.</p>
      <?=$img;?>
   </div>
   <div class="col-md-4"></div>
</section>

<div class="container-fluid">
   <div class="row">
      <?php 
      $sn = 1; // Initialize CKEditor counter before the loop
      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['header_image_name'];?>" class="img-responsive" style="height:280px; width:100%;"> 
            </section>
            <div class="text-center"><input type="file" name="header_image_name"></div>
           
            <label>Title :</label>
            <input type="text" name="flash_title" class="form-control" value="<?=$result['flash_title'];?>" >
           
            <label>Description :</label>
            <textarea name="flash_sub_sub_title" placeholder="Description......" class="form-control" id="ckeditor<?=$sn;?>" style="width: 100%; height:100px;">
                <?=$result['flash_sub_sub_title'];?>
            </textarea> 

            <label>Links :</label>
            <input type="text" name="flash_link" class="form-control" value="<?=$result['flash_link'];?>" >
            
            <input type="hidden" name="img_id" value="<?=$result['header_id']?>">
            <div class="text-center"><button class="btn btn-primary" name="Updt" style="width:100%;">Update</button> </div>
         </form>
         <form method="post">
            <input type="hidden" name="del_logo_id" value="<?=$result['header_id']?>">
            <div class="text-center"><button class="btn btn-primary" name="del" style="width:100%;">Delete</button></div>
         </form>
         </div>
      <?php 
         $sn++; // Increment CKEditor counter
      } ?>
   </div>
   <!-- / row -->
</div>

<?php if($count >= 100){ 
   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 } ?>

<script>
// Dynamically replace textareas with CKEditor instances
<?php for($i = 1; $i < $sn; $i++) { ?>
   CKEDITOR.replace('ckeditor<?=$i;?>');
<?php } ?>
</script>

<?php include('site-footer.php'); ?>