<?php
session_start();
include 'include/config.php';

// if(!isset($_SESSION['id'])){
//  echo "<script> window.location.href = 'index.php' </script>";
//   }
?>

<?php
$idddddd = $_GET['iddd'];
$fch = mysqli_fetch_assoc(mysqli_query($conn,"select * from `other` where `id`='$idddddd'"));
?>

<?php
       if(isset($_POST['submitt'])){
    $privcy_police = $_POST['privcy_police'];
    $disclaimer = $_POST['disclaimer'];
    $term_condition = $_POST['term_condition'];
    $support_mail = $_POST['support_mail'];
    // $address = $_POST['address'];
    // $gst = $_POST['gst'];
    // $about_shop = $_POST['about_shop'];
    // $map_address = $_POST['map_address'];
    // $rating      = $_POST['rating'];
    // $status = $_POST['status'];

    // Check if a new image is uploaded
    if(!empty($_FILES['image1']['name'])) {
        $image = $_FILES['image1']['name'];
        $tmp_name = $_FILES['image1']['tmp_name'];
        $image_url = 'https://createapp.co.in/findmySpa/upload/' . $image;

        // Update the database with the new image information
       
        
        $sql = "UPDATE `other` SET `privcy_police`='$privcy_police',`disclaimer`='$disclaimer',`term_condition`='$term_condition',`support_mail`='$support_mail',
                          `slide_img_1`='$image_url' WHERE `id`='$idddddd'";
        $res = mysqli_query($conn, $sql);

        if($res) {
            // Move the new image to the upload directory
            move_uploaded_file($tmp_name, '../upload/' . $image);
            echo "<h6> Other Updated </h6>";
            echo "<script>window.location.href='otherr_edit.php'</script>";
        } else {
            echo "<h6> Update Failed </h6>";
        }
    } elseif(!empty($_FILES['image2']['name'])) {
        $image2 = $_FILES['image2']['name'];
        $tmp_name2 = $_FILES['image2']['tmp_name'];
        $image_url2 = 'https://createapp.co.in/findmySpa/upload/' . $image2;

        // Update the database with the new image information
       $sql = "UPDATE `other` SET `privcy_police`='$privcy_police',`disclaimer`='$disclaimer',`term_condition`='$term_condition',`support_mail`='$support_mail',
                          `slide_img_2`='$image_url2' WHERE `id`='$idddddd'";
        $res = mysqli_query($conn, $sql);

         if($res) {
            // Move the new image to the upload directory
            move_uploaded_file($tmp_name2, '../upload/' . $image2);
            echo "<h6> Other Updated </h6>";
            echo "<script>window.location.href='otherr_edit.php'</script>";
        }else {
            echo "<h6> Update Failed </h6>";
        }
    }elseif(!empty($_FILES['image3']['name'])) {
        $image3 = $_FILES['image3']['name'];
        $tmp_name3 = $_FILES['image3']['tmp_name'];
        $image_url3 = 'https://createapp.co.in/findmySpa/upload/' . $image3;

        // Update the database with the new image information
        $sql = "UPDATE `other` SET `privcy_police`='$privcy_police',`disclaimer`='$disclaimer',`term_condition`='$term_condition',`support_mail`='$support_mail',
                          `slide_img_3`='$image_url3' WHERE `id`='$idddddd'";
        $res = mysqli_query($conn, $sql);

        if($res) {
            // Move the new image to the upload directory
            move_uploaded_file($tmp_name3, '../upload/' . $image_url3);
            echo "<h6> Other Updated </h6>";
            echo "<script>window.location.href='otherr_edit.php'</script>";
        } else {
            echo "<h6> Update Failed </h6>";
        }
    }else  
    {
        // If no new image is provided, update only the non-image fields in the database
        $sql = "UPDATE `other` SET `privcy_police`='$privcy_police',`disclaimer`='$disclaimer',`term_condition`='$term_condition',`support_mail`='$support_mail'
                           WHERE `id`='$idddddd'";
                           
        $res = mysqli_query($conn, $sql);

        if($res) {
            echo "<h6> Other Updated </h6>";
             echo "<script>window.location.href='otherr_edit.php'</script>";
        } else {
            echo "<h6> Update Failed </h6>";
        }
    }
}
?>

