vdp

Untitled

vdp
Jul 31st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.52 KB | None | 0 0
  1. <?php
  2. include("rupiah.php");
  3. $host = "localhost";
  4. $database = "kshop";
  5. $user = "root";
  6. $password = "";
  7. $db =mysqli_connect("$host","$user","$password","$database");
  8.  
  9. //gettting IP Address
  10. function getRealIpAddress()
  11. {
  12.     if(!empty($_SERVER['HTTP_CLIENT_IP']))      // check ip FROM share internet
  13.     {
  14.         $ip = $_SERVER['HTTP_CLIENT_IP'];
  15.     }
  16.     else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //check if IP is passed FROM  proxy
  17.     {
  18.         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  19.     }
  20.     else
  21.     {
  22.         $ip = $_SERVER['REMOTE_ADDR'];
  23.     }
  24.  
  25.     return $ip;
  26. }
  27. function getDefault()
  28. {
  29.     global $db;
  30.  
  31.     $c= $_SESSION['customer_email'];
  32.  
  33.     $get_c = "SELECT * FROM `customers` WHERE `customer_email`='$c'";
  34.  
  35.     echo "<script>alert('default customerid $get_c ') </script>";
  36.     $run_c=mysqli_query($db,$get_c);
  37.     $row_c = mysqli_fetch_array($run_c);
  38.     $customer_id=$row_c['customer_id'];
  39.  
  40.     if(!isSET($_GET['my_orders'])){
  41.         if(!isSET($_GET['edit_account'])){
  42.             if(!isSET($_GET['change_pass'])){
  43.                 if(!isSET($_GET['delete_account'])){
  44.  
  45.                     $get_orders= "SELECT * FROM `customer_orders` WHERE `customer_id`='$customer_id' AND `order_status`='pending'";
  46.                     $run_orders=mysqli_query($db,$get_orders);
  47.                     $count_orders = mysqli_num_rows($run_orders);
  48.  
  49.                     if($count_orders>0)
  50.                     {
  51.                         echo "
  52.                         <div style='padding:10px'>
  53.                         <h1 style='color:red;'> Important!!</h1>
  54.  
  55.                         <h2> You Have $count_orders pending orders.</h3>
  56.                         <h3> Please see your orders details by clicking this <a href='my_account.php?my_orders'> LINK </a>
  57.                         </h3>
  58.  
  59.  
  60.                         </div>
  61.                         ";
  62.  
  63.                     }
  64.                     else
  65.                     {
  66.                         echo "
  67.                         <div style='padding:10px'>
  68.                         <br> </br>
  69.  
  70.                         <h2 style='color:red;'> You Have NO pending orders.</h3>
  71.                         <h3> You can see your order history by clicking this <a href='my_account.php?my_orders'> LINK </a>
  72.                         <br>  </h3>
  73.                         </div>
  74.                         ";
  75.                     }
  76.  
  77.  
  78.                 }
  79.             }
  80.         }
  81.     }
  82.  
  83.  
  84.  
  85. }//function
  86. // creating a script for cart
  87. function cart()
  88. {
  89.     if(isSET($_GET['add_cart']))
  90.     {
  91.         global $db;
  92.         $p_id = $_GET['add_cart'];
  93.         $ip_add = getRealIpAddress();
  94.  
  95.  
  96.  
  97.         $check_product = "SELECT * FROM `cart` WHERE `ip_add` = '$ip_add' AND `p_id` ='$p_id'";
  98.  
  99.         $run_check = mysqli_query($db, $check_product);
  100.  
  101.         $row_pro = mysqli_fetch_array($run_check);
  102.         $quan = $row_pro[2];
  103.  
  104.         //This means item already exists in the cart.. simply incremenet the quanitity
  105.         if($quan > 0)
  106.         {
  107.             $quan++;
  108.             $increment_qty = "UPDATE `cart` SET `qty`='$quan' WHERE `ip_add`='$ip_add' AND `p_id`='$p_id'";
  109.             $run_qty = mysqli_query($db, $increment_qty);
  110.             //echo "<script>alert('Successul')</script>";
  111.             echo "<script>alert('Same Product Added. Quantity incremented.')</script>";
  112.         }
  113.         else
  114.         {
  115.             $ip_add = getRealIpAddress();
  116.  
  117.             echo "<script>alert('Product has been added.')</script>";
  118.  
  119.             $query = "INSERT INTO `cart` (`p_id`,`ip_add`,`qty`) VALUES ('$p_id ','$ip_add',1)";
  120.  
  121.             $run_query = mysqli_query($db, $query);
  122.             echo "<script>window.open('index.php','_self')</script>";
  123.         }
  124.  
  125.     }// outer if
  126. }
  127.  
  128. // get number of items FROM cart
  129. function itemsFromCart()
  130. {
  131.     if(!isSET($_GET['add_cat']))
  132.     {
  133.         global $db;
  134.  
  135.         $ip_add = getRealIpAddress();
  136.         $get_items = "SELECT * FROM `cart` WHERE `ip_add` = '$ip_add'";
  137.  
  138.         $run_items = mysqli_query($db, $get_items);
  139.         $count_items =  mysqli_num_rows($run_items);
  140.     }
  141.     else
  142.     {
  143.         global $db;
  144.         $ip_add = getRealIpAddress();
  145.         $get_items = "SELECT * FROM `cart` WHERE `ip_add` = '$ip_add'";
  146.  
  147.         $run_items = mysqli_query($db, $get_items);
  148.         $count_items =  mysqli_num_rows($run_items);
  149.     }
  150.  
  151.     echo $count_items;
  152. }
  153.  
  154. //get total price for items in cart
  155. function getTotalPrice()
  156. {
  157.     $ip_add = getRealIpAddress();
  158.  
  159.     global $db;
  160.  
  161.     $total =0;
  162.  
  163.  
  164.     $SELECT_price = "SELECT * FROM `cart` WHERE `ip_add` = '$ip_add'";
  165.  
  166.     $run_price = mysqli_query($db, $SELECT_price);
  167.  
  168.     //$row_quantity = mysqli_fetch_array($run_check);
  169.     //$qty = $row_quantity[2];
  170.  
  171.     while($record=mysqli_fetch_array($run_price))
  172.     {
  173.         $product_id = $record['p_id'];
  174.         $qty=$record[2];
  175.  
  176.         $prod_price = "SELECT * FROM `products` WHERE `product_id` = '$product_id'";
  177.  
  178.         $run_product_price = mysqli_query($db, $prod_price);
  179.  
  180.         while($p_price=mysqli_fetch_array($run_product_price))
  181.         {
  182.             $product_price = array($p_price['product_price']); //get product price FROM table column in DB
  183.             $value = array_sum($product_price); // sum all the values
  184.             $total += $value*$qty;
  185.         }
  186.  
  187.     }
  188.     return $total;
  189. }
  190.  
  191. //This is what user sees when they go to their account// default look
  192.  
  193. //get products to display
  194. function getPro()
  195. {
  196.     global $db;
  197.  
  198.     if(!isSET($_GET['cat'])){
  199.  
  200.         if(!isSET($_GET['brand'])){
  201.  
  202.             $get_products = "SELECT * FROM `products` order by rand() LIMIT 0,6";
  203.             $run_products = mysqli_query($db, $get_products);
  204.  
  205.             while($row_products= mysqli_fetch_array($run_products))
  206.             {
  207.                 $pro_id = $row_products['product_id'];
  208.                 $pro_title = $row_products['product_title'];
  209.                 $pro_cat = $row_products['cat_id'];
  210.                 $pro_brand = $row_products['brand_id'];
  211.                 $pro_desc = $row_products['product_desc'];
  212.                 $pro_price = rupiah($row_products['product_price']);
  213.                 $pro_image = $row_products['product_img1'];
  214.  
  215.                 echo "
  216.                 <div class='col-sm-4'>
  217.                 <h3>$pro_title</h3><br>
  218.  
  219.                 <img src='admin_area/product_images/$pro_image' width='200' height='180'/><br>
  220.                 <p><b>Price: $pro_price</b></p>
  221.                 <a href='details.php?pro_id=$pro_id' class='btn btn-default' style='float:left;'><i class='fa fa-eye'></i>&nbsp;Details</a>
  222.                 <a href='index.php?add_cart=$pro_id'><button class='btn btn-success' style='float:right;'><i class='fa fa-shopping-cart'></i>&nbsp;Add to Cart</button></a>
  223.  
  224.                 </div>
  225.  
  226.                 ";
  227.             }//while
  228.         }//inner if
  229.  
  230.     }//if
  231. }
  232.  
  233. //get category products
  234. function getCatPro()
  235. {
  236.     global $db;
  237.  
  238.     if(isSET($_GET['cat']))
  239.     {
  240.  
  241.         $cat_id = $_GET['cat']; //getting and assigning cat id FROM database
  242.         $get_cat_pro = "SELECT * FROM `products` WHERE `cat_id` ='$cat_id'";
  243.  
  244.         $run_cat_pro = mysqli_query($db, $get_cat_pro);
  245.  
  246.         $count = mysqli_num_rows($run_cat_pro);
  247.         if($count==0)
  248.         {
  249.             echo "<h1>No Products found in this category!</h1>";
  250.         }
  251.  
  252.         while($row_cat_pro= mysqli_fetch_array($run_cat_pro))
  253.         {
  254.             $pro_id = $row_cat_pro['product_id'];
  255.             $pro_title = $row_cat_pro['product_title'];
  256.             $pro_cat = $row_cat_pro['cat_id'];
  257.             $pro_brand = $row_cat_pro['brand_id'];
  258.             $pro_desc = $row_cat_pro['product_desc'];
  259.             $pro_price = rupiah($row_cat_pro['product_price']);
  260.             $pro_image = $row_cat_pro['product_img1'];
  261.  
  262.             echo "
  263.             <div class='col-sm-4'>
  264.             <h3>$pro_title</h3><br>
  265.  
  266.             <img src='admin_area/product_images/$pro_image' width='200' height='180'/><br>
  267.             <p><b>Price: $pro_price</b></p>
  268.             <a href='details.php?pro_id=$pro_id' class='btn btn-default' style='float:left;'><i class='fa fa-eye'></i>&nbsp;Details</a>
  269.             <a href='index.php?add_cart=$pro_id'><button class='btn btn-success' style='float:right;'><i class='fa fa-shopping-cart'></i>&nbsp;Add to Cart</button></a>
  270.  
  271.             </div>
  272.  
  273.             ";
  274.  
  275.         }//while
  276.  
  277.     }//if
  278. }
  279.  
  280. //get bran products
  281. function getBrandPro()
  282. {
  283.     global $db;
  284.  
  285.     if(isSET($_GET['brand']))
  286.     {
  287.  
  288.         $brand_id = $_GET['brand']; //getting and assigning cat id FROM database
  289.         $get_brand_pro = "SELECT * FROM `products` WHERE `brand_id` ='$brand_id'";
  290.  
  291.         $run_brand_pro = mysqli_query($db, $get_brand_pro);
  292.  
  293.         $count = mysqli_num_rows($run_brand_pro);
  294.         if($count==0)
  295.         {
  296.             echo "<h1>No Products found under this brand!</h1>";
  297.         }
  298.  
  299.         while($row_brand_pro= mysqli_fetch_array($run_brand_pro))
  300.         {
  301.             $pro_id = $row_brand_pro['product_id'];
  302.             $pro_title = $row_brand_pro['product_title'];
  303.             $pro_cat = $row_brand_pro['cat_id'];
  304.             $pro_brand = $row_brand_pro['brand_id'];
  305.             $pro_desc = $row_brand_pro['product_desc'];
  306.             $pro_price = rupiah($row_brand_pro['product_price']);
  307.             $pro_image = $row_brand_pro['product_img1'];
  308.  
  309.             echo "
  310.             <div class='col-sm-4'>
  311.             <h3>$pro_title</h3><br>
  312.  
  313.             <img src='admin_area/product_images/$pro_image' width='200' height='180'/><br>
  314.             <p><b>Price: $pro_price</b></p>
  315.             <a href='details.php?pro_id=$pro_id' class='btn btn-default' style='float:left;'><i class='fa fa-eye'></i>&nbsp;Details</a>
  316.             <a href='index.php?add_cart=$pro_id'><button class='btn btn-success' style='float:right;'><i class='fa fa-shopping-cart'></i>&nbsp;Add to Cart</button></a>
  317.  
  318.             </div>
  319.  
  320.             ";
  321.         }//while
  322.  
  323.     }//if
  324. }
  325.  
  326.  
  327.  
  328. //get the brands to display
  329. function getBrands()
  330. {
  331.     global $db;
  332.  
  333.     $get_brand = "SELECT * FROM `brands`";
  334.     $run_brand = mysqli_query($db, $get_brand);
  335.     $brand=NULL;
  336.     if(isSET($_GET['brand'])){
  337.         $brand= $_GET['brand'];
  338.     }
  339.     while($row_brand = mysqli_fetch_array($run_brand)){
  340.         $brand_id= $row_brand['brand_id'];
  341.         $brand_title= $row_brand['brand_title'];
  342.         if($brand_id==$brand){
  343.             echo "<li style='background:#ea4335;'><a style='color:#ffffff' href='index.php?brand=$brand_id'>$brand_title</a></li>";
  344.         }else{
  345.             echo "<li><a href='index.php?brand=$brand_id'>$brand_title</a></li>";
  346.         }
  347.     }
  348. }
  349.  
  350. //get categories to display
  351. function getCategories()
  352. {
  353.     global $db;
  354.     $get_category = "SELECT * FROM `categories`";
  355.     $run_category = mysqli_query($db, $get_category);
  356.     $cat=NULL;
  357.     if(isSET($_GET['cat'])){
  358.         $cat = $_GET['cat'];
  359.     }
  360.     while($row_category = mysqli_fetch_array($run_category)){
  361.         $cat_id= $row_category['cat_id'];
  362.         $cat_title= $row_category['cat_title'];
  363.         if($cat_id==$cat){
  364.             echo "<li style='background:#ea4335;'><a style='color:#ffffff' href='index.php?cat=$cat_id'>$cat_title</a></li>";
  365.         }else{
  366.             echo "<li><a href='index.php?cat=$cat_id'>$cat_title</a></li>";
  367.         }
  368.     }
  369. }
  370.  
  371. ?>
Add Comment
Please, Sign In to add comment