-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
331 lines (268 loc) · 13.7 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
<?php
/*
* ColourPicker webapp for Hyperion.
*
* Refactored by: Brad Cornford <me@bradleycornford.co.uk> - February 2014
* Email: me@bradleycornford.co.uk
* Twitter: @BradCornford
*
* Based on ColourPicker v1.0 by nadnerb - April 2013
* More info: http://blog.nadnerb.co.uk
* Twitter: @_nadnerb
*
* Farbtastic: http://acko.net/blog/farbtastic-jquery-color-picker-plug-in/
*/
include('colourPicker/lib/RemoteCommand.class.php');
include('colourPicker/conf/Configuration.php');
session_start();
session_destroy();
session_start();
if (empty($_SESSION)) {
$_SESSION['priority'] = array();
$_SESSION['colour'] = '00FFFF';
$_SESSION['duration'] = -1;
}
$messages = array();
$com = new RemoteCommand();
if (isset($_POST['submit'])) {
switch ($_POST['submit']) {
case 'Turn On':
$return = $com->withServer($config['serverAddress'], $config['serverUsername'], $config['serverPassword'], $config['debug'])
->withController($config['serverController'])
->withSleep(2)
->callOn();
if ($return) {
$messages[] = array(
'type' => 'success',
'content' => 'Turned on Hyperion successfully.'
);
}
break;
case 'Turn Off':
$return = $com->withServer($config['serverAddress'], $config['serverUsername'], $config['serverPassword'], $config['debug'])
->withController($config['serverController'])
->withSleep(1)
->callOff();
if ($return) {
$messages[] = array(
'type' => 'success',
'content' => 'Turned off Hyperion successfully.'
);
}
break;
case 'Clear':
$return = $com->withServer($config['serverAddress'], $config['serverUsername'], $config['serverPassword'], $config['debug'])
->withAddress($config['hyperionAddress'])
->withPriority($_POST['priority'])
->callClear();
unset($_SESSION['priority'][$_POST['priority']]);
if ($return) {
$messages[] = array(
'type' => 'success',
'content' => 'Cleared the priority channel ' . $_POST['priority'] . '.'
);
}
break;
case 'Clear All':
$return = $com->withServer($config['serverAddress'], $config['serverUsername'], $config['serverPassword'], $config['debug'])
->withAddress($config['hyperionAddress'])
->callClearAll();
$_SESSION['priority'] = array();
if ($return) {
$messages[] = array(
'type' => 'success',
'content' => 'Cleared the all priority channels.'
);
}
break;
case 'Change Colour':
$return = $com->withServer($config['serverAddress'], $config['serverUsername'], $config['serverPassword'], $config['debug'])
->withAddress($config['hyperionAddress'])
->withDuration($_POST['duration'] > 0 ? $_POST['duration'] : false)
->withPriority($_POST['priority'])
->withColour($_POST['colour'])
->callColour();
$_SESSION['colour'] = $_POST['colour'];
$_SESSION['priority'][$_POST['priority']] = true;
$_SESSION['duration'] = $_POST['duration'];
$messages[] = array(
'type' => 'success',
'content' => 'Loaded colour "' . $_POST['colour'] . '" with the priority ' . $_POST['priority'] . '' . ($_POST['duration'] > 0 ? ' and the duration ' . $_POST['duration'] : '') . '.'
);
break;
case 'Loading Effect...':
$return = $com->withServer($config['serverAddress'], $config['serverUsername'], $config['serverPassword'], $config['debug'])
->withAddress($config['hyperionAddress'])
->withDuration($_POST['duration'] > 0 ? $_POST['duration'] : false)
->withPriority($_POST['priority'])
->withEffect($_POST['effect'])
->callEffect();
$_SESSION['priority'][$_POST['priority']] = true;
$_SESSION['duration'] = $_POST['duration'];
if ($return) {
$messages[] = array(
'type' => 'success',
'content' => 'Loaded effect "' . $_POST['effect'] . '" with the priority ' . $_POST['priority'] . '' . ($_POST['duration'] > 0 ? ' and the duration ' . $_POST['duration'] : '') . '.'
);
}
break;
default:
$return = $com->callDefault();
break;
}
if (!$return) {
$message[] = array(
'type' => 'error',
'content' => 'An error occurred running the command.'
);
}
}
$currentStatus = $com->withServer($config['serverAddress'], $config['serverUsername'], $config['serverPassword'], $config['debug'])
->withAddress($config['hyperionAddress'])
->getStatus();
$currentCommands = $com->withServer($config['serverAddress'], $config['serverUsername'], $config['serverPassword'], $config['debug'])
->withAddress($config['hyperionAddress'])
->getCommands();
$currentEffects = $com->withServer($config['serverAddress'], $config['serverUsername'], $config['serverPassword'], $config['debug'])
->withAddress($config['hyperionAddress'])
->getEffects();
if ($currentCommands) {
$_SESSION['priority'] = array();
foreach ($currentCommands as $key => $command) {
if ($command == 1000 || (isset($_POST['submit']) && $_POST['submit'] == 'Turn On')) {
unset($currentCommands[$key]);
} else {
$_SESSION['priority'][$command] = true;
}
}
}
if ($config['overwriteStatus']) {
$currentStatus = true;
}
?>
<html>
<head>
<title>Hyperion</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="HandheldFriendly" content="true">
<meta name="MobileOptimized" content="320">
<link rel="shortcut icon" href="colourPicker/img/favicon.ico" type="image/x-icon" />
<link rel="apple-touch-icon" href="colourPicker/img/apple-touch-icon.png" />
<link rel="apple-touch-icon" sizes="57x57" href="colourPicker/img/apple-touch-icon-57x57.png" />
<link rel="apple-touch-icon" sizes="72x72" href="colourPicker/img/apple-touch-icon-72x72.png" />
<link rel="apple-touch-icon" sizes="76x76" href="colourPicker/img/apple-touch-icon-76x76.png" />
<link rel="apple-touch-icon" sizes="114x114" href="colourPicker/img/apple-touch-icon-114x114.png" />
<link rel="apple-touch-icon" sizes="120x120" href="colourPicker/img/apple-touch-icon-120x120.png" />
<link rel="apple-touch-icon" sizes="144x144" href="colourPicker/img/apple-touch-icon-144x144.png" />
<link rel="apple-touch-icon" sizes="152x152" href="colourPicker/img/apple-touch-icon-152x152.png" />
<link rel="stylesheet" href="colourPicker/css/jquery-ui.css" type="text/css" />
<link rel="stylesheet" href="colourPicker/css/farbtastic.css" type="text/css" />
<link rel="stylesheet" href="colourPicker/css/style.css" type="text/css" />
</head>
<body ontouchstart="">
<div align="center" id="header">
<h1><img src="colourPicker/img/logo.png" width="44"/>Hyperion</h1>
</div>
<div id="wrapper">
<div align="center" id="content">
<form id="form" name="form" action="" method="post">
<div id="color-picker" class="<?php echo !$currentStatus ? 'hidden' : ''; ?>"></div>
<div class="border thin <?php echo !$currentStatus ? 'hidden' : ''; ?>">
<input name="colour" id="color" size="7" type="text" class="colourCode" value=""/>
</div>
<div <?php echo !$currentStatus ? 'class="hidden"' : ''; ?>>
<h2 class="border">Actions</h2>
</div>
<div <?php echo !$currentStatus ? ' class="hidden"' : ''; ?>>
<input name="submit" type="submit" class="large button green" value="Change Colour"/>
</div>
<div <?php echo !$currentStatus ? 'class="hidden"' : ''; ?>>
<?php
if ($currentStatus && count($currentCommands) > 0) {
echo '<input name="submit" type="submit" class="large button orange" value="Clear"/>';
}
?>
</div>
<div <?php echo !$currentStatus ? 'class="hidden"' : ''; ?>>
<?php
if ($currentStatus && count($currentCommands) > 1) {
echo '<input name="submit" type="submit" class="large button orange" value="Clear All"/>';
}
?>
</div>
<div <?php echo !$currentStatus ? ' class="hidden"' : ''; ?>>
<button id="effect-switch" class="large button blue"><?php echo isset($_POST['effect']) && !$_POST['effect'] || !isset($_POST['effect']) ? ' Effects' : 'Close Effects'; ?></button>
</div>
<div id="effect-display" class="<?php echo isset($_POST['effect']) && !$_POST['effect'] || !isset($_POST['effect']) ? ' hidden' : ''; ?>">
<input type="hidden" name="effect" id="effect" value="" />
<?php
if ($currentEffects) {
foreach ($currentEffects as $key => $value) {
echo '<div>
<input name="submit" type="submit" class="large button effect" value="' . $value . '"/>
</div>';
}
} else {
echo '<p>No effects to display.</p>';
}
?>
</div>
<?php
if (!$config['overwriteStatus']) {
?>
<div class="border thin">
<?php
if ($currentStatus) {
echo '<input name="submit" type="submit" class="large button red" value="Turn Off" />';
} else {
echo '<input name="submit" type="submit" class="large button green" value="Turn On" />';
}
?>
</div>
<?php
}
?>
<div <?php echo !$currentStatus ? 'class="hidden"' : ''; ?>>
<h2 class="border">Options</h2>
</div>
<div id="priority-holder" class="border thin<?php echo !$currentStatus ? ' hidden' : ''; ?>">
<input type="hidden" id="priority" name="priority" value="<?php echo !empty($_SESSION['priority']) ? key($_SESSION['priority']) : 500; ?>" />
<div id="priority-slider-display"><strong>Priority:</strong> <span><?php echo !empty($_SESSION['priority']) ? key($_SESSION['priority']) : 500; ?></span></div>
<div id="priority-slider"></div>
</div>
<div id="duration-holder" class="border thin <?php echo !$currentStatus ? ' hidden' : ''; ?>">
<input type="hidden" id="duration" name="duration" value="<?php echo !empty($_SESSION['duration']) ? $_SESSION['duration'] : -1; ?>" />
<div id="duration-slider-display"><strong>Duration:</strong> <span>Infinity</span></div>
<div id="duration-slider"></div>
</div>
</form>
</div>
</div>
<?php
if ($messages && $config['messageDisplay']) {
foreach ($messages as $message) {
echo '<div class="alert alert-' . $message['type'] . '">' . $message['content'] . '</div>';
}
$messages = array();
}
?>
<div align="center" id="footer">
<a href="https://github.com/tvdzwan/hyperion/wiki">Hyperion Team</a><br/>
(original version by <a href="http://twitter.com/_nadnerb">@_nadnerb</a>)<br/>
(refactored by <a href="http://twitter.com/BradCornford">@BradCornford</a>)
</div>
</body>
<script type="text/javascript" src="colourPicker/js/jquery.js"></script>
<script type="text/javascript" src="colourPicker/js/jquery-ui.js"></script>
<script type="text/javascript" src="colourPicker/js/jquery-ui-touch-punch.js"></script>
<script type="text/javascript" src="colourPicker/js/farbtastic.js"></script>
<script type="text/javascript" src="colourPicker/js/general.js"></script>
<script language="JavaScript" type="text/javascript">
var currentColour="<?php echo $_SESSION['colour']; ?>";
var currentPriority="<?php echo !empty($_SESSION['priority']) ? key($_SESSION['priority']) : 500; ?>";
var currentDuration="<?php echo $_SESSION['duration']; ?>";
</script>
</html>