<?php
/**
 * @copyright ONE/DEPO Project
 * @license   PHP License 3.01 <http://www.php.net/license/3_01.txt>
 */


//JSONを扱うためのパーサ
//require_once(WEBAPP_DIR."/JSON.php");

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
require_once 'Net/UserAgent/Mobile.php';

/**
 * [[機能説明]]
 *
 * @package     [[package名]]
 * @author      Your Name <mail@example.com>
 * @access      public
 */
class Customer_Itembuy_Nonmember
{
    var $title;
    var $pagename;

    var $c_pref;
    var $deposit;
    var $c_cart;
    var $payment;
    var $dlitem;

    var $fix;
    var $session;


    var $actionChain;

    var $from;
    var $back;

    var $paymentflg;
    var $sum_quantity;
    var $quantity;
    var $takkyubin;


    /**
     * [[機能説明]]
     *
     * @access  public
     */
    function execute()
    {
        $mobile = &Net_UserAgent_Mobile::isMobile();
        $re_str = ($mobile) ? "mobile_" : "";

        $log =& LogFactory::getLog();
        $log->debug("Customer_Itembuy_Nonmemberが実行されました", "Customer_Itembuy_Nonmember#execute");


        $item_array = $this->session->getParameter('cart_items');
        if($item_array != NULL)
        {
            $souryou = array();
            for($i=0; $i < count($item_array); $i++)
            {
                if(isset($this->quantity[$i])) $item_array[$i][3] = $this->quantity[$i];
                $params = $this->c_cart->selectOne($item_array[$i][0], $item_array[$i][1], $item_array[$i][2]);
                if($params) {
                    // _E[hi͉・・ｃﾝ
                    $data = $this->dlitem->getDownloadItem($item_array[$i][0], $item_array[$i][1]);
                    if ($data!==FALSE && !is_null($data)) {
                        return "error";
                    }
                    //--

                    if (!$this->paymentflg) { 
                        if (!empty($params["sellercd"]) || $params["reserveflg"] == 1) $this->paymentflg = true; 
                        if (SELLER_PAY_ETC) $this->paymentflg = false; 
                    } 

                    $item_array[$i][4] = $params['itemnm'];
                    $item_array[$i][5] = intval($params['sellingprice']);
                    $this->sum_quantity += intval($item_array[$i][3]) * intval($item_array[$i][5]);

                    if (empty($params["sellernm"]) && $params["reserveflg"]==0) { // ݌ﾉ
                        //$souryou["normal"] = SITE_SOURYOU;
                        $souryou["normal"] = 0;
                    } else if (empty($params["sellernm"]) && $params["reserveflg"]==1) { // \・                        //$souryou["reserve"] += SITE_SOURYOU;
                        $souryou["reserve"] += 0;
                    } else { // oi
                        $souryou[$params["sellercd"]] = $params["souryouprc"];
                    }

                }
            }
            $this->sum_quantity += array_sum($souryou);

            $this->session->setParameter('cart_items',$item_array);
        } else {
            return "error";
        }

        return $re_str ."success";
    }
    
    function setFix($value)
    {
        $this->fix = $value;
    }
    
    function getAddress()
    {
        $destination = $this->session->getParameter('destination');
        if (!is_array($destination)) $destination = NULL;
        $this->session->removeParameter('destination');
        return $destination;
    }

    function getBack() {
        $this->back = "cart";
        if ($this->fix) {
            $this->back = "nonmember_check";
        }
        return $this->back;
    }
  
    function getPrefData()
    {
        return $this->c_pref->selectAll();
    }

    function getPaymentarray()
    {
        $data = $this->session->getParameter('payment');
        $this->session->removeParameter('payment');
        return $data;
    }

    function getDt() { 
      return $this->payment->getMi($this->sum_quantity);
    }

    function getMiSig() {
      return $this->payment->getMiSig();
    }

    function getPrice() {
        return $this->sum_quantity;
    }

    function getCVSSig() {
      return $this->payment->getCVSSig($this->sum_quantity);
    }
}
?>
