Repository navigation
Expand file tree
/
Copy pathprocess_project_response.php
More file actions
77 lines (67 loc) · 2.64 KB
/
Copy pathprocess_project_response.php
File metadata and controls
77 lines (67 loc) · 2.64 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
72
73
74
75
76
77
<?php
require_once 'includes/session_config.php';
include 'conn.php';
// Check if user is logged in
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'freelancer') {
header("Location: signin.php");
exit();
}
$user_id = $_SESSION['user_id'];
$action = isset($_GET['action']) ? $_GET['action'] : '';
$project_id = isset($_GET['project_id']) ? intval($_GET['project_id']) : 0;
$bid_amount = isset($_GET['bid_amount']) ? floatval($_GET['bid_amount']) : 0;
if (empty($action) || $project_id <= 0) {
header("Location: home_user.php");
exit();
}
// Verify the project assignment exists for this freelancer
$check_sql = "SELECT * FROM project_assignments WHERE project_id = ? AND freelancer_id = ?";
$check_stmt = $conn->prepare($check_sql);
$check_stmt->bind_param("ii", $project_id, $user_id);
$check_stmt->execute();
$result = $check_stmt->get_result();
if ($result->num_rows === 0) {
// Project not assigned to this freelancer
header("Location: home_user.php");
exit();
}
// Process the action
// In the accept action section
if ($action === 'accept') {
// Get the bid amount from the bids table if not provided in URL
if ($bid_amount <= 0) {
$bid_sql = "SELECT bid_amount FROM bids WHERE project_id = ? AND user_id = ? ORDER BY bid_date DESC LIMIT 1";
$bid_stmt = $conn->prepare($bid_sql);
$bid_stmt->bind_param("ii", $project_id, $user_id);
$bid_stmt->execute();
$bid_result = $bid_stmt->get_result();
if ($bid_result->num_rows > 0) {
$bid_data = $bid_result->fetch_assoc();
$bid_amount = $bid_data['bid_amount'];
}
}
// Update project_assignments table with bid amount
$update_sql = "UPDATE project_assignments
SET is_accepted = 1,
is_rejected = 0,
is_read = 1,
bid_amount = ?,
response_date = CURRENT_TIMESTAMP
WHERE project_id = ? AND freelancer_id = ?";
$update_stmt = $conn->prepare($update_sql);
$update_stmt->bind_param("dii", $bid_amount, $project_id, $user_id);
$update_stmt->execute();
// Update project status to "In Progress"
$project_sql = "UPDATE projects SET status = 'On Progress' WHERE id = ?";
$project_stmt = $conn->prepare($project_sql);
$project_stmt->bind_param("i", $project_id);
$project_stmt->execute();
if (isset($_GET['redirect']) && $_GET['redirect'] === 'communication') {
header("Location: project_communication.php?id=" . $project_id);
exit();
} else {
header("Location: home_user.php");
exit();
}
}
?>