<?php
	require_once '../../autoload.php';
	
	$id1	 		= -1;
	$position1		= 0;
	$id2	 		= -1;
	$position2		= 0;
		
	
	if ( isset ( $_REQUEST['id1'] ) 			)	$id1		 		= $_REQUEST['id1'];
	if ( isset ( $_REQUEST['position1'] )		)	$position1 		 	= $_REQUEST['position1'];
	if ( isset ( $_REQUEST['id2'] ) 			)	$id2		 		= $_REQUEST['id2'];
	if ( isset ( $_REQUEST['position2'] )		)	$position2 		 	= $_REQUEST['position2'];
	
		
	$conn = get_dbconnection();
	
	$response = -1;
	
	if ( $conn )
	{
		$sql = '';

		$sql = 'update survey_field set position = '.$position1.' where id='.$id1.'; update survey_field set position='.$position2.' where id='.$id2.'; commit;';
		
		$result = pg_query ( $conn, $sql );
		
		if ( $result )
		{
			// if ( $row = pg_fetch_row($result) )
			{
				$response = $id1;
			}
		}
	}
	
	header ('Content-type: text/xml' );
	
	echo $response;
?>