<?php require_once('../auth/auth.php'); ?>  

<?php
//action.php
if(isset($_POST["action"]))
{
 if($_POST["action"] == "fetch")
 {
  $query = "SELECT * FROM eco_tamplate where col_type='slider' ";
  $result = mysqli_query($conn, $query);
  $output = '
   <table class="ttable  ">  
    <tr>
     <th class="text-center">ID</th>
     <th class="text-center">Image</th>
     <th class="text-center">Change</th>
    </tr>
  ';
  while($row = mysqli_fetch_array($result))
  {
   $output .= '

    <tr>
     <td class="text-center">'.$row["eco_id"].'</td>
     <td class="text-center">
      <img src="data:image/jpeg;base64,'.base64_encode($row['img_blob'] ).'" height="60" width="75" class="img-thumbnail" />
     </td>
     <td class="text-center"><button type="button" name="update" class="btn btn-danger bt-xs update" id="'.$row["eco_id"].'"> <i class="fa fa-edit"></i> </button></td>
    </tr>
   ';
  }
  $output .= '</table>';
  echo $output;
 }

 // if($_POST["action"] == "insert")
 // {
 //  $file = addslashes(file_get_contents($_FILES["image"]["tmp_name"]));
 //  $query = "INSERT INTO eco_tamplate(col_value) VALUES ('$file')";
 //  if(mysqli_query($conn, $query))
 //  {
 //   echo 'Image Inserted into Database';
 //  }
 // }
 if($_POST["action"] == "update")
 {
  $file = addslashes(file_get_contents($_FILES["image"]["tmp_name"]));
  $query = "UPDATE eco_tamplate SET img_blob = '$file' WHERE eco_id = '".$_POST["image_id"]."'";
  if(mysqli_query($conn, $query))
  {
   echo 'Image Updated into Database';
  }
 }
 // if($_POST["action"] == "delete")
 // {
 //  $query = "DELETE FROM tbl_images WHERE id = '".$_POST["image_id"]."'";
 //  if(mysqli_query($conn, $query))
 //  {
 //   echo 'Image Deleted from Database';
 //  }
 // }
}
?>
