<?php
/*
	Copyright(c) 2010 Shift Tech Inc. All Rights Reserved.
 	http://www.shift-tech.jp/

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*********************************************
 キャリア判定クラス
**********************************************/
class chkAgent {

	var $agent;

	/**
     * キャリア判定処理
	 * @author   sonehara
	 * @param    なし
	 * @return   $tpl_name String テンプレート名
	 *
	 * キャリア判別を行い、機種別のテンプレート名を取得する。
	 *
	 */
	function chkUserAgent() {

		$this->agent = &Net_UserAgent_Mobile::factory();

		//変数宣言
		$comp_code;
		$model;

		//キャリア判定（会社コード設定）
		if ($this->agent->isDoCoMo()) {
			$comp_code = 1;
			$model = "docomo";

		} elseif ($this->agent->isEZweb()) {
			$comp_code = 2;
			$model = "au";

		} elseif ($this->agent->isVodafone()) {
			$comp_code = 3;
			$model = "softbank";

		} else {
			$comp_code = 1;
			$model = "docomo";
		}

		//テンプレート名取得
		return array($comp_code, $model);
	}

	/**
     * 画面サイズの取得
	 * @author   Nishino
	 * @return   width	integer
	 */
	function getDispSize() {
	    $display = $this->agent->getDisplay();
	    $w = $display->getWidth();
	    //標準サイズを幅180とする
	    if ($w == 0) $w = 180;
	    return $w;
	}
	/**
     * 個体識別番号を取得処理
	 * @author   0508 miyashita
	 * @param    なし
	 * @return   $ser,$icc,$srn,$ezn String 個体識別番号
	 *
	 * キャリア判別を行い、機種別のテンプレート名を取得する。
	 *
	 */
	function chkUim() {

		$ag = &Net_UserAgent_Mobile::factory();
		$agent = $_SERVER["HTTP_USER_AGENT"];
		$code = "";
		$ser = "";
		$icc = "";
		if (preg_match("/^DoCoMo\/[12]\.0/i", $agent)) {
			if(preg_match("/ser([a-zA-Z0-9]+)/",$agent,$dprg)){
		    	if(strlen($dprg[1]) == 11){
		        	$ser = $dprg[1];
		        }elseif(strlen($dprg[1]) == 15){
		        	$ser = $dprg[1];
		        	if(preg_match("/icc([a-zA-Z0-9]+)/",$agent,$dpeg)){
		            	if(strlen($dpeg[1]) == 20){
		              		$icc = $dpeg[1];
		            	}
		          	}
		        }
			    $code = $ser.$icc;
				$_SESSION['UIM'] = $code;
		    }

		}elseif(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]980|SoftBank)\//i", $agent)){
	    	$code = $ag->getSerialNumber();
			$_SESSION['UIM'] = $ag->getSerialNumber();
		}elseif(preg_match("/^KDDI\-/i", $agent)){
			$code = $_SERVER['HTTP_X_UP_SUBNO'];
			$_SESSION['UIM'] = $code;
		}else {
			$code = "";
		}
		return $code;
	}
}
?>