<?php

/**

 *     个人中心关注

 *

 *     2016-4-22 wzf $

 */

if(!defined('IN_DISCUZ')){

    exit('Access Denied');

}

$fuid = $_GET['friend_id'];

$type = $_GET['type'];

$server = $_GET['server'];

if($server==1){

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

        showmessage('not_loggedin');

    }

    if(!$fuid){

       showmessage('openid_not_exists');

    } 

    $user= DB::fetch_first('SELECT username  FROM '.DB::table('common_member')." as u  WHERE uid = '$fuid'");

    $fusername=$user['username'];

    if($type == 'add_friend') {

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

           showmessage('user_already_froend');

        }

       $result= DB::insert('home_follow_friend', array(

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

            'fuid'=>$fuid,

            'fusername'=>$fusername,

            'dateline'=>time()

        ));

       if($result){

           odz_result(array('is_friend_id'=>'1'));

       }else{

           showmessage('user_friend_error');

       }

    } else if($type == 'delete_friend') {

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

            showmessage('delete_friend_error');

        }

        if(DB::delete('home_follow_friend', DB::field('uid', $_G['uid']) .' AND '.DB::field('fuid', $fuid))){

            odz_result(array('is_friend_id'=>'2'));

        }else{

            showmessage('delete_friend_error');

        }

    } else {

       showmessage('undefined_action');

    }

}else{

    $uid= empty($_GET['uid']) ? 0 : intval($_GET['uid']);//数据段

    if($uid){ $_G['uid']= $uid;};  

    $fusername = $_GET['fusername'];

    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_error');exit;

        }

    } else {

       echo odz_lang('undefined_action');exit;

    }

}

?>