<?php
	require_once '../../autoload.php';
	
	RightsCheck ("VIEW_EXAMIDENT");
	
	$id		 		= -1;
	$name 			= "";
		
	
	if ( isset ( $_REQUEST['id'] ) 				)	$id		 		= $_REQUEST['id'];
	if ( isset ( $_REQUEST['name'] )			)	$name		 	= $_REQUEST['name'];
	if ( isset ( $_REQUEST['description'] )		)	$description 	= $_REQUEST['description'];
			
	$conn = get_dbconnection();
	
	$response = -1;
	
	if ( $conn )
	{
		$sql = '';

		if ( $id == -1 )
			$sql = 'insert into examident(name, description) values (\''.pg_escape_string ($conn,$name).'\', \''.pg_escape_string ($conn,$description).'\' ) returning id;';
		else
			$sql = 'update examident set name=\''.pg_escape_string ($conn,$name).'\', description=\''.$description.'\' where id='.$id.'; commit;';
		
		$result = pg_query ( $conn, $sql );
		
		if ( $result )
		{
			if ( $id == -1 )
			{
				if ( $row = pg_fetch_row($result) )
					$response = $row [0];
			}
			else
				$response = $id;
		}
	}
	
	header ('Content-type: text/xml' );
	
	echo $response;
?>