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