beginTransaction(); // Clear existing job statuses for this company to avoid duplicates on re-submission $stmt = $pdo->prepare("DELETE FROM job_statuses WHERE company_id = ?"); $stmt->execute([$company_id]); $insert_stmt = $pdo->prepare("INSERT INTO job_statuses (company_id, name, is_default) VALUES (?, ?, ?)"); foreach ($statuses as $index => $status_name) { $is_default = (int)($index == $default_status_index); // Explicitly cast to int (0 or 1) $insert_stmt->execute([$company_id, $status_name, $is_default]); } $pdo->commit(); header('Location: onboarding.php?step=2&message=Job statuses saved successfully!&message_type=success'); exit(); } catch (PDOException $e) { $pdo->rollBack(); $message = 'Error saving job statuses: ' . $e->getMessage(); $message_type = 'error'; } } } elseif ($step === 2) { // Handle Required Job Folder Setup submission $folders = $_POST['folders'] ?? []; if (empty($folders)) { $message = 'Please add at least one required folder.'; $message_type = 'error'; } else { try { $pdo = db(); $pdo->beginTransaction(); // Clear existing job folders for this company $stmt = $pdo->prepare("DELETE FROM job_folders WHERE company_id = ? AND is_required = TRUE"); $stmt->execute([$company_id]); $insert_stmt = $pdo->prepare("INSERT INTO job_folders (company_id, name, is_required) VALUES (?, ?, TRUE)"); foreach ($folders as $folder_name) { $insert_stmt->execute([$company_id, $folder_name]); } // Mark onboarding as complete $stmt = $pdo->prepare("UPDATE companies SET onboarding_complete = TRUE WHERE id = ?"); $stmt->execute([$company_id]); $pdo->commit(); header('Location: index.php?message=Onboarding complete!&message_type=success'); exit(); } catch (PDOException $e) { $pdo->rollBack(); $message = 'Error saving job folders: ' . $e->getMessage(); $message_type = 'error'; } } } } // Get messages from URL for display if (isset($_GET['message'])) { $message = htmlspecialchars($_GET['message']); $message_type = htmlspecialchars($_GET['message_type'] ?? ''); } ?>
Define the different statuses a job can have within your company. One status must be set as default.
Define folders that will automatically appear on every job. These cannot be deleted by users.