Moved lists back to same folder as songs.
[songbook.git] / web / songbook.php
1 <?php
2 $baseDir    = getcwd();
3 $songbook   = "/opt/songbook";
4 $songFolder = "Andrew";
5 $songDir    = "/opt/songbook/$songFolder";
6
7 if (isset ($_REQUEST['debug'])) {
8   $debug = $_REQUEST['debug'];
9 } // if
10
11 // Initialize music objects
12 $songs   = getSongs($songDir);
13 $sets    = getSets($songDir);
14 $artists = getArtists($songs);
15
16 function debug ($msg) {
17   global $debug;
18
19   if (isset ($debug)) {
20     echo "<font color=red>DEBUG:</font> $msg<br>";
21   } // if
22 } // debug
23
24 function getSongs ($songDir) {
25   return glob("$songDir/*.pro");
26 } // getSongs
27
28 function getSets ($songDir) {
29   return glob("$songDir/*.lst");
30 } // getSets
31
32 function songsDropdown () {
33   global $songs;
34
35   print "<form method=\"get\" action=\"webchord.cgi\" name=\"song\">";
36   print "Songs:&nbsp;&nbsp;";
37   print "<select name=\"chordpro\">";
38
39   sort ($songs);
40   foreach ($songs as $song) {
41     $title = basename ($song, ".pro");
42     $artist = getArtist ($song);
43
44     print "<option value=\"$title.pro\">$title</option>";
45
46     if ($artist != "") {
47       $title .= "&nbsp;($artist)";
48     } // if
49   } // foreach
50
51   print "</select>";
52   print "&nbsp;<input type=\"submit\" value=\"Go\">";
53   print "</form>";
54 } // songsDropdown
55
56 function artistsDropdown () {
57   global $artists;
58
59   print "<form method=\"get\" action=\"displayartist.php\" name=\"artist\">";
60   print "Artists:&nbsp;&nbsp;";
61   print "<select name=\"artist\">";
62
63   sort ($artists);
64   foreach ($artists as $artist) {
65     print "<option>$artist</option>";
66   } // foreach
67
68   print "</select>";
69   print "&nbsp;<input type=\"submit\" value=\"Go\">";
70   print "</form>";
71 } // artistsDropdown
72
73 function setsDropdown () {
74   global $sets;
75
76   print "<form method=\"get\" action=\"displayset.php\" name=\"set\">";
77   print "Sets:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
78   print "<select name=\"set\">";
79
80   sort ($sets);
81   foreach ($sets as $set) {
82     print "Processing set<br>";
83     $title = basename ($set, ".lst");
84
85     print "<option value=\"$title.lst\">$title</option>";
86   } // foreach
87
88   print "</select>";
89   print "&nbsp;<input type=\"submit\" value=\"Go\">";
90   print "</form>";
91 } // setsDropdown
92
93 function getArtist ($song) {
94   $lyrics = @file_get_contents ($song);
95
96   if (preg_match ("/\{(st|subtitle):(.*)\}/", $lyrics, $matches)) {
97     return trim ($matches[2]);
98   } else {
99     return "";
100   } // if
101 } // getArtist
102
103 function getArtists ($songs) {
104   foreach ($songs as $song) {
105     $artist = getArtist ($song);
106
107     if ($artist != '') {
108       $artists[$artist] = 1;
109     } // if
110   } // foreach
111
112   return array_keys ($artists);
113 } // getArtists
114