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

		if ( $id == -1 )
			$sql = 'insert into login_role(name) values (\''.pg_escape_string ($conn,$name).'\') returning id;';
		else
			$sql = 'update login_role set name=\''.pg_escape_string ($conn,$name).'\' 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;
?>