-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddClient.php
More file actions
executable file
·367 lines (319 loc) · 18.4 KB
/
addClient.php
File metadata and controls
executable file
·367 lines (319 loc) · 18.4 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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?php
session_start();
$errorMessage = "";
$successMessage = "";
$conn = require __DIR__ . "/database.php";
session_start();
if (!isset($_SESSION["email"])) {
// Redirect to the login page if the user is not logged in
header('Location: index.php');
exit();
}
$email = mysqli_real_escape_string($conn, $_SESSION['email']);
$query = "SELECT * FROM account WHERE email='$email'";
$result = mysqli_query($conn, $query);
if ($row = mysqli_fetch_assoc($result)) {
$name = $row['userName'];
$password = $row['password'];
$phone = $row['phoneNum'];
$role = $row['role'];
} else {
// Handle case where email is not found in the database
$name = '';
$password = '';
$phone = '';
$role = '';
}
if ($_SERVER["REQUEST_METHOD"] === "POST") {
if (empty($_POST["fullName"]) || empty($_POST["address"]) || empty($_POST["id"]) || empty($_POST["gender"]) || empty($_POST["phoneNumber"])) {
$errorMessage = "שדה חובה ריק";
} else if (!is_numeric($_POST["id"])) {
$errorMessage = "מספר זיהוי חייב להיות מספר";
} else if (!empty($_POST["email"]) && (!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL))) {
$errorMessage = "אימייל לא חוקי";
} else if ($_POST['gender'] === "בחר/י") {
$errorMessage = 'צריך לציין את המין.<br>';
} else {
$fullName = $_POST['fullName'];
$adress = $_POST['address'];
$id = $_POST['id'];
$gender = $_POST['gender'];
$phoneNumber = $_POST['phoneNumber'];
$phoneNumber2 = $_POST['phoneNumber2'];
$email = $_POST['email'];
$stmt = $conn->prepare("insert into client(fullName, address, id, gender, phone, phone2, email) values(?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssss", $fullName, $adress, $id, $gender, $phoneNumber, $phoneNumber2, $email);
try {
$execval = $stmt->execute();
if ($execval) {
$successMessage = "הלקוח נקלט בהצלחה";
}
} catch (mysqli_sql_exception $e) {
if ($e->getCode() === 1062) { // Error code for duplicate entry
$errorMessage = "כנראה שהלקוח כבר קיים במערכת";
} else {
$errorMessage = "Error: " . $e->getMessage();
}
}
$stmt->close();
$conn->close();
}
// Store the messages in session variables
$_SESSION["successMessage"] = $successMessage;
$_SESSION["errorMessage"] = $errorMessage;
// Redirect to the same page to prevent re-submission
header("Location: " . $_SERVER['REQUEST_URI']);
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>DASHMIN - Bootstrap Admin Template</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta content="" name="keywords">
<meta content="" name="description">
<!-- Favicon -->
<link href="img/favicon.ico" rel="icon">
<!-- Google Web Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Heebo:wght@400;500;600;700&display=swap" rel="stylesheet">
<!-- Icon Font Stylesheet -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.0/css/all.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.1/font/bootstrap-icons.css" rel="stylesheet">
<!-- Libraries Stylesheet -->
<link href="lib/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet">
<link href="lib/tempusdominus/css/tempusdominus-bootstrap-4.min.css" rel="stylesheet" />
<!-- Customized Bootstrap Stylesheet -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Template Stylesheet -->
<link href="css/style.css" rel="stylesheet">
<style>
.custom-form {
display: flex;
justify-content: center;
}
.custom-form-container {
max-width: 500px;
width: 100%;
direction: rtl;
text-align: right;
}
.custom-form .form-floating {
text-align: right;
}
</style>
</head>
<body>
<div class="container-xxl position-relative bg-white d-flex p-0">
<!-- Spinner Start -->
<div id="spinner" class="show bg-white position-fixed translate-middle w-100 vh-100 top-50 start-50 d-flex align-items-center justify-content-center">
<div class="spinner-border text-primary" style="width: 3rem; height: 3rem;" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<!-- Spinner End -->
<!-- Sidebar Start -->
<div class="sidebar pe-4 pb-3">
<nav class="navbar bg-light navbar-light">
<a href="index.php" class="navbar-brand mx-4 mb-3">
<h3 class="text-primary">אבו <?php echo $name ?></h3>
<h3 class="text-primary"><i class="fa fa-hashtag me-2"></i>BUILD-TECH</h3>
</a>
<div class="d-flex align-items-center ms-4 mb-4">
<div class="position-relative">
<img class="rounded-circle" src="img/user.jpg" alt="" style="width: 40px; height: 40px;">
<div class="bg-success rounded-circle border border-2 border-white position-absolute end-0 bottom-0 p-1"></div>
</div>
<div class="ms-3">
<h6 class="mb-0"><?php echo $name ?></h6>
<span><?php echo $role ?></span>
</div>
</div>
<div class="navbar-nav w-100" style="float:right;">
<a href="home.php" class="nav-item nav-link "><i class="fa fa-home me-2"></i>ראשי</a>
<a href="projectsTable.php" class="nav-item nav-link"><i class="fa fa-map me-2"></i>פרויקטים</a>
<a href="bid1.php" class="nav-item nav-link"><i class="fa fa-superscript"></i>הצעת מחיר</a>
<a href="economic.php" class="nav-item nav-link"><i class="fa fa-university me-2"></i>כלכלי</a>
<a href="inventory.php" class="nav-item nav-link"><i class="fa fa-cubes me-2"></i>מחסן</a>
<a href="addShift.php" class="nav-item nav-link"><i class="fa fa-book me-2"></i>דיווח משמרת</a>
<a href="reports.php" class="nav-item nav-link"><i class="far fa-file-alt me-2 me-2"></i>דוחות</a>
<a href="notifications.php" class="nav-item nav-link"><i class="far fa-bell me-2 me-2"></i>התראות</a>
<a href="profile.php" class="nav-item nav-link"><i class="far fa-user me-2 me-2"></i>עדכון פרופיל</a>
<div class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle active" data-bs-toggle="dropdown"><i class="fa fa-plus-square me-2"></i>הוספה</a>
<div class="dropdown-menu bg-transparent border-0">
<a href="addEmployee.php" class="dropdown-item">עובד</a>
<a href="addClient.php" class="dropdown-item active">לקוח</a>
<a href="addmaterial.php" class="dropdown-item">חומר</a>
<a href="addProject.php" class="dropdown-item">פרויקט</a>
<a href="addException.php" class="dropdown-item">חריגה</a>
<a href="addSupplier.php" class="dropdown-item">ספק</a>
<a href="addVehicle.php" class="dropdown-item">רכב & ציוד צמ"ה</a>
<a href="addCheck.php" class="dropdown-item">צ'יק</a>
<a href="addReport.php" class="dropdown-item">דו"ח תנועה</a>
<a href="addFuel.php" class="dropdown-item">דיווח דלק</a>
<a href="carFix.php" class="dropdown-item">טיפול רכב</a>
</div>
</div>
<div class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown"><i class="far fa-edit me-2"></i>עריכה & מחיקה</a>
<div class="dropdown-menu bg-transparent border-0">
<a href="editEmployee.php" class="dropdown-item">עובד</a>
<a href="editClient.php" class="dropdown-item">לקוח</a>
<a href="editMaterial.php" class="dropdown-item">חומר</a>
<a href="editShift.php" class="dropdown-item">משמרת</a>
<a href="editException.php" class="dropdown-item">חריגה</a>
<a href="editSupplier.php" class="dropdown-item">ספק</a>
<a href="editCar.php" class="dropdown-item">רכב & ציוד צמ"ה</a>
<a href="editCheck.php" class="dropdown-item">צ'יק</a>
<a href="editReport.php" class="dropdown-item">דו"ח תנועה</a>
<a href="editFuel.php" class="dropdown-item">דיווח דלק</a>
<a href="editFixing.php" class="dropdown-item">טיפול רכב</a>
</div>
</div>
</div>
</nav>
</div>
<!-- Sidebar End -->
<!-- Content Start -->
<div class="content">
<!-- Navbar Start -->
<nav class="navbar navbar-expand bg-light navbar-light sticky-top px-4 py-0">
<a href="index.php" class="navbar-brand d-flex d-lg-none me-4">
<h2 class="text-primary mb-0"><i class="fa fa-hashtag"></i></h2>
</a>
<div class="navbar-nav me-auto">
<div class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
<img class="rounded-circle me-lg-2" src="img/user.jpg" alt="" style="width: 40px; height: 40px;">
<span class="d-none d-lg-inline-flex"><?php echo $name ?></span>
</a>
<div class="dropdown-menu dropdown-menu-end bg-light border-0 rounded-0 rounded-bottom m-0">
<a href="profile.php" class="dropdown-item">הפרופיל שלי</a>
<a href="logOut.php" class="dropdown-item">יציאה</a>
</div>
</div>
<div class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
<i class="fa fa-bell me-lg-2"></i><span class="position-absolute top-45 start-50 translate-middle badge rounded-pill bg-danger"></span>
<span class="d-none d-lg-inline-flex">התראות</span>
</a>
<div class="dropdown-menu dropdown-menu-end bg-light border-0 rounded-0 rounded-bottom m-0">
<?php
if ($result_notify->num_rows <= 0) {
echo "";
} else {
while (($row_notify = $result_notify->fetch_assoc())) {
echo "<a href='#' class='dropdown-item'>";
echo "<h6 class='fw-normal mb-0'>" . $row_notify["title"] . "</h6>";
echo "<small>" . $row_notify["date"] . "</small>";
echo "</a>";
}
}
?>
<hr class="dropdown-divider">
<a href="notifications.php" class="dropdown-item text-center">הצגת כל ההתראות</a>
</div>
</div>
</div>
<div class="navbar-nav ms-auto">
<a href="#" class="sidebar-toggler flex-shrink-0 ms-2">
<i class="fa fa-bars"></i>
</a>
</div>
</nav>
<!-- Navbar End -->
<div class="col-sm-12 custom-form">
<div class="bg-light rounded p-4 custom-form-container" dir="rtl">
<h5 class="mb-4">הוספת לקוח</h6>
<form method="post">
<div class="form-floating mb-3">
<input type="text" class="form-control" id="fullName" name="fullName" placeholder="">
<label for="fullName" class="position-absolute top-0 end-0">שם מלא</label>
</div>
<div class="form-floating mb-3">
<input type="text" class="form-control" id="address" name="address" placeholder="">
<label for="address" class="position-absolute top-0 end-0">כתובת</label>
</div>
<div class="form-floating mb-3">
<input type="text" class="form-control" id="id" name="id" placeholder="">
<label for="id" class="position-absolute top-0 end-0">ת"ז/ח.פ</label>
</div>
<div class="form-floating mb-3">
<select class="form-select" id="gender" name="gender" aria-label="Floating label select example">
<option selected>בחר/י</option>
<option>זכר</option>
<option>נקבה</option>
</select>
<label for="gender" class="position-absolute top-0 end-0">מין</label>
</div>
<div class="form-floating mb-3">
<input type="text" class="form-control" id="phoneNumber" name="phoneNumber" placeholder="">
<label for="phoneNumber" class="position-absolute top-0 end-0">מס' טלפון</label>
</div>
<div class="form-floating mb-3">
<input type="text" class="form-control" id="phoneNumber2" name="phoneNumber2" placeholder="">
<label for="phoneNumber2" class="position-absolute top-0 end-0">מס' טלפון נוסף</label>
</div>
<div class="form-floating mb-3">
<input type="email" class="form-control" id="email" name="email" placeholder="">
<label for="email" class="position-absolute top-0 end-0">אימייל</label>
</div>
<button type="submit" class="btn btn-primary">הוסף</button>
<!-- Display error message -->
<?php if (isset($_SESSION["errorMessage"]) && !empty($_SESSION["errorMessage"])) { ?>
<div class="alert alert-danger" role="alert">
<?php echo $_SESSION["errorMessage"]; ?>
</div>
<?php } ?>
<!-- Display success message -->
<?php if (isset($_SESSION["successMessage"]) && !empty($_SESSION["successMessage"])) { ?>
<div class="alert alert-success" role="alert">
<?php echo $_SESSION["successMessage"]; ?>
</div>
<?php } ?>
<!-- Clear session variables after displaying messages -->
<?php
unset($_SESSION["errorMessage"]);
unset($_SESSION["successMessage"]);
?>
</form>
</div>
</div>
<!-- Footer Start -->
<div class="container-fluid pt-4 px-4">
<div class="bg-light rounded-top p-4">
<div class="row">
<div class="col-12 col-sm-6 text-center text-sm-start">
© <a href="#">Your Site Name</a>, All Right Reserved.
</div>
<div class="col-12 col-sm-6 text-center text-sm-end">
<!--/*** This template is free as long as you keep the footer author’s credit link/attribution link/backlink. If you'd like to use the template without the footer author’s credit link/attribution link/backlink, you can purchase the Credit Removal License from "https://htmlcodex.com/credit-removal". Thank you for your support. ***/-->
Designed By <a href="https://htmlcodex.com">HTML Codex</a>
</div>
</div>
</div>
</div>
<!-- Footer End -->
</div>
<!-- Content End -->
<!-- Back to Top -->
<a href="#" class="btn btn-lg btn-primary btn-lg-square back-to-top"><i class="bi bi-arrow-up"></i></a>
</div>
<!-- JavaScript Libraries -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="lib/chart/chart.min.js"></script>
<script src="lib/easing/easing.min.js"></script>
<script src="lib/waypoints/waypoints.min.js"></script>
<script src="lib/owlcarousel/owl.carousel.min.js"></script>
<script src="lib/tempusdominus/js/moment.min.js"></script>
<script src="lib/tempusdominus/js/moment-timezone.min.js"></script>
<script src="lib/tempusdominus/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Template Javascript -->
<script src="js/main.js"></script>
</body>
</html>