query("SELECT namn FROM sortiment_produkt WHERE artikelnr='$produktid'") or die(mysqli_error());; $row = $result->fetch_assoc(); return $row['namn']; } // Funkrion för att hämta pris på produkt function get_price($produktid){ global $koppling; $result=$koppling->query("SELECT pris FROM sortiment_produkt WHERE artikelnr='$produktid'"); $row = $result->fetch_assoc(); return $row['pris']; } // Funktion för att hämta rabattkod function get_cupon($cupon){ global $koppling; $rabattkoll=$koppling->query("SELECT * FROM webshop_discount WHERE code='$cupon'") or (mysqli_error(die)); $rad = $rabattkoll->fetch_assoc(); // Om felaktikgt kod if (mysqli_num_rows($rabattkoll) == 0) { $mox=$cupon; header("Location: /varukorg/kodfel/"); } else { $_SESSION['rabatt']=(100-$rad['procent'])/100; $mox=$rad['procent']; header("Location: /varukorg/kodok/"); } return $mox; } // Funktion för att räkna ut totalpriset i varukorgen function get_order_total(){ $max=count($_SESSION['cart']); $sum=0; for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $q=$_SESSION['cart'][$i]['quantity']; //$price=get_price($pid); $price=$_SESSION['cart'][$i]['price']; $sum+=$price*$q; } return $sum; } // Funktion för att räkna ut totalt antal valda varor function get_total_choise(){ $max=count($_SESSION['cart']); $sum=0; for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $q=$_SESSION['cart'][$i]['quantity']; $totalX+=$q; } if(($totalX=="") OR ($totalX=="0")) { return " tom"; } else if($totalX=="1") { return $totalX." produkt"; } else { return $totalX." produkter"; } } //Funktion för att resna hela varukorgen function clear_cart() { unset($_SESSION['fraktkoll']); unset($_SESSION['fraktkoll2']); unset($_SESSION['cart']); $_SESSION['cart']=array_values($_SESSION['cart']); } function update_cart($productid,$quantity) { $max=count($_SESSION['cart']); for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $q=intval($_REQUEST['product'.$pid]); if($q>0 && $q<=999){ $_SESSION['cart'][$i]['quantity']=$q; } else { $msg='Some proudcts not updated!, quantity must be a number between 1 and 999'; } } } function krypt1($data = "", $width=192, $rounds = 3) { return substr( implode( array_map( function ($h) { return str_pad(bin2hex(strrev($h)), 16, "0"); }, str_split(hash("tiger192,$rounds", $data, true), 8) ) ), 0, 48-(192-$width)/4 ); } // Funktion för att kryptera lösenord. function krypt($string) { if ($string != "") { $retstring=""; for($i=0;$i < strlen($string); $i++) { $retstring[$i]=chr((ord($string[$i])+($i%60))); } return $retstring; } else { return false; } } // Funktion för att dekryptera lösenord. function dekryptOLD($string) { if ($string != "") { $retstring=""; for($i=0;$i < strlen($string); $i++) { $retstring[$i]=chr((ord($string[$i])-($i%60))); } return implode("",$retstring); } else { return false; } } // Funktion för att skapa SEO vänliga urler function urlname( $s, $charset='utf-8' ) { $pattern = '/&([a-z][ze]?)(uml|acute|circ|tilde|ring|lig|grave|slash|horn|cedil|th);/i'; $replace = "\\1"; $s = htmlentities($s, ENT_NOQUOTES, $charset); $s = preg_replace($pattern, $replace, $s); $s = html_entity_decode($s, ENT_NOQUOTES, $charset); return preg_replace('/[^a-z0-9._-]/', '-', strtolower( $s )); } // Funktion för att ladda upp bilder och beskära class thumbnail { var $img; function thumbnail($imgfile) { //detect image format $this->img["format"] = preg_replace("#.*\.(.*)$#", "\\1", $imgfile); $this->img["format"] = strtoupper($this->img["format"]); if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { //JPEG $this->img["format"]="JPEG"; $this->img["src"] = ImageCreateFromJPEG ($imgfile); } else if ($this->img["format"]=="PNG") { //PNG $this->img["format"]="PNG"; $this->img["src"] = ImageCreateFromPNG ($imgfile); } else if ($this->img["format"]=="GIF") { //GIF $this->img["format"]="GIF"; $this->img["src"] = ImageCreateFromGIF ($imgfile); } else if ($this->img["format"]=="WBMP") { //WBMP $this->img["format"]="WBMP"; $this->img["src"] = ImageCreateFromWBMP ($imgfile); } else { //DEFAULT echo "Not Supported File"; exit(); } @$this->img["lebar"] = imagesx($this->img["src"]); @$this->img["tinggi"] = imagesy($this->img["src"]); //default quality jpeg $this->img["quality"]=75; } function size_height($size=100) { //height $this->img["tinggi_thumb"]=$size; //@$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]; } function size_width($size=100) { //width $this->img["lebar_thumb"]=$size; //@$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]; } function size_auto($size=500) { //size if ($this->img["lebar"]>=$this->img["tinggi"]) { $this->img["lebar_thumb"]=$size; @$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]; } else { $this->img["tinggi_thumb"]=$size; @$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]; } } function jpeg_quality($quality=75) { //jpeg quality $this->img["quality"]=$quality; } function show() { //show thumb @Header("Content-Type: image/".$this->img["format"]); /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/ $this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]); @imagecopyresampled ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]); if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { //JPEG imageJPEG($this->img["des"],"",$this->img["quality"]); } elseif ($this->img["format"]=="PNG") { //PNG imagePNG($this->img["des"]); } elseif ($this->img["format"]=="GIF") { //GIF imageGIF($this->img["des"]); } elseif ($this->img["format"]=="WBMP") { //WBMP imageWBMP($this->img["des"]); } } function save($save="") { //save thumb if (empty($save)) $save=strtolower("./thumb.".$this->img["format"]); /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/ $this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]); ImageCopyResampled($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]); if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { //JPEG imageJPEG($this->img["des"],"$save",$this->img["quality"]); } elseif ($this->img["format"]=="PNG") { //PNG imagePNG($this->img["des"],"$save"); } elseif ($this->img["format"]=="GIF") { //GIF imageGIF($this->img["des"],"$save"); } elseif ($this->img["format"]=="WBMP") { //WBMP imageWBMP($this->img["des"],"$save"); } } } function stammerPersonnummer($personnummer, $kon){ for($i = 2; $i < 13; $i++) if($i != 8) @$kontroll += ($nummer = $personnummer[$i] * (2 - @$uddaEllerJamn++ % 2)) > 9 ? $nummer - 9 : $nummer; return $personnummer[11] % 2 == ($kon == "Man") && !($kontroll % 10); } ?>