mvp.4
This commit is contained in:
parent
44f71c32c4
commit
e1227cfbcd
@ -19,11 +19,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$stmt->execute([$name, $description]);
|
||||
} catch (PDOException $e) {
|
||||
// In a real app, log this error. For now, we'll just die.
|
||||
die("Database error: " . $e->getMessage());
|
||||
error_log("DB Error: " . $e->getMessage());
|
||||
header('Location: index.php?error=dberror');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Redirect back to the main page after successful insertion
|
||||
header('Location: index.php?success=1');
|
||||
header('Location: index.php?success=processadded');
|
||||
exit;
|
||||
} else {
|
||||
// If not a POST request, redirect to the main page
|
||||
|
||||
@ -8,13 +8,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['id'])) {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("DELETE FROM processes WHERE id = :id");
|
||||
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
if ($stmt->execute()) {
|
||||
header('Location: index.php?success=processdeleted');
|
||||
exit();
|
||||
} else {
|
||||
header('Location: index.php?error=deletionfailed');
|
||||
exit();
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
error_log("DB Error: " . $e->getMessage());
|
||||
// Optionally, redirect with an error message
|
||||
header('Location: index.php?error=dberror');
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
header('Location: index.php?error=invalidrequest');
|
||||
exit();
|
||||
}
|
||||
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
?>
|
||||
61
index.php
61
index.php
@ -37,6 +37,51 @@ $project_image_url = htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '');
|
||||
<script src="https://unpkg.com/feather-icons"></script>
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
<div id="message-area" class="container mt-4">
|
||||
<?php
|
||||
if (isset($_GET['success'])) {
|
||||
$message = '';
|
||||
switch ($_GET['success']) {
|
||||
case 'processadded':
|
||||
$message = 'Process added successfully!';
|
||||
break;
|
||||
case 'processupdated':
|
||||
$message = 'Process updated successfully!';
|
||||
break;
|
||||
case 'processdeleted':
|
||||
$message = 'Process deleted successfully!';
|
||||
break;
|
||||
default:
|
||||
$message = 'Action successful!';
|
||||
}
|
||||
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">' . $message . '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>';
|
||||
}
|
||||
|
||||
if (isset($_GET['error'])) {
|
||||
$message = '';
|
||||
switch ($_GET['error']) {
|
||||
case 'emptyfields':
|
||||
$message = 'Please fill in all fields.';
|
||||
break;
|
||||
case 'dberror':
|
||||
$message = 'A database error occurred. Please try again.';
|
||||
break;
|
||||
case 'deletionfailed':
|
||||
$message = 'Failed to delete process. Please try again.';
|
||||
break;
|
||||
case 'invalidrequest':
|
||||
$message = 'Invalid request.';
|
||||
break;
|
||||
case 'processnotfound':
|
||||
$message = 'Process not found.';
|
||||
break;
|
||||
default:
|
||||
$message = 'An error occurred. Please try again.';
|
||||
}
|
||||
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">' . $message . '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<header class="header">
|
||||
<div class="container">
|
||||
@ -53,7 +98,7 @@ $project_image_url = htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '');
|
||||
<div class="card-body p-4">
|
||||
<h2 class="h4 card-title fw-bold">Map a New Process</h2>
|
||||
<p class="card-subtitle mb-4 text-muted">Define a process to begin analysis.</p>
|
||||
<form action="add_process.php" method="POST">
|
||||
<form action="add_process.php" method="POST" id="addProcessForm">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Process Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
@ -119,6 +164,20 @@ $project_image_url = htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '');
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
// Client-side validation for the Add Process form
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var form = document.getElementById('addProcessForm');
|
||||
if (form) {
|
||||
form.addEventListener('submit', function(event) {
|
||||
if (!form.checkValidity()) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
form.classList.add('was-validated');
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
feather.replace()
|
||||
</script>
|
||||
</body>
|
||||
|
||||
@ -15,19 +15,22 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
header('Location: index.php?status=success&message=Process updated successfully!');
|
||||
header('Location: index.php?success=processupdated');
|
||||
exit();
|
||||
} else {
|
||||
header('Location: edit_process.php?id=' . $id . '&status=error&message=Failed to update process.');
|
||||
header('Location: index.php?error=updatefailed');
|
||||
exit();
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
error_log("DB Error: " . $e->getMessage());
|
||||
header('Location: edit_process.php?id=' . $id . '&status=error&message=Database error: ' . urlencode($e->getMessage()));
|
||||
header('Location: index.php?error=dberror');
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
header('Location: index.php?error=emptyfields');
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
header('Location: index.php?status=error&message=Invalid request method.');
|
||||
header('Location: index.php?error=invalidrequest');
|
||||
exit();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user