<?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: */

/**
 * 会員登録・変更フォーム
 *
 * @package     Customer.Mypage.Member.Insert.Form
 * @author      FUCO T.Hoshino
 * @access      public
 */
class Customer_Mypage_Member_Insert_Form
{
    var $title;
    var $pagename;
    
    var $ba;                //backAction ログイン前に閲覧していたページのID(?)
    
    var $l_crypt;
    var $bodyid;
    
    var $c_member;         //member DataBase
    var $c_secquestion;
    var $c_genre;          //ジャンル情報用ＤＢクラス
    var $c_moremember;     //その他の登録情報用ＤＢクラス
    
    var $questionlist;
    var $genrelist;        //foreachで並べるためのジャンル名の配列
    
    var $yearloopcnt;      //年を選択するリストのsectionループ回数
    
    var $newmember;        //新規会員登録情報
    var $newmember_serial; //新規会員登録情報のシリアライズ化情報
    
    var $auth;             //Authオブジェクトを取得
    
    
    /**
     * execute
     *
     * @access  public
     */
    function execute()
    {
        $log =& LogFactory::getLog();
        $log->debug("Customer_Mypage_Member_Insert_Formが実行されました", "Customer_Mypage_Member_Insert_Form#execute");
        
        $mobile = &Net_UserAgent_Mobile::isMobile();
        $re_str = ($mobile) ? "mobile_" : "";
        
        $memberCd = $this -> auth -> getAuthData("membercd");
        if($memberCd && !$this -> newmember -> memberCd){
            $res = $this -> setMemberInfo($memberCd);
//            if(!$res) echo "err";
        }
        
        // ループ回数の決定 下限が1900 上限が「今年」
        $this->yearloopcnt = date('Y') - 1900 + 1;
        
        //秘密の質問データをとっておく
        $this->questionlist = $this->c_secquestion->selectAll();
        
        // ジャンル情報の取得
        $this->genrelist   = $this->c_genre->selectAll(1);
        
        if ($this -> newmember -> member_div == ""){
            $this -> newmember -> member_div = ($mobile) ? 2 : 1;
        }
        
        return $re_str .'success';
    }


    function getSecQuestionData()
    {
        $res = $this->questionlist;
        return $res;
    }

    function getNewmember()
    {
        return $this -> newmember;
    }

    function setNewmember_serial($value)
    {
        $value = urldecode($value);
        $this -> newmember_serial = $value;
        $this -> newmember = unserialize($value);
    }

    function setMemberInfo($memberCd)
    {
        $memberInfo = $this -> c_member -> select_one($memberCd);
        if($memberInfo === false) return false;
        
        //前処理
        $mailAddr = split("@", $memberInfo['mailaddr']);
        
        $this -> newmember -> mailaddress_user   = $mailAddr[0];
        $this -> newmember -> mailaddress_domain = $mailAddr[1];
        $this -> newmember -> lastname           = $memberInfo['lastnm'];
        $this -> newmember -> lastname_kana      = $memberInfo['lastnmkana'];
        $this -> newmember -> frontname          = $memberInfo['firstnm'];
        $this -> newmember -> frontname_kana     = $memberInfo['firstnmkana'];
        $this -> newmember -> nickname           = $memberInfo['nicknm'];
        if (is_null($memberInfo['birthdate'])){
            $this -> newmember -> select_year    = "";
            $this -> newmember -> select_month   = "";
            $this -> newmember -> select_day     = "";
        } else {
            $birth_tmp = explode("-", $memberInfo['birthdate']);
            $this -> newmember -> select_year    = $birth_tmp[0];
            $this -> newmember -> select_month   = $birth_tmp[1];
            $this -> newmember -> select_day     = $birth_tmp[2];
        }
        $this -> newmember -> sex                = $memberInfo['sex'];
        //$this -> newmember -> password           = $memberInfo['password'];
        $this -> newmember -> question           = $memberInfo['secquestioncd'];
        $this -> newmember -> answer             = $this -> l_crypt -> decrypt($memberInfo['secquestionans']);
        if ($memberInfo['maildiv'] == 1 || $memberInfo['maildiv'] == 3){
            $this -> newmember -> mail_accept = 1;  // 受取許可
        } else {
            $this -> newmember -> mail_accept = 0;  // 受取拒否
        }
        
        $this -> newmember -> updCnt             = $memberInfo['updcnt'];
        $this -> newmember -> memberCd           = $memberCd;
        $this -> newmember -> category           = $this->c_moremember->getGenreMember($memberCd);
        $this -> newmember -> member_div         = $memberInfo['memberdiv'];
        return true;
    }

    function getBa()
    {
        return $this -> ba;
    }

    function getYearLoopCount()
    {
        return $this -> yearloopcnt;
    }

    function getGenreList()
    {
        return $this -> genrelist;
    }

    function getGenreExists($var)
    {
        $genrecd = $var["genrecd"];
        
        foreach($this->newmember->category as $selectGenre){
        
            if($selectGenre == $genrecd) return true;
        }
        
        return false;
    }

    function getUpdCnt()
    {
        return $this->newmember->updCnt;
    }

}
?>
