3 $songDir = "/opt/songbook/Songs";
4 $debug = $_REQUEST["debug"];
6 function debug ($msg) {
10 echo "<font color=red>DEBUG:</font> $msg<br>";
14 function getSongs () {
17 return glob("$songDir/*.pro");
23 return glob("$songDir/*.lst");
26 function songsDropdown () {
29 print "<form method=\"get\" action=\"webchord.cgi\" name=\"song\">";
30 print "Songs: ";
31 print "<select name=\"chordpro\">";
34 foreach ($songs as $song) {
35 $title = basename ($song, ".pro");
36 $artist = getArtist ($song);
38 print "<option value=\"$title.pro\">$title</option>";
41 $title .= " ($artist)";
46 print " <input type=\"submit\" value=\"Go\">";
50 function artistsDropdown () {
52 $artists = getArtists ($songs);
54 print "<form method=\"get\" action=\"displayartist.php\" name=\"artist\">";
55 print "Artists: ";
56 print "<select name=\"artist\">";
59 foreach ($artists as $artist) {
60 print "<option>$artist</option>";
64 print " <input type=\"submit\" value=\"Go\">";
68 function setsDropdown () {
71 print "<form method=\"get\" action=\"displayset.php\" name=\"set\">";
72 print "Sets: ";
73 print "<select name=\"set\">";
76 foreach ($sets as $set) {
77 print "Processing set<br>";
78 $title = basename ($set, ".lst");
80 print "<option value=\"$title.lst\">$title</option>";
84 print " <input type=\"submit\" value=\"Go\">";
88 function getArtist ($song) {
89 $lyrics = file_get_contents ($song);
91 if (preg_match ("/\{(st|subtitle):(.*)\}/", $lyrics, $matches)) {
92 return trim ($matches[2]);
98 function getArtists ($songs) {
101 foreach ($songs as $song) {
102 $artist = getArtist ($song);
105 $artists[$artist] = 1;
109 return array_keys ($artists);
112 function formatTable ($songs) {
115 foreach ($songs as $song) {
116 $artist = getArtist ($song);
118 $title = basename ($song, ".pro");
120 echo "<li><a href=\"webchord.cgi?chordpro=$song\">$title</a>";
123 echo " ($artist)";