<?php

	include "library.php";

	$cxn = start_code();
	
	$cxn_common = db_common_login();
	

	
			/* get variables */

	$account_id = val( $_SESSION, "account_id" );

	$add = val( $_GET, "add" );
	
	$remembered_id = val( $_GET, "rememberedid" );

	$returnpoint = val( $_GET, "returnpoint" );

	$startpos = val( $_GET, "startpos" );


			/* start page */

	page_header( "", $cxn, $cxn_common );


		/* check parameters */

	crash_if_missing( $account_id, "account_id missing in add_to_remembered", $cxn );

	crash_if_missing( $add, "add missing in add_to_remembereds", $cxn );

	crash_if_missing( $remembered_id, "remembered_id missing in add_to_remembered", $cxn );

	crash_if_missing( $returnpoint, "return point missing in add_to_remembered", $cxn );

//	crash_if_missing( $startpos, "start pos missing in add_to_remembered", $cxn );


	if ($add == "no")
		echo black( "Add to remembered list cancelled<br><br>" );
	else
	{
			/* record the addition to the remembered list */

		$date_added = date('Y-m-d');


			/* don't create another record if already in the remembered list */

		if (! query_has_rows( "SELECT id FROM remembered WHERE account_id = ".$account_id." AND remembered_id = ".$remembered_id, $cxn ) )
		{
			$query = "INSERT INTO remembered (account_id, remembered_id, date_added) VALUES ( ".$account_id.", ".$remembered_id.", '".$date_added."' )";

			$result = run_query( $query, $cxn );
		}

		echo black( "Listing added successfully<br><br>" );
	}
	
	show_return_point( $returnpoint, $startpos, $remembered_id );
?>

