View file Remove image backgrounds/remove-bg/dark/admin-pannel/files.php

File size: 14.06Kb
<?php
// Start session
session_start();

// Redirect to login page if not logged in
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
    header("Location: login.php");
    exit;
}

// Include coredb.php for database connection
require_once('config/core.php');

// Create database connection
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Function to get the site settings
function getSiteSettings($conn) {
    $sql = "SELECT favicon, company_copyright FROM site_settings LIMIT 1";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        return $result->fetch_assoc();
    } else {
        return [
            'favicon' => 'default_favicon_url.ico', // Default favicon URL if not found in the database
            'company_copyright' => ''
        ];
    }
}

try {
    $siteSettings = getSiteSettings($conn);
    $favicon = $siteSettings['favicon'];
    $companyCopyright = $siteSettings['company_copyright'];

    // Retrieve the saved scripts from the database
    $sql = "SELECT script, script_1, script_2, script_3 FROM google_adsense ORDER BY id DESC LIMIT 1";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        $row = $result->fetch_assoc();
        $scriptVariable = $row['script'];
        $script_1 = $row['script_1'];
        $script_2 = $row['script_2'];
        $script_3 = $row['script_3'];
    } else {
        $scriptVariable = '';
        $script_1 = '';
        $script_2 = '';
        $script_3 = '';
    }

} catch (Exception $e) {
    // Handle database connection error
    echo "Connection failed: " . $e->getMessage();
}

$uploadSuccess = "";
$uploadError = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $uploadDir = "../"; // Upload directory, outside the admin-panel folder

    // Handle sitemap.xml upload
    if (isset($_FILES["sitemap"]) && $_FILES["sitemap"]["error"] == 0) {
        $sitemapFileType = pathinfo($_FILES["sitemap"]["name"], PATHINFO_EXTENSION);
        if ($sitemapFileType == "xml") {
            $sitemapPath = $uploadDir . "sitemap.xml";
            if (move_uploaded_file($_FILES["sitemap"]["tmp_name"], $sitemapPath)) {
                $uploadSuccess .= "sitemap.xml has been uploaded successfully. ";
                // Update the database
                $stmt = $conn->prepare("UPDATE files SET sitemap = ? WHERE id = 1");
                $stmt->bind_param("s", $sitemapPath);
                $stmt->execute();
                $stmt->close();
            } else {
                $uploadError .= "Failed to upload sitemap.xml. ";
            }
        } else {
            $uploadError .= "Only .xml files are allowed for sitemap.xml. ";
        }
    }

    // Handle robots.txt upload
    if (isset($_FILES["robots"]) && $_FILES["robots"]["error"] == 0) {
        $robotsFileType = pathinfo($_FILES["robots"]["name"], PATHINFO_EXTENSION);
        if ($robotsFileType == "txt") {
            $robotsPath = $uploadDir . "robots.txt";
            if (move_uploaded_file($_FILES["robots"]["tmp_name"], $robotsPath)) {
                $uploadSuccess .= "robots.txt has been uploaded successfully. ";
                // Update the database
                $stmt = $conn->prepare("UPDATE files SET robot = ? WHERE id = 1");
                $stmt->bind_param("s", $robotsPath);
                $stmt->execute();
                $stmt->close();
            } else {
                $uploadError .= "Failed to upload robots.txt. ";
            }
        } else {
            $uploadError .= "Only .txt files are allowed for robots.txt. ";
        }
    }
}

// Set the webpage name
$webpage_name = "files"; // Replace "your_webpage_name" with the actual webpage name

// metatitle, metadescription, metakeyword Begin
// Prepare and bind the SQL query
$sql = "SELECT title, meta_description, meta_keyword FROM webpages WHERE webpage_name = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $webpage_name);
// Execute the query
$stmt->execute();
// Bind the result variables
$stmt->bind_result($title, $meta_description, $meta_keyword);
// Fetch the values
$stmt->fetch();
// Close statement
$stmt->close();
// metatitle, metadescription, metakeyword End

// fetch google_adsense data Begin
$sql = "SELECT script FROM google_adsense ORDER BY id DESC LIMIT 1";
$result = $conn->query($sql);

// Initialize variable to store the script
$scriptVariable = '';

// Check if the query was successful
if ($result && $result->num_rows > 0) {
    // Fetch the script
    $row = $result->fetch_assoc();
    $scriptVariable = $row['script'];
}
// fetch google_adsense data end

// fetch data google_analytics Begin
// Initialize the variable
$analytics_script = '';

// SQL query to select the analytics_script from google_analytics table
$sql = "SELECT analytics_script FROM google_analytics";

// Execute the query
$result = $conn->query($sql);

// Check if the query was successful and if there is at least one row returned
if ($result && $result->num_rows > 0) {
    // Fetch the data
    $row = $result->fetch_assoc();
    // Assign the analytics_script to the variable
    $analytics_script = $row['analytics_script'];
} else {
    $analytics_script = 'No analytics script found.';
}
// fetch data google_analytics End

