diff --git a/api.php b/api.php
new file mode 100644
index 0000000..6c69dc6
--- /dev/null
+++ b/api.php
@@ -0,0 +1,223 @@
+$command,'error'=>'false', 'exists'=>$exists);
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+
+}
+
+if ($command == "venueAccepting")
+{
+ if (getAccepting())
+ $output = array('command'=>$command,'accepting'=>true);
+ else
+ $output = array('command'=>$command,'accepting'=>false);
+ header('Content-type: application/json');
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+
+if ($command == "submitRequest")
+{
+ $songId = $data['songId'];
+ $singerName = $data['singerName'];
+ $sql = "SELECT artist,title FROM songdb WHERE song_id = $songId";
+ foreach ($db->query($sql) as $row) {
+ $artist = $row['artist'];
+ $title = $row['title'];
+ }
+ $stmt = $db->prepare("INSERT INTO requests (singer,artist,title) VALUES(:singerName, :artist, :title)");
+ $stmt->execute(array(":singerName" => $singerName, ":artist" => $artist, ":title" => $title));
+ newSerial();
+ $output = array('command'=>$command,'error'=>'false', 'success'=>true);
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+
+if ($command == "search")
+{
+ $terms = explode(' ',$data['searchString']);
+ $no = count($terms);
+ $wherestring = '';
+ if ($no == 1) {
+ $wherestring = "WHERE (combined LIKE \"%" . $terms[0] . "%\")";
+ } elseif ($no >= 2) {
+ foreach ($terms as $i => $term) {
+ if ($i == 0) {
+ $wherestring .= "WHERE ((combined LIKE \"%" . $term . "%\")";
+ }
+ if (($i > 0) && ($i < $no - 1)) {
+ $wherestring .= " AND (combined LIKE \"%" . $term . "%\")";
+ }
+ if ($i == $no - 1) {
+ $wherestring .= " AND (combined LIKE \"%" . $term . "%\") AND(artist<>'DELETED'))";
+ }
+ }
+ } else {
+ $wherestring = "";
+ }
+ $entries = null;
+ $res = array();
+ $sql = "SELECT song_id,artist,title,combined FROM songdb $wherestring ORDER BY UPPER(artist), UPPER(title)";
+ foreach ($db->query($sql) as $row)
+ {
+ if ((stripos($row['combined'],'wvocal') === false) && (stripos($row['combined'],'w-vocal') === false) && (stripos($row['combined'],'vocals') === false)) {
+ $res[] = array('song_id'=>$row['song_id'],'artist'=>$row['artist'],'title'=>$row['title']);
+ }
+ }
+ $output = array("command" => "search", "songs" => $res);
+ header('Content-type: application/json');
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+
+
+
+
+
+// API stuff for OpenKJ application
+
+if ($command == "clearDatabase")
+{
+ $db->exec("DELETE FROM songdb");
+ $db->exec("DELETE FROM requests");
+ $newSerial = newSerial();
+ $output = array('command'=>$command,'error'=>'false', 'serial'=>newSerial());
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+
+function error($error_string) {
+ header('Content-type: application/json');
+ print(json_encode(array('command'=>$command,'error'=>'true','errorString'=>$error_string),JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+
+if ($command == "clearRequests")
+{
+ $db->exec("DELETE FROM requests");
+ $output = array('command'=>$command,'error'=>'false', 'serial'=>newSerial());
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+
+if ($command == "deleteRequest")
+{
+ $request_id = $data['request_id'];
+ $stmt = $db->prepare("DELETE FROM requests WHERE request_id = :requestId");
+ $stmt->execute(array(":requestId" => $request_id));
+ $output = array('command'=>$command,'error'=>'false', 'serial'=>newSerial());
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+
+if ($command == "connectionTest")
+{
+ header('Content-type: application/json');
+ $output = array('command'=>$command,'connection'=>'ok');
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+if ($command == "addSongs")
+{
+ $stmt = $db->prepare("INSERT OR IGNORE INTO songdb (artist, title, combined) VALUES (:artist, :title, :combined)");
+ $db->beginTransaction();
+ $errors = array();
+ $count = 0;
+ $artist = "";
+ $title = "";
+ $combined = "";
+ $error = "false";
+ foreach ($data['songs'] as $song)
+ {
+ $artist = $song['artist'];
+ $title = $song['title'];
+ $combined = $artist . " " . $title;
+ $inarray = array(":artist" => $artist, ":title" => $title, ":combined" => $combined);
+ $result = $stmt->execute($inarray);
+ if ($result === false)
+ {
+ $errors[] = $db->errorInfo();
+ $error = "true";
+ }
+ $count++;
+ }
+ $result = $db->commit();
+ if ($result == false)
+ $errors[] = $db->errorInfo();
+ $output['command'] = $command;
+ $output['error'] = $error;
+ $output['errors'] = $errors;
+ $output['entries processed'] = $count;
+ $output['last_artist'] = $artist;
+ $output['last_title'] = $title;
+ header('Content-type: application/json');
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+
+if ($command == "getSerial")
+{
+ $output = array('command'=>$command,'serial'=>getSerial(),'error'=>'false');
+ header('Content-type: application/json');
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+
+if ($command == "getAccepting")
+{
+ $accepting = getAccepting();
+ $output = array('command'=>$command,'accepting'=>$venue['accepting'],'venue_id'=>0);
+ header('Content-type: application/json');
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+
+if ($command == "setAccepting")
+{
+ $accepting = (bool)$data['accepting'];
+ setAccepting($accepting);
+ $newSerial = newSerial();
+ $output = array('command'=>$command,'error'=>'false','venue_id'=>0,'accepting'=>$accepting,'serial'=>$newSerial);
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+
+if ($command == "getVenues")
+{
+ $output = getVenues();
+ $output['command'] = $command;
+ $output['error'] = 'false';
+ header('Content-type: application/json');
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+
+if ($command == "getRequests")
+{
+ $serial = getSerial();
+ $output = getRequests();
+ $output['command'] = $command;
+ $output['error'] = 'false';
+ $output['serial'] = $serial;
+ header('Content-type: application/json');
+ print(json_encode($output,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ exit();
+}
+
+?>
diff --git a/global.inc b/global.inc
new file mode 100644
index 0000000..e79961d
--- /dev/null
+++ b/global.inc
@@ -0,0 +1,161 @@
+exec("CREATE TABLE IF NOT EXISTS songdb (song_id integer PRIMARY KEY AUTOINCREMENT, artist text, title TEXT, combined TEXT UNIQUE)");
+$db->exec("CREATE TABLE IF NOT EXISTS state (accepting bool, serial integer NOT NULL)");
+$db->exec("INSERT OR IGNORE INTO state (rowid,accepting,serial) VALUES(0,0,1)");
+$db->exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_songstrings ON songdb(combined)");
+$db->exec("CREATE TABLE IF NOT EXISTS requests (request_id integer PRIMARY KEY AUTOINCREMENT, artist TEXT, title TEXT, singer TEXT, request_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
+
+$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
+$accepting = true;
+$songdbtable = "songdb";
+$requeststable = "requests";
+
+if (isset($_SERVER['REFERER'])) $referer = $_SERVER['REFERER'];
+function siteheader($title)
+{
+ global $venueName;
+ global $screensize;
+ echo "
+
+
+ $venueName Karaoke Songbook
+
+
+ ";
+
+
+
+}
+
+function sitefooter() {
+ echo "";
+}
+
+function navbar($backurl)
+{
+ if ($backurl == "")
+ $backurl = index.php;
+ global $screensize;
+ echo "
+ OpenKJ Songbook
+
Back ";
+}
+
+function setAccepting($accepting)
+{
+ global $db;
+ $db->exec("UPDATE state SET accepting=$accepting");
+}
+
+function getAccepting()
+{
+ global $db;
+ $accepting = false;
+ foreach ($db->query("SELECT accepting FROM state LIMIT 1") as $row)
+ {
+ $accepting = (bool)$row['accepting'];
+ }
+ return $accepting;
+}
+
+function searchform()
+{
+ global $db;
+ global $venue_id;
+ if (!getAccepting())
+ {
+ echo "
Sorry, requests are not being accepted at this time ";
+ }
+ else
+ {
+ global $url_name;
+ global $screensize;
+ echo "
";
+ echo '
You may enter any part of the artist and/or title of the song. Partial words are allowed.
+
For example "pai bla stone" would match "Rolling Stones, The - Paint it black".
';
+ }
+}
+
+
+
+function getSerial()
+{
+ global $db;
+ $serial = -1;
+ foreach ($db->query("SELECT serial FROM state LIMIT 1") as $row)
+ {
+ $serial = (int)$row['serial'];
+ }
+ return $serial;
+}
+
+function newSerial()
+{
+ global $db;
+ $serial = getSerial();
+ $newSerial = mt_rand(0,99999);
+ while ($newSerial == $serial)
+ {
+ $newSerial = mt_rand(0,99999);
+ }
+ $db->exec("UPDATE state SET serial=$newSerial");
+ return $newSerial;
+}
+
+function getVenue()
+{
+ // We don't really do multiple venues in standalone, just fake it
+ global $db;
+ global $venueName;
+ $serial = -1;
+ $venue = array();
+ $venue['venue_id'] = $venue_id;
+ $venue['accepting'] = getAccepting();
+ $venue['name'] = $venueName;
+ $venue['url_name'] = "none";
+ return $venue;
+}
+
+function getVenues()
+{
+ // We don't really do multiple venues in standalone, just fake it
+ global $db;
+ global $venueName;
+ $venues = array();
+ $venue['venue_id'] = 0;
+ $venue['accepting'] = getAccepting();
+ $venue['name'] = $venueName;
+ $venue['url_name'] = "none";
+ $venues['venues'][] = $venue;
+ return $venues;
+}
+
+function getRequests()
+{
+ global $db;
+ $requests = array();
+ $result = $db->query("SELECT request_id,artist,title,singer,strftime('%s', request_time) AS unixtime FROM requests");
+ if ($result)
+ {
+ foreach ($result as $row)
+ {
+ $request['request_id'] = (int)$row['request_id'];
+ $request['artist'] = $row['artist'];
+ $request['title'] = $row['title'];
+ $request['singer'] = $row['singer'];
+ $request['request_time'] = (int)$row['unixtime'];
+ $requests['requests'][] = $request;
+ }
+ }
+ return $requests;
+}
+
+
+?>
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..c9b8ccf
--- /dev/null
+++ b/index.php
@@ -0,0 +1,16 @@
+
Want to search using your smartphone, tablet, or laptop? Browse to songbook.openkj.org/venue/$url_name in the web browser on your device.
+";
+}
+*/
+sitefooter();
+
+?>
diff --git a/okjweb.db b/okjweb.db
new file mode 100644
index 0000000..b29a1c8
Binary files /dev/null and b/okjweb.db differ
diff --git a/search.php b/search.php
new file mode 100644
index 0000000..514d180
--- /dev/null
+++ b/search.php
@@ -0,0 +1,69 @@
+You must enter at least one search term
";
+ die();
+}
+
+if (strlen($_GET['q']) < 3)
+{
+ echo '
Your search string was too short, please try again
';
+ die();
+}
+
+echo '
Search Results Tap a song to submit it
';
+
+$terms = explode(' ',$_GET['q']);
+$no = count($terms);
+$wherestring = '';
+if ($no == 1) {
+ $wherestring = "WHERE (combined LIKE \"%" . $terms[0] . "%\")";
+} elseif ($no >= 2) {
+ foreach ($terms as $i => $term) {
+ if ($i == 0) {
+ $wherestring .= "WHERE ((combined LIKE \"%" . $term . "%\")";
+ }
+ if (($i > 0) && ($i < $no - 1)) {
+ $wherestring .= " AND (combined LIKE \"%" . $term . "%\")";
+ }
+ if ($i == $no - 1) {
+ $wherestring .= " AND (combined LIKE \"%" . $term . "%\") AND(artist != 'DELETED'))";
+ }
+ }
+
+} else {
+ echo "
You must enter at least one search term ";
+ die();
+}
+
+$entries = null;
+$res = array();
+ $sql = "SELECT song_id,artist,title,combined FROM songdb $wherestring ORDER BY UPPER(artist), UPPER(title)";
+ foreach ($db->query($sql) as $row)
+ {
+ if ((stripos($row['combined'],'wvocal') === false) && (stripos($row['combined'],'w-vocal') === false) && (stripos($row['combined'],'vocals') === false)) {
+ $res[$row['song_id']] = $row['artist'] . " - " . $row['title'];
+ }
+ }
+ $db = null;
+
+$unique = array_unique($res);
+
+foreach ($unique as $key => $val) {
+ $entries[] = "
" . $val . " ";
+}
+if (count($unique) > 0) {
+ echo '
';
+ foreach ($entries as $song) {
+ echo $song;
+ }
+ echo '
';
+} else {
+ echo "
Sorry, no match found.
";
+}
+
+sitefooter();
+?>
diff --git a/settings.inc b/settings.inc
new file mode 100644
index 0000000..250851c
--- /dev/null
+++ b/settings.inc
@@ -0,0 +1,5 @@
+
diff --git a/submitreq-run.php b/submitreq-run.php
new file mode 100644
index 0000000..4e1f593
--- /dev/null
+++ b/submitreq-run.php
@@ -0,0 +1,35 @@
+Sorry, you must input a singer name. Please go back and try again.";
+ die();
+
+}
+navbar("index.php");
+$entries = null;
+$wherestring = null;
+$artist = '';
+$title = '';
+$sql = "SELECT artist,title FROM songdb WHERE song_id = $songid";
+foreach ($db->query($sql) as $row) {
+ $artist = $row['artist'];
+ $title = $row['title'];
+}
+$stmt = $db->prepare("INSERT INTO requests (singer,artist,title) VALUES(:singer, :artist, :title)");
+$stmt->execute(array(":singer" => $singer, ":artist" => $artist, ":title" => $title));
+newSerial();
+echo "
Song: $artist - $title
+
Submitted for singer: $singer
+
Please press back to return to the main screen
+";
+
+sitefooter();
+?>
diff --git a/submitreq.php b/submitreq.php
new file mode 100644
index 0000000..5290f18
--- /dev/null
+++ b/submitreq.php
@@ -0,0 +1,25 @@
+query($sql) as $row) {
+ $artist = $row['artist'];
+ $title = $row['title'];
+}
+$db = null;
+echo "
Submitting Song: ";
+echo "
$artist - $title
";
+echo "
";
+echo "
If you have a common first name, please also enter your last initial or last name. Doing so will help eliminate confusion and reduce the risk of your turn getting skipped.";
+?>
diff --git a/venuestyle.css b/venuestyle.css
new file mode 100644
index 0000000..0bf21d2
--- /dev/null
+++ b/venuestyle.css
@@ -0,0 +1,98 @@
+@import url(http://fonts.googleapis.com/css?family=Scada);
+@import url(http://fonts.googleapis.com/css?family=Audiowide);
+
+body
+{
+ text-align: center;
+ font-family: 'Scada', sans-serif;
+ font-size: 1.2em;
+ font-weight: bold;
+ background-color: white;
+ color: black;
+ padding-top: 60px;
+}
+input[type=text] {
+ border: 2px solid black;
+ padding-top: 5px;
+ padding-bottom: 5px;
+ margin-right: 5px;
+ font-size: 1.2em;
+ font-weight: bold;
+}
+p.info
+{
+ font-size: 1.0em;
+}
+div.navbar
+{
+# height: 50px;
+ width: 100%;
+ position: fixed;
+ left: 0;
+ top: 0;
+ padding-left: 5px;
+ padding-top: 5px;
+ padding-bottom: 5px;
+ padding-right: 5px
+ width: 100%;
+ background-color: white;
+ color: black;
+ text-align: left;
+ border-style: solid;
+ border-width: 0px 0px 2px 0px;
+}
+a.navbar
+{
+ color: white;
+ text-decoration: none;
+}
+div.spacer
+{
+ position: relative;
+ width: 90%;
+ top: 0;
+ height: 50px;
+}
+table
+{
+ margin: auto;
+ min-width: 60%;
+ border: 1px;
+}
+td.result
+{
+ color: black;
+ font-size: 1.6em;
+ font-weight: bold;
+ text-align: left;
+ padding: 20px;
+ border-spacing: 10px;
+ border-style: solid;
+ border-size: 2px;
+}
+
+input[type=button], input[type=submit], input[type=reset], a.button {
+ background-color: white;
+ border: 2px;
+ border-style: solid;
+ border-color: black;
+ font-weight: bold;
+ color: black;
+ padding: 8px 20px;
+ margin-top: 12px;
+ text-decoration: none;
+ font-size: 1.2em;
+ cursor: pointer;
+}
+.backbtn {
+ position: fixed;
+ top: 75px;
+ left: 5px;
+}
+.title {
+ font-size: 2em;
+ font-family: Audiowide, cursive;
+ float: right;
+ margin-right: 10px;
+ text-shadow: 4px 4px 4px #aaa;
+}