Mini Shell

Direktori : /home/haworld/www/admin/
Upload File :
Current File : /home/haworld/www/admin/hvac_product-add.php

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

<head>
    <?php include('include/head_admin.php');
    $page_id = '24';

    $url = '';
    $name = '';
    $image = '';
    $image_alt_tag = '';
    $description = '';

    if (isset($_GET['id']) && $_GET['id'] != '') {
        $id = get_safe_value($con, $_GET['id']);
        $image_required = '';
        $res = mysqli_query($con, "select * from hvac_product where id='$id'");
        $check = mysqli_num_rows($res);
        if ($check > 0) {
            $row = mysqli_fetch_assoc($res);
            $url = $row['url'];
            $name = $row['name'];
            $image = $row['image'];
            $image_alt_tag = $row['image_alt_tag'];
            $description = $row['description'];
        } else {
            header('location:hvac_product-all.php');
            die();
        }
    }

    if (isset($_POST['submit_hvac_product'])) {
        // prx($_POST);
        $name = get_safe_value($con, $_POST['name']);
        $url = generate_seo_friendly_title($name);
        $image_alt_tag = get_safe_value($con, $_POST['image_alt_tag']);
        $description = get_safe_value($con, $_POST['description']);

        if (isset($_GET['id']) && $_GET['id'] == 0) {
            if ($_FILES['image']['type'] != 'image/png' && $_FILES['image']['type'] != 'image/jpg' && $_FILES['image']['type'] != 'image/jpeg' && $_FILES['image']['type'] != 'image/webp') {
                $msg = "Please select only png, jpg, webp and jpeg image format";
            }
        } else {
            if ($_FILES['image']['type'] != '') {
                if ($_FILES['image']['type'] != 'image/png' && $_FILES['image']['type'] != 'image/jpg' && $_FILES['image']['type'] != 'image/jpeg' && $_FILES['image']['type'] != 'image/jpeg') {
                    $msg = "Please select only png, jpg, webp and jpeg image format";
                }
            }
        }

        $msg = "";

        if ($msg == '') {
            if (isset($_GET['id']) && $_GET['id'] != '') {
                if ($_FILES['image']['name'] != '') {
                    $image =  $_FILES['image']['name'];
                    move_uploaded_file($_FILES['image']['tmp_name'], "../media/hvac_product/" . $image);
                    mysqli_query($con, "UPDATE `hvac_product` SET `url`='$url', `name`='$name', `image`='$image',`image_alt_tag`='$image_alt_tag',`description`='$description' WHERE `id`='$id'");
                } else {
                    $update_query = "UPDATE `hvac_product` SET `url`='$url',`name`='$name',`image`='$image',`image_alt_tag`='$image_alt_tag',`description`='$description' WHERE `id`='$id'";

                    mysqli_query($con, $update_query);
                }
            } else {
                $image = rand(111111111, 999999999) . '_' . $_FILES['image']['name'];
                move_uploaded_file($_FILES['image']['tmp_name'], "../media/hvac_product/" . $image);
                $insert_query = "INSERT INTO `hvac_product`(`url`, `name`, `image`,`image_alt_tag`,`description`) 
                VALUES ('$url','$name','$image','$image_alt_tag','$description')";
                mysqli_query($con, $insert_query);
                print_r($insert_query);
            }
            header('location:hvac_product-all.php');
            die();
        }
    }
    function generate_seo_friendly_title($title)
    {
        // Convert the title to lowercase
        $title = strtolower($title);

        // Replace spaces with dashes
        $title = str_replace(' ', '-', $title);

        // Remove special characters
        $title = preg_replace('/[^A-Za-z0-9\-]/', '', $title);

        return $title;
    }
    ?>
</head>

