Merge branch 'master' of defaria.com:/opt/git/clearscm
[clearscm.git] / songbook / web / songbook.php
deleted file mode 120000 (symlink)
index d43dedd65a681f896ce51446890810ec2a80d850..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1 +0,0 @@
-/web/php/songbook/songbook.php
\ No newline at end of file
new file mode 100644 (file)
index 0000000000000000000000000000000000000000..54d5fea92878848f4e9bd8de482809a77540c8e5
--- /dev/null
@@ -0,0 +1,97 @@
+<?php
+$baseDir = getcwd();
+$songs   = glob (dirname($baseDir) . "/Songs/*.pro");
+
+function getSongs () {
+  global $songs;
+
+  $path = "/opt/clearscm/songbook/Songs";
+
+  // Why didn't the previous one execute correctly?
+  $songs = glob("$path/*.pro");
+} // getSongs
+
+function songsDropdown () {
+  global $songs;
+
+  print "<form method=\"get\" action=\"webchord.cgi\" name=\"song\">";
+  print "Songs:&nbsp;&nbsp;";
+  print "<select name=\"chordpro\">";
+
+  sort ($songs);
+  foreach ($songs as $song) {
+    $title = basename ($song, ".pro");
+    $artist = getArtist ($song);
+
+    print "<option value=\"$title.pro\">$title</option>";
+
+    if ($artist != "") {
+      $title .= "&nbsp;($artist)";
+    } // if
+  } // foreach
+
+  print "<input type=\"submit\" value=\"Go\">";
+  print "</select>";
+  print "</form>";
+} // songsDropdown
+
+function artistsDropdown () {
+  global $songs;
+
+  $artists = getArtists ($songs);
+
+  print "<form method=\"get\" action=\"displayartist.php\" name=\"artist\">";
+  print "Artists:&nbsp;&nbsp;";
+  print "<select name=\"artist\">";
+
+  sort ($artists);
+  foreach ($artists as $artist) {
+    print "<option>$artist</option>";
+  } // foreach
+
+  print "<input type=\"submit\" value=\"Go\">";
+  print "</select>";
+  print "</form>";
+} // artistsDropdown
+
+function getArtist ($song) {
+  $lyrics = file_get_contents ($song);
+
+  if (preg_match ("/\{(st|subtitle):(.*)\}/", $lyrics, $matches)) {
+    return trim ($matches[2]);
+  } else {
+    return "";
+  } // if
+} // getArtist
+
+function getArtists ($songs) {
+  $artists = array();
+
+  foreach ($songs as $song) {
+    $artist = getArtist ($song);
+
+    if ($artist != '') {
+      $artists[$artist] = 1;
+    } // if
+  } // foreach
+
+  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 "&nbsp;($artist)";
+    } // if
+  } // foreach
+
+  echo "</ol>";
+} // formatTable