diff --git a/assets/css/custom.css b/assets/css/custom.css index e9e2160..d72383c 100644 --- a/assets/css/custom.css +++ b/assets/css/custom.css @@ -1,9 +1,11 @@ +/* General Body & Typography */ body { - background-color: #F9FAFB; - color: #1F2937; font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif; + background-color: #F9FAFB; /* Gray-50 */ + color: #1F2937; /* Gray-800 */ } +/* Gradient Text */ .gradient-text { background: linear-gradient(to right, #6366F1, #EC4899); -webkit-background-clip: text; @@ -12,27 +14,64 @@ body { text-fill-color: transparent; } +/* Buttons */ .btn-primary { background-color: #6366F1; border-color: #6366F1; + padding: 0.75rem 1.5rem; + border-radius: 0.5rem; + font-weight: 600; + transition: all 0.2s ease-in-out; } .btn-primary:hover { - background-color: #4f52c4; - border-color: #4f52c4; + background-color: #4F46E5; /* Darker Indigo */ + border-color: #4F46E5; + transform: translateY(-2px); + box-shadow: 0 4px 12px rgba(0,0,0,0.1); } +/* Hero Section */ .hero-section { padding: 6rem 0; background-color: #FFFFFF; } -.editor-section { - background-color: #F9FAFB; +/* Editor Section */ +.editor-section, .editor-section-locked { padding: 4rem 0; + background-color: #F9FAFB; /* Gray-50 */ } -.card { +.editor-section .card, .editor-section-locked .card { border: none; - box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15); + border-radius: 0.5rem; + box-shadow: 0 10px 25px rgba(0,0,0,0.05); } + +.editor-section-locked a { + color: #6366F1; + text-decoration: none; + font-weight: 600; +} + +.editor-section-locked a:hover { + text-decoration: underline; +} + + +/* Form Controls */ +.form-control { + border-radius: 0.5rem; + border: 1px solid #D1D5DB; /* Gray-300 */ +} + +.form-control:focus { + border-color: #6366F1; + box-shadow: 0 0 0 0.25rem rgba(99, 102, 241, 0.25); +} + +/* Footer */ +footer { + border-top: 1px solid #E5E7EB; /* Gray-200 */ +} \ No newline at end of file diff --git a/db/migrate.php b/db/migrate.php index 8a67627..8f5f3ef 100644 --- a/db/migrate.php +++ b/db/migrate.php @@ -2,19 +2,56 @@ require_once __DIR__ . '/config.php'; try { - // Connect without specifying a database - $pdo = new PDO('mysql:host='.DB_HOST, DB_USER, DB_PASS, [ - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + // First, ensure the database exists + $pdo = new PDO('mysql:host=' . DB_HOST, DB_USER, DB_PASS, [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]); - $pdo->exec("CREATE DATABASE IF NOT EXISTS ".DB_NAME); - echo "Database created successfully (if it didn't exist).\n"; + $pdo->exec("CREATE DATABASE IF NOT EXISTS " . DB_NAME); - // Now connect to the database and run migrations + // Now, connect to the actual database $pdo = db(); - $sql = file_get_contents(__DIR__ . '/migrations/001_create_users_table.sql'); - $pdo->exec($sql); - echo "Migration successful!\n"; + echo "Successfully connected to database: " . DB_NAME . "\n"; + + // 1. Create migrations tracking table if it doesn't exist + $pdo->exec("CREATE TABLE IF NOT EXISTS `migrations` ( + `migration` VARCHAR(255) NOT NULL, + PRIMARY KEY (`migration`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); + + // 2. Get all migrations that have been run + $run_migrations_stmt = $pdo->query("SELECT `migration` FROM `migrations`"); + $run_migrations = $run_migrations_stmt->fetchAll(PDO::FETCH_COLUMN); + + // 3. Get all available migration files + $migration_files = glob(__DIR__ . '/migrations/*.sql'); + sort($migration_files); + + $migrations_run_this_time = 0; + + // 4. Loop through files and run any new migrations + foreach ($migration_files as $file) { + $migration_name = basename($file); + if (!in_array($migration_name, $run_migrations)) { + echo "Running migration: " . $migration_name . "...\n"; + + $sql = file_get_contents($file); + $pdo->exec($sql); + + // Record the migration + $stmt = $pdo->prepare("INSERT INTO `migrations` (`migration`) VALUES (?)"); + $stmt->execute([$migration_name]); + + echo " -> Success.\n"; + $migrations_run_this_time++; + } + } + + if ($migrations_run_this_time === 0) { + echo "All migrations are up to date.\n"; + } else { + echo "Finished running " . $migrations_run_this_time . " new migration(s).\n"; + } + } catch (PDOException $e) { die("Migration failed: " . $e->getMessage() . "\n"); -} \ No newline at end of file +} diff --git a/db/migrations/002_create_user_content_table.sql b/db/migrations/002_create_user_content_table.sql new file mode 100644 index 0000000..20a9aa4 --- /dev/null +++ b/db/migrations/002_create_user_content_table.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS `user_content` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `user_id` INT NOT NULL, + `content` JSON NOT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/index.php b/index.php index 54e1127..4b6d0f0 100644 --- a/index.php +++ b/index.php @@ -1,89 +1,79 @@ 'Build Your Dream Website', - 'hero_subtitle' => 'Visually design, customize, and publish beautiful, responsive websites. No code required.', - 'features_title' => 'Powerful Features', - 'features' => [ - [ - 'icon' => 'bi-grid-1x2-fill', - 'title' => 'Drag & Drop Builder', - 'description' => 'Easily build and customize your site with our intuitive visual editor.' - ], - [ - 'icon' => 'bi-palette-fill', - 'title' => 'Beautiful Templates', - 'description' => 'Choose from a variety of professionally designed templates to get started.' - ], - [ - 'icon' => 'bi-phone-fill', - 'title' => 'Fully Responsive', - 'description' => 'Your website will look stunning on any device, from desktops to smartphones.' - ] - ], - 'about_title' => 'About Us', - 'about_text' => 'We are a passionate team dedicated to making web creation accessible to everyone. Our mission is to empower you to bring your ideas to life online, without needing to write a single line of code. Join us on this journey!' -]; +$is_logged_in = isset($_SESSION['user_id']); +$content = []; -// Load content from JSON file if it exists -if (file_exists($content_file)) { - $json_content = file_get_contents($content_file); - $content = json_decode($json_content, true); - // Merge with defaults to ensure all keys are present - $content = array_merge($default_content, $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 { - $content = $default_content; + // User is not logged in, show default content + $content = json_decode(file_get_contents('db/content.json'), true); } -// Handle POST request to update content -if ($_SERVER['REQUEST_METHOD'] === 'POST') { - // Update Hero - if (isset($_POST['hero_title'])) { - $content['hero_title'] = htmlspecialchars($_POST['hero_title']); - } - if (isset($_POST['hero_subtitle'])) { - $content['hero_subtitle'] = htmlspecialchars($_POST['hero_subtitle']); - } - // Update About - if (isset($_POST['about_title'])) { - $content['about_title'] = htmlspecialchars($_POST['about_title']); - } - if (isset($_POST['about_text'])) { - $content['about_text'] = htmlspecialchars($_POST['about_text']); - } +// Handle content updates +if ($_SERVER['REQUEST_METHOD'] === 'POST' && $is_logged_in) { + $pdo = db(); - // Update Features Title - if (isset($_POST['features_title'])) { - $content['features_title'] = htmlspecialchars($_POST['features_title']); - } + // 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 Features - if (isset($_POST['features']) && is_array($_POST['features'])) { - $updated_features = []; - foreach ($_POST['features'] as $feature_data) { - $updated_features[] = [ - 'icon' => htmlspecialchars($feature_data['icon']), - 'title' => htmlspecialchars($feature_data['title']), - 'description' => htmlspecialchars($feature_data['description']) - ]; - } - $content['features'] = $updated_features; - } + // 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']]); - file_put_contents($content_file, json_encode($content, JSON_PRETTY_PRINT)); - // Redirect to avoid form resubmission - header("Location: " . $_SERVER['REQUEST_URI']); + 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.'); + ?> @@ -91,150 +81,167 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { webCreatorSaas - - - - - - - - - - - + - - + - - + - -
- -
-
-

-

- Start Building for Free +
+ +
+
+

+

+ Get Started +
+
+ + +
+
+
+

-
- - -
-
-
-

-
-
- -
-
- -

-

+
+
+
+
+
-
- -
-
-
- - -
-
-
-
-

-

+
+

-
-
- - -
-
-
-
-
-

Live Editor

-

Change the text in the sections above.

-
-
- Hero Section -
- - -
-
- - -
-
- -
- Features Section -
- - -
- $feature): ?> -
- -
- - -
-
- - -
-
- - -
-
- -
- -
- About Section -
- - -
-
- - -
-
- -
- -
-
+
+
+
+
+
+

+
+
+
+
+
+ +
+
+

-
-
-
- - -
-
-
-

© webCreatorSaas. Built with love by Flatlogic.

-
+
+ + +
+
+
+
+

+

+
+
+ +
+
+
+
+ + +
+
+ +
+
+

Live Editor

+
+
+
+
+ Hero Section +
+ + +
+
+ + +
+
+ +
+ Features Section +
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ +
+ About Section +
+ + +
+
+ + +
+
+ + +
+
+
+ +
+ +

Editor Locked

+

Please log in or create an account to edit the page content.

+
+ +
+
+
+ + - - - - - + \ No newline at end of file