<?
function ka_actions(){
?>
<HTML>
<BODY>


<?PHP

 
// gets operation to perform
$operation = $_GET['operation'];

/**
 * delete a synonym
 */
if ($operation == 'deleteka'){
	$ka = $_POST['ka']; 
	// delete all responses
	$query = "select response_id from npc_triggers where area='$ka'";
	$result = mysql_query2($query);
	while ($line = mysql_fetch_array($result, MYSQL_NUM)){
		$query2 = "delete from npc_responses where id=$line[0]";
		$result2 = mysql_query2($query2);
	} 
	// delete all triggers
	$query = "delete from npc_triggers where area='$ka'";
	$result = mysql_query2($query); 
	// redirect
	?><SCRIPT language="javascript">
          document.location = "index.php?page=listkas";
       </script>
    <?PHP

	/**
	 * add a ka
	 */
}else if ($operation == 'createka'){
	$ka = $_POST['ka']; 
	// get last response id
	$newrespid = getNextId("npc_responses", "id"); 
	// get trigger id
	$newtriggerid = getNextId("npc_triggers", "id"); 
	// insert trigger
	$query = "insert into npc_triggers values($newtriggerid,'newka $ka', $newrespid, 0, -100, 100, '$ka',0)";
	$result = mysql_query2($query); 
	// insert response
	$query = "insert into npc_responses values($newrespid,'newka $ka', '','','','','','','','','',0)";
	$result = mysql_query2($query); 
	// redirect
	?><SCRIPT language="javascript">
          document.location = "index.php?page=listkas";
       </script>
    <?PHP

}else{ 
	// manage another operation here
	echo "Operation $operation not supported.";
}

?>



</body>
</html>
<?
}
?>