<?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();
}
// Set the webpage name
$webpage_name = "google_adsense"; // 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>
Google Adsense Code
</h3>
</div>
<!--Row Begin-->
<div class="row">
<!--Google Adsense 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 Adsense Code</h6>
</div>
<!--card Body Begin-->
<div class="card-body">
<!--Form Begin-->
<form method="post" action="google_adsense_save.php" id="saveScriptForm">
<!--row Begin-->
<div class="row">
<!--Google Adsense Code 1 Begin-->
<div class="col-md-6">
<div class="mb-3">
<label for="meta_title" class="form-label">Google Adsense Code 1</label>
<textarea name="adsense_script" placeholder="Enter your Google AdSense code.." class="form-control" rows="5"><?php echo htmlspecialchars($scriptVariable); ?></textarea>
</div>
</div>
<!--Google Adsense Code 1 End-->
<!--Google Adsense Code 2 Begin-->
<div class="col-md-6">
<div class="mb-3">
<label for="meta_title" class="form-label">Google Adsense Code 2</label>
<textarea name="adsense_script_1" placeholder="Enter your Google AdSense code.." class="form-control" rows="5"><?php echo htmlspecialchars($script_1); ?></textarea>
</div>
</div>
<!--Google Adsense Code 2 End-->
<!--Google Adsense Code 3 Begin-->
<div class="col-md-6">
<div class="mb-3">
<label for="meta_title" class="form-label">Google Adsense Code 3</label>
<textarea name="adsense_script_2" placeholder="Enter your Google AdSense code.." class="form-control" rows="5"><?php echo htmlspecialchars($script_2); ?></textarea>
</div>
</div>
<!--Google Adsense Code 3 End-->
<!--Google Adsense Code 4 Begin-->
<div class="col-md-6">
<div class="mb-3">
<label for="meta_title" class="form-label">Google Adsense Code 4</label>
<textarea name="adsense_script_3" placeholder="Enter your Google AdSense code.." class="form-control" rows="5"><?php echo htmlspecialchars($script_3); ?></textarea>
</div>
</div>
<!--Google Adsense Code 4 End-->
<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 Adsense Code 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>
// Wait for the DOM to be fully loaded
document.addEventListener("DOMContentLoaded", function() {
// Select the form element
var saveScriptForm = document.getElementById('saveScriptForm');
// If the form element exists
if (saveScriptForm) {
// Add submit event listener
saveScriptForm.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
if (formSubmittedSuccessfully) {
// Display success alert message
alert("Script saved successfully!");
} else {
// Display error alert message
alert("Failed to save script. Please try again later.");
}
});
}
});
</script>
</div>
<!--scroll-top End-->
</div>
<!--unique id End -->
</body>
</html>