D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
aviscollection.com
/
admin
/
Filename :
manage-offer.php
back
Copy
<?php include'config.php'; include'function.php'; $action = $_GET['action']; $action_title = stringModify($action); $item_title = ""; $item_content = ""; $item_status = ''; $item_img = ""; if($action == 'delete_offer'){ $del_id = $_GET['id']; $del_gallery = mysqli_query($conn, "DELETE FROM `offers` WHERE offer_id = '$del_id'"); if ($del_event) { echo '<script>alert("Image data deleted.")</script>'; echo '<script> window.location.href = "offer-list";</script>'; } } if($action == 'edit_offer'){ $edit_id = $_GET['id']; $view_gallery = mysqli_query($conn, "SELECT * FROM offers WHERE offer_id = '$edit_id'"); while($row = mysqli_fetch_array($view_gallery)) { $item_title = $row['offer_title']; $item_content = $row['offer_category']; $item_img = $row['offer_img']; } } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Manage Offers | <?php echo $company; ?></title> <?php include'style.php'; ?> </head> <body> <div id="layout-wrapper"> <?php include'header.php'; ?> <div class="main-content"> <div class="page-content"> <div class="container-fluid"> <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="offer-list">Offers List</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> <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">Offer Title:</label> <input class="form-control" type="text" value="<?php echo $item_title; ?>" name="item_title" placeholder="Offer Title"> </div> <div class="col-12 mb-3"> <label for="example-text-input" class="form-label">Offer Details:</label> <textarea class="form-control" name="item_content" placeholder="Offer Details"><?php echo $item_content; ?></textarea> </div> <div class="mb-3"> <label for="example-text-input" class="form-label">Offer Image:</label> <input class="form-control" type="file" value="<?php echo $item_img; ?>" name="item_img" placeholder="Offer Image"> </div> <div class="mb-3"> <label for="example-text-input" class="form-label">product status:</label> <?php if($item_status == 1){ echo '<div class="form-check"> <input class="form-check-input" type="radio" name="item_status" id="flexRadioDefault1" value="1" checked> <label class="form-check-label" for="flexRadioDefault1">Active</label> </div> <div class="form-check"> <input class="form-check-input" type="radio" name="item_status" id="flexRadioDefault2" value="0"> <label class="form-check-label" for="flexRadioDefault2">Inactive</label> </div>'; } elseif ($item_status === 0) { echo '<div class="form-check"> <input class="form-check-input" type="radio" name="item_status" id="flexRadioDefault1" value="1" > <label class="form-check-label" for="flexRadioDefault1">Active</label> </div> <div class="form-check"> <input class="form-check-input" type="radio" name="item_status" id="flexRadioDefault2" value="0" checked> <label class="form-check-label" for="flexRadioDefault2">Inactive</label> </div>'; } else{ echo '<div class="form-check"> <input class="form-check-input" type="radio" name="item_status" id="flexRadioDefault1" value="1" checked> <label class="form-check-label" for="flexRadioDefault1">Active</label> </div> <div class="form-check"> <input class="form-check-input" type="radio" name="item_status" id="flexRadioDefault2" value="0"> <label class="form-check-label" for="flexRadioDefault2">Inactive</label> </div>'; }?> </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_offer'])){ $item_title = $_POST['item_title']; $item_content = $_POST['item_content']; $item_status = $_POST['item_status']; $imgdir = 'offer-images'; if(!is_dir($imgdir)){ mkdir($imgdir); } $item_img = $_FILES['item_img']['name']; $tmp_img = $_FILES['item_img']['tmp_name']; $item_path = $imgdir ."/". $item_img; if(move_uploaded_file($tmp_img, $item_path)){ echo '<script>alert("Image uploaded.")</script>'; } else{ echo '<script>alert("Image not uploaded.")</script>'; } $insert_qury = "insert into offers() values('', '$item_title', '$item_content', '$item_img', $item_status)"; $run_query = mysqli_query($conn, $insert_qury) or mysqli_error($conn); if ($run_query){ ?> <script> var ask = window.confirm('Are you sure you want to Add more Offers?'); if (ask) { window.alert('Offer uploaded.'); } else{ window.alert('Offer uploaded.'); window.location.href = "offer-list"; } </script> <?php } else{ echo '<script>alert("Offer not uploaded.")</script>'; } } if (isset($_POST['edit_offer'])) { $item_title = $_POST['item_title']; $item_content = $_POST['item_content']; $ItemImg_Condition = ''; if ($_FILES['item_img']['name'] != '') { $item_img = $_FILES['item_img']['name']; $ItemImg_path = 'offer-images/'.$item_img; move_uploaded_file($_FILES['item_img']['tmp_name'], $ItemImg_path); $ItemImg_Condition = ", offer_img='$item_img'"; } $update_event = mysqli_query($conn, "UPDATE offers SET `offer_title`='$item_title', `offer_content`='$item_content' $ItemImg_Condition WHERE `offer_id` = '$edit_id'"); if ($update_event){ echo '<script>alert("Offer data edited.")</script>'; echo '<script> window.location.href = "offer-list";</script>'; } else{ echo '<script>alert("Offer data not edited.")</script>'; } } ?>