// Close the database connection
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?php echo htmlspecialchars($title); ?></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link id="image_2" rel="icon" type="image/x-icon" href="<?php echo htmlspecialchars($favicon); ?>">
    <meta name="robots" content="index, follow" />
    <meta name="author" content="Design Collection">
    <meta name="description" content="<?php echo htmlspecialchars($meta_description); ?>">
    <meta name="keywords" content="<?php echo htmlspecialchars($meta_keyword); ?>">
    <!-- Viewport configuration, scaling options -->
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!-- Bootstrap CSS -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <!-- custom CSS -->
    <link href="assets/css/custom.css" rel="stylesheet">
    <!-- Font Awesome icon -->
    <link href="assets/fontawesome/css/fontawesome.css" rel="stylesheet" />
    <!-- Google web font  -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
     <link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <!--analytics_script Begin-->
    <?php echo $analytics_script ?>
    <!--analytics_script End-->
</head>
<body>
    <!--unique id begin -->
    <div id="s_mm">
        <?php include 'preloader.php';?>
        <!--scroll-top Begin-->
        <div id="scroll-top">
            <!--sidebarwrapper Begin-->
            <div id="sidebarwrapper">
                <!--Sidebarmenu Begin-->
                <?php include 'sidebar-menu.php';?>
                <!--Sidebarmenu End-->
                <!--content-wrapper Begin-->
                <div id="content-wrapper" class="d-flex flex-column dashboard-navbar">
                    <div id="maincontent">
                        <!-- Navbar Topbar Begin-->
                        <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">
                            <button id="humbergersidebarToggleTop" class="btn btn-link rounded-circle mr-3">
                                <i class="fa fa-bars"></i>
                            </button>
                        </nav>
                        <!-- Navbar Topbar End-->
                        <!-- Container Begin-->
                        <div class="container-fluid px-4">
                            <div class="d-sm-flex align-items-center justify-content-between mb-4">
                                <h3>
                                   sitemap.xml and robot.txt files
                                </h3>
                            </div>
                            <!--Row Begin-->
                            <div class="row">
                                <!--sitemap.xml and robot.txt files Begin-->
                                <div class="col-md-12">
                                    <div class="card border-0  shadow mb-4">
                                        <div class="card-header bg-white border-bottom py-3 border-top-left-right">
                                            <h6 class="m-0 fw-bold"> Edit sitemap.xml and robot.txt files</h6>
                                        </div>
                                        <!--card Body Begin-->
                                        <div class="card-body">
                                            <!--Form Begin-->
                                            <form method="post" enctype="multipart/form-data">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="sitemap" class="form-label">sitemap.xml file</label>
                                        <input type="file" class="form-control" name="sitemap" id="sitemap" accept=".xml">
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="robots" class="form-label">robots.txt file</label>
                                        <input type="file" class="form-control" name="robots" id="robots" accept=".txt">
                                    </div>
                                </div>
                                <div class="col-md-12">
                                    <button type="submit" class="btn btn-primary">Save</button>
                                </div>
                                
                            </div>
                        </form>
                        <?php if (!empty($uploadSuccess)): ?>
                            <div id="success-message" class="alert alert-success alert-dismissible">
                            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>    
                            <?php echo $uploadSuccess; ?></div>
                        <?php endif; ?>
                        <?php if (!empty($uploadError)): ?>
                            <div id="error-message" class="alert alert-danger alert-dismissible">
                            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>    
                            <?php echo $uploadError; ?></div>
                        <?php endif; ?>
                                            <!--Form End-->
                                        </div>
                                        <!--card Body End-->
                                    </div>
                                </div>
                                <!---sitemap.xml and robot.txt files End-->
                                <!--Adsense Begin-->
                                <div class='col-md-12'>
                                    <?php echo $script_3; ?>
                                </div>
                                <!--Adsense End-->
                                <!--col-md-12 End-->
                            </div>
                            <!--Row End-->
                        </div>
                        <!-- Container End-->
                    </div>
                    <!--Copyright Begin-->
                    <div class="p-4 border bg-white">
                        <div class="container">
                            <div class="row align-items-center">
                                <div class="col-lg-12 col-sm-12">
                                    <p class="small text-center p-0 m-0"><?php echo htmlspecialchars($companyCopyright); ?></p>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--Copyright End-->
                </div>
                <!--content-wrapper End-->
            </div>
            <!--sidebarwrapper End-->
            <!--scroll to top Begin-->
            <button onclick="topFunction()" id="gobackToTop" title="arrow-right"><i class="fas fa-angle-up"></i></button>
            <!--scroll to top end-->
            <!-- Jquery Script -->
            <script src="assets/js/jquery-3.4.1.min.js"></script>
            <!-- Bootstrap Script -->
            <script src="assets/js/bootstrap.bundle.min.js"></script>
            <!-- theme-min Script -->
            <script src="assets/js/dashboard-custom.js"></script>
            <script>
        // Function to hide messages after 5 seconds
        setTimeout(function() {
            var successMessage = document.getElementById('success-message');
            var errorMessage = document.getElementById('error-message');
            if (successMessage) {
                successMessage.style.opacity = '0';
                successMessage.style.display = 'none';
            }
            if (errorMessage) {
                errorMessage.style.opacity = '0';
                errorMessage.style.display = 'none';
            }
        }, 5000);
    </script>
        </div>
        <!--scroll-top End-->
    </div>
    <!--unique id End -->
</body>
</html>