<body>
    <!--== MAIN CONTRAINER ==-->
    <?php include('include/header_admin.php'); ?>

    <!--== BODY CONTNAINER ==-->
    <div class="container-fluid sb2">
        <div class="row">

            <?php include('include/sidebar_admin.php'); ?>

            <div class="sb2-2">
                <div class="sb2-2-2">
                    <ul>
                        <li><a href="index.php"><i class="fa fa-home" aria-hidden="true"></i> Home</a>
                        </li>
                        <li class="active-bre"><a href="#"> Add New HVAC Product</a>
                        </li>
                        <!-- <li class="page-back"><a href="index.php"><i class="fa fa-backward" aria-hidden="true"></i> Back</a>
                        </li> -->
                    </ul>
                </div>
                <div class="sb2-2-add-product sb2-2-1">
                    <div class="box-inn-sp">
                        <div class="inn-title">
                            <h4>Add New HVAC Product</h4>
                            <!-- <p>Airtport Hotels The Right Way To Start A Short Break Holiday</p> -->
                        </div>
                        <div class="bor">
                            <form method="post" enctype="multipart/form-data">
                                <div class="row">
                                    <!-- <div class="input-field col s12">
                                        <input id="url" type="text" name="url" class="validate" value="<?php echo $url ?>" required>
                                        <label for="url">Url</label>
                                    </div> -->
                                    <div class="input-field col s12">
                                        <input id="name" type="text" name="name" class="validate" value="<?php echo $name ?>" required>
                                        <label for="name">Product Name</label>
                                    </div>
                                    <div class="input-field col s12">
                                        <div class="file-field">
                                            <div class="btn">
                                                <span>File</span>
                                                <input type="file" name="image" value="<?php echo $image ?>">
                                            </div>
                                            <div class="file-path-wrapper">
                                                <input class="file-path validate" type="text" name="image" placeholder="Upload Product Image" value="<?php echo $image ?>">
                                            </div>
                                        </div>
                                        <?php
                                        if ($image != '') {
                                            echo "<a target='_blank' href='" . "../media/hvac_product/" . $image . "'><img width='150px' src='" . "../media/hvac_product/" . $image . "'/></a>";
                                        }
                                        ?>
                                    </div>
                                    <div class="input-field col s12">
                                        <input id="image_alt_tag" type="text" name="image_alt_tag" class="validate" value="<?php echo $image_alt_tag ?>" required>
                                        <label for="image_alt_tag">Image Alt Text</label>
                                    </div>

                                   
                                </div>
                                <div class="row">
                                    <div class="input-field col s12">
                                        <textarea id="editor" name="description"><?php echo $description ?></textarea>
                                        <!-- <label>product Descriptions:</label> -->
                                    </div>
                                </div>
                                <div class="row">
                                   

                                    <!-- <div class="input-field col s12">
                                        <select multiple>
                                            <option value="" disabled selected>Choose Category</option>
                                            <option value="1">Hotels</option>
                                            <option value="2">Educations</option>
                                            <option value="3">Medical</option>
                                            <option value="3">Health</option>
                                            <option value="3">Fitness</option>
                                            <option value="3">Tution</option>
                                            <option value="3">Software</option>
                                            <option value="3">Wedding</option>
                                            <option value="3">Party</option>
                                            <option value="3">Spa/Club</option>
                                        </select>
                                        <label>Select Sub Category</label>
                                    </div> -->
                                </div>
                                <div class="row">
                                    <div class="input-field col s12">
                                        <input type="submit" name="submit_hvac_product" class="waves-effect waves-light btn-large" value="Submit">
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <?php include('include/footer_admin.php'); ?>

    <?php include('include/foot_admin.php'); ?>
    <script>
        // Add JavaScript to show/hide the second dropdown based on the selected category
        document.getElementById('categorySelect').addEventListener('change', function() {
            var category = this.value;
            var subcategoryDiv = document.getElementById('subcategoryDiv');
            var subcategoryLabel = document.getElementById('subcategory_label');

            if (category === "Ring") {
                subcategoryDiv.style.display = 'block';
                subcategoryLabel.style.display = 'block';
            } else {
                subcategoryDiv.style.display = 'none';
                subcategoryLabel.style.display = 'none';
            }
        });
    </script>

</body>

</html>