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


/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
require_once 'Net/UserAgent/Mobile.php';
/**
 * お届け先変更 入力
 *
 * @package     Customer.Mypage.Consumer.Insert.Form
 * @author      Your Name <mail@example.com>
 * @access      public
 */
class Customer_Mypage_Consumer_Insert_Form
{
    var $conregist;
    var $conregist_serial;
    var $c_consumer;
    var $c_pref;
    var $preflist;
    
    
    var $auth;
    
    var $from;
    
    var $memberview;
    var $lastnm;
    var $firstnm;
    var $lastnmkana;
    var $firstnmkana;
    
    var $mobile;
    
    function setConregist($conregist)
    {
        $this -> conregist = $conregist;
    }
    
    function getConregist()
    {
        return $this -> conregist;
    }
    
    function getPrefData()
    {
        $res = $this->preflist;
        return $res;
    }
    
    /**
     * execute
     *
     * @access  public
     */
    function execute()
    {
        //$this->mobile = &Net_UserAgent_Mobile::isMobile();
        
        //県データを変数に取っておく
        $this->preflist = $this->c_pref->selectAll();
        $log =& LogFactory::getLog();
        $log->debug("Customer_Mypage_Consumer_Insert_Formが実行されました", "Customer_Mypage_Consumer_Insert_Form#execute");

        $memberCd = $this -> auth -> getAuthData("membercd");
        if($memberCd && empty($this -> conregist -> memberCd)){
            $res = $this -> setConsumerInfo($memberCd);
            
            $mem = $this -> memberview -> SelectMemberNm($memberCd);
                if (!isset($this->lastnm) && 
                    !isset($this->firstnm) && 
                    !isset($this->lastnmkana) && 
                    !isset($this->firstnmkana)) {
        
                    $this->lastnm      = $mem["lastnm"];
                    $this->firstnm     = $mem["firstnm"];
                    $this->lastnmkana  = $mem["lastnmkana"];
                    $this->firstnmkana = $mem["firstnmkana"];
                    }
            
            //if($res === false) echo "err";
        }
        return 'success';
    }
    
    function setConsumerInfo($memberCd)
    {
        $consumerInfo = $this -> c_consumer -> select_one($memberCd);
        if($consumerInfo === false || !$consumerInfo) return false;
        
        //前処理
        $postalCode = split("-", $consumerInfo['postalcd']);
        $telNo1 = split("-", $consumerInfo['telno1']);
        $telNo2 = split("-", $consumerInfo['telno2']);                
        $sendPostalCode = split("-", $consumerInfo['sendpostalcd']);
        $sendTelNo = split("-", $consumerInfo['sendtelno1']);
        
        
        $this -> conregist -> zip[0] = $postalCode[0];
        $this -> conregist -> zip[1] = $postalCode[1];
        /*
        $this -> conregist -> zip1 = $postalCode[0];
        $this -> conregist -> zip2 = $postalCode[1];
        */
        $this -> conregist -> pref = $consumerInfo['prefcd'];
        $this -> conregist -> addr1 = $consumerInfo['addr1'];
        $this -> conregist -> addr2 = $consumerInfo['addr2'];
        $this -> conregist -> phone1 = $telNo1;
        $this -> conregist -> phone2 = $telNo2;
        $this -> conregist -> subzip[0] = $sendPostalCode[0];
        $this -> conregist -> subzip[1] = $sendPostalCode[1];
        $this -> conregist -> subpref = $consumerInfo['sendprefcd'];
        $this -> conregist -> subaddr1 = $consumerInfo['sendaddr1'];
        $this -> conregist -> subaddr2 = $consumerInfo['sendaddr2'];
        $this -> conregist -> subphone = $sendTelNo;
        $this -> conregist -> atena = $consumerInfo['addressee'];
        
        $this -> conregist -> updCnt = $consumerInfo['updcnt'];
        $this -> conregist -> memberCd = $memberCd;
    }
    
    function setConregist_serial($value)
    {
        
        $value = urldecode($value);
        $this -> conregist_serial = $value;
        $this -> conregist = unserialize($value);
    }

    function getConregist_serial()
    {
        return urlencode(serialize($this->conregist));
    }
    
    function isMobile()
    {
        $mobile = &Net_UserAgent_Mobile::isMobile();
        return $mobile;
    }
}
?>
