<?php
  /**
   * Add To 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['addtocart']))
      : if ($_POST['addtocart'] == 0 || empty($_POST['addtocart']))
      : redirect_to("../index.php");
  endif;
  
  $item_id = intval($_POST['addtocart']);
  if ($row = $db->first("SELECT id, price FROM products WHERE id = '" . $db->escape($item_id) . "'")) {
      $data = array(
		  'user_id' => sanitize($user->sesid), 
		  'pid' => $row['id'], 
		  'price' => floatval($row['price'])
	  );
      
      $db->insert("cart", $data);
  }
  
  endif;
?>