<?php

	include "small_library.php";

	$cxn = start_code( true );


		/* get parameters */

	$conversation_id = val( $_GET, 'conversationid' );

	$member_id = val( $_GET, 'memberid' );

	$text = val( $_GET, 'text' );


		/* check them */

		// don't check for faster operation
		
//	crash_if_missing( $conversation_id, "conversation_id missing in save_chat_text", $cxn );
	
//	crash_if_missing( $member_id, "member_id missing in save_chat_text", $cxn );


		/* save text typed */


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

		
		// if the user types an apostrophy this needs to be escaped in the SQL insert query
		
	$text = str_replace( "'", "\\'", $text );
	
	
	$query = "INSERT INTO chat_text (conversation_id, typed_by, text, typed) VALUES (".$conversation_id.", ".$member_id.", '".$text."', '".$typed."')";

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

	

	$query = "INSERT INTO chat_text_history (conversation_id, typed_by, text, typed) VALUES (".$conversation_id.", ".$member_id.", '".$text."', '".$typed."')";

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

	echo "ok";

?>