<?php



if(!defined('IN_DISCUZ')){

    exit('Access Denied');

}



if(!$_G['uid']){

    odz_error('not_loggedin', ODZ_ERR_LOGIN);

}



$type = trim($_GET['type']);

if($type == 'mobile') {

    $mobile = trim($_GET['mobile']);

    $code = trim($_GET['code']);

    if(!$mobile || !preg_match('/^(\+)?(86)?0?1\d{10}$/', $mobile)) {

        odz_error('error_phone_number');

    }

    if(!$code) {

        odz_error('code_empty');

    }

    if(DB::result_first('SELECT COUNT(*) FROM '.DB::table('mocuz_mobile')." WHERE uid = '$_G[uid]'")) {

        odz_error('user_already_used');

    }

    if(DB::result_first('SELECT COUNT(*) FROM '.DB::table('mocuz_mobile')." WHERE mobile = '$mobile'")) {

        odz_error('phone_number_already_used');

    }

    if(!DB::result_first('SELECT COUNT(*) FROM '.DB::table('mocuz_mobile_verify')." WHERE mobile = '$mobile' AND code = '$code'")) {

        odz_error('code_error');

    }

    DB::insert('mocuz_mobile', array(

        'uid'=>$_G['uid'],

        'mobile'=>$mobile,

        'dateline'=>$_G['timestamp']

    ));

    odz_success('phone_bind_succeed');

} else {

    odz_error('undefined_action');

}



?>