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

File size: 10.88Kb
<?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 favicon URL and company copyright
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 analytics script from the database
    $sql = "SELECT analytics_script FROM google_analytics ORDER BY id DESC LIMIT 1";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        $row = $result->fetch_assoc();
        $analyticsscripts = $row['analytics_script'];
    } else {
        $analyticsscripts = '';
    }
} catch (Exception $e) {
    // Handle database connection error
    echo "Connection failed: " . $e->getMessage();
}

// 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);
// Set the webpage name
$webpage_name = "google_analytics"; // Replace "your_webpage_name" with the actual 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

// 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 $analyticsscripts ?>
    <!--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>
                                    Google Analytics Code
                                </h3>
                            </div>
                            <!--Row Begin-->
                            <div class="row">
                                <!--Google Analytics Code 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"> Google Analytics Code</h6>
                                        </div>
                                        <!--card Body Begin-->
                                        <div class="card-body">
                                            <!--Form Begin-->
                                            <form method="post" action="google_analytics_save.php" id="saveAnalyticsScriptForm">
                                                <!--row Begin-->
                                                <div class="row">
                                                    <div class="col-md-12">
                                                        <div class="mb-3">
                                                            <label for="meta_title" class="form-label">Google Analytics Code</label>
                                                            <textarea name="analytics_script" placeholder="Enter your Google Analytics code.." class="form-control" rows="5"><?php echo htmlspecialchars($analyticsscripts); ?></textarea>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-12">
                                                        <button type="submit" class="btn btn-primary" name="save">Save Script</button>
                                                    </div>
                                                      
                                                </div>
                                                <!--row End-->
                                            </form>
                                            <!--Form End-->
                                        </div>
                                        <!--card Body End-->
                                    </div>
                                </div>
                                <!---Google Analytics Code 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>
                // Wait for the DOM to be fully loaded
                document.addEventListener("DOMContentLoaded", function() {
                    // Select the form element
                    var saveAnalyticsScriptForm = document.getElementById('saveAnalyticsScriptForm');
                    // If the form element exists
                    if (saveAnalyticsScriptForm) {
                        // Add submit event listener
                        saveAnalyticsScriptForm.addEventListener('submit', function(event) {
                            // Check if the form submission was successful
                            var formSubmittedSuccessfully = true; // Change this to true or false based on your logic
                            
                            // Display different alert messages based on the form submission result
                            var alertMessage = "";
                            if (formSubmittedSuccessfully) {
                                // Success message
                                alertMessage = "Google Analytics script saved successfully!";
                            } else {
                                // Error message
                                alertMessage = "Failed to save Google Analytics script. Please try again later.";
                            }
                            
                            // Display the alert message
                            alert(alertMessage);
                        });
                    }
                });
            </script>
        </div>
        <!--scroll-top End-->
    </div>
    <!--unique id End -->
</body>
</html>