<?
require_once('../include/user.php');
require_once('../include/mysql.php');
require_once('../include/functions.php');
require_once('../include/fb.php');

ob_start();

// SETUP MYSQL HANDLERS
$mysqldb1 = new mysql($host, $user, $pswd, $db);
$mysqldb1->connect();
$mysqldb1->select();

$query = "SELECT * FROM contact_category_link WHERE contact_id=".$_GET['contact_id']." AND contact_category_id=".$_GET['contact_category_id'];
$mysqldb1->query($query);
$existing_rows = $mysqldb1->affectedRows();

$query = "
	INSERT INTO
		contact_category_link
	SET 
		contact_id=".$_GET['contact_id'].",
		contact_category_id=".$_GET['contact_category_id'].", 
		status=".$_GET['status'];

if ($existing_rows > 0) {
    $query = "
		UPDATE
			contact_category_link
		SET 
			status=".$_GET['status']."
		WHERE 
			contact_id=".$_GET['contact_id']." AND 
			contact_category_id=".$_GET['contact_category_id'];
}

fb($query);
$response = 0;
if ($mysqldb1->query($query)) {
    $response = 1;
}
print $response;
?>