<?php
// dvdstorecommon.php3
// Functions and other definitions used by other scripts

require( 'dvdstoredbfunctions.php3' );
define( "FROM_STATUS", 0 );
define( "FROM_SEARCH", 1 );

function GenerateLoginForm( )
{
printf( "<FORM METHOD=POST ACTION=dvdstorelogin.php3>\n" );
printf("<TABLE>");
printf( "<TR><TD><B>Lastname:</B></TD><TD> <INPUT TYPE=text SIZE=30  NAME=lastName><TD></TR><BR>\n" );
printf( "<TR><TD><B>Member ID:</B> </TD><TD><INPUT TYPE=text SIZE=30  NAME=memberID></TD></TR><BR>\n" );
printf( "<TR><TD><INPUT TYPE=submit VALUE=\"Submit\"></TD></TR>\n" );
printf("</TABLE>");
printf( "</FORM>" );
}

function GenerateHTMLHeader( $message )
{
printf( "<H1>%s</H1>\n", $message );
}

function DisplayErrorMessage( $message )
{
printf( "<BLOCKQUOTE><BLOCKQUOTE><BLOCKQUOTE><H3><FONT COLOR=\"#cc0000\">%s</FONT></H3></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE>\n", $message );
}

function DisplaySearchMenu($memberID)
{

printf( "<FORM METHOD=POST ACTION=dvdstoresearch.php3?memberID=%s>\n", $memberID );
printf("<TABLE>\n");
printf( "<TR><TD><B>Movie title:</B></TD> <TD><INPUT TYPE=text SIZE=40  NAME=title></TD></TR>\n" );
printf( "<TR><TD><B>Director/ Actors:</B></TD> <TD> <INPUT TYPE=text SIZE=30  NAME=director><BR></TD></TR>\n" );
printf( "<TR><TD><INPUT TYPE=submit VALUE=\"Search\"></TD></TR>\n" );
printf("</TABLE>\n");
printf( "</FORM>" );
}

function DisplayUserMenu( $memberID )
{
printf( "<A HREF=\"dvdstorestatus.php3?memberID=%s\"><H3>Check your reservation status</H3></A>", $memberID );
printf( "<A HREF=\"dvdstoresearch.php3?memberID=%s\"><H3>Search for movies</H3></A>", $memberID );
}

function DisplayDVDDetails( $titleID, $searchORstatus )
{
global $memberID;
	
if (dvd_title_get( $titleID, $title_object) == false) {
	DisplayErrorMessage( "dvd_title_get failed" );
} else {
	if ( $searchORstatus == SEARCH ) {
		printf( "<B>Search results:</B><BR>\n" );	
	}
	if ( $searchORstatus == STATUS ) {
		printf( "<B>You have the following DVD reserved:</B><BR>\n" );	
	}	
		
	printf( "<BR><BR> <B>Title:</B> %s<BR>\n", $title_object->title_text);
	printf( "<B>Director:</B> %s<BR>\n", $title_object->director );
	printf( "<B>Genre:</B> %s<BR>\n", $title_object->genre_name );

	printf( "<B>Rated:</B> %s<BR>\n", $title_object->classification );
	printf( "<B>Cast:</B> %s", $title_object->actor1);
	if (strlen($title_object->actor2)>0) {
		printf(", %s<BR>\n", $title_object->actor2);
	} else {
		printf("\n");
	}
	printf( "<B>Year:</B> %s<BR>\n", $title_object->release_date );
	printf( "<B>Rental cost:</B> %s<BR>\n", $title_object->rental_cost );

	if ( $searchORstatus == SEARCH )
		printf( "<BR><BR>Click <A HREF=\"dvdstorereserve.php3?memberID=%s&titleID=%s&date=0\">here </A> to reserve this title<BR><BR><BR>\n", $memberID, $titleID );	

	if ( $searchORstatus == STATUS )
		printf( "<BR><BR>Click <A HREF=\"dvdstorecancel.php3?memberID=%s\">here </A> to unreserve this title<BR><BR><BR>\n", $memberID );	
}
}


function GetReserveDate( $memberID, $titleID )
{
GenerateHTMLHeader( "Reserve a DVD title" );
printf( "<FORM METHOD=POST ACTION=\"dvdstorereserve.php3?memberID=%s&title=%s\">\n", $memberID, $titleID );
printf( "<B>Enter a date to reserve this title (MM/DD/YYYY format):</B> <INPUT TYPE=text SIZE=10  NAME=dateToReserve><BR>\n" );
printf( "<INPUT TYPE=submit VALUE=\"Submit\">\n" );
printf( "</FORM>" );
}
