35632-vm/workflows.php
2025-11-20 03:49:15 +00:00

172 lines
9.8 KiB
PHP

<?php
require_once 'auth.php';
// Check if user is logged in
if (!is_logged_in()) {
header('Location: login.php');
exit;
}
if (!hasPermission('view_workflows')) {
// Optionally, you can redirect to a generic page or show an error.
// For now, redirecting to the main index page.
header('Location: index.php');
exit;
}
require_once 'db/config.php';
$pdo = db();
// Handle form submission for adding a new workflow
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_workflow'])) {
if (hasPermission('manage_workflows')) {
$name = $_POST['name'] ?? '';
$trigger = $_POST['trigger'] ?? '';
if ($name && $trigger) {
$stmt = $pdo->prepare("INSERT INTO workflows (name, trigger_event) VALUES (?, ?)");
$stmt->execute([$name, $trigger]);
$newWorkflowId = $pdo->lastInsertId();
header("Location: workflow_actions.php?id=" . $newWorkflowId);
exit;
}
}
}
// Fetch workflows from the database
$stmt = $pdo->query("SELECT * FROM workflows ORDER BY created_at DESC");
$workflows = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FinMox Workflows</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-50">
<div id="workflows-page" class="min-h-screen p-8">
<div class="max-w-7xl mx-auto">
<!-- Header -->
<div class="flex items-center justify-between mb-8">
<div>
<h1 class="text-3xl font-bold text-gray-900">Your Automation Workflows</h1>
<p class="text-gray-600 mt-1">Click any workflow to view and edit its actions</p>
</div>
<?php if (hasPermission('manage_workflows')): ?>
<button onclick="openModal('addWorkflowModal')" class="bg-blue-600 text-white px-6 py-3 rounded-lg font-semibold hover:bg-blue-700 flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path></svg>
Create New Workflow
</button>
<?php endif; ?>
</div>
<!-- Workflow Cards Grid -->
<div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
<?php if (empty($workflows)): ?>
<!-- Static Example Cards when no workflows exist -->
<div class="bg-white rounded-xl shadow-sm border-2 border-gray-200">
<div class="p-6">
<div class="flex items-center gap-3 mb-4">
<div class="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center"><svg class="w-6 h-6 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"></path></svg></div>
<div><h3 class="text-lg font-bold text-gray-900">Smart Candidate Intake</h3></div>
</div>
<p class="text-gray-600">Automatically captures, enriches, and routes new candidates.</p>
</div>
</div>
<div class="bg-white rounded-xl shadow-sm border-2 border-gray-200">
<div class="p-6">
<div class="flex items-center gap-3 mb-4">
<div class="w-12 h-12 bg-green-100 rounded-lg flex items-center justify-center"><svg class="w-6 h-6 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"></path></svg></div>
<div><h3 class="text-lg font-bold text-gray-900">Interview Scheduling</h3></div>
</div>
<p class="text-gray-600">Automates calendar checks and interview coordination.</p>
</div>
</div>
<div class="bg-white rounded-xl shadow-sm border-2 border-gray-200">
<div class="p-6">
<div class="flex items-center gap-3 mb-4">
<div class="w-12 h-12 bg-purple-100 rounded-lg flex items-center justify-center"><svg class="w-6 h-6 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path></svg></div>
<div><h3 class="text-lg font-bold text-gray-900">Onboarding Automation</h3></div>
</div>
<p class="text-gray-600">Creates and tracks onboarding tasks for new hires.</p>
</div>
</div>
<?php else: ?>
<?php foreach ($workflows as $workflow): ?>
<a href="workflow_actions.php?id=<?php echo $workflow['id']; ?>" class="block bg-white rounded-xl shadow-sm border-2 border-gray-200 hover:border-blue-500 hover:shadow-lg transition-all">
<div class="p-6">
<div class="flex items-start justify-between mb-4">
<div class="flex items-center gap-3">
<div class="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center">
<svg class="w-6 h-6 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h6m-6 4h6m-6 4h6"></path></svg>
</div>
<div>
<h3 class="text-lg font-bold text-gray-900"><?php echo htmlspecialchars($workflow['name']); ?></h3>
<span class="inline-block px-2 py-1 bg-green-100 text-green-700 text-xs font-semibold rounded mt-1">Active</span>
</div>
</div>
</div>
<p class="text-gray-600">
Trigger: <strong><?php echo htmlspecialchars(str_replace('_', ' ', ucfirst($workflow['trigger_event']))); ?></strong>
</p>
</div>
</a>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
<!-- Add Workflow Modal -->
<div id="addWorkflowModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full hidden">
<div class="relative top-20 mx-auto p-5 border w-full max-w-md shadow-lg rounded-md bg-white">
<div class="flex justify-between items-center pb-3">
<p class="text-2xl font-bold">Create New Workflow</p>
<div class="cursor-pointer z-50" onclick="closeModal('addWorkflowModal')">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
</div>
</div>
<form method="POST">
<input type="hidden" name="add_workflow" value="1">
<div class="mb-4">
<label for="name" class="block text-gray-700 text-sm font-bold mb-2">Workflow Name</label>
<input type="text" id="name" name="name" required class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
<div class="mb-6">
<label for="trigger" class="block text-gray-700 text-sm font-bold mb-2">Trigger</label>
<select id="trigger" name="trigger" required class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
<option value="" disabled selected>Select a trigger</option>
<option value="candidate_created">New Candidate is Created</option>
<option value="task_completed">Task is Completed</option>
</select>
</div>
<div class="flex items-center justify-end">
<button type="button" onclick="closeModal('addWorkflowModal')" class="bg-gray-200 text-gray-800 font-bold py-2 px-4 rounded hover:bg-gray-300 mr-2">
Cancel
</button>
<button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Save Workflow
</button>
</div>
</form>
</div>
</div>
<script>
function openModal(modalId) {
document.getElementById(modalId).classList.remove('hidden');
}
function closeModal(modalId) {
document.getElementById(modalId).classList.add('hidden');
}
</script>
</body>
</html>