<?php
/**
    example モジュール
 */

class example{

    var 
$module="example";    //モジュール(クラス)名をここで決め打ちしておく(Simpley利用時必須)
    
var $message;            //モジュール用メッセージ(Simpley利用時必須)
    
var $message_main;        //コアメッセージ類(Simpley利用時必須)
    
var $main_option;        //オプション設定情報(Simpley利用時必須)

    /**
        コンストラクタ
        ここで初期化を呼び出しメンバへセットする
        汎用クラスの再利用等で、すでにコンストラクタが有る場合はinit()を追加してください。
        同じ名前の init() が有る場合はメソッド名を変更して追加してください。
        PHP5は専用のコンストラクタへ追加して
    **/
    
function example(){
        
$this->init();
    }

    
/*
        初期化
        init()がかぶってたら他の名前に変更しコンストラクタへ追加
    */
    
function init(){
        
clearstatcache();
        global 
$MESSAGE_MAIN;                //コアメッセージ(Simpley利用時必須)
        
global $MAIN_OPTION;                //全設定(Simpley利用時必須)
        
$this->main_option  =$MAIN_OPTION;    //全設定(Simpley利用時必須)
        
$this->message_main =$MESSAGE_MAIN;    //コアメッセージ(Simpley利用時必須)
        
if( is_file(MAIN_DIR.'/modules/'.$this->module.'/langs/'.MAIN_LANG.'.mes') ){
            include(
MAIN_DIR.'/modules/'.$this->module.'/langs/'.MAIN_LANG.'.mes');
        } else {
            echo 
$this->message_main["ERR_LANG"].':'.MAIN_DIR.'/modules/'.$this->module.'/langs/'.MAIN_LANG.'.mes';
        }
    }





    
/**
        ----------------スキンに出力させるメソッド(モデル・コントローラ)はここから下----------------
     */

    /**
        テストメソッド
        @access public
        @param  $param  array
        @return array
    **/
    
function test($param) {
        
$out=array();
        
$message ='';
        
$message.=$this->message['hello World'];

        if( 
strlen($message)>){
            
$out['message']=$message;
        }

        if( 
count($out)==){
            
$out=true;
        }
        return 
$out;
    }

    
/**
        テストメソッド2
        @access public
        @param  $param  array
        @return array
    **/
    
function test2$param ){
        
$out=array();

        
$tmp=array( array(0,'shina'=>'BANANA','price'=>'10') , array(1,'shina'=>'ORANGE','price'=>'15') );

        
$out['list']=$tmp;


        
$tmp2[]=array('shina'=>'BANANA2','price'=>'1000');
        
$tmp2[]=array('shina'=>'ORANGE2','price'=>'1500');


        
$out['list2']=$tmp2;

        if( 
count($out)==){
            
$out=true;
        }
        return 
$out;
    }


    
/**
        テストメソッド3
        @access public
        @param  $param  array
        @return array
    **/
    
function test3$param ){
        
$out=array();

        
$tmp2[]=array('kosuu'=>'10','tanni'=>'個');
        
$tmp2[]=array('kosuu'=>'10','tanni'=>'百個');

        
$tmp=array( array(0,'shina'=>'BANANA','price'=>'10','select'=>$tmp2) , array(1,'shina'=>'ORANGE','price'=>'15','select'=>$tmp2) );
/*
        foreach( $tmp as $line ){
            $out['list'][]=array('shina'=>$line[0],
                                'price'=>$line[0],
                                'select'=>$tmp2,
                                );
        }
*/

        
$out['list']=$tmp;

//var_dump($out);

        
if( count($out)==){
            
$out=true;
        }
        return 
$out;
    }


    
/**
        テストメソッド4
        @access public
        @param  $param  array
        @return array
    **/
    
function test4$param ){
        
$out=array();

        if( isset(
$param['mode']) ){
            
$mode=$param['mode'];
        }

        if( !isset(
$_REQUEST['mode']) ){
            
$_REQUEST['mode']=null;
        }

        if( 
strlen($_REQUEST['mode'])!==){
            
$mode=$_REQUEST['mode'];
        }

        if( !isset(
$mode) ){
            
$mode="";
        }

        switch (
$mode) {
            case 
'val':
                
$out['message']=$this->message['test4']['val'];
                
$out['val']='on';
            break;

            case 
'rval':
                
$out['message']=$this->message['test4']['rval'];
                
$out['rval']='on';
            break;

            case 
'xval':
                
$out['message']=$this->message['test4']['xval'];
                
$out['xval']='on';
            break;

            case 
'uval':
                
$out['message']=$this->message['test4']['uval'];
                
$out['uval']='on';
            break;

            default:
                
$out['message']=$this->message['test4']['none'];
            break;
        }

        
$out['MODE']=$mode;

        if( 
count($out)==){
            
$out=true;
        }
        return 
$out;
    }



    
