<?php

if(!defined('IN_DISCUZ')){
    exit('Access Denied');
}

$fuid = $_GET['friend_id'];
$type = $_GET['type'];
$fusername = $_GET['fusername'];
$uid= empty($_GET['uid']) ? 0 : intval($_GET['uid']);//Êý¾Ý¶Î
if($uid){ $_G['uid']= $uid;};  
if(!$_G['uid']){
    echo odz_lang('not_loggedin');exit;
}

if(!$fuid){
   echo odz_lang('openid_not_exists');exit;
} 

if($type == 'add_friend') {
    if(DB::result_first('SELECT COUNT(*) FROM '.DB::table('home_follow_friend')." WHERE uid = '$_G[uid]' and fuid= '$fuid'")) {
      echo  odz_lang('user_already_froend');exit;
    }

   $result= DB::insert('home_follow_friend', array(
        'uid'=>$_G['uid'],
        'fuid'=>$fuid,
        'fusername'=>$fusername,
        'dateline'=>time()
    ));
   if($result){
       echo 1;exit; 
   }else{
       echo odz_lang('user_friend_error');exit;
   }
   
} else if($type == 'delete_friend') {
    if(!DB::result_first('SELECT COUNT(*) FROM '.DB::table('home_follow_friend')." WHERE uid = '$_G[uid]' and fuid= '$fuid'")) {
       echo odz_lang('delete_friend_error');exit;
    }
    if(DB::delete('home_follow_friend', DB::field('uid', $_G['uid']) .' AND '.DB::field('fuid', $fuid))){
        echo 2; exit;
    }else{
        echo odz_lang('delete_friend_success');exit;
    }
} else {
   echo odz_lang('undefined_action');exit;
    
}

?>