| @@ -1,40 +1,40 @@ | ||
| function addToCart(str){ | ||
| if (str ==""){ | ||
| return; | ||
| }else{ | ||
| var x = document.getElementById("quantity").value; | ||
| var y = str+" "+x; | ||
| if (window.XMLHttpRequest) { | ||
| xmlhttp = new XMLHttpRequest(); | ||
| }else{ | ||
| xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | ||
| } | ||
| xmlhttp.onreadystatechange = function(){ | ||
| if(this.readyState == 4 && this.status == 200){ | ||
| document.getElementById("txtHint").innerHTML = this.responseText; | ||
| getQuantity(str); | ||
| } | ||
| }; | ||
| xmlhttp.open("GET", "getproduct.php?q="+y,true); | ||
| xmlhttp.send(); | ||
| } | ||
| } | ||
|
|
||
| function getQuantity(ant){ | ||
| if (ant ==""){ | ||
| return; | ||
| }else{ | ||
| if (window.XMLHttpRequest) { | ||
| xmlhttp = new XMLHttpRequest(); | ||
| }else{ | ||
| xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | ||
| } | ||
| xmlhttp.onreadystatechange = function(){ | ||
| if(this.readyState == 4 && this.status == 200){ | ||
| document.getElementById("show_quantity").innerHTML = this.responseText; | ||
| } | ||
| }; | ||
| xmlhttp.open("GET", "getquantity.php?q="+ant,true); | ||
| xmlhttp.send(); | ||
| } | ||
| } |
| @@ -1,61 +1,61 @@ | ||
| <?php | ||
| /** | ||
| * Created by PhpStorm. | ||
| * User: palm | ||
| * Date: 2016-11-16 | ||
| * Time: 10:24 | ||
| */ | ||
|
|
||
| /* | ||
| * Detta program ska läsa in produkter från databasen och sammanställa dem till en lista. | ||
| * Preliminärt kommer det att generera statisk HTML, men om allt är klart till den sista sprinten så | ||
| * ska detta omvandlas till JSON för att skickas via AJAJ. | ||
| * | ||
| * TODO: Testa detta program när en webbserver är tillgänglig | ||
| */ | ||
|
|
||
| require_once 'functions.php'; | ||
| require 'template/header.php'; | ||
| require 'template/footer.php'; | ||
|
|
||
| generateHeader("Produktlista"); | ||
| $products = NULL; | ||
| if (isset($_GET["id"])) { | ||
| $id = sanitizeString($_GET["id"]); | ||
| $products = querySQL("SELECT * FROM Products WHERE category_ID = $id"); | ||
| } else { | ||
| $products = querySQL("SELECT * FROM Products"); | ||
| } | ||
|
|
||
| //echo $products; | ||
| ?> | ||
| <table class="table table-hover"> | ||
| <thead> | ||
| <tr> | ||
| <th>Produktnamn</th> | ||
| <th>Betyg</th> | ||
| <th>Pris</th> | ||
| <th>Redigera</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <?php | ||
| while ($prod = $products->fetch_assoc()) { | ||
| $org_price = $prod["price"] + $prod["price"] * $prod["vat"]; // Beräkna egentligt pris | ||
| $curr_price = $prod["current_price"] + $prod["current_price"] * $prod["vat"]; | ||
| $grade = ($prod["avg_grade"] == NULL) ? 0 : $prod["avg_grade"]; // Se till att betyg inte är NULL | ||
| if ($curr_price < $org_price) { // Markera rea :P | ||
| $curr_price = "<span class=\"text-danger\">".$curr_price."</span>"; | ||
| } | ||
| ?> | ||
| <tr> | ||
| <td><a href="viewproduct.php?id=<?=$prod["ID"]?>"><?=$prod["name"]?></a></td> | ||
| <td><?=$grade?></td> | ||
| <td><?=$curr_price?></td> | ||
| <td><a href="editproduct.php?id=<?=$prod["ID"]?>">Redigera</a></td> | ||
| </tr><?php | ||
| }?> | ||
| </tbody> | ||
| </table> | ||
| <?php | ||
| generateFooter(); |
| @@ -1,40 +1,40 @@ | ||
| function loadCart(id){ | ||
| if (id ==""){ | ||
| return; | ||
| }else{ | ||
| if (window.XMLHttpRequest) { | ||
| xmlhttp = new XMLHttpRequest(); | ||
| }else{ | ||
| xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | ||
| } | ||
| xmlhttp.onreadystatechange = function(){ | ||
| if(this.readyState == 4 && this.status == 200){ | ||
| document.getElementById("cart").innerHTML = this.responseText; | ||
| console.log("Hej"); | ||
| } | ||
| }; | ||
| xmlhttp.open("GET", "loadcart.php?q="+id,true); | ||
| console.log("1"); | ||
| xmlhttp.send(); | ||
| } | ||
| } | ||
| function deleteItem(item){ | ||
| var x = JSON.parse(item); | ||
| if (item ==""){ | ||
| console.log("Item är tomt"); | ||
| return; | ||
| }else{ | ||
| if (window.XMLHttpRequest) { | ||
| xmlhttp = new XMLHttpRequest(); | ||
| }else{ | ||
| xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | ||
| } | ||
| xmlhttp.onreadystatechange = function(){ | ||
| if(this.readyState == 4 && this.status == 200){ | ||
| loadCart(x.user_ID); | ||
| } | ||
| }; | ||
| xmlhttp.open("GET", "deleteitem.php?q="+item,true); | ||
| xmlhttp.send(); | ||
| } | ||
| } |
| @@ -0,0 +1,18 @@ | ||
| <?php | ||
| // Database specifications | ||
| $dbhost = 'utbweb.its.ltu.se'; // Our hostname | ||
| $dbname = 'paljon4db'; // name of the database (guess it's paljon4db?) | ||
| $dbuser = 'paljon-4'; // User of the database (root?) | ||
| $dbpass = 'Boden1337'; // password | ||
| $appname = "kontorsmaterial.se"; // | ||
| $connection = new mysqli($dbhost, $dbuser, $dbpass, $dbname); // Sets up new mysql connection | ||
| if ($connection->connect_error) die($connection->connect_error); // If unable to connect we end the connection | ||
|
|
||
| function querySQL($query) | ||
| { | ||
| global $connection; | ||
| $result = $connection->query($query); | ||
| if (!$result) die($connection->error); | ||
| return $result; | ||
| } | ||
| ?> |
| @@ -1,35 +1,35 @@ | ||
| <?php | ||
| require_once 'functions.php'; | ||
| require 'template/header.php'; | ||
| require 'template/footer.php'; | ||
| $email = $orgnr = $password = $name = $lastname = $securityNumber = $phonenumber = $town = $zipcode = $address1 = $address2 = $addressco = ""; | ||
| //Undviker SQL-injection | ||
| if (isset($_POST["submit"])){ | ||
| global $connection; | ||
| $title = sanitizeString($_POST["title"]); | ||
| $img = $connection->real_escape_string($_POST["img"]); | ||
|
|
||
| //Kontrollerar om alla fällt är ifyllda. | ||
| if ($title == "" || $img == ""){ | ||
| echo "Not all fields were entered correctly."; | ||
| }else{ | ||
| $query = querySQL("INSERT INTO Categories(title, img_path) VALUES ('$title', '$img')"); | ||
| } | ||
| } | ||
| generateHeader("Skapa kategori"); | ||
| ?> | ||
| <h1>Registrering</h1> | ||
| <form action = "" method = "POST"> | ||
| Kategorins namn: | ||
| <input type = "text" name = "title"/><br><br> | ||
|
|
||
| URL till standardbild: | ||
| <input type = "text" name = "img"/><br><br> | ||
|
|
||
|
|
||
| <input type = "submit" name = "submit" value = "Lägg till kategori!"/> | ||
| <hr> | ||
| </form> | ||
| <?php | ||
| generateFooter(); | ||
| ?> |
| @@ -1,21 +1,21 @@ | ||
| <?php | ||
| session_start(); | ||
| require "connect.php"; | ||
| global $connection; | ||
| $session_ID = session_ID(); | ||
| $val= $_GET['q']; | ||
| $id = $item = ""; | ||
| $val = json_decode($val, true); | ||
| echo $cart_ID = $val['ID']; | ||
| echo $item = $val['item']; | ||
| echo $user_ID = $val['user_ID']; | ||
|
|
||
| $con = $connection; | ||
| if (!$con){ | ||
| die('Could not connect: ' . mysqli_error($con)); | ||
| } | ||
|
|
||
| $sql="DELETE FROM Cart WHERE item = '$item' AND user_ID = '$user_ID' AND ID = '$cart_ID' "; // Lägg till rätt ID här... | ||
| $result = mysqli_query($con,$sql); | ||
| mysqli_close($con); | ||
| ?> |
| @@ -1,15 +1,15 @@ | ||
| <?php | ||
| require 'functions.php'; | ||
| $error_str = "Kunde inte hitta någon product med ID: "; | ||
| if(isset($_GET["id"])) { | ||
| $id = sanitizeString($_GET["id"]); | ||
| querySQL("DELETE FROM Products WHERE ID = $id"); | ||
| global $connection; | ||
| if($connection->affected_rows > 0) { | ||
| echo "Produkten är borttagen!"; | ||
| } else { | ||
| echo $error_str.$id; | ||
| } | ||
| } else { | ||
| echo $error_str.$id; | ||
| } |
| @@ -1,111 +1,111 @@ | ||
| <?php | ||
| require_once 'functions.php'; | ||
| require 'template/header.php'; | ||
| require 'template/footer.php'; | ||
| global $connection; | ||
| $email = $orgnr = $password = $name = $lastname = $securityNumber = $phonenumber = $town = $zipcode = $address1 = $address2 = $addressco = ""; | ||
| //Undviker SQL-injection | ||
| if (isset($_POST["submit"])){ | ||
| $id = sanitizeString($_POST["id"]); | ||
| $_GET["id"] = $id; | ||
| $pname = sanitizeString($_POST["pname"]); | ||
| $quantity = sanitizeString($_POST["quantity"]); | ||
| $desc = $connection->real_escape_string($_POST["desc"]); | ||
| $price = sanitizeString($_POST["price"]); | ||
| $cprice = sanitizeString($_POST["cprice"]); | ||
| $vat = sanitizeString($_POST["vat"]); | ||
| $cat = sanitizeString($_POST["cat"]); | ||
| $img = sanitizeString($_POST["img"]); | ||
| $imgid = sanitizeString($_POST["imgid"]); | ||
| // $address2 = sanitizeString($_POST['address2']); | ||
| // $addressco = sanitizeString($_POST['addressco']); | ||
| //Kontrollerar om alla fällt är ifyllda. | ||
| if ($pname == "" || $quantity < 0 || $desc =="" || $price < 0 || $vat == "" || $cat == "") { | ||
| echo "Not all fields were entered correctly."; | ||
| }else{ | ||
| $query = querySQL("UPDATE Products SET name = '$pname', quantity = $quantity, description = '$desc', price = $price, vat = $vat, current_price = $cprice, category_ID = $cat WHERE ID = $id;"); | ||
| if (strlen($img)) { | ||
| querySQL("UPDATE Images SET path = '$img' WHERE ID = $imgid"); | ||
| } else { | ||
| querySQL("UPDATE Products SET preview = NULL WHERE ID = $id"); | ||
| } | ||
| } | ||
| } | ||
| if(!isset($_GET["id"])) { | ||
| die("Inget ID funnet!"); | ||
| } | ||
| $id = $_GET["id"]; | ||
| generateHeader("Lägg till produkt"); | ||
| $result = querySQL("SELECT name, quantity, description, price, vat, current_price, category_ID FROM Products WHERE ID = $id"); | ||
| if($result->num_rows != 1) { | ||
| die("Inget giltigt ID funnet!"); | ||
| } | ||
| $res = $result->fetch_assoc(); | ||
| ?> | ||
| <script> | ||
| function isNumber(evt) { | ||
| evt = (evt) ? evt : window.event; | ||
| var charCode = (evt.which) ? evt.which : evt.keyCode; | ||
| if (charCode > 31 && (charCode < 48 || charCode > 57)) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| </script> | ||
| <h1>Registrering</h1> | ||
| <form action = "" method = "POST"> | ||
| Produktnamn: | ||
| <input type = "text" name = "pname" value="<?=$res["name"]?>"/><br><br> | ||
|
|
||
| Ursprungligt lagersaldo: | ||
| <input type = "text" name = "quantity" onkeypress="return isNumber(event)" maxlength = "4" size = "4" value="<?=$res["quantity"]?>"/><br><br> | ||
|
|
||
| Produktbeskrivning (tillåter HTML): | ||
| <textarea name="desc" cols="40" rows="10"><?=$res["description"]?></textarea><br /><br /> | ||
|
|
||
| Grundpris exklusive moms: | ||
| <input type = "text" name = "price" onkeypress="return isNumber(event)" maxlength = "6" size = "6" value="<?=$res["price"]?>"/><br><br> | ||
|
|
||
| Nuvarande exklusive moms: | ||
| <input type = "text" name = "cprice" onkeypress="return isNumber(event)" maxlength = "6" size = "6" value="<?=$res["current_price"]?>"/><br><br> | ||
| <input type = "hidden" name = "id" value="<?=$id?>" /> | ||
| Momssats: | ||
| <select name="vat"> | ||
| <option value = "<?=$res["vat"]?>">-- Samma som förut --</option> | ||
| <option value = "0.06">6% - Kultur, böcker, mm.</option> | ||
| <option value = "0.12">12% - Livsmedel, mm.</option> | ||
| <option value = "0.25">25% - ALLA digitala tjänster och övriga artiklar</option> | ||
| </select><br><br> | ||
|
|
||
| Kategori: | ||
| <select name = "cat"> | ||
| <option value = "<?=$res["category_ID"]?>">-- Samma som förut --</option> | ||
| <?php | ||
| $result1 = querySQL("SELECT ID, title FROM Categories"); | ||
| while ($res1 = $result1->fetch_assoc()) { ?> | ||
| <option value="<?=$res1["ID"]?>"><?=$res1["title"]?></option> | ||
| <?php | ||
| } | ||
| ?> | ||
| </select><br><br> | ||
| <?php | ||
| $r = querySQL("SELECT ID, path FROM Images WHERE product_ID = $id"); | ||
| $iurl = ""; | ||
| $imgid = ""; | ||
| if ($r->num_rows > 0) { | ||
| $assoc = $r->fetch_assoc(); | ||
| $iurl = $assoc["path"]; | ||
| $imgid = $assoc["ID"]; | ||
|
|
||
| } | ||
| ?> | ||
| Bild-URL. Om du vill använda kategorins standardbild, lämna detta fält blankt: | ||
| <input type = "text" name = "img" value="<?=$iurl?>"/><br/><br/> | ||
| <input type = "hidden" name = "imgid" value="<?=$imgid?>"/> | ||
|
|
||
|
|
||
| <button type="submit" name = "submit" class = "btn btn-default"><span class="glyphicon glyphicon-pencil"></span> Redigera vara!</button><a href="deleteproduct.php?id=<?=$id?>"><button type="button" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> Ta bort</button></a> | ||
| <hr> | ||
| </form> | ||
| <?php | ||
| generateFooter(); |
| @@ -1,29 +1,29 @@ | ||
| <?php | ||
| require "connect.php"; | ||
| function sanitizeString($var){ | ||
| global $connection; | ||
| $var = strip_tags($var); | ||
| $var = htmlentities($var); | ||
| $var = stripslashes($var); | ||
| return $connection->real_escape_string($var); | ||
| } | ||
| function fixDate($year, $month, $day){ | ||
| $result = $year."-".$month."-".$day; | ||
| return $result; | ||
| } | ||
|
|
||
| function fixSecurityNumber($year, $month, $day, $ssn){ | ||
| $year = $year % 100; | ||
| $result = $year.$month.$day."-".$ssn; | ||
| return $result; | ||
| } | ||
| function getRegistrationDate(){ | ||
| $year = date('Y', time()); | ||
| $month = date('m', time()); | ||
| $day = date('d', time()); | ||
| $result = $year."-".$month."-".$day; | ||
| return $result; | ||
| } | ||
|
|
||
|
|
||
| ?> |
| @@ -1,32 +1,32 @@ | ||
| function loaduser(id){ | ||
| if (id ==""){ | ||
| return; | ||
| }else{ | ||
| if (window.XMLHttpRequest) { | ||
| xmlhttp = new XMLHttpRequest(); | ||
| }else{ | ||
| xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | ||
| } | ||
| xmlhttp.onreadystatechange = function(){ | ||
| if(this.readyState == 4 && this.status == 200){ | ||
| var x = this.responseText; | ||
| console.log(x); | ||
| var y = JSON.parse(x); | ||
| document.getElementById("name").value = y.first_name; | ||
| document.getElementById("lastname").value = y.last_name; | ||
| document.getElementById("email").value = y.email; | ||
| document.getElementById("address1").value =decodeChar(y.address1); | ||
| document.getElementById("zip").value = y.zip; | ||
| document.getElementById("city").value = y.city; | ||
| document.getElementById("phone").value = y.phone; | ||
|
|
||
| } | ||
| }; | ||
| xmlhttp.open("GET", "getuser.php?q="+id,true); | ||
| xmlhttp.send(); | ||
| } | ||
| } | ||
|
|
||
| function decodeChar(str){ | ||
|
|
||
| } |
| @@ -1,62 +1,62 @@ | ||
| <?php | ||
| session_start(); | ||
| $user_ID = $session_ID = ""; | ||
| if(isset($_SESSION['user_ID'])){ | ||
| $user_ID = $_SESSION['user_ID']; | ||
| }else{ | ||
| $session_ID = session_ID(); | ||
| } | ||
| ?> | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <title>Bootstrap Example</title> | ||
| <meta charset="utf-8"> <!-- Taken from W3Schools Bootstrap tutorial --> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | ||
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | ||
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | ||
| <script src="cart.js"></script> | ||
| <script> | ||
| window.onload = function(){ | ||
| loadCart('<?php echo $user_ID;?>'); | ||
| } | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <div class="jumbotron"> | ||
| <h1>Simple Design Mockup</h1> | ||
| <p>Just trying to make some bloody prototype</p> | ||
| </div> | ||
| <div class="container-fluid"> | ||
| <div class="row"> | ||
| <div class="col-sm-2"> | ||
| <h3>Kategori</h3> | ||
| <ul class="list-group"> | ||
| <li class="list-group-item">Pennor <span class="badge">14</span></li> | ||
| <li class="list-group-item">Bläck <span class="badge">8</span></li> | ||
| <li class="list-group-item">Papper <span class="badge">5</span></li> | ||
| <li class="list-group-item">Skrivare <span class="badge">3</span></li> | ||
| </ul> | ||
| </div> | ||
| <div class="col-sm-7"> | ||
| <h2>Productbeskrivning</h2> | ||
| <img src="https://pixabay.com/static/uploads/photo/2012/04/14/16/36/pencil-34532_960_720.png" alt="Världens bästa penna!" height = "200px" /> | ||
| <p>Här har vi världens bästa penna. För bra för att vara verklig...</p> | ||
|
|
||
| </div> | ||
| <div class="col-sm-3"> | ||
| <h2>Cart</h2> | ||
| <div class = "table-responsive"> | ||
| <table id = "cart" class ="table table-striped"> | ||
|
|
||
|
|
||
| </table> | ||
| </div> | ||
| <button type="button" class="btn btn-success"><span class="glyphicon glyphicon-shopping-cart"></span> Kassa</button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -1,36 +1,36 @@ | ||
| function loadCart(id){ | ||
| if (id ==""){ | ||
| return; | ||
| }else{ | ||
| if (window.XMLHttpRequest) { | ||
| xmlhttp = new XMLHttpRequest(); | ||
| }else{ | ||
| xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | ||
| } | ||
| xmlhttp.onreadystatechange = function(){ | ||
| if(this.readyState == 4 && this.status == 200){ | ||
| document.getElementById("cart").innerHTML = this.responseText; | ||
| } | ||
| }; | ||
| xmlhttp.open("GET", "loadcart.php?q="+id,true); | ||
| xmlhttp.send(); | ||
| } | ||
| } | ||
| function deleteItem(item){ | ||
| if (id ==""){ | ||
| return; | ||
| }else{ | ||
| if (window.XMLHttpRequest) { | ||
| xmlhttp = new XMLHttpRequest(); | ||
| }else{ | ||
| xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | ||
| } | ||
| xmlhttp.onreadystatechange = function(){ | ||
| if(this.readyState == 4 && this.status == 200){ | ||
| document.getElementById("cart").innerHTML = this.responseText; | ||
| } | ||
| }; | ||
| xmlhttp.open("GET", "loadcart.php?q="+id,true); | ||
| xmlhttp.send(); | ||
| } | ||
| } |
| @@ -1,52 +1,52 @@ | ||
| <?php | ||
| session_start(); | ||
| require "connect.php"; | ||
| global $connection; | ||
| $total= "0"; | ||
| $user_ID = $session_ID = ""; | ||
| if(isset($_SESSION['user_ID']) && !($_SESSION['user_ID']== 0)){ | ||
| $user_ID = $_SESSION['user_ID']; | ||
| }else{ | ||
| $session_ID = session_ID(); | ||
| } | ||
| $id= $_GET['q']; | ||
|
|
||
|
|
||
| $con = $connection; | ||
| if (!$con){ | ||
| die('Could not connect: ' . mysqli_error($con)); | ||
| } | ||
|
|
||
| $sql="SELECT Products.name, Products.price, Products.vat, Cart.item, Cart.ID, Cart.quantity FROM Products INNER JOIN Cart ON Cart.item = Products.ID AND Cart.user_ID = '$user_ID' WHERE Cart.order_ID IS NULL"; | ||
| $result = mysqli_query($con,$sql); | ||
| echo " <tr> | ||
| <th>Produkt:</th> | ||
| <th>Pris/st:</th> | ||
| <th>Antal:</th> | ||
| <th>Summa:</th> | ||
| </tr>"; | ||
| while($row = mysqli_fetch_array($result)) { | ||
| $row['user_ID'] = $user_ID; | ||
| $totalprice = $row['quantity']*$row['price'] + $row['quantity']*$row['price']*$row['vat']; | ||
| $total = sum($totalprice, $total); | ||
| $unitprice = $row["price"] + $row["price"] * $row["vat"]; | ||
| $ggnice = array('user_ID'=>$row['user_ID'], 'ID'=>$row['ID'], 'item'=>$row['item']); | ||
| $mew= json_encode ($ggnice); | ||
| echo " | ||
| <tr> | ||
| <td>$row[name]</td> | ||
| <td>$unitprice kr</td> | ||
| <td>$row[quantity]st</td> | ||
| <td>$totalprice:-</td> | ||
| <td onClick=deleteItem('$mew'); style='cursor: pointer;'><img src = 'media/kryss.png' height='10px'></td> | ||
| </tr>"; | ||
|
|
||
| } | ||
| echo "<h4>Total:<br> $total kr</h4>"; | ||
|
|
||
| mysqli_close($con); | ||
|
|
||
| function sum($price, $total){ | ||
| return $total+$price; | ||
| } | ||
| ?> |
| @@ -1,40 +1,40 @@ | ||
| html { | ||
| background: url(bg.jpg) no-repeat center center fixed; | ||
| -webkit-background-size: cover; | ||
| -moz-background-size: cover; | ||
| -o-background-size: cover; | ||
| background-size: cover; | ||
| overflow-x: hidden; | ||
| } | ||
| body{ | ||
| overflow-x: hidden; | ||
| font-family: helvetica; | ||
| color: #202020; | ||
| } | ||
| .loginbox{ | ||
| float:right; | ||
| margin-right: 150px; | ||
| margin-top:160px; | ||
| background-color:#202020; | ||
| opacity: 0.8; | ||
| border-style: solid; | ||
| border-width: 40px 120px 40px 120px; | ||
| border-radius: 10px; | ||
| } | ||
| .message{ | ||
|
|
||
| margin-top: 160px; | ||
| margin-left:150px; | ||
| float:left; | ||
|
|
||
| } | ||
| h1{ | ||
| margin-top:0; | ||
| } | ||
| .gg{opacity:1;} | ||
| h4{ | ||
| margin-top:0; | ||
| padding-top:0; | ||
| margin-bottom: 3px; | ||
| color: #ffffff; | ||
| } |
| @@ -1,62 +1,62 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <title>Bootstrap Example</title> | ||
| <meta charset="utf-8"> <!-- Taken from W3Schools Bootstrap tutorial --> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | ||
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | ||
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <div class="jumbotron"> | ||
| <h1>Simple Design Mockup</h1> | ||
| <p>Just trying to make some bloody prototype</p> | ||
| </div> | ||
| <div class="container-fluid"> | ||
| <div class="row"> | ||
| <div class="col-sm-2"> | ||
| <h3>Kategori</h3> | ||
| <ul class="list-group"> | ||
| <li class="list-group-item">Pennor <span class="badge">14</span></li> | ||
| <li class="list-group-item">Bläck <span class="badge">8</span></li> | ||
| <li class="list-group-item">Papper <span class="badge">5</span></li> | ||
| <li class="list-group-item">Skrivare <span class="badge">3</span></li> | ||
| </ul> | ||
| </div> | ||
| <div class="col-sm-8"> | ||
| <h2>Productbeskrivning</h2> | ||
| <img src="https://pixabay.com/static/uploads/photo/2012/04/14/16/36/pencil-34532_960_720.png" alt="Världens bästa penna!" height = "200px" /> | ||
| <p>Här har vi världens bästa penna. För bra för att vara verklig...</p> | ||
| </div> | ||
| <div class="col-sm-2"> | ||
| <h2>Cart</h2> | ||
| <table class="table table-hover"> | ||
| <thead> | ||
| <tr> | ||
| <th>Vara</th> | ||
| <th>Antal</th> | ||
| <th>á Pris</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr> | ||
| <td>Penna, Blå</td> | ||
| <td>3</td> | ||
| <td>20</td> | ||
| </tr> | ||
| <tr> | ||
| <td>Papper, A4, 100-pack</td> | ||
| <td>2</td> | ||
| <td>58</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| <p><strong>Totalt: 299</strong></p> | ||
| <button type="button" class="btn btn-success"><span class="glyphicon glyphicon-shopping-cart"></span> Kassa</button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -1,42 +1,42 @@ | ||
| CREATE TABLE IF NOT EXISTS Users(ID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
| email VARCHAR(64) UNIQUE, passw TEXT, regdate DATE, access INT, birthday DATE, phone VARCHAR(16), zip VARCHAR(16), sec VARCHAR(16) UNIQUE, address1 VARCHAR(64), city VARCHAR(64), country VARCHAR(32), first_name VARCHAR(32), last_name VARCHAR(32)); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS Categories(ID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
| title VARCHAR(32) UNIQUE NOT NULL, img_path TEXT); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS Products(ID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
| name TEXT, quantity INT UNSIGNED, description TEXT, avg_grade FLOAT, category_ID INT UNSIGNED, price DECIMAL(10,2), vat DECIMAL(10,2), preview INT UNSIGNED, added DATE, current_price DECIMAL(10,2), | ||
| FOREIGN KEY (category_ID) REFERENCES Categories(ID)); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS Orders(ID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
| payment_option VARCHAR(16), payment_received VARCHAR(16), order_placed DATE, discount DECIMAL(10,2)); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS OrderAddresses(ID INT UNSIGNED, addr_type CHAR UNIQUE NOT NULL, | ||
| phone VARCHAR(16), zip VARCHAR(16), address1 VARCHAR(64), city VARCHAR(64), country VARCHAR(32), | ||
| FOREIGN KEY (ID) REFERENCES Orders(ID), PRIMARY KEY (ID, addr_type)); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS Images(ID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
| product_ID INT UNSIGNED, path TEXT NOT NULL, | ||
| FOREIGN KEY (product_ID) REFERENCES Products(ID)); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS Cart(ID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
| user_ID INT UNSIGNED, item INT UNSIGNED, quantity INT UNSIGNED, order_ID INT UNSIGNED, | ||
| FOREIGN KEY (order_ID) REFERENCES Orders(ID), FOREIGN KEY (user_ID) REFERENCES Users(ID), FOREIGN KEY (item) REFERENCES Products(ID)); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS Comments(ID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
| title VARCHAR(64), description VARCHAR(512), parent INT UNSIGNED, product_ID INT UNSIGNED, user_ID INT UNSIGNED, approved BOOLEAN, | ||
| FOREIGN KEY (parent) REFERENCES Comments(ID), FOREIGN KEY (user_ID) REFERENCES Users(ID), FOREIGN KEY (product_ID) REFERENCES Products(ID)); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS Grades(ID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
| grade DECIMAL(10,2) NOT NULL, product_ID INT UNSIGNED, user_ID INT UNSIGNED, comment_ID INT UNSIGNED, | ||
| FOREIGN KEY (product_ID) REFERENCES Products(ID), FOREIGN KEY (user_ID) REFERENCES Users(ID), FOREIGN KEY (comment_ID) REFERENCES Comments(ID)); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS TagDefinitions(ID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
| definition TEXT, title VARCHAR(64) UNIQUE NOT NULL); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS Tags(ID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
| product_ID INT UNSIGNED, definition_ID INT UNSIGNED, | ||
| FOREIGN KEY (product_ID) REFERENCES Products(ID), FOREIGN KEY (definition_ID) REFERENCES TagDefinitions(ID)); | ||
|
|
||
| ALTER TABLE Products ADD FOREIGN KEY (preview) REFERENCES Images(ID); | ||
|
|
| @@ -1,30 +1,30 @@ | ||
| <?php | ||
| /** | ||
| * Created by PhpStorm. | ||
| * User: palm | ||
| * Date: 2016-11-16 | ||
| * Time: 10:25 | ||
| */ | ||
|
|
||
| /* | ||
| * Syftet med denna fil är att ha en gemensam header för alla sidor. Denna ska sedan inkluderas i samtliga | ||
| * PHP-dokument. Just nu får denna dock vara tom. | ||
| * */ | ||
|
|
||
| function generateFooter() { | ||
| ?> | ||
| <!-- TODO: Lägg till paneler och slut på andra taggar som eventuellt startas i en framtida version av headern. --> | ||
| </div> | ||
| <div class="col-sm-3"> | ||
| <h2>Kundvagn</h2> | ||
| <table class="table table-responsive table-hover" id="cart"> | ||
| </table> | ||
| <script src="cart.js"></script> | ||
| <a href="addorder.php"><button type="button" class="btn btn-success"><span class="glyphicon glyphicon-shopping-cart"></span>Kassa</button></a> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> | ||
| <?php | ||
| } |
| @@ -1,89 +1,89 @@ | ||
| <?php | ||
| /** | ||
| * Created by PhpStorm. | ||
| * User: palm | ||
| * Date: 2016-11-16 | ||
| * Time: 10:25 | ||
| */ | ||
|
|
||
| /* | ||
| * Syftet med denna fil är att ha en gemensam header för alla sidor. Denna ska sedan inkluderas i samtliga | ||
| * PHP-dokument. Just nu får denna dock vara ganska så bare-bones. | ||
| * */ | ||
|
|
||
| session_start(); | ||
| $user_ID = $session_ID = ""; | ||
| if(isset($_SESSION['user_ID'])){ | ||
| $user_ID = $_SESSION['user_ID']; | ||
| }else{ | ||
| $session_ID = session_ID(); | ||
| } | ||
| function generateCategories() { | ||
| $categories = querySQL("SELECT ID, title FROM Categories"); | ||
| while($category = $categories->fetch_assoc()) { | ||
| $id = $category["ID"]; | ||
| $items = querySQL("SELECT ID FROM Products WHERE category_ID = $id")->num_rows; | ||
| ?> | ||
| <li class="list-group-item"><a href="browseproducts.php?id=<?=$id?>"><?=$category["title"]?></a><span class="badge"><?=$items?></span></li> | ||
| <?php | ||
| } | ||
| } | ||
|
|
||
| function generateBootstrap() { | ||
| ?> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> | ||
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | ||
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | ||
| <?php | ||
| } | ||
|
|
||
| function generateHeader ($title, $gen_head = true, $gen_bootstrap = true) | ||
| { | ||
| if ($gen_head) { ?> | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"/> | ||
| <title><?= $title ?></title> | ||
| <?php | ||
| if ($gen_bootstrap) { | ||
| generateBootstrap(); | ||
| } | ||
| ?> | ||
| </head> | ||
| <?php | ||
| } ?> | ||
| <body onload="loadCart(<?php echo $_SESSION['user_ID'];?>);"> | ||
| <div class="jumbotron" stype="margin-left:10pt;"> | ||
| <h1>Kontorsshoppen.se - <?=$title?></h1> | ||
| <p>Kontorsvaror för den prisblinde kunden</p> | ||
|
|
||
| <nav class="navbar navbar-default"> | ||
| <div class="container-fluid"> | ||
| <div class="navbar-header"> | ||
| <a class="navbar-brand" href="#">kontorsshoppen.se</a> | ||
| </div> | ||
| <ul class="nav navbar-nav"> | ||
| <li><a href="index.php">Start</a></li> | ||
| <li><a href="browseproducts.php">Shop</a></li> | ||
| <li><a href="addproduct.php">Skapa produkter</a></li> | ||
| <li><a href="createcategory.php">Skapa kategori</a></li> | ||
|
|
||
| </ul> | ||
| </div> | ||
| </nav></div> | ||
| <div class="container-fluid"> | ||
| <div class="row"> | ||
| <div class="col-sm-2"> | ||
| <h3>Kategorier</h3> | ||
| <ul class="list-group"><!-- Lägg till så att man kan få fram kategorierna --> | ||
| <?php generateCategories(); ?> | ||
| </ul> | ||
| </div> | ||
| <div class="col-sm-7"> | ||
|
|
||
|
|
||
| <!-- TODO: Lägg till paneler och sådant. Kundvagn kan vara mycket viktigt i detta fall. --> | ||
| <?php | ||
| } |
| @@ -1,72 +1,71 @@ | ||
| <?php | ||
| session_start(); | ||
|
|
||
| require_once 'functions.php'; | ||
| require 'template/header.php'; | ||
| require 'template/footer.php'; | ||
|
|
||
| $valid = isset($_GET["id"]); | ||
| $id = sanitizeString($_GET["id"]); | ||
| $desc = $title = $price = ""; | ||
| $cursor = NULL; | ||
| $val = NULL; | ||
|
|
||
| if ($valid) { | ||
| $cursor = querySQL("SELECT * FROM Products WHERE ID = $id"); | ||
| if ($cursor->num_rows == 0) { | ||
| $valid = false; // Produkten kunde inte hittas | ||
| } else { | ||
| $val = $cursor->fetch_assoc(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| generateHeader($valid ? $val["name"] : "Proukten kunde inte hittas"); | ||
| ?> | ||
| <script> | ||
| function isNumber(evt) { // Emils script från register.php. Borde vi flytta det till en egen fil istället för copy paste? | ||
| evt = (evt) ? evt : window.event; | ||
| var charCode = (evt.which) ? evt.which : evt.keyCode; | ||
| if (charCode > 31 && (charCode < 48 || charCode > 57)) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| </script> | ||
| <script> | ||
| window.onload = function(){ | ||
| getQuantity('<?php echo $id;?>'); | ||
| } | ||
| </script> | ||
| <script src="addtocart.js"></script> | ||
| <?php | ||
|
|
||
| if (!$valid) { | ||
| ?> | ||
| <h2 class="text-danger">Produkten du letar efter kunde inte hittas!</h2> | ||
| <?php | ||
| } else { | ||
| $price = $val["current_price"] + $val["current_price"] * $val["vat"]; | ||
| $img_id = 0; | ||
| $img_url = ""; | ||
| if ($val["preview"] == NULL) { | ||
| $img_url = querySQL("SELECT img_path FROM Categories WHERE ID = {$val["category_ID"]}")->fetch_assoc()["img_path"]; | ||
| } else { | ||
| $img_id = $val["preview"]; | ||
| $img_url = querySQL("SELECT path FROM Images WHERE ID = $img_id")->fetch_assoc()["path"]; | ||
| } | ||
| ?> | ||
| <h2><?=$val["name"]?></h2> | ||
| <img src = "<?=$img_url?>" alt = "Produktbild" width = "500px" /> | ||
| <p>Lagersaldo: <div id = "show_quantity"></div></p> | ||
| <p>Pris: <?=$price?></p> | ||
| <p><?=$val["description"]?></p> | ||
| Antal: <input type = "text" value ="1" id ="quantity" name = "quantity" onkeypress="return isNumber(event)" maxlength = "4" size = "4" /><br><br> | ||
| <button type="submit" class="btn btn-success" onClick="addToCart(<?php echo $id; ?>)"> | ||
| Lägg till i varukorgen <span class="glyphicon glyphicon-shopping-cart"></span> | ||
| </button> | ||
| <div id="txtHint"></div> | ||
| <?php | ||
| } | ||
| generateFooter(); |