3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function OdeberZKosiku($id_polozka) { global $session_user; $id_polozka=intval($id_polozka); $query = mysql_query(" DELETE FROM ".TBL_PREFIX."kosik_polozky WHERE id_polozka='$id_polozka' and id_user='$session_user' ") or die(err(1)); } function PridejDoKosikuHromadne($id_produkty, $pocet) { $pridano=false; for ($f=0;$f<count($id_produkty);$f++) { if ($pocet[$f]>0) { $vystup=PridejDoKosiku($id_produkty[$f],$pocet[$f]); if ($vystup) $pridano=true; } } return $pridano; } function PridejDoKosiku($add_id, $pocet) { global $session_user; //vypoÄ?Ă­tĂĄm cenu a zjistĂ­m zda produkt existuje, kvĹŻli POST podvrĹženĂ­ $query = mysql_query(" SELECT p.id, p.cena1, m.id_poplatek FROM ".TBL_PREFIX."produkty p JOIN ".TBL_PREFIX."produkty_matky m ON p.id_matka=m.id_matka WHERE p.id='$add_id' and m.web='".__WEB__."' and m.aktivni=1 ") or die(err(1)); if (mysql_num_rows($query)==1) { $row = mysql_fetch_array($query); $cena=CenaProZakaznika($row['id']); //poÄ?et produktĹŻ v koĹĄĂ­ku $query_pocet = mysql_query("SELECT pocet FROM ".TBL_PREFIX."kosik_polozky WHERE id_produkt='$add_id' and id_user='$session_user' ") or die(err(1)); if (mysql_num_rows($query_pocet)==0) { //poplatek je bez DPH, pĹ?ed vloĹženĂ­m do koĹĄĂ­ku musĂ­m DPH pĹ?idat... if ($cena['druh_cena']==__BEZ_DPH__) { $cena['poplatek']=($cena['poplatek']*$cena['dph_sazba']/100)+$cena['poplatek']; // $cena['poplatek']=$cena['poplatek']*$cena['dph_sazba']/100)+$cena['poplatek']; } //nenĂ­ jeĹĄtÄ? v koĹĄĂ­ku........insert $vloz=mysql_query(" INSERT INTO ".TBL_PREFIX."kosik_polozky (id_polozka, id_user, id_produkt, cena_bez_dph, cena_s_dph, dph, cena_poplatek, id_poplatek, pocet, cas) VALUES ( '', '$session_user', '$add_id', '".$cena['cena_bez_dph']."', '".$cena['cena_s_dph']."', '".$cena['dph_sazba']."', '".$cena['poplatek']."', '".$row['id_poplatek']."', '$pocet', now() ) ") or die(err(1)); } else { //je v koĹĄĂ­ku........update $row_pocet = mysql_fetch_array($query_pocet); $pridat=$row_pocet['pocet']+$pocet; $vloz=mysql_query(" UPDATE ".TBL_PREFIX."kosik_polozky SET pocet='$pridat' WHERE id_produkt='$add_id' and id_user='$session_user' LIMIT 1 ") or die(err(1)); } return true; //header("Location: ".__URL__."kosik.html"); //exit(); } else return false; } function PrepocitejKosik($id,$pocet) { global $session_user; //mazĂĄnĂ­ vĹĄeho mysql_query(" DELETE FROM ".TBL_PREFIX."kosik_polozky WHERE id_user='$session_user' ") or die(err(1)); for ($f=0;$f<count($id);$f++) { //vypoÄ?Ă­tĂĄm cenu a zjistĂ­m zda produkt existuje, kvĹŻli POST podvrĹženĂ­ $query = mysql_query(" SELECT p.id, m.id_poplatek FROM ".TBL_PREFIX."produkty p JOIN ".TBL_PREFIX."produkty_matky m ON p.id_matka=m.id_matka WHERE p.id='$id[$f]' and m.web='".__WEB__."' ") or die(err(1)); if (mysql_num_rows($query)==1) { $row = mysql_fetch_array($query); $cena=CenaProZakaznika($row['id']); } if ($pocet[$f]>0) { //poplatek je bez DPH, pĹ?ed vloĹženĂ­m do koĹĄĂ­ku musĂ­m DPH pĹ?idat... if ($cena['druh_cena']==__BEZ_DPH__) { $cena['poplatek']=($cena['poplatek']*$cena['dph_sazba']/100)+$cena['poplatek']; // $cena['poplatek']=$cena['poplatek']*$cena['dph_sazba']/100)+$cena['poplatek']; } $vloz=mysql_query(" INSERT INTO ".TBL_PREFIX."kosik_polozky (id_polozka, id_user, id_produkt, cena_bez_dph, cena_s_dph, dph, cena_poplatek, id_poplatek, pocet, cas) VALUES ('','$session_user', '$id[$f]', '".$cena['cena_bez_dph']."', '".$cena['cena_s_dph']."', '".$cena['dph_sazba']."', '".$cena['poplatek']."', '".$row['id_poplatek']."', '$pocet[$f]', now() ) ") or die(err(1)); } } } //prepocita celkovou cenu v session v 1 kroku objednavky pri zadani slevoveho kuponu function NastavSessionCeny() { global $session_user; $usk = __UPLATNOVAT_SLEVOVE_KODY_NA_ZBOZI_KTERE_NENI_SKLADEM__ == 'Ano' ? 1: 0; $query_kosik = mysql_query(" SELECT k.*, IF (p.uplatnit_slevovy_kod = 1 AND ((p.kusu_skladem > 0 AND ".$usk." = 0) OR ".$usk."=1),1,0) AS uplatnit_slevovy_kod FROM ".TBL_PREFIX."kosik_polozky k JOIN ".TBL_PREFIX."produkty p ON p.id=k.id_produkt JOIN ".TBL_PREFIX."produkty_matky m ON p.id_matka=m.id_matka JOIN ".TBL_PREFIX."menu menu ON menu.id_matka=m.id_matka and vychozi=1 WHERE id_user='$session_user' and m.aktivni=1 and p.aktivni=1 and m.web='".__WEB__."' GROUP BY p.id ORDER BY k.id_polozka ") or die(mysql_error()); $soucet_s_dph = $soucet_bez_dph = 0; if (mysql_num_rows($query_kosik)==0) return false; while($kosik=mysql_fetch_array($query_kosik)) { $poplatek=$kosik['cena_poplatek']; //pokud je zadan slevovy kod, pak probehne odecteni slevy, je u produktu, ktere nemaji priznak "Na tento produkt lze uplatnit slevovĂ˝ kupĂłn" $sleva_koef = __MODUL_SLEVOVE_KODY__ && $kosik['uplatnit_slevovy_kod'] == 1 && isset($_SESSION['obj']['slevovy_kod_sleva']) && $_SESSION['obj']['slevovy_kod_sleva'] > 0 ? 1 - ($_SESSION['obj']['slevovy_kod_sleva'] / 100) : 1; $soucet_s_dph=$soucet_s_dph+((($kosik['cena_s_dph']*$sleva_koef)+$poplatek)*$kosik['pocet']); $soucet_bez_dph=$soucet_bez_dph+$kosik['cena_bez_dph']*$sleva_koef*$kosik['pocet']; } $_SESSION['obj']['celkova_cena']=$soucet_s_dph; $_SESSION['obj']['celkem_bez_dph']=$soucet_bez_dph; return true; } ?>