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

File size: 12.5Kb
<?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);
   }
   
   // Fetch favicon and company_copyright from site_settings table Begin
   $sql = "SELECT favicon, company_copyright FROM site_settings LIMIT 1";
   $result = $conn->query($sql);
   
   // Check if data exists
   if ($result && $result->num_rows > 0) {
       $row = $result->fetch_assoc();
       $favicon_url = $row['favicon'];
       $company_copyright = $row['company_copyright'];
   } else {
       // Default values if not found in the database
       $favicon_url = "default_favicon_url.ico";
       $company_copyright = "";
   }
   // Fetch favicon and company_copyright from site_settings table End
   
   // Handle form submission
   if ($_SERVER["REQUEST_METHOD"] === "POST") {
       foreach ($_POST as $key => $value) {
           // Check if the key represents a social media icon or URL
           if (strpos($key, 'social_') === 0) {
               // Extract the index of the social media
               $index = substr($key, strlen('social_'));
               // Get the corresponding URL key
               $url_key = 'social_url_' . $index;
   
               // Prepare and execute the update query
               $stmt = $conn->prepare("UPDATE social_media SET icon = ?, url = ? WHERE id = ?");
               $stmt->bind_param("ssi", $value, $_POST[$url_key], $index);
               $stmt->execute();
           }
       }
       // Set a session variable to indicate successful form submission
       $_SESSION['form_submitted'] = true;
       // Redirect to the same page to show the alert message
       header("Location: " . $_SERVER['PHP_SELF']);
       exit;
   }
   
   // Retrieve social media data
   $socials = [];
   $result = $conn->query("SELECT * FROM social_media");
   if ($result->num_rows > 0) {
       while ($row = $result->fetch_assoc()) {
           $socials[] = $row;
       }
   }
   
   // 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 = "social-media"; // 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
   
   // fetch google_adsense data Begin
   // Fetch data from google_adsense table
   $sql = "SELECT script_2 FROM google_adsense ORDER BY id DESC LIMIT 1";
   $result = $conn->query($sql);
   
   // Initialize variable to store the script
   $script_2 = '';
   
   // Check if the query was successful
   if ($result && $result->num_rows > 0) {
       // Fetch the script
       $row = $result->fetch_assoc();
       $script_2 = $row['script_2'];
   }
   // 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 $title; ?></title>
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <link id="image_2" rel="icon" type="image/x-icon" href="<?php echo $favicon_url; ?>">
      <meta name="robots" content="index, follow" />
      <meta name="author" content="Design Collection">
      <meta name="description" content="<?php echo $meta_description; ?>">
      <meta name="keywords" content="<?php echo $meta_keyword; ?>">
      <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
      <link href="assets/css/bootstrap.min.css" rel="stylesheet">
      <link href="assets/css/custom.css" rel="stylesheet">
      <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">
      <!--[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>
      <div id="s_mm">
         <?php include 'preloader.php'; ?>
         <div id="scroll-top">
            <div id="sidebarwrapper">
               <?php include 'sidebar-menu.php'; ?>
               <div id="content-wrapper" class="d-flex flex-column dashboard-navbar">
                  <div id="maincontent">
                     <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>
                     <div class="container-fluid px-4">
                        <div class="d-sm-flex align-items-center justify-content-between mb-4">
                           <h3>Social Media</h3>
                        </div>
                        <div class="row">
                           <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 Social Media</h6>
                                 </div>
                                 <div class="card-body">
                                    <form method="post">
                                       <div class="row">
                                          <?php foreach ($socials as $i => $social): ?>
                                          <div class="col-md-6 mb-3">
                                             <select class="form-select form-control-sm" name="social_<?php echo $i + 1 ?>" required>
                                                <option value="" selected disabled>Select social media</option>
                                                <option value="fab fa-facebook-f" <?php echo $social['icon'] === 'fab fa-facebook-f' ? 'selected' : '' ?>>Facebook</option>
                                                <option value="fab fa-instagram" <?php echo $social['icon'] === 'fab fa-instagram' ? 'selected' : '' ?>>Instagram</option>
                                                <option value="fab fa-twitter" <?php echo $social['icon'] === 'fab fa-twitter' ? 'selected' : '' ?>>Twitter</option>
                                                <option value="fab fa-youtube" <?php echo $social['icon'] === 'fab fa-youtube' ? 'selected' : '' ?>>YouTube</option>
                                                <option value="fab fa-whatsapp" <?php echo $social['icon'] === 'fab fa-whatsapp' ? 'selected' : '' ?>>Whatsapp</option>
                                                <option value="fab fa-linkedin-in" <?php echo $social['icon'] === 'fab fa-linkedin-in' ? 'selected' : '' ?>>Linkedin</option>
                                                <option value="fab fa-google-plus-g" <?php echo $social['icon'] === 'fab fa-google-plus-g' ? 'selected' : '' ?>>Google Plus</option>
                                                <option value="fab fa-pinterest" <?php echo $social['icon'] === 'fab fa-pinterest' ? 'selected' : '' ?>>Pinterest</option>
                                                <!-- add more options here -->
                                             </select>
                                          </div>
                                          <div class="col-md-6 mb-3">
                                             <input class="form-control" type="text" name="social_url_<?php echo $i + 1 ?>" value="<?php echo $social['url'] ?>" placeholder="Enter URL" required>
                                          </div>
                                          <?php endforeach; ?>
                                          <div class="col-md-12 mb-3">
                                             <button type="submit" class="btn btn-primary mt-2">Save</button>
                                          </div>
                                          <!--Alert Message Begin-->
                                          <div class="col-md-12">
                                             <div id="alert" class="alert alert-success alert-dismissible fade show" style="display:none;" role="alert">
                                                Your data has been saved successfully!
                                                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                                             </div>
                                          </div>
                                          <!--Alert Message End-->
                                         
                                       </div>
                                    </form>
                                 </div>
                              </div>
                           </div>
                           <div class="col-md-12">
                              <?php echo $script_2; ?>
                           </div>
                        </div>
                     </div>
                  </div>
                  <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 $company_copyright; ?></p>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
            <button onclick="topFunction()" id="gobackToTop" title="arrow-right"><i class="fas fa-angle-up"></i></button>
            <script src="assets/js/jquery-3.4.1.min.js"></script>
            <script src="assets/js/bootstrap.bundle.min.js"></script>
            <script src="assets/js/dashboard-custom.js"></script>
            <script>
               // Function to show the alert message
               function showAlert() {
                   document.getElementById("alert").style.display = "block";
                   setTimeout(function(){ document.getElementById("alert").style.display = "none"; }, 3000); // Hide after 3 seconds
               }
               
               // Check if form was submitted successfully
               <?php if(isset($_SESSION['form_submitted']) && $_SESSION['form_submitted']): ?>
                   window.onload = showAlert;
                   <?php unset($_SESSION['form_submitted']); ?> // Unset session variable
               <?php endif; ?>
            </script>
         </div>
      </div>
   </body>
</html>