-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtry.php
More file actions
164 lines (140 loc) · 5.09 KB
/
try.php
File metadata and controls
164 lines (140 loc) · 5.09 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
// notifications_table.php - Run this once to create the notifications table
session_start();
include 'connection.php';
//$conn->query($createNotificationsTable);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Previous head content remains the same -->
<style>
/* Previous styles remain the same */
.request-modal {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
z-index: 1000;
width: 400px;
}
.modal-content {
display: flex;
flex-direction: column;
gap: 15px;
}
.btn-group {
display: flex;
gap: 10px;
justify-content: flex-end;
}
.btn {
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
}
.btn-primary {
background-color: #4CAF50;
color: white;
}
.btn-secondary {
background-color: #f44336;
color: white;
}
.success-message {
background-color: #4CAF50;
color: white;
padding: 10px;
border-radius: 4px;
margin-top: 10px;
display: none;
}
</style>
</head>
<body>
<!-- Previous content remains the same until the table -->
<table>
<!-- Previous table headers remain the same -->
<?php
require_once 'connection.php';
$query = "SELECT * FROM nannytbl";
$stmt = $conn->query($query);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo '<tr class="clickable"
data-email="' . htmlspecialchars($row['Email']) . '"
data-name="' . htmlspecialchars($row['Fullname']) . '"
data-id="' . htmlspecialchars($row['id']) . '">';
// Previous table cells remain the same
echo '</tr>';
}
}
?>
</table>
<!-- Updated Request Modal -->
<div class="request-modal" id="requestModal">
<div class="modal-content">
<h3>Send Request to <span id="nannyName"></span></h3>
<p>Send a hiring request to this nanny. They will be notified when they log in.</p>
<textarea id="requestMessage" placeholder="Add a message (optional)" rows="4" style="width: 100%;"></textarea>
<div class="btn-group">
<button class="btn btn-secondary" onclick="closeModal()">Cancel</button>
<button class="btn btn-primary" onclick="sendRequest()">Send Request</button>
</div>
<div class="success-message" id="successMessage">
Request sent successfully!
</div>
</div>
</div>
<script>
let selectedNanny = null;
document.querySelectorAll('tr.clickable').forEach(row => {
row.addEventListener('click', () => {
selectedNanny = {
id: row.dataset.id,
email: row.dataset.email,
name: row.dataset.name
};
openRequestModal();
});
});
function openRequestModal() {
const modal = document.getElementById('requestModal');
document.getElementById('nannyName').textContent = selectedNanny.name;
modal.style.display = 'block';
}
function closeModal() {
document.getElementById('requestModal').style.display = 'none';
document.getElementById('successMessage').style.display = 'none';
document.getElementById('requestMessage').value = '';
}
async function sendRequest() {
const message = document.getElementById('requestMessage').value;
const parentId = <?php echo isset($_SESSION['user_id']) ? $_SESSION['user_id'] : '0'; ?>;
const parentName = <?php echo isset($_SESSION['name']) ? "'" . $_SESSION['name'] . "'" : "'Unknown'"; ?>;
try {
const response = await fetch('send_request.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `parent_id=${parentId}&parent_name=${parentName}&nanny_id=${selectedNanny.id}&nanny_email=${selectedNanny.email}&message=${encodeURIComponent(message)}`
});
const result = await response.text();
document.getElementById('successMessage').style.display = 'block';
setTimeout(closeModal, 2000);
} catch (error) {
console.error('Error:', error);
alert('Error sending request');
}
}
</script>
</body>
</html>