<?php

	include "library.php";

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


	$pathroot = "/home/academi1/public_html/melbourneparaplanning/clients";


	$request_id = val( $_GET, "requestid" );


		/* start the page  */

	page_header( "Download area", $cxn );

    echo "<br>";

	$query = "SELECT * FROM request WHERE id = ".$request_id;
    
	$result = run_query( $query, $cxn );

	$data = get_row( $result );

    $request_id = $data['id'];


	echo "<table><tr><td>".green( "Client name(s):&nbsp;&nbsp;" )."</td><td>".green( $data['client_names'] )."</td></tr>";

//	echo "<tr><td>".black( "Practice" )."</td><td>".black( $data['practice'] )."</td></tr>";

//	echo "<tr><td>".black( "Adviser" )."</td><td>".black( $data['adviser1'] )."</td></tr>";

	echo "</table><br><br>";	

		
	$random_file_number2 = $data['random_file_number2'];


		/* retrieve existing files */

	$query = "SELECT * FROM downloads WHERE request_id = ".$request_id;

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

	$data = get_row( $result );


    
	if (query_num_rows($result) == 0)
		echo red( "No files currently stored" );

	echo "<br><table><tr>";


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

	for ($i=0;$i <  query_num_rows($result);$i++)
	{
		$data = get_row( $result );

		$file_path = "/attachments/request_".$request_id."_".$random_file_number2."/".$data['filename'];

		$modified_datetime = date( "d M Y H:i:s", filemtime( $pathroot.$file_path ) );

		echo "<tr><td align='left'><a href='https://www.melbourneparaplanning.com.au/clients".$file_path."'>".black( $data['filename'] )."</a></td><td>&nbsp;".black( $modified_datetime );

//		echo "&nbsp;&nbsp;&nbsp;".show_link( "rename", "get_new_task_filename.php", "taskid", $id, "taskfileid", $data['id'] );		
	    
	    echo "</td></tr>";
	}

	echo "</tr><tr>";

	echo "</tr></table><br><br><br>";
	
	echo "<br>";
	echo "<br>";
	echo "<br>";
	echo "<br>";
	echo "<br>";
	echo "<br>";
	echo "<br>";
	

?>