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

		if ( $lro_id == -1 )
			$sql = "insert into login_role(name) values ('NewGroupFilter'||'_'||currval(pg_get_serial_sequence('login_role', 'lro_id'))) returning lro_id;";
		else
			$sql = "update login_role set name = '".$name."' where lro_id=".$lro_id.";commit;";

		error_log ( "sql : " .$sql);
		
		$result = pg_query ( $conn, $sql );
		
		if ( $result )
		{
			if ( $lro_id == -1 )
			{
				if ( $row = pg_fetch_row($result) )
					$response = $row [0];
			}
			else
				$response = $lro_id;
		}
	}
	
	header ('Content-type: text/xml' );
	
	echo $response;
?>