38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['id'])) {
|
|
$id = filter_var($_POST['id'], FILTER_SANITIZE_NUMBER_INT);
|
|
|
|
try {
|
|
$pdo = db();
|
|
$pdo->beginTransaction();
|
|
|
|
// Delete associated steps first
|
|
$stmtSteps = $pdo->prepare("DELETE FROM process_steps WHERE process_id = :id");
|
|
$stmtSteps->bindParam(':id', $id, PDO::PARAM_INT);
|
|
$stmtSteps->execute();
|
|
|
|
// Then delete the process
|
|
$stmtProcess = $pdo->prepare("DELETE FROM processes WHERE id = :id");
|
|
$stmtProcess->bindParam(':id', $id, PDO::PARAM_INT);
|
|
if ($stmtProcess->execute()) {
|
|
$pdo->commit();
|
|
header('Location: index.php?success=processdeleted');
|
|
exit();
|
|
} else {
|
|
$pdo->rollBack();
|
|
header('Location: index.php?error=deletionfailed');
|
|
exit();
|
|
}
|
|
} catch (PDOException $e) {
|
|
$pdo->rollBack();
|
|
error_log("DB Error: " . $e->getMessage());
|
|
header('Location: index.php?error=dberror');
|
|
exit();
|
|
}
|
|
} else {
|
|
header('Location: index.php?error=invalidrequest');
|
|
exit();
|
|
}
|
|
?>
|