Merge branch 'master' of defaria.com:/opt/git/clearscm
[clearscm.git] / songbook / web / songbook.php
1 <?php
2 $baseDir = getcwd();
3 $songs   = glob (dirname($baseDir) . "/Songs/*.pro");
4
5 function getSongs () {
6   global $songs;
7
8   $path = "/opt/clearscm/songbook/Songs";
9
10   // Why didn't the previous one execute correctly?
11   $songs = glob("$path/*.pro");
12 } // getSongs
13
14 function songsDropdown () {
15   global $songs;
16
17   print "<form method=\"get\" action=\"webchord.cgi\" name=\"song\">";
18   print "Songs:&nbsp;&nbsp;";
19   print "<select name=\"chordpro\">";
20
21   sort ($songs);
22   foreach ($songs as $song) {
23     $title = basename ($song, ".pro");
24     $artist = getArtist ($song);
25
26     print "<option value=\"$title.pro\">$title</option>";
27
28     if ($artist != "") {
29       $title .= "&nbsp;($artist)";
30     } // if
31   } // foreach
32
33   print "<input type=\"submit\" value=\"Go\">";
34   print "</select>";
35   print "</form>";
36 } // songsDropdown
37
38 function artistsDropdown () {
39   global $songs;
40
41   $artists = getArtists ($songs);
42
43   print "<form method=\"get\" action=\"displayartist.php\" name=\"artist\">";
44   print "Artists:&nbsp;&nbsp;";
45   print "<select name=\"artist\">";
46
47   sort ($artists);
48   foreach ($artists as $artist) {
49     print "<option>$artist</option>";
50   } // foreach
51
52   print "<input type=\"submit\" value=\"Go\">";
53   print "</select>";
54   print "</form>";
55 } // artistsDropdown
56
57 function getArtist ($song) {
58   $lyrics = file_get_contents ($song);
59
60   if (preg_match ("/\{(st|subtitle):(.*)\}/", $lyrics, $matches)) {
61     return trim ($matches[2]);
62   } else {
63     return "";
64   } // if
65 } // getArtist
66
67 function getArtists ($songs) {
68   $artists = array();
69
70   foreach ($songs as $song) {
71     $artist = getArtist ($song);
72
73     if ($artist != '') {
74       $artists[$artist] = 1;
75     } // if
76   } // foreach
77
78   return array_keys ($artists);
79 } // getArtists
80
81 function formatTable ($songs) {
82   echo "<ol>";
83
84   foreach ($songs as $song) {
85     $artist = getArtist ($song);
86
87     $title = basename ($song, ".pro");
88
89     echo "<li><a href=\"webchord.cgi?chordpro=$song\">$title</a>";
90
91     if ($artist != "") {
92     echo "&nbsp;($artist)";
93     } // if
94   } // foreach
95
96   echo "</ol>";
97 } // formatTable