<?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 
   $pro_id=$_GET['pro_id'];
   
    $tmp = $_FILES['gal_image']['tmp_name'];
    $fn = $_FILES['gal_image']['name'];
    $ext = explode(".",$fn);
    $extt = end($ext);
    $fnn = rand().".$extt";

   // $image_name=$_FILES['gal_image']['name']; 
   // $image_names= time()."_".$image_name;
   ?>
<?php
   if(isset($_REQUEST['Insert']))
   {
      $sqlinsrt = "INSERT INTO `tbl_pro_gallery`(`pro_id`, `gal_image`) VALUES ('$pro_id','$fnn')";
      
      if(mysqli_query($link,$sqlinsrt))
                 {
                    move_uploaded_file($tmp, "../product-image/$fnn");
                   // move_uploaded_file($_FILES['gal_image']['tmp_name'],"../gallery-image/".$image_names); 
                   $img = "<p style='color:green;'>Image Upload successfully!!!!!</p>";
                 }        
   }
   ?> 
<?php
   if(isset($_REQUEST['Updt']))
   {
   if($_FILES['gal_image']['name']=="")
   { 
      $sqlu="select * from tbl_pro_gallery where gal_id='$_REQUEST[img_id]'";
      $datau=mysql_query($sqlu);
      $resultu=mysql_fetch_array($datau);
      $fnn=$resultu['gal_image'];
   }
   $del_image = $_REQUEST['del_image'];
   $gal_name =$_REQUEST['gal_name'];
   $gal_category = $_REQUEST['gal_category'];
   $sqlUp ="UPDATE `tbl_pro_gallery` SET 
                     `gal_name`='$gal_name',
                     `gal_category`='$gal_category',
                     `gal_image`='$fnn' 
                     WHERE `gal_id`='$_REQUEST[img_id]'";
   
   mysql_query($sqlUp);
     if(move_uploaded_file($tmp, "../product-image/$fnn"))
     {
      unlink("../product-image/$del_image"); 
      $img = "<p style='color:green;'>update successfully!!!!!</p>";
     }        
   }
   ?> 
<?php 
   if($_REQUEST['del_logo_id']!=""){
   $del_logo_id=$_REQUEST['del_logo_id'];
   echo $del_image = $_REQUEST['del_image'];
   $sql="delete from tbl_pro_gallery where gal_id='$del_logo_id'";
     if($data=mysql_query($sql))
     {
      unlink("../gallery-image/$del_image");
     }
   }
   ?>
<?php
   $sql="SELECT * FROM `tbl_pro_gallery` WHERE `pro_id`='$pro_id'";
   $data=mysql_query($sql);
   $count=mysql_num_rows($data);
   ?>     
<section id="page-title" class="row">
   <div class="col-md-8">
      <h1>Gallery Image</h1>
      <p class="lead">Update your Gallery Image</strong>.</p>
      <p style="font-weight: bold;font-size:18px;">Gallery Image Size(408 x 300)Pixel</p>
      <?=$img;?>
      <a href="product-item.php" class="btn btn-primary">Back</a>
   </div>
   <div class="col-md-4">
   </div>
</section>
<!-- / PAGE TITLE -->
<div class="container-fluid">
   <div class="row">
      <?php while($result=mysql_fetch_array($data)){ ?>
      <form enctype="multipart/form-data" method="post">
         <div class="col-md-4">
            <section class="panel tasks-widget"> <img  src="../product-image/<?php echo $result['gal_image']; ?>" class="img-responsive" style="height:280px; width:100%;"> </section>
            <div class="text-center"><input type="file" name="gal_image"></div>
             <label> Title:</label>
            <input type="text" value="<?=$result['gal_name'];?>" name="gal_name" class="form-control"> 
             <label>Sub Title:</label>
            <input type="text" value="<?=$result['gal_category'];?>" name="gal_category" class="form-control"> 
            <input type="hidden" name="del_image" value="<?php echo $result['gal_image']; ?>">
            <input type="hidden" name="img_id" value="<?php echo $result['gal_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_image" value="<?php echo $result['gal_image']; ?>">
      <input type="hidden" name="del_logo_id" value="<?php echo $result['gal_id'] ?>">
      <div class="text-center"><button class="btn btn-primary" name="del" style="width:100%;">Delete</button> </div> 
      </form>
      </div>
      <?php } ?>
   </div>
   <!-- / row -->
</div>
<?php if($count>=5000){ 
   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="gal_image" 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 -->
<?php include('site-footer.php'); ?>