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 "
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 "

Song search:

"; 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; } ?>