<?php
  /**
   * Load Shopping Cart
   *
   * @package Digital Downloads Pro
   * @author wojoscripts.com
   * @copyright 2010
   * @version $Id: load-cart.php, v2.00 2011-07-10 10:12:05 gewa Exp $
   */
  define("_VALID_PHP", true);
  require_once("../init.php");

?>
<?php
  if (isset($request->post['cartsmall'])) :
	if($row = $db->first("SELECT sum(price) as ptotal, COUNT(*) as itotal FROM cart WHERE user_id = '" . $db->escape($user->sesid) . "'")): 
	   $itotal =  ($row['itotal'] == 0) ? '-': $row['itotal'];
	   $ptotal =  ($row['ptotal'] == 0) ? '-': $core->formatMoney($row['ptotal']);
		print $itotal.' / '.$ptotal;
	else:
		 print '-/-';
	endif;
  endif;
?>
<?php
  if (isset($request->post['cartbig'])) :
	$content->renderCart();
  endif;
?>
<?php
  if (isset($request->post['delcart'])) :
    $id = intval($_POST['delcart']);
	$db->delete("cart", "pid='".$id."' AND user_id = '".$db->escape($user->sesid)."'");
	$db->delete("extras", "user_id = '".$db->escape($user->sesid)."'");
  endif;
?>
<?php
  if (isset($request->post['checkout'])) :
	$cartrow = $content->getCartContent();
	$totalrow = $content->getCartTotal();
	$discount = $totalrow['total'] - $totalrow['coupon'];
?>
  <?php if(!$cartrow):?>
  <div class="msgInfo"><span>!تـوجـه</span>!با عرض پوزش سبد خرید شما خالی می باشـد</div>
  <?php else:?>
      <table cellpadding="0" cellspacing="0" class="display">
        <thead>
          <tr>
            <th width="20" class="left">#</th>
            <th class="right">نـام محصـول</th>
            <th class="right">قیمـت محصـول</th>
            <th align="center">تـعـداد</th>
            <th align="center">قیمـت کـل</th>
            <th width="25">&nbsp;</th>
          </tr>
        </thead>
        <tbody>
          <?php $i = 0;?>
          <?php foreach ($cartrow as $ccrow): ?>
          <?php $i++;;?>
          <tr>
            <th><?php echo $i;?>.</th>
            <td><?php echo $ccrow['title'];?></td>
            <td><?php echo $core->formatMoney($ccrow['price']);?></td>
            <td align="center"><?php echo $ccrow['total'];?></td>
            <td align="center"><?php echo $core->formatMoney($ccrow['total'] * $ccrow['price']);?></td>
            <td><a href="javascript:void(0);" class="del-cart-full" id="item_<?php echo $ccrow['pid'];?>"><img src="<?php echo SITEURL;?>/images/del.png" alt=""/></a></td>
          </tr>
          <?php endforeach;?>
          <?php unset($ccrow);?>
          <tr>
            <td colspan="4" align="left" valign="top"><strong>
              <?php if($totalrow['coupon'] !=0):?>
              تخفیـف :<br />
              <?php endif;?>
              جـمـع :&nbsp;&nbsp;&nbsp;&nbsp;<br />
              </strong></td>
            <td align="center"" valign="top"><strong>
              <?php if($totalrow['coupon'] !=0):?>
              - <?php echo $core->formatMoney($totalrow['coupon']);?><br />
              <?php endif;?>
              <?php echo $core->formatMoney($discount);?><br />
              </strong></td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td colspan="4" align="left" valign="top"><strong style="color:#F00">جـمـع کـل :&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
            <td align="center" valign="top"><strong style="color:#F00"><?php echo $core->formatMoney($discount);?></strong></td>
            <td>&nbsp;</td>
          </tr>
        </tbody>
      </table>
  <?php endif;?>
<?php endif;?>