forked from jancchi/HM26
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrematch.php
More file actions
71 lines (62 loc) · 1.97 KB
/
rematch.php
File metadata and controls
71 lines (62 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
session_start();
require_once 'db.php';
require_once 'config.php';
require_once 'integrations.php';
if (!isset($_SESSION['admin_logged_in'])) {
header('Location: admin.php');
exit;
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: admin.php');
exit;
}
$requestId = (int) ($_POST['request_id'] ?? 0);
if ($requestId <= 0) {
header('Location: admin.php');
exit;
}
try {
$requestStmt = $pdo->prepare(
'SELECT id, title, category, role, description, city, urgency, help_type, tags_text
FROM requests
WHERE id = :id
LIMIT 1'
);
$requestStmt->execute([':id' => $requestId]);
$request = $requestStmt->fetch();
if (!$request) {
header('Location: admin.php');
exit;
}
$offersStmt = $pdo->query(
'SELECT id, full_name, role, skills_description, category, city
FROM offers
WHERE active = 1
ORDER BY created_at DESC
LIMIT 50'
);
$allOffers = $offersStmt->fetchAll();
$matches = [];
if (!empty($allOffers)) {
$matches = matchRequestToOffers([
'title' => (string) ($request['title'] ?? ''),
'category' => (string) ($request['category'] ?? ''),
'role' => (string) ($request['role'] ?? ''),
'description' => (string) ($request['description'] ?? ''),
'city' => (string) ($request['city'] ?? ''),
'urgency' => (string) ($request['urgency'] ?? ''),
'help_type' => (string) ($request['help_type'] ?? ''),
'tags_text' => (string) ($request['tags_text'] ?? ''),
], $allOffers);
}
$updateStmt = $pdo->prepare('UPDATE requests SET ai_matches = :m WHERE id = :id');
$updateStmt->execute([
':m' => !empty($matches) ? json_encode($matches, JSON_UNESCAPED_UNICODE) : null,
':id' => $requestId,
]);
} catch (Exception $e) {
}
header('Location: matches.php?id=' . urlencode((string) $requestId));
exit;
?>