<?php
if(!isset($_SESSION)) session_start();
include("config.php");

require_once("demosettings.php");
include("loginCheckPoint.php");
include("sqlUtils.php");
include('parseUtils.php');
require_once 'allConceptsData.php';
require_once 'allConceptArr.php';
require_once("slotToCaption.php");
$mysqli = sqlCreateConnection("SearchEng");
global $username;
require_once 'settings.php';
$settings_class =  new Settings($mysqli, $username);
$allConceptArrDB = $settings_class->getAllConceptsArr();

$allConceptFlavor =  $settings_class->getActiveFlavor();

$concept_class =  new AllConceptsData($mysqli, $allConceptArrDB, $allConceptFlavor, $username);

	$response = array();

    foreach($concept_class->getMergedData() as $element){
	  $response["tableNames"][] = ontologyName2TableName($element["name"]);
    }
	
															
    $sql = "SELECT username FROM userCake_Users ORDER BY username";
	$res = $mysqli->query($sql);
	if (!empty($res)){	
		while ($row = $res->fetch_object()){
			$response["users"][] = $row->username;
		}
	}
	
	//languges
	$sql = "SELECT DISTINCT languages FROM files WHERE languages IS NOT NULL";
	$res = $mysqli->query($sql);
	$arr = array();
	if (!empty($res)){	
		while ($row = $res->fetch_object()){
			$e = explode(";", $row->languages);
			foreach ($e as $v){
				if (strlen($v) > 0)
					$arr[$v] = $v;	
			}
			$e = explode(",", $row->document_topic);
			foreach ($e as $v){
				if (strlen($v) > 0)
					$arr[$v] = $v;	
			}		
		}
	}
	ksort($arr);
	foreach ($arr as $v){
		$response["languages"][] = $v;
	}
	
	//topic
	$sql = "SELECT DISTINCT domain,document_topic FROM files WHERE (domain IS NOT NULL) OR (document_topic IS NOT NULL)";
	$res = $mysqli->query($sql);
	$arr = array();
	if (!empty($res)){	
		while ($row = $res->fetch_object()){
			$e = explode(";", $row->domain);
			foreach ($e as $v){
				if (strlen($v) > 0)
					$arr[$v] = $v;	
			}
			$e = explode(";", $row->document_topic);
			foreach ($e as $v){
				if (strlen($v) > 0)
					$arr[$v] = $v;	
			}		
		}
	}
	ksort($arr);
	foreach ($arr as $v){
		$response["topic"][] = $v;
	}
	echo json_encode($response);
?>