<?php
require("connection/dbconn.php");
require("include/functions.php");
require("include/cookie.php");

if ($torolni == 1 && isset($azonosit)) 
{
  if ($belepve == 1) 
  {
	$sql = "DELETE FROM kosar WHERE ugyfel_id=$webshop_id AND rendeles_id=0 AND id=$azonosit";
  }
  else 
  {
	$sql = "DELETE FROM kosar WHERE session_id='" . session_id() . "' AND rendeles_id=0 AND id=$azonosit";
  }
  mysql_query($sql);
  
  header("Location: index.php?page=kategoria&kateg=$kateg");
}

if ($belepve == 0) 
{
  $most = date("Y-m-d H:i:s");
  $parancs = "SELECT * FROM kosar WHERE session_id='" . session_id() . "' AND termek_id=$termek_id AND rendeles_id=0";
  $eredmeny = mysql_query($parancs);

  if (mysql_num_rows($eredmeny) > 0) 
  {
	$sor = mysql_fetch_array($eredmeny);
	$kosar_id = $sor["id"];
	$sql = "UPDATE kosar SET mennyiseg=mennyiseg+$db WHERE id=$kosar_id";
	mysql_query($sql);
  }
  else
  {
	$sql = "INSERT INTO kosar (termek_id, session_id, mennyiseg, kosarba_date) VALUES ($termek_id, '" . session_id() . "', $db, '$most')";
	mysql_query($sql);
  }
}

else 
{
  $parancs = "SELECT * FROM kosar WHERE ugyfel_id=$webshop_id AND termek_id=$termek_id AND rendeles_id=0";
  $eredmeny = mysql_query($parancs);
 
  if (mysql_num_rows($eredmeny) > 0) 
  {
    $sor = mysql_fetch_array($eredmeny);
    $kosar_id = $sor["id"];
    $sql = "UPDATE kosar SET mennyiseg=mennyiseg+$db WHERE id=$kosar_id";
    mysql_query($sql);
  }
  else 
  {
    $sql = "INSERT INTO kosar (termek_id, ugyfel_id, session_id, mennyiseg, kosarba_date) VALUES ($termek_id, $webshop_id, '" . session_id() . "', $db, '$most')";
    mysql_query($sql);
  }
}

header("Location: index.php?page=kategoria&kateg=$kateg");

mysql_close($connect);
?>