Skip to content

Commit

Permalink
PHP files for the components set in the website page such footer, hea…
Browse files Browse the repository at this point in the history
…der,login, logout, wish list, and connection to database -fixes #6
  • Loading branch information
aya250 committed Apr 24, 2023
1 parent a674cf8 commit 929096f
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 0 deletions.
51 changes: 51 additions & 0 deletions ecommerce-website/components/admin_header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
if(isset($message)){
foreach($message as $message){
echo '
<div class="message">
<span>'.$message.'</span>
<i class="fas fa-times" onclick="this.parentElement.remove();"></i>
</div>
';
}
}
?>

<header class="header">

<section class="flex">

<a href="../admin/dashboard.php" class="logo">Admin<span>Panel</span></a>

<nav class="navbar">
<a href="../admin/dashboard.php">home</a>
<a href="../admin/products.php">products</a>
<a href="../admin/placed_orders.php">orders</a>
<a href="../admin/admin_accounts.php">admins</a>
<a href="../admin/users_accounts.php">users</a>
<a href="../admin/messages.php">messages</a>
</nav>

<div class="icons">
<div id="menu-btn" class="fas fa-bars"></div>
<div id="user-btn" class="fas fa-user"></div>
</div>

<div class="profile">
<?php
$select_profile = $conn->prepare("SELECT * FROM `admins` WHERE id = ?");
$select_profile->execute([$admin_id]);
$fetch_profile = $select_profile->fetch(PDO::FETCH_ASSOC);
?>
<p><?= $fetch_profile['name']; ?></p>
<a href="../admin/update_profile.php" class="btn">update profile</a>
<div class="flex-btn">
<a href="../admin/register_admin.php" class="option-btn">register</a>
<a href="../admin/admin_login.php" class="option-btn">login</a>
</div>
<a href="../components/admin_logout.php" class="delete-btn" onclick="return confirm('logout from the website?');">logout</a>
</div>

</section>

</header>
11 changes: 11 additions & 0 deletions ecommerce-website/components/admin_logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

include 'connect.php';

session_start();
session_unset();
session_destroy();

header('location:../admin/admin_login.php');

?>
9 changes: 9 additions & 0 deletions ecommerce-website/components/connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$db_name = 'mysql:host=localhost;dbname=shop_db';
$user_name = 'root';
$user_password = '';

$conn = new PDO($db_name, $user_name, $user_password);

?>
23 changes: 23 additions & 0 deletions ecommerce-website/components/footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<footer class="footer">

<section class="grid">
<div class="box">
<h3>quick links</h3>
<a href="home.php"> <i class="fas fa-angle-right"></i> Home</a>
<a href="about.php"> <i class="fas fa-angle-right"></i> About</a>
<a href="shop.php"> <i class="fas fa-angle-right"></i> Shop</a>
<a href="contact.php"> <i class="fas fa-angle-right"></i> Contact</a>
</div>
<div class="box">
<h3>extra links</h3>
<a href="user_login.php"> <i class="fas fa-angle-right"></i> Login</a>
<a href="user_register.php"> <i class="fas fa-angle-right"></i> Register</a>
<a href="cart.php"> <i class="fas fa-angle-right"></i> Cart</a>
<a href="orders.php"> <i class="fas fa-angle-right"></i> Orders</a>
</div>
</section>
</footer>
76 changes: 76 additions & 0 deletions ecommerce-website/components/user_header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
if(isset($message)){
foreach($message as $message){
echo '
<div class="message">
<span>'.$message.'</span>
<i class="fas fa-times" onclick="this.parentElement.remove();"></i>
</div>
';
}
}
?>

<header class="header">

<section class="flex">

<a href="home.php" class="logo">Warehouse Robot Mini-Shop<span>.</span></a>

<nav class="navbar">
<a href="home.php">Home</a>
<a href="about.php">About</a>
<a href="orders.php">Orders</a>
<a href="shop.php">Shop</a>
<a href="contact.php">Contact</a>
</nav>

<div class="icons">
<?php
$count_wishlist_items = $conn->prepare("SELECT * FROM `wishlist` WHERE user_id = ?");
$count_wishlist_items->execute([$user_id]);
$total_wishlist_counts = $count_wishlist_items->rowCount();

