1 | <? |
---|
2 | |
---|
3 | require('./conf/config.php'); |
---|
4 | |
---|
5 | /******************************************************************************** |
---|
6 | * |
---|
7 | * addService($idService) |
---|
8 | * selectService($idService) |
---|
9 | * delService($idService) |
---|
10 | * addCMDService($idService, $command) |
---|
11 | * selectCMDService($idService) |
---|
12 | * delCMDService($idService, $command) |
---|
13 | * |
---|
14 | * |
---|
15 | * |
---|
16 | ********************************************************************************/ |
---|
17 | |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | function addService($idService) { |
---|
22 | |
---|
23 | //connect DB |
---|
24 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
25 | if (!$link) { |
---|
26 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
27 | return $buffer; |
---|
28 | } |
---|
29 | |
---|
30 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
31 | if (!$db_selected) { |
---|
32 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | //Add service |
---|
37 | $sql = "INSERT INTO SERVICE VALUE('$idService');"; |
---|
38 | |
---|
39 | if (mysql_query($sql, $link)) { |
---|
40 | $buffer = 1 ; |
---|
41 | } else { |
---|
42 | $buffer = "CREATE SERVICE $idService: [FAILED] :" . mysql_error() ; |
---|
43 | } |
---|
44 | |
---|
45 | return $buffer; |
---|
46 | |
---|
47 | |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | function selectService($idService) { |
---|
53 | //connect DB |
---|
54 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
55 | if (!$link) { |
---|
56 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
57 | return $buffer; |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | $db_selected = mysql_select_db($GLOBALS['nameDB'], $link); |
---|
62 | if (!$db_selected) { |
---|
63 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
64 | } |
---|
65 | |
---|
66 | if (empty($idService)) { |
---|
67 | $sql = "SELECT * FROM SERVICE"; |
---|
68 | }else{ |
---|
69 | $sql = "SELECT * FROM SERVICE WHERE idService='$idService'; "; |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | if ($result = mysql_query($sql, $link)) { |
---|
74 | //test if $return is_array |
---|
75 | |
---|
76 | return $result ; |
---|
77 | |
---|
78 | } else { |
---|
79 | $buffer = "SELECT SERVICE $idService: [FAILED] :" . mysql_error() ; |
---|
80 | return $buffer ; |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | function delService($idService) { |
---|
91 | |
---|
92 | //connect DB |
---|
93 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
94 | if (!$link) { |
---|
95 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
96 | return $buffer; |
---|
97 | } |
---|
98 | |
---|
99 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
100 | if (!$db_selected) { |
---|
101 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
102 | } |
---|
103 | |
---|
104 | //del service from SERVICEUSER |
---|
105 | $sql = "DELETE FROM SERVICEUSER WHERE idService = '$idService';"; |
---|
106 | |
---|
107 | if (mysql_query($sql, $link)) { |
---|
108 | $buffer .= "DELETE SERVICE $idService FROM TABLE SERVICEUSER: [OK]<BR />"; |
---|
109 | } else { |
---|
110 | $buffer = "DELETE SERVICE $idService FROM TABLE SERVICEUSER: [FAILED] :" . mysql_error() ; |
---|
111 | return $buffer; |
---|
112 | } |
---|
113 | |
---|
114 | //del service from SERVICESWITCH |
---|
115 | $sql = "DELETE FROM SERVICESWITCH WHERE idService='$idService' ;"; |
---|
116 | |
---|
117 | if (mysql_query($sql, $link)) { |
---|
118 | $buffer = 1 ; |
---|
119 | }else{ |
---|
120 | $buffer = "DELETE SERVICE $idService FROM TABLE SERVICESWITCH : [FAILED] :" . mysql_error() ; |
---|
121 | return $buffer ; |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | |
---|
126 | //del service from CMDSERVICE |
---|
127 | $sql = "DELETE FROM CMDSERVICE WHERE idService = '$idService';"; |
---|
128 | |
---|
129 | if (mysql_query($sql, $link)) { |
---|
130 | $buffer .= "DELETE SERVICE $idService FROM TABLE CMDSERVICE: [OK]<BR />"; |
---|
131 | } else { |
---|
132 | $buffer = "DELETE SERVICE $idService FROM TABLE CMDSERVICE: [FAILED] :" . mysql_error() ; |
---|
133 | return $buffer; |
---|
134 | } |
---|
135 | |
---|
136 | //del service |
---|
137 | $sql = "DELETE FROM SERVICE WHERE idService='$idService';"; |
---|
138 | |
---|
139 | if (mysql_query($sql, $link)) { |
---|
140 | $buffer = "DELETE SERVICE $idService: [OK]<BR />"; |
---|
141 | } else { |
---|
142 | $buffer = "DELETE SERVICE $idService: [FAILED] :" . mysql_error() ; |
---|
143 | } |
---|
144 | |
---|
145 | return $buffer; |
---|
146 | |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | function addCMDService($idService, $command) { |
---|
151 | |
---|
152 | //connect DB |
---|
153 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
154 | if (!$link) { |
---|
155 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
156 | return $buffer; |
---|
157 | } |
---|
158 | |
---|
159 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
160 | if (!$db_selected) { |
---|
161 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
162 | } |
---|
163 | |
---|
164 | |
---|
165 | |
---|
166 | //Add command (right) for service |
---|
167 | $sql = "INSERT INTO CMDSERVICE VALUE('$command', '$idService');"; |
---|
168 | |
---|
169 | if (mysql_query($sql, $link)) { |
---|
170 | $buffer =1; |
---|
171 | } else { |
---|
172 | $buffer = "ADD COMMAND $command FOR SERVICE $idService: [FAILED] :" . mysql_error() ; |
---|
173 | } |
---|
174 | |
---|
175 | return $buffer; |
---|
176 | } |
---|
177 | |
---|
178 | |
---|
179 | function selectCMDService($idService, $idPower) { |
---|
180 | |
---|
181 | //connect DB |
---|
182 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
183 | if (!$link) { |
---|
184 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
185 | return $buffer; |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
190 | if (!$db_selected) { |
---|
191 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
192 | } |
---|
193 | |
---|
194 | |
---|
195 | if (empty($idService) && empty($idPower) ) { |
---|
196 | $sql = "SELECT * FROM CMDSERVICE"; |
---|
197 | }else{ |
---|
198 | if ( !empty($idService) && empty($idPower) ) { |
---|
199 | |
---|
200 | $sql = "SELECT * FROM CMDSERVICE WHERE idService='$idService'; "; |
---|
201 | }else{ |
---|
202 | if ( empty($idService) && !empty($idPower) ) { |
---|
203 | $sql = "SELECT * FROM CMDSERVICE WHERE idPower='$idPower'; "; |
---|
204 | }else{ |
---|
205 | $sql = "SELECT * FROM CMDSERVICE WHERE idService='$idService' AND idPower='$idPower'; "; |
---|
206 | } |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | |
---|
211 | if ($result = mysql_query($sql, $link)) { |
---|
212 | //test if $return is_array |
---|
213 | return $result ; |
---|
214 | |
---|
215 | } else { |
---|
216 | $buffer = "SELECT SERVICE $idService: [FAILED] :" . mysql_error() ; |
---|
217 | return $buffer ; |
---|
218 | } |
---|
219 | |
---|
220 | } |
---|
221 | |
---|
222 | |
---|
223 | |
---|
224 | function delCMDService($idService, $command) { |
---|
225 | |
---|
226 | //connect DB |
---|
227 | $link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']); |
---|
228 | if (!$link) { |
---|
229 | $buffer = "Connexion [FAILED]: " . mysql_error() ; |
---|
230 | return $buffer; |
---|
231 | } |
---|
232 | |
---|
233 | |
---|
234 | $db_selected = @mysql_select_db($GLOBALS['nameDB'], $link); |
---|
235 | if (!$db_selected) { |
---|
236 | $buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error(); |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | //del command (right) for service |
---|
241 | $sql = "DELETE FROM CMDSERVICE WHERE idService='$idService' |
---|
242 | AND idPower='$command';"; |
---|
243 | |
---|
244 | if (mysql_query($sql, $link)) { |
---|
245 | $buffer = 1; |
---|
246 | } else { |
---|
247 | $buffer = "DELETE COMMAND $command FOR SERVICE $idService: [FAILED] :" . mysql_error() ; |
---|
248 | } |
---|
249 | |
---|
250 | return $buffer; |
---|
251 | } |
---|
252 | |
---|
253 | |
---|
254 | |
---|
255 | ?> |
---|