<?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;
} // 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;
} // if
} // foreach
- print "<input type=\"submit\" value=\"Go\">";
print "</select>";
+ print " <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: ";
print "<option>$artist</option>";
} // foreach
- print "<input type=\"submit\" value=\"Go\">";
print "</select>";
+ print " <input type=\"submit\" value=\"Go\">";
print "</form>";
} // artistsDropdown
+function setsDropdown () {
+ global $sets;
+
+ print "<form method=\"get\" action=\"displayset.php\" name=\"set\">";
+ print "Sets: ";
+ 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 " <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]);
} // getArtist
function getArtists ($songs) {
- $artists = array();
-
foreach ($songs as $song) {
$artist = getArtist ($song);
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 " ($artist)";
- } // if
- } // foreach
-
- echo "</ol>";
-} // formatTable