<?php
/**
 * Created by PhpStorm.
 * User: jaskokoyn
 * Date: 4/26/2015
 * Time: 9:23 PM
 */

include('../../inc/db.php');
include('../../inc/functions.php');

$params                     =   getParams();
$output                     =   array('status' => 1);

if(!isset($_SESSION['loggedin'])){
    dj($output);
}

if( !isReady($params, array( "id" ) ) ){
    dj($output);
}

$bid                        =   intval($params['id']);

$friendCheckQuery           =   $db->prepare("SELECT * FROM blocked_users WHERE uid = :uid AND bid = :bid");
$friendCheckQuery->execute(array(
    ":uid"                  =>  $_SESSION['uid'],
    ":bid"                  =>  $bid
));

if($friendCheckQuery->rowCount() === 0){
    $friendQuery            =   $db->prepare("INSERT INTO blocked_users(uid,bid) VALUES( :uid, :bid )");
}else{
    $friendQuery            =   $db->prepare("DELETE FROM blocked_users WHERE uid = :uid AND bid = :bid");
}

$friendQuery->execute(array(
    ":uid"                  =>  $_SESSION['uid'],
    ":bid"                  =>  $bid
));
dj($output);