diff --git a/.htaccess b/.htaccess
index abeece8..207e958 100644
--- a/.htaccess
+++ b/.htaccess
@@ -12,4 +12,5 @@
RewriteEngine On
RewriteRule ^admin/dashboard$ admin/dashboard.php
-RewriteRule ^admin/products$ admin/dashboard.php
\ No newline at end of file
+RewriteRule ^admin/products$ admin/dashboard.php
+RewriteRule ^admin/accounts$ admin/dashboard.php
\ No newline at end of file
diff --git a/account/accounts.php b/account/accounts.php
new file mode 100644
index 0000000..78ff6df
--- /dev/null
+++ b/account/accounts.php
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+ Accounts
+
+
+
+
+
+
+
+ No
+ Name
+ Username
+ Role
+ Actions
+
+ getAll();
+ $i = 1;
+
+ foreach($accounts as $account) {
+ ?>
+
+ = $i ?>
+ = $account['first_name'] . ' ' . $account['last_name']; ?>
+ = $account['username']; ?>
+ = $account['role']; ?>
+
+ Edit
+ Delete
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/account/view-accounts.php b/account/view-accounts.php
new file mode 100644
index 0000000..d425106
--- /dev/null
+++ b/account/view-accounts.php
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+ No
+ Name
+ Username
+ Role
+ Actions
+
+
+
+ getAll();
+ $i = 1;
+
+ foreach($accounts as $account) {
+ ?>
+
+ = $i ?>
+ = $account['first_name'] . ' ' . $account['last_name']; ?>
+ = $account['username']; ?>
+ = $account['role']; ?>
+
+ Edit
+ Delete
+
+
+
+
+
+
+
+
+
+
+
diff --git a/classes/account.class.php b/classes/account.class.php
index 29626f5..12c1896 100644
--- a/classes/account.class.php
+++ b/classes/account.class.php
@@ -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();
\ No newline at end of file
+// $obj->add();
diff --git a/includes/sidebar.php b/includes/sidebar.php
index 87e0572..cd477cd 100644
--- a/includes/sidebar.php
+++ b/includes/sidebar.php
@@ -38,7 +38,7 @@
-
+
Accounts
diff --git a/js/admin.js b/js/admin.js
index 29bdf2b..9810c82 100644
--- a/js/admin.js
+++ b/js/admin.js
@@ -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')
}
@@ -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, {
@@ -192,4 +218,4 @@ $(document).ready(function(){
}
});
}
-});
\ No newline at end of file
+});
diff --git a/products/add-product.php b/products/add-product.php
index cb3471b..19e5b05 100644
--- a/products/add-product.php
+++ b/products/add-product.php
@@ -8,6 +8,7 @@
$uploadDir = '../uploads/';
$allowedType = ['jpg', 'jpeg', 'png'];
+$maxFileSize = 5 * 1024 * 1024;
$productObj = new ProductImage();
@@ -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