-
Notifications
You must be signed in to change notification settings - Fork 1
/
createBranch.php
584 lines (471 loc) · 20.1 KB
/
createBranch.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
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
<?php
// Start the session
session_start();
// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}
// Include the database connection
include 'config/db.php';
// Get session email
$email = $_SESSION['email'];
// Get user name, email, and role from the register table
$getAdminData = "SELECT * FROM register WHERE email = '$email'";
$resultData = mysqli_query($conn, $getAdminData);
if ($resultData->num_rows > 0) {
$row2 = $resultData->fetch_assoc();
$adminName = $row2['name'];
$adminEmail = $row2['email'];
$userRole = $row2['role']; // Assuming you have a 'role' column in the 'register' table
}
// Check if the user is an admin, otherwise redirect
if (isset($_SESSION['role']) && $_SESSION['role'] != 'admin') {
// If the user is not an Admin, redirect to index page
header("Location: index.php");
exit();
}
// Retrieve company ID from URL
$company_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
// Validate company ID
$companyQuery = "SELECT comp_id FROM compani WHERE comp_id = $company_id";
$companyResult = $conn->query($companyQuery);
if ($companyResult && $companyResult->num_rows === 0) {
die("Error: Company ID does not exist.");
}
if (isset($_POST['submit'])) {
// Fetching values from the form using POST and ensuring security with real_escape_string
$branch_name = mysqli_real_escape_string($conn, $_POST['branch_name']);
$account_desc = mysqli_real_escape_string($conn, $_POST['account_desc']);
$registration = mysqli_real_escape_string($conn, $_POST['registration']);
$expiry = mysqli_real_escape_string($conn, $_POST['expiry']);
$contact_person = mysqli_real_escape_string($conn, $_POST['foc']);
$role = mysqli_real_escape_string($conn, $_POST['role']);
$auth = mysqli_real_escape_string($conn, $_POST['authority']);
$contact_phone = mysqli_real_escape_string($conn, $_POST['foc_phone']);
$address = mysqli_real_escape_string($conn, $_POST['address']);
$pickup_address = mysqli_real_escape_string($conn, $_POST['pickup_address']); // renamed input field for better understanding
//check duplicate company name
$accCheckQuery = "SELECT * FROM `branches` WHERE `branch_name` = '$branch_name'";
$accCheckResult = $conn->query($accCheckQuery);
if ($accCheckResult->num_rows > 0) {
die("Error: The company name '$branch_name' already exists.");
}
// SQL query to insert the data into the database
$sql = "INSERT INTO branches (comp_id_fk, branch_name, account_desc, registration_date, expiry_date, contact_person, role, auth, contact_phone, address, pickup_address)
VALUES ('$company_id', '$branch_name', '$account_desc', '$registration', '$expiry', '$contact_person', '$role', '$auth', '$contact_phone', '$address', '$pickup_address')";
if (mysqli_query($conn, $sql)) {
//get id of newly inserted branch
$newBranchId = mysqli_insert_id($conn);
$addStaff = "INSERT INTO `employee` (`branch_id_fk`, `name`, `phone`, `role`, `Authority`)
VALUES ('$newBranchId', '$contact_person', '$contact_phone', '$role', '$auth') ";
if (mysqli_query($conn, $addStaff)) {
header("Location: Branches.php?id=" . $company_id);
exit; // Ensure script ends after redirect
echo "success";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>create branch</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Favicons -->
<link href="assets/img/favicon.png" rel="icon">
<link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">
<!-- Google Fonts -->
<link href="https://fonts.gstatic.com" rel="preconnect">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i" rel="stylesheet">
<!-- Vendor CSS Files -->
<link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
<link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
<link href="assets/vendor/quill/quill.snow.css" rel="stylesheet">
<link href="assets/vendor/quill/quill.bubble.css" rel="stylesheet">
<link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
<link href="assets/vendor/simple-datatables/style.css" rel="stylesheet">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/simple-datatables@latest/dist/style.css" rel="stylesheet" type="text/css">
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@latest" type="text/javascript"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Source+Serif+Pro:400,600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="fonts/icomoon/style.css">
<link rel="stylesheet" href="css/owl.carousel.min.css">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- Style -->
<link rel="stylesheet" href="css/style.css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<!-- Favicons -->
<link href="assets/img/favicon.png" rel="icon">
<link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">
<!-- Google Fonts -->
<link href="https://fonts.gstatic.com" rel="preconnect">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
<!-- Vendor CSS Files -->
<link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
<link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
<link href="assets/vendor/quill/quill.snow.css" rel="stylesheet">
<link href="assets/vendor/quill/quill.bubble.css" rel="stylesheet">
<link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
<link href="assets/vendor/simple-datatables/style.css" rel="stylesheet">
<style>
/* Custom CSS to decrease font size of the table */
.img {
border-radius: 30%;
}
.custom {
font-size: 0.9rem;
/* Adjust as needed */
font-family: monospace;
}
.company-name {
font-size: 1rem;
}
.company-title {
font-size: 1.1rem;
}
.burger {
left: -10px;
top: -20px;
}
.custom-card2 {
width: 100%;
margin-left: 290px;
box-shadow: none;
border: none;
}
/*styles for form*/
.card-body {
padding: 0 20px 20px 20px;
font-size: 0.8rem;
}
.form-control[type=file]:not(:disabled):not([readonly]) {
cursor: pointer;
font-size: 0.8rem;
}
input[type=date].form-control {
appearance: none;
font-size: 0.8rem;
}
@media (min-width: 1200px) {
.h2,
h2 {
font-size: 1.5rem;
}
}
.headerimg h2 {
font-family: "Nunito", sans-serif;
font-size: 1.5rem;
}
/* Define the pulse animation */
@keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(1.1);
}
100% {
transform: scale(1);
}
}
/* Define the click animation */
@keyframes clickEffect {
0% {
transform: scale(1);
opacity: 1;
}
50% {
transform: scale(0.9);
opacity: 0.7;
}
100% {
transform: scale(1);
opacity: 1;
}
}
.card-title {
margin-bottom: 40px;
}
.card {
margin-left: 145px;
}
.company-name {
color: #000;
text-decoration: none;
display: inline-block;
transition: color 0.3s ease;
}
.company-name:hover {
color: #007bff;
/* Change color on hover */
animation: pulse 10s ease-in-out;
/* Apply the pulse animation on hover */
}
.company-name:active {
animation: clickEffect 0.s ease;
/* Apply the click effect animation on click */
color: #0056b3;
/* Darken color on click */
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.headerimg {
margin-top: 100px;
margin-left: 100px;
}
.custom-card {
width: 60%;
margin-top: 50px;
box-shadow: none;
border: none;
}
</style>
<!-- Template Main CSS File -->
<link href="assets/css/style.css" rel="stylesheet">
<title>Add Branch</title>
</head>
<!-- ======= Header ======= -->
<header id="header" class="header fixed-top d-flex align-items-center">
<div class="d-flex align-items-center justify-content-between">
<img class="navbar-image" src="assets/img/logo3.png" alt="">
<a href="index.php" class="logo d-flex align-items-center">
<span class="d-none d-lg-block">FingerLog</span>
</a>
<i class="bi bi-list toggle-sidebar-btn"></i>
</div><!-- End Logo -->
<!--
<div class="search-bar">
<form class="search-form d-flex align-items-center" method="POST" action="#">
<input type="text" name="query" placeholder="Search" title="Enter search keyword">
<button type="submit" title="Search"><i class="bi bi-search"></i></button>
</form>
</div>
End Search Bar -->
<nav class="header-nav ms-auto">
<ul class="d-flex align-items-center">
<li class="nav-item d-block d-lg-none">
<a class="nav-link nav-icon search-bar-toggle " href="#">
<i class="bi bi-search"></i>
</a>
</li><!-- End Search Icon-->
<li class="nav-item profileimage dropdown pe-3 mr-4">
<a class="nav-link nav-profile d-flex align-items-center pe-0" href="#" data-bs-toggle="dropdown">
<img src="image/admin-png.png" alt="Profile" class="rounded-circle">
<span class="d-none d-md-block dropdown-toggle ps-2"><?php echo $adminName ?></span>
</a><!-- End Profile Image Icon -->
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow profile">
<li class="dropdown-header">
<h6><?php echo $adminName ?></h6>
<span><?php echo $adminEmail ?></span>
</li>
<li>
<hr class="dropdown-divider">
</li>
</li>
<li>
<a class="dropdown-item d-flex align-items-center" href="logout.php">
<i class="bi bi-box-arrow-right"></i>
<span>Sign Out</span>
</a>
</li>
</ul><!-- End Profile Dropdown Items -->
</li><!-- End Profile Nav -->
</ul>
</nav><!-- End Icons Navigation -->
</header><!-- End Header -->
<!-- ======= Sidebar ======= -->
<aside id="sidebar" class="sidebar">
<ul class="sidebar-nav" id="sidebar-nav">
<li class="nav-item">
<a class="nav-link collapsed" href="index.php">
<i class="ri-home-8-line"></i>
<span>Dashboard</span>
</a>
</li><!-- End Dashboard Nav -->
<li class="nav-item">
<a class="nav-link active" data-bs-target="#tables-nav" data-bs-toggle="" href="Companies.php">
<i class="ri-building-4-line"></i><span>Accounts</span><i class="bi bi-chevron ms-auto"></i>
</a>
</li>
<li class="nav-item">
<a class="nav-link collapsed" data-bs-target="#tables-nav" data-bs-toggle="" href="box.php">
<i class="ri-archive-stack-fill"></i><span>Containers</span><i class="bi bi-chevron ms-auto"></i>
</a>
</li>
<li class="nav-item">
<a class="nav-link collapsed" data-bs-target="#tables-nav" data-bs-toggle="" href="order.php">
<i class="ri-list-ordered"></i><span>Work Orders</span><i class="bi bi-chevron ms-auto"></i>
</a>
</li>
<li class="nav-item">
<a class="nav-link collapsed" data-bs-target="#tables-nav" data-bs-toggle="" href="racks.php">
<i class="bi bi-box"></i><span>Racks</span><i class="bi bi-chevron ms-auto"></i>
</a>
</li>
<li class="nav-item">
<a class="nav-link collapsed" data-bs-target="#tables-nav" data-bs-toggle="" href="store.php">
<i class="bi bi-shop"></i><span>Store</span><i class="bi bi-chevron ms-auto"></i>
</a>
</li>
<li class="nav-heading">Pages</li>
<!-- End Profile Page Nav -->
<!-- <li class="nav-item">
<a class="nav-link collapsed" href="pages-register.php">
<i class="bi bi-card-list"></i>
<span>Register</span>
</a>
</li> -->
<!-- End Register Page Nav -->
<li class="nav-item">
<a class="nav-link collapsed" href="pages-login.php">
<i class="bi bi-box-arrow-in-right"></i>
<span>Login</span>
</a>
</li><!-- End Login Page Nav -->
<li class="nav-item">
<a class="nav-link collapsed" href="logout.php">
<i class="bi bi-box-arrow-in-right"></i>
<span>Logout</span>
</a>
</li><!-- End Login Page Nav -->
<li class="nav-item">
<a class="nav-link collapsed" href="pages-contact.php">
<i class="bi bi-envelope"></i>
<span>Contact</span>
</a>
</li><!-- End Contact Page Nav -->
</ul>
</aside>
<!-- ---------------------------------------------------End Sidebar--------------------------------------------------->
<body>
<div class="headerimg text-center">
<img src="image/create.png" alt="network-logo" width="50" height="50">
<h2>Create Branch</h2>
</div>
<!-- End Header form -->
<div class="container d-flex justify-content-center">
<div class="card custom-card shadow-lg mt-3">
<!-- <h5 class="card-title ml-4">Create Company </h5> -->
<div class="card-body">
<br>
<!-- Multi Columns Form -->
<form class="row g-3 p-3" action="#" method="POST">
<!-- Company ID input (readonly) -->
<!-- <div class="col-md-6">
<label class="form-label">Company ID</label>
<input type="text" class="form-control" name="comp_id_fk" value="<?php echo htmlspecialchars($company_id); ?>" readonly>
</div> -->
<?php
$getAccLev1 = "SELECT * FROM compani WHERE comp_id = '$company_id'";
$resultAccLev1 = mysqli_query($conn, $getAccLev1);
if ($resultAccLev1->num_rows > 0) {
$rowAccLev1 = $resultAccLev1->fetch_assoc();
// $fetchAcc1 = $rowAccLev1['acc_lev_1'];
}
?>
<!-- <div class="col-md-6">
<label class="form-label">Account level 1</label>
<input type="text" class="form-control" name="" value="<?php echo htmlspecialchars($fetchAcc1); ?>" readonly>
</div> -->
<div class="col-md-6">
<label class="form-label">Branch Name</label>
<input type="text" class="form-control" name="branch_name" required>
</div>
<div class="col-md-6">
<label for="account_description" class="form-label">Account Description</label>
<textarea type="text" class="form-control" id="acc_desc" name="account_desc" rows="1" columns="20"></textarea>
</div>
<div class="col-md-6">
<label for="registration" class="form-label">Setup Date</label>
<input type="date" class="form-control" id="registration" name="registration" required>
</div>
<div class="col-md-6 mb-3">
<label for="expiry" class="form-label">Conract Exp_Date</label>
<input type="date" class="form-control" id="expiry" name="expiry">
</div>
<div class="col-md-6">
<label for="" class="form-label">Contact Person</label>
<input type="text" class="form-control" id="" name="foc" required pattern="[A-Za-z\s\.]+" required minlength="3" maxlength="38" title="only letters allowed; at least 3" required>
</div>
<div class="col-md-6">
<label for="" class="form-label">Role</label>
<select name="role" id="" class="form-select">
<option value="">Select Role of the Employee</option>
<option value="Branch Manager">Branch Manager</option>
<option value="Department Manager">Department Manager</option>
<option value="Junior Employee">Junior Employee</option>
<option value="Head of Operations">Head of Operations</option>
</select>
</div>
<div class="col-md-6">
<label for="phone" class="form-label">Access/Authority</label>
<select name="authority" id="" class="form-select">
<option value="">Select level of access</option>
<option value="can get information about branch boxes">can get information about branch boxes</option>
<option value="only retrieve department boxes">only retrieve department boxes</option>
<option value="all departments of their branch">all departments of their branch</option>
<option value="all departments and all branches of company">all departments and all branches of company</option>
</select>
</div>
<div class="col-md-6">
<label for="phone" class="form-label">Phone</label>
<input type="text" class="form-control" id="" name="foc_phone" required>
</div>
<div class="col-md-6">
<label for="pickup_address" class="form-label">Pickup/Delievry Address </label>
<input type="text" class="form-control" id="" name="pickup_address" required>
</div>
<div class="col-md-6">
<label for="address" class="form-label">Address</label>
<input type="text" class="form-control" id="" name="address" required>
</div>
<div class="text-center mt-4 mb-2">
<button type="submit" class="btn btn-outline-primary mr-2" name="submit" value="submit">Submit</button>
<button type="reset" class="btn btn-outline-secondary ">Reset</button>
</div>
</form>
</div>
</div>
</div>
<!-- Vendor JS Files -->
<script src="assets/vendor/apexcharts/apexcharts.min.js"></script>
<script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="assets/vendor/chart.js/chart.umd.js"></script>
<script src="assets/vendor/echarts/echarts.min.js"></script>
<script src="assets/vendor/quill/quill.js"></script>
<script src="assets/vendor/simple-datatables/simple-datatables.js"></script>
<script src="assets/vendor/tinymce/tinymce.min.js"></script>
<script src="assets/vendor/php-email-form/validate.js"></script>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/main.js">
</script>
<!-- Bootstrap JS (Optional) -->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-7/z1gk35k1RA6QQg+SjaK6MjpS3TdeL1h1jDdED5+ZIIbsSdyX/twQvKZq5uY15B" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9BfDxO4v5a9J9TZz1ck8vTAvO8ue+zjqBd5l3eUe8n5EM14ZlXyI4nN" crossorigin="anonymous"></script>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>