開発メモ

開発用のメモです。

EC-CUBE 未来日チェック (SC_CheckError)

<?php

    //日付チェック
    // value[0] = 項目名
    // value[1] = YYYY
    // value[2] = MM
    // value[3] = DD
    public function CHECK_DATE_FUTURE( $value ) {
        $disp_name = $value[ 0 ];
        $keyname = $value[ 1 ];

        if( isset( $this->arrErr[ $keyname ] ) ) {
            return;
        }

        $start_year = date( "Y" );
        $start_month = date( "m" );
        $start_day = date( "d" );
        $end_year = $this->arrParam[ $value[ 1 ] ];
        $end_month = $this->arrParam[ $value[ 2 ] ];
        $end_day = $this->arrParam[ $value[ 3 ] ];
        if( (strlen( $start_year ) > 0 || strlen( $start_month ) > 0 || strlen( $start_day ) > 0) && ! checkdate( $start_month, $start_day, $start_year ) ) {
            $this->arrErr[ $keyname ] = "{$disp_name1}を正しく指定してください。<br />";
        }
        if( (strlen( $start_year ) > 0 && strlen( $start_month ) > 0 && strlen( $start_day ) > 0) && (strlen( $end_year ) > 0 || strlen( $end_month ) > 0 || strlen( $end_day ) > 0) ) {
            $date1 = sprintf( '%d%02d%02d000000', $start_year, $start_month, $start_day );
            $date2 = sprintf( '%d%02d%02d235959', $end_year, $end_month, $end_day );

            if( ($this->arrErr[ $keyname ] == '' && $this->arrErr[ $keyname2 ] == '') && $date1 > $date2 ) {
                $this->arrErr[ $keyname ] = "{$disp_name}に過去日は指定できません。<br />";
            }
        }
    }
Twitter: @asahina_alice