<?php

	include "library.php";

	$cxn = start_code();

	$cxn_common = db_common_login();


	
			/* get variables */

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

	$noted_member_id = val( $_GET, "notedid" );

	$notes = val( $_POST, "notes" );

	$notes = prep_for_sql( $notes );

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

	$sent = date("Y-m-d H:i:s");

	crash_if_missing( $id, "id missing in notes go", $cxn );

	crash_if_missing( $noted_member_id, "noted_member_id missing in notes go", $cxn );

	alert( "Notes added" );

	if (query_has_rows( "SELECT id FROM notes WHERE member_id = ".$id." AND noted_member_id = ".$noted_member_id, $cxn ))
	{
		run_query( "UPDATE notes SET text = '".$notes."' WHERE member_id = ".$id." AND noted_member_id = ".$noted_member_id, $cxn );
	}
	else
	{
		run_query( "INSERT INTO notes (member_id, noted_member_id, text) VALUES (".$id.", ".$noted_member_id.", '".$notes."')", $cxn );
	}

	echo black( "Notes saved<br><br>" );

	echo show_link( "Return", "mailboxes.php", "box", "contacts" );
	
?>