<?php

	include "small_library.php";

	$cxn = start_code( true );


	
		/* get parameters */

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

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


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


		/* get line(s) of text typed */

	$query = "SELECT chat_text.id as chat_text_id, profile.handle, text FROM chat_text LEFT JOIN profile ON profile.id = chat_text.typed_by WHERE conversation_id = ".$conversation_id." AND typed_by = ".$member_id." ORDER BY chat_text.id";

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

	$text = "";


		// loop as there may be multiple lines of text typed and saved since the last call to this function
		
	for ($i=0; $i < query_num_rows($result); $i++)
	{
		$data = get_row( $result );

		$text .= $data['handle'].": ".$data['text']."<br><br>";
		
	    $query2 = "DELETE FROM chat_text WHERE id = ".$data['chat_text_id'];
	    
    	$result2 = run_query( $query2, $cxn );	    
	}

		/* send of the new lines of text */
	echo $text;

?>