173 lines
9.5 KiB
PHP
173 lines
9.5 KiB
PHP
<?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) {
|
|
$stmt_steps = $pdo->prepare("SELECT id, title, description, step_order FROM process_steps WHERE process_id = :process_id ORDER BY step_order ASC");
|
|
$stmt_steps->bindParam(':process_id', $id, PDO::PARAM_INT);
|
|
$stmt_steps->execute();
|
|
$process['steps'] = $stmt_steps->fetchAll(PDO::FETCH_ASSOC);
|
|
} else {
|
|
$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>
|
|
|
|
<hr class="my-4">
|
|
<h5 class="fw-bold mb-3">Process Steps</h5>
|
|
<div id="processStepsContainer">
|
|
<?php if (!empty($process['steps'])): ?>
|
|
<?php foreach ($process['steps'] as $index => $step): ?>
|
|
<div class="mb-3 p-3 border rounded bg-light position-relative process-step-item">
|
|
<input type="hidden" name="steps[<?php echo $index; ?>][id]" value="<?php echo htmlspecialchars($step['id']); ?>">
|
|
<div class="mb-2">
|
|
<label for="stepTitle_<?php echo $index; ?>" class="form-label fw-bold">Step <?php echo $index + 1; ?> Title</label>
|
|
<input type="text" class="form-control" id="stepTitle_<?php echo $index; ?>" name="steps[<?php echo $index; ?>][title]" value="<?php echo htmlspecialchars($step['title']); ?>" required>
|
|
</div>
|
|
<div>
|
|
<label for="stepDescription_<?php echo $index; ?>" class="form-label">Step <?php echo $index + 1; ?> Description</label>
|
|
<textarea class="form-control" id="stepDescription_<?php echo $index; ?>" name="steps[<?php echo $index; ?>][description]" rows="2" required><?php echo htmlspecialchars($step['description']); ?></textarea>
|
|
</div>
|
|
<button type="button" class="btn btn-sm btn-danger position-absolute top-0 end-0 mt-2 me-2 remove-step-btn" title="Remove Step">
|
|
<i data-feather="x" style="width: 16px; height: 16px;"></i>
|
|
</button>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
<button type="button" id="addStepBtn" class="btn btn-outline-secondary btn-sm mb-4">
|
|
<i data-feather="plus" style="width: 16px; height: 16px;"></i> Add New Step
|
|
</button>
|
|
|
|
<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>© <?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()
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const processStepsContainer = document.getElementById('processStepsContainer');
|
|
const addStepBtn = document.getElementById('addStepBtn');
|
|
|
|
let stepIndex = processStepsContainer.children.length; // Start index after existing steps
|
|
|
|
function updateStepNumbers() {
|
|
Array.from(processStepsContainer.children).forEach((stepItem, index) => {
|
|
stepItem.querySelector('label[for^="stepTitle_"]').textContent = `Step ${index + 1} Title`;
|
|
stepItem.querySelector('label[for^="stepDescription_"]').textContent = `Step ${index + 1} Description`;
|
|
|
|
// Update name attributes for proper form submission
|
|
stepItem.querySelector('input[name$="[title]"]').name = `steps[${index}][title]`;
|
|
stepItem.querySelector('textarea[name$="[description]"]').name = `steps[${index}][description]`;
|
|
const hiddenIdInput = stepItem.querySelector('input[name$="[id]"]');
|
|
if (hiddenIdInput) {
|
|
hiddenIdInput.name = `steps[${index}][id]`;
|
|
}
|
|
});
|
|
}
|
|
|
|
addStepBtn.addEventListener('click', function() {
|
|
const newStepHtml = `
|
|
<div class="mb-3 p-3 border rounded bg-light position-relative process-step-item">
|
|
<div class="mb-2">
|
|
<label for="stepTitle_${stepIndex}" class="form-label fw-bold">Step ${stepIndex + 1} Title</label>
|
|
<input type="text" class="form-control" id="stepTitle_${stepIndex}" name="steps[${stepIndex}][title]" required>
|
|
</div>
|
|
<div>
|
|
<label for="stepDescription_${stepIndex}" class="form-label">Step ${stepIndex + 1} Description</label>
|
|
<textarea class="form-control" id="stepDescription_${stepIndex}" name="steps[${stepIndex}][description]" rows="2" required></textarea>
|
|
</div>
|
|
<button type="button" class="btn btn-sm btn-danger position-absolute top-0 end-0 mt-2 me-2 remove-step-btn" title="Remove Step">
|
|
<i data-feather="x" style="width: 16px; height: 16px;"></i>
|
|
</button>
|
|
</div>
|
|
`;
|
|
processStepsContainer.insertAdjacentHTML('beforeend', newStepHtml);
|
|
feather.replace(); // Re-render feather icons for new button
|
|
stepIndex++;
|
|
updateStepNumbers();
|
|
});
|
|
|
|
processStepsContainer.addEventListener('click', function(event) {
|
|
if (event.target.closest('.remove-step-btn')) {
|
|
event.target.closest('.process-step-item').remove();
|
|
updateStepNumbers();
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|