<?php
if(!isset($modosit))
{
?>
  <div class="folyamat">
    <a href="index.php?page=megerosit" style="font-size:11pt; font-weight:bolder; color:#900; text-decoration:none;">A kosár tartalma >></a> 
    <span style="font-size:8pt; font-weight:bold; color:#999; text-decoration:none;">Megrendelői adatok >></span> 
    <span style="font-size:8pt; font-weight:bold; color:#999; text-decoration:none;">Adatok ellenőrzése >></span> 
    <span style="font-size:8pt; font-weight:bold; color:#999; text-decoration:none;">Rendelés elküldése</span>
  </div>
  <br />
  <br />    
  <form name="megerosit" id="megerosit" action="index.php?page=megerosit" method="POST" class="regform">
    <input type="hidden" name="modosit" value="mod">

    <table width="100%">
      <tr class="kosar_tartalma_fejlec">
        <td style="padding:3px; text-align:left;">A termék megnevezése</td>
        <td style="padding:3px; text-align:center;">Egységár</td>
        <td style="padding:3px; text-align:center;">Darabszám</td>
        <td style="padding:3px; text-align:right;">Összeg</td>
      </tr>

      <?php
      $osszeg = 0;
      
      if ($belepve == 0) 
      {
        $sql = "SELECT * FROM kosar WHERE session_id='" . session_id() . "' AND rendeles_id=0";
      }
      else 
      {
        $sql = "SELECT * FROM kosar WHERE ugyfel_id=$webshop_id AND rendeles_id=0";
      }

      $eredmeny = mysql_query($sql);
      
      while ($sor = mysql_fetch_array($eredmeny)) 
      {
        $kosar_id = $sor["id"];
        $termek_id = $sor["termek_id"];
        $mennyiseg = $sor["mennyiseg"];
        
        $parancs = "SELECT * FROM termekek WHERE id=$termek_id";
        $rs = mysql_query($parancs);

        if (mysql_num_rows($rs) > 0) 
        {
          $egysor = mysql_fetch_array($rs);
          $nev = $egysor["nev"];
          $ar = $egysor["ar"];
          $osszeg += $mennyiseg * $ar;
          ?>
          <tr>
            <td class="kosar_tartalma_nev"><?php echo $nev?></td>
            <td class="kosar_tartalma_egysegar"><?php echo szampontos($ar)?> Ft</td>
            <td class="kosar_tartalma_mennyiseg">
              <div class="inpdiv1" style="width:34px;float:left;"><div class="inpdiv2"><div class="inpdiv3">
                <div style="height:4px;"><!--  --></div>
                <input id="<?php echo $kosar_id?>" name="<?php echo $kosar_id?>" maxlength="4" class="db" value="<?php echo $mennyiseg?>" />
              </div></div></div>
            </td>
            <td class="kosar_tartalma_osszeg"><?php echo szampontos($mennyiseg*$ar)?> Ft</td>
          </tr>
          <?php
        }
      }
      ?>
      <tr style="border-top: 1px solid #000;">
        <td style="text-align:left; font-weight:bold; color:#600" colspan="3">Összesen:</td>
        <td style="text-align:right; font-weight:bold;"><?php echo szampontos($osszeg)?> Ft</td>
      </tr>

      <tr><td colspan="4">&nbsp;</td></tr>

      <tr>
        <td>
          <input type="button" value="Frissítés" onclick="document.megerosit.submit()" />
        </td>
        <td colspan="3">
          <input type="button" value="Tovább >>" onclick="document.location='index.php?page=szallitas'" />
        </td>
      </tr>
    </table>
  </form>
<?php
}
else if($modosit == "mod")
{
  foreach($_POST as $nev => $ertek) 
  {
    if ($nev != "modosit") 
	{
      if ($ertek == 0) 
	  {
        $sql = "DELETE FROM kosar WHERE id=$nev";
      }
      else 
	  {
        $sql = "UPDATE kosar SET mennyiseg=$ertek WHERE id=$nev";
      }
      mysql_query($sql);
    }
  }
  echo "A kosár frissítve!";
  ?>
  <br />
  <a href="index.php?page=megerosit">Vissza a kosár tartalmához...</a>
  <?php
}
?>