<?php
	require_once '../../autoload.php';
	
	RightsCheck ("VIEW_LOGINROLE");
	
	$id		 		= -1;
	$admin			= -1;
	$working_view	= -1;
		
	
	if ( isset ( $_REQUEST['id'] ) 				)	$id		 		= $_REQUEST['id'];
	if ( isset ( $_REQUEST['admin'] )			)	$admin 			= $_REQUEST['admin'];
	if ( isset ( $_REQUEST['working_view'] )	)	$working_view	= $_REQUEST['working_view'];

		
	$conn = get_dbconnection();
	
	$response = -1;
	
	if ( $conn )
	{
		$sql = '';

		if ( $id != -1 )
		{
			if ( $admin != -1 )
			{
				$adm = ( $admin==1 )? 'true' : 'false';
				$sql = 'update login_role_permission set value='.$adm.' where id='.$id.'; commit;';
			}
			else
			{
				if ( $working_view != -1 )
				{
					$wv = ($working_view == 1)? 'true' : 'false';
					$sql = 'update login_role_permission set working_view='.$wv.' where id='.$id.'; commit;';
				}
			}
		}
		
		$result = false;
		if ( empty($sql) == false )
			$result = pg_query ( $conn, $sql );
		
		if ( $result )
		{
			$response = $id;
		}
	}
	
	header ('Content-type: text/xml' );
	
	echo $response;
?>