New version
[songbook.git] / web / songbook.php
index a231add..113af43 100644 (file)
@@ -1,8 +1,13 @@
 <?php
 $baseDir = getcwd();
-$songs   = glob (dirname($baseDir) . "/Songs/*.pro");
+$songDir = "/opt/songbook/Songs";
 $debug   = $_REQUEST["debug"];
 
+// Initialize music objects
+$songs   = getSongs($songDir);
+$sets    = getSets($songDir);
+$artists = getArtists($songs);
+
 function debug ($msg) {
   global $debug;
 
@@ -11,15 +16,14 @@ function debug ($msg) {
   } // if
 } // debug
 
-function getSongs () {
-  global $songs;
-
-  $path = "/opt/songbook/Songs";
-
-  // Why didn't the previous one execute correctly?
-  $songs = glob("$path/*.pro");
+function getSongs ($songDir) {
+  return glob("$songDir/*.pro");
 } // getSongs
 
+function getSets ($songDir) {
+  return glob("$songDir/*.lst");
+} // getSets
+
 function songsDropdown () {
   global $songs;
 
@@ -39,15 +43,13 @@ function songsDropdown () {
     } // if
   } // foreach
 
-  print "<input type=\"submit\" value=\"Go\">";
   print "</select>";
+  print "&nbsp;<input type=\"submit\" value=\"Go\">";
   print "</form>";
 } // songsDropdown
 
 function artistsDropdown () {
-  global $songs;
-
-  $artists = getArtists ($songs);
+  global $artists;
 
   print "<form method=\"get\" action=\"displayartist.php\" name=\"artist\">";
   print "Artists:&nbsp;&nbsp;";
@@ -58,11 +60,31 @@ function artistsDropdown () {
     print "<option>$artist</option>";
   } // foreach
 
-  print "<input type=\"submit\" value=\"Go\">";
   print "</select>";
+  print "&nbsp;<input type=\"submit\" value=\"Go\">";
   print "</form>";
 } // artistsDropdown
 
+function setsDropdown () {
+  global $sets;
+
+  print "<form method=\"get\" action=\"displayset.php\" name=\"set\">";
+  print "Sets:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
+  print "<select name=\"set\">";
+
+  sort ($sets);
+  foreach ($sets as $set) {
+    print "Processing set<br>";
+    $title = basename ($set, ".lst");
+
+    print "<option value=\"$title.lst\">$title</option>";
+  } // foreach
+
+  print "</select>";
+  print "&nbsp;<input type=\"submit\" value=\"Go\">";
+  print "</form>";
+} // setsDropdown
+
 function getArtist ($song) {
   $lyrics = file_get_contents ($song);
 
@@ -74,8 +96,6 @@ function getArtist ($song) {
 } // getArtist
 
 function getArtists ($songs) {
-  $artists = array();
-
   foreach ($songs as $song) {
     $artist = getArtist ($song);
 
@@ -87,20 +107,3 @@ function getArtists ($songs) {
   return array_keys ($artists);
 } // getArtists
 
-function formatTable ($songs) {
-  echo "<ol>";
-
-  foreach ($songs as $song) {
-    $artist = getArtist ($song);
-
-    $title = basename ($song, ".pro");
-
-    echo "<li><a href=\"webchord.cgi?chordpro=$song\">$title</a>";
-
-    if ($artist != "") {
-    echo "&nbsp;($artist)";
-    } // if
-  } // foreach
-
-  echo "</ol>";
-} // formatTable