Skip to content

Commit

Permalink
Merge pull request #25 from TEAM-7-SAD/SPD-82-preloader
Browse files Browse the repository at this point in the history
Spd 82 preloader
  • Loading branch information
Carl-Tabuso authored May 24, 2024
2 parents c4c2f8c + 73a72bc commit 8620adc
Show file tree
Hide file tree
Showing 32 changed files with 279 additions and 129 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore
src/includes/error-logs.txt
44 changes: 26 additions & 18 deletions src/accounts.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<?php
require_once 'includes/db-connector.php';
require_once 'includes/session-handler.php';
include_once str_replace('/', DIRECTORY_SEPARATOR, 'includes/file-utilities.php');
require_once FileUtils::normalizeFilePath('includes/db-connector.php');
require_once FileUtils::normalizeFilePath('includes/session-handler.php');
include_once FileUtils::normalizeFilePath('includes/error-reporting.php');

if(isset($_SESSION['id'])) {

$sql = "SELECT * FROM user";
$result = $db->query($sql);
$row = $result->fetch_assoc();

?>

<!DOCTYPE html>
Expand All @@ -28,7 +34,8 @@

<!--Navbar-->
<?php
include 'includes/navbar.php';
include FileUtils::normalizeFilePath('includes/navbar.php');
include FileUtils::normalizeFilePath('includes/preloader.html');
?>

<!--Main Container-->
Expand Down Expand Up @@ -73,21 +80,21 @@
</thead>
<tbody>
<?php
$sql = "SELECT * FROM user";
$result = $db->query($sql);

while($row = $result->fetch_assoc()) {
echo '
<tr data-id="'.$row['id'].'" class="selectable">
<td><input type="checkbox" class="account-checkbox" data-account-id="'.$row['id'].'"></td>
<td>'.$row['last_name'].'</td>
<td>'.$row["first_name"].'</td>
<td>'.$row['middle_name'].'</td>
<td>'.$row['email'].'</td>
</tr>
';
}
?>
$sql = "SELECT * FROM user";
$result = $db->query($sql);
while($row = $result->fetch_assoc()) {
echo '
<tr data-id="'.$row['id'].'" class="selectable">
<td><input type="checkbox" class="account-checkbox" data-account-id="'.$row['id'].'"></td>
<td>'.$row['last_name'].'</td>
<td>'.$row["first_name"].'</td>
<td>'.$row['middle_name'].'</td>
<td>'.$row['email'].'</td>
</tr>
';
}
$db->close();
?>
</tbody>

<tfoot>
Expand Down Expand Up @@ -204,6 +211,7 @@ class="btn fw-medium btn-medium-brown text-capitalize py-2 px-4">add account</bu
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://cdn.datatables.net/2.0.3/js/dataTables.js"></script>
<script src="https://cdn.datatables.net/2.0.3/js/dataTables.bootstrap5.js"></script>
<script src="javascript/preloader.js"></script>

<!-- Adding of Accounts -->
<script>
Expand Down
4 changes: 3 additions & 1 deletion src/add-account.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
require_once 'includes/db-connector.php';
include_once str_replace('/', DIRECTORY_SEPARATOR, 'includes/file-utilities.php');
require_once FileUtils::normalizeFilePath('includes/db-connector.php');
include_once FileUtils::normalizeFilePath('includes/error-reporting.php');

$last_name = $_POST['last_name'];
$first_name = $_POST['first_name'];
Expand Down
14 changes: 9 additions & 5 deletions src/create-order.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
require_once 'includes/db-connector.php';
require_once 'includes/session-handler.php';
include_once str_replace('/', DIRECTORY_SEPARATOR, 'includes/file-utilities.php');
require_once FileUtils::normalizeFilePath('includes/db-connector.php');
require_once FileUtils::normalizeFilePath('includes/session-handler.php');
include_once FileUtils::normalizeFilePath('includes/error-reporting.php');

if(isset($_SESSION['id'])) {

Expand All @@ -26,7 +28,8 @@

<!--Navbar-->
<?php
include 'includes/navbar.php';
include FileUtils::normalizeFilePath('includes/navbar.php');
include FileUtils::normalizeFilePath('includes/preloader.html');
?>

<!--Main Content-->
Expand Down Expand Up @@ -82,7 +85,7 @@
<?php
// Fetch and display the default category's list of items
if ($defaultCategoryId !== null) {
include 'get-products.php';
include FileUtils::normalizeFilePath('get-products.php');
}
?>
</div>
Expand All @@ -93,7 +96,7 @@


<?php
include 'billing-section.php';
include FileUtils::normalizeFilePath('billing-section.php');
?>

</div>
Expand All @@ -107,6 +110,7 @@
<script src="../vendor/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<!--Custom JavaScript/jQuery-->
<script src="javascript/get-products.js"></script>
<script src="javascript/preloader.js"></script>

</body>
</html>
Expand Down
4 changes: 3 additions & 1 deletion src/delete-account.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
// Include the database connection file
require_once 'includes/db-connector.php';
include_once str_replace('/', DIRECTORY_SEPARATOR, 'includes/file-utilities.php');
require_once FileUtils::normalizeFilePath('includes/db-connector.php');
include_once FileUtils::normalizeFilePath('includes/error-reporting.php');

// Check if account IDs are provided
if (isset($_POST['accountIds']) && is_array($_POST['accountIds'])) {
Expand Down
5 changes: 4 additions & 1 deletion src/delete-sale.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
// Include the database connection file
require_once 'includes/db-connector.php';
include_once str_replace('/', DIRECTORY_SEPARATOR, 'includes/file-utilities.php');
require_once FileUtils::normalizeFilePath('includes/db-connector.php');
include_once FileUtils::normalizeFilePath('includes/error-reporting.php');

// Check if account IDs are provided
if (isset($_POST['saleIds']) && is_array($_POST['saleIds'])) {
// Get the account IDs from the POST data
Expand Down
4 changes: 3 additions & 1 deletion src/get-product-details.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
// Include necessary files and connect to the database
require_once 'includes/db-connector.php';
include_once str_replace('/', DIRECTORY_SEPARATOR, 'includes/file-utilities.php');
require_once FileUtils::normalizeFilePath('includes/db-connector.php');
include_once FileUtils::normalizeFilePath('includes/error-reporting.php');

// Check if the required parameters are present
if(isset($_POST['productId']) && isset($_POST['productType'])) {
Expand Down
4 changes: 3 additions & 1 deletion src/get-products.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
require_once 'includes/db-connector.php';
include_once str_replace('/', DIRECTORY_SEPARATOR, 'includes/file-utilities.php');
require_once FileUtils::normalizeFilePath('includes/db-connector.php');
include_once FileUtils::normalizeFilePath('includes/error-reporting.php');

if(isset($_POST['category'])) {
$categoryId = $_POST['category'];
Expand Down
4 changes: 4 additions & 0 deletions src/includes/db-connector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php

include_once str_replace('/', DIRECTORY_SEPARATOR, 'file-utilities.php');
include_once FileUtils::normalizeFilePath('error-reporting.php');

// Creates connection to the database
$server = "localhost";
$username = "root";
Expand Down
19 changes: 19 additions & 0 deletions src/includes/error-reporting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

include_once str_replace('/', DIRECTORY_SEPARATOR, 'file-utilities.php');
include_once FileUtils::normalizeFilePath('default-timezone.php');

error_reporting(E_ALL);
ini_set("display_errors", 0);

function logErrors($errno, $errstr, $errfile, $errline) {

// Relative file path
$log_directory = __DIR__ . "/error-logs.txt";
$timestamp = date('Y-m-d g:i a');
$log_message = "$timestamp Error: [$errno] $errstr - $errfile: $errline";
error_log($log_message . PHP_EOL, 3, $log_directory);

}

set_error_handler("logErrors");
4 changes: 3 additions & 1 deletion src/includes/execute-prediction-script.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
include_once 'default-timezone.php';
include_once str_replace('/', DIRECTORY_SEPARATOR, 'file-utilities.php');
include_once FileUtils::normalizeFilePath('default-timezone.php');
include_once FileUtils::normalizeFilePath('error-reporting.php');

function should_execute_script() {
// Get the current day of the week
Expand Down
20 changes: 20 additions & 0 deletions src/includes/file-utilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* File function utilities.
*
*/
class FileUtils
{
/**
* Replace forward slashes with appropriate directory separator in a file path for current operating system.
*
* @param string $path The file path to transform.
* @return string The transformed file path.
*/
public static function normalizeFilePath($path)
{

return str_replace('/', DIRECTORY_SEPARATOR, $path);
}
}
48 changes: 48 additions & 0 deletions src/includes/login-authenticator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
include_once str_replace('/', DIRECTORY_SEPARATOR, 'file-utilities.php');
require_once FileUtils::normalizeFilePath('session-handler.php');
require_once FileUtils::normalizeFilePath('db-connector.php');
include_once FileUtils::normalizeFilePath('error-reporting.php');

if(isset($_POST['sign_in_btn'])) {

$username = $_POST['username'];
$password = $_POST['password'];

if(empty($username) || empty($password)) {
$_SESSION['error_message'] = 'Please do not leave the input fields empty.';
header("Location: ../login.php");
exit();
}

// Query the user table for the entered username
$stmt = $db->prepare("SELECT id, username, password FROM user WHERE BINARY username = ?");
$stmt->bind_param('s', $username);
$stmt->execute();
$result = $stmt->get_result();

// Check if a user of this username exists
if($result->num_rows > 0) {
$row = $result->fetch_assoc();

// Verify if password match the entered username
if (password_verify($password, $row['password'])) {
$_SESSION['id'] = $row['id'];
session_regenerate_id(true);
header("location: ../index.php");
exit();
}
// If username and password mismatched, display this
else {
$_SESSION['error_message'] = 'Username and password mismatched.';
header("Location: ../login.php");
exit();
}
}
// If there is no user with the username, display this
else {
$_SESSION['error_message'] = 'User is not found.';
header("Location: ../login.php");
exit();
}
}
9 changes: 9 additions & 0 deletions src/includes/logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
include_once str_replace('/', DIRECTORY_SEPARATOR, 'file-utilities.php');
require_once FileUtils::normalizeFilePath('session-handler.php');
include_once FileUtils::normalizeFilePath('error-reporting.php');

session_destroy();
header("location: ../login.php");
exit();
?>
4 changes: 3 additions & 1 deletion src/includes/mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require __DIR__ . "/../../vendor/autoload.php";
include_once str_replace('/', DIRECTORY_SEPARATOR, 'file-utilities.php');
require FileUtils::normalizeFilePath(__DIR__ . "/../../vendor/autoload.php");
include_once FileUtils::normalizeFilePath('error-reporting.php');

// CONFIGURATION

Expand Down
6 changes: 4 additions & 2 deletions src/includes/navbar.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
require_once 'includes/db-connector.php';
include_once str_replace('/', DIRECTORY_SEPARATOR, 'file-utilities.php');
require_once FileUtils::normalizeFilePath('includes/db-connector.php');
include_once FileUtils::normalizeFilePath('error-reporting.php');

// Query user table to display the current user
$sql = $db->prepare("SELECT id, first_name FROM user WHERE id = ?");
Expand Down Expand Up @@ -73,7 +75,7 @@
</svg>
Accounts</a>
</li>
<li><a class="dropdown-item" href="logout.php">
<li><a class="dropdown-item" href="includes/logout.php">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-box-arrow-in-left" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M10 3.5a.5.5 0 0 0-.5-.5h-8a.5.5 0 0 0-.5.5v9a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-2a.5.5 0 0 1 1 0v2A1.5 1.5 0 0 1 9.5 14h-8A1.5 1.5 0 0 1 0 12.5v-9A1.5 1.5 0 0 1 1.5 2h8A1.5 1.5 0 0 1 11 3.5v2a.5.5 0 0 1-1 0z"/>
<path fill-rule="evenodd" d="M4.146 8.354a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L5.707 7.5H14.5a.5.5 0 0 1 0 1H5.707l2.147 2.146a.5.5 0 0 1-.708.708z"/>
Expand Down
5 changes: 5 additions & 0 deletions src/includes/preloader.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="spinner-wrapper">
<div class="spinner-border text-tiger-orange" role="status">
<span class="visually-hidden"></span>
</div>
</div>
5 changes: 3 additions & 2 deletions src/includes/process-reset-password.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

require_once 'db-connector.php';
include_once str_replace('/', DIRECTORY_SEPARATOR, 'file-utilities.php');
require_once FileUtils::normalizeFilePath('db-connector.php');
include_once FileUtils::normalizeFilePath('error-reporting.php');

$token = $_POST["token"];
$token_hash = hash("sha256", $token);
Expand Down
8 changes: 5 additions & 3 deletions src/includes/send-password-reset.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

require_once 'db-connector.php';
require_once 'session-handler.php';
include_once str_replace('/', DIRECTORY_SEPARATOR, 'file-utilities.php');
require_once FileUtils::normalizeFilePath('db-connector.php');
require_once FileUtils::normalizeFilePath('session-handler.php');
include_once FileUtils::normalizeFilePath('error-reporting.php');
include_once FileUtils::normalizeFilePath('default-timezone.php');

if(!isset($_POST['send-email-btn'])) {
$_SESSION['error_message'] = 'Something went wrong.';
Expand Down
3 changes: 3 additions & 0 deletions src/includes/session-handler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php
include_once str_replace('/', DIRECTORY_SEPARATOR, 'file-utilities.php');
include_once FileUtils::normalizeFilePath('default-timezone.php');
include_once FileUtils::normalizeFilePath('error-reporting.php');

ini_set('session.use_only_cookies', 1);
ini_set('session.use_strict_mode', 1);
Expand Down
Loading

0 comments on commit 8620adc

Please sign in to comment.