-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.php
90 lines (72 loc) · 2.15 KB
/
state.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
<?php
/*
Version: 1.1
Author: xopr
Date: 2015-07-06
*/
const STR_OPEN = "Open";
const STR_CLOSED = "Closed";
const STR_UNKNOWN = "Unknown";
class state
{
public function updateSpaceApi( $_spaceAPI )
{
global $stateAbstraction;
$apiPart = Array();
/*
$apiPart["trigger_person"] = "Herman ACKer";
*/
/*
//$apiPart["lastchange"] = $stateAbstraction->getStateChangedTimestamp();
//$apiPart["message"] = "open";
*/
$state = $stateAbstraction->getState();
$description = $stateAbstraction->getStateDescription( $state[ "state" ] );
switch( $state[ "state" ] )
{
case "-2":
case "0":
// Closed
$apiPart["open"] = false; // Mandatory
$apiPart["message"] = STR_CLOSED;
break;
case "-1":
case "1":
// Open
$apiPart["open"] = true; // Mandatory
$apiPart["message"] = STR_OPEN;
break;
case "2":
// Unknown
$apiPart["open"] = null; // Mandatory
$apiPart["message"] = STR_UNKNOWN;
break;
}
if ( !is_null( $description ) )
$apiPart["message"] = $description;
$apiPart["lastchange"] = (int)$state[ "created" ];
$apiPart["icon"]["open"] = "https://ackspace.nl/icon/open.png";
$apiPart["icon"]["closed"] = "https://ackspace.nl/icon/closed.png";
return $apiPart;
}
public function updateDatabase( )
{
global $stateAbstraction;
// Store the IP of the client that triggers the state change
// NOTE: depending on the connection, we might want to use HTTP_X_FORWARDED_FOR as well
$ip = $_SERVER['REMOTE_ADDR'];
file_put_contents( "ip.txt", $ip);
// Read the state parameter
switch ( getVar( "state" ) )
{
case "-2":
case "-1":
case "0":
case "1":
return $stateAbstraction->updateState( (int)getVar( "state" ) );
}
// State not handled correctly
return false;
}
}
?>