-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.php
349 lines (297 loc) · 11.1 KB
/
index.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
348
349
<?php
include("logic/config.php");
// Delete Layer.
if ( isset($_GET['delete']) ){
$id = sanitize($mysqli, $_GET['delete']);
delete_layer($mysqli, $id);
header("Location: ./");
}
// Add Layer.
if ( isset($_POST['layer_name']) ){
$name = sanitize($mysqli, $_POST['layer_name']);
add_layer($mysqli, $name);
header("Location: ./");
}
// Check if CasparCG Server is online.
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$connection = @socket_connect($socket, $ip, $port);
if( $connection ){
$status = 'online';
$alert_class = 'alert-success';
}
else {
$status = 'offline: <i>' . socket_strerror(socket_last_error( $socket )) . '</i>';
$alert_class = 'alert-danger';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>WebCG Client</title>
<?php include("head.php"); ?>
</head>
<body>
<div id="wrapper">
<!-- Navigation -->
<?php include("navigation.php"); ?>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Rundown
<div class="pull-right">
<?php
if($status == 'online'){
?>
<button type="button" id="kill" class="btn btn-danger command" data-command="KILL" data-toggle="confirmation" data-placement="top">
<i class="fa fa-times fa-fw"></i> KILL Server
</button>
<?php
}
?>
<button class="btn btn-primary" data-toggle="modal" data-target="#addModal"><i class="fa fa-plus" aria-hidden="true"></i> Add Layer </button>
<a href="./" class="btn btn-warning"><i class="fa fa-circle-o-notch" aria-hidden="true"></i> Reload Rundown [F5]</a>
<button type="button" class="btn btn-danger command" data-command="CLEAR <?php echo $channel;?>"><i class="fa fa-eraser fa-fw"></i> CLEAR Channel [F10]</button>
</div>
</h1>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="alert <?php echo $alert_class; ?>">
<strong>CasparCG</strong> [<?php echo $ip.":".$port;?>] is <?php echo $status; ?>
</div>
</div>
</div>
<div class="form-group input-group">
<span class="input-group-addon"><i><i class="fa fa-terminal fa-fw"></i> Executed Command</i></span>
<input id="executed-command" class="form-control input" type="text" readonly>
</div>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-navicon fa-fw"></i> Layers
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Video Layer</th>
<th>Transition</th>
<th>Duration</th>
<th>Direction</th>
<th>Playout</th>
</tr>
</thead>
<tbody>
<?php
$result = $mysqli->query("
SELECT layers.id AS id, layers.name AS name, video_layer, transitions.name AS transition_name, duration, directions.name AS direction_name
FROM layers, transitions, directions
WHERE
layers.visible = '1' AND
layers.transition = transitions.id AND
layers.direction = directions.id
ORDER BY video_layer DESC, layers.name
");
$total_layers = mysqli_num_rows($result);
if ($total_layers > 0){
while($layer = $result->fetch_assoc()){
$command_play = "PLAY ".$channel."-".$layer['video_layer']." [HTML] "http://".$_SERVER["SERVER_ADDR"]."/".basename($_SERVER["REQUEST_URI"])."/layers/".$layer['id'].".html""." ".$layer['transition_name']." ".$layer['duration']." Linear"." ".$layer['direction_name'];
$command_stop = "STOP ".$channel."-".$layer['video_layer'];
?>
<tr>
<td><a href="layer.php?id=<?php echo $layer['id']; ?>" title="Layer Settings"><strong><?php echo $layer['name']; ?></strong></a></td>
<td class="small"><?php echo $layer['video_layer']; ?></td>
<td class="small"><?php echo $layer['transition_name']; ?></td>
<td class="small"><?php echo $layer['duration']; ?> frame</td>
<td class="small"><?php echo $layer['direction_name']; ?></td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-sm btn-success command" data-command="<?php echo $command_play; ?>">
<i class="fa fa-play" aria-hidden="true"></i> PLAY
</button>
<button type="button" class="btn btn-sm btn-danger command" data-command="<?php echo $command_stop; ?>">
<i class="fa fa-stop" aria-hidden="true"></i> STOP
</button>
</div>
</td>
</tr>
<?php
if(count(detect_f($mysqli, $layer['id'])) > 0){
?>
<tr>
<td colspan="6" class="options">
<form id="form-<?php echo $layer['id']; ?>">
<?php
// Get placeholders and values.
list($placeholders, $field_values) = detect_placeholders($mysqli, $layer['id']);
$counter = 0;
foreach ( detect_f($mysqli, $layer['id']) as $value ){
?>
<div class="form-group input-group col-lg-2 form-options">
<span class="input-group-addon input-sm">
<strong><?php echo $placeholders[$counter];?></strong>
</span>
<input type="text" name="<?php echo $value;?>"
<?php
if(isset($field_values[$counter])){
?>
value="<?php echo htmlspecialchars($field_values[$counter]);?>"
<?php
}
?>
class="form-control input input-sm">
</div>
<?php
$counter++;
}
?>
<button type="button" class="btn btn-sm btn-primary update" data-id="<?php echo $layer['id']; ?>" data-layer="<?php echo $layer['video_layer']; ?>"><i class="fa fa-refresh" aria-hidden="true"></i> UPDATE</button>
</form>
</td>
</tr>
<?php
}
?>
<?php
}
}
else{
?>
<tr>
<td colspan="4">No active layers found.</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
</div>
<!-- /.row -->
<div class="spacer"></div>
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<!-- Modal: Add Module -->
<div class="modal" id="addModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Add Layer</h4>
</div>
<form method="post">
<div class="modal-body">
<div class="form-group">
<label>Layer Name</label>
<input class="form-control" name="layer_name" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary"><i class="fa fa-plus" aria-hidden="true"></i> Add</button>
</div>
</form>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<?php include("scripts.php"); ?>
<script>
// Modal Call, focus.
$(document).ready(function() {
$('.modal').on('shown.bs.modal', function () {
$('[name="layer_name"]').focus();
});
});
// Command Execusion.
$(document).ready(function() {
$(".command").click(function(){
// Get command.
var command = $(this).data('command');
// Update command textfield for preview.
$('#executed-command').attr('value', command);
// Send command to Command Handler for execution.
$.ajax({
url: 'http://<?php echo $_SERVER["SERVER_ADDR"];?>/<?php echo $folder_main_path; ?>/logic/CommandHandler.php',
type: 'POST',
data: {casparcg_command: command}
});
});
});
// On key press.
document.onkeydown = function(e) {
switch (e.keyCode) {
case 121: // Clear Channel.
e.preventDefault();
var command = 'CLEAR <?php echo $channel;?>';
// Update command textfield for preview.
$('#executed-command').attr('value', command);
// Send command to Command Handler for execution.
$.ajax({
url: 'http://<?php echo $_SERVER["SERVER_ADDR"];?>/<?php echo $folder_main_path;?>/logic/CommandHandler.php',
type: 'POST',
data: {casparcg_command: command}
});
break;
}
}
// Layer Update Execusion.
$(document).ready(function() {
$(".update").click(function(){
// Get layer id.
var layer_id = $(this).data('id');
// Get video layer.
var video_layer = $(this).data('layer');
// Get dynamic values.
var dynamic_fields = new Array();
$('form#form-'+layer_id+' input[type=text]').each(function(){
var name = $(this).attr("name");
var value = $(this).val();
// Update the file template permanent to reflect changes in f[] values.
$.ajax({
url: 'logic/LayerValuesHandler.php',
type: 'POST',
data: {layer: layer_id, field_id: name, field_value: value,}
});
// Create array.
dynamic_fields.push(name, escape(value));
});
// Create command.
// Add single quotes to array values.
var newArr = jQuery.map( dynamic_fields, function( n, i ) {
return ( "\'"+n+"\'" );
});
var command = 'CALL <?php echo $channel ?>-'+video_layer+' INVOKE "DynamicFields('+newArr+')"';
// Send command to Command Handler for execution.
$.ajax({
url: 'http://<?php echo $_SERVER["SERVER_ADDR"];?>/<?php echo $folder_main_path; ?>/logic/CommandHandler.php',
type: 'POST',
data: {casparcg_command: command}
});
// Update command textfield for preview.
$('#executed-command').attr('value', command);
});
});
// On KILL button reload page to change the status of the server.
$(document).ready(function() {
$("#kill").click( function(){
setTimeout( function(){
location.reload();
},1000);
});
});
</script>
</body>
</html>