50 lines
1.7 KiB
PHP
50 lines
1.7 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
// Basic validation
|
|
if (empty(trim($_POST['name'])) || empty(trim($_POST['description']))) {
|
|
// Redirect back with an error message if needed, but for now we just exit.
|
|
header('Location: index.php?error=emptyfields');
|
|
exit;
|
|
}
|
|
|
|
$name = trim($_POST['name']);
|
|
$description = trim($_POST['description']);
|
|
|
|
try {
|
|
$pdo = db();
|
|
$sql = "INSERT INTO processes (name, description) VALUES (?, ?)";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([$name, $description]);
|
|
|
|
$process_id = $pdo->lastInsertId();
|
|
|
|
// Insert process steps if available
|
|
if (isset($_POST['steps']) && is_array($_POST['steps'])) {
|
|
$step_order = 0;
|
|
$stmt_steps = $pdo->prepare("INSERT INTO process_steps (process_id, title, description, step_order) VALUES (?, ?, ?, ?)");
|
|
foreach ($_POST['steps'] as $step) {
|
|
if (isset($step['title']) && isset($step['description'])) {
|
|
$stmt_steps->execute([$process_id, $step['title'], $step['description'], $step_order]);
|
|
$step_order++;
|
|
}
|
|
}
|
|
}
|
|
} catch (PDOException $e) {
|
|
// In a real app, log this error. For now, we'll just die.
|
|
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=processadded');
|
|
exit;
|
|
} else {
|
|
// If not a POST request, redirect to the main page
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
?>
|