95 lines
3.6 KiB
PHP
95 lines
3.6 KiB
PHP
<?php
|
|
session_start();
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
require_once __DIR__ . '/../db/config.php';
|
|
require_once __DIR__ . '/../includes/security.php';
|
|
|
|
$error_message = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
if (!validate_csrf_token()) {
|
|
$error_message = 'CSRF token validation failed.';
|
|
} else {
|
|
$title = $_POST['title'] ?? '';
|
|
$description = $_POST['description'] ?? '';
|
|
|
|
if (empty($title)) {
|
|
$error_message = 'Title is required.';
|
|
} else {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("INSERT INTO surveys (title, description) VALUES (?, ?)");
|
|
$stmt->execute([$title, $description]);
|
|
$new_survey_id = $pdo->lastInsertId();
|
|
header("Location: survey_build.php?id=" . $new_survey_id . "&status=created");
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
$error_message = "Database error: " . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Add New Survey - FormFlex Pro</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="../assets/css/admin.css">
|
|
</head>
|
|
<body>
|
|
|
|
<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
|
|
<a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">FormFlex Pro</a>
|
|
</header>
|
|
|
|
<div class="container-fluid">
|
|
<div class="row">
|
|
<nav id="sidebarMenu" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
|
|
<div class="position-sticky pt-3">
|
|
<ul class="nav flex-column">
|
|
<li class="nav-item"><a class="nav-link" href="index.php">Dashboard</a></li>
|
|
<li class="nav-item"><a class="nav-link active" aria-current="page" href="surveys.php">Surveys</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="users.php">Users</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="#">Settings</a></li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
|
<h1 class="h2">Add New Survey</h1>
|
|
</div>
|
|
|
|
<?php if ($error_message): ?>
|
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST" action="survey_add.php" class="card p-3">
|
|
<?php echo csrf_input_field(); ?>
|
|
<div class="mb-3">
|
|
<label for="title" class="form-label">Survey Title</label>
|
|
<input type="text" class="form-control" id="title" name="title" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="description" class="form-label">Description (Optional)</label>
|
|
<textarea class="form-control" id="description" name="description" rows="3"></textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Save and Add Questions</button>
|
|
<a href="surveys.php" class="btn btn-secondary mt-2">Cancel</a>
|
|
</form>
|
|
|
|
</main>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|