<?php
session_start();
if (!isset($_SESSION['FirstName'])) {
	die('0');
}

include ('includes/db1config.php');
include ('../includes/mysql_connect.php');

$response = array(
	'result' => 1
);

if (isset($_POST['selected_tags']) && !empty($_POST['selected_tags'])) {
	$selectedTags = $_POST['selected_tags'];
	$selectedTags = explode(',', $_POST['selected_tags']);
	foreach ($selectedTags as $key => $tag) {
		$selectedTags[$key] = trim($tag);
	}
} else {
	$selectedTags = array();
}

$sql = "SELECT *
		FROM blog_tags ";
if (!empty($selectedTags)) {
	$sql .= "WHERE tags NOT IN ('";
	$sql .= implode("','", $selectedTags);
	$sql .= "') ";
}
$sql .= " ORDER BY tags ASC";

$result = mysql_query($sql) or die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {
	$tags[] = $row['tags'];
}

$response['result'] = 1;
$response['tags'] = $tags;

echo json_encode($response);
die();

?>