<?php  include 'include/head.php'; ?>
 <div class="container-fluid">
                        
                        <!-- start page title -->
                        <div class="row">
                            <div class="col-12">
                                <div class="page-title-box">
                                    <div class="page-title-right">
                                        <ol class="breadcrumb m-0">
                                            <li class="breadcrumb-item"><a href="">Home</a></li>
                                            <li class="breadcrumb-item active">Edit Others</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title">Edit Others</h4>
                                </div>
                            </div>
                        </div>
                        <!-- end page title --> 

                        <div class="row">
                        <div class="col-12">
                            <div class="card">
                                <div class="card-body">

                    

                             <form action=""  method="POST" enctype="multipart/form-data">
                                
                                    <!-- end nav-->
                                    <div class="tab-content">
                                        <div class="tab-pane show active">
                                            <div class="row">
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">privcy Policy</label>
                                                        <input type="text" value="<?php echo $fch['privcy_police'];?>" name="privcy_police" class="form-control" placeholder="category name">
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Disclaimer</label>
                                                        <input type="text" value="<?php echo $fch['disclaimer'];?>" name="disclaimer" class="form-control" placeholder="category name">
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Term Condition</label>
                                                        <input type="text" value="<?php echo $fch['term_condition'];?>" name="term_condition" class="form-control" placeholder="category name">
                                                    </div>
                                                </div>
                                               
                                                     <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Support Mail</label>
                                                        <input type="email" value="<?php echo $fch['support_mail'];?>" name="support_mail" class="form-control" placeholder="category name">
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Slide Image One</label>
                                                        <input type="file" value="" name="image1" class="form-control" placeholder="category name">
                                                        <?php
                                                                 $fullImagePath = $fch['slide_img_1'];
                                                                 $prefixToRemove = 'https://createapp.co.in/findmySpa/upload/';

                                                                 $imageFilename = str_replace($prefixToRemove, '', $fullImagePath);
                                                                 $imageUrl = '../upload/' . $imageFilename;
                                                                 ?>
                                                                 <img src="<?= $imageUrl; ?>" style="width: 100px; height: 60px;">
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Slide Image Two</label>
                                                        <input type="file" value="" name="image2" class="form-control" placeholder="category name">
                                                        <?php
                                                                 $fullImagePath = $fch['slide_img_2'];
                                                                 $prefixToRemove = 'https://createapp.co.in/findmySpa/upload/';

                                                                 $imageFilename = str_replace($prefixToRemove, '', $fullImagePath);
                                                                 $imageUrl = '../upload/' . $imageFilename;
                                                                 ?>
                                                                 <img src="<?= $imageUrl; ?>" style="width: 100px; height: 60px;">
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Slide Image Three</label>
                                                        <input type="file" value="" name="image3" class="form-control" placeholder="category name">
                                                        <?php
                                                                 $fullImagePath = $fch['slide_img_3'];
                                                                 $prefixToRemove = 'https://createapp.co.in/findmySpa/upload/';

                                                                 $imageFilename = str_replace($prefixToRemove, '', $fullImagePath);
                                                                 $imageUrl = '../upload/' . $imageFilename;
                                                                 ?>
                                                                 <img src="<?= $imageUrl; ?>" style="width: 100px; height: 60px;">
                                                    </div>
                                                </div>

                                                </div>
                                                
                                                
                                                </div>
                                                
                                                

                                            </div>

                                            <div class="row">
                                                <div class="clearfix"></div>
                                                <div class="col-lg-6">
                                                    <!-- Predefined Date Ranges -->
                                                    <div class="mb-3">
                                                        <input type="submit" name="submitt" class="btn btn-success" value="submit">
                                                        
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- end preview-->

                                        
                                        <!-- end preview code-->
                                    </div>
                                    <!-- end tab-content-->
                    </form>
                                </div>
                                <!-- end card-body -->
                            </div>
                            <!-- end card-->
                        </div>
                            <!-- end col -->
            </div> <!-- end row-->


                    
    </div> <!-- container -->
<?php  
include 'include/footer.php'; 
?>