/
IPSScript.class.php
133 lines (121 loc) · 2.47 KB
/
IPSScript.class.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
<?
/**
* Script class
*
* This class creates and configures ips scripts and manages them
*
* @link https://github.com/florianprobst/ips-library project website
*
* @author Florian Probst <florian.probst@gmx.de>
*
* @license GNU
* GNU General Public License, version 3
*/
/**
* class IPSScript
*/
class IPSScript{
/**
* ips instance id of the script
*
* @var int
* @access private
*/
protected $id;
/**
* name of the script
*
* @var string
* @access private
*/
protected $name;
/**
* id of the scripts parent
* this defines where the script will be created
*
* @var int
* @access private
*/
protected $parentId;
/**
* debug information
* enables debug information for this class
*
* @var boolean
* @access private
*/
private $debug;
/**
* constructor
*
* @throws Exception if $type is not valid
* @access public
*/
public function __construct($parentId, $name, $content, $debug = false){
$this->parentId = $parentId;
$this->name = $name;
$this->content = $content;
$this->debug = $debug;
$this->id = @IPS_GetScriptIDByName($this->name, $this->parentId);
//check if event does already exist
if($this->id == false){
if($this->debug) echo "INFO - create IPS script $name\n";
$this->id = IPS_CreateScript(0);
IPS_SetName($this->id, $this->name);
IPS_SetParent($this->id, $this->parentId);
IPS_SetScriptContent($this->id, $this->content);
IPS_SetInfo($this->id, "this script was created by script " . $_IPS['SELF'] . " which is part of the ips-library (https://github.com/florianprobst/ips-library)");
}
}
/**
* getInstanceId
*
* @return integer scripts instance id
* @access public
*/
public function getInstanceId(){
return $this->id;
}
/**
* getName
*
* @return $string script name
* @access public
*/
public function getName(){
return $this->name;
}
/**
* setScriptTimer
* calls this script every $seconds while 0 disables it
*
* @param integer $seconds must be smaller 3600
* @access public
*/
public function setScriptTimer($seconds)
{
if($seconds < 0 || $seconds >= 3600){
throw new Exception("Parameter \$seconds is only valid with 0 - 3599");
}
return IPS_SetScriptTimer($this->id, $seconds);
}
/**
* disable
* disables this scripts timer
*
* @access public
*/
public function disableScriptTimer(){
return IPS_SetScriptTimer($this->id, 0);
}
/**
* delete
* deletes this script
*
* @access public
*/
public function delete(){
return IPS_DeleteScript($this->id, true);
}
}
?>