<?php
/**
 * 
 * @copyright   2000-2007 LOCKON CO.,LTD. All Rights Reserved.
 * @version CVS: $Id: 1.0 2006-06-04 06:38:01Z matsumura $
 * @link        http://www.lockon.co.jp/
 *
 */
 
class LC_Page {
    
    function LC_Page() {
        $this->tpl_mainpage = MODULE_PATH . "blayn/blayn.tpl";
        $this->tpl_title = "ブレインIP登録";
        $this->tpl_subtitle = "ブレインIP設定モジュール";
    }
}
$objPage = new LC_Page();
$objView = new SC_AdminView();
$objQuery = new SC_Query();


if(isset($_POST['blayn_ip01'])) {
    $objPage->arrErr = lfCheckError();
    if(count($objPage->arrErr) <= 0) {
        lfDelete();
        lfRegist();
    }
}
$objPage->arrIP = lfGetIP();

$objView->assignobj($objPage);      //変数をテンプレートにアサインする
$objView->display($objPage->tpl_mainpage);      //テンプレートの出力

// ------------------------------------------------------------------------------------------------------

function lfCheckError() {
    
    $objErr = new SC_CheckError;
    
    $arrErr->arrErr[] = $objErr->doFunc(array("IPアドレス", "blayn_ip01"), array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
    $arrErr->arrErr[] = $objErr->doFunc(array("IPアドレス", "blayn_ip02"), array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
    $arrErr->arrErr[] = $objErr->doFunc(array("IPアドレス", "blayn_ip03"), array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
    $arrErr->arrErr[] = $objErr->doFunc(array("IPアドレス", "blayn_ip04"), array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
    sfprintr($arrErr->arrErr);
    if(is_array($arrErr->arrErr)) {
        foreach($arrErr->arrErr as $val) {
            if(!empty($val)) {
                sfprintr($val);
                $arrVal = split("。", $val);
                foreach($arrVal as $val02) {
                    $val02 .= "。";
                    sfprintr($val02);
                    if(!ereg("$val02", $arrErr->error)) {
                        sfprintr($arrErr->error);
                        $arrErr->error .= $val02;
                        sfprintr($arrErr->error);
                    }
                
                }
            }
        }
    }
    return($arrErr->error);
}

function lfRegist() {
    
    global $objQuery;
    
    $blayn_ip .= $_POST['blayn_ip01'];
    $blayn_ip .= "." . $_POST['blayn_ip02'];
    $blayn_ip .= "." . $_POST['blayn_ip03'];
    $blayn_ip .= "." . $_POST['blayn_ip04'];
    
    $sqlVal['blayn_ip'] = $blayn_ip;
    $objQuery->insert("dtb_blayn", $sqlVal);
}


function lfDelete() {
    
    global $objQuery;
    
    $objQuery->delete("dtb_blayn");
}


function lfGetIP() {
    
    global $objQuery;
    
    $arrSql = $objQuery->select("blayn_ip", "dtb_blayn");
    $arrRet = split("\.", $arrSql[0]['blayn_ip']);
    return $arrRet;

}

?>