$count_cart_items = $conn->prepare("SELECT * FROM `cart` WHERE user_id = ?");
$count_cart_items->execute([$user_id]);
$total_cart_counts = $count_cart_items->rowCount();
?>
<div id="menu-btn" class="fas fa-bars"></div>
<a href="search_page.php"><i class="fas fa-search"></i></a>
<a href="wishlist.php"><i class="fas fa-heart"></i><span>(<?= $total_wishlist_counts; ?>)</span></a>
<a href="cart.php"><i class="fas fa-shopping-cart"></i><span>(<?= $total_cart_counts; ?>)</span></a>
<div id="user-btn" class="fas fa-user"></div>
</div>

<div class="profile">
<?php
$select_profile = $conn->prepare("SELECT * FROM `users` WHERE id = ?");
$select_profile->execute([$user_id]);
if($select_profile->rowCount() > 0){
$fetch_profile = $select_profile->fetch(PDO::FETCH_ASSOC);
?>
<p><?= $fetch_profile["name"]; ?></p>
<a href="update_user.php" class="btn">update profile</a>
<div class="flex-btn">
<a href="user_register.php" class="option-btn">register</a>
<a href="user_login.php" class="option-btn">login</a>
</div>
<a href="components/user_logout.php" class="delete-btn" onclick="return confirm('logout from the website?');">logout</a>
<?php
}else{
?>
<p>please login or register first!</p>
<div class="flex-btn">
<a href="user_register.php" class="option-btn">register</a>
<a href="user_login.php" class="option-btn">login</a>
</div>
<?php
}
?>


</div>

</section>

</header>
11 changes: 11 additions & 0 deletions ecommerce-website/components/user_logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

include 'connect.php';

session_start();
session_unset();
session_destroy();

header('location:../home.php');

?>
80 changes: 80 additions & 0 deletions ecommerce-website/components/wishlist_cart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

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

if($user_id == ''){
header('location:user_login.php');
}else{

$pid = $_POST['pid'];
$pid = filter_var($pid, FILTER_SANITIZE_STRING);
$name = $_POST['name'];
$name = filter_var($name, FILTER_SANITIZE_STRING);
$price = $_POST['price'];
$price = filter_var($price, FILTER_SANITIZE_STRING);
$image = $_POST['image'];
$image = filter_var($image, FILTER_SANITIZE_STRING);

$check_wishlist_numbers = $conn->prepare("SELECT * FROM `wishlist` WHERE name = ? AND user_id = ?");
$check_wishlist_numbers->execute([$name, $user_id]);

$check_cart_numbers = $conn->prepare("SELECT * FROM `cart` WHERE name = ? AND user_id = ?");
$check_cart_numbers->execute([$name, $user_id]);

if($check_wishlist_numbers->rowCount() > 0){
$message[] = 'already added to wishlist!';
}elseif($check_cart_numbers->rowCount() > 0){
$message[] = 'already added to cart!';
}else{
$insert_wishlist = $conn->prepare("INSERT INTO `wishlist`(user_id, pid, name, price, image) VALUES(?,?,?,?,?)");
$insert_wishlist->execute([$user_id, $pid, $name, $price, $image]);
$message[] = 'added to wishlist!';
}

}

}

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

if($user_id == ''){
header('location:user_login.php');
}else{

$pid = $_POST['pid'];
$pid = filter_var($pid, FILTER_SANITIZE_STRING);
$name = $_POST['name'];
$name = filter_var($name, FILTER_SANITIZE_STRING);
$price = $_POST['price'];
$price = filter_var($price, FILTER_SANITIZE_STRING);
$image = $_POST['image'];
$image = filter_var($image, FILTER_SANITIZE_STRING);
$qty = $_POST['qty'];
$qty = filter_var($qty, FILTER_SANITIZE_STRING);

$check_cart_numbers = $conn->prepare("SELECT * FROM `cart` WHERE name = ? AND user_id = ?");
$check_cart_numbers->execute([$name, $user_id]);

if($check_cart_numbers->rowCount() > 0){
$message[] = 'already added to cart!';
}else{

$check_wishlist_numbers = $conn->prepare("SELECT * FROM `wishlist` WHERE name = ? AND user_id = ?");
$check_wishlist_numbers->execute([$name, $user_id]);

if($check_wishlist_numbers->rowCount() > 0){
$delete_wishlist = $conn->prepare("DELETE FROM `wishlist` WHERE name = ? AND user_id = ?");
$delete_wishlist->execute([$name, $user_id]);
}

$insert_cart = $conn->prepare("INSERT INTO `cart`(user_id, pid, name, price, quantity, image) VALUES(?,?,?,?,?,?)");
$insert_cart->execute([$user_id, $pid, $name, $price, $qty, $image]);
$message[] = 'added to cart!';

}

}

}

?>

0 comments on commit 929096f

Please sign in to comment.