/**
        テストメソッド5
        @access public
        @param  $param  array
        @return array
    **/
    
function test5$param ){
        
$out=array();
        
$message='';

        
//main

//print_r($param);
//print_r($this);


        
if( strlen($message)!==){
            
$out['message']=$message;
        }

        if( 
count($out)==){
            
$out=true;
        }
        return 
$out;
    }



    
/**
        テストメソッド6
        @access public
        @param  $param  array
        @return array
    **/
    
function test6($param){
        
$out=array();
        
$message='';


        
$Simpley = new Simpley;
        
$ret=$Simpley->ConvartEnc$_GET );

        
$message.="Internal Encoding : ".$Simpley->GetInternalEnc()."\n";
        
$message.="Output Encoding : ".$Simpley->GetOutputEnc()."\n";

        if( 
strlen($message)!==){
            
$out['message']=$message;
        }

        if( 
count($out)==){
            
$out=true;
        }
        return 
$out;
    }



    
/**
        テストメソッド7
        @access public
        @param  $param  array
        @return array
    **/
    
function test7($param){
        
$out=array();
        
$message='';

        
//var_dump(mb_http_input('I'));

        
if( !isset($_REQUEST['emoji']) ){
            
$_REQUEST['emoji']=null;
        }

        
$emoji=$_REQUEST['emoji'];
        
$emoji=emoji_input_conv($emoji);

        
$out['emoji']=$emoji;


        if( 
strlen($message)!==){
            
$out['message']=$message;
        }

        if( 
count($out)==){
            
$out=true;
        }
        return 
$out;
    }

    
//テストメソッド8
    
function test8$param ){
        
$out=array();
        
$message='';
        if( !isset(
$_REQUEST['emoji']) ){
            
$_REQUEST['emoji']=null;
        }

        
//$emoji=emoji_input_conv($_REQUEST['emoji']);
        
$simpley = new Simpley;
        
$emoji=$simpley->valconv($_REQUEST['emoji'] , );
        
//$a=$simpley->ModuleObject["example"]->test3(array());
        
$a=$this->test3(array());
        
$out['list']=$a['list'];

/*
        $file='/home/nmx00/public_html/fw/config/Simpley.php';
        $file_value=Simpley::GetReadFile($file);
        $emoji.=$file_value;
*/

        
$out['input']=$emoji;
        if( 
count($out)==){
            
$out=true;
        }
        return 
$out;
    }

    
/*
        テストメソッド 9
    */
    
function test9$param ){
        
$out=array();
        
$message='';

        global 
$emoji_e;
        global 
$emoji_i;
        global 
$emoji_v;
        global 
$emoji_h;

        
$i=1;
        foreach( 
$emoji_i as $key=>$value ) {
            
$br='';
            if( !(
$i $param['br']) ){
                
$br='ON';
            }
            
$out['list'][($i-1)]=array('key'=>$key 'value'=>$value 'br'=>$br );
            
$i++;
        }

        if( 
count($out)==){
            
$out=true;
        }
        return 
$out;
    }

    
/*
        テストメソッド 10
    */
    
function test10$param ){
        
$out=array();
        
$message='';

        
$select_box=array();
        
$select_box[0]=array( 'id'=>'value'=>'-no select-' );
        for(
$i=1;$i<=15;$i++){
            
$select_box[$i]=array( 'id'=>$i 'value'=>'-'.$i.'select-' );
        }

        if( !isset(
$_REQUEST['select']) ){
            
$_REQUEST['select']=0;
        }
        
$select=$_REQUEST['select'];



        
$out['select_box']=$select_box;
        
$out['select']=$select;
        if( 
count($out)==){
            
$out=true;
        }
        return 
$out;
    }


    
/*
        テストメソッド 11

    郵便番号テーブル(SQLite用)

CREATE TABLE post_number(
jis           VARCHAR NOT NULL,
post5         VARCHAR NOT NULL,
post7         VARCHAR NOT NULL,
ken_kana      VARCHAR NOT NULL,
city_kana     VARCHAR NOT NULL,
machi_kana    VARCHAR NOT NULL,
ken           VARCHAR NOT NULL,
city          VARCHAR NOT NULL,
machi         VARCHAR NOT NULL,
ext1          VARCHAR NOT NULL,
ext2          VARCHAR NOT NULL,
ext3          VARCHAR NOT NULL,
ext4          VARCHAR NOT NULL,
ext5          VARCHAR NOT NULL,
ext6          VARCHAR NOT NULL
);
CREATE INDEX post_number_idx_post7 ON post_number(post7);
CREATE INDEX post_number_idx_ken ON post_number(ken);
CREATE INDEX post_number_idx_city ON post_number(city);
CREATE INDEX post_number_idx_machi ON post_number(machi);
CREATE INDEX post_number_idx_ken_kana ON post_number(ken_kana);
CREATE INDEX post_number_idx_city_kana ON post_number(city_kana);
CREATE INDEX post_number_idx_machi_kana ON post_number(machi_kana);

    */

    
function test11$param ){
        
$out=array();
        
$message='';

        
/* セレクトボックスを組み立てる 
            本当は外部メッセージファイルに値を入れて外部メソッドで組み立てて値を返すのがイイかも 
            $this->message['select_box'][]=array( 'id'=>0 , 'value'=>'-no select-' );みたいな感じで・・
            そうすれば表題の言語エンコーディング気にしなくてイイ
        */
        
$select_box=array();
        
$select_box[]=array( 'id'=>'value'=>'-no select-' );
        
$select_box[]=array( 'id'=>'value'=>'-PloofSearch-' );
        
$select_box[]=array( 'id'=>'value'=>'-CitySearch-' );
        
$select_box[]=array( 'id'=>'value'=>'-TownSearch-' );
        
$select_box[]=array( 'id'=>'value'=>'-PostNumberSearch-' );

        
$simpley = new Simpley;    //Simpleyをnewする・・
        
if( count($_POST)!==0){
            
//外部エンコーディングから内部エンコーディングに変換(連想配列対応)
            //内外のエンコーディングが同一の場合はそのまま値が返ってくる
            //phpで自動変換の場合もそのまま返ってくる(はず)
            // ini_get( 'mbstring.http_input' )を取得して判定して返しているので・・・
            
$simpley->ConvertEncreset();    //メンバ変数初期化
            
$_POST=$simpley->ConvartEnc($_POST );
        }

        if( !isset(
$_POST['mode']) ){
            
$_POST['mode']=0;
        }

        if( !isset(
$_POST['srarch']) ){
            
$_POST['srarch']=null;
        }

        
$mode=intval($_POST['mode']);
        
$search_org=$_POST['srarch'];

        
//DBに有ったクオートを追加(サイトコンフィグレーションにより自動的に決定)
        //DBに値を投げる前これやらないとSQLインジェクションやられるYO!!
        
$search=$simpley->DBquote($search_org);
        
$search=$simpley->valconv$search );    //DBと内部エンコードが違う場合があるので、内部からDBエンコーディングへ変換

        
if($mode!==and strlen($search)==0){    //サーチワードが無ければ検索しない
            
$mode=0;
        }

        
$ret=array();
        
//検索条件
        
switch ($mode) {
            case 
1:        //都道府県から検索
                
$ret=$this->GetPloofSearch($search);
            break;
            case 
2:        //市町村から検索
                
$ret=$this->GetCitySearch($search);
            break;
            case 
3:        //町から検索
                
$ret=$this->GetTownSearch($search);
            break;
            case 
4:        //郵便番号7桁から検索
                
$ret=$this->GetPostNumberSearch($search);
            break;

         }

        if( 
$mode>){
            if( 
$ret===false ){        //===の代わりに !is_array() でもいいかも
                
$message.=$this->message['ERR_DB'];        //DBエラーメッセージ
            
}elseif( count($ret)==){
                
$message.=$this->message['NO_DATA'];    //データが無いよメッセージ
            
}else{
                
//スキンパース用変数に取得したリストをセット
                //エンコーディングが違う場合はスキンで自動変換
                // SQL SELECT * で取った場合 レコード番号添え字+カラム名がキーになるよ。
                
if( !(MAIN_LANG==DB_LANG) ){    //DBと内部エンコードが違った場合
                    
$simpley->ConvertEncreset();    //メンバ変数初期化
                    
$ret=$simpley->ConvartEnc$ret );    //DBエンコードから内部エンコードへ
                
}
                
$out['list']=$ret;
            }
        }

        
