D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
guruglobalpreschool.com
/
admin
/
Filename :
manage-category.php
back
Copy
<?php include'config.php'; include'function.php'; error_reporting(); $action = $_GET['action']; $action_title = stringModify($action); $item_name = ''; $item_img = ''; $item_status = ''; if($action == 'delete_category'){ $del_id = $_GET['id']; $del_event = mysqli_query($conn, "DELETE FROM `gallery_category` WHERE category_id = '$del_id'"); if ($del_event) { echo '<script>alert("Category data deleted.")</script>'; echo '<script> window.location.href = "gallery_category.php";</script>'; } } if($action == 'edit_category'){ $edit_id = $_GET['id']; $view_event = mysqli_query($conn, "SELECT * FROM `gallery_category` WHERE category_id = '$edit_id'") or mysqli_error($conn); while($row = mysqli_fetch_array($view_event)) { echo $item_id = $row['category_id']; echo $item_name = $row['category_name']; echo $item_img = $row['category_img']; echo $item_status = $row['category_status']; } } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Admin, Manage Gallery Category| <?php echo $company; ?></title> <?php include'style.php'; ?> </head> <body> <!-- Begin page --> <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; ?></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="card"> <div class="card-body p-4"> <div class="row"> <div class="col-lg-8 col-sm-12 col-xs-12"> <form action="" method="POST" enctype="multipart/form-data" > <div class="mb-3"> <label for="example-text-input" class="form-label">Category name:</label> <input class="form-control" type="text" value="<?php echo $item_name; ?>" id="example-text-input" name="item_name" placeholder="Category name" required> </div> <div class="mb-3"> <label for="example-text-input" class="form-label">Category Image:</label> <input class="form-control" type="file" name="item_img" placeholder="Category Image"> </div> <div class="mb-3"> <label for="example-text-input" class="form-label">Category status:</label> <!-- <input type="text" class="form-control" name="item_status" placeholder="" value="<?php echo $item_status;?>"> --> <?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 class="col-lg-4 col-sm-12 col-xs-12"> <div class="data_img"> <img src="gallery-category/<?php echo $item_img; ?>" style="height:200px;width: auto;" alt="<?php echo $item_img; ?>"> </div> </div> </div> </div> </div> </div> </div> <?php include'right-sidebar.php'; ?> <?php include'script.php'; ?> </body> </html> <?php if (isset($_POST['add_category'])) { $item_name = $_POST['item_name']; $item_category = $_POST['item_category']; $item_status = $_POST['item_status']; if ($_POST['item_status'] != '') {$item_status = $_POST['item_status'];} else{ $item_status = 0;} $uploaddir = 'gallery-category'; if(!is_dir($uploaddir)){ mkdir($uploaddir); } $item_img = $_FILES['item_img']['name']; $item_tmp = $_FILES['item_img']['tmp_name']; $item_path = $uploaddir ."/". $item_img; if(move_uploaded_file($item_tmp, $item_path)){ echo '<script>alert("Category image uploaded.")</script>'; }else{ echo '<script>alert("Category image not uploaded.")</script>'; } $insrt_item = "insert into gallery_category() values('', '$item_name', '$item_img', '$item_status')"; $run_query = mysqli_query($conn, $insrt_item) or die(mysqli_error($conn)); if ($run_query){ echo '<script>alert("Gallery Category data uploaded.")</script>';?> <script> var ask = window.confirm('You want to add more Gallery?'); if (ask) { window.alert('Gallery uploaded in Review List.'); } else{ window.alert('Gallery uploaded in Gallery List.'); window.location.href = "gallery_category.php"; } </script> <?php } else{ echo '<script>alert("Gallery Category data not uploaded.")</script>'; } } if (isset($_POST['edit_category'])) { $item_name = $_POST['item_name']; $item_status = $_POST['item_status']; $itemImg_Condition = ''; if ($_FILES['item_img']['name'] != '') { $item_img = $_FILES['item_img']['name']; $itemImg_path = 'gallery-category/'.$item_img; move_uploaded_file($_FILES['item_img']['tmp_name'], $itemImg_path); $itemImg_Condition = ", category_img='$item_img'"; } echo $update_item = "UPDATE `gallery_category` SET `category_name`='$item_name' $itemImg_Condition ,`category_status`='$item_status' WHERE `category_id` = '$edit_id'"; $run_query = mysqli_query($conn, $update_item) or mysqli_error($conn); if ($run_query){ echo '<script>alert("Category data edited.")</script>'; // echo '<script> window.location.href = "gallery_category.php";</script>'; } else{ echo '<script>alert("Category data not edited.")</script>'; } } ?>