<?php

	include "library.php";

	$cxn = start_code( true );

	$cxn_common = db_common_login();
	

//	$form_name = val( $_GET, "formname" );	

	$next = val( $_GET, "next" );
	
	$id = val( $_SESSION, "id" );
	
	
	$query = "SELECT * FROM ".common_data_database_name.".screen_definition_main WHERE form_name = 'financial_planning_practices'";
		
	$result = run_query( $query, $cxn );

	$data = get_row( $result );
	
	$table_name = $data['table_name'];

		// this function scrolls by ID which may not be the sort order
		
	if ($next == "true")
	{
		$query = "SELECT id FROM ".$table_name." WHERE id > ".$id." ORDER BY id LIMIT 1";
		
		$result = run_query( $query, $cxn );		
	}
	else
	{
		$query = "SELECT id FROM ".$table_name." WHERE id < ".$id." ORDER BY id DESC LIMIT 1";
		
		$result = run_query( $query, $cxn );		
	}
		
	if (query_num_rows( $result ) >= 1)
	{
		$data = get_row( $result );			
		
		$_SESSION['id'] = $data['id'];			
	}
		
	$nextpage = url_encode( "edit_fp_practice.php", "newrecord", "false" );
		
	header( "Location: ".$nextpage );
	

?>
