Skip to content

Commit c459090

Browse files
Version 1.9 User Management Added
1 parent c614c57 commit c459090

File tree

7 files changed

+46
-58
lines changed

7 files changed

+46
-58
lines changed

assets/js/main.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,20 @@ new DataTable('table.table-display',{
8888
$('input[name="phone"]').val(phone);
8989
});
9090

91-
} else if (currentPath.includes("/RMMFB/staff.php")) {
91+
} else if (currentPath.includes("/CUSTMBRS/users.php")) {
9292
$('a[data-bs-target="#update"]').on('click', function() {
9393
var id = $(this).data('id');
9494
var username = $(this).data('username');
95-
console.log(id, username);
96-
97-
$('input[name="data_id"]').val(id);
95+
var address = $(this).data('address');
96+
var phone = $(this).data('phone');
97+
$('input[name="id"]').val(id);
9898
$('input[name="username"]').val(username);
99-
99+
$('input[name="address"]').val(address);
100+
$('input[name="phone"]').val(phone);
101+
console.log(id, username);
100102
});
101-
} else if (currentPath.includes("/RMMFB/inventory.php")) {
103+
104+
} else if (currentPath.includes("/CUSTMBRS/inventory.php")) {
102105
$('a[data-bs-target="#update"]').on('click', function() {
103106
var id = $(this).data('id');
104107
var name = $(this).data('name');
@@ -121,7 +124,7 @@ new DataTable('table.table-display',{
121124
console.log(id);
122125
$('input[name="data_id"]').val(id);
123126
});
124-
}else if (currentPath.includes("/RMMFB/rents.php")) {
127+
}else if (currentPath.includes("/CUSTMBRS/rents.php")) {
125128
$('a[data-bs-target="#return"]').on('click', function() {
126129
var id = $(this).data('id');
127130
$('input[name="data_id"]').val(id);

functions/staff-create.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@
33

44
$username = $_POST['username'];
55
$password = $_POST['password'];
6+
$address = $_POST['address'];
7+
$phone = $_POST['phone'];
68

79
$sql = "SELECT * FROM users WHERE username = :username";
810
$stmt = $db->prepare($sql);
911
$stmt->bindParam(':username', $username);
1012
$stmt->execute();
1113

1214
if ($stmt->rowCount() > 0) {
13-
header('Location: ../staff.php?type=error&message='.$username.' is already exist');
15+
header('Location: ../users.php?type=error&message='.$username.' is already exist');
1416
exit;
1517
}
1618

17-
$sql = "INSERT INTO users (username, password, type) VALUES (:username, :password, 'staff')";
19+
$sql = "INSERT INTO users (`username`, `password`, `address`, `phone`, `type`) VALUES (:username, :password, :address, :phone, 'staff')";
1820
$stmt = $db->prepare($sql);
1921
$stmt->bindParam(':username', $username);
2022
$stmt->bindParam(':password', password_hash($password, PASSWORD_DEFAULT));
23+
$stmt->bindParam(':address', $address);
24+
$stmt->bindParam(':phone', $phone);
2125
$stmt->execute();
2226

23-
generate_logs('Adding Staff', $fullname.'| New Staff was added');
24-
header('Location: ../staff.php?type=success&message=New Staff was added successfully');
27+
generate_logs('Adding user', $fullname.'| New user was added');
28+
header('Location: ../users.php?type=success&message=New user was added successfully');
2529
?>

functions/staff-remove.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
include_once 'connection.php';
33

44
try {
5-
$id = $_POST['data_id'];
5+
$id = $_POST['id'];
66

77
$sql = "SELECT * FROM users WHERE id = :id";
88
$statement = $db->prepare($sql);
@@ -14,9 +14,9 @@
1414
$statement = $db->prepare($sql);
1515
$statement->bindParam(':id', $id);
1616
$statement->execute();
17-
generate_logs('Removing Staff', $result['username'].' was removed');
18-
header('Location: ../staff.php?type=success&message='.$result['username'].' was removed successfully!');
17+
generate_logs('Removing user', $result['username'].' was removed');
18+
header('Location: ../users.php?type=success&message='.$result['username'].' was removed successfully!');
1919
} catch (\Throwable $th) {
20-
generate_logs('Removing Staff', $th);
21-
header('Location: ../staff.php?type=error&message=Something went wrong, please try again');
20+
generate_logs('Removing users', $th);
21+
header('Location: ../users.php?type=error&message=Something went wrong, please try again');
2222
}

functions/staff-update.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22
include_once 'connection.php';
33

44
try {
5-
$id = $_POST['data_id'];
5+
$id = $_POST['id'];
66
$username = $_POST['username'];
77
$password = $_POST['password'];
8+
$address = $_POST['address'];
9+
$phone = $_POST['phone'];
810

9-
$sql = "UPDATE users SET username = :username, password = :password WHERE id = :id";
11+
$sql = "UPDATE users SET `username` = :username, `password` = :password, `address` = :address, `phone` = :phone WHERE id = :id";
1012
$statement = $db->prepare($sql);
1113
$statement->bindParam(':id', $id);
1214
$statement->bindParam(':username', $username);
15+
$statement->bindParam(':address', $address);
16+
$statement->bindParam(':phone', $phone);
1317
$statement->bindParam(':password', password_hash($password, PASSWORD_DEFAULT));
1418
$statement->execute();
1519

1620
generate_logs('Staff Update', $username.'| Info was updated');
17-
header('Location: ../staff.php?type=success&message=Staff Info was updated successfully!');
21+
header('Location: ../users.php?type=success&message=Staff Info was updated successfully!');
1822
exit();
1923

2024
} catch (\Throwable $th) {

functions/tables/datatables.php

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ function customer_list(){
4646
}
4747

4848
function customers(){
49-
5049
global $db;
5150
$sql = 'SELECT * FROM customers ORDER BY fullname ASC';
5251
$stmt = $db->prepare($sql);
@@ -62,44 +61,24 @@ function customers(){
6261

6362
function staff_list(){
6463
global $db;
65-
$sql = 'SELECT * FROM users WHERE type = "staff"';
64+
$sql = 'SELECT * FROM users WHERE `type` = "staff"';
6665
$stmt = $db->prepare($sql);
6766
$stmt->execute();
6867
$results = $stmt->fetchAll();
6968

7069
foreach ($results as $row) {
7170
?>
7271
<tr>
73-
<td><?php echo $row['id'] ?></td>
74-
<td><img class="rounded-circle me-2" width="30" height="30" src="assets/img/avatars/avatar1.png"><?php echo $row['username']; ?></td>
72+
<td><img class="rounded-circle me-2" width="30" height="30" src="assets/img/icon.png"><?php echo $row['username']; ?></td>
7573
<td><?php echo $row['password'] ?></td>
74+
<td><?php echo $row['phone'] ?></td>
75+
<td><?php echo $row['address'] ?></td>
7676
<td><?php echo $row['created_at'] ?></td>
7777
<td class="text-center">
78-
<a data-bs-toggle="modal" data-bss-tooltip="" class="mx-1" href="#" data-bs-target="#update" data-id="<?php echo $row['id']?>" data-username="<?php echo $row['username']?>" title="Here you can update the customer Information."><i class="far fa-edit text-warning" style="font-size: 20px;"></i></a>
78+
<a data-bs-toggle="modal" data-bss-tooltip="" class="mx-1" href="#" data-bs-target="#update" data-id="<?php echo $row['id']?>" data-username="<?php echo $row['username']?>" data-address="<?php echo $row['address']?>" data-phone="<?php echo $row['phone']?>" title="Here you can update the customer Information."><i class="far fa-edit text-warning" style="font-size: 20px;"></i></a>
7979
<a data-bs-toggle="modal" data-bss-tooltip="" class="mx-1" href="#" data-bs-target="#remove" data-id="<?php echo $row['id']?>" title="Here you can remove the customer."><i class="far fa-trash-alt text-danger" style="font-size: 20px;"></i></a>
8080
</td>
8181
</tr>
8282
<?php
8383
}
8484
}
85-
86-
function item_list(){
87-
global $db;
88-
$sql = 'SELECT * FROM inventory';
89-
$stmt = $db->prepare($sql);
90-
$stmt->execute();
91-
$results = $stmt->fetchAll();
92-
93-
foreach ($results as $row) {
94-
?>
95-
<tr>
96-
<td><?php echo $row['id'] ?></td>
97-
<td><?php echo $row['name'] ?></td>
98-
<td><?php echo $row['description'] ?></td>
99-
<td><?php echo $row['qty'] ?></td>
100-
<td><?php echo $row['created_at'] ?></td>
101-
<td class="text-center"><a class="mx-1" href="#" data-bs-target="#stock-in" data-bs-toggle="modal" data-id="<?php echo $row['id'] ?>"><i class="far fa-arrow-alt-circle-up text-success" style="font-size: 20px;"></i></a><a class="mx-1" href="#" data-bs-target="#stock-out" data-bs-toggle="modal" data-id="<?php echo $row['id'] ?>"><i class="far fa-arrow-alt-circle-down" style="font-size: 20px;"></i></a><a class="mx-1" href="#" data-bs-target="#update" data-bs-toggle="modal" data-id="<?php echo $row['id'] ?>" data-name="<?php echo $row['name'] ?>" data-description="<?php echo $row['description'] ?>"><i class="far fa-edit text-warning" style="font-size: 20px;"></i></a><a class="mx-1" href="#" data-bs-target="#remove" data-bs-toggle="modal" data-id="<?php echo $row['id'] ?>"><i class="far fa-trash-alt text-danger" style="font-size: 20px;"></i></a></td>
102-
</tr>
103-
<?php
104-
}
105-
}

rent.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
include_once 'functions/menu/offcanva-menu.php';
33
include_once 'functions/authentication.php';
4+
include_once 'functions/tables/datatables.php';
45
?>
56
<!DOCTYPE html>
67
<html data-bs-theme="light" lang="en">
@@ -154,7 +155,7 @@
154155
<form novalidate="" method="post">
155156
<div class="mb-1"><label class="form-label">Customer</label><select class="selectpicker select" data-live-search="true" name="customer">
156157
<optgroup label="SELECT CUSTOMER">
157-
<option value="1" selected="">&lt;customer&gt;</option>
158+
<?php customers(); ?>
158159
</optgroup>
159160
</select></div>
160161
</form>

users.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
include_once 'functions/menu/offcanva-menu.php';
33
include_once 'functions/authentication.php';
4+
include_once 'functions/tables/datatables.php';
45
?>
56
<!DOCTYPE html>
67
<html data-bs-theme="light" lang="en">
@@ -72,14 +73,7 @@
7273
</tr>
7374
</thead>
7475
<tbody>
75-
<tr>
76-
<td><img class="rounded-circle me-2" width="30" height="30" src="assets/img/logo.png">&nbsp;&lt;username&gt;</td>
77-
<td>&lt;password&gt;</td>
78-
<td>&lt;phone&gt;</td>
79-
<td>&lt;address&gt;</td>
80-
<td>&lt;created_at&gt;</td>
81-
<td class="text-center"><a class="mx-1" href="#"><i class="fas fa-eye fs-4"></i></a><a class="mx-1" href="#" data-bs-target="#update" data-bs-toggle="modal"><i class="fas fa-user-edit fs-4 text-warning"></i></a><a class="mx-1" href="#" data-bs-target="#remove" data-bs-toggle="modal"><i class="fas fa-trash-alt fs-4 text-danger"></i></a></td>
82-
</tr>
76+
<?php staff_list(); ?>
8377
</tbody>
8478
<tfoot>
8579
<tr></tr>
@@ -105,7 +99,7 @@
10599
<h4 class="modal-title">Add User</h4><button class="btn-close" type="button" aria-label="Close" data-bs-dismiss="modal"></button>
106100
</div>
107101
<div class="modal-body">
108-
<form class="needs-validation" method="post" novalidate>
102+
<form class="needs-validation" action="functions/staff-create.php" method="post" novalidate>
109103
<div class="mb-1"><label class="form-label">Username</label><input class="form-control" type="text" name="username" required="">
110104
<div class="invalid-feedback">
111105
Please enter your username.
@@ -140,7 +134,8 @@
140134
<h4 class="modal-title">Update User</h4><button class="btn-close" type="button" aria-label="Close" data-bs-dismiss="modal"></button>
141135
</div>
142136
<div class="modal-body">
143-
<form class="needs-validation" method="post" novalidate>
137+
<form class="needs-validation" action="functions/staff-update.php" method="post" novalidate>
138+
<input type="hidden" name="id">
144139
<div class="mb-1"><label class="form-label">Username</label><input class="form-control" type="text" name="username" required="">
145140
<div class="invalid-feedback">
146141
Please enter your username.
@@ -177,7 +172,10 @@
177172
<div class="modal-body">
178173
<p>Are you sure you want to remove this User?</p>
179174
</div>
180-
<div class="modal-footer"><button class="btn btn-light" type="button" data-bs-dismiss="modal">Close</button><button class="btn btn-danger" type="button">Remove</button></div>
175+
<form action="functions/staff-remove.php" method="post">
176+
<input type="hidden" name="id">
177+
<div class="modal-footer"><button class="btn btn-light" type="button" data-bs-dismiss="modal">Close</button><button class="btn btn-danger" type="submit">Remove</button></div>
178+
</form>
181179
</div>
182180
</div>
183181
</div>
@@ -194,7 +192,6 @@
194192
<script src="assets/js/buttons.html5.min.js"></script>
195193
<script src="assets/js/sweetalert2.all.min.js"></script>
196194
<script src="assets/js/main.js"></script>
197-
<script src="assets/js/fullcalendar.js"></script>
198195
<script src="assets/js/index.global.min.js"></script>
199196
<script src="assets/js/tinymce.min.js"></script>
200197
</body>

0 commit comments

Comments
 (0)