<?php  

include_once("config.php");
include_once("sem/updates.php");
include_once("sem/queries.php");

$queryType = $_REQUEST["queryType"];

if ($queryType == "insertslotvalue"){
	$slotQName = $_REQUEST["slotQName"];
	$value = $_REQUEST["value"];
	$label = $_REQUEST["label"];
	$qname = $_REQUEST["qname"];
	$lang = $_REQUEST["lang"];
	$results = insertSlotValue($qname, $slotQName, $value, $label, $lang);
}
else if ($queryType == "editslotvalue"){
	$slotQName = $_REQUEST["slotQName"];
	$newValue = $_REQUEST["newValue"];
	$oldValue = $_REQUEST["oldValue"];
	$oldLabel = $_REQUEST["oldLabel"];
	$newLabel = $_REQUEST["label"];
	$qname = $_REQUEST["qname"];
	$lang = $_REQUEST["lang"];
	//echo "$qname, $slotQName, $newValue, $newLabel, $lang, $oldValue";
	$results = editSlotValue($qname, $slotQName, $newValue, $newLabel, $lang, $oldValue, $oldLabel);
}
else if ($queryType == "deleteslotvalue"){
	$slotQName = $_REQUEST["slotQName"];
	$value = $_REQUEST["value"];
	$qname = $_REQUEST["qname"];
	$lang = $_REQUEST["lang"];
	$results = deleteSlotValue($qname, $slotQName, $value, "", $lang);
}
else if ($queryType == "removeslot"){
	$slotQName = $_REQUEST["slotQName"];
	$qname = $_REQUEST["qname"];
	$results = removeSlot($qname, $slotQName);
}
else if ($queryType == "insertnewtype"){
	$typeLabel = $_REQUEST["typeLabel"];
	$qname = $_REQUEST["qname"];
	$type = $_REQUEST["type"];

	if (strlen($typeLabel) > 0){
		$type = label2QName($typeLabel);
	}
	$results = insertNewType($qname, $type);	
}
else if ($queryType == "deletetype"){
	$typeLabel = $_REQUEST["typeLabel"];
	$qname = $_REQUEST["qname"];
	$type = $_REQUEST["type"];

	if (strlen($typeLabel) > 0){
		$type = label2QName($typeLabel);
	}
	$results = deleteType($qname, $type);	
}
else if ($queryType == "deleteelement"){
	$qname = $_REQUEST["qname"];
	$results = deleteElement($qname);	
}
else if ($queryType == "insertlexentry"){
	$desc = $_REQUEST["description"];
	$package = $_REQUEST["package"];
	$inst = $_REQUEST["instance"];
	$lang = $_REQUEST["lang"];
	$results = insertLexiconEntry($desc, $inst, $package, $lang);
}
else if ($queryType == "editlexentrydescription"){
	$qname = $_REQUEST["qname"];
	$desc = $_REQUEST["description"];
	$results = editLexiconEntryDescription($qname, $desc);
}
else if ($queryType == "insertelement"){
	$elementType = $_REQUEST["elementType"];
	$typeLabel = $_REQUEST["typeLabel"];
	$label = $_REQUEST["label"];
	$package = $_REQUEST["package"];
	$results = insertElement($elementType, $typeLabel, $label, $package);
}
else if ($queryType == "insertpackage"){
	$label = $_REQUEST["label"];
	$results = insertPackage($label);
}
else if ($queryType == "publish"){
	$serversStr = $_REQUEST["servers"];
	$servers = json_decode($serversStr, true);
	$results = publish($servers);
}

echo $results;  
  
?>  