File "site-settings.php"

Full path: /home/u525140468/domains/productsizer.com/public_html/admin/site-settings.php
File size: 11.85 B (11.85 KB bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php
// Load current values if exist
$settingsFile = __DIR__ . '/data/data.site-settings.php';
$name = $title = $description = $site_url = $email = $phone = $address = $facebook = $linkedin = $twitter = $youtube = '';
$ads = false;
$imagelogo = false;

if (file_exists($settingsFile)) {
    include $settingsFile;
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $fields = ['name', 'title', 'description', 'site_url', 'email', 'phone', 'address', 'facebook', 'linkedin', 'twitter', 'youtube', 'logotext', 'logoicon'];
    $settingsData = "<?php\n";

    foreach ($fields as $field) {
        $value = trim($_POST[$field] ?? '');
        $settingsData .= "\$$field = " . var_export($value, true) . ";\n";
    }

    // Handle boolean switches
    $ads = isset($_POST['ads']);
    $settingsData .= "\$ads = " . ($ads ? 'true' : 'false') . ";\n";
    $imagelogo = isset($_POST['imagelogo']);
    $settingsData .= "\$imagelogo = " . ($imagelogo ? 'true' : 'false') . ";\n";

    file_put_contents($settingsFile, $settingsData);

    // Logo and favicon upload
    $uploadDir = __DIR__ . '/../assets/';
    if (!is_dir($uploadDir)) mkdir($uploadDir, 0777, true);

    foreach (['logo', 'favicon'] as $fileKey) {
        if (!empty($_FILES[$fileKey]['tmp_name'])) {
            $newFile = $uploadDir . $fileKey . '.png';
            if (file_exists($newFile)) unlink($newFile);
            move_uploaded_file($_FILES[$fileKey]['tmp_name'], $newFile);
        }
    }

    header("Location: site-settings.php?success=1");
    exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Site Settings</title>
  <?php include "data/styles.php"?>
  <style>
    .fade-in {
      animation: fadeIn 0.3s ease-in;
    }
    @keyframes fadeIn {
      from { opacity: 0; transform: translateY(10px); }
      to { opacity: 1; transform: translateY(0); }
    }
    .hover-scale {
      transition: transform 0.2s ease;
    }
    .hover-scale:hover {
      transform: scale(1.02);
    }
    .input-focus {
      transition: all 0.2s ease;
    }
    .input-focus:focus {
      border-color: #3b82f6;
      box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }
  </style>
</head>
<body class="bg-gray-100 min-h-screen p-6 text-gray-800">
  <div class="max-w-3xl mx-auto bg-white shadow-lg p-6 rounded-2xl animate-fade animate-once animate-ease-in">
    <h1 class="text-2xl font-semibold text-gray-700 mb-6 flex items-center gap-3">
      <i data-lucide="settings" class="w-7 h-7 text-blue-600"></i> Site Settings
    </h1>

    <?php if (isset($_GET['success'])): ?>
      <div class="bg-green-50 text-green-800 p-4 rounded-xl mb-6 border border-green-200 flex items-center gap-2">
        <i data-lucide="check-circle" class="w-5 h-5 text-green-600"></i> Settings saved successfully.
      </div>
    <?php endif; ?>

    <form action="" method="post" enctype="multipart/form-data" class="space-y-6">
      <!-- Ads Switch -->
      <div class="flex items-center justify-between bg-gray-50 p-4 rounded-xl border border-gray-200">
        <label class="font-medium text-gray-700 flex items-center gap-2">
          <i data-lucide="badge-dollar-sign" class="w-5 h-5 text-yellow-500"></i> Enable Ads
        </label>
        <label class="relative inline-flex items-center cursor-pointer">
          <input type="checkbox" name="ads" class="sr-only peer" <?= $ads ? 'checked' : '' ?>>
          <div class="w-12 h-7 bg-gray-200 rounded-full peer peer-checked:bg-blue-600 peer-focus:ring-4 peer-focus:ring-blue-100 transition-all"></div>
          <div class="absolute left-1 top-1 bg-white w-5 h-5 rounded-full peer-checked:translate-x-5 transition-transform"></div>
        </label>
      </div>

      <!-- Site Name -->
      <div>
        <label class="block text-sm mb-2 font-medium text-gray-400">Site Name</label>
        <input type="text" name="name" value="<?= htmlspecialchars($name) ?>" class="w-full border border-gray-200 p-3 rounded-xl bg-gray-50 text-gray-900 input-focus">
      </div>

      <!-- Site Title -->
      <div>
        <label class="block text-sm mb-2 font-medium text-gray-400">Site Title</label>
        <input type="text" name="title" value="<?= htmlspecialchars($title) ?>" class="w-full border border-gray-200 p-3 rounded-xl bg-gray-50 text-gray-900 input-focus">
      </div>

      <!-- Description -->
      <div>
        <label class="block text-sm mb-2 font-medium text-gray-400">Description</label>
        <textarea name="description" rows="4" class="w-full border border-gray-200 p-3 rounded-xl bg-gray-50 text-gray-900 input-focus"><?= htmlspecialchars($description) ?></textarea>
      </div>

      <!-- Site URL -->
      <div>
        <label class="block text-sm mb-2 font-medium text-gray-400">Site URL</label>
        <div class="relative">
          <i data-lucide="globe" class="w-5 h-5 text-gray-400 absolute left-3 top-1/2 transform -translate-y-1/2"></i>
          <input type="url" name="site_url" value="<?= htmlspecialchars($site_url) ?>" class="w-full border border-gray-200 p-3 pl-10 rounded-xl bg-gray-50 text-gray-900 input-focus">
        </div>
      </div>

      <!-- Email and Phone -->
      <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
        <div>
          <label class="block text-sm mb-2 font-medium text-gray-400">Email</label>
          <div class="relative">
            <i data-lucide="mail" class="w-5 h-5 text-gray-400 absolute left-3 top-1/2 transform -translate-y-1/2"></i>
            <input type="email" name="email" value="<?= htmlspecialchars($email) ?>" class="w-full border border-gray-200 p-3 pl-10 rounded-xl bg-gray-50 text-gray-900 input-focus">
          </div>
        </div>
        <div>
          <label class="block text-sm mb-2 font-medium text-gray-400">Phone Number</label>
          <div class="relative">
            <i data-lucide="phone" class="w-5 h-5 text-gray-400 absolute left-3 top-1/2 transform -translate-y-1/2"></i>
            <input type="tel" name="phone" value="<?= htmlspecialchars($phone) ?>" class="w-full border border-gray-200 p-3 pl-10 rounded-xl bg-gray-50 text-gray-900 input-focus">
          </div>
        </div>
      </div>

      <!-- Address -->
      <div>
        <label class="block text-sm mb-2 font-medium text-gray-400">Address</label>
        <div class="relative">
          <i data-lucide="map-pin" class="w-5 h-5 text-gray-400 absolute left-3 top-3"></i>
          <textarea name="address" rows="3" class="w-full border border-gray-200 p-3 pl-10 rounded-xl bg-gray-50 text-gray-900 input-focus"><?= htmlspecialchars($address) ?></textarea>
        </div>
      </div>

      <!-- Social Links -->
      <div>
        <label class="block text-sm mb-2 font-medium text-gray-400">Social Links</label>
        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
          <div>
            
            <div class="relative">
              <i data-lucide="facebook" class="w-5 h-5 text-gray-400 absolute left-3 top-1/2 transform -translate-y-1/2"></i>
              <input type="url" name="facebook" value="<?= htmlspecialchars($facebook) ?>" class="w-full border border-gray-200 p-3 pl-10 rounded-xl bg-gray-50 text-gray-900 input-focus">
            </div>
          </div>
          <div>

            <div class="relative">
              <i data-lucide="instagram" class="w-5 h-5 text-gray-400 absolute left-3 top-1/2 transform -translate-y-1/2"></i>
              <input type="url" name="linkedin" value="<?= htmlspecialchars($linkedin) ?>" class="w-full border border-gray-200 p-3 pl-10 rounded-xl bg-gray-50 text-gray-900 input-focus">
            </div>
          </div>
          <div>

            <div class="relative">
              <i data-lucide="twitter" class="w-5 h-5 text-gray-400 absolute left-3 top-1/2 transform -translate-y-1/2"></i>
              <input type="url" name="twitter" value="<?= htmlspecialchars($twitter) ?>" class="w-full border border-gray-200 p-3 pl-10 rounded-xl bg-gray-50 text-gray-900 input-focus">
            </div>
          </div>
          <div>

            <div class="relative">
              <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-lucide="brand-pinterest" class="lucide lucide-youtube w-5 h-5 text-gray-400 absolute left-3 top-1/2 transform -translate-y-1/2"><path d="M8 20l4 -9" /><path d="M10.7 14c.437 1.263 1.43 2 2.55 2c2.071 0 3.75 -1.554 3.75 -4a5 5 0 1 0 -9.7 1.7" /><path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" /></svg>
              <input type="url" name="youtube" value="<?= htmlspecialchars($youtube) ?>" class="w-full border border-gray-200 p-3 pl-10 rounded-xl bg-gray-50 text-gray-900 input-focus">
            </div>
          </div>
        </div>
      </div>
	  
	  <!-- Logo Text and Icon -->
		<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
		  <div>
			<label class="block text-sm mb-2 font-medium text-gray-400">Logo Text</label>
			<input type="text" name="logotext" value="<?= htmlspecialchars($logotext ?? '') ?>" class="w-full border border-gray-200 p-3 rounded-xl bg-gray-50 text-gray-900 input-focus">
		  </div>
		  <div>
			<label class="block text-sm mb-2 font-medium text-gray-400">Logo Icon </label>
			<input type="text" name="logoicon" value="<?= htmlspecialchars($logoicon ?? '') ?>" class="w-full border border-gray-200 p-3 rounded-xl bg-gray-50 text-gray-900 input-focus">
		  </div>
		</div>

      <!-- Use Image Logo Switch -->
      <div class="flex items-center justify-between bg-gray-50 p-4 rounded-xl border border-gray-200">
        <label class="font-medium text-gray-700 flex items-center gap-2">
          <i data-lucide="image" class="w-5 h-5 text-blue-500"></i> Use Image Logo
        </label>
        <label class="relative inline-flex items-center cursor-pointer">
          <input type="checkbox" name="imagelogo" class="sr-only peer" <?= $imagelogo ? 'checked' : '' ?>>
          <div class="w-12 h-7 bg-gray-200 rounded-full peer peer-checked:bg-blue-600 peer-focus:ring-4 peer-focus:ring-blue-100 transition-all"></div>
          <div class="absolute left-1 top-1 bg-white w-5 h-5 rounded-full peer-checked:translate-x-5 transition-transform"></div>
        </label>
      </div>

      <!-- Logo Upload -->
      <div>
        <label class="block text-sm mb-2 font-medium text-gray-400">Upload Logo</label>
        <div class="flex items-center gap-4">
          <input type="file" name="logo" accept="image/*" class="text-sm border border-gray-200 rounded-xl bg-gray-50 p-3 file:border-0 file:bg-blue-50 file:px-4 file:py-2 file:rounded-lg file:text-blue-600 file:cursor-pointer">
          <?php if (file_exists(__DIR__ . '/../assets/logo.png')): ?>
            <img src="../assets/logo.png" alt="Logo" class="h-12 rounded-lg border border-gray-200">
          <?php endif; ?>
        </div>
      </div>

      <!-- Favicon Upload -->
      <div>
        <label class="block text-sm mb-2 font-medium text-gray-400">Upload Favicon</label>
        <div class="flex items-center gap-4">
          <input type="file" name="favicon" accept="image/*" class="text-sm border border-gray-200 rounded-xl bg-gray-50 p-3 file:border-0 file:bg-blue-50 file:px-4 file:py-2 file:rounded-lg file:text-blue-600 file:cursor-pointer">
          <?php if (file_exists(__DIR__ . '/../assets/favicon.png')): ?>
            <img src="../assets/favicon.png" alt="Favicon" class="h-10 rounded-lg border border-gray-200">
          <?php endif; ?>
        </div>
      </div>

      <!-- Submit Button -->
      <div class="flex justify-end">
        <button type="submit" class="bg-blue-600 text-white px-6 py-3 rounded-xl hover:bg-blue-700 flex items-center gap-2 transition-colors">
          <i data-lucide="save" class="w-5 h-5"></i> Save Settings
        </button>
      </div>
    </form>
  </div>
</body>
</html>