Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("rupiah.php");
- $host = "localhost";
- $database = "kshop";
- $user = "root";
- $password = "";
- $db =mysqli_connect("$host","$user","$password","$database");
- //gettting IP Address
- function getRealIpAddress()
- {
- if(!empty($_SERVER['HTTP_CLIENT_IP'])) // check ip FROM share internet
- {
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- }
- else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //check if IP is passed FROM proxy
- {
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
- }
- else
- {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- return $ip;
- }
- function getDefault()
- {
- global $db;
- $c= $_SESSION['customer_email'];
- $get_c = "SELECT * FROM `customers` WHERE `customer_email`='$c'";
- echo "<script>alert('default customerid $get_c ') </script>";
- $run_c=mysqli_query($db,$get_c);
- $row_c = mysqli_fetch_array($run_c);
- $customer_id=$row_c['customer_id'];
- if(!isSET($_GET['my_orders'])){
- if(!isSET($_GET['edit_account'])){
- if(!isSET($_GET['change_pass'])){
- if(!isSET($_GET['delete_account'])){
- $get_orders= "SELECT * FROM `customer_orders` WHERE `customer_id`='$customer_id' AND `order_status`='pending'";
- $run_orders=mysqli_query($db,$get_orders);
- $count_orders = mysqli_num_rows($run_orders);
- if($count_orders>0)
- {
- echo "
- <div style='padding:10px'>
- <h1 style='color:red;'> Important!!</h1>
- <h2> You Have $count_orders pending orders.</h3>
- <h3> Please see your orders details by clicking this <a href='my_account.php?my_orders'> LINK </a>
- </h3>
- </div>
- ";
- }
- else
- {
- echo "
- <div style='padding:10px'>
- <br> </br>
- <h2 style='color:red;'> You Have NO pending orders.</h3>
- <h3> You can see your order history by clicking this <a href='my_account.php?my_orders'> LINK </a>
- <br> </h3>
- </div>
- ";
- }
- }
- }
- }
- }
- }//function
- // creating a script for cart
- function cart()
- {
- if(isSET($_GET['add_cart']))
- {
- global $db;
- $p_id = $_GET['add_cart'];
- $ip_add = getRealIpAddress();
- $check_product = "SELECT * FROM `cart` WHERE `ip_add` = '$ip_add' AND `p_id` ='$p_id'";
- $run_check = mysqli_query($db, $check_product);
- $row_pro = mysqli_fetch_array($run_check);
- $quan = $row_pro[2];
- //This means item already exists in the cart.. simply incremenet the quanitity
- if($quan > 0)
- {
- $quan++;
- $increment_qty = "UPDATE `cart` SET `qty`='$quan' WHERE `ip_add`='$ip_add' AND `p_id`='$p_id'";
- $run_qty = mysqli_query($db, $increment_qty);
- //echo "<script>alert('Successul')</script>";
- echo "<script>alert('Same Product Added. Quantity incremented.')</script>";
- }
- else
- {
- $ip_add = getRealIpAddress();
- echo "<script>alert('Product has been added.')</script>";
- $query = "INSERT INTO `cart` (`p_id`,`ip_add`,`qty`) VALUES ('$p_id ','$ip_add',1)";
- $run_query = mysqli_query($db, $query);
- echo "<script>window.open('index.php','_self')</script>";
- }
- }// outer if
- }
- // get number of items FROM cart
- function itemsFromCart()
- {
- if(!isSET($_GET['add_cat']))
- {
- global $db;
- $ip_add = getRealIpAddress();
- $get_items = "SELECT * FROM `cart` WHERE `ip_add` = '$ip_add'";
- $run_items = mysqli_query($db, $get_items);
- $count_items = mysqli_num_rows($run_items);
- }
- else
- {
- global $db;
- $ip_add = getRealIpAddress();
- $get_items = "SELECT * FROM `cart` WHERE `ip_add` = '$ip_add'";
- $run_items = mysqli_query($db, $get_items);
- $count_items = mysqli_num_rows($run_items);
- }
- echo $count_items;
- }
- //get total price for items in cart
- function getTotalPrice()
- {
- $ip_add = getRealIpAddress();
- global $db;
- $total =0;
- $SELECT_price = "SELECT * FROM `cart` WHERE `ip_add` = '$ip_add'";
- $run_price = mysqli_query($db, $SELECT_price);
- //$row_quantity = mysqli_fetch_array($run_check);
- //$qty = $row_quantity[2];
- while($record=mysqli_fetch_array($run_price))
- {
- $product_id = $record['p_id'];
- $qty=$record[2];
- $prod_price = "SELECT * FROM `products` WHERE `product_id` = '$product_id'";
- $run_product_price = mysqli_query($db, $prod_price);
- while($p_price=mysqli_fetch_array($run_product_price))
- {
- $product_price = array($p_price['product_price']); //get product price FROM table column in DB
- $value = array_sum($product_price); // sum all the values
- $total += $value*$qty;
- }
- }
- return $total;
- }
- //This is what user sees when they go to their account// default look
- //get products to display
- function getPro()
- {
- global $db;
- if(!isSET($_GET['cat'])){
- if(!isSET($_GET['brand'])){
- $get_products = "SELECT * FROM `products` order by rand() LIMIT 0,6";
- $run_products = mysqli_query($db, $get_products);
- while($row_products= mysqli_fetch_array($run_products))
- {
- $pro_id = $row_products['product_id'];
- $pro_title = $row_products['product_title'];
- $pro_cat = $row_products['cat_id'];
- $pro_brand = $row_products['brand_id'];
- $pro_desc = $row_products['product_desc'];
- $pro_price = rupiah($row_products['product_price']);
- $pro_image = $row_products['product_img1'];
- echo "
- <div class='col-sm-4'>
- <h3>$pro_title</h3><br>
- <img src='admin_area/product_images/$pro_image' width='200' height='180'/><br>
- <p><b>Price: $pro_price</b></p>
- <a href='details.php?pro_id=$pro_id' class='btn btn-default' style='float:left;'><i class='fa fa-eye'></i> Details</a>
- <a href='index.php?add_cart=$pro_id'><button class='btn btn-success' style='float:right;'><i class='fa fa-shopping-cart'></i> Add to Cart</button></a>
- </div>
- ";
- }//while
- }//inner if
- }//if
- }
- //get category products
- function getCatPro()
- {
- global $db;
- if(isSET($_GET['cat']))
- {
- $cat_id = $_GET['cat']; //getting and assigning cat id FROM database
- $get_cat_pro = "SELECT * FROM `products` WHERE `cat_id` ='$cat_id'";
- $run_cat_pro = mysqli_query($db, $get_cat_pro);
- $count = mysqli_num_rows($run_cat_pro);
- if($count==0)
- {
- echo "<h1>No Products found in this category!</h1>";
- }
- while($row_cat_pro= mysqli_fetch_array($run_cat_pro))
- {
- $pro_id = $row_cat_pro['product_id'];
- $pro_title = $row_cat_pro['product_title'];
- $pro_cat = $row_cat_pro['cat_id'];
- $pro_brand = $row_cat_pro['brand_id'];
- $pro_desc = $row_cat_pro['product_desc'];
- $pro_price = rupiah($row_cat_pro['product_price']);
- $pro_image = $row_cat_pro['product_img1'];
- echo "
- <div class='col-sm-4'>
- <h3>$pro_title</h3><br>
- <img src='admin_area/product_images/$pro_image' width='200' height='180'/><br>
- <p><b>Price: $pro_price</b></p>
- <a href='details.php?pro_id=$pro_id' class='btn btn-default' style='float:left;'><i class='fa fa-eye'></i> Details</a>
- <a href='index.php?add_cart=$pro_id'><button class='btn btn-success' style='float:right;'><i class='fa fa-shopping-cart'></i> Add to Cart</button></a>
- </div>
- ";
- }//while
- }//if
- }
- //get bran products
- function getBrandPro()
- {
- global $db;
- if(isSET($_GET['brand']))
- {
- $brand_id = $_GET['brand']; //getting and assigning cat id FROM database
- $get_brand_pro = "SELECT * FROM `products` WHERE `brand_id` ='$brand_id'";
- $run_brand_pro = mysqli_query($db, $get_brand_pro);
- $count = mysqli_num_rows($run_brand_pro);
- if($count==0)
- {
- echo "<h1>No Products found under this brand!</h1>";
- }
- while($row_brand_pro= mysqli_fetch_array($run_brand_pro))
- {
- $pro_id = $row_brand_pro['product_id'];
- $pro_title = $row_brand_pro['product_title'];
- $pro_cat = $row_brand_pro['cat_id'];
- $pro_brand = $row_brand_pro['brand_id'];
- $pro_desc = $row_brand_pro['product_desc'];
- $pro_price = rupiah($row_brand_pro['product_price']);
- $pro_image = $row_brand_pro['product_img1'];
- echo "
- <div class='col-sm-4'>
- <h3>$pro_title</h3><br>
- <img src='admin_area/product_images/$pro_image' width='200' height='180'/><br>
- <p><b>Price: $pro_price</b></p>
- <a href='details.php?pro_id=$pro_id' class='btn btn-default' style='float:left;'><i class='fa fa-eye'></i> Details</a>
- <a href='index.php?add_cart=$pro_id'><button class='btn btn-success' style='float:right;'><i class='fa fa-shopping-cart'></i> Add to Cart</button></a>
- </div>
- ";
- }//while
- }//if
- }
- //get the brands to display
- function getBrands()
- {
- global $db;
- $get_brand = "SELECT * FROM `brands`";
- $run_brand = mysqli_query($db, $get_brand);
- $brand=NULL;
- if(isSET($_GET['brand'])){
- $brand= $_GET['brand'];
- }
- while($row_brand = mysqli_fetch_array($run_brand)){
- $brand_id= $row_brand['brand_id'];
- $brand_title= $row_brand['brand_title'];
- if($brand_id==$brand){
- echo "<li style='background:#ea4335;'><a style='color:#ffffff' href='index.php?brand=$brand_id'>$brand_title</a></li>";
- }else{
- echo "<li><a href='index.php?brand=$brand_id'>$brand_title</a></li>";
- }
- }
- }
- //get categories to display
- function getCategories()
- {
- global $db;
- $get_category = "SELECT * FROM `categories`";
- $run_category = mysqli_query($db, $get_category);
- $cat=NULL;
- if(isSET($_GET['cat'])){
- $cat = $_GET['cat'];
- }
- while($row_category = mysqli_fetch_array($run_category)){
- $cat_id= $row_category['cat_id'];
- $cat_title= $row_category['cat_title'];
- if($cat_id==$cat){
- echo "<li style='background:#ea4335;'><a style='color:#ffffff' href='index.php?cat=$cat_id'>$cat_title</a></li>";
- }else{
- echo "<li><a href='index.php?cat=$cat_id'>$cat_title</a></li>";
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment