75 lines
2.0 KiB
PHP
75 lines
2.0 KiB
PHP
<?php
|
|
require_once 'includes/header.php';
|
|
require_once 'db/config.php';
|
|
require_once 'docuseal/config.php';
|
|
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'client') {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$client_id = $_SESSION['user_id'];
|
|
|
|
// Fetch client's email
|
|
$stmt = db()->prepare('SELECT email FROM clients WHERE id = ?');
|
|
$stmt->execute([$client_id]);
|
|
$client = $stmt->fetch();
|
|
|
|
if (!$client) {
|
|
// Client not found
|
|
header('Location: dashboard.php');
|
|
exit;
|
|
}
|
|
|
|
// Fetch the latest contract
|
|
$stmt = db()->query('SELECT * FROM contracts ORDER BY created_at DESC LIMIT 1');
|
|
$contract = $stmt->fetch();
|
|
|
|
if (!$contract) {
|
|
// No contract found, so redirect to dashboard
|
|
header('Location: dashboard.php');
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$submission = $docuseal->submissions->create([
|
|
'template_id' => DOCUSEAL_TEMPLATE_ID,
|
|
'submitters' => [
|
|
[
|
|
'email' => $client['email'],
|
|
'role' => $contract['role']
|
|
]
|
|
],
|
|
'custom_fields' => [
|
|
['name' => 'contract_content', 'value' => $contract['content']]
|
|
]
|
|
]);
|
|
|
|
// Store the submission ID
|
|
$stmt = db()->prepare('INSERT INTO client_contracts (client_id, contract_id, docuseal_submission_id) VALUES (?, ?, ?)');
|
|
$stmt->execute([$client_id, $contract['id'], $submission['id']]);
|
|
|
|
} catch (Exception $e) {
|
|
// Handle API errors
|
|
echo 'Error creating DocuSeal submission: ' . $e->getMessage();
|
|
exit;
|
|
}
|
|
|
|
?>
|
|
|
|
<div class="container mt-5">
|
|
<h2>Sign Your Contract</h2>
|
|
<p>Please review and sign the following contract to complete your registration.</p>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3><?php echo htmlspecialchars($contract['title']); ?></h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<iframe src="<?php echo $submission['url']; ?>" width="100%" height="800px" frameborder="0"></iframe>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|