Moved lists back to same folder as songs.
[songbook.git] / web / songbook.php
index a231add..ae50faa 100644 (file)
@@ -1,7 +1,17 @@
 <?php
-$baseDir = getcwd();
-$songs   = glob (dirname($baseDir) . "/Songs/*.pro");
-$debug   = $_REQUEST["debug"];
+$baseDir    = getcwd();
+$songbook   = "/opt/songbook";
+$songFolder = "Andrew";
+$songDir    = "/opt/songbook/$songFolder";
+
+if (isset ($_REQUEST['debug'])) {
+  $debug = $_REQUEST['debug'];
+} // if
+
+// Initialize music objects
+$songs   = getSongs($songDir);
+$sets    = getSets($songDir);
+$artists = getArtists($songs);
 
 function debug ($msg) {
   global $debug;
@@ -11,15 +21,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 +48,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,13 +65,33 @@ 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);
+  $lyrics = @file_get_contents ($song);
 
   if (preg_match ("/\{(st|subtitle):(.*)\}/", $lyrics, $matches)) {
     return trim ($matches[2]);
@@ -74,8 +101,6 @@ function getArtist ($song) {
 } // getArtist
 
 function getArtists ($songs) {
-  $artists = array();
-
   foreach ($songs as $song) {
     $artist = getArtist ($song);
 
@@ -87,20 +112,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