D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
guruglobalpreschool.com
/
admin
/
Filename :
manage-gallery.php
back
Copy
<?php include'config.php'; include'function.php'; $action = $_GET['action']; $action_title = stringModify($action); $item_name = ""; $item_category = ""; $item_img = ""; if($action == 'delete_image'){ $del_id = $_GET['id']; $del_query = mysqli_query($conn, "DELETE FROM `image_gallery` WHERE image_id = '$del_id'"); if ($del_query) { echo '<script>alert("Image data deleted.")</script>'; echo '<script>window.location.href = "image-gallery.php";</script>'; } } if($action == 'edit_image'){ $edit_id = $_GET['id']; $view_gallery = mysqli_query($conn, "SELECT * FROM image_gallery WHERE image_id = '$edit_id'"); while($row = mysqli_fetch_array($view_gallery)) { $item_name = $row['image_name']; $item_category = $row['image_category']; $item_img = $row['image_img']; } } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Manage Gallery Images | <?php echo $company; ?></title> <?php include'style.php'; ?> </head> <body> <!-- Begin page --> <div id="layout-wrapper"> <?php include'header.php'; ?> <!-- ============================================================== --> <!-- Start right Content here --> <!-- ============================================================== --> <div class="main-content"> <div class="page-content"> <div class="container-fluid"> <!-- start page title --> <div class="row"> <div class="col-12"> <div class="page-title-box d-sm-flex align-items-center justify-content-between"> <h4 class="mb-sm-0 font-size-18"><?php echo $action_title; ?> / <span class="mx-2"><a class="" href="image-gallery.php">Image Gallery</a></span> </h4> <div class="page-title-right"> <ol class="breadcrumb m-0"> <li class="breadcrumb-item"><a href="./">Admin</a></li> <li class="breadcrumb-item active"><?php echo $action_title; ?></li> </ol> </div> </div> </div> </div> <!-- end page title --> <div class="row"> <div class="col-12"> <div class="card"> <div class="card-body p-4"> <div class="row"> <div class="col-lg-6"> <form action="" method="POST" enctype="multipart/form-data" > <div class="mb-3"> <label for="example-text-input" class="form-label">Image Title:</label> <input class="form-control" type="text" value="<?php echo $item_name; ?>" name="item_name" placeholder="Image Title"> </div> <div class="mb-3"> <label for="example-text-input" class="form-label">Image Category:</label> <?php $cat = "SELECT * FROM gallery_category"; echo $displ_cat = mysqli_query($conn, $cat) or mysqli_error($conn); echo "<select class='form-control' name='item_category'> <option value=''>select Images Category</option>"; if (mysqli_num_rows($displ_cat) > 0) { while ($row = mysqli_fetch_array($displ_cat)) { $cat = $row['category_name']; $catId = $row['category_id']; if ($item_category == $catId) { echo "<option value='$catId' selected>$cat</option>"; } else{ echo "<option value='$catId'>$cat</option>"; } } echo "</select>"; } ?> </div> <div class="mb-3"> <label for="example-text-input" class="form-label">Gallery Image:</label> <input class="form-control" type="file" value="<?php echo $item_img; ?>" name="item_img" placeholder="Gallery Image"> </div> <div class="mt-4"> <div class="btn_div"> <button type="submit" name="<?php echo $action; ?>" class="btn btn-primary w-md btn_manage"><?php echo $action_title; ?></button> </div> </div> </form> </div> </div> </div> </div> </div> <!-- end col --> </div> <!-- end row --> </div> <!-- container-fluid --> </div> <?php include'right-sidebar.php'; ?> <?php include'script.php'; ?> </body> </html> <?php if (isset($_POST['add_image'])){ $item_name = $_POST['item_name']; $item_cat = $_POST['item_category']; $gallerydir = 'images-gallery'; if(!is_dir($gallerydir)){ mkdir($gallerydir); } $item_img = $_FILES['item_img']['name']; $tmp_img = $_FILES['item_img']['tmp_name']; $gallery_path = $gallerydir ."/". $item_img; if(move_uploaded_file($tmp_img, $gallery_path)){ $insert_photo = "insert into image_gallery() values('', '$item_name', '$item_img', '$item_cat', '')"; $run_query = mysqli_query($conn, $insert_photo) or die(mysqli_error($conn)); if ($run_query){ ?> <script> var ask = window.confirm('Are you sure you want to Add more Photos?'); if (ask) { window.alert('Image uploaded in Gallery.'); } else{ window.alert('Image uploaded in Gallery.'); window.location.href = "image-gallery.php"; } </script> <?php } else{ echo '<script>alert("Image not uploaded in Gallery.")</script>'; } } else{ echo '<script>alert("Image not uploaded.")</script>'; } } if (isset($_POST['edit_image'])) { $item_name = $_POST['item_name']; $item_cat = $_POST['item_category']; $ItemImg_Condition = ''; if ($_FILES['item_img']['name'] != '') { $item_img = $_FILES['item_img']['name']; $ItemImg_path = 'images-gallery/'.$item_img; move_uploaded_file($_FILES['item_img']['tmp_name'], $ItemImg_path); $ItemImg_Condition = ", image_img='$item_img'"; } echo $update_event = "UPDATE image_gallery SET `image_name`='$item_name', `image_category`='$item_cat' $ItemImg_Condition WHERE `image_id` = '$edit_id'"; $run_event = mysqli_query($conn, $update_event) or mysqli_error($conn); if ($update_event){ echo '<script>alert("Gallery data edited.")</script>'; echo '<script> window.location.href = "image-gallery.php";</script>'; } else{ echo '<script>alert("Gallery data not edited.")</script>'; } } ?>