diff --git a/admin.php b/admin.php new file mode 100644 index 0000000..08de7e7 --- /dev/null +++ b/admin.php @@ -0,0 +1,89 @@ +query("SELECT id, title, created_at FROM surveys ORDER BY created_at DESC"); + $surveys = $stmt->fetchAll(); +} catch (PDOException $e) { + // Handle error properly in a real app + error_log("Database error: " . $e->getMessage()); +} + +?> + + + + + + Admin Dashboard + + + + + + + +
+
+

Survey Dashboard

+ Create New Survey +
+ +
+
+ Existing Surveys +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
IDTitleCreated AtActions
No surveys found.
+ View + View Responses +
+
+
+
+ + + + diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..8764d03 --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,66 @@ + +body { + font-family: 'Inter', sans-serif; + background-color: #f8f9fa; +} + +.navbar-brand { + font-weight: 700; +} + +.hero { + background: linear-gradient(45deg, #0d6efd, #0dcaf0); + color: white; + padding: 6rem 0; + text-align: center; +} + +.hero h1 { + font-size: 3.5rem; + font-weight: 700; +} + +.hero p { + font-size: 1.25rem; + margin-bottom: 2rem; +} + +.btn-hero { + font-size: 1.25rem; + padding: 0.75rem 2rem; + font-weight: 600; +} + +.section { + padding: 4rem 0; +} + +.question-card { + border: 1px solid #dee2e6; + border-radius: 0.5rem; + margin-bottom: 1.5rem; + background-color: #fff; +} + +.question-card .card-header { + background-color: #f8f9fa; + border-bottom: 1px solid #dee2e6; + font-weight: 600; + display: flex; + justify-content: space-between; + align-items: center; +} + +.question-card .card-body { + padding: 1.5rem; +} + +.footer { + background-color: #343a40; + color: white; + padding: 2rem 0; +} + +.footer a { + color: #0dcaf0; +} diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..a8b6d0a --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,65 @@ +document.addEventListener('DOMContentLoaded', function () { + const addQuestionButtons = document.querySelectorAll('.add-question-btn'); + const questionsContainer = document.getElementById('questions-container'); + let questionCounter = 0; + + addQuestionButtons.forEach(button => { + button.addEventListener('click', function () { + const type = this.dataset.type; + addQuestion(type); + }); + }); + + function addQuestion(type) { + questionCounter++; + const questionId = `question-${questionCounter}`; + let questionHtml = ` +
+
+ Question ${questionCounter} + +
+
+
+ + +
+ + `; + + switch (type) { + case 'text': + questionHtml += `

A short text answer will be collected.

`; + break; + case 'multiple-choice': + case 'checkboxes': + questionHtml += ` +
+ +
+
+ + +
+
+ +
+ `; + break; + } + + questionHtml += `
`; + questionsContainer.insertAdjacentHTML('beforeend', questionHtml); + } + + window.addOption = function(questionId, questionIndex) { + const optionsContainer = document.getElementById(`${questionId}-options-container`); + const optionHtml = ` +
+ + +
+ `; + optionsContainer.insertAdjacentHTML('beforeend', optionHtml); + } +}); diff --git a/create_survey.php b/create_survey.php new file mode 100644 index 0000000..9a4ea28 --- /dev/null +++ b/create_survey.php @@ -0,0 +1,90 @@ + + + + + + + Create a New Survey - survey-demo-app + + + + + + + + + + + + + + + + + + +
+
+
+

Create a New Survey

+

Start by giving your survey a title, then add your questions.

+
+ +
+
+
+
+ + +
+
+ + +
+
+
+ +
+ +
+
+ + + +
+
+ +
+ +
+
+
+
+ + + + + + + diff --git a/db/create_database.php b/db/create_database.php new file mode 100644 index 0000000..10e0617 --- /dev/null +++ b/db/create_database.php @@ -0,0 +1,11 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $pdo->exec("CREATE DATABASE IF NOT EXISTS `" . DB_NAME . "` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); + echo "Database '" . DB_NAME . "' created or already exists." . PHP_EOL; +} catch (PDOException $e) { + die("Database creation failed: " . $e->getMessage()); +} diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..8a04e03 --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,62 @@ +exec("CREATE TABLE IF NOT EXISTS surveys ( + id INT AUTO_INCREMENT PRIMARY KEY, + title VARCHAR(255) NOT NULL, + description TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + )"); + + // Create questions table + $pdo->exec("CREATE TABLE IF NOT EXISTS questions ( + id INT AUTO_INCREMENT PRIMARY KEY, + survey_id INT NOT NULL, + question_text VARCHAR(255) NOT NULL, + question_type VARCHAR(50) NOT NULL, + options TEXT, -- JSON encoded options for multiple_choice/checkboxes + FOREIGN KEY (survey_id) REFERENCES surveys(id) ON DELETE CASCADE + )"); + + $pdo->exec("CREATE TABLE IF NOT EXISTS survey_responses ( + id INT AUTO_INCREMENT PRIMARY KEY, + survey_id INT NOT NULL, + submitted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (survey_id) REFERENCES surveys(id) ON DELETE CASCADE + )"); + + $pdo->exec("CREATE TABLE IF NOT EXISTS survey_answers ( + id INT AUTO_INCREMENT PRIMARY KEY, + response_id INT NOT NULL, + question_id INT NOT NULL, + answer_text TEXT, + FOREIGN KEY (response_id) REFERENCES survey_responses(id) ON DELETE CASCADE, + FOREIGN KEY (question_id) REFERENCES questions(id) ON DELETE CASCADE + )"); + + // Create users table + $pdo->exec("CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(50) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + )"); + + // Insert a default admin user if one doesn't exist + $stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?"); + $stmt->execute(['admin']); + if ($stmt->rowCount() == 0) { + $username = 'admin'; + $password = password_hash('password', PASSWORD_DEFAULT); + $pdo->prepare("INSERT INTO users (username, password) VALUES (?, ?)")->execute([$username, $password]); + } + + echo "Database tables created successfully!"; + +} catch (PDOException $e) { + die("Database migration failed: " . $e->getMessage()); +} \ No newline at end of file diff --git a/index.php b/index.php index 7205f3d..148ca8c 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,114 @@ - - + - - - New Style - - - - - - - - - - - - - - - - - - - + + + survey-demo-app + + + + + + + + + + + + + -
-
-

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

-
-
- + + + +
+
+

Create Beautiful Surveys, Effortlessly

+

Build engaging forms and surveys to capture the data you need. Simple, fast, and free.

+ Get Started Now +
+
+ +
+
+
+
+
+

About SurveyBuilder

+

SurveyBuilder is a modern tool designed to make survey creation intuitive and fast. Whether you're gathering customer feedback, conducting market research, or planning an event, we provide the tools you need to get answers.

+

Our mission is to simplify data collection without compromising on power or design.

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

Powerful Features, Simple Interface

+

Everything you need to build and analyze surveys.

+
+
+
+
+ +

Multiple Question Types

+

From short text to multiple choice and checkboxes, create the perfect question for any scenario.

+
+
+
+
+ +

Real-time Results

+

Watch responses roll in and analyze your data with a clean, simple dashboard.

+
+
+
+
+ +

Easy Sharing

+

Get a unique, shareable link for your survey the moment you publish it.

+
+
+
+
+
+
+ + + + - + \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..892cf72 --- /dev/null +++ b/login.php @@ -0,0 +1,81 @@ +prepare("SELECT * FROM users WHERE username = ?"); + $stmt->execute([$username]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['username'] = $user['username']; + header("Location: admin.php"); + exit; + } else { + $error = 'Invalid username or password.'; + } + } catch (PDOException $e) { + $error = "Database error: " . $e->getMessage(); + } + } +} +?> + + + + + + Login - Survey App + + + + + + + +
+
+
+
+
+ Admin Login +
+
+ +
+ +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+ + + + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..766a593 --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ + + + + + + Privacy Policy - survey-demo-app + + + + + + + + + + + + + + + + + + +
+
+

Privacy Policy

+

This is a placeholder for your privacy policy. You should replace this content with your own policy, detailing how you collect, use, and protect your users' data.

+ +

Information We Collect

+

Detail the types of information you collect from users, such as personal identification information (name, email address, etc.) and non-personal information (browser type, etc.).

+ +

How We Use Information

+

Explain how you use the collected information, for example, to provide and improve your services, to communicate with users, and for marketing purposes.

+ +

Data Protection

+

Describe the measures you take to protect user data from unauthorized access or disclosure.

+ +

Last updated:

+
+
+ + + + + + diff --git a/save_response.php b/save_response.php new file mode 100644 index 0000000..2140e9b --- /dev/null +++ b/save_response.php @@ -0,0 +1,49 @@ +beginTransaction(); + + // 1. Create a new survey response + $stmt = $pdo->prepare("INSERT INTO survey_responses (survey_id) VALUES (?)"); + $stmt->execute([$survey_id]); + $response_id = $pdo->lastInsertId(); + + // 2. Save each answer + $stmt = $pdo->prepare("INSERT INTO survey_answers (response_id, question_id, answer_text) VALUES (?, ?, ?)"); + foreach ($answers as $question_id => $answer_text) { + if (is_array($answer_text)) { + // For checkboxes, implode the array into a string + $answer_text = implode(', ', $answer_text); + } + $stmt->execute([$response_id, $question_id, $answer_text]); + } + + $pdo->commit(); + + // Redirect to a success page + header('Location: survey_success.php?response=true'); + exit; + + } catch (PDOException $e) { + if ($pdo->inTransaction()) { + $pdo->rollBack(); + } + // In a real app, you'd log this error + http_response_code(500); + die('Database error: ' . $e->getMessage()); + } +} else { + http_response_code(405); + die('Method not allowed.'); +} diff --git a/save_survey.php b/save_survey.php new file mode 100644 index 0000000..1e9162d --- /dev/null +++ b/save_survey.php @@ -0,0 +1,75 @@ +beginTransaction(); + + // 1. Insert the survey + $stmt = $pdo->prepare("INSERT INTO surveys (title, description) VALUES (?, ?)"); + $stmt->execute([$title, $description]); + $surveyId = $pdo->lastInsertId(); + + // 2. Insert the questions + $questionStmt = $pdo->prepare( + "INSERT INTO questions (survey_id, question_text, question_type, options) VALUES (?, ?, ?, ?)" + ); + + foreach ($questions as $question) { + $text = trim($question['text'] ?? ''); + $type = trim($question['type'] ?? ''); + $options = $question['options'] ?? []; + + if (empty($text) || empty($type)) { + // Skip invalid/empty questions + continue; + } + + // For choice-based questions, ensure options are provided and encode them as JSON + $optionsJson = null; + if (($type === 'multiple-choice' || $type === 'checkboxes')) { + // Filter out empty option strings + $validOptions = array_filter($options, function($val) { + return trim($val) !== ''; + }); + if (empty($validOptions)) { + // If no valid options, skip this question + continue; + } + $optionsJson = json_encode($validOptions); + } + + $questionStmt->execute([$surveyId, $text, $type, $optionsJson]); + } + + $pdo->commit(); + + // Redirect to a success page + header("Location: survey_success.php?id=" . $surveyId); + exit; + +} catch (PDOException $e) { + // If anything goes wrong, roll back the transaction + if ($pdo->inTransaction()) { + $pdo->rollBack(); + } + // In a real app, log this error instead of showing it to the user + die("Database error: " . $e->getMessage()); +} catch (Exception $e) { + die("An unexpected error occurred: " . $e->getMessage()); +} diff --git a/session.php b/session.php new file mode 100644 index 0000000..2cbefa3 --- /dev/null +++ b/session.php @@ -0,0 +1,7 @@ + + + + http://your-domain.com/ + 2025-10-15 + weekly + 1.0 + + + http://your-domain.com/create_survey.php + 2025-10-15 + monthly + 0.8 + + + http://your-domain.com/privacy.php + 2025-10-15 + yearly + 0.5 + + diff --git a/survey_success.php b/survey_success.php new file mode 100644 index 0000000..0ec8874 --- /dev/null +++ b/survey_success.php @@ -0,0 +1,54 @@ + + + + + + + Survey Created! - survey-demo-app + + + + + + +
+
+
+ +

Thank You!

+

Your response has been submitted successfully.

+ + +

🎉 Success!

+

Your survey has been created successfully.

+
+

You can share this link with your respondents:

+
+ + +
+ View Survey + Create Another Survey +
+ +
+
+
+ + + + + diff --git a/view_responses.php b/view_responses.php new file mode 100644 index 0000000..c85e422 --- /dev/null +++ b/view_responses.php @@ -0,0 +1,114 @@ +prepare("SELECT title FROM surveys WHERE id = ?"); + $stmt->execute([$survey_id]); + $survey = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$survey) { + http_response_code(404); + echo "Error: Survey not found."; + exit; + } + + // Fetch all responses for this survey + $stmt = $pdo->prepare("SELECT * FROM survey_responses WHERE survey_id = ? ORDER BY submitted_at DESC"); + $stmt->execute([$survey_id]); + $responses = $stmt->fetchAll(PDO::FETCH_ASSOC); + + // For each response, fetch the answers + $responses_with_answers = []; + foreach ($responses as $response) { + $answer_stmt = $pdo->prepare(" + SELECT sa.answer_text, q.question_text + FROM survey_answers sa + JOIN questions q ON sa.question_id = q.id + WHERE sa.response_id = ? + "); + $answer_stmt->execute([$response['id']]); + $answers = $answer_stmt->fetchAll(PDO::FETCH_ASSOC); + $response['answers'] = $answers; + $responses_with_answers[] = $response; + } + +} catch (PDOException $e) { + http_response_code(500); + echo "Database error: " . htmlspecialchars($e->getMessage()); + exit; +} +?> + + + + + + Responses for <?php echo htmlspecialchars($survey['title']); ?> + + + + + + +
+

Responses for ""

+ + ← Back to Dashboard + + +
+ No responses have been submitted for this survey yet. +
+ + +
+
+ Response submitted on: +
+
+
    + +
  • +

    +

    +
  • + + +
  • No answers were provided for this submission.
  • + +
+
+
+ + +
+ + + + diff --git a/view_survey.php b/view_survey.php new file mode 100644 index 0000000..7950921 --- /dev/null +++ b/view_survey.php @@ -0,0 +1,129 @@ +prepare("SELECT title, description FROM surveys WHERE id = ?"); + $stmt->execute([$survey_id]); + $survey = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$survey) { + http_response_code(404); + echo "Error: Survey not found."; + exit; + } + + // Fetch questions + $stmt = $pdo->prepare("SELECT id, question_text, question_type, options FROM questions WHERE survey_id = ? ORDER BY id ASC"); + $stmt->execute([$survey_id]); + $questions = $stmt->fetchAll(PDO::FETCH_ASSOC); + +} catch (PDOException $e) { + http_response_code(500); + echo "Database error: " . htmlspecialchars($e->getMessage()); + exit; +} +?> + + + + + + <?php echo htmlspecialchars($survey['title']); ?> - Survey + + + + + + + +
+
+
+

+
+
+

+
+
+ + + $question): ?> + +
+ + + + + + + + + +
+ + +
+ + + + + + + +
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + +