-
Notifications
You must be signed in to change notification settings - Fork 20
/
global.inc
166 lines (149 loc) · 4.51 KB
/
global.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
include("settings.inc");
$db = new PDO("sqlite:$dbFilePath");
$db->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);
$songdbtable = "songdb";
$requeststable = "requests";
if (isset($_SERVER['REFERER'])) $referer = $_SERVER['REFERER'];
function siteheader($title)
{
global $venueName;
global $screensize;
echo "<html><head>
<link href='https://fonts.googleapis.com/css?family=Audiowide' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'>
<title>$venueName Karaoke Songbook</title>
<link rel=stylesheet type=\"text/css\" href=venuestyle.css />
<script type=\"text/javascript\">
function submitreq(varid){
window.location = \"./submitreq.php?id=\" + varid;
}
</script>
</head><body>";
}
function sitefooter() {
echo "</div></body></html>";
}
function navbar($backurl)
{
if ($backurl == "")
$backurl = index.php;
global $screensize;
echo "<div class=navbar>
<span class=title>OpenKJ Songbook</span>
</div><div class=mainbody><span class=backbtn><a class=button href=\"$backurl\" class=navbar id=backlink>Back</a></span>";
}
function setAccepting($accepting)
{
global $db;
if ($accepting == 1)
{
echo("setting accepting to 1");
$db->exec("UPDATE state SET accepting=1");
}
else
{
echo("setting accepting to 0");
$db->exec("UPDATE state SET accepting=0");
}
}
function getAccepting()
{
global $db;
$accepting = false;
foreach ($db->query("SELECT accepting FROM state LIMIT 1") as $row)
{
$accepting = $row['accepting'];
}
return $accepting;
}
function searchform()
{
global $db;
global $venue_id;
if (!getAccepting())
{
echo "<br><br><h2>Sorry, requests are not being accepted at this time</h2>";
}
else
{
global $url_name;
global $screensize;
echo "<br><p><form method=get action=search.php>Song search: <input type=text name=q autofocus autocomplete=off><input type=submit value=Search></form></p>";
echo '<p class=info>You may enter any part of the artist and/or title of the song. Partial words are allowed.</p>
<p class=info>For example "pai bla stone" would match "Rolling Stones, The - Paint it black".</p>';
}
}
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;
}
?>