247 lines
13 KiB
PHP
247 lines
13 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
$is_logged_in = isset($_SESSION['user_id']);
|
|
$content = [];
|
|
|
|
if ($is_logged_in) {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT content FROM user_content WHERE user_id = ?");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$user_content_row = $stmt->fetch();
|
|
|
|
if ($user_content_row) {
|
|
$content = json_decode($user_content_row['content'], true);
|
|
} else {
|
|
// New user, so create default content for them
|
|
$default_content_json = file_get_contents('db/content.json');
|
|
$content = json_decode($default_content_json, true);
|
|
|
|
$insert_stmt = $pdo->prepare("INSERT INTO user_content (user_id, content) VALUES (?, ?)");
|
|
$insert_stmt->execute([$_SESSION['user_id'], $default_content_json]);
|
|
}
|
|
} else {
|
|
// User is not logged in, show default content
|
|
$content = json_decode(file_get_contents('db/content.json'), true);
|
|
}
|
|
|
|
|
|
// Handle content updates
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $is_logged_in) {
|
|
$pdo = db();
|
|
|
|
// Fetch existing content to merge
|
|
$stmt = $pdo->prepare("SELECT content FROM user_content WHERE user_id = ?");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$current_content_json = $stmt->fetchColumn();
|
|
$current_content = json_decode($current_content_json, true);
|
|
|
|
// Update with new values from POST
|
|
$current_content['hero_title'] = $_POST['hero_title'] ?? $current_content['hero_title'];
|
|
$current_content['hero_subtitle'] = $_POST['hero_subtitle'] ?? $current_content['hero_subtitle'];
|
|
$current_content['features_title'] = $_POST['features_title'] ?? $current_content['features_title'];
|
|
$current_content['feature_1_title'] = $_POST['feature_1_title'] ?? $current_content['feature_1_title'];
|
|
$current_content['feature_1_text'] = $_POST['feature_1_text'] ?? $current_content['feature_1_text'];
|
|
$current_content['feature_2_title'] = $_POST['feature_2_title'] ?? $current_content['feature_2_title'];
|
|
$current_content['feature_2_text'] = $_POST['feature_2_text'] ?? $current_content['feature_2_text'];
|
|
$current_content['feature_3_title'] = $_POST['feature_3_title'] ?? $current_content['feature_3_title'];
|
|
$current_content['feature_3_text'] = $_POST['feature_3_text'] ?? $current_content['feature_3_text'];
|
|
$current_content['about_title'] = $_POST['about_title'] ?? $current_content['about_title'];
|
|
$current_content['about_text'] = $_POST['about_text'] ?? $current_content['about_text'];
|
|
|
|
$new_content_json = json_encode($current_content, JSON_PRETTY_PRINT);
|
|
|
|
// Update the database
|
|
$update_stmt = $pdo->prepare("UPDATE user_content SET content = ? WHERE user_id = ?");
|
|
$update_stmt->execute([$new_content_json, $_SESSION['user_id']]);
|
|
|
|
// Redirect to avoid form resubmission
|
|
header("Location: " . $_SERVER['PHP_SELF']);
|
|
exit;
|
|
}
|
|
|
|
// Default values
|
|
$hero_title = htmlspecialchars($content['hero_title'] ?? 'Build Your Dream Website');
|
|
$hero_subtitle = htmlspecialchars($content['hero_subtitle'] ?? 'Visually design, customize, and publish beautiful, responsive websites. No code required.');
|
|
$features_title = htmlspecialchars($content['features_title'] ?? 'Features');
|
|
$feature_1_title = htmlspecialchars($content['feature_1_title'] ?? 'Visual Editor');
|
|
$feature_1_text = htmlspecialchars($content['feature_1_text'] ?? 'Design and customize your site with a powerful, intuitive drag-and-drop editor.');
|
|
$feature_2_title = htmlspecialchars($content['feature_2_title'] ?? 'Responsive Templates');
|
|
$feature_2_text = htmlspecialchars($content['feature_2_text'] ?? 'Start with professionally designed, mobile-friendly templates that look great on any device.');
|
|
$feature_3_title = htmlspecialchars($content['feature_3_title'] ?? 'One-Click Publishing');
|
|
$feature_3_text = htmlspecialchars($content['feature_3_text'] ?? 'Go live instantly. We handle the hosting, security, and scaling for you.');
|
|
$about_title = htmlspecialchars($content['about_title'] ?? 'About Us');
|
|
$about_text = htmlspecialchars($content['about_text'] ?? 'We believe creating a website should be simple and accessible to everyone. Our mission is to empower creators with tools that are both powerful and easy to use.');
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>webCreatorSaas</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body class="bg-light">
|
|
|
|
<?php include 'partials/navigation.php'; ?>
|
|
|
|
<main>
|
|
<!-- Hero Section -->
|
|
<header class="hero-section text-white text-center py-5">
|
|
<div class="container">
|
|
<h1 class="display-4 fw-bold"><?php echo $hero_title; ?></h1>
|
|
<p class="lead"><?php echo $hero_subtitle; ?></p>
|
|
<a href="#editor" class="btn btn-lg btn-light text-primary fw-bold">Get Started</a>
|
|
</div>
|
|
</header>
|
|
|
|
<!-- Features Section -->
|
|
<section id="features" class="py-5">
|
|
<div class="container">
|
|
<div class="text-center mb-5">
|
|
<h2 class="fw-bold"><?php echo $features_title; ?></h2>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-4 mb-4">
|
|
<div class="card h-100 text-center p-4">
|
|
<div class="mb-3">
|
|
<i class="bi bi-palette-fill fs-1 text-primary"></i>
|
|
</div>
|
|
<h5 class="card-title fw-bold"><?php echo $feature_1_title; ?></h5>
|
|
<p class="card-text"><?php echo $feature_1_text; ?></p>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4 mb-4">
|
|
<div class="card h-100 text-center p-4">
|
|
<div class="mb-3">
|
|
<i class="bi bi-phone-fill fs-1 text-primary"></i>
|
|
</div>
|
|
<h5 class="card-title fw-bold"><?php echo $feature_2_title; ?></h5>
|
|
<p class="card-text"><?php echo $feature_2_text; ?></p>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4 mb-4">
|
|
<div class="card h-100 text-center p-4">
|
|
<div class="mb-3">
|
|
<i class="bi bi-cloud-arrow-up-fill fs-1 text-primary"></i>
|
|
</div>
|
|
<h5 class="card-title fw-bold"><?php echo $feature_3_title; ?></h5>
|
|
<p class="card-text"><?php echo $feature_3_text; ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- About Section -->
|
|
<section id="about" class="py-5 bg-white">
|
|
<div class="container">
|
|
<div class="row align-items-center">
|
|
<div class="col-md-6">
|
|
<h2 class="fw-bold"><?php echo $about_title; ?></h2>
|
|
<p><?php echo $about_text; ?></p>
|
|
</div>
|
|
<div class="col-md-6 text-center">
|
|
<i class="bi bi-gem fs-1 text-primary"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- Editor Section -->
|
|
<section id="editor" class="py-5">
|
|
<div class="container">
|
|
<?php if ($is_logged_in): ?>
|
|
<div class="card shadow-sm">
|
|
<div class="card-header bg-primary text-white">
|
|
<h3 class="mb-0 fw-bold"><i class="bi bi-pencil-square"></i> Live Editor</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<form method="POST" action="index.php">
|
|
<fieldset class="mb-4">
|
|
<legend class="fs-5 fw-bold border-bottom pb-2 mb-3">Hero Section</legend>
|
|
<div class="mb-3">
|
|
<label for="hero_title" class="form-label">Title</label>
|
|
<input type="text" class="form-control" id="hero_title" name="hero_title" value="<?php echo $hero_title; ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="hero_subtitle" class="form-label">Subtitle</label>
|
|
<input type="text" class="form-control" id="hero_subtitle" name="hero_subtitle" value="<?php echo $hero_subtitle; ?>">
|
|
</div>
|
|
</fieldset>
|
|
|
|
<fieldset class="mb-4">
|
|
<legend class="fs-5 fw-bold border-bottom pb-2 mb-3">Features Section</legend>
|
|
<div class="mb-3">
|
|
<label for="features_title" class="form-label">Section Title</label>
|
|
<input type="text" class="form-control" id="features_title" name="features_title" value="<?php echo $features_title; ?>">
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<div class="mb-3">
|
|
<label for="feature_1_title" class="form-label">Feature 1 Title</label>
|
|
<input type="text" class="form-control" id="feature_1_title" name="feature_1_title" value="<?php echo $feature_1_title; ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="feature_1_text" class="form-label">Feature 1 Text</label>
|
|
<textarea class="form-control" id="feature_1_text" name="feature_1_text" rows="3"><?php echo $feature_1_text; ?></textarea>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="mb-3">
|
|
<label for="feature_2_title" class="form-label">Feature 2 Title</label>
|
|
<input type="text" class="form-control" id="feature_2_title" name="feature_2_title" value="<?php echo $feature_2_title; ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="feature_2_text" class="form-label">Feature 2 Text</label>
|
|
<textarea class="form-control" id="feature_2_text" name="feature_2_text" rows="3"><?php echo $feature_2_text; ?></textarea>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="mb-3">
|
|
<label for="feature_3_title" class="form-label">Feature 3 Title</label>
|
|
<input type="text" class="form-control" id="feature_3_title" name="feature_3_title" value="<?php echo $feature_3_title; ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="feature_3_text" class="form-label">Feature 3 Text</label>
|
|
<textarea class="form-control" id="feature_3_text" name="feature_3_text" rows="3"><?php echo $feature_3_text; ?></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</fieldset>
|
|
|
|
<fieldset class="mb-4">
|
|
<legend class="fs-5 fw-bold border-bottom pb-2 mb-3">About Section</legend>
|
|
<div class="mb-3">
|
|
<label for="about_title" class="form-label">Title</label>
|
|
<input type="text" class="form-control" id="about_title" name="about_title" value="<?php echo $about_title; ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="about_text" class="form-label">Text</label>
|
|
<textarea class="form-control" id="about_text" name="about_text" rows="4"><?php echo $about_text; ?></textarea>
|
|
</div>
|
|
</fieldset>
|
|
|
|
<button type="submit" class="btn btn-primary fw-bold w-100 py-2">Save Changes</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="editor-locked text-center p-5 bg-white rounded shadow-sm">
|
|
<i class="bi bi-lock-fill fs-1 text-primary"></i>
|
|
<h3 class="mt-3 fw-bold">Editor Locked</h3>
|
|
<p class="text-muted">Please <a href="login.php">log in</a> or <a href="register.php">create an account</a> to edit the page content.</p>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
|
|
<?php include 'partials/footer.php'; ?>
|
|
|
|
</body>
|
|
</html>
|