This commit is contained in:
Flatlogic Bot 2026-01-02 11:10:39 +00:00
parent 4df1537bcb
commit 44f71c32c4
3 changed files with 137 additions and 6 deletions

90
edit_process.php Normal file
View File

@ -0,0 +1,90 @@
<?php
require_once 'db/config.php';
$process = null;
$error = '';
if (isset($_GET['id'])) {
$id = $_GET['id'];
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT id, name, description FROM processes WHERE id = :id");
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
$process = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$process) {
$error = "Process not found.";
}
} catch (PDOException $e) {
error_log("DB Error: " . $e->getMessage());
$error = "Could not retrieve process details.";
}
} else {
$error = "No process ID provided.";
}
$project_name = htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'ProcessFlow Optimizer');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Process - <?php echo $project_name; ?></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/custom.css?v=<?php echo time(); ?>">
<script src="https://unpkg.com/feather-icons"></script>
</head>
<body class="bg-light">
<header class="header">
<div class="container">
<h1 class="h3 mb-0"><?php echo $project_name; ?></h1>
<p class="text-muted mb-0">A business process analyzer and automated optimizer</p>
</div>
</header>
<main class="container py-5">
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="card shadow-sm">
<div class="card-body p-4">
<?php if ($error): ?>
<div class="alert alert-danger" role="alert">
<?php echo $error; ?>
</div>
<a href="index.php" class="btn btn-primary">Go Back</a>
<?php elseif ($process): ?>
<h2 class="h4 card-title fw-bold">Edit Process: <?php echo htmlspecialchars($process['name']); ?></h2>
<p class="card-subtitle mb-4 text-muted">Modify the details of your process.</p>
<form action="update_process.php" method="POST">
<input type="hidden" name="id" value="<?php echo $process['id']; ?>">
<div class="mb-3">
<label for="name" class="form-label">Process Name</label>
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($process['name']); ?>" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="4" required><?php echo htmlspecialchars($process['description']); ?></textarea>
</div>
<button type="submit" class="btn btn-primary">Update Process</button>
<a href="index.php" class="btn btn-link">Cancel</a>
</form>
<?php endif; ?>
</div>
</div>
</div>
</div>
</main>
<footer class="text-center py-4 text-muted">
<p>&copy; <?php echo date("Y"); ?> <?php echo $project_name; ?>. All rights reserved.</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
feather.replace()
</script>
</body>
</html>

View File

@ -87,6 +87,13 @@ $project_image_url = htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '');
<h5 class="mb-1 fw-bold"><?php echo htmlspecialchars($process['name']); ?></h5> <h5 class="mb-1 fw-bold"><?php echo htmlspecialchars($process['name']); ?></h5>
<small class="text-muted"><?php echo date("M d, Y", strtotime($process['created_at'])); ?></small> <small class="text-muted"><?php echo date("M d, Y", strtotime($process['created_at'])); ?></small>
</div> </div>
<div class="d-flex align-items-center">
<form action="edit_process.php" method="GET" class="me-2">
<input type="hidden" name="id" value="<?php echo $process['id']; ?>">
<button type="submit" class="btn btn-sm btn-outline-primary" title="Edit Process">
<i data-feather="edit" style="width: 16px; height: 16px;"></i>
</button>
</form>
<form action="delete_process.php" method="POST" onsubmit="return confirm('Are you sure you want to delete this process?');"> <form action="delete_process.php" method="POST" onsubmit="return confirm('Are you sure you want to delete this process?');">
<input type="hidden" name="id" value="<?php echo $process['id']; ?>"> <input type="hidden" name="id" value="<?php echo $process['id']; ?>">
<button type="submit" class="btn btn-sm btn-outline-danger" title="Delete Process"> <button type="submit" class="btn btn-sm btn-outline-danger" title="Delete Process">
@ -94,6 +101,7 @@ $project_image_url = htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '');
</button> </button>
</form> </form>
</div> </div>
</div>
<p class="mb-1 text-muted"><?php echo htmlspecialchars($process['description']); ?></p> <p class="mb-1 text-muted"><?php echo htmlspecialchars($process['description']); ?></p>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>

33
update_process.php Normal file
View File

@ -0,0 +1,33 @@
<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = $_POST['id'] ?? null;
$name = $_POST['name'] ?? null;
$description = $_POST['description'] ?? null;
if ($id && $name && $description) {
try {
$pdo = db();
$stmt = $pdo->prepare("UPDATE processes SET name = :name, description = :description WHERE id = :id");
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
$stmt->bindParam(':description', $description, PDO::PARAM_STR);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
if ($stmt->execute()) {
header('Location: index.php?status=success&message=Process updated successfully!');
exit();
} else {
header('Location: edit_process.php?id=' . $id . '&status=error&message=Failed to update process.');
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()));
exit();
}
}
} else {
header('Location: index.php?status=error&message=Invalid request method.');
exit();
}