230 lines
11 KiB
PHP
230 lines
11 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')) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
|
|
if (!isset($_GET['workflow_id'])) {
|
|
header('Location: workflows.php');
|
|
exit;
|
|
}
|
|
|
|
$workflow_id = $_GET['workflow_id'];
|
|
$pdo = db();
|
|
|
|
// Fetch workflow details
|
|
$stmt = $pdo->prepare("SELECT * FROM workflows WHERE id = ?");
|
|
$stmt->execute([$workflow_id]);
|
|
$workflow = $stmt->fetch();
|
|
|
|
if (!$workflow) {
|
|
header('Location: workflows.php');
|
|
exit;
|
|
}
|
|
|
|
// Handle form submission for new action
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_action']) && hasPermission('manage_workflows')) {
|
|
$action_type = $_POST['action_type'] ?? '';
|
|
$config = [];
|
|
|
|
if ($action_type === 'send_email') {
|
|
$config['to'] = $_POST['to'] ?? '';
|
|
$config['subject'] = $_POST['subject'] ?? '';
|
|
$config['message'] = $_POST['message'] ?? '';
|
|
} elseif ($action_type === 'create_task') {
|
|
$config['task_name'] = $_POST['task_name'] ?? '';
|
|
$config['assign_to'] = $_POST['assign_to'] ?? '';
|
|
} elseif ($action_type === 'send_slack_notification') {
|
|
$config['webhook_url'] = $_POST['webhook_url'] ?? '';
|
|
$config['message'] = $_POST['slack_message'] ?? '';
|
|
} elseif ($action_type === 'update_candidate_status') {
|
|
$config['new_status'] = $_POST['new_status'] ?? '';
|
|
}
|
|
|
|
if (!empty($action_type)) {
|
|
try {
|
|
$stmt = $pdo->prepare("INSERT INTO workflow_actions (workflow_id, action_type, config) VALUES (?, ?, ?)");
|
|
$stmt->execute([$workflow_id, $action_type, json_encode($config)]);
|
|
header("Location: " . $_SERVER['REQUEST_URI']);
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
error_log("Error adding action: " . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fetch actions for the workflow
|
|
$stmt = $pdo->prepare("SELECT * FROM workflow_actions WHERE workflow_id = ? ORDER BY created_at DESC");
|
|
$stmt->execute([$workflow_id]);
|
|
$actions = $stmt->fetchAll();
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Workflow Actions</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
<header class="header d-flex justify-content-between align-items-center">
|
|
<div class="logo">FinMox<span class="dot">.</span></div>
|
|
<nav class="d-flex align-items-center">
|
|
<a href="index.php" class="btn btn-outline-primary me-2">Home</a>
|
|
<a href="chat.php" class="btn btn-outline-primary me-2">Chat</a>
|
|
<a href="dashboard.php" class="btn btn-outline-primary me-2">Dashboard</a>
|
|
<a href="workflows.php" class="btn btn-outline-primary me-3">Workflows</a>
|
|
<div class="dropdown">
|
|
<button class="btn btn-outline-secondary dropdown-toggle" type="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<?php echo htmlspecialchars($_SESSION['username']); ?>
|
|
</button>
|
|
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
|
|
<?php if (hasPermission('manage_roles')): ?>
|
|
<li><a class="dropdown-item" href="roles.php">Manage Roles</a></li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<?php endif; ?>
|
|
<li><a class="dropdown-item" href="logout.php">Logout</a></li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
|
|
<main class="container-fluid">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2>Actions for "<?php echo htmlspecialchars($workflow['name']); ?>"</h2>
|
|
<?php if (hasPermission('manage_workflows')): ?>
|
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addActionModal">Add Action</button>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Action Type</th>
|
|
<th>Configuration</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($actions as $action): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($action['action_type']); ?></td>
|
|
<td><pre><?php echo htmlspecialchars(json_encode(json_decode($action['config']), JSON_PRETTY_PRINT)); ?></pre></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<!-- Add Action Modal -->
|
|
<div class="modal fade" id="addActionModal" tabindex="-1" aria-labelledby="addActionModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="addActionModalLabel">Add New Action</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form method="POST">
|
|
<input type="hidden" name="add_action" value="1">
|
|
<div class="mb-3">
|
|
<label for="action_type" class="form-label">Action Type</label>
|
|
<select class="form-select" id="action_type" name="action_type" required onchange="showActionConfig(this.value)">
|
|
<option value="" disabled selected>Select an action</option>
|
|
<option value="send_email">Send Email</option>
|
|
<option value="create_task">Create Task</option>
|
|
<option value="send_slack_notification">Send Slack Notification</option>
|
|
<option value="update_candidate_status">Update Candidate Status</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div id="send_email_config" style="display: none;">
|
|
<div class="mb-3">
|
|
<label for="to" class="form-label">To</label>
|
|
<input type="email" class="form-control" id="to" name="to">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="subject" class="form-label">Subject</label>
|
|
<input type="text" class="form-control" id="subject" name="subject">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="message" class="form-label">Message</label>
|
|
<textarea class="form-control" id="message" name="message" rows="3"></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="create_task_config" style="display: none;">
|
|
<div class="mb-3">
|
|
<label for="task_name" class="form-label">Task Name</label>
|
|
<input type="text" class="form-control" id="task_name" name="task_name">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="assign_to" class="form-label">Assign To</label>
|
|
<input type="text" class="form-control" id="assign_to" name="assign_to" placeholder="Candidate ID or '{{candidate.id}}'">
|
|
</div>
|
|
</div>
|
|
|
|
<div id="send_slack_notification_config" style="display: none;">
|
|
<div class="mb-3">
|
|
<label for="webhook_url" class="form-label">Slack Webhook URL</label>
|
|
<input type="text" class="form-control" id="webhook_url" name="webhook_url">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="slack_message" class="form-label">Message</label>
|
|
<textarea class="form-control" id="slack_message" name="slack_message" rows="3"></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="update_candidate_status_config" style="display: none;">
|
|
<div class="mb-3">
|
|
<label for="new_status" class="form-label">New Status</label>
|
|
<select class="form-select" id="new_status" name="new_status">
|
|
<option value="Applied">Applied</option>
|
|
<option value="Interviewing">Interviewing</option>
|
|
<option value="Offered">Offered</option>
|
|
<option value="Hired">Hired</option>
|
|
<option value="Rejected">Rejected</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
<button type="submit" class="btn btn-primary">Save Action</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
function showActionConfig(actionType) {
|
|
document.getElementById('send_email_config').style.display = 'none';
|
|
document.getElementById('create_task_config').style.display = 'none';
|
|
document.getElementById('send_slack_notification_config').style.display = 'none';
|
|
document.getElementById('update_candidate_status_config').style.display = 'none';
|
|
|
|
if (actionType) {
|
|
document.getElementById(actionType + '_config').style.display = 'block';
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|