-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_employes.php
298 lines (256 loc) · 10.1 KB
/
add_employes.php
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
// الاتصال بقاعدة البيانات
include 'db_connection.php';
include 'header.php';
// متغير لتخزين رسالة النجاح أو الخطأ
$message = '';
// التحقق من إرسال النموذج
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// التحقق من تعبئة جميع الحقول
if (!empty($_POST['fName']) && !empty($_POST['lName']) && !empty($_POST['salary']) && !empty($_POST['user_id']) && !empty($_POST['hire_date'])) {
$fName = $_POST['fName'];
$lName = $_POST['lName'];
$salary = $_POST['salary'];
$DOB = $_POST['DOB'];
$phone = $_POST['phone'];
$user_id = $_POST['user_id'];
// جلب الدور من جدول المستخدمين بناءً على معرف المستخدم
$sql = "SELECT role, email FROM users WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
$stmt->close();
if ($result->num_rows > 0) {
$user = $result->fetch_assoc();
$role = $user['role']; // الدور من جدول المستخدمين
$email = $user['email']; // تعبئة الإيميل تلقائيًا من جدول المستخدمين
// تحقق إذا كان للمستخدم سجل موظف بالفعل
$check_sql = "SELECT employeeID FROM employees WHERE user_id = ?";
$check_stmt = $conn->prepare($check_sql);
$check_stmt->bind_param("i", $user_id);
$check_stmt->execute();
$check_result = $check_stmt->get_result();
$check_stmt->close();
if ($check_result->num_rows > 0) {
$message = "<div class='alert error' id='message'>المستخدم لديه بالفعل سجل موظف.</div>";
} else {
// إدخال الموظف في جدول الموظفين
$sql = "INSERT INTO employees (fName, lName, role, salary, email, DOB, phone, hire_date, user_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssssssssi", $fName, $lName, $role, $salary, $email, $DOB, $phone, $_POST['hire_date'], $user_id);
$stmt->execute();
if ($stmt->affected_rows > 0) {
$message = "<div class='alert success' id='message'>Employee added successfully</div>";
} else {
$message = "<div class='alert error' id='message'>Error: " . $conn->error . "</div>";
}
$stmt->close();
}
} else {
$message = "<div class='alert error' id='message'>User not found!!</div>";
}
} else {
$message = "<div class='alert error' id='message'>Please fill in all fields!!</div>";
}
// إعادة التوجيه بعد عرض الرسالة (بغض النظر عن النتيجة)
header("Refresh: 1; url=".$_SERVER['PHP_SELF']);
}
// جلب المستخدمين الذين لديهم أدوار Doctor, Caregiver, Supervisor, admin
$sql = "SELECT id, name FROM users WHERE role IN ('Doctor', 'Caregiver', 'Supervisor', 'admin')";
$result = $conn->query($sql);
?>
<?php //TEMPLATES
include 'templates_html/header.html';
if (isset($_SESSION['user_role'])) {
switch ($_SESSION['user_role']) {
case 'admin':
include 'templates_html/main-grid-content-2columns.html';
include 'templates_html/admin-side-bar.html';
default:
include 'templates_html/alert-dashboard.php';
include 'templates_html/admin.html';
include 'templates_html/main-grid-content-1column.html';
}
} else {
include 'templates_html/main-grid-content-1column.html';
}
include 'templates_html/main-content.html';
?>
<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add_New_Employee</title>
<link rel="stylesheet" href="style.css"> <!-- إضافة ملف CSS هنا -->
<style>
body {
font-family: Arial, sans-serif;
margin: 40px;
background-color: #f4f4f4;
}
h1 {
margin-bottom: 20px;
text-align: center;
}
.container {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
padding: 30px;
width: 400px; /* Increased the width */
max-width: 90%;
margin: auto;
}
input[type="text"],
input[type="number"],
input[type="date"],
select,
input[type="email"],
button {
width: 95%; /* Slightly increased width for better centering */
padding: 12px;
margin: 10px auto;
display: block;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
box-sizing: border-box; /* Ensures padding is included in the width */
}
button {
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
font-size: 18px;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
label {
font-weight: bold;
font-size: 18px;
margin-bottom: 10px; /* Reduced margin */
display: block; /* Ensure labels are block elements for better spacing */
}
.alert {
padding: 10px;
border-radius: 4px;
margin-bottom: 20px;
text-align: center;
}
.success {
background-color: #d4edda;
color: #155724;
}
.error {
background-color: #f8d7da;
color: #721c24;
}
.primary-btn {
background-color: #007bff;
color: white;
border: none;
padding: 12px;
font-size: 18px;
cursor: pointer;
width: 100%;
margin-top: 10px;
border-radius: 4px;
}
.primary-btn:hover {
background-color: #0056b3;
}
.link-btn {
display: inline-block;
background-color: #28a745;
color: white;
text-decoration: none;
padding: 12px;
font-size: 18px;
text-align: center;
border-radius: 4px;
width: 100%; /* Make the link button full width */
margin-top: 8px;
}
.link-btn:hover {
background-color: #218838;
}
</style>
</head>
<body>
<div class="container">
<h1>New_Employee</h1>
<hr>
<?php if ($message): ?>
<?php echo $message; ?>
<script>
// إخفاء الرسالة بعد 7 ثوانٍ
setTimeout(function() {
var message = document.getElementById('message');
if (message) {
message.style.display = 'none';
}
}, 7000);
</script>
<?php endif; ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<label for="user_id">Select_User:</label>
<select name="user_id" id="user_id" required>
<option value="">----------</option>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<option value='" . $row['id'] . "'>" . $row['name'] . "</option>";
}
} else {
echo "<option value=''>No users available!!</option>";
}
?>
</select>
<label for="fName">fName:</label>
<input type="text" name="fName" placeholder="fName" required>
<label for="lName">lName:</label>
<input type="text" name="lName" placeholder="lName" required>
<label for="salary">Salary:</label>
<input type="number" name="salary" placeholder="salary" required>
<label for="DOB">DOB:</label>
<input type="date" name="DOB" required>
<label for="phone">Contact_NO:</label>
<input type="text" name="phone" placeholder=" Contact_NO" required>
<label for="email"> Email_Address:</label>
<input type="email" id="email" name="email" placeholder="Email_Address " readonly required>
<label for="hire_date"> Hire_date:</label>
<input type="date" name="hire_date" required><br>
<hr>
<button type="submit" class="primary-btn">Add_New_Employee</button>
<a href="taske_dashboard.php" class="link-btn">Go to Control Panel</a>
</form>
<script>
// عند تغيير المستخدم المختار، تعبئة البريد الإلكتروني تلقائيًا
document.getElementById('user_id').addEventListener('change', function () {
var userId = this.value;
if (userId) {
// إجراء طلب لجلب البريد الإلكتروني من الخادم
var xhr = new XMLHttpRequest();
xhr.open('GET', 'get_email.php?user_id=' + userId, true);
xhr.onload = function () {
if (xhr.status === 200) {
document.getElementById('email').value = xhr.responseText;
}
};
xhr.send();
} else {
document.getElementById('email').value = '';
}
});
</script>
</div>
</body>
</html>
<?php // TEMPLATES
include 'templates_html/end-main-content.html';
include 'templates_html/footer.html';
?>