diff --git a/admin_competitions.php b/admin_competitions.php new file mode 100644 index 0000000..402d9f3 --- /dev/null +++ b/admin_competitions.php @@ -0,0 +1,127 @@ +prepare($sql); + $stmt->execute([$title, $description, $start_date, $end_date]); + $message = '
Competition created successfully!
'; + } catch (PDOException $e) { + $message = '
Error: ' . $e->getMessage() . '
'; + } + } else { + $message = '
Please fill in all required fields.
'; + } +} + +// Fetch all competitions +$competitions = []; +try { + $pdo = db(); + $stmt = $pdo->query("SELECT id, title, description, start_date, end_date FROM competitions ORDER BY created_at DESC"); + $competitions = $stmt->fetchAll(); +} catch (PDOException $e) { + // Handle error if needed +} + +?> + + + + + + Admin: Manage Competitions + + + + + + + +
+
+
+

Manage Competitions

+
+
+
+ +
+ +
+

Create New Competition

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

Existing Competitions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDTitleStart DateEnd DateActions
No competitions found.
+ Edit + Delete +
+
+
+
+ + + + + + diff --git a/admin_submissions.php b/admin_submissions.php new file mode 100644 index 0000000..b63c5f0 --- /dev/null +++ b/admin_submissions.php @@ -0,0 +1,145 @@ +beginTransaction(); + + try { + // Update submission status + $stmt = $pdo->prepare("UPDATE submissions SET status = ? WHERE id = ?"); + $stmt->execute([$status, $submission_id]); + + if ($status == 'approved') { + // Check if a certificate already exists + $stmt_check = $pdo->prepare("SELECT id FROM certificates WHERE submission_id = ?"); + $stmt_check->execute([$submission_id]); + if ($stmt_check->rowCount() == 0) { + // Generate a unique certificate code + $certificate_code = uniqid('CERT-'); + $stmt_insert = $pdo->prepare("INSERT INTO certificates (submission_id, certificate_code) VALUES (?, ?)"); + $stmt_insert->execute([$submission_id, $certificate_code]); + } + } else { + // If status is not 'approved', delete any existing certificate + $stmt_delete = $pdo->prepare("DELETE FROM certificates WHERE submission_id = ?"); + $stmt_delete->execute([$submission_id]); + } + + // Commit transaction + $pdo->commit(); + echo "
Submission status updated successfully.
"; + + } catch (Exception $e) { + // Rollback transaction on error + $pdo->rollBack(); + echo "
Failed to update submission status: " . $e->getMessage() . "
"; + } +} + +// Fetch all competitions +$stmt_competitions = $pdo->query("SELECT id, title FROM competitions ORDER BY start_date DESC"); +$competitions = $stmt_competitions->fetchAll(); + +// Fetch all submissions with user and competition info +$stmt_submissions = $pdo->query(" + SELECT + s.id, + s.file_path, + s.uploaded_at, + s.status, + u.name as user_name, + c.title as competition_title, + c.id as competition_id + FROM + submissions s + JOIN + users u ON s.user_id = u.id + JOIN + competitions c ON s.competition_id = c.id + ORDER BY + c.id, s.uploaded_at DESC +"); +$submissions_by_competition = []; +while ($row = $stmt_submissions->fetch()) { + $submissions_by_competition[$row['competition_id']][] = $row; +} + +?> + +
+

Competition Submissions

+ + +
No competitions found.
+ +
+ +
+

+ +

+
+
+ + + + + + + + + + + + + + + + + + + + + + +
UserFileUploaded AtStatusAction
View Submission +
+ + + +
+
+ +

No submissions for this competition yet.

+ +
+
+
+ +
+ + +
+ + diff --git a/admin_users.php b/admin_users.php new file mode 100644 index 0000000..3d14b99 --- /dev/null +++ b/admin_users.php @@ -0,0 +1,57 @@ +query("SELECT id, name, email, created_at FROM users ORDER BY created_at DESC"); +$users = $stmt->fetchAll(PDO::FETCH_ASSOC); +?> + +
+
+
+

Registered Users

+
+
+

This table displays all users who have registered on the platform.

+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
IDNameEmailRegistration Date
No users found.
+
+
+
+
+ + diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..7276318 --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,52 @@ +body { + padding-top: 56px; /* Adjust for fixed navbar */ + font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; +} + +#hero { + height: 80vh; + background: linear-gradient(45deg, rgba(13, 110, 253, 0.1), rgba(13, 202, 240, 0.1)); + color: #333; +} + +#hero h1 { + color: #000; +} + +.btn-primary { + background-image: linear-gradient(45deg, #0D6EFD, #0DCAF0); + border: none; + transition: transform 0.2s; +} + +.btn-primary:hover { + transform: translateY(-2px); + box-shadow: 0 4px 8px rgba(0,0,0,0.1); +} + +section { + scroll-margin-top: 56px; /* Offset for navbar */ +} + +.card { + border: none; + box-shadow: 0 4px 12px rgba(0,0,0,0.08); + transition: transform 0.2s; +} + +.card:hover { + transform: translateY(-5px); +} + +#contactForm .form-control { + border-radius: 1rem; +} + +#contactForm .form-control:focus { + box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25); + border-color: #0D6EFD; +} + +#form-feedback .alert { + border-radius: 1rem; +} diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..77bb366 --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,46 @@ +document.addEventListener('DOMContentLoaded', function () { + // Smooth scrolling for anchor links + document.querySelectorAll('a[href^="#"]').forEach(anchor => { + anchor.addEventListener('click', function (e) { + e.preventDefault(); + document.querySelector(this.getAttribute('href')).scrollIntoView({ + behavior: 'smooth' + }); + }); + }); + + // Contact form submission + const contactForm = document.getElementById('contactForm'); + if (contactForm) { + contactForm.addEventListener('submit', function (e) { + e.preventDefault(); + const name = document.getElementById('name').value; + const email = document.getElementById('email').value; + const message = document.getElementById('message').value; + const feedbackContainer = document.getElementById('form-feedback'); + const formContainer = document.getElementById('contact-form-container'); + + const formData = new FormData(); + formData.append('name', name); + formData.append('email', email); + formData.append('message', message); + + fetch('contact.php', { + method: 'POST', + body: formData + }) + .then(response => response.json()) + .then(data => { + let alertClass = data.success ? 'alert-success' : 'alert-danger'; + feedbackContainer.innerHTML = `
${data.message}
`; + if (data.success) { + formContainer.style.display = 'none'; + } + }) + .catch(error => { + feedbackContainer.innerHTML = `
An unexpected error occurred. Please try again.
`; + console.error('Error:', error); + }); + }); + } +}); diff --git a/competition_details.php b/competition_details.php new file mode 100644 index 0000000..3ff6384 --- /dev/null +++ b/competition_details.php @@ -0,0 +1,87 @@ +Competition ID is missing."; + require_once 'includes/footer.php'; + exit; +} + +$pdo = db(); +$stmt = $pdo->prepare("SELECT * FROM competitions WHERE id = ?"); +$stmt->execute([$competition_id]); +$competition = $stmt->fetch(); + +if (!$competition) { + echo "
Competition not found.
"; + require_once 'includes/footer.php'; + exit; +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['submission_file'])) { + if (!isset($_SESSION['user_id'])) { + echo "
You must be logged in to make a submission.
"; + } else { + $user_id = $_SESSION['user_id']; + $file = $_FILES['submission_file']; + + // File validation + if ($file['error'] === UPLOAD_ERR_OK) { + $upload_dir = 'uploads/'; + $file_name = uniqid() . '-' . basename($file['name']); + $target_path = $upload_dir . $file_name; + + if (move_uploaded_file($file['tmp_name'], $target_path)) { + $stmt = $pdo->prepare("INSERT INTO submissions (competition_id, user_id, file_path) VALUES (?, ?, ?)"); + if ($stmt->execute([$competition_id, $user_id, $target_path])) { + echo "
Submission uploaded successfully.
"; + } else { + echo "
Failed to save submission to the database.
"; + } + } else { + echo "
Failed to move uploaded file.
"; + } + } else { + echo "
Error uploading file.
"; + } + } +} + +?> + +
+

+

+ Start Date:
+ End Date: +

+

+ +
+ + +
+
+

Submit Your Entry

+
+
+
+
+ + +
+ +
+
+
+ +
+ Please login to submit your entry for this competition. +
+ +
+ + diff --git a/competitions.php b/competitions.php new file mode 100644 index 0000000..155f5c6 --- /dev/null +++ b/competitions.php @@ -0,0 +1,67 @@ +query("SELECT id, title, description, start_date, end_date FROM competitions WHERE end_date > NOW() ORDER BY start_date ASC"); + $competitions = $stmt->fetchAll(); +} catch (PDOException $e) { + // In a real app, you'd log this error. + $error_message = "Sorry, we couldn't load competitions at this time."; +} + +?> + + + + + + Competitions - READY BUDDY + + + + + + + +
+
+
+

Available Competitions

+

Join a competition and show your skills!

+
+
+
+ +
+ +
+ +
+
No upcoming competitions right now. Please check back later!
+
+ + +
+
+
+
+

+

Starts:

+

Ends:

+ View Details +
+
+
+ + +
+
+ + + + + + diff --git a/contact.php b/contact.php new file mode 100644 index 0000000..c9d4e2a --- /dev/null +++ b/contact.php @@ -0,0 +1,38 @@ + false, + 'message' => 'An error occurred.' +]; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $name = trim($_POST['name'] ?? ''); + $email = trim($_POST['email'] ?? ''); + $message = trim($_POST['message'] ?? ''); + + if (empty($name) || empty($email) || empty($message)) { + $response['message'] = 'Please fill out all fields.'; + } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + $response['message'] = 'Please provide a valid email address.'; + } else { + $to = getenv('MAIL_TO') ?: null; // Use environment variable or default in MailService + $subject = 'New Contact Form Submission from READY BUDDY'; + + $mailResult = MailService::sendContactMessage($name, $email, $message, $to, $subject); + + if (!empty($mailResult['success'])) { + $response['success'] = true; + $response['message'] = 'Thank you for your message! We will get back to you shortly.'; + } else { + // In a real app, you would log the detailed error: error_log($mailResult['error']); + $response['message'] = 'Sorry, there was an issue sending your message. Please try again later.'; + } + } +} else { + $response['message'] = 'Invalid request method.'; +} + +echo json_encode($response); diff --git a/db/migrations/001_create_competitions_table.php b/db/migrations/001_create_competitions_table.php new file mode 100644 index 0000000..998f594 --- /dev/null +++ b/db/migrations/001_create_competitions_table.php @@ -0,0 +1,19 @@ +exec($sql); + echo "Table 'competitions' created successfully (if it didn't exist)." . PHP_EOL; +} catch (PDOException $e) { + die("DB ERROR: " . $e->getMessage()); +} diff --git a/db/migrations/002_create_users_table.php b/db/migrations/002_create_users_table.php new file mode 100644 index 0000000..c8204b5 --- /dev/null +++ b/db/migrations/002_create_users_table.php @@ -0,0 +1,23 @@ +query("SHOW TABLES LIKE 'users'"); + if ($stmt->rowCount() == 0) { + $sql = "CREATE TABLE users ( + id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + )"; + $pdo->exec($sql); + echo "Table 'users' created successfully." . PHP_EOL; + } else { + echo "Table 'users' already exists." . PHP_EOL; + } +} catch (PDOException $e) { + die("Could not connect to the database or create table: " . $e->getMessage()); +} diff --git a/db/migrations/003_create_submissions_table.php b/db/migrations/003_create_submissions_table.php new file mode 100644 index 0000000..83f1fa3 --- /dev/null +++ b/db/migrations/003_create_submissions_table.php @@ -0,0 +1,21 @@ +exec($sql); + echo "Migration 003_create_submissions_table executed successfully." . PHP_EOL; +} catch (PDOException $e) { + die("Could not connect to the database: " . $e->getMessage()); +} diff --git a/db/migrations/004_add_status_to_submissions.php b/db/migrations/004_add_status_to_submissions.php new file mode 100644 index 0000000..55ee085 --- /dev/null +++ b/db/migrations/004_add_status_to_submissions.php @@ -0,0 +1,11 @@ +exec($sql); + echo "Migration 004_add_status_to_submissions executed successfully." . PHP_EOL; +} catch (PDOException $e) { + die("Could not connect to the database: " . $e->getMessage()); +} diff --git a/db/migrations/005_create_certificates_table.php b/db/migrations/005_create_certificates_table.php new file mode 100644 index 0000000..096b843 --- /dev/null +++ b/db/migrations/005_create_certificates_table.php @@ -0,0 +1,19 @@ +exec($sql); + echo "Migration 005_create_certificates_table executed successfully." . PHP_EOL; +} catch (PDOException $e) { + die("Could not connect to the database: " . $e->getMessage()); +} diff --git a/generate_certificate.php b/generate_certificate.php new file mode 100644 index 0000000..53277a5 --- /dev/null +++ b/generate_certificate.php @@ -0,0 +1,91 @@ +prepare(" + SELECT + c.certificate_code, + u.name as user_name, + comp.title as competition_title, + s.uploaded_at + FROM certificates c + JOIN submissions s ON c.submission_id = s.id + JOIN users u ON s.user_id = u.id + JOIN competitions comp ON s.competition_id = comp.id + WHERE c.certificate_code = ? +"); +$stmt->execute([$certificate_code]); +$certificate = $stmt->fetch(); + +if (!$certificate) { + die("Invalid certificate code."); +} + +?> + + + + + + Certificate of Achievement + + + + +
+
Certificate of Achievement
+
This is to certify that
+
+
has successfully participated in the
+
+
Date:
+
+ Certificate Code: +
+
+ + diff --git a/includes/footer.php b/includes/footer.php new file mode 100644 index 0000000..9906e7c --- /dev/null +++ b/includes/footer.php @@ -0,0 +1,6 @@ + diff --git a/includes/header.php b/includes/header.php new file mode 100644 index 0000000..0220401 --- /dev/null +++ b/includes/header.php @@ -0,0 +1,53 @@ + +
+ +
diff --git a/index.php b/index.php index 7205f3d..3994c44 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,106 @@ - - + - - - New Style - - - - - - - - - - - - - - - - - - - + + + READY BUDDY + + + + + + + + + + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

-
-
- + + + +
+
+
+

Welcome to READY BUDDY

+

The ultimate platform to challenge yourself, compete with others, and win amazing prizes. Your journey to greatness starts here.

+ Get Started +
+
+ +
+
+
+
+

About Us

+

READY BUDDY is a vibrant community and competition platform designed to bring out the best in you. We believe in the power of healthy competition to foster growth, learning, and connection. Whether you're a student, a professional, or a hobbyist, our platform provides the stage for you to shine.

+

We host a variety of competitions, from coding challenges and design contests to quizzes and creative showcases. Join us to test your skills, win prizes, and become part of a supportive community.

+
+
+ +
+
+
+
+ +
+
+

Portfolio

+

Check out some of our past competitions and winner showcases.

+
+
CodeFest 2025

An intense coding marathon.

+
Design Masters

A creative design challenge.

+
Quiz Bowl

A battle of wits and knowledge.

+
+
+
+ +
+
+

What Our Users Say

+ +
+
+ +
+
+
+
+

Contact Us

+

Have questions? We'd love to hear from you.

+
+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+
+
+ + + + + - + \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..2afb2c6 --- /dev/null +++ b/login.php @@ -0,0 +1,91 @@ +prepare("SELECT id, password, name FROM users WHERE email = ?"); + $stmt->execute([$email]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['user_name'] = $user['name']; + + header("Location: " . $return_url); + exit; + } else { + $error = 'Invalid email or password.'; + } + } catch (PDOException $e) { + $error = "Database error: " . $e->getMessage(); + } + } +} +?> + + + + + + Login - READY BUDDY + + + + + + + +
+
+
+
+
+

Login

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

Don't have an account? Register here.

+
+
+
+
+
+
+ + + + + + + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..f83284d --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ +prepare(" + SELECT + c.certificate_code, + comp.title as competition_title + FROM certificates c + JOIN submissions s ON c.submission_id = s.id + JOIN competitions comp ON s.competition_id = comp.id + WHERE s.user_id = ? +"); +$stmt->execute([$user_id]); +$certificates = $stmt->fetchAll(); + +?> + +
+

My Certificates

+ + +
You have not earned any certificates yet.
+ + + +
+ + diff --git a/register.php b/register.php new file mode 100644 index 0000000..72bf139 --- /dev/null +++ b/register.php @@ -0,0 +1,96 @@ +prepare("SELECT id FROM users WHERE email = ?"); + $stmt->execute([$email]); + if ($stmt->fetch()) { + $error = 'Email already exists.'; + } else { + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + $stmt = $pdo->prepare("INSERT INTO users (name, email, password) VALUES (?, ?, ?)"); + if ($stmt->execute([$name, $email, $hashed_password])) { + $success = 'Registration successful! You can now login.'; + } else { + $error = 'Something went wrong. Please try again.'; + } + } + } catch (PDOException $e) { + $error = "Database error: " . $e->getMessage(); + } + } +} +?> + + + + + + Register - READY BUDDY + + + + + + + +
+
+
+
+
+

Create Account

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

Already have an account? Login here.

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