<?php

	include "library.php";

	$cxn = start_code();

	
			/* get variables */

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

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

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

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


			/* start page */

	page_header( "", $cxn );


		/* check parameters */

	crash_if_missing( $id, "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 member_id = ".$id." AND remembered_id = ".$remembered_id, $cxn ) )
		{
			$query = "INSERT INTO remembered (member_id, remembered_id, date_added) VALUES ( ".$id.", ".$remembered_id.", '".$date_added."' )";

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

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