//テキストボックスにそのまま値を返すため用(skinはxvalがいいよ)
        
$out['search_org']=$search_org;

        
//スキンパース用変数にセレクトボックスの内容をセット
        
$out['select_box']=$select_box;

        if( 
strlen($message)!==0){
            
$out['message']=$message;
        }

        if( 
count($out)==){
            
$out=true;
        }
        return 
$out;
    }


    
/* 都道府県から検索するメソッド */
    
function GetPloofSearch($search){
        
//DB毎に違うSQLじゃないと逝けない場合はcaseに適時入れてね。
        
switch (MAIN_DB) {
            case 
'postgres':
            case 
'mysql':
            case 
'oracle':
            case 
'sqlite':
            case 
'mssql':
                
$sql ="SELECT * FROM post_number WHERE ken like '$search%'";
            break;
        }
        
$val=SelectRec($sql);
        return 
$val;
    }

    
/* 市町村から検索するメソッド */
    
function GetCitySearch($search){
        switch (
MAIN_DB) {
            case 
'postgres':
            case 
'mysql':
            case 
'oracle':
            case 
'sqlite':
            case 
'mssql':
                
$sql ="SELECT * FROM post_number WHERE city like '$search%'";
            break;
        }
        
$val=SelectRec($sql);
        return 
$val;
    }

    
/* 町から検索するメソッド */
    
function GetTownSearch($search){
        switch (
MAIN_DB) {
            case 
'postgres':
            case 
'mysql':
            case 
'oracle':
            case 
'sqlite':
            case 
'mssql':
                
$sql ="SELECT * FROM post_number WHERE machi like '$search%'";
            break;
        }
        
$val=SelectRec($sql);
        return 
$val;
    }

    
/* 郵便番号7桁から検索するメソッド */
    
function GetPostNumberSearch($search){
        switch (
MAIN_DB) {
            case 
'postgres':
            case 
'mysql':
            case 
'oracle':
            case 
'sqlite':
            case 
'mssql':
                
$sql ="SELECT * FROM post_number WHERE post7 = '$search'";
            break;
        }
        
$val=SelectRec($sql);
        return 
$val;
    }

    
/*
        テスト12メソッド
    */
    
function test12$param ){
        
$list_s[]=array('id'=>1,'val'=>'number 1');
        
$list_s[]=array('id'=>2,'val'=>'number 2');
        
$list_s[]=array('id'=>3,'val'=>'number 3');
        
$list_s[]=array('id'=>4,'val'=>'number 4');

        
$list[]=array('id'=>1,'val'=>'number 1');
        
$list[]=array('id'=>2,'val'=>'number 2');
        
$list[]=array('id'=>3,'val'=>'number 3');
        
$list[]=array('id'=>4,'val'=>'number 4');

        
$out['list_s']=$list_s;
        
$out['list']=$list;

        return 
$out;
    }

    
/*
        テスト13メソッド
    */
    
function test13$param ){
        
$out['list']=array('key1'=>'value','key2'=>'value2','key3'=>'value3' );
        
$out['list2']=array('1key1'=>'1value1','2key2'=>'2value2','3key3'=>'3value3' );
        return 
$out;
    }



    
/*
        テスト14メソッド
    */
    
function test14$param ){

        if( !isset(
$_SESSION['count']) ){
            
$_SESSION['count']=0;
        }

        
$_SESSION['count']++;
        
$out['count']=$_SESSION['count'];

        return 
$out;
    }

    
/*
        テスト15メソッド
    */
    
function test15$param ){

        
$out=array();

        if( isset(
$param['BR']) ){
            
$br=$param['BR'];
        }else{
            
$br='<br>';
        }

        if( isset(
$param['BR_NUM']) ){
            
$br_num=intval($param['BR_NUM']);
        }else{
            
$br_num=10;
        }


        if( isset(
$_GET['count']) ){
            
$count=intval($_GET['count']);
        }else{
            
$count=0;
        }

        if( 
$count!==and $count<10001 ){    //10000回以下だけ処理する
            
for( $i=$count>=$i $i++ ){

                if( !(
$i $br_num)==){
                    
$br_tmp='';
                }else{
                    
$br_tmp=$br;
                }

                
$out['list'][]=array('count'=>$i,'br'=>$br_tmp);
            }
        }

        
$out['count']=$count;

        if( 
count($out)==){
            
$out=true;
        }

        return 
$out;
    }


}

?>