<?
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 advert_page_link WHERE advert_id=".$_GET['advert_id']." AND page_id=".$_GET['page_id'];
$mysqldb1->query($query);
$existing_rows = $mysqldb1->affectedRows();

$query = "
	INSERT INTO
		advert_page_link
	SET 
		advert_id=".$_GET['advert_id'].",
		page_id=".$_GET['page_id'].", 
		status=".$_GET['status'];

if ($existing_rows > 0) {
    $query = "
		UPDATE
			advert_page_link
		SET 
			status=".$_GET['status']."
		WHERE 
			advert_id=".$_GET['advert_id']." AND 
			page_id=".$_GET['page_id'];
}

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