forked from BroadcastVision/webCG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer.php
336 lines (286 loc) · 11 KB
/
layer.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
<?php
include("logic/config.php");
if (isset($_GET['id']) && isset($_GET['clone'])){ // Clone.
$id = sanitize($mysqli, $_GET['id']);
// Clone this layer. Add a prefix [Clone].
$mysqli->query("
INSERT INTO layers (name,icon,video_layer,transition,duration,direction,css,html_php,js,visible)
SELECT CONCAT('[Clone] ', name),icon,video_layer,transition,duration,direction,css,html_php,js,visible
FROM layers
WHERE id='$id'
");
// Generate Layer HTML file.
generate_html_layer($mysqli, $mysqli->insert_id, $folder_main_path);
// Redirect to the new layer page.
header("Location: layer.php?id=".$mysqli->insert_id);
}
if (isset($_POST['layer_name'])){ // Update detaills.
// Sanitize input.
$id = sanitize($mysqli, $_GET['id']);
$layer_name = sanitize($mysqli, $_POST['layer_name']);
$layer_icon = sanitize($mysqli, $_POST['layer_icon']);
$layer_video_layer = sanitize($mysqli, $_POST['layer_video_layer']);
$transition = sanitize($mysqli, $_POST['layer_transition']);
$duration = sanitize($mysqli, $_POST['layer_duration']);
$direction = sanitize($mysqli, $_POST['layer_direction']);
$css = sanitize($mysqli, $_POST['textarea_css']);
$html_php = sanitize($mysqli, $_POST['textarea_html_php']);
$js = sanitize($mysqli, $_POST['textarea_js']);
if(isset($_POST['visible']))
$visible = 1;
else
$visible = 0;
$mysqli->query ("
UPDATE layers
SET
name = '$layer_name',
icon = '$layer_icon',
video_layer = '$layer_video_layer',
transition = '$transition',
duration = '$duration',
direction = '$direction',
css = '$css',
html_php = '$html_php',
js = '$js',
visible = '$visible'
WHERE id='$id'
LIMIT 1
");
echo $mysqli->error;
// Generate Layer HTML file.
generate_html_layer($mysqli, $id, $folder_main_path);
// Redirect to the layer page.
header("Location: layer.php?id=".$id);
}
if ( isset($_GET['id']) ){
// Sanitize input.
$id = sanitize($mysqli, $_GET['id']);
$result = $mysqli->query("
SELECT layers.id AS id, layers.name AS name, icon, video_layer, transitions.name AS transition_name, duration, directions.name AS direction_name, css, html_php, js, visible
FROM layers, transitions, directions
WHERE
layers.id = '".$id."' AND
layers.transition = transitions.id AND
layers.direction = directions.id
ORDER BY video_layer, layers.name
");
$count_layers = mysqli_num_rows($result);
if($count_layers == 0)
header("Location: ./");
$layer = $result->fetch_assoc(); // Get layer details.
}
else
header("Location: ./");
// Get all Transitions.
$result_transitions = $mysqli->query("SELECT * FROM transitions");
// Get all Directions.
$result_directions = $mysqli->query("SELECT * FROM directions");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Layer: <?php echo $layer['name']; ?></title>
<?php include("head.php"); ?>
<style>
#editor_css, #editor_html, #editor_js{border:0;}
.textarea_hide{display:none;}
</style>
</head>
<body>
<div id="wrapper">
<!-- Navigation -->
<?php include("navigation.php"); ?>
<div id="page-wrapper">
<form id="layer_form" method="post">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Layer: <?php echo $layer['name']; ?>
<div class="pull-right">
<a href="index.php?delete=<?php echo $layer['id']; ?>" class="btn btn-default" data-toggle="confirmation" data-placement="top"><i class="fa fa-remove"></i> Delete </a>
<a href="preview.php?id=<?php echo $layer['id']; ?>&mode=browser" class="btn btn-success" target="_blank"><i class="fa fa-tv" aria-hidden="true"></i> Preview</a>
<a href="layer.php?id=<?php echo $layer['id']; ?>&clone" class="btn btn-primary" data-toggle="confirmation" data-placement="top"><i class="fa fa-clone" aria-hidden="true"></i> Clone</a>
<button type="submit" form="layer_form" type="button" class="btn btn-primary"><i class="fa fa-save" aria-hidden="true"></i> Save</button>
</div>
</h1>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-cog fa-fw"></i> Settings
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="col-lg-4">
<label>Name</label>
<input class="form-control" name="layer_name" value="<?php echo $layer['name']; ?>" required>
</div>
<div class="col-lg-2">
<label>Video Layer</label>
<input class="form-control" name="layer_video_layer" value="<?php echo $layer['video_layer']; ?>" required>
</div>
<div class="col-lg-2">
<div class="form-group">
<label>Transition</label>
<select name="layer_transition" class="form-control">
<?php
while($transition = $result_transitions->fetch_assoc()){
?>
<option value="<?php echo $transition['id']; ?>" <?php if ($layer['transition_name']==$transition['name']){echo "selected";} ?>><?php echo $transition['name']; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="col-lg-2">
<label>Duration (frame)</label>
<input class="form-control" name="layer_duration" value="<?php echo $layer['duration']; ?>" required>
</div>
<div class="col-lg-2">
<div class="form-group">
<label>Direction</label>
<select name="layer_direction" class="form-control">
<?php
while($direction = $result_directions->fetch_assoc()){
?>
<option value="<?php echo $direction['id']; ?>" <?php if ($layer['direction_name']==$direction['name']){echo "selected";} ?>><?php echo $direction['name']; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="col-lg-12">
<hr/>
</div>
<div class="col-lg-2">
<div class="form-group">
<label>Rundown Visibility</label>
<div class="checkbox">
<label>
<input name="visible" type="checkbox" <?php if($layer['visible']==1) echo "checked"; ?>>Active
</label>
</div>
</div>
</div>
<div class="col-lg-3">
<label>Layer Icon (<a href="http://fontawesome.io/icons/" target="_blank" title="Font Awesome Icons">?</a>)</label>
<input class="form-control" name="layer_icon" value="<?php echo $layer['icon']; ?>" placeholder="fa-square-o">
</div>
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
</div>
<!-- /.row -->
<div class="alert alert-danger">
Use <strong>double quotes</strong> for coding only. If you use single quotes you may experience issues while importing/exporting the MySQL database.
</div>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<strong>CSS Code</strong>
</div>
<div class="panel-body">
<pre id="editor_css" style="height: 400px;"><?php echo htmlspecialchars($layer['css']); ?></pre>
<textarea name="textarea_css" class="textarea_hide"></textarea>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<strong>HTML + PHP Code</strong>
</div>
<div class="panel-body">
<div class="alert alert-info">
To include <strong>PHP</strong> code use normally the <strong><?php ... ?></strong> tags.
</div>
<div class="alert alert-info">
To assign dynamically values to div tags from the <strong>Rundown</strong> use only: <strong><div id="f0"></div></strong> etc.
</div>
<?php
if(count(detect_f($mysqli, $layer['id'])) > 0){
?>
<div class="alert alert-success">
<strong>Dynamic Fields detected:</strong>
<?php
$dv = NULL;
foreach(detect_f($mysqli, $layer['id']) as $dynamic_value) {
$dv .= $dynamic_value.", ";
}
echo trim($dv, ", ");
?>
</div>
<?php
}
?>
<pre id="editor_html_php" style="height: 400px;"><?php echo htmlspecialchars($layer['html_php']); ?></pre>
<textarea name="textarea_html_php" class="textarea_hide"></textarea>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<strong>JavaScript Code</strong>
</div>
<div class="panel-body">
<div class="alert alert-info">
Include the <strong><script></strong> tag in your code. JQuery script is automatically loaded.
</div>
<pre id="editor_js" style="height: 400px;"><?php echo htmlspecialchars($layer['js']); ?></pre>
<textarea name="textarea_js" class="textarea_hide"></textarea>
</div>
</div>
</div>
</div>
</form>
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<?php include("scripts.php"); ?>
<script src="assets/ace/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
// CSS Editor.
var editor_css = ace.edit("editor_css");
editor_css.setTheme("ace/theme/monokai");
editor_css.setOption("showPrintMargin", false);
editor_css.session.setUseWorker(false);
editor_css.getSession().setMode("ace/mode/css");
$("textarea[name='textarea_css']").val(editor_css.getSession().getValue());
editor_css.getSession().on('change', function () {
$("textarea[name='textarea_css']").val(editor_css.getSession().getValue());
});
// HTML + PHP Editor.
var editor_html_php = ace.edit("editor_html_php");
editor_html_php.setTheme("ace/theme/monokai");
editor_html_php.setOption("showPrintMargin", false);
editor_html_php.session.setUseWorker(false);
editor_html_php.getSession().setMode("ace/mode/html");
$("textarea[name='textarea_html_php']").val(editor_html_php.getSession().getValue());
editor_html_php.getSession().on('change', function () {
$("textarea[name='textarea_html_php']").val(editor_html_php.getSession().getValue());
});
// JS Editor.
var editor_js = ace.edit("editor_js");
editor_js.setTheme("ace/theme/monokai");
editor_js.setOption("showPrintMargin", false);
editor_js.session.setUseWorker(false);
editor_js.getSession().setMode("ace/mode/javascript");
$("textarea[name='textarea_js']").val(editor_js.getSession().getValue());
editor_js.getSession().on('change', function () {
$("textarea[name='textarea_js']").val(editor_js.getSession().getValue());
});
</script>
</body>
</html>