<?php
	$files = array();

	$reason = dir("./music");
	while( $file = $reason->read() ) {
		if(preg_match("/mp3$/", $file)) {
			$file = substr($file, 0,-4);
			$files[strtoupper($file[0])][] = $file;
		}
	}
	$reason->close();
	
	ksort($files);

#####################################################################
#####################################################################
	header("Content-type: text/xml");

	print("<?xml version=\"1.0\"?>");

?>

<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
  <help>There truely is no hope for you.</help>
  <noinput>Um, say something. <reprompt /></noinput>
  <nomatch>What? That's not an option.  Try again <reprompt /></nomatch>

  
  <menu id="main_menu" scope="document">
    <prompt>
	<say-as type="name">Adam Smith</say-as> dot A S. loop browser.
	select a starting letter of the loop name from the following <?=count(array_keys($files))?> options: <enumerate />
    </prompt>
<?php foreach( array_keys($files) as $letter ) { ?>
    <choice next="#menu<?=$letter?>"><?=$letter?></choice>
<?php } ?>
    <choice next="#main_menu">main menu</choice>
  </menu>

<?php foreach( array_keys($files) as $letter ) { ?>
  <menu id="menu<?=$letter?>" accept="approximate">
	<?=count($files[$letter])?> loops starting with <?=$letter?>: <enumerate />
<?php foreach( $files[$letter] as $key => $value ) { 
	$value = preg_replace("/\[.*\]/", "", $value);
	$value = preg_replace("/(\s*-\s*)/", " ", $value);
	$value = substr($value, 0, 25); ?>
    <choice next="#form<?=$letter.$key?>"><?=$value?></choice> 
<?php } ?>
  </menu>

<?php } ?>   

<?php foreach ( array_keys($files) as $letter ) { foreach( $files[$letter] as $key=>$value) { ?>
  <form id="form<?=$letter.$key?>">
    <block>
      <?=$value?>.
      <audio fetchhint="safe" src="http://www.adamsmith.as/music/reason/<?=$value?>.mp3" /><goto next="#main_menu" />
    </block>
  </form>
<?php } } ?>   

</vxml>

