<?php

	include "library.php";

	$cxn = start_code();

	
			/* get variables */

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


		/* if the user is not logged in them direct them to the login page then back to here */

	if ($id == "")
	{
		$_SESSION['nextpage'] = url_encode( "manage_photos.php" );

		jump_to_page( "login.php" );		/* must happen before print output */

		exit();
	}

		/* start the page  */

	page_header( "Photos", $cxn );


		/* retrieve existing photos */

	$query = "SELECT * FROM photos WHERE member_id = ".$id." ORDER BY id";

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

	if (mysql_num_rows($result) == 0)
		echo black( "No photos currently stored" );

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

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

		if ($data['primary_photo'] == "yes")
			echo "<td align='center'>".black( "<b>Primary Photo</b>" )."</td>";
		else
			echo "<td align='center'></td>";
	}

	echo "</tr><tr>";

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

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

		echo "<td align='center'>";

		show_photo( $id, 120, $data['photo_number'], true, false, $cxn );

		echo "</td>";
	}

	echo "</tr><tr>";

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

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

		echo "<td align='center'>";

		show_button_h( "delete", "delete_photo.php", "photonumber", $data['photo_number'] );

		echo "</td>";
	}

	echo "</tr><tr>";

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

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

		echo "<td align='center'>";

		show_button_h( "set_as_primary", "set_as_primary.php", "photonumber", $data['photo_number'] );

		echo "</td>";
	}

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

	echo "<br>".blue( "Upload a new photo" )."<br><br><br>";

	echo "<table>";

	echo "<form enctype='multipart/form-data' action='".url_encode( "upload_photo.php" )."' method='POST'>";

	echo "<tr><td valign='center'>".black( "<b>Select File</b>" )."</td><td valign='center'><input type='file' src='buttons/".button_filename( "upload" )."' name='file' size='60'></td></tr>";

	echo "<tr>";

//	form_submit( "upload" );

	echo "<tr><td></td><td><br><br><input type='image' onclick='alert(\"The upload process can take several minutes. Please click `ok` and wait until the `photo uploaded successfully` message appears.\" ); return (true);' src='buttons/".button_filename( "upload" )."' border='0'></td></tr>";

	echo "</tr>";

	form_end();

	echo "<br><br>".blue( "Requirements for photos" )."<br><br>";
	echo "<ul>";
	echo "<li>".black( "Files must be in JPG format" )."</li><br>";
	echo "<li>".black( "Pictures must be of yourself or of subjects of interest" )."</li><br>";
	echo "<li>".black( "You cannot upload photographs of children even if they are your own" )."</li><br>";
	echo "<li>".black( "No offensive material or nudity is allowed" )."</li><br>";
	echo "<li>".black( "You may upload as many photos as you wish" )."</li><br>";
	echo "</ul>";

	echo "<br>".red( "The upload process may take several minutes. Please do not close this screen after clicking 'upload' until the 'Photo uploaded successfully' message appears" )."<br><br>";

?>

