Moved lists back to same folder as songs.
[songbook.git] / web / songbook.php
index cbfe933..ae50faa 100644 (file)
@@ -1,7 +1,17 @@
 <?php
-$baseDir = getcwd();
-$songDir = "/opt/songbook/Songs";
-$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,20 +21,16 @@ function debug ($msg) {
   } // if
 } // debug
 
-function getSongs () {
-  global $songDir;
-
+function getSongs ($songDir) {
   return glob("$songDir/*.pro");
 } // getSongs
 
-function getSets () {
-  global $songDir;
-
+function getSets ($songDir) {
   return glob("$songDir/*.lst");
 } // getSets
 
 function songsDropdown () {
-  $songs = getSongs();
+  global $songs;
 
   print "<form method=\"get\" action=\"webchord.cgi\" name=\"song\">";
   print "Songs:&nbsp;&nbsp;";
@@ -48,8 +54,7 @@ function songsDropdown () {
 } // songsDropdown
 
 function artistsDropdown () {
-  $songs = getSongs();
-  $artists = getArtists ($songs);
+  global $artists;
 
   print "<form method=\"get\" action=\"displayartist.php\" name=\"artist\">";
   print "Artists:&nbsp;&nbsp;";
@@ -66,7 +71,7 @@ function artistsDropdown () {
 } // artistsDropdown
 
 function setsDropdown () {
-  $sets = getSets();
+  global $sets;
 
   print "<form method=\"get\" action=\"displayset.php\" name=\"set\">";
   print "Sets:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
@@ -86,7 +91,7 @@ function setsDropdown () {
 } // 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]);
@@ -96,8 +101,6 @@ function getArtist ($song) {
 } // getArtist
 
 function getArtists ($songs) {
-  $artists = array();
-
   foreach ($songs as $song) {
     $artist = getArtist ($song);
 
@@ -109,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