<?php
/*
 * testdisplay.php
 * 
 * Copyright 2013 William <william@william-gaming>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 * 
 */

?>
<!DOCTYPE html>
<html>

<head>
	<title>St. Fred's Automatic Hymn Display</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta name="generator" content="Geany 0.21" />
	<style type="text/css">
	#displaybox:first-line
	{ 
		font-weight:bold;
		font-size: large;
	}
	body {
		background-image: url("images/Texture0218.jpg");
		text-align: center;
	}
	</style>
</head>

<body>
		<?php
		if(isset($_GET["hymn"])){
			//Setup the path to the files (if all in same folder)
			$hymnpath = "z_/" . $_GET["hymn"];
		
			if ( is_file($hymnpath . ".ogg") || is_file($hymnpath . ".mp3") )
			{			
				//Insert audio player
				echo "<audio controls>";
					//Audio sources
				if (is_file( $hymnpath . ".ogg" ))
				{
					echo "<source src=\"";
					echo $hymnpath;
					echo ".ogg\" type=\"audio/ogg\">";
				}
				if (is_file( $hymnpath . ".mp3" ))
				{
					echo "<source src=\"";
					echo $hymnpath;
					echo ".mp3\" type=\"audio/mpeg\">";
				}
						
				//	<!-- One of these may work, need to test with real file. -->
				//	<track  src=\"001_en.vtt\" kind=\"subtitles\" srclang=\"en\" label=\"English\">
				//	<track  src=\"001_en.vtt\" kind=\"captions\" srclang=\"en\" label=\"English\">
				
				//Backup if audio tag not supported
				echo "Your browser does not support the audio tag.
					Audio links:";
					
				if (is_file($hymnpath . ".mp3"))
				{
					echo " <a href=\"001.mp3\">MP3</a>";
				}
				
				if (is_file($hymnpath . ".midi"))
				{
					echo " <a href=\"001.midi\">MIDI</a>";
				}
				
				if (is_file($hymnpath . ".nwc"))
				{
					echo " <a href=\"001.nwc\">NWC</a>";
				}
				echo ".";
				//Alternative link
				if (is_file($hymnpath . "z.mp3"))
				{
					echo "There is also an <a href=\"001z.mp3\">alternative MP3</a>.";
				}
				//End Backup if audio tag not supported
				echo "</audio>";
				
				
				if (is_file($hymnpath . "z.mp3") || is_file($hymnpath . "z.ogg"))
				{
					echo " Alternate: ";
					echo "<audio controls>";
						//Audio sources
						if (is_file( $hymnpath . "z.ogg" ))
						{
							echo "<source src=\"";
							echo $hymnpath;
							echo "z.ogg\" type=\"audio/ogg\">";
						}
						if (is_file( $hymnpath . "z.mp3" ))
						{
							echo "<source src=\"";
							echo $hymnpath;
							echo "z.mp3\" type=\"audio/mpeg\">";
						}
					//	<!-- One of these may work, need to test with real file. -->
					//	<track  src=\"001_en.vtt\" kind=\"subtitles\" srclang=\"en\" label=\"English\">
					//	<track  src=\"001_en.vtt\" kind=\"captions\" srclang=\"en\" label=\"English\">
					echo "</audio>";
				}
				/*
				echo " | Other: ";
				if (is_file($hymnpath . ".mid"))
				{
					echo " <a href=\"001.mid\">MIDI</a>";
				}
				if (is_file($hymnpath . ".nwc"))
				{
					echo " <a href=\"001.nwc\">NWC</a>";
				}
				*/
			}
			else
			{
				echo "No playable audio files found! <br/>";
				echo "Trying to find other files: ";
				if (is_file($hymnpath . ".midi"))
				{
					echo " <a href=\"001.midi\">MIDI</a>";
				}
				if (is_file($hymnpath . ".nwc"))
				{
					echo " <a href=\"001.nwc\">NWC</a>";
				}
				echo "<br/>";
			}
			
			//Insert Lyrics
			echo "<div id=\"displaybox\">";
			if (!is_file($hymnpath . ".txt"))
			{
				echo "Lyrics missing: Text file not found.";
			}
			else
			{
				$text = file_get_contents($hymnpath . ".txt");
				$text = nl2br($text);
				// $text1 = htmlspecialchars($text, ENT_QUOTES);
				echo $text;
			}
			echo "</div>";
		}
		//Test content for when attribute not set so page isn't blank.
		else
		{
			echo "\"hymn\" attribute not set. Please add \"?hymn=XXX\" to the url end where XXX is a number of at least 3 digits (leading zero inclusive for smaller than 100.)";
		}
		
		?>	
	
	
</body>

</html>
