<?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['logo_image_name']['name']; 
$image_names= time()."_".$image_name;
$del_image = $_POST['del_image'];
?>  
  <?php
if(isset($_REQUEST['Insert']))
{
    $sqlinsrt = "INSERT INTO `client_logo`(`logo_image_name`, `type`) VALUES ('$image_names','1')";
      if(mysqli_query($link,$sqlinsrt))
        {
          move_uploaded_file($_FILES['logo_image_name']['tmp_name'],"../logo-images/".$image_names);
          $img = "<p style='color:green;'>Save Update successfully!!!!!</p>";
        }             
}
?> 
<?php
if(isset($_REQUEST['client_logo_id'])!="")
{   
    $logo_link=$_REQUEST['logo_link'];
    if(isset($_REQUEST['Updt']))
    {
      if($_FILES['logo_image_name']['name']!=="")
      {
        $sqlUp = "UPDATE `client_logo` SET 
                          `logo_link`='$logo_link',
                          `logo_image_name`='$image_names' 
                          WHERE `client_logo_id` ='$_REQUEST[client_logo_id]'";
                          if(mysqli_query($link,$sqlUp))
                          {
                            unlink("../logo-images/$del_image"); 
                            move_uploaded_file($_FILES['logo_image_name']['tmp_name'],"../logo-images/".$image_names);
                            $img = "<p style='color:green;'>Image Update successfully!!!!!</p>";
                          }

      }
      else
      {
          $sqlUp = "UPDATE `client_logo` SET 
                          `logo_link`='$logo_link' 
                          WHERE `client_logo_id` ='$_REQUEST[client_logo_id]'";
                          if(mysqli_query($link,$sqlUp))
                          {
                            $img = "<p style='color:green;'>Update successfully!!!!!</p>";
                          }
      }
               
    }
}
?> 
<?php 
if($_REQUEST['del_logo_id']!="")
{
    $del_logo_id=$_REQUEST['del_logo_id'];
    $sql="delete from client_logo where client_logo_id='$del_logo_id'";
      if(mysqli_query($link,$sql))
                 {
                  unlink("../logo-images/$del_image");
                   $img = "<p style='color:green;'>Image Delete successfully!!!!!</p>";
                 } 
    
}
?>
<?php 
$sqlImage="SELECT * FROM `client_logo` WHERE `type`=1";
$data= mysqli_query($link,$sqlImage);
?>
    <section id="page-title" class="row">
      <div class="col-md-8">
        <h1>Brands </h1>
        <p class="lead">Update your Brands </strong>.</p>
         <label>image size (176 x 132)pixel:</label>
            
          <?=$img;?>
      </div>
      <div class="col-md-4">
       <!--  <ol class="breadcrumb pull-right no-margin-bottom">
          <li><a href="dashboard.php">Client Logo</a></li>
          <li class="active">Update Clients / Brands Logo</li>
        </ol> -->
      </div>
    </section>
    <!-- / PAGE TITLE -->
    <div class="container-fluid">
      <div class="row">
      <?php
                while($resultImg=mysqli_fetch_array($data)){
				?> 
        <form method="post" enctype="multipart/form-data">
        <div class="col-md-3">
         <section class="panel tasks-widget"> <img  src="../logo-images/<?=$resultImg['logo_image_name'];?>" class="img-responsive" style="height:200px; width:100%;"> </section>
          <div class="text-center"> 
            <input type="file" name="logo_image_name" class="btn btn-primary"> </div>
            <!-- <input type="text" class="form-control" placeholder="Linking.." name="logo_link" value="<?=$resultImg['logo_link'];?>"> -->
          <div class="text-center"> 
            <input type="hidden" name="client_logo_id" value="<?php echo $resultImg['client_logo_id'];?>" class="btn btn-primary"> 
            <input type="hidden" name="del_image" value="<?=$resultImg['logo_image_name'];?>">
          </div>
             
          <div class="text-center"> <button type="submit" name="Updt" class="btn btn-primary" style="float:right; width:100%;">Update  </button></div>
          </form>
          <form method="post">
           <div class="text-center"> 
           <input type="hidden" name="del_logo_id" value="<?php echo $resultImg['client_logo_id'];?>" class="btn btn-primary">
           <input type="hidden" name="del_image" value="<?=$resultImg['logo_image_name'];?>"> 
          </div>
           <div class="text-center"> <button type="submit" name="Updt" class="btn btn-primary" style="float:right; width:100%;">Delete  </button></div></form>
        </div>
        
          
        <?php } ?>
       
      </div>
      <!-- / row -->
    </div>
    <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="logo_image_name" class="btn btn-primary"> </div>
            <div class="text-center"> <button type="submit" name="Insert" class="btn btn-primary" style=" width:100%;">Add  </button></div>
          </div>
        </form>
        <div class="col-md-4"></div>
      </div>
      <!-- / row -->
    </div>
    
    <!-- / container-fluid -->
 <?php include('site-footer.php'); ?>