forked from MoeFwacky/Plex-Now-Playing-Display
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db-schedule.php
347 lines (343 loc) · 17.9 KB
/
db-schedule.php
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<!DOCTYPE html>
<?php
$ch_file="";
include('./control.php');
include('./config.php');
$tvlocations = glob($pseudochannelTrim . "*", GLOB_ONLYDIR);
$boxes = '';
?>
<html lang="en" class="no-js" style="height:100%">
<head>
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous">
</script>
<script>
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const tv = urlParams.get('tv');
if (tv != "null") {
topbar = "topbar.php?tv="+tv;
getdata = "getSchedule.php?tv="+tv;
getclock = "getClock.php?tv="+tv;
} else {
topbar = "topbar.php";
getdata = "getSchedule.php";
getclock = "getClock.php";
}
$(document).ready( function() {
$("#topbar").load(topbar);
$.getJSON(topbar,function(data) {
$.each(data, function(key,val) {
$('#'+key).html(val);
});
});
});
</script>
<style type="text/css">a {text-decoration: none}</style>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FakeTV Schedule Editor for Pseudo Channel</title>
<meta name="description" content="A page to edit Pseudo Channel database schedules" />
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<link rel="stylesheet" type="text/css" href="css/demo.css" />
<link rel="stylesheet" type="text/css" href="css/component.css" />
<link rel="apple-touch-icon" sizes="180x180" href="assets/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="assets/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="assets/favicon-16x16.png">
<link rel="manifest" href="assets/site.webmanifest">
<link rel="mask-icon" href="assets/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="assets/favicon.ico">
<meta name="msapplication-TileColor" content="#2b5797">
<meta name="msapplication-config" content="assets/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="js/classie.js"></script>
<script src="js/gnmenu.js"></script>
<script src="js/modernizr.custom.js"></script>
<!-- <script>
var query = window.location.search.substring(1)
if(query.length) {
if(window.history != undefined && window.history.pushState != undefined) {
window.history.pushState({}, document.title, window.location.pathname);
}
}
</script>
<script language="JavaScript">
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
</script> -->
</head>
<body>
<?php
$dircontents=array();
$scheduleTable = "<table width='100%' max-width='100%' class='schedule-table'><thead><tr width='100%'><th width='4%' max-width='4%'> ID </th><th colspan='1' width='8%' max-width='8%'>Day</th><th colspan='1' width='8%' max-width='8%'>Start Time</th><th colspan='1' width='8%' max-width='8%'>Section</th><th colspan='1' max-width='8%' width='8%'>Title</th><th colspan='1' width='8%' max-width='8%'>Time Mode</th><th colspan='1' max-width='8%' width='8%'>Duration</th><th colspan='1' width='8%' max-width='8%'>Time Shift</th><th colspan='1' max-width='8%' width='8%'>Max Preempt</th><th colspan='1' width='8%' max-width='8%'>Extra Data</th><th>Submit</th></thead><tbody>";
//GET ALL PSEUDO CHANNEL DATABASE FILE LOCATIONS
$DBarray = array();
$globString = $pseudochannelMaster . "/pseudo-channel_*/pseudo-channel.db";
$DBarray = glob($globString);
if(isset($_GET['channel'])) {
$channelNumber = $_GET['channel'];
} else {
$channelNumber = "01";
}
if(isset($_GET['dayOfWeek'])) {
$selectDayOfWeek = $_GET['dayOfWeek'];
} else {
$selectDayOfWeek = "all";
}
$channelDropdown = "<table><span style='color:white'>CHANNEL: </span><form method='get'><select name='channel' style='width:4em'>";
foreach($DBarray as $channelFromList) {
$channelFile = str_replace($pseudochannelMaster . "/pseudo-channel_", "", $channelFromList);
$channelFileNumber = str_replace("/pseudo-channel.db", "", $channelFile);
if ($channelNumber == $channelFileNumber) {
$channelDropdown .= "<option value='" . $channelFileNumber . "' selected>" . $channelFileNumber . "</option>";
} else {
$channelDropdown .= "<option value='" . $channelFileNumber . "'>" . $channelFileNumber . "</option>";
}
}
$channelDropdown .= "</select>";
$daysDropDown = "<span style='color:white'> DAY: </span><select name='dayOfWeek' style='width:10em'>";
$allDays = array('all','sundays','mondays','tuesdays','wednesdays','thursdays','fridays','saturdays','weekends','weekdays','everyday');
foreach ($allDays as $theDay) {
if ($selectDayOfWeek == $theDay) {
$daysDropDown .= "<option value='" . $theDay . "' selected>" . ucfirst($theDay) . "</option>";
} else {
$daysDropDown .= "<option value='" . $theDay . "'>" . ucfirst($theDay) . "</option>";
}
}
$daysDropDown .="</select><input type='submit'></form></table></br>";
foreach ($DBarray as $databasefile) { //do the following for each database file
if($databasefile) {
$psDB = new SQLite3($databasefile);
$ch_file = str_replace($pseudochannelMaster . "/pseudo-channel_", "ch", $databasefile); //get channel number
$ch_file = str_replace("/pseudo-channel.db", "", $ch_file);
$ch_number = str_replace("ch", "", $ch_file);
$ch_row = "row" . $ch_number;
$sqlData = array();
if($channelNumber == $ch_number) {
if(isset($_GET['addRow'])) {
if ($_GET['addRow'] == "addAbove") {
$getStartTimeUnix = strval(strtotime($_GET['startTime']) - (30 * 60));
$getStartTime = strftime("%H:%M:%S", $getStartTimeUnix);
$rightNow = intval(time());
$getID = intval($_GET['id']);
$getDay = $_GET['day'];
$insertStatement = $psDB->prepare("INSERT INTO schedule VALUES (null, :unix, '999', 'random', '19,30', :startTime, '0', :dayOfWeek, :startTimeUnix, 'TV Shows', 'secondary', '5', '30', '', '', '', '', '', '', '', '', '')");
$insertStatement->bindParam(':unix', $rightNow);
$insertStatement->bindParam(':startTime', $getStartTime);
$insertStatement->bindParam(':dayOfWeek', $getDay);
$insertStatement->bindParam(':startTimeUnix', $getStartTimeUnix);
$insertResult = $insertStatement->execute();
} elseif ($_GET['addRow'] == "addBelow") {
$getStartTimeUnix = strval(strtotime($_GET['startTime']) + (30 * 60));
$getStartTime = strftime("%H:%M:%S", $getStartTimeUnix);
$rightNow = intval(time());
$getID = intval($_GET['id']) + 1;
$getDay = $_GET['day'];
$insertStatement = $psDB->prepare("INSERT INTO schedule VALUES (null, :unix, '999', 'random', '19,30', :startTime, '0', :dayOfWeek, :startTimeUnix, 'TV Shows', 'secondary', '5', '30', '', '', '', '', '', '', '', '', '')");
$insertStatement->bindParam(':unix', $rightNow);
$insertStatement->bindParam(':startTime', $getStartTime);
$insertStatement->bindParam(':dayOfWeek', $getDay);
$insertStatement->bindParam(':startTimeUnix', $getStartTimeUnix);
$insertResult = $insertStatement->execute();
} elseif ($_GET['addRow'] == "delete") {
$getID = intval($_GET['id']);
$deleteStatement = $psDB->prepare("DELETE FROM schedule WHERE ID = :getID");
$deleteStatement->bindParam(':getID', $getID);
$deleteResult = $deleteStatement->execute();
}
}
if($selectDayOfWeek != "all") {
// $result = $psDB->query("SELECT * FROM schedule ORDER BY CASE WHEN dayOfWeek='all' THEN 0 WHEN dayOfWeek='sundays' THEN 1 WHEN dayOfWeek='mondays' THEN 2 WHEN dayOfWeek='tuesdays' THEN 3 WHEN dayOfWeek='wednesdays' THEN 4 WHEN dayOfWeek='thursdays' THEN 5 WHEN dayOfWeek='fridays' THEN 6 WHEN dayOfWeek='saturdays' THEN 7 WHEN dayOfWeek='weekends' THEN 8 WHEN dayOfWeek='weekdays' THEN 9 WHEN dayOfWeek='everyday' THEN 10 END, startTime");
$statement = $psDB->prepare("SELECT * FROM schedule WHERE dayOfWeek = :day ORDER BY startTime");
$statement->bindParam(':day', $selectDayOfWeek);
$result = $statement->execute();
} else {
// $result = $psDB->query("SELECT * FROM schedule ORDER BY dayOfWeek, startTime");
$result = $psDB->query("SELECT * FROM schedule ORDER BY CASE WHEN dayOfWeek='all' THEN 0 WHEN dayOfWeek='sundays' THEN 1 WHEN dayOfWeek='mondays' THEN 2 WHEN dayOfWeek='tuesdays' THEN 3 WHEN dayOfWeek='wednesdays' THEN 4 WHEN dayOfWeek='thursdays' THEN 5 WHEN dayOfWeek='fridays' THEN 6 WHEN dayOfWeek='saturdays' THEN 7 WHEN dayOfWeek='weekends' THEN 8 WHEN dayOfWeek='weekdays' THEN 9 WHEN dayOfWeek='everyday' THEN 10 END, startTime");
}
while ($sqlData = $result->fetchArray()) {
if ($sqlData['mediaID'] != 9999) {
$sectionValue = $sqlData['section'];
$sectionText = $sqlData['section'];
} else {
$sectionValue = "random";
$sectionText = "Random Episode";
}
if ($sqlData['strictTime'] == "true") {
$timeMode = "Strict Start Time";
} elseif ($sqlData['strictTime'] == "false") {
$timeMode = "Variable Start Time";
} elseif ($sqlData['strictTime'] == "secondary") {
$timeMode = "Allow Preempting";
} else {
$timeMode = "INVALID ENTRY";
}
$explodeDuration = explode(",", $sqlData['duration']);
if ($sqlData['mediaID'] == 9999) {
if($explodeDuration[0] == "0" && $explodeDuration[1] == "43200000") {
$durationStatement = $psDB->prepare("SELECT * FROM shows WHERE title == :title");
$durationStatement->bindParam(':title', $sqlData['title']);
$durationResult = $durationStatement->execute();
$durationArray = $durationResult->fetchArray();
$scheduleDuration = round($durationArray['duration'] / 60000) . " Mins";
} else {
$scheduleDuration = $explodeDuration[0] . " - " . $explodeDuration[1] . " Mins";
}
} elseif ($sqlData['title'] != "random" and $sqlData['title'] != "kevinbacon") {
$durationStatement = $psDB->prepare("SELECT * FROM shows WHERE title == :title");
$durationStatement->bindParam(':title', $sqlData['title']);
$durationResult = $durationStatement->execute();
$durationArray = $durationResult->fetchArray();
$scheduleDuration = round($durationArray['duration'] / 60000) . " Mins";
} else {
if($explodeDuration[0] == "0" && $explodeDuration[1] == "43200000") {
$scheduleDuration = "Any";
} else {
$scheduleDuration = $explodeDuration[0] . " - " . $explodeDuration[1] . " Mins";
}
}
if ($sqlData['xtra'] != "") {
$xtraData = str_replace(";","</br>",$sqlData['xtra']);
$xtraData = str_replace(":",": ",$xtraData);
$xtraData = ucwords($xtraData,">");
$xtraData = ucwords($xtraData," ");
$xtraData = ucwords($xtraData,"-");
} else {
$xtraData = "";
if ($sqlData['rerun'] == "1") {
$xtraData .= "Rerun Last Episode</br>";
}
if ($sqlData['seasonEpisode'] != "") {
$seasonEpisodeArray = explode(',', $sqlData['seasonEpisode']);
if ($seasonEpisodeArray[0] != '*') {
$xtraData .= "Season # " . $seasonEpisodeArray[0] . "</br>";
}
if ($seasonEpisodeArray[1] != '*') {
$xtraData .= "Episode # " . $seasonEpisodeArray[1] . "</br>";
}
}
if ($sqlData['year'] != "") {
if (strpos($sqlData['year'], '*') !== false) {
$decade = str_replace('*','0s',$sqlData['year']);
$xtraData .= "Decade: " . $decade . "</br>";
} else {
$xtraData .= "Year: " . $sqlData['year'] . "</br>";
}
}
if ($sqlData['genres'] != "") {
if (strpos($sqlData['genres'], ',') !== false) {
$genreArray = explode(',', $sqlData['genres']);
foreach($genreArray as $genre) {
$xtraData .= "Genre: " . $genre . "</br>";
}
} else {
$xtraData .= "Genre: " . $sqlData['genres'] . "</br>";
}
}
if ($sqlData['actors'] != "") {
if (strpos($sqlData['actors'], ',') !== false) {
$actorArray = explode(',', $sqlData['actors']);
foreach($actorArray as $actor) {
$xtraData .= "Actor: " . $actor . "</br>";
}
} else {
$xtraData .= "Actor: " . $sqlData['actors'] . "</br>";
}
}
if ($sqlData['collections'] != "") {
if (strpos($sqlData['collections'], ',') !== false) {
$collectionArray = explode(',', $sqlData['collections']);
foreach($collectionArray as $collection) {
$xtraData .= "Collection: " . $collection . "</br>";
}
} else {
$xtraData .= "Collection: " . $sqlData['collections'] . "</br>";
}
}
if ($sqlData['rating'] != "") {
$ratingArray = explode(',', $sqlData['rating']);
$xtraData .= "Rating: " . $ratingArray[1];
if ($ratingArray[2] == '<') {
$xtraData .= "↓</br>";
} elseif ($ratingArray[2] == '>') {
$xtraData .= "↑</br>";
} else {
$xtraData .= "</br>";
}
}
if ($sqlData['studio'] != "") {
if (strpos($sqlData['studio'], ',') !== false) {
$studioArray = explode(',', $sqlData['studio']);
foreach($studioArray as $studio) {
$xtraData .= "Studio: " . $studio . "</br>";
}
} else {
$xtraData .= "Studio: " . $sqlData['studio'] . "</br>";
}
}
}
$scheduleTable .= "<tr><td>" . $sqlData['id'] . "</td>";
$scheduleTable .= "<td><span name='" . $ch_row . "Day' style='width: 6em'>" . ucfirst($sqlData['dayOfWeek']) . "</span></td>";
$scheduleTable .= "<td><span name='" . $ch_row . "Start' style='width: 7em'>" . $sqlData['startTime'] . "</span></td>";
$scheduleTable .= "<td><span name='" . $ch_row . "Section' style='width: 9em'>" . ucfirst($sectionText) . "</span></td>";
if($sqlData['title'] == "kevinbacon") {
$scheduleTable .= "<td><span name='" . $ch_row . "Title' style='width: 20em'>" . ucfirst("Random (Kevin Bacon Mode)") . "</td>";
} else {
$scheduleTable .= "<td><span name='" . $ch_row . "Title' style='width: 20em'>" . ucfirst($sqlData['title']) . "</td>";
}
$scheduleTable .= "<td><span name='" . $ch_row . "strictTime'>" . $timeMode . "</td>";
$scheduleTable .= "<td><span name='" . $ch_row . "DurationMin' style='width: 7em'>" . $scheduleDuration . "</span></td>";
$scheduleTable .= "<td><span name='" . $ch_row . "TimeShift' style='width: 4em'>" . $sqlData['timeShift'] . " Mins</td>";
$scheduleTable .= "<td><span name='" . $ch_row . "OverlapMax' style='width: 4em'>" . $sqlData['overlapMax'] . " Mins</td>";
$scheduleTable .= "<td><span name='" . $ch_row . "Xtra'>" . $xtraData . "</td>";
$scheduleTable .= "<td><form action='db-schedule.php' method='get'>";
$scheduleTable .= "<input type='hidden' name='channel' value=" . $channelNumber . ">";
$scheduleTable .= "<input type='hidden' name='id' value=" . $sqlData['id'] . ">";
if(isset($_GET['dayOfWeek'])) {
$scheduleTable .= "<input type='hidden' name='dayOfWeek' value=" . $_GET['dayOfWeek'] . ">";
}
$scheduleTable .= "<input type='hidden' name='day' value=" . $sqlData['dayOfWeek'] . ">";
$scheduleTable .= "<input type='hidden' name='startTime' value=" . $sqlData['startTime'] . ">";
$scheduleTable .= "<button type='submit' name='addRow' value='addAbove'>Add Above</button></form>";
$scheduleTable .= "<form action='db-edit.php' method='get' style='display:inline-block'><input type='hidden' name='channelNumber' value=" . $channelNumber . "><input type='hidden' name='dayOfWeek' value=" . $_GET['dayOfWeek'] . "><button type='submit' name='id' value=" . $sqlData['id'] . ">Edit Row</button></form>";
$scheduleTable .= "<form action='db-schedule.php' method='get' style='display:inline-block'>";
$scheduleTable .= "<input type='hidden' name='channel' value=" . $channelNumber . ">";
$scheduleTable .= "<input type='hidden' name='id' value=" . $sqlData['id'] . ">";
if(isset($_GET['dayOfWeek'])) {
$scheduleTable .= "<input type='hidden' name='dayOfWeek' value=" . $_GET['dayOfWeek'] . ">";
}
$scheduleTable .= "<input type='hidden' name='day' value=" . $sqlData['dayOfWeek'] . ">";
$scheduleTable .= "<button type='submit' name='addRow' value='delete'>Delete Row</button></form>";
$scheduleTable .= "<form action='db-schedule.php' method='get'>";
$scheduleTable .= "<input type='hidden' name='channel' value=" . $channelNumber . ">";
$scheduleTable .= "<input type='hidden' name='id' value=" . $sqlData['id'] . ">";
if(isset($_GET['dayOfWeek'])) {
$scheduleTable .= "<input type='hidden' name='dayOfWeek' value=" . $_GET['dayOfWeek'] . ">";
}
$scheduleTable .= "<input type='hidden' name='day' value=" . $sqlData['dayOfWeek'] . ">";
$scheduleTable .= "<input type='hidden' name='startTime' value=" . $sqlData['startTime'] . ">";
$scheduleTable .= "<button type='submit' name='addRow' value='addBelow'>Add Below</button></td></tr></form>";
}
}
}
}
$scheduleTable .= "</tbody></table>";
?>
<div id="topbar" name="topbar"></div>
<div class="container main-container">
<?php echo $channelDropdown; ?>
<?php echo $daysDropDown; ?>
<?php echo $scheduleTable; ?>
</div><!-- /container -->
</body>
</html>