-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.php
45 lines (43 loc) · 1.49 KB
/
ajax.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
<?php
header("Content-type: text/html; charset=utf-8");
require_once 'HTTP/OAuth/Consumer.php';
require_once 'config/main.php';
//get url parameter and include right file.
$parameter = isset($_GET['p'])?$_GET['p']:'';
//session_destroy();
$parameters = explode('/',$parameter);
$account = new account();
if(!$account->authenticated)
{
die();
}
/* AJAX callback pages */
switch($parameters[0])
{
case 'current':
$account->initTelldusData();
$current = array(
'tubTemp' => isset($account->telldusData->data['tubTemp']) ? $account->telldusData->data['tubTemp'] : false,
'tubStateOn' => isset($account->telldusData->data['tubStateOn']) ? $account->telldusData->data['tubStateOn'] : null,
'airTemp' => isset($account->telldusData->data['airTemp']) ? $account->telldusData->data['airTemp'] : false,
'lastChecked' => date("H:i", $account->telldusData->data['tubLastChecked']),
'lastCheckedRecently' => $account->telldusData->data['tubLastCheckedRecently'],
);
echo json_encode($current);
break;
case 'turn-on':
$account->initTelldusData();
$account->initTelldusData();
$deviceId = $account->settings['tubDeviceId']['value'];
$account->telldusData->turnOnDevice($deviceId);
echo json_encode(true);
break;
case 'turn-off':
$account->initTelldusData();
$account->initTelldusData();
$deviceId = $account->settings['tubDeviceId']['value'];
$account->telldusData->turnOffDevice($deviceId);
echo json_encode(true);
break;
}
?>