Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@

RewriteEngine On
RewriteRule ^admin/dashboard$ admin/dashboard.php
RewriteRule ^admin/products$ admin/dashboard.php
RewriteRule ^admin/products$ admin/dashboard.php
RewriteRule ^admin/accounts$ admin/dashboard.php
55 changes: 55 additions & 0 deletions account/accounts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
session_start();

if(isset($_SESSION['account'])){
if(!$_SESSION['account']['is_staff']){
header('location: login.php');
}
}else{
header('location: login.php');
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accounts</title>
</head>
<body>

<?php
require_once '../classes/account.class.php';
$accountObj = new Account();
?>

<table border="1">
<tr>
<th>No</th>
<th>Name</th>
<th>Username</th>
<th>Role</th>
<th>Actions</th>
</tr>
<?php
$accounts = $accountObj->getAll();
$i = 1;

foreach($accounts as $account) {
?>
<tr>
<td><?= $i ?></td>
<td><?= $account['first_name'] . ' ' . $account['last_name']; ?></td>
<td><?= $account['username']; ?></td>
<td><?= $account['role']; ?></td>
<td>
<button class="btn btn-sm btn-outline-success">Edit</button>
<button class="btn btn-sm btn-outline-danger">Delete</button>
</td>
</tr>
<?php $i++; } ?>
</table>

</body>
</html>
51 changes: 51 additions & 0 deletions account/view-accounts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="page-title-box">
<h4 class="page-title">Accounts</h4>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table table-centered table-nowrap mb-0">
<thead class="table-light">
<tr>
<th>No</th>
<th>Name</th>
<th>Username</th>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
require_once '../classes/account.class.php';
$accountObj = new Account();
$accounts = $accountObj->getAll();
$i = 1;

foreach($accounts as $account) {
?>
<tr>
<td><?= $i ?></td>
<td><?= $account['first_name'] . ' ' . $account['last_name']; ?></td>
<td><?= $account['username']; ?></td>
<td><?= $account['role']; ?></td>
<td>
<button class="btn btn-sm btn-outline-success">Edit</button>
<button class="btn btn-sm btn-outline-danger">Delete</button>
</td>
</tr>
<?php $i++; } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
15 changes: 14 additions & 1 deletion classes/account.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,21 @@ function fetch($username){

return $data;
}

function getAll(){
$sql = "SELECT * FROM account;";
$query = $this->db->connect()->prepare($sql);
$data = null;

if($query->execute()){
$data = $query->fetchAll();
}

return $data;
}

}

// $obj = new Account();

// $obj->add();
// $obj->add();
2 changes: 1 addition & 1 deletion includes/sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<a href="accounts" id="accounts-link" class="nav-link">
<i class="bi bi-people"></i>
<span class="fs-6 ms-2">Accounts</span>
</a>
Expand Down
28 changes: 27 additions & 1 deletion js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ $(document).ready(function(){
viewProducts()
})

$('#accounts-link').on('click', function(e){
e.preventDefault()
viewAccounts()
})



let url = window.location.href;
if (url.endsWith('dashboard')){
$('#dashboard-link').trigger('click')
}else if (url.endsWith('products')){
$('#products-link').trigger('click')
}else if (url.endsWith('accounts')){
$('#accounts-link').trigger('click')
}else{
$('#dashboard-link').trigger('click')
}
Expand All @@ -39,6 +48,23 @@ $(document).ready(function(){
})
}

function viewAccounts(){
$.ajax({
type: 'GET',
url: '../account/view-accounts.php',
dataType: 'html',
success: function(response){
$('.content-page').html(response)

$('#table-accounts').DataTable({
dom: 'rtp',
pageLength: 10,
ordering: false,
});
}
})
}

function loadChart(){
const ctx = document.getElementById('salesChart').getContext('2d');
const salesChart = new Chart(ctx, {
Expand Down Expand Up @@ -192,4 +218,4 @@ $(document).ready(function(){
}
});
}
});
});
7 changes: 6 additions & 1 deletion products/add-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

$uploadDir = '../uploads/';
$allowedType = ['jpg', 'jpeg', 'png'];
$maxFileSize = 5 * 1024 * 1024;

$productObj = new ProductImage();

Expand Down Expand Up @@ -43,10 +44,14 @@
}

$imageFileType = strtolower(pathinfo($image, PATHINFO_EXTENSION));
$fileSize = $_FILES['product_image']['size'];

if(empty($image)){
$imageErr = 'Product image is required.';
}else if(!in_array($imageFileType, $allowedType)){
} else if(!in_array($imageFileType, $allowedType)){
$imageErr = 'Accepted files are jpg, jpeg, and png only.';
} else if($fileSize > $maxFileSize){
$imageErr = 'File size must not exceed 5MB.';
}

// If there are validation errors, return them as JSON
Expand Down