Passed
Push — master ( e80252...a999dd )
by Nikolay
32:05 queued 14:50
created
etc/asterisk/agi-bin/cdr_connector.php 3 patches
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -18,12 +18,12 @@  discard block
 block discarded – undo
18 18
  * @return array
19 19
  */
20 20
 function Event_dial($agi, $action){
21
-	$now = Util::get_now_date();
21
+    $now = Util::get_now_date();
22 22
     $data = array();
23 23
 	
24
-	// Уточним канал, на случай очереди.
24
+    // Уточним канал, на случай очереди.
25 25
     $QUEUE_SRC_CHAN = $agi->get_variable("QUEUE_SRC_CHAN", true);
26
-	$orign_chan     = $agi->get_variable("orign_chan",     true);
26
+    $orign_chan     = $agi->get_variable("orign_chan",     true);
27 27
     $id   	        = $agi->get_variable("pt1c_UNIQUEID",  true);
28 28
     $IS_ORGNT   	= $agi->get_variable("IS_ORGNT",       true);
29 29
     if($id == '' || !empty($QUEUE_SRC_CHAN)){
@@ -31,13 +31,13 @@  discard block
 block discarded – undo
31 31
         // Если это новый вызов $id == ''.
32 32
         $id   = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
33 33
     }
34
-	// Канал, AGI скрипта.
35
-	$channel 		= $agi->request['agi_channel'];
34
+    // Канал, AGI скрипта.
35
+    $channel 		= $agi->request['agi_channel'];
36 36
     $is_local       = !(stripos($channel, 'local/') === false);
37
-	if($QUEUE_SRC_CHAN != '' && $is_local){
38
-		// Это LOCAL, Переопределим на исходный. 
39
-		$channel = $QUEUE_SRC_CHAN;
40
-	}else if($is_local && (stripos($orign_chan, 'local/') === false)){
37
+    if($QUEUE_SRC_CHAN != '' && $is_local){
38
+        // Это LOCAL, Переопределим на исходный. 
39
+        $channel = $QUEUE_SRC_CHAN;
40
+    }else if($is_local && (stripos($orign_chan, 'local/') === false)){
41 41
         $channel = $orign_chan;
42 42
     }
43 43
 
@@ -68,20 +68,20 @@  discard block
 block discarded – undo
68 68
         $dst_num  	 = $agi->request['agi_extension'];
69 69
     }
70 70
 
71
-	$data['src_chan'] 	 = $channel;
72
-	$data['src_num']  	 = $src_num;
73
-	$data['dst_num']  	 = $dst_num;
74
-	$data['start']  	 = $now;
75
-	$data['linkedid']  	 = $agi->get_variable("CDR(linkedid)", true);
76
-	$data['UNIQUEID']  	 = $id;
77
-	$data['transfer']  	 = '0';
78
-	$data['agi_channel'] = $agi->request['agi_channel'];;
79
-	$data['did']		 = $agi->get_variable("FROM_DID",  true);
80
-	$data['from_account']= $from_account;
81
-	$data['IS_ORGNT']    = !empty($IS_ORGNT);
82
-
83
- 	$agi->set_variable("__pt1c_UNIQUEID", "$id");		
84
-	return $data;
71
+    $data['src_chan'] 	 = $channel;
72
+    $data['src_num']  	 = $src_num;
73
+    $data['dst_num']  	 = $dst_num;
74
+    $data['start']  	 = $now;
75
+    $data['linkedid']  	 = $agi->get_variable("CDR(linkedid)", true);
76
+    $data['UNIQUEID']  	 = $id;
77
+    $data['transfer']  	 = '0';
78
+    $data['agi_channel'] = $agi->request['agi_channel'];;
79
+    $data['did']		 = $agi->get_variable("FROM_DID",  true);
80
+    $data['from_account']= $from_account;
81
+    $data['IS_ORGNT']    = !empty($IS_ORGNT);
82
+
83
+        $agi->set_variable("__pt1c_UNIQUEID", "$id");		
84
+    return $data;
85 85
 }
86 86
 
87 87
 /**
@@ -92,17 +92,17 @@  discard block
 block discarded – undo
92 92
  */
93 93
 function Event_dial_create_chan($agi, $action){
94 94
     $now = Util::get_now_date();
95
-	$data 	    = [];
96
-	$id   	    = $agi->get_variable("pt1c_UNIQUEID", true);
97
-	$data['action']  	 = "$action";
98
-	$data['dst_chan']	 = $agi->request['agi_channel'];
99
-	$data['UNIQUEID']	 = $id;
100
-	$data['linkedid']  	 = $agi->get_variable("CDR(linkedid)", true);
95
+    $data 	    = [];
96
+    $id   	    = $agi->get_variable("pt1c_UNIQUEID", true);
97
+    $data['action']  	 = "$action";
98
+    $data['dst_chan']	 = $agi->request['agi_channel'];
99
+    $data['UNIQUEID']	 = $id;
100
+    $data['linkedid']  	 = $agi->get_variable("CDR(linkedid)", true);
101 101
     $data['event_time']  = $now;
102 102
 
103
-	if( stripos($data['dst_chan'], 'local/') === false ){
103
+    if( stripos($data['dst_chan'], 'local/') === false ){
104 104
         $data['to_account']  	= $agi->get_variable('CUT(CUT(CHANNEL(name),,1),/,2)', true);
105
-	}
105
+    }
106 106
 
107 107
     $IS_ORGNT   = $agi->get_variable("IS_ORGNT",       true);
108 108
     if(!empty($IS_ORGNT)){
@@ -128,16 +128,16 @@  discard block
 block discarded – undo
128 128
 function Event_dial_answer($agi, $action){
129 129
     $now = Util::get_now_date();
130 130
 
131
-	$id   = $agi->get_variable("pt1c_UNIQUEID", true);
132
-	$data = [];
133
-	$data['action']  	= "$action";
134
-	$data['answer']  	= $now;
135
-	$data['id'] 		= $id;
131
+    $id   = $agi->get_variable("pt1c_UNIQUEID", true);
132
+    $data = [];
133
+    $data['action']  	= "$action";
134
+    $data['answer']  	= $now;
135
+    $data['id'] 		= $id;
136 136
     $data['dst_num']	= $agi->request['agi_callerid'];
137
-	$data['agi_channel']= $agi->request['agi_channel'];
138
-	$data['linkedid']  	= $agi->get_variable("CDR(linkedid)", true);
137
+    $data['agi_channel']= $agi->request['agi_channel'];
138
+    $data['linkedid']  	= $agi->get_variable("CDR(linkedid)", true);
139 139
 
140
-	$data['ENDCALLONANSWER']= $agi->get_variable("ENDCALLONANSWER", true);
140
+    $data['ENDCALLONANSWER']= $agi->get_variable("ENDCALLONANSWER", true);
141 141
     $data['BRIDGEPEER']     = $agi->get_variable("FROM_CHAN", true);
142 142
 
143 143
     $IS_ORGNT   = $agi->get_variable("IS_ORGNT",       true);
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
     }
175 175
     $agi->set_variable("__pt1c_UNIQUEID", "$id");
176 176
 
177
-	return $data;
177
+    return $data;
178 178
 }
179 179
 
180 180
 /**
@@ -186,17 +186,17 @@  discard block
 block discarded – undo
186 186
 function Event_dial_hangup_DEPRECATED($agi, $action){
187 187
     // TODO Удалить эту функцию в будущем.
188 188
     $now    = Util::get_now_date();
189
-	$data 	= array();
190
-	$data['action']  	 = "$action";
191
-	$data['end']  		 = $now;
192
-	$data['id'] 		 = $agi->get_variable("pt1c_UNIQUEID", true);
193
-	$data['agi_channel'] = $agi->request['agi_channel'];
194
-	$data['linkedid']  	 = $agi->get_variable("CDR(linkedid)", true);
195
-	$data['did']		 = $agi->get_variable("FROM_DID", true);
189
+    $data 	= array();
190
+    $data['action']  	 = "$action";
191
+    $data['end']  		 = $now;
192
+    $data['id'] 		 = $agi->get_variable("pt1c_UNIQUEID", true);
193
+    $data['agi_channel'] = $agi->request['agi_channel'];
194
+    $data['linkedid']  	 = $agi->get_variable("CDR(linkedid)", true);
195
+    $data['did']		 = $agi->get_variable("FROM_DID", true);
196 196
 
197
-	$data['agi_threadid'] = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
197
+    $data['agi_threadid'] = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
198 198
 
199
-	return $data;
199
+    return $data;
200 200
 }
201 201
 
202 202
 /**
@@ -207,12 +207,12 @@  discard block
 block discarded – undo
207 207
  */
208 208
 function Event_transfer_dial($agi, $action){
209 209
     $now = Util::get_now_date();
210
-	$id   = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
210
+    $id   = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
211 211
 
212
-	// Пытаемся определить канал.
212
+    // Пытаемся определить канал.
213 213
     $TRANSFERERNAME = $agi->get_variable("TRANSFERERNAME", true);
214
-	$QUEUE_SRC_CHAN = $agi->get_variable("QUEUE_SRC_CHAN", true);
215
-	$is_local       = !(stripos($TRANSFERERNAME, 'local/') === false);
214
+    $QUEUE_SRC_CHAN = $agi->get_variable("QUEUE_SRC_CHAN", true);
215
+    $is_local       = !(stripos($TRANSFERERNAME, 'local/') === false);
216 216
     if( $QUEUE_SRC_CHAN != '' && $is_local ){
217 217
         // Это LOCAL, Переопределим на исходный.
218 218
         $channel = $QUEUE_SRC_CHAN;
@@ -225,21 +225,21 @@  discard block
 block discarded – undo
225 225
         $channel = $TRANSFERERNAME;
226 226
     }
227 227
 
228
-	$data   = array();
229
-	$data['action']  	= "$action";
230
-	$data['agi_channel']= $channel;// $agi->request['agi_channel'];
231
-	$data['linkedid']  	= $agi->get_variable("CDR(linkedid)", true);
232
-	$data['src_chan'] 	= $channel;
233
-	$data['did']		= $agi->get_variable("FROM_DID", true);;
234
-	$data['start']  	= $now;
235
-	$data['UNIQUEID']  	= $id;	
236
-	$data['transfer']  	= ($TRANSFERERNAME == '')?'0':'1';
237
-	$data['src_num']  	= $agi->request['agi_callerid'];
238
-	$data['dst_num']  	= $agi->request['agi_extension'];
228
+    $data   = array();
229
+    $data['action']  	= "$action";
230
+    $data['agi_channel']= $channel;// $agi->request['agi_channel'];
231
+    $data['linkedid']  	= $agi->get_variable("CDR(linkedid)", true);
232
+    $data['src_chan'] 	= $channel;
233
+    $data['did']		= $agi->get_variable("FROM_DID", true);;
234
+    $data['start']  	= $now;
235
+    $data['UNIQUEID']  	= $id;	
236
+    $data['transfer']  	= ($TRANSFERERNAME == '')?'0':'1';
237
+    $data['src_num']  	= $agi->request['agi_callerid'];
238
+    $data['dst_num']  	= $agi->request['agi_extension'];
239 239
 
240 240
     $agi->set_variable("__transfer_UNIQUEID", $id);
241 241
 
242
-	return $data;
242
+    return $data;
243 243
 }
244 244
 
245 245
 /**
@@ -249,14 +249,14 @@  discard block
 block discarded – undo
249 249
  * @return array
250 250
  */
251 251
 function Event_transfer_dial_create_chan($agi, $action){
252
-	$id  	= $agi->get_variable("transfer_UNIQUEID", true);
253
-	$data   = array();
254
-	$data['dst_chan'] 			= $agi->request['agi_channel'];
255
-	$data['transfer_UNIQUEID'] 	= "$id";
256
-	$data['action']  			= "$action";
257
-	$data['linkedid']  			= $agi->get_variable("CDR(linkedid)", true);
258
-
259
-	return $data;
252
+    $id  	= $agi->get_variable("transfer_UNIQUEID", true);
253
+    $data   = array();
254
+    $data['dst_chan'] 			= $agi->request['agi_channel'];
255
+    $data['transfer_UNIQUEID'] 	= "$id";
256
+    $data['action']  			= "$action";
257
+    $data['linkedid']  			= $agi->get_variable("CDR(linkedid)", true);
258
+
259
+    return $data;
260 260
 }
261 261
 
262 262
 /**
@@ -266,16 +266,16 @@  discard block
 block discarded – undo
266 266
  * @return array
267 267
  */
268 268
 function Event_transfer_dial_answer($agi, $action){
269
-	$data 	= array();
269
+    $data 	= array();
270 270
     $now    = Util::get_now_date();
271
-	$id   	= $agi->get_variable("transfer_UNIQUEID", true);
272
-	$data['answer'] 			= $now;
273
-	$data['transfer_UNIQUEID'] 	= "$id";
274
-	$data['action']  			= "$action";
275
-	$data['agi_channel']		= $agi->request['agi_channel'];
276
-	$data['linkedid']  			= $agi->get_variable("CDR(linkedid)", true);
277
-
278
-	return $data;
271
+    $id   	= $agi->get_variable("transfer_UNIQUEID", true);
272
+    $data['answer'] 			= $now;
273
+    $data['transfer_UNIQUEID'] 	= "$id";
274
+    $data['action']  			= "$action";
275
+    $data['agi_channel']		= $agi->request['agi_channel'];
276
+    $data['linkedid']  			= $agi->get_variable("CDR(linkedid)", true);
277
+
278
+    return $data;
279 279
 }
280 280
 
281 281
 /**
@@ -286,25 +286,25 @@  discard block
 block discarded – undo
286 286
  */
287 287
 function Event_transfer_dial_hangup($agi, $action){
288 288
     $now    = Util::get_now_date();
289
-	$data 	= array();
290
-	$data['end']  		  = $now;
291
-	$data['linkedid']  	  = $agi->get_variable("CDR(linkedid)", true);
292
-	$data['did']		  = $agi->get_variable("FROM_DID", true);;
293
-	$data['action']  	  = "$action";
294
-	$data['agi_channel']  = $agi->request['agi_channel'];
295
-	$data['agi_threadid'] = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
296
-
297
-	$pos = stripos( $data['agi_channel'], 'local/');
298
-	if($pos === false){
299
-		// Если это завершение переадресации (консультативной). Создадим новую строку CDR.
300
-	}else{
301
-		// Если пришел локальный канал:
302
-		$data['TRANSFERERNAME'] = $agi->get_variable("TRANSFERERNAME", 	true);
303
-		$data['ANSWEREDTIME'] 	= $agi->get_variable("ANSWEREDTIME", 	true);
304
-		$data['dst_chan'] 		= $agi->get_variable("CDR(dstchannel)", true);
305
-	}
306
-
307
-	return $data;
289
+    $data 	= array();
290
+    $data['end']  		  = $now;
291
+    $data['linkedid']  	  = $agi->get_variable("CDR(linkedid)", true);
292
+    $data['did']		  = $agi->get_variable("FROM_DID", true);;
293
+    $data['action']  	  = "$action";
294
+    $data['agi_channel']  = $agi->request['agi_channel'];
295
+    $data['agi_threadid'] = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
296
+
297
+    $pos = stripos( $data['agi_channel'], 'local/');
298
+    if($pos === false){
299
+        // Если это завершение переадресации (консультативной). Создадим новую строку CDR.
300
+    }else{
301
+        // Если пришел локальный канал:
302
+        $data['TRANSFERERNAME'] = $agi->get_variable("TRANSFERERNAME", 	true);
303
+        $data['ANSWEREDTIME'] 	= $agi->get_variable("ANSWEREDTIME", 	true);
304
+        $data['dst_chan'] 		= $agi->get_variable("CDR(dstchannel)", true);
305
+    }
306
+
307
+    return $data;
308 308
 }
309 309
 
310 310
 /**
@@ -315,23 +315,23 @@  discard block
 block discarded – undo
315 315
  */
316 316
 function Event_hangup_chan($agi, $action){
317 317
     $now    = Util::get_now_date();
318
-	$data 	= [];
318
+    $data 	= [];
319 319
     $data['action']  	    = "$action";
320 320
     $data['did']		    = $agi->get_variable("FROM_DID", true);;
321 321
     $data['agi_threadid'] = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
322 322
 
323
-	$data['linkedid']  	    = $agi->get_variable("CDR(linkedid)", true);
324
-	$data['dialstatus']     = $agi->get_variable("DIALSTATUS", true);
325
-	if('ANSWER' == $data['dialstatus']){
323
+    $data['linkedid']  	    = $agi->get_variable("CDR(linkedid)", true);
324
+    $data['dialstatus']     = $agi->get_variable("DIALSTATUS", true);
325
+    if('ANSWER' == $data['dialstatus']){
326 326
         $data['dialstatus'] = "ANSWERED";
327 327
     }
328
-	$data['agi_channel']    = $agi->request['agi_channel'];
329
-	$data['end']  		    = $now;
328
+    $data['agi_channel']    = $agi->request['agi_channel'];
329
+    $data['end']  		    = $now;
330 330
 
331 331
     $data['OLD_LINKEDID']   = $agi->get_variable("OLD_LINKEDID", true);
332 332
     $data['UNIQUEID']  	    = $agi->get_variable("pt1c_UNIQUEID", true);
333 333
 
334
-	return $data;
334
+    return $data;
335 335
 }
336 336
 
337 337
 /**
@@ -342,64 +342,64 @@  discard block
 block discarded – undo
342 342
  */
343 343
 function Event_unpark_call($agi, $action){
344 344
     $now    = Util::get_now_date();
345
-	// Обработка данных парковки. 
346
-	$exten	= $agi->get_variable("EXTEN", 	true);
347
-	$park_row = p_Park::get_parkslot_data($exten);
345
+    // Обработка данных парковки. 
346
+    $exten	= $agi->get_variable("EXTEN", 	true);
347
+    $park_row = p_Park::get_parkslot_data($exten);
348 348
 	
349
-	$agi->set_variable("__pt1c_IS_PARK", "1");		
350
-	$agi->set_variable("pt1c_PARK_CHAN", $park_row['ParkeeChannel']);
349
+    $agi->set_variable("__pt1c_IS_PARK", "1");		
350
+    $agi->set_variable("pt1c_PARK_CHAN", $park_row['ParkeeChannel']);
351 351
 	
352
-	// Сбор данных для генерации CDR.
353
-	$id   	= $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
354
-	$channel= $agi->request['agi_channel'];
355
- 	$agi->set_variable("__pt1c_UNIQUEID", "$id");		
356
-	$data 	= array();
357
-	$data['action']  	 = "$action";
358
-	$data['UNIQUEID']  	 = $id;
359
-	$data['linkedid_old']= $agi->get_variable("CDR(linkedid)", true);
360
-	$data['agi_channel'] = $channel;
361
-	$data['linkedid']  	 = $park_row['ParkeeLinkedid'];
362
-	$data['start']  	 = $now;
363
-	$data['transfer']  	 = '0';
364
-	$data['did']		 = $agi->get_variable("FROM_DID", true);
365
-	$data['answer']  	 = $data['start'];
352
+    // Сбор данных для генерации CDR.
353
+    $id   	= $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
354
+    $channel= $agi->request['agi_channel'];
355
+        $agi->set_variable("__pt1c_UNIQUEID", "$id");		
356
+    $data 	= array();
357
+    $data['action']  	 = "$action";
358
+    $data['UNIQUEID']  	 = $id;
359
+    $data['linkedid_old']= $agi->get_variable("CDR(linkedid)", true);
360
+    $data['agi_channel'] = $channel;
361
+    $data['linkedid']  	 = $park_row['ParkeeLinkedid'];
362
+    $data['start']  	 = $now;
363
+    $data['transfer']  	 = '0';
364
+    $data['did']		 = $agi->get_variable("FROM_DID", true);
365
+    $data['answer']  	 = $data['start'];
366 366
 	
367
-	if(null == $park_row){
368
-		$data['src_chan'] 	= $channel;
369
-		$data['src_num']  	= $agi->request['agi_callerid'];
370
-		$data['dst_num']  	= $agi->request['agi_extension'];
371
-		$data['dst_chan'] 	= 'Park:'.$agi->request['agi_extension'];
372
-	}else if(true == $park_row['pt1c_is_dst']){
373
-		$data['src_chan'] 	= $channel;
374
-		$data['dst_chan'] 	= $park_row['ParkeeChannel'];
375
-		$data['src_num']  	= $agi->request['agi_callerid'];
376
-		$data['dst_num']  	= $park_row['ParkeeCallerIDNum'];
377
-	}else{
378
-		$data['src_chan'] 	= $park_row['ParkeeChannel'];
379
-		$data['dst_chan'] 	= $channel;
380
-		$data['src_num']  	= $park_row['ParkeeCallerIDNum'];
381
-		$data['dst_num']  	= $agi->request['agi_callerid'];
382
-	}
367
+    if(null == $park_row){
368
+        $data['src_chan'] 	= $channel;
369
+        $data['src_num']  	= $agi->request['agi_callerid'];
370
+        $data['dst_num']  	= $agi->request['agi_extension'];
371
+        $data['dst_chan'] 	= 'Park:'.$agi->request['agi_extension'];
372
+    }else if(true == $park_row['pt1c_is_dst']){
373
+        $data['src_chan'] 	= $channel;
374
+        $data['dst_chan'] 	= $park_row['ParkeeChannel'];
375
+        $data['src_num']  	= $agi->request['agi_callerid'];
376
+        $data['dst_num']  	= $park_row['ParkeeCallerIDNum'];
377
+    }else{
378
+        $data['src_chan'] 	= $park_row['ParkeeChannel'];
379
+        $data['dst_chan'] 	= $channel;
380
+        $data['src_num']  	= $park_row['ParkeeCallerIDNum'];
381
+        $data['dst_num']  	= $agi->request['agi_callerid'];
382
+    }
383 383
 	
384
-	if(trim($park_row['ParkingDuration'])!=''){
385
-		$time_start = date("Y-m-d H:i:s", time() - 1*($park_row['ParkingDuration']) );
386
-		$data_parking = array(
387
-		    'UNIQUEID' => $id .'_'. Util::generateRandomString(3),
388
-			'src_chan' => $park_row['ParkeeChannel'],
389
-			'src_num'  => $park_row['ParkeeCallerIDNum'],
390
-			'dst_num'  => $park_row['ParkingSpace'],
391
-			'dst_chan' => 'Park:'.$park_row['ParkingSpace'],
392
-			'start'    => $time_start,
393
-			'answer'   => $time_start,
394
-			'endtime'  => $now,
395
-			'did'	   => $data['did'],
396
-			'transfer' => '0',
397
-			'linkedid' => $data['linkedid']
398
-		);
399
-		$data['data_parking'] = $data_parking;
400
-	}
401
-
402
-	return $data;	
384
+    if(trim($park_row['ParkingDuration'])!=''){
385
+        $time_start = date("Y-m-d H:i:s", time() - 1*($park_row['ParkingDuration']) );
386
+        $data_parking = array(
387
+            'UNIQUEID' => $id .'_'. Util::generateRandomString(3),
388
+            'src_chan' => $park_row['ParkeeChannel'],
389
+            'src_num'  => $park_row['ParkeeCallerIDNum'],
390
+            'dst_num'  => $park_row['ParkingSpace'],
391
+            'dst_chan' => 'Park:'.$park_row['ParkingSpace'],
392
+            'start'    => $time_start,
393
+            'answer'   => $time_start,
394
+            'endtime'  => $now,
395
+            'did'	   => $data['did'],
396
+            'transfer' => '0',
397
+            'linkedid' => $data['linkedid']
398
+        );
399
+        $data['data_parking'] = $data_parking;
400
+    }
401
+
402
+    return $data;	
403 403
 }
404 404
 
405 405
 /**
@@ -410,28 +410,28 @@  discard block
 block discarded – undo
410 410
  */
411 411
 function Event_unpark_call_timeout($agi, $action){
412 412
     $now  = Util::get_now_date();
413
-	$id   = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
414
-	// PARKER=SIP/206
415
-	$PARKING_DURATION = $agi->get_variable("PARKING_DURATION", true);
416
-	$PARKING_DURATION = ($PARKING_DURATION == '')?45:$PARKING_DURATION;
413
+    $id   = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
414
+    // PARKER=SIP/206
415
+    $PARKING_DURATION = $agi->get_variable("PARKING_DURATION", true);
416
+    $PARKING_DURATION = ($PARKING_DURATION == '')?45:$PARKING_DURATION;
417 417
 		
418
-	$time_start = date("Y-m-d H:i:s", time() - 1*($PARKING_DURATION));
419
-	$PARKING_SPACE = $agi->get_variable("PARKING_SPACE", true);
420
-	$data = array(
421
-		'action'   => "$action",
422
-		'src_chan' => $agi->request['agi_channel'], // $agi->get_variable("PARKER", true), // ???
423
-		'src_num'  => $agi->request['agi_callerid'],
424
-		'dst_num'  => $PARKING_SPACE,
425
-		'dst_chan' => 'Park:'.$PARKING_SPACE,
426
-		'start'    => $time_start,
427
-		'answer'   => $time_start,
428
-		'endtime'  => $now,
429
-		'did'	   => $agi->get_variable("FROM_DID", true),
430
-		'UNIQUEID' => $id,
431
-		'transfer' => '0',
432
-		'linkedid' => $agi->get_variable("CDR(linkedid)", true),
418
+    $time_start = date("Y-m-d H:i:s", time() - 1*($PARKING_DURATION));
419
+    $PARKING_SPACE = $agi->get_variable("PARKING_SPACE", true);
420
+    $data = array(
421
+        'action'   => "$action",
422
+        'src_chan' => $agi->request['agi_channel'], // $agi->get_variable("PARKER", true), // ???
423
+        'src_num'  => $agi->request['agi_callerid'],
424
+        'dst_num'  => $PARKING_SPACE,
425
+        'dst_chan' => 'Park:'.$PARKING_SPACE,
426
+        'start'    => $time_start,
427
+        'answer'   => $time_start,
428
+        'endtime'  => $now,
429
+        'did'	   => $agi->get_variable("FROM_DID", true),
430
+        'UNIQUEID' => $id,
431
+        'transfer' => '0',
432
+        'linkedid' => $agi->get_variable("CDR(linkedid)", true),
433 433
         'PARKER'   => $agi->get_variable("PARKER", true),
434
-	);
434
+    );
435 435
 
436 436
 
437 437
     $id2   = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
@@ -458,18 +458,18 @@  discard block
 block discarded – undo
458 458
     }
459 459
 
460 460
     $data = array(
461
-		'action'   => "$action",
462
-		// 'src_chan' => $agi->request['agi_channel'],
463
-		// 'src_num'  => $agi->request['agi_callerid'],
464
-		'dst_num'  => $agi->request['agi_extension'],
465
-		'dst_chan' => 'Queue:'.$agi->request['agi_extension'],
466
-		// 'answer'   => $time_start,
467
-		// 'end'  	   => $now,
468
-		'did'	   => $agi->get_variable("FROM_DID", true),
469
-		'is_app' => '1',
470
-		'UNIQUEID' => $id,
471
-		'linkedid' => $agi->get_variable("CDR(linkedid)", true)
472
-	);
461
+        'action'   => "$action",
462
+        // 'src_chan' => $agi->request['agi_channel'],
463
+        // 'src_num'  => $agi->request['agi_callerid'],
464
+        'dst_num'  => $agi->request['agi_extension'],
465
+        'dst_chan' => 'Queue:'.$agi->request['agi_extension'],
466
+        // 'answer'   => $time_start,
467
+        // 'end'  	   => $now,
468
+        'did'	   => $agi->get_variable("FROM_DID", true),
469
+        'is_app' => '1',
470
+        'UNIQUEID' => $id,
471
+        'linkedid' => $agi->get_variable("CDR(linkedid)", true)
472
+    );
473 473
     if(!empty($time_start)){
474 474
         $data['src_chan'] = $agi->get_variable("QUEUE_SRC_CHAN", true);
475 475
         $data['src_num']  = $agi->request['agi_callerid'];
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
         $data['transfer']  	= '0';
485 485
     }
486 486
 
487
-	return $data;	
487
+    return $data;	
488 488
 }
489 489
 
490 490
 /**
@@ -495,15 +495,15 @@  discard block
 block discarded – undo
495 495
  */
496 496
 function Event_queue_answer($agi, $action){
497 497
     $now  = Util::get_now_date();
498
-	$id   = $agi->get_variable("pt1c_q_UNIQUEID", true);
499
-	$data = array();
500
-	$data['action']  	= "$action";
501
-	$data['answer']  	= $now;
502
-	$data['id'] 		= $id;
503
-	$data['agi_channel']= $agi->request['agi_channel'];
504
-	$data['linkedid']  	= $agi->get_variable("CDR(linkedid)", true);
505
-
506
-	return $data;	
498
+    $id   = $agi->get_variable("pt1c_q_UNIQUEID", true);
499
+    $data = array();
500
+    $data['action']  	= "$action";
501
+    $data['answer']  	= $now;
502
+    $data['id'] 		= $id;
503
+    $data['agi_channel']= $agi->request['agi_channel'];
504
+    $data['linkedid']  	= $agi->get_variable("CDR(linkedid)", true);
505
+
506
+    return $data;	
507 507
 }
508 508
 
509 509
 /**
@@ -514,16 +514,16 @@  discard block
 block discarded – undo
514 514
  */
515 515
 function Event_queue_end($agi, $action){
516 516
     $now  = Util::get_now_date();
517
-	$id   = $agi->get_variable("pt1c_q_UNIQUEID", true);
518
-	$data = array();
519
-	$data['action']  	= "$action";
520
-	$data['end']  		= $now;
521
-	$data['id'] 		= $id;
522
-	$data['dialstatus'] = $agi->get_variable("QUEUESTATUS", true);
523
-	$data['agi_channel']= $agi->request['agi_channel'];
524
-	$data['linkedid']  	= $agi->get_variable("CDR(linkedid)", true);
525
-
526
-	return $data;	
517
+    $id   = $agi->get_variable("pt1c_q_UNIQUEID", true);
518
+    $data = array();
519
+    $data['action']  	= "$action";
520
+    $data['end']  		= $now;
521
+    $data['id'] 		= $id;
522
+    $data['dialstatus'] = $agi->get_variable("QUEUESTATUS", true);
523
+    $data['agi_channel']= $agi->request['agi_channel'];
524
+    $data['linkedid']  	= $agi->get_variable("CDR(linkedid)", true);
525
+
526
+    return $data;	
527 527
 }
528 528
 
529 529
 /**
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 if( function_exists($func_name) ){
673 673
     $agi = new AGI();
674 674
     // Сбор сведений по каналу.
675
-	$result = $func_name($agi, $action);
675
+    $result = $func_name($agi, $action);
676 676
     // Оповещение без задержек.
677 677
     $data = base64_encode(json_encode($result));
678 678
     $agi->exec("UserEvent", "CdrConnector,AgiData:".base64_encode(json_encode($result)));
Please login to merge, or discard this patch.
Spacing   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -17,53 +17,53 @@  discard block
 block discarded – undo
17 17
  * @param string $action
18 18
  * @return array
19 19
  */
20
-function Event_dial($agi, $action){
20
+function Event_dial($agi, $action) {
21 21
 	$now = Util::get_now_date();
22 22
     $data = array();
23 23
 	
24 24
 	// Уточним канал, на случай очереди.
25 25
     $QUEUE_SRC_CHAN = $agi->get_variable("QUEUE_SRC_CHAN", true);
26
-	$orign_chan     = $agi->get_variable("orign_chan",     true);
27
-    $id   	        = $agi->get_variable("pt1c_UNIQUEID",  true);
28
-    $IS_ORGNT   	= $agi->get_variable("IS_ORGNT",       true);
29
-    if($id == '' || !empty($QUEUE_SRC_CHAN)){
26
+	$orign_chan     = $agi->get_variable("orign_chan", true);
27
+    $id = $agi->get_variable("pt1c_UNIQUEID", true);
28
+    $IS_ORGNT   	= $agi->get_variable("IS_ORGNT", true);
29
+    if ($id == '' || !empty($QUEUE_SRC_CHAN)) {
30 30
         // Если это вызов на агента очереди !empty($QUEUE_SRC_CHAN).
31 31
         // Если это новый вызов $id == ''.
32
-        $id   = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
32
+        $id = $agi->request['agi_uniqueid'].'_'.Util::generateRandomString();
33 33
     }
34 34
 	// Канал, AGI скрипта.
35
-	$channel 		= $agi->request['agi_channel'];
36
-    $is_local       = !(stripos($channel, 'local/') === false);
37
-	if($QUEUE_SRC_CHAN != '' && $is_local){
35
+	$channel = $agi->request['agi_channel'];
36
+    $is_local = !(stripos($channel, 'local/') === false);
37
+	if ($QUEUE_SRC_CHAN != '' && $is_local) {
38 38
 		// Это LOCAL, Переопределим на исходный. 
39 39
 		$channel = $QUEUE_SRC_CHAN;
40
-	}else if($is_local && (stripos($orign_chan, 'local/') === false)){
40
+	} else if ($is_local && (stripos($orign_chan, 'local/') === false)) {
41 41
         $channel = $orign_chan;
42 42
     }
43 43
 
44 44
     // Получим ID исходного канала.
45 45
     $from_account = $agi->get_variable("FROM_PEER", true);
46
-    if( $from_account == '' && stripos($agi->request['agi_channel'], 'local/') === false ){
47
-        $from_account  	= $agi->get_variable('CUT(CUT(CHANNEL(name),,1),/,2)', true);
46
+    if ($from_account == '' && stripos($agi->request['agi_channel'], 'local/') === false) {
47
+        $from_account = $agi->get_variable('CUT(CUT(CHANNEL(name),,1),/,2)', true);
48 48
     }
49 49
 
50
-    $data['action']  	 = "$action";
51
-    if(!empty($IS_ORGNT)){
50
+    $data['action'] = "$action";
51
+    if (!empty($IS_ORGNT)) {
52 52
         $dst_num  	        = $agi->request['agi_callerid'];
53 53
         $src_num  	        = $agi->request['agi_extension'];
54 54
         $data['dialstatus'] = 'ORIGINATE';
55
-        $from_account='';
55
+        $from_account = '';
56 56
 
57
-        $p_start = strpos($agi->request['agi_channel'],'/')+1;
58
-        $p_end   = strpos($agi->request['agi_channel'],'@') - $p_start;
57
+        $p_start = strpos($agi->request['agi_channel'], '/') + 1;
58
+        $p_end   = strpos($agi->request['agi_channel'], '@') - $p_start;
59 59
         $num     = substr($agi->request['agi_channel'], $p_start, $p_end);
60 60
 
61
-        $p_start = strpos($agi->request['agi_channel'],';');
62
-        $dst_chan= substr($agi->request['agi_channel'], 0, $p_start).';1';
61
+        $p_start = strpos($agi->request['agi_channel'], ';');
62
+        $dst_chan = substr($agi->request['agi_channel'], 0, $p_start).';1';
63 63
 
64
-        $id   = substr($agi->request['agi_uniqueid'],0, 16) .'_'.$num.'_'. $IS_ORGNT;
65
-        $data['dst_chan'] 	 = $dst_chan;
66
-    }else{
64
+        $id = substr($agi->request['agi_uniqueid'], 0, 16).'_'.$num.'_'.$IS_ORGNT;
65
+        $data['dst_chan'] = $dst_chan;
66
+    } else {
67 67
         $src_num  	 = $agi->request['agi_callerid'];
68 68
         $dst_num  	 = $agi->request['agi_extension'];
69 69
     }
@@ -71,13 +71,13 @@  discard block
 block discarded – undo
71 71
 	$data['src_chan'] 	 = $channel;
72 72
 	$data['src_num']  	 = $src_num;
73 73
 	$data['dst_num']  	 = $dst_num;
74
-	$data['start']  	 = $now;
74
+	$data['start'] = $now;
75 75
 	$data['linkedid']  	 = $agi->get_variable("CDR(linkedid)", true);
76 76
 	$data['UNIQUEID']  	 = $id;
77 77
 	$data['transfer']  	 = '0';
78
-	$data['agi_channel'] = $agi->request['agi_channel'];;
79
-	$data['did']		 = $agi->get_variable("FROM_DID",  true);
80
-	$data['from_account']= $from_account;
78
+	$data['agi_channel'] = $agi->request['agi_channel']; ;
79
+	$data['did'] = $agi->get_variable("FROM_DID", true);
80
+	$data['from_account'] = $from_account;
81 81
 	$data['IS_ORGNT']    = !empty($IS_ORGNT);
82 82
 
83 83
  	$agi->set_variable("__pt1c_UNIQUEID", "$id");		
@@ -90,28 +90,28 @@  discard block
 block discarded – undo
90 90
  * @param string $action
91 91
  * @return array
92 92
  */
93
-function Event_dial_create_chan($agi, $action){
93
+function Event_dial_create_chan($agi, $action) {
94 94
     $now = Util::get_now_date();
95 95
 	$data 	    = [];
96 96
 	$id   	    = $agi->get_variable("pt1c_UNIQUEID", true);
97 97
 	$data['action']  	 = "$action";
98 98
 	$data['dst_chan']	 = $agi->request['agi_channel'];
99 99
 	$data['UNIQUEID']	 = $id;
100
-	$data['linkedid']  	 = $agi->get_variable("CDR(linkedid)", true);
101
-    $data['event_time']  = $now;
100
+	$data['linkedid'] = $agi->get_variable("CDR(linkedid)", true);
101
+    $data['event_time'] = $now;
102 102
 
103
-	if( stripos($data['dst_chan'], 'local/') === false ){
104
-        $data['to_account']  	= $agi->get_variable('CUT(CUT(CHANNEL(name),,1),/,2)', true);
103
+	if (stripos($data['dst_chan'], 'local/') === false) {
104
+        $data['to_account'] = $agi->get_variable('CUT(CUT(CHANNEL(name),,1),/,2)', true);
105 105
 	}
106 106
 
107
-    $IS_ORGNT   = $agi->get_variable("IS_ORGNT",       true);
108
-    if(!empty($IS_ORGNT)){
107
+    $IS_ORGNT = $agi->get_variable("IS_ORGNT", true);
108
+    if (!empty($IS_ORGNT)) {
109 109
         // Вероятно необходимо переопределить искать по двум ID.
110 110
         // Применимо только для Originate, когда в качестве звонящего используем два канала
111 111
         // мобильный и внутренний номер.
112
-        $peer_mobile= $agi->get_variable("peer_mobile", true);
113
-        if( !empty($peer_mobile) && stripos($id, $peer_mobile) === false ) {
114
-            $id   = substr($agi->request['agi_uniqueid'],0, 16) .'_'.$peer_mobile.'_'. $IS_ORGNT;
112
+        $peer_mobile = $agi->get_variable("peer_mobile", true);
113
+        if (!empty($peer_mobile) && stripos($id, $peer_mobile) === false) {
114
+            $id = substr($agi->request['agi_uniqueid'], 0, 16).'_'.$peer_mobile.'_'.$IS_ORGNT;
115 115
             $data['org_id'] = $id;
116 116
         }
117 117
     }
@@ -125,52 +125,52 @@  discard block
 block discarded – undo
125 125
  * @param string $action
126 126
  * @return array
127 127
  */
128
-function Event_dial_answer($agi, $action){
128
+function Event_dial_answer($agi, $action) {
129 129
     $now = Util::get_now_date();
130 130
 
131 131
 	$id   = $agi->get_variable("pt1c_UNIQUEID", true);
132 132
 	$data = [];
133 133
 	$data['action']  	= "$action";
134 134
 	$data['answer']  	= $now;
135
-	$data['id'] 		= $id;
135
+	$data['id'] = $id;
136 136
     $data['dst_num']	= $agi->request['agi_callerid'];
137
-	$data['agi_channel']= $agi->request['agi_channel'];
137
+	$data['agi_channel'] = $agi->request['agi_channel'];
138 138
 	$data['linkedid']  	= $agi->get_variable("CDR(linkedid)", true);
139 139
 
140
-	$data['ENDCALLONANSWER']= $agi->get_variable("ENDCALLONANSWER", true);
141
-    $data['BRIDGEPEER']     = $agi->get_variable("FROM_CHAN", true);
140
+	$data['ENDCALLONANSWER'] = $agi->get_variable("ENDCALLONANSWER", true);
141
+    $data['BRIDGEPEER'] = $agi->get_variable("FROM_CHAN", true);
142 142
 
143
-    $IS_ORGNT   = $agi->get_variable("IS_ORGNT",       true);
144
-    if(!empty($IS_ORGNT)){
143
+    $IS_ORGNT = $agi->get_variable("IS_ORGNT", true);
144
+    if (!empty($IS_ORGNT)) {
145 145
         // Вероятно необходимо переопределить ID.
146 146
         // Применимо только для Originate, когда в качестве звонящего используем два канала
147 147
         // мобильный и внутренний номер.
148
-        $peer_mobile= $agi->get_variable("peer_mobile", true);
149
-        if( !empty($peer_mobile) && stripos($id, $peer_mobile) === false ) {
150
-            $id   = substr($agi->request['agi_uniqueid'],0, 16) .'_'.$peer_mobile.'_'. $IS_ORGNT;
148
+        $peer_mobile = $agi->get_variable("peer_mobile", true);
149
+        if (!empty($peer_mobile) && stripos($id, $peer_mobile) === false) {
150
+            $id = substr($agi->request['agi_uniqueid'], 0, 16).'_'.$peer_mobile.'_'.$IS_ORGNT;
151 151
             $data['org_id'] = $id;
152 152
         }
153 153
     }
154 154
 
155
-    if(!empty($data['ENDCALLONANSWER'])){
155
+    if (!empty($data['ENDCALLONANSWER'])) {
156 156
         $agi->set_variable("__ENDCALLONANSWER", "");
157 157
     }
158 158
 
159 159
     $PICKUPEER      = trim(''.$agi->get_variable("PICKUPEER", true));
160 160
     $data['dnid']   = $agi->request['agi_dnid'];
161 161
     $pickupexten = Config::get_pickupexten();
162
-    if('unknown' == $data['dnid'] && $PICKUPEER != ''){
162
+    if ('unknown' == $data['dnid'] && $PICKUPEER != '') {
163 163
         // Скорее всего ответ на вызов из 1С.
164 164
         $data['dnid']   = $pickupexten;
165
-    }elseif ($pickupexten == substr($data['dnid'], 0, 2) && $PICKUPEER != ''){
165
+    }elseif ($pickupexten == substr($data['dnid'], 0, 2) && $PICKUPEER != '') {
166 166
         // Это перехват при наборе номера *8XXX.
167 167
         $data['dnid']   = $pickupexten;
168 168
     }
169
-    if(trim($data['dnid']) == $pickupexten ) {
169
+    if (trim($data['dnid']) == $pickupexten) {
170 170
         // Очищаем переменную канала. Больше не требуется.
171 171
         $agi->set_variable("PICKUPEER", "");
172 172
         $data['old_id'] = $id;
173
-        $data['id'] 	= $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
173
+        $data['id'] = $agi->request['agi_uniqueid'].'_'.Util::generateRandomString();
174 174
     }
175 175
     $agi->set_variable("__pt1c_UNIQUEID", "$id");
176 176
 
@@ -183,18 +183,18 @@  discard block
 block discarded – undo
183 183
  * @param string $action
184 184
  * @return array
185 185
  */
186
-function Event_dial_hangup_DEPRECATED($agi, $action){
186
+function Event_dial_hangup_DEPRECATED($agi, $action) {
187 187
     // TODO Удалить эту функцию в будущем.
188
-    $now    = Util::get_now_date();
189
-	$data 	= array();
190
-	$data['action']  	 = "$action";
191
-	$data['end']  		 = $now;
188
+    $now = Util::get_now_date();
189
+	$data = array();
190
+	$data['action'] = "$action";
191
+	$data['end'] = $now;
192 192
 	$data['id'] 		 = $agi->get_variable("pt1c_UNIQUEID", true);
193 193
 	$data['agi_channel'] = $agi->request['agi_channel'];
194 194
 	$data['linkedid']  	 = $agi->get_variable("CDR(linkedid)", true);
195 195
 	$data['did']		 = $agi->get_variable("FROM_DID", true);
196 196
 
197
-	$data['agi_threadid'] = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
197
+	$data['agi_threadid'] = $agi->request['agi_uniqueid'].'_'.Util::generateRandomString();
198 198
 
199 199
 	return $data;
200 200
 }
@@ -205,35 +205,35 @@  discard block
 block discarded – undo
205 205
  * @param string $action
206 206
  * @return array
207 207
  */
208
-function Event_transfer_dial($agi, $action){
208
+function Event_transfer_dial($agi, $action) {
209 209
     $now = Util::get_now_date();
210
-	$id   = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
210
+	$id = $agi->request['agi_uniqueid'].'_'.Util::generateRandomString();
211 211
 
212 212
 	// Пытаемся определить канал.
213 213
     $TRANSFERERNAME = $agi->get_variable("TRANSFERERNAME", true);
214 214
 	$QUEUE_SRC_CHAN = $agi->get_variable("QUEUE_SRC_CHAN", true);
215 215
 	$is_local       = !(stripos($TRANSFERERNAME, 'local/') === false);
216
-    if( $QUEUE_SRC_CHAN != '' && $is_local ){
216
+    if ($QUEUE_SRC_CHAN != '' && $is_local) {
217 217
         // Это LOCAL, Переопределим на исходный.
218 218
         $channel = $QUEUE_SRC_CHAN;
219
-    }else if( $QUEUE_SRC_CHAN != '' && $TRANSFERERNAME == '' ){
219
+    } else if ($QUEUE_SRC_CHAN != '' && $TRANSFERERNAME == '') {
220 220
         // Это редирект на очередь.
221 221
         $channel = $QUEUE_SRC_CHAN;
222
-    }else if($TRANSFERERNAME == ''){
222
+    } else if ($TRANSFERERNAME == '') {
223 223
         $channel = $agi->request['agi_channel'];
224
-    }else{
224
+    } else {
225 225
         $channel = $TRANSFERERNAME;
226 226
     }
227 227
 
228
-	$data   = array();
229
-	$data['action']  	= "$action";
230
-	$data['agi_channel']= $channel;// $agi->request['agi_channel'];
228
+	$data = array();
229
+	$data['action'] = "$action";
230
+	$data['agi_channel'] = $channel; // $agi->request['agi_channel'];
231 231
 	$data['linkedid']  	= $agi->get_variable("CDR(linkedid)", true);
232
-	$data['src_chan'] 	= $channel;
233
-	$data['did']		= $agi->get_variable("FROM_DID", true);;
234
-	$data['start']  	= $now;
232
+	$data['src_chan'] = $channel;
233
+	$data['did'] = $agi->get_variable("FROM_DID", true); ;
234
+	$data['start'] = $now;
235 235
 	$data['UNIQUEID']  	= $id;	
236
-	$data['transfer']  	= ($TRANSFERERNAME == '')?'0':'1';
236
+	$data['transfer']  	= ($TRANSFERERNAME == '') ? '0' : '1';
237 237
 	$data['src_num']  	= $agi->request['agi_callerid'];
238 238
 	$data['dst_num']  	= $agi->request['agi_extension'];
239 239
 
@@ -248,13 +248,13 @@  discard block
 block discarded – undo
248 248
  * @param string $action
249 249
  * @return array
250 250
  */
251
-function Event_transfer_dial_create_chan($agi, $action){
252
-	$id  	= $agi->get_variable("transfer_UNIQUEID", true);
253
-	$data   = array();
254
-	$data['dst_chan'] 			= $agi->request['agi_channel'];
255
-	$data['transfer_UNIQUEID'] 	= "$id";
256
-	$data['action']  			= "$action";
257
-	$data['linkedid']  			= $agi->get_variable("CDR(linkedid)", true);
251
+function Event_transfer_dial_create_chan($agi, $action) {
252
+	$id = $agi->get_variable("transfer_UNIQUEID", true);
253
+	$data = array();
254
+	$data['dst_chan'] = $agi->request['agi_channel'];
255
+	$data['transfer_UNIQUEID'] = "$id";
256
+	$data['action'] = "$action";
257
+	$data['linkedid'] = $agi->get_variable("CDR(linkedid)", true);
258 258
 
259 259
 	return $data;
260 260
 }
@@ -265,13 +265,13 @@  discard block
 block discarded – undo
265 265
  * @param string $action
266 266
  * @return array
267 267
  */
268
-function Event_transfer_dial_answer($agi, $action){
268
+function Event_transfer_dial_answer($agi, $action) {
269 269
 	$data 	= array();
270
-    $now    = Util::get_now_date();
270
+    $now = Util::get_now_date();
271 271
 	$id   	= $agi->get_variable("transfer_UNIQUEID", true);
272
-	$data['answer'] 			= $now;
273
-	$data['transfer_UNIQUEID'] 	= "$id";
274
-	$data['action']  			= "$action";
272
+	$data['answer'] = $now;
273
+	$data['transfer_UNIQUEID'] = "$id";
274
+	$data['action'] = "$action";
275 275
 	$data['agi_channel']		= $agi->request['agi_channel'];
276 276
 	$data['linkedid']  			= $agi->get_variable("CDR(linkedid)", true);
277 277
 
@@ -284,24 +284,24 @@  discard block
 block discarded – undo
284 284
  * @param string $action
285 285
  * @return array
286 286
  */
287
-function Event_transfer_dial_hangup($agi, $action){
288
-    $now    = Util::get_now_date();
289
-	$data 	= array();
290
-	$data['end']  		  = $now;
287
+function Event_transfer_dial_hangup($agi, $action) {
288
+    $now = Util::get_now_date();
289
+	$data = array();
290
+	$data['end'] = $now;
291 291
 	$data['linkedid']  	  = $agi->get_variable("CDR(linkedid)", true);
292
-	$data['did']		  = $agi->get_variable("FROM_DID", true);;
293
-	$data['action']  	  = "$action";
292
+	$data['did'] = $agi->get_variable("FROM_DID", true); ;
293
+	$data['action'] = "$action";
294 294
 	$data['agi_channel']  = $agi->request['agi_channel'];
295
-	$data['agi_threadid'] = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
295
+	$data['agi_threadid'] = $agi->request['agi_uniqueid'].'_'.Util::generateRandomString();
296 296
 
297
-	$pos = stripos( $data['agi_channel'], 'local/');
298
-	if($pos === false){
297
+	$pos = stripos($data['agi_channel'], 'local/');
298
+	if ($pos === false) {
299 299
 		// Если это завершение переадресации (консультативной). Создадим новую строку CDR.
300
-	}else{
300
+	} else {
301 301
 		// Если пришел локальный канал:
302
-		$data['TRANSFERERNAME'] = $agi->get_variable("TRANSFERERNAME", 	true);
303
-		$data['ANSWEREDTIME'] 	= $agi->get_variable("ANSWEREDTIME", 	true);
304
-		$data['dst_chan'] 		= $agi->get_variable("CDR(dstchannel)", true);
302
+		$data['TRANSFERERNAME'] = $agi->get_variable("TRANSFERERNAME", true);
303
+		$data['ANSWEREDTIME'] = $agi->get_variable("ANSWEREDTIME", true);
304
+		$data['dst_chan'] = $agi->get_variable("CDR(dstchannel)", true);
305 305
 	}
306 306
 
307 307
 	return $data;
@@ -313,20 +313,20 @@  discard block
 block discarded – undo
313 313
  * @param string $action
314 314
  * @return array
315 315
  */
316
-function Event_hangup_chan($agi, $action){
317
-    $now    = Util::get_now_date();
318
-	$data 	= [];
316
+function Event_hangup_chan($agi, $action) {
317
+    $now = Util::get_now_date();
318
+	$data = [];
319 319
     $data['action']  	    = "$action";
320
-    $data['did']		    = $agi->get_variable("FROM_DID", true);;
321
-    $data['agi_threadid'] = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
320
+    $data['did'] = $agi->get_variable("FROM_DID", true); ;
321
+    $data['agi_threadid'] = $agi->request['agi_uniqueid'].'_'.Util::generateRandomString();
322 322
 
323 323
 	$data['linkedid']  	    = $agi->get_variable("CDR(linkedid)", true);
324 324
 	$data['dialstatus']     = $agi->get_variable("DIALSTATUS", true);
325
-	if('ANSWER' == $data['dialstatus']){
325
+	if ('ANSWER' == $data['dialstatus']) {
326 326
         $data['dialstatus'] = "ANSWERED";
327 327
     }
328
-	$data['agi_channel']    = $agi->request['agi_channel'];
329
-	$data['end']  		    = $now;
328
+	$data['agi_channel'] = $agi->request['agi_channel'];
329
+	$data['end'] = $now;
330 330
 
331 331
     $data['OLD_LINKEDID']   = $agi->get_variable("OLD_LINKEDID", true);
332 332
     $data['UNIQUEID']  	    = $agi->get_variable("pt1c_UNIQUEID", true);
@@ -340,51 +340,51 @@  discard block
 block discarded – undo
340 340
  * @param string $action
341 341
  * @return array
342 342
  */
343
-function Event_unpark_call($agi, $action){
344
-    $now    = Util::get_now_date();
343
+function Event_unpark_call($agi, $action) {
344
+    $now = Util::get_now_date();
345 345
 	// Обработка данных парковки. 
346
-	$exten	= $agi->get_variable("EXTEN", 	true);
346
+	$exten = $agi->get_variable("EXTEN", true);
347 347
 	$park_row = p_Park::get_parkslot_data($exten);
348 348
 	
349 349
 	$agi->set_variable("__pt1c_IS_PARK", "1");		
350 350
 	$agi->set_variable("pt1c_PARK_CHAN", $park_row['ParkeeChannel']);
351 351
 	
352 352
 	// Сбор данных для генерации CDR.
353
-	$id   	= $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
354
-	$channel= $agi->request['agi_channel'];
353
+	$id   	= $agi->request['agi_uniqueid'].'_'.Util::generateRandomString();
354
+	$channel = $agi->request['agi_channel'];
355 355
  	$agi->set_variable("__pt1c_UNIQUEID", "$id");		
356 356
 	$data 	= array();
357
-	$data['action']  	 = "$action";
357
+	$data['action'] = "$action";
358 358
 	$data['UNIQUEID']  	 = $id;
359
-	$data['linkedid_old']= $agi->get_variable("CDR(linkedid)", true);
359
+	$data['linkedid_old'] = $agi->get_variable("CDR(linkedid)", true);
360 360
 	$data['agi_channel'] = $channel;
361 361
 	$data['linkedid']  	 = $park_row['ParkeeLinkedid'];
362
-	$data['start']  	 = $now;
362
+	$data['start'] = $now;
363 363
 	$data['transfer']  	 = '0';
364
-	$data['did']		 = $agi->get_variable("FROM_DID", true);
365
-	$data['answer']  	 = $data['start'];
364
+	$data['did'] = $agi->get_variable("FROM_DID", true);
365
+	$data['answer'] = $data['start'];
366 366
 	
367
-	if(null == $park_row){
367
+	if (null == $park_row) {
368 368
 		$data['src_chan'] 	= $channel;
369 369
 		$data['src_num']  	= $agi->request['agi_callerid'];
370 370
 		$data['dst_num']  	= $agi->request['agi_extension'];
371 371
 		$data['dst_chan'] 	= 'Park:'.$agi->request['agi_extension'];
372
-	}else if(true == $park_row['pt1c_is_dst']){
372
+	} else if (true == $park_row['pt1c_is_dst']) {
373 373
 		$data['src_chan'] 	= $channel;
374 374
 		$data['dst_chan'] 	= $park_row['ParkeeChannel'];
375 375
 		$data['src_num']  	= $agi->request['agi_callerid'];
376 376
 		$data['dst_num']  	= $park_row['ParkeeCallerIDNum'];
377
-	}else{
377
+	} else {
378 378
 		$data['src_chan'] 	= $park_row['ParkeeChannel'];
379 379
 		$data['dst_chan'] 	= $channel;
380 380
 		$data['src_num']  	= $park_row['ParkeeCallerIDNum'];
381 381
 		$data['dst_num']  	= $agi->request['agi_callerid'];
382 382
 	}
383 383
 	
384
-	if(trim($park_row['ParkingDuration'])!=''){
385
-		$time_start = date("Y-m-d H:i:s", time() - 1*($park_row['ParkingDuration']) );
384
+	if (trim($park_row['ParkingDuration']) != '') {
385
+		$time_start = date("Y-m-d H:i:s", time() - 1 * ($park_row['ParkingDuration']));
386 386
 		$data_parking = array(
387
-		    'UNIQUEID' => $id .'_'. Util::generateRandomString(3),
387
+		    'UNIQUEID' => $id.'_'.Util::generateRandomString(3),
388 388
 			'src_chan' => $park_row['ParkeeChannel'],
389 389
 			'src_num'  => $park_row['ParkeeCallerIDNum'],
390 390
 			'dst_num'  => $park_row['ParkingSpace'],
@@ -408,14 +408,14 @@  discard block
 block discarded – undo
408 408
  * @param string $action
409 409
  * @return array
410 410
  */
411
-function Event_unpark_call_timeout($agi, $action){
412
-    $now  = Util::get_now_date();
413
-	$id   = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
411
+function Event_unpark_call_timeout($agi, $action) {
412
+    $now = Util::get_now_date();
413
+	$id = $agi->request['agi_uniqueid'].'_'.Util::generateRandomString();
414 414
 	// PARKER=SIP/206
415 415
 	$PARKING_DURATION = $agi->get_variable("PARKING_DURATION", true);
416
-	$PARKING_DURATION = ($PARKING_DURATION == '')?45:$PARKING_DURATION;
416
+	$PARKING_DURATION = ($PARKING_DURATION == '') ? 45 : $PARKING_DURATION;
417 417
 		
418
-	$time_start = date("Y-m-d H:i:s", time() - 1*($PARKING_DURATION));
418
+	$time_start = date("Y-m-d H:i:s", time() - 1 * ($PARKING_DURATION));
419 419
 	$PARKING_SPACE = $agi->get_variable("PARKING_SPACE", true);
420 420
 	$data = array(
421 421
 		'action'   => "$action",
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 	);
435 435
 
436 436
 
437
-    $id2   = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
437
+    $id2 = $agi->request['agi_uniqueid'].'_'.Util::generateRandomString();
438 438
     $agi->set_variable("__pt1c_UNIQUEID", "$id2");
439 439
 
440 440
     return $data;
@@ -446,13 +446,13 @@  discard block
 block discarded – undo
446 446
  * @param string $action
447 447
  * @return array
448 448
  */
449
-function Event_queue_start($agi, $action){
450
-    $now  = Util::get_now_date();
449
+function Event_queue_start($agi, $action) {
450
+    $now = Util::get_now_date();
451 451
     $time_start = null;
452
-    $id = $agi->get_variable("pt1c_UNIQUEID",  true);
453
-    $ISTRANSFER = $agi->get_variable("ISTRANSFER",  true);
452
+    $id = $agi->get_variable("pt1c_UNIQUEID", true);
453
+    $ISTRANSFER = $agi->get_variable("ISTRANSFER", true);
454 454
 
455
-    if(empty($id) || !empty($ISTRANSFER)) {
455
+    if (empty($id) || !empty($ISTRANSFER)) {
456 456
         $id = $agi->request['agi_uniqueid'].'_'.Util::generateRandomString();
457 457
         $time_start = $now;
458 458
     }
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 		'UNIQUEID' => $id,
471 471
 		'linkedid' => $agi->get_variable("CDR(linkedid)", true)
472 472
 	);
473
-    if(!empty($time_start)){
473
+    if (!empty($time_start)) {
474 474
         $data['src_chan'] = $agi->get_variable("QUEUE_SRC_CHAN", true);
475 475
         $data['src_num']  = $agi->request['agi_callerid'];
476 476
         $data['start']    = $time_start;
@@ -478,9 +478,9 @@  discard block
 block discarded – undo
478 478
         $data['transfer'] = '0';
479 479
         $agi->set_variable("__pt1c_q_UNIQUEID", "$id");
480 480
     }
481
-    if(!empty($ISTRANSFER)){
481
+    if (!empty($ISTRANSFER)) {
482 482
         $data['transfer']  	= '1';
483
-    }else{
483
+    } else {
484 484
         $data['transfer']  	= '0';
485 485
     }
486 486
 
@@ -493,14 +493,14 @@  discard block
 block discarded – undo
493 493
  * @param string $action
494 494
  * @return array
495 495
  */
496
-function Event_queue_answer($agi, $action){
497
-    $now  = Util::get_now_date();
496
+function Event_queue_answer($agi, $action) {
497
+    $now = Util::get_now_date();
498 498
 	$id   = $agi->get_variable("pt1c_q_UNIQUEID", true);
499 499
 	$data = array();
500 500
 	$data['action']  	= "$action";
501 501
 	$data['answer']  	= $now;
502
-	$data['id'] 		= $id;
503
-	$data['agi_channel']= $agi->request['agi_channel'];
502
+	$data['id'] = $id;
503
+	$data['agi_channel'] = $agi->request['agi_channel'];
504 504
 	$data['linkedid']  	= $agi->get_variable("CDR(linkedid)", true);
505 505
 
506 506
 	return $data;	
@@ -512,15 +512,15 @@  discard block
 block discarded – undo
512 512
  * @param string $action
513 513
  * @return array
514 514
  */
515
-function Event_queue_end($agi, $action){
516
-    $now  = Util::get_now_date();
515
+function Event_queue_end($agi, $action) {
516
+    $now = Util::get_now_date();
517 517
 	$id   = $agi->get_variable("pt1c_q_UNIQUEID", true);
518 518
 	$data = array();
519
-	$data['action']  	= "$action";
520
-	$data['end']  		= $now;
521
-	$data['id'] 		= $id;
519
+	$data['action'] = "$action";
520
+	$data['end'] = $now;
521
+	$data['id'] = $id;
522 522
 	$data['dialstatus'] = $agi->get_variable("QUEUESTATUS", true);
523
-	$data['agi_channel']= $agi->request['agi_channel'];
523
+	$data['agi_channel'] = $agi->request['agi_channel'];
524 524
 	$data['linkedid']  	= $agi->get_variable("CDR(linkedid)", true);
525 525
 
526 526
 	return $data;	
@@ -532,52 +532,52 @@  discard block
 block discarded – undo
532 532
  * @param string $action
533 533
  * @return array
534 534
  */
535
-function Event_meetme_dial($agi, $action){
535
+function Event_meetme_dial($agi, $action) {
536 536
     $now        = Util::get_now_date();
537 537
     $id         = '';
538 538
     $time_start = $now;
539 539
     $exten      = $agi->request['agi_extension'];
540 540
 
541
-    $not_local       = (stripos($agi->request['agi_channel'], 'local/') === false);
542
-    if($not_local){
541
+    $not_local = (stripos($agi->request['agi_channel'], 'local/') === false);
542
+    if ($not_local) {
543 543
         $am     = Util::get_am();
544 544
         $res    = $am->meetMeCollectInfo($exten, ['conf_1c']);
545 545
         $callid = $agi->request['agi_callerid'];
546
-        $users_nums   = [ [$callid] ];
547
-        foreach ($res as $row){
546
+        $users_nums = [[$callid]];
547
+        foreach ($res as $row) {
548 548
             $users_nums[] = explode('_', $row['conf_1c']);
549 549
         }
550 550
         $users = implode('_', array_unique(array_merge(... $users_nums)));
551 551
         $agi->set_variable('conf_1c', $users);
552
-        $agi->set_variable('CALLERID(num)','Conference_Room');
552
+        $agi->set_variable('CALLERID(num)', 'Conference_Room');
553 553
         $agi->set_variable('CALLERID(name)', $callid);
554
-        $agi->set_variable('mikoconfcid',    $exten);
555
-        $agi->set_variable('mikoidconf',     $exten);
554
+        $agi->set_variable('mikoconfcid', $exten);
555
+        $agi->set_variable('mikoidconf', $exten);
556 556
 
557 557
         $mikoidconf = $exten;
558
-        $BLINDTRANSFER  = $agi->get_variable("BLINDTRANSFER", true);
559
-        if(empty($BLINDTRANSFER)){
558
+        $BLINDTRANSFER = $agi->get_variable("BLINDTRANSFER", true);
559
+        if (empty($BLINDTRANSFER)) {
560 560
             $id     = $agi->get_variable('pt1c_UNIQUEID', true);
561 561
         }
562
-        $src_num= $callid;
563
-        $dst_num= $exten;
564
-    }else{
562
+        $src_num = $callid;
563
+        $dst_num = $exten;
564
+    } else {
565 565
         $mikoidconf     = $agi->get_variable('mikoidconf', true);
566
-        if(empty($mikoidconf)){
566
+        if (empty($mikoidconf)) {
567 567
             $mikoidconf = $exten;
568 568
         }
569
-        $src_num    = $agi->get_variable('mikoconfcid', true);
569
+        $src_num = $agi->get_variable('mikoconfcid', true);
570 570
         // Отсечем все до "/".
571 571
         $tmp_arr = explode('/', $mikoidconf);
572
-        if(count($tmp_arr)>1){
572
+        if (count($tmp_arr) > 1) {
573 573
             unset($tmp_arr[0]);
574 574
             $mikoidconf = implode('/', $tmp_arr);
575 575
         }
576
-        $dst_num    = substr($mikoidconf, 4);
576
+        $dst_num = substr($mikoidconf, 4);
577 577
     }
578 578
 
579
-    if(empty($id)){
580
-        $id         = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
579
+    if (empty($id)) {
580
+        $id = $agi->request['agi_uniqueid'].'_'.Util::generateRandomString();
581 581
     }
582 582
 
583 583
     $recordingfile = Cdr::MeetMeSetRecFilename($id);
@@ -595,8 +595,8 @@  discard block
 block discarded – undo
595 595
         'UNIQUEID'      => $id,
596 596
         'linkedid'      => $agi->get_variable('CDR(linkedid)', true)
597 597
     ];
598
-    $agi->set_variable('MEETME_RECORDINGFILE',  $recordingfile);
599
-    $agi->set_variable('__pt1c_q_UNIQUEID',     $id);
598
+    $agi->set_variable('MEETME_RECORDINGFILE', $recordingfile);
599
+    $agi->set_variable('__pt1c_q_UNIQUEID', $id);
600 600
 
601 601
     return $data;
602 602
 }
@@ -610,11 +610,11 @@  discard block
 block discarded – undo
610 610
 function Event_hangup_chan_meetme($agi, $action):array {
611 611
     $now  = Util::get_now_date();
612 612
     $data = [];
613
-    $data['action']  	= $action;
613
+    $data['action'] = $action;
614 614
     $data['linkedid']  	= $agi->get_variable('CDR(linkedid)', true);
615 615
     $data['src_chan']   = $agi->request['agi_channel'];
616
-    $data['agi_channel']= $agi->request['agi_channel'];
617
-    $data['end']  		= $now;
616
+    $data['agi_channel'] = $agi->request['agi_channel'];
617
+    $data['end'] = $now;
618 618
     $data['meetme_id'] 	= $agi->get_variable('MEETMEUNIQUEID', true);
619 619
     $data['conference'] = $agi->get_variable('mikoidconf', true);
620 620
     $data['UNIQUEID']   = $agi->get_variable('pt1c_q_UNIQUEID', true);
@@ -632,10 +632,10 @@  discard block
 block discarded – undo
632 632
  * @param string $action
633 633
  * @return array
634 634
  */
635
-function Event_dial_app($agi, $action){
636
-    $id         = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
635
+function Event_dial_app($agi, $action) {
636
+    $id         = $agi->request['agi_uniqueid'].'_'.Util::generateRandomString();
637 637
     $extension 	= $agi->get_variable("APPEXTEN", true);
638
-    if(empty($extension)){
638
+    if (empty($extension)) {
639 639
         $extension = $agi->request['agi_extension'];
640 640
     }
641 641
 
@@ -655,21 +655,21 @@  discard block
 block discarded – undo
655 655
  * @param string $action
656 656
  * @return array
657 657
  */
658
-function Event_dial_outworktimes($agi, $action){
658
+function Event_dial_outworktimes($agi, $action) {
659 659
     $data = Event_dial($agi, $action);
660 660
     $data['dst_chan']   = 'App:outworktimes';
661
-    $data['dst_num']  	= 'outworktimes';
661
+    $data['dst_num'] = 'outworktimes';
662 662
     $data['is_app']     = 1;
663 663
     return $data;
664 664
 }
665 665
 
666 666
 // Должны быть переданы параметры.
667
-if(count($argv)==1) exit;
667
+if (count($argv) == 1) exit;
668 668
 
669 669
 $action	    = trim($argv[1]);
670 670
 $func_name 	= "Event_$action";
671 671
 
672
-if( function_exists($func_name) ){
672
+if (function_exists($func_name)) {
673 673
     $agi = new AGI();
674 674
     // Сбор сведений по каналу.
675 675
 	$result = $func_name($agi, $action);
Please login to merge, or discard this patch.
Braces   +48 added lines, -29 removed lines patch added patch discarded remove patch
@@ -17,7 +17,8 @@  discard block
 block discarded – undo
17 17
  * @param string $action
18 18
  * @return array
19 19
  */
20
-function Event_dial($agi, $action){
20
+function Event_dial($agi, $action)
21
+{
21 22
 	$now = Util::get_now_date();
22 23
     $data = array();
23 24
 	
@@ -37,7 +38,7 @@  discard block
 block discarded – undo
37 38
 	if($QUEUE_SRC_CHAN != '' && $is_local){
38 39
 		// Это LOCAL, Переопределим на исходный. 
39 40
 		$channel = $QUEUE_SRC_CHAN;
40
-	}else if($is_local && (stripos($orign_chan, 'local/') === false)){
41
+	} else if($is_local && (stripos($orign_chan, 'local/') === false)){
41 42
         $channel = $orign_chan;
42 43
     }
43 44
 
@@ -63,7 +64,7 @@  discard block
 block discarded – undo
63 64
 
64 65
         $id   = substr($agi->request['agi_uniqueid'],0, 16) .'_'.$num.'_'. $IS_ORGNT;
65 66
         $data['dst_chan'] 	 = $dst_chan;
66
-    }else{
67
+    } else{
67 68
         $src_num  	 = $agi->request['agi_callerid'];
68 69
         $dst_num  	 = $agi->request['agi_extension'];
69 70
     }
@@ -90,7 +91,8 @@  discard block
 block discarded – undo
90 91
  * @param string $action
91 92
  * @return array
92 93
  */
93
-function Event_dial_create_chan($agi, $action){
94
+function Event_dial_create_chan($agi, $action)
95
+{
94 96
     $now = Util::get_now_date();
95 97
 	$data 	    = [];
96 98
 	$id   	    = $agi->get_variable("pt1c_UNIQUEID", true);
@@ -125,7 +127,8 @@  discard block
 block discarded – undo
125 127
  * @param string $action
126 128
  * @return array
127 129
  */
128
-function Event_dial_answer($agi, $action){
130
+function Event_dial_answer($agi, $action)
131
+{
129 132
     $now = Util::get_now_date();
130 133
 
131 134
 	$id   = $agi->get_variable("pt1c_UNIQUEID", true);
@@ -162,7 +165,7 @@  discard block
 block discarded – undo
162 165
     if('unknown' == $data['dnid'] && $PICKUPEER != ''){
163 166
         // Скорее всего ответ на вызов из 1С.
164 167
         $data['dnid']   = $pickupexten;
165
-    }elseif ($pickupexten == substr($data['dnid'], 0, 2) && $PICKUPEER != ''){
168
+    } elseif ($pickupexten == substr($data['dnid'], 0, 2) && $PICKUPEER != ''){
166 169
         // Это перехват при наборе номера *8XXX.
167 170
         $data['dnid']   = $pickupexten;
168 171
     }
@@ -183,7 +186,8 @@  discard block
 block discarded – undo
183 186
  * @param string $action
184 187
  * @return array
185 188
  */
186
-function Event_dial_hangup_DEPRECATED($agi, $action){
189
+function Event_dial_hangup_DEPRECATED($agi, $action)
190
+{
187 191
     // TODO Удалить эту функцию в будущем.
188 192
     $now    = Util::get_now_date();
189 193
 	$data 	= array();
@@ -205,7 +209,8 @@  discard block
 block discarded – undo
205 209
  * @param string $action
206 210
  * @return array
207 211
  */
208
-function Event_transfer_dial($agi, $action){
212
+function Event_transfer_dial($agi, $action)
213
+{
209 214
     $now = Util::get_now_date();
210 215
 	$id   = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
211 216
 
@@ -216,12 +221,12 @@  discard block
 block discarded – undo
216 221
     if( $QUEUE_SRC_CHAN != '' && $is_local ){
217 222
         // Это LOCAL, Переопределим на исходный.
218 223
         $channel = $QUEUE_SRC_CHAN;
219
-    }else if( $QUEUE_SRC_CHAN != '' && $TRANSFERERNAME == '' ){
224
+    } else if( $QUEUE_SRC_CHAN != '' && $TRANSFERERNAME == '' ){
220 225
         // Это редирект на очередь.
221 226
         $channel = $QUEUE_SRC_CHAN;
222
-    }else if($TRANSFERERNAME == ''){
227
+    } else if($TRANSFERERNAME == ''){
223 228
         $channel = $agi->request['agi_channel'];
224
-    }else{
229
+    } else{
225 230
         $channel = $TRANSFERERNAME;
226 231
     }
227 232
 
@@ -248,7 +253,8 @@  discard block
 block discarded – undo
248 253
  * @param string $action
249 254
  * @return array
250 255
  */
251
-function Event_transfer_dial_create_chan($agi, $action){
256
+function Event_transfer_dial_create_chan($agi, $action)
257
+{
252 258
 	$id  	= $agi->get_variable("transfer_UNIQUEID", true);
253 259
 	$data   = array();
254 260
 	$data['dst_chan'] 			= $agi->request['agi_channel'];
@@ -265,7 +271,8 @@  discard block
 block discarded – undo
265 271
  * @param string $action
266 272
  * @return array
267 273
  */
268
-function Event_transfer_dial_answer($agi, $action){
274
+function Event_transfer_dial_answer($agi, $action)
275
+{
269 276
 	$data 	= array();
270 277
     $now    = Util::get_now_date();
271 278
 	$id   	= $agi->get_variable("transfer_UNIQUEID", true);
@@ -284,7 +291,8 @@  discard block
 block discarded – undo
284 291
  * @param string $action
285 292
  * @return array
286 293
  */
287
-function Event_transfer_dial_hangup($agi, $action){
294
+function Event_transfer_dial_hangup($agi, $action)
295
+{
288 296
     $now    = Util::get_now_date();
289 297
 	$data 	= array();
290 298
 	$data['end']  		  = $now;
@@ -297,7 +305,7 @@  discard block
 block discarded – undo
297 305
 	$pos = stripos( $data['agi_channel'], 'local/');
298 306
 	if($pos === false){
299 307
 		// Если это завершение переадресации (консультативной). Создадим новую строку CDR.
300
-	}else{
308
+	} else{
301 309
 		// Если пришел локальный канал:
302 310
 		$data['TRANSFERERNAME'] = $agi->get_variable("TRANSFERERNAME", 	true);
303 311
 		$data['ANSWEREDTIME'] 	= $agi->get_variable("ANSWEREDTIME", 	true);
@@ -313,7 +321,8 @@  discard block
 block discarded – undo
313 321
  * @param string $action
314 322
  * @return array
315 323
  */
316
-function Event_hangup_chan($agi, $action){
324
+function Event_hangup_chan($agi, $action)
325
+{
317 326
     $now    = Util::get_now_date();
318 327
 	$data 	= [];
319 328
     $data['action']  	    = "$action";
@@ -340,7 +349,8 @@  discard block
 block discarded – undo
340 349
  * @param string $action
341 350
  * @return array
342 351
  */
343
-function Event_unpark_call($agi, $action){
352
+function Event_unpark_call($agi, $action)
353
+{
344 354
     $now    = Util::get_now_date();
345 355
 	// Обработка данных парковки. 
346 356
 	$exten	= $agi->get_variable("EXTEN", 	true);
@@ -369,12 +379,12 @@  discard block
 block discarded – undo
369 379
 		$data['src_num']  	= $agi->request['agi_callerid'];
370 380
 		$data['dst_num']  	= $agi->request['agi_extension'];
371 381
 		$data['dst_chan'] 	= 'Park:'.$agi->request['agi_extension'];
372
-	}else if(true == $park_row['pt1c_is_dst']){
382
+	} else if(true == $park_row['pt1c_is_dst']){
373 383
 		$data['src_chan'] 	= $channel;
374 384
 		$data['dst_chan'] 	= $park_row['ParkeeChannel'];
375 385
 		$data['src_num']  	= $agi->request['agi_callerid'];
376 386
 		$data['dst_num']  	= $park_row['ParkeeCallerIDNum'];
377
-	}else{
387
+	} else{
378 388
 		$data['src_chan'] 	= $park_row['ParkeeChannel'];
379 389
 		$data['dst_chan'] 	= $channel;
380 390
 		$data['src_num']  	= $park_row['ParkeeCallerIDNum'];
@@ -408,7 +418,8 @@  discard block
 block discarded – undo
408 418
  * @param string $action
409 419
  * @return array
410 420
  */
411
-function Event_unpark_call_timeout($agi, $action){
421
+function Event_unpark_call_timeout($agi, $action)
422
+{
412 423
     $now  = Util::get_now_date();
413 424
 	$id   = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
414 425
 	// PARKER=SIP/206
@@ -446,7 +457,8 @@  discard block
 block discarded – undo
446 457
  * @param string $action
447 458
  * @return array
448 459
  */
449
-function Event_queue_start($agi, $action){
460
+function Event_queue_start($agi, $action)
461
+{
450 462
     $now  = Util::get_now_date();
451 463
     $time_start = null;
452 464
     $id = $agi->get_variable("pt1c_UNIQUEID",  true);
@@ -480,7 +492,7 @@  discard block
 block discarded – undo
480 492
     }
481 493
     if(!empty($ISTRANSFER)){
482 494
         $data['transfer']  	= '1';
483
-    }else{
495
+    } else{
484 496
         $data['transfer']  	= '0';
485 497
     }
486 498
 
@@ -493,7 +505,8 @@  discard block
 block discarded – undo
493 505
  * @param string $action
494 506
  * @return array
495 507
  */
496
-function Event_queue_answer($agi, $action){
508
+function Event_queue_answer($agi, $action)
509
+{
497 510
     $now  = Util::get_now_date();
498 511
 	$id   = $agi->get_variable("pt1c_q_UNIQUEID", true);
499 512
 	$data = array();
@@ -512,7 +525,8 @@  discard block
 block discarded – undo
512 525
  * @param string $action
513 526
  * @return array
514 527
  */
515
-function Event_queue_end($agi, $action){
528
+function Event_queue_end($agi, $action)
529
+{
516 530
     $now  = Util::get_now_date();
517 531
 	$id   = $agi->get_variable("pt1c_q_UNIQUEID", true);
518 532
 	$data = array();
@@ -532,7 +546,8 @@  discard block
 block discarded – undo
532 546
  * @param string $action
533 547
  * @return array
534 548
  */
535
-function Event_meetme_dial($agi, $action){
549
+function Event_meetme_dial($agi, $action)
550
+{
536 551
     $now        = Util::get_now_date();
537 552
     $id         = '';
538 553
     $time_start = $now;
@@ -561,7 +576,7 @@  discard block
 block discarded – undo
561 576
         }
562 577
         $src_num= $callid;
563 578
         $dst_num= $exten;
564
-    }else{
579
+    } else{
565 580
         $mikoidconf     = $agi->get_variable('mikoidconf', true);
566 581
         if(empty($mikoidconf)){
567 582
             $mikoidconf = $exten;
@@ -632,7 +647,8 @@  discard block
 block discarded – undo
632 647
  * @param string $action
633 648
  * @return array
634 649
  */
635
-function Event_dial_app($agi, $action){
650
+function Event_dial_app($agi, $action)
651
+{
636 652
     $id         = $agi->request['agi_uniqueid'] .'_'. Util::generateRandomString();
637 653
     $extension 	= $agi->get_variable("APPEXTEN", true);
638 654
     if(empty($extension)){
@@ -655,7 +671,8 @@  discard block
 block discarded – undo
655 671
  * @param string $action
656 672
  * @return array
657 673
  */
658
-function Event_dial_outworktimes($agi, $action){
674
+function Event_dial_outworktimes($agi, $action)
675
+{
659 676
     $data = Event_dial($agi, $action);
660 677
     $data['dst_chan']   = 'App:outworktimes';
661 678
     $data['dst_num']  	= 'outworktimes';
@@ -664,7 +681,9 @@  discard block
 block discarded – undo
664 681
 }
665 682
 
666 683
 // Должны быть переданы параметры.
667
-if(count($argv)==1) exit;
684
+if(count($argv)==1) {
685
+    exit;
686
+}
668 687
 
669 688
 $action	    = trim($argv[1]);
670 689
 $func_name 	= "Event_$action";
Please login to merge, or discard this patch.
etc/asterisk/agi-bin/phpagi-asmanager.php 3 patches
Spacing   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
      * @param string $config is the name of the config file to parse or a parent agi from which to read the config
89 89
      * @param array  $optconfig is an array of configuration vars and vals, stuffed into $this->config['asmanager']
90 90
      */
91
-    function __construct($config = NULL, $optconfig = array()){
91
+    function __construct($config = NULL, $optconfig = array()) {
92 92
         // load config
93 93
         if (!is_null($config) && file_exists($config)) $this->config = parse_ini_file($config, true); elseif (file_exists(DEFAULT_PHPAGI_CONFIG)) $this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIG, true);
94 94
 
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
      * @param array  $parameters
110 110
      * @return array of parameters
111 111
      */
112
-    function send_request($action, $parameters = array()){
112
+    function send_request($action, $parameters = array()) {
113 113
         $req = "Action: $action\r\n";
114 114
         foreach ($parameters as $var => $val) $req .= "$var: $val\r\n";
115 115
         $req .= "\r\n";
116
-        if(!is_resource($this->socket)){
116
+        if (!is_resource($this->socket)) {
117 117
             return array();
118 118
         }
119 119
         @fwrite($this->socket, $req);
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
      * @param array  $parameters
128 128
      * @return array of parameters
129 129
      */
130
-    function send_request_timeout($action, $parameters = array()){
130
+    function send_request_timeout($action, $parameters = array()) {
131 131
         $req = "Action: $action\r\n";
132 132
         foreach ($parameters as $var => $val) $req .= "$var: $val\r\n";
133 133
         $req .= "\r\n";
134
-        if(!is_resource($this->socket)){
134
+        if (!is_resource($this->socket)) {
135 135
             return array();
136 136
         }
137 137
         @fwrite($this->socket, $req);
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
      * @param string $pingname
144 144
      * @return array|bool
145 145
      */
146
-    function ping_ami_listner($pingname = 'CdrConnector'){
146
+    function ping_ami_listner($pingname = 'CdrConnector') {
147 147
         // Установим фильтр на события.
148
-        $params   = ['Operation'=>'Add', 'Filter' => 'Event: UserEvent'];
148
+        $params = ['Operation'=>'Add', 'Filter' => 'Event: UserEvent'];
149 149
         $this->send_request_timeout('Filter', $params);
150 150
         // Отправим пинг.
151 151
         $req = '';
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
         );
156 156
         foreach ($parameters as $var => $val) $req .= "$var: $val\r\n";
157 157
         $req .= "\r\n";
158
-        if(!is_resource($this->socket)){
158
+        if (!is_resource($this->socket)) {
159 159
             return array();
160 160
         }
161 161
         @fwrite($this->socket, $req);
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
         do {
170 170
             $type       = '';
171 171
             $parameters = [];
172
-            if(!is_resource($this->socket)){
172
+            if (!is_resource($this->socket)) {
173 173
                 return false;
174 174
             }
175 175
             $buffer = trim(@fgets($this->socket, 4096));
176 176
             while ($buffer != '') {
177 177
                 $a = strpos($buffer, ':');
178 178
                 if ($a) {
179
-                    if (!count($parameters)){
179
+                    if (!count($parameters)) {
180 180
                         $type = strtolower(substr($buffer, 0, $a));
181 181
                     }
182 182
                     $parameters[substr($buffer, 0, $a)] = substr($buffer, $a + 2);
@@ -184,16 +184,16 @@  discard block
 block discarded – undo
184 184
                 $buffer = trim(fgets($this->socket, 4096));
185 185
             }
186 186
 
187
-            if($type == '' && count($this->Ping())==0){
187
+            if ($type == '' && count($this->Ping()) == 0) {
188 188
                 $timeout = true;
189 189
             }
190
-            else if('event' == $type && $parameters['Event'] == 'UserEvent' && "{$pingname}Pong" == $parameters['UserEvent']){
190
+            else if ('event' == $type && $parameters['Event'] == 'UserEvent' && "{$pingname}Pong" == $parameters['UserEvent']) {
191 191
                 // Ответ получен.
192 192
                 $result = true;
193 193
                 break;
194 194
             }
195 195
             $time = $this->microtime_float() - $time_start;
196
-            if($time > 2){
196
+            if ($time > 2) {
197 197
                 // Таймаут ожидания.
198 198
                 break;
199 199
             }
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
         return $result;
204 204
     }
205 205
 
206
-    private function wait_response_get_sub_data(&$parameters, $end_string = '', $event_as_array=true):void {
207
-        if(!is_array($parameters)){
206
+    private function wait_response_get_sub_data(&$parameters, $end_string = '', $event_as_array = true):void {
207
+        if (!is_array($parameters)) {
208 208
             $parameters = [];
209 209
         }
210
-        if(empty($end_string)){
210
+        if (empty($end_string)) {
211 211
             return;
212 212
         }
213 213
         $parameters['data'] = array();
@@ -218,10 +218,10 @@  discard block
 block discarded – undo
218 218
             $buff   = fgets($this->socket, 4096);
219 219
             $a_pos  = strpos($buff, ':');
220 220
             if (!$a_pos) {
221
-                if (count($m)>0) {
222
-                    if($event_as_array){
221
+                if (count($m) > 0) {
222
+                    if ($event_as_array) {
223 223
                         $parameters['data'][$m['Event']][] = $m;
224
-                    }else{
224
+                    } else {
225 225
                         $parameters['data'][$m['Event']] = $m;
226 226
                     }
227 227
                 }
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
         do {
252 252
             $type = NULL;
253 253
             $parameters = array();
254
-            if(!is_resource($this->socket)){
254
+            if (!is_resource($this->socket)) {
255 255
                 return $parameters;
256 256
             }
257 257
             $buffer = trim(@fgets($this->socket, 4096));
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
                 if ($a) {
261 261
                     $key = ''; $value = '';
262 262
                     $event_text = substr($buffer, $a + 2);
263
-                    if (!count($parameters)){
263
+                    if (!count($parameters)) {
264 264
                         $type = strtolower(substr($buffer, 0, $a));
265 265
                         if ($event_text === 'Follows') {
266 266
                             // A follows response means there is a miltiline field that follows.
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
                         // MeetmeList
309 309
                         $this->wait_response_get_sub_data($parameters, 'MeetmeListRoomsComplete');
310 310
                     }
311
-                    unset($key,$value);
311
+                    unset($key, $value);
312 312
                     // store parameter in $parameters
313 313
                     $parameters[substr($buffer, 0, $a)] = $event_text;
314 314
                 }
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
                 case 'response':
328 328
                     break;
329 329
                 default:
330
-                    $this->log('Unhandled response packet from Manager: ' . print_r($parameters, true));
330
+                    $this->log('Unhandled response packet from Manager: '.print_r($parameters, true));
331 331
                     break;
332 332
             }
333 333
         } while ($type !== 'response' && !$timeout);
@@ -339,30 +339,30 @@  discard block
 block discarded – undo
339 339
      * @param $allow_timeout bool
340 340
      * @return array of parameters, empty on timeout
341 341
      */
342
-    function wait_user_event($allow_timeout = false){
342
+    function wait_user_event($allow_timeout = false) {
343 343
         $timeout = false;
344 344
         do {
345 345
             $type       = '';
346 346
             $parameters = [];
347
-            try{
347
+            try {
348 348
                 $buffer = trim(@fgets($this->socket, 4096));
349
-            }catch (Exception $e){
349
+            } catch (Exception $e) {
350 350
                 return false;
351 351
             }
352 352
             while ($buffer != '') {
353 353
                 $a = strpos($buffer, ':');
354 354
                 if ($a) {
355
-                    if (!count($parameters)){
355
+                    if (!count($parameters)) {
356 356
                         $type = strtolower(substr($buffer, 0, $a));
357 357
                     }
358 358
                     $parameters[substr($buffer, 0, $a)] = substr($buffer, $a + 2);
359 359
                 }
360 360
                 $buffer = trim(fgets($this->socket, 4096));
361 361
             }
362
-            if($type == '' && count($this->Ping())==0){
362
+            if ($type == '' && count($this->Ping()) == 0) {
363 363
                 $timeout = $allow_timeout;
364 364
             }
365
-            else if('event' == $type){
365
+            else if ('event' == $type) {
366 366
                 $this->process_event($parameters);
367 367
             }
368 368
         } while (!$timeout);
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
      * @param string $events
381 381
      * @return boolean true on success
382 382
      */
383
-    function connect($server = NULL, $username = NULL, $secret = NULL, $events = 'on'){
383
+    function connect($server = NULL, $username = NULL, $secret = NULL, $events = 'on') {
384 384
         // use config if not specified
385 385
         if (is_null($server)) $server = $this->config['asmanager']['server'];
386 386
         if (is_null($username)) $username = $this->config['asmanager']['username'];
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
         return true;
429 429
     }
430 430
 
431
-    public function logged_in(){
431
+    public function logged_in() {
432 432
         return $this->_logged_in;
433 433
     }
434 434
 
@@ -437,9 +437,9 @@  discard block
 block discarded – undo
437 437
      *
438 438
      * @example examples/sip_show_peer.php Get information about a sip peer
439 439
      */
440
-    function disconnect(){
440
+    function disconnect() {
441 441
         if ($this->_logged_in == TRUE) $this->logoff();
442
-        if(is_resource($this->socket)){
442
+        if (is_resource($this->socket)) {
443 443
             fclose($this->socket);
444 444
         }
445 445
     }
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
      * @param integer $timeout Maximum duration of the call (sec)
459 459
      * @return array
460 460
      */
461
-    function AbsoluteTimeout($channel, $timeout){
461
+    function AbsoluteTimeout($channel, $timeout) {
462 462
         return $this->send_request('AbsoluteTimeout', array('Channel' => $channel, 'Timeout' => $timeout));
463 463
     }
464 464
 
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
      * @param string $file the new name of the file created in the monitor spool directory.
471 471
      * @return array
472 472
      */
473
-    function ChangeMonitor($channel, $file){
473
+    function ChangeMonitor($channel, $file) {
474 474
         return $this->send_request('ChangeMontior', array('Channel' => $channel, 'File' => $file));
475 475
     }
476 476
 
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
      * @param string $actionid message matching variable
485 485
      * @return array
486 486
      */
487
-    function Command($command, $actionid = NULL){
487
+    function Command($command, $actionid = NULL) {
488 488
         $parameters = array('Command' => $command);
489 489
         if ($actionid) $parameters['ActionID'] = $actionid;
490 490
         return $this->send_request('Command', $parameters);
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
      * @param string $eventmask is either 'on', 'off', or 'system,call,log'
498 498
      * @return array
499 499
      */
500
-    function Events($eventmask){
500
+    function Events($eventmask) {
501 501
         return $this->send_request('Events', array('EventMask' => $eventmask));
502 502
     }
503 503
 
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
      * @param string $actionid message matching variable
511 511
      * @return array
512 512
      */
513
-    function ExtensionState($exten, $context, $actionid = NULL){
513
+    function ExtensionState($exten, $context, $actionid = NULL) {
514 514
         $parameters = array('Exten' => $exten, 'Context' => $context);
515 515
         if ($actionid) $parameters['ActionID'] = $actionid;
516 516
         return $this->send_request('ExtensionState', $parameters);
@@ -527,15 +527,15 @@  discard block
 block discarded – undo
527 527
      * @param boolean $ret_array
528 528
      * @return string | array
529 529
      */
530
-    function GetVar($channel, $variable, $actionid = NULL, $ret_array = true){
530
+    function GetVar($channel, $variable, $actionid = NULL, $ret_array = true) {
531 531
         $parameters = array('Channel' => $channel, 'Variable' => $variable);
532
-        if ($actionid){
532
+        if ($actionid) {
533 533
             $parameters['ActionID'] = $actionid;
534 534
         }
535 535
 
536 536
         $data = $this->send_request('GetVar', $parameters);
537
-        if($ret_array != true){
538
-            $data = (isset($data['Value']) && $data['Value'] )?$data['Value']:'';
537
+        if ($ret_array != true) {
538
+            $data = (isset($data['Value']) && $data['Value']) ? $data['Value'] : '';
539 539
         }
540 540
         return $data;
541 541
     }
@@ -545,21 +545,21 @@  discard block
 block discarded – undo
545 545
      * @param boolean $group
546 546
      * @return array
547 547
      */
548
-    public function GetChannels($group = true){
549
-        $res 	  = $this->send_request_timeout('CoreShowChannels');
548
+    public function GetChannels($group = true) {
549
+        $res = $this->send_request_timeout('CoreShowChannels');
550 550
         $channels = null;
551
-        if(isset($res['data']['CoreShowChannel'])){
551
+        if (isset($res['data']['CoreShowChannel'])) {
552 552
             $channels = $res['data']['CoreShowChannel'];
553 553
         }
554 554
         $channels_id = array();
555
-        if(null != $channels){
556
-            foreach($channels as $chan){
557
-                if($group == true){
558
-                    if(! isset($chan['Linkedid']) ){
555
+        if (null != $channels) {
556
+            foreach ($channels as $chan) {
557
+                if ($group == true) {
558
+                    if (!isset($chan['Linkedid'])) {
559 559
                         continue;
560 560
                     }
561 561
                     $channels_id[$chan['Linkedid']][] = $chan['Channel'];
562
-                }else{
562
+                } else {
563 563
                     $channels_id[] = $chan['Channel'];
564 564
                 }
565 565
             }
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
      * @param string $channel The channel name to be hungup
576 576
      * @return array
577 577
      */
578
-    function Hangup($channel){
578
+    function Hangup($channel) {
579 579
         return $this->send_request('Hangup', array('Channel' => $channel));
580 580
     }
581 581
 
@@ -585,10 +585,10 @@  discard block
 block discarded – undo
585 585
      * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+IAXpeers
586 586
      * @return array
587 587
      */
588
-    function IAXpeerlist(){
588
+    function IAXpeerlist() {
589 589
         $result = $this->send_request('IAXpeerlist');
590
-        $data = (isset($result['data']) && is_array($result['data']))?$result['data']:[];
591
-        $arr_peer = (isset($data['PeerEntry']) && is_array($data['PeerEntry']))?$data['PeerEntry']:[];
590
+        $data = (isset($result['data']) && is_array($result['data'])) ? $result['data'] : [];
591
+        $arr_peer = (isset($data['PeerEntry']) && is_array($data['PeerEntry'])) ? $data['PeerEntry'] : [];
592 592
         return $arr_peer;
593 593
     }
594 594
 
@@ -596,10 +596,10 @@  discard block
 block discarded – undo
596 596
      * Возвращает регистрации пиров.
597 597
      * @return array
598 598
      */
599
-    function IAXregistry(){
599
+    function IAXregistry() {
600 600
         $result = $this->send_request('IAXregistry');
601
-        $data = (isset($result['data']) && is_array($result['data']))?$result['data']:[];
602
-        $arr_peer = (isset($data['RegistryEntry']) && is_array($data['RegistryEntry']))?$data['RegistryEntry']:[];
601
+        $data = (isset($result['data']) && is_array($result['data'])) ? $result['data'] : [];
602
+        $arr_peer = (isset($data['RegistryEntry']) && is_array($data['RegistryEntry'])) ? $data['RegistryEntry'] : [];
603 603
         return $arr_peer;
604 604
     }
605 605
 
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
      * @param string $actionid message matching variable
611 611
      * @return array
612 612
      */
613
-    function ListCommands($actionid = NULL){
613
+    function ListCommands($actionid = NULL) {
614 614
         if ($actionid) return $this->send_request('ListCommands', array('ActionID' => $actionid)); else
615 615
             return $this->send_request('ListCommands');
616 616
     }
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
      * @param  array  $headers
622 622
      * @return array
623 623
      */
624
-    function UserEvent($name, $headers){
624
+    function UserEvent($name, $headers) {
625 625
         $headers['UserEvent'] = $name;
626 626
         return $this->send_request_timeout('UserEvent', $headers);
627 627
     }
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
      *
632 632
      * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Logoff
633 633
      */
634
-    function Logoff(){
634
+    function Logoff() {
635 635
         return $this->send_request_timeout('Logoff');
636 636
     }
637 637
 
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
      * @param string $actionid message matching variable
650 650
      * @return array
651 651
      */
652
-    function MailboxCount($mailbox, $actionid = NULL){
652
+    function MailboxCount($mailbox, $actionid = NULL) {
653 653
         $parameters = array('Mailbox' => $mailbox);
654 654
         if ($actionid) $parameters['ActionID'] = $actionid;
655 655
         return $this->send_request('MailboxCount', $parameters);
@@ -668,7 +668,7 @@  discard block
 block discarded – undo
668 668
      * @param string $actionid message matching variable
669 669
      * @return array
670 670
      */
671
-    function MailboxStatus($mailbox, $actionid = NULL){
671
+    function MailboxStatus($mailbox, $actionid = NULL) {
672 672
         $parameters = array('Mailbox' => $mailbox);
673 673
         if ($actionid) $parameters['ActionID'] = $actionid;
674 674
         return $this->send_request('MailboxStatus', $parameters);
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
      * @param boolean $mix
685 685
      * @return array
686 686
      */
687
-    function Monitor($channel, $file = NULL, $format = NULL, $mix = NULL){
687
+    function Monitor($channel, $file = NULL, $format = NULL, $mix = NULL) {
688 688
         $parameters = array('Channel' => $channel);
689 689
         if ($file) $parameters['File'] = $file;
690 690
         if ($format) $parameters['Format'] = $format;
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
      * @param string $command
703 703
      * @return array
704 704
      */
705
-    function MixMonitor($channel, $file, $options, $command){
705
+    function MixMonitor($channel, $file, $options, $command) {
706 706
         $parameters = array('Channel' => $channel);
707 707
         $parameters['File'] = $file;
708 708
         $parameters['options'] = $options;
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
      * @param string $channel
718 718
      * @return array
719 719
      */
720
-    function StopMixMonitor($channel){
720
+    function StopMixMonitor($channel) {
721 721
         $parameters = array('Channel' => $channel);
722 722
         return $this->send_request_timeout('StopMixMonitor', $parameters);
723 723
     }
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
      * @param string $Val
731 731
      * @return array
732 732
      */
733
-    function DBPut($Family, $Key, $Val = ''){
733
+    function DBPut($Family, $Key, $Val = '') {
734 734
         $parameters = array('Family' => $Family, 'Key' => $Key, 'Val' => $Val);
735 735
         $res_data = $this->send_request_timeout('DBPut', $parameters);
736 736
         return $res_data;
@@ -742,8 +742,8 @@  discard block
 block discarded – undo
742 742
      * @param $ActionID
743 743
      * @return array
744 744
      */
745
-    public function MeetmeList($Conference, $ActionID=''):array {
746
-        if(empty($ActionID)){
745
+    public function MeetmeList($Conference, $ActionID = ''):array {
746
+        if (empty($ActionID)) {
747 747
             $ActionID = Util::generateRandomString(5);
748 748
         }
749 749
         $parameters = [
@@ -758,8 +758,8 @@  discard block
 block discarded – undo
758 758
      * @param $ActionID
759 759
      * @return array
760 760
      */
761
-    public function MeetmeListRooms($ActionID=''):array {
762
-        if(empty($ActionID)){
761
+    public function MeetmeListRooms($ActionID = ''):array {
762
+        if (empty($ActionID)) {
763 763
             $ActionID = Util::generateRandomString(5);
764 764
         }
765 765
         $parameters = [
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
      * @param string $Key
776 776
      * @return array
777 777
      */
778
-    function DBGet($Family, $Key){
778
+    function DBGet($Family, $Key) {
779 779
         $parameters = array('Family' => $Family, 'Key' => $Key);
780 780
         return $this->send_request_timeout('DBGet', $parameters);
781 781
     }
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
      * @param string  $actionid message matching variable
799 799
      * @return array
800 800
      */
801
-    function Originate($channel, $exten = NULL, $context = NULL, $priority = NULL, $application = NULL, $data = NULL, $timeout = NULL, $callerid = NULL, $variable = NULL, $account = NULL, $async = NULL, $actionid = NULL){
801
+    function Originate($channel, $exten = NULL, $context = NULL, $priority = NULL, $application = NULL, $data = NULL, $timeout = NULL, $callerid = NULL, $variable = NULL, $account = NULL, $async = NULL, $actionid = NULL) {
802 802
         $parameters = array('Channel' => $channel);
803 803
 
804 804
         if ($exten) $parameters['Exten'] = $exten;
@@ -826,12 +826,12 @@  discard block
 block discarded – undo
826 826
      * @param string $parkinglot message matching variable
827 827
      * @return array
828 828
      */
829
-    function ParkedCalls($parkinglot = NULL, $actionid = NULL){
829
+    function ParkedCalls($parkinglot = NULL, $actionid = NULL) {
830 830
         $parameters = [];
831
-        if ($actionid){
831
+        if ($actionid) {
832 832
             $parameters['ActionID'] = $actionid;
833 833
         }
834
-        if ($parkinglot){
834
+        if ($parkinglot) {
835 835
             $parameters['ParkingLot'] = $parkinglot;
836 836
         }
837 837
         $result = $this->send_request_timeout('ParkedCalls', $parameters);
@@ -844,7 +844,7 @@  discard block
 block discarded – undo
844 844
      *
845 845
      * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Ping
846 846
      */
847
-    function Ping(){
847
+    function Ping() {
848 848
         return $this->send_request_timeout('Ping');
849 849
     }
850 850
 
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
      * @param integer $penalty
858 858
      * @return array
859 859
      */
860
-    function QueueAdd($queue, $interface, $penalty = 0){
860
+    function QueueAdd($queue, $interface, $penalty = 0) {
861 861
         $parameters = array('Queue' => $queue, 'Interface' => $interface);
862 862
         if ($penalty) $parameters['Penalty'] = $penalty;
863 863
         return $this->send_request('QueueAdd', $parameters);
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
      * @param string $interface
872 872
      * @return array
873 873
      */
874
-    function QueueRemove($queue, $interface){
874
+    function QueueRemove($queue, $interface) {
875 875
         return $this->send_request('QueueRemove', array('Queue' => $queue, 'Interface' => $interface));
876 876
     }
877 877
 
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
      *
881 881
      * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Queues
882 882
      */
883
-    function Queues(){
883
+    function Queues() {
884 884
         return $this->send_request('Queues');
885 885
     }
886 886
 
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
      * @param string $actionid message matching variable
892 892
      * @return array
893 893
      */
894
-    function QueueStatus($actionid = NULL){
894
+    function QueueStatus($actionid = NULL) {
895 895
         if ($actionid) return $this->send_request('QueueStatus', array('ActionID' => $actionid)); else
896 896
             return $this->send_request('QueueStatus');
897 897
     }
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
      * @param string $priority
908 908
      * @return array
909 909
      */
910
-    function Redirect($channel, $extrachannel, $exten, $context, $priority){
910
+    function Redirect($channel, $extrachannel, $exten, $context, $priority) {
911 911
         return $this->send_request('Redirect', array('Channel' => $channel, 'ExtraChannel' => $extrachannel, 'Exten' => $exten, 'Context' => $context, 'Priority' => $priority));
912 912
     }
913 913
 
@@ -920,7 +920,7 @@  discard block
 block discarded – undo
920 920
      * @param string $append
921 921
      * @return array
922 922
      */
923
-    function SetCDRUserField($userfield, $channel, $append = NULL){
923
+    function SetCDRUserField($userfield, $channel, $append = NULL) {
924 924
         $parameters = array('UserField' => $userfield, 'Channel' => $channel);
925 925
         if ($append) $parameters['Append'] = $append;
926 926
         return $this->send_request('SetCDRUserField', $parameters);
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
      * @param string $value
936 936
      * @return array
937 937
      */
938
-    function SetVar($channel, $variable, $value){
938
+    function SetVar($channel, $variable, $value) {
939 939
         return $this->send_request('SetVar', array('Channel' => $channel, 'Variable' => $variable, 'Value' => $value));
940 940
     }
941 941
 
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
      * @param string $actionid message matching variable
948 948
      * @return array
949 949
      */
950
-    function Status($channel, $actionid = NULL){
950
+    function Status($channel, $actionid = NULL) {
951 951
         $parameters = array('Channel' => $channel);
952 952
         if ($actionid) $parameters['ActionID'] = $actionid;
953 953
         return $this->send_request('Status', $parameters);
@@ -960,7 +960,7 @@  discard block
 block discarded – undo
960 960
      * @param string $channel
961 961
      * @return array
962 962
      */
963
-    function StopMonitor($channel){
963
+    function StopMonitor($channel) {
964 964
         return $this->send_request('StopMonitor', array('Channel' => $channel));
965 965
     }
966 966
 
@@ -972,7 +972,7 @@  discard block
 block discarded – undo
972 972
      * Полученире текущих регистраций.
973 973
      * @return array
974 974
      */
975
-    public function get_sip_registry(){
975
+    public function get_sip_registry() {
976 976
         $peers = array();
977 977
         $result = $this->send_request_timeout('SIPshowregistry');
978 978
         if ($result['data'] !== null && $result['data']['RegistryEntry'] !== null) {
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
     public function get_pj_sip_registry():array {
996 996
         $peers  = [];
997 997
         $result = $this->send_request_timeout('PJSIPShowRegistrationsOutbound');
998
-        if ( isset($result['data']['OutboundRegistrationDetail']) ) {
998
+        if (isset($result['data']['OutboundRegistrationDetail'])) {
999 999
             foreach ($result['data']['OutboundRegistrationDetail'] as $peer) {
1000 1000
                 [$sip, $host, $port] = explode(':', $peer['ServerUri']);
1001 1001
                 $peers[] = array(
@@ -1017,9 +1017,9 @@  discard block
 block discarded – undo
1017 1017
     public function get_pj_sip_peers():array {
1018 1018
         $peers = [];
1019 1019
         $result = $this->send_request_timeout('PJSIPShowEndpoints');
1020
-        if ( isset($result['data']['EndpointList']) ) {
1020
+        if (isset($result['data']['EndpointList'])) {
1021 1021
             foreach ($result['data']['EndpointList'] as $peer) {
1022
-                if($peer['ObjectName'] === 'anonymous'){
1022
+                if ($peer['ObjectName'] === 'anonymous') {
1023 1023
                     continue;
1024 1024
                 }
1025 1025
 
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
      * Получение статусов пиров.
1043 1043
      * @return array
1044 1044
      */
1045
-    function get_sip_peers(){
1045
+    function get_sip_peers() {
1046 1046
         $peers = array();
1047 1047
         $res = $this->send_request_timeout('SIPpeers');
1048 1048
         if (isset($res['data']) && $res['data'] != null && $res['data']['PeerEntry'] != null) {
@@ -1061,12 +1061,12 @@  discard block
 block discarded – undo
1061 1061
      * @param $peer
1062 1062
      * @return array
1063 1063
      */
1064
-    function get_sip_peer($peer){
1064
+    function get_sip_peer($peer) {
1065 1065
         $parameters = ['Peer' => trim($peer)];
1066 1066
         $res = $this->send_request_timeout('SIPshowpeer', $parameters);
1067 1067
         $arr_status          = explode(' ', $res['Status']);
1068 1068
         $res['state']        = strtoupper($arr_status[0]);
1069
-        $res['time-response']= strtoupper(str_replace(['(', ')'],'',$arr_status[1]));
1069
+        $res['time-response'] = strtoupper(str_replace(['(', ')'], '', $arr_status[1]));
1070 1070
         return $res;
1071 1071
     }
1072 1072
 
@@ -1075,15 +1075,15 @@  discard block
 block discarded – undo
1075 1075
      * @param $peer
1076 1076
      * @return array
1077 1077
      */
1078
-    function get_pj_sip_peer($peer){
1078
+    function get_pj_sip_peer($peer) {
1079 1079
         $result = [];
1080 1080
         $parameters = ['Endpoint' => trim($peer)];
1081 1081
         $res = $this->send_request_timeout('PJSIPShowEndpoint', $parameters);
1082 1082
 
1083
-        if(isset($res['data']['ContactStatusDetail'])){
1083
+        if (isset($res['data']['ContactStatusDetail'])) {
1084 1084
             $result = $res['data']['ContactStatusDetail'];
1085 1085
         }
1086
-        $result['state']  = isset($result['URI']) && !empty($result['URI']) ? 'OK' : 'UNKNOWN';
1086
+        $result['state'] = isset($result['URI']) && !empty($result['URI']) ? 'OK' : 'UNKNOWN';
1087 1087
         return $result;
1088 1088
     }
1089 1089
 
@@ -1092,17 +1092,17 @@  discard block
 block discarded – undo
1092 1092
      * @param array $vars
1093 1093
      * @return array
1094 1094
      */
1095
-    public function meetMeCollectInfo($conference, $vars=[]):array {
1095
+    public function meetMeCollectInfo($conference, $vars = []):array {
1096 1096
         $result = [];
1097 1097
         $conf_data = $this->MeetmeList($conference);
1098
-        if(!isset($conf_data['data']['MeetmeList'])){
1098
+        if (!isset($conf_data['data']['MeetmeList'])) {
1099 1099
             return $result;
1100 1100
         }
1101
-        foreach ($conf_data['data']['MeetmeList'] as $user_data){
1102
-            $user_data['linkedid']  = $this->GetVar($user_data['Channel'], 'CDR(linkedid)',  null, false);
1101
+        foreach ($conf_data['data']['MeetmeList'] as $user_data) {
1102
+            $user_data['linkedid']  = $this->GetVar($user_data['Channel'], 'CDR(linkedid)', null, false);
1103 1103
             $user_data['meetme_id'] = $this->GetVar($user_data['Channel'], 'MEETMEUNIQUEID', null, false);
1104 1104
 
1105
-            foreach ($vars as $var){
1105
+            foreach ($vars as $var) {
1106 1106
                 $user_data[$var] = $this->GetVar($user_data['Channel'], $var, null, false);
1107 1107
             }
1108 1108
 
@@ -1127,14 +1127,14 @@  discard block
 block discarded – undo
1127 1127
      * @param string $message
1128 1128
      * @param integer $level from 1 to 4
1129 1129
      */
1130
-    function log($message, $level = 1){
1130
+    function log($message, $level = 1) {
1131 1131
         if ($this->pagi != false) $this->pagi->conlog($message, $level);
1132 1132
 
1133 1133
     }
1134 1134
 
1135
-    function microtime_float(){
1135
+    function microtime_float() {
1136 1136
         list($usec, $sec) = explode(" ", microtime());
1137
-        return ((float)$usec + (float)$sec);
1137
+        return ((float) $usec + (float) $sec);
1138 1138
     }
1139 1139
 
1140 1140
     /**
@@ -1177,7 +1177,7 @@  discard block
 block discarded – undo
1177 1177
      * @param string | array $callback function
1178 1178
      * @return boolean sucess
1179 1179
      */
1180
-    function add_event_handler($event, $callback){
1180
+    function add_event_handler($event, $callback) {
1181 1181
         $event = strtolower($event);
1182 1182
         if (isset($this->event_handlers[$event])) {
1183 1183
             $this->log("$event handler is already defined, not over-writing.");
@@ -1194,21 +1194,21 @@  discard block
 block discarded – undo
1194 1194
      * @param array $parameters
1195 1195
      * @return mixed result of event handler or false if no handler was found
1196 1196
      */
1197
-    function process_event($parameters){
1197
+    function process_event($parameters) {
1198 1198
         $ret = false;
1199 1199
         $e = strtolower($parameters['Event']);
1200 1200
         $this->log("Got event.. $e");
1201 1201
 
1202 1202
         $handler = '';
1203
-        if (isset($this->event_handlers[$e])){
1203
+        if (isset($this->event_handlers[$e])) {
1204 1204
             $handler = $this->event_handlers[$e];
1205 1205
         }
1206
-        elseif (isset($this->event_handlers['*'])){
1206
+        elseif (isset($this->event_handlers['*'])) {
1207 1207
             $handler = $this->event_handlers['*'];
1208 1208
         }
1209
-        if(is_array($handler)){
1209
+        if (is_array($handler)) {
1210 1210
             call_user_func($handler, $parameters);
1211
-        }else if (function_exists($handler)) {
1211
+        } else if (function_exists($handler)) {
1212 1212
             $this->log("Execute handler $handler");
1213 1213
             $ret = $handler($e, $parameters, $this->server, $this->port);
1214 1214
         } else
Please login to merge, or discard this patch.
Braces   +228 added lines, -101 removed lines patch added patch discarded remove patch
@@ -26,7 +26,8 @@  discard block
 block discarded – undo
26 26
  * @example examples/sip_show_peer.php Get information about a sip peer
27 27
  * @package phpAGI
28 28
  */
29
-class AGI_AsteriskManager {
29
+class AGI_AsteriskManager
30
+{
30 31
     /**
31 32
      * Config variables
32 33
      *
@@ -88,18 +89,33 @@  discard block
 block discarded – undo
88 89
      * @param string $config is the name of the config file to parse or a parent agi from which to read the config
89 90
      * @param array  $optconfig is an array of configuration vars and vals, stuffed into $this->config['asmanager']
90 91
      */
91
-    function __construct($config = NULL, $optconfig = array()){
92
+    function __construct($config = NULL, $optconfig = array())
93
+    {
92 94
         // load config
93
-        if (!is_null($config) && file_exists($config)) $this->config = parse_ini_file($config, true); elseif (file_exists(DEFAULT_PHPAGI_CONFIG)) $this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIG, true);
95
+        if (!is_null($config) && file_exists($config)) {
96
+            $this->config = parse_ini_file($config, true);
97
+        } elseif (file_exists(DEFAULT_PHPAGI_CONFIG)) {
98
+            $this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIG, true);
99
+        }
94 100
 
95 101
         // If optconfig is specified, stuff vals and vars into 'asmanager' config array.
96
-        foreach ($optconfig as $var => $val) $this->config['asmanager'][$var] = $val;
102
+        foreach ($optconfig as $var => $val) {
103
+            $this->config['asmanager'][$var] = $val;
104
+        }
97 105
 
98 106
         // add default values to config for uninitialized values
99
-        if (!isset($this->config['asmanager']['server'])) $this->config['asmanager']['server'] = 'localhost';
100
-        if (!isset($this->config['asmanager']['port'])) $this->config['asmanager']['port'] = 5038;
101
-        if (!isset($this->config['asmanager']['username'])) $this->config['asmanager']['username'] = 'phpagi';
102
-        if (!isset($this->config['asmanager']['secret'])) $this->config['asmanager']['secret'] = 'phpagi';
107
+        if (!isset($this->config['asmanager']['server'])) {
108
+            $this->config['asmanager']['server'] = 'localhost';
109
+        }
110
+        if (!isset($this->config['asmanager']['port'])) {
111
+            $this->config['asmanager']['port'] = 5038;
112
+        }
113
+        if (!isset($this->config['asmanager']['username'])) {
114
+            $this->config['asmanager']['username'] = 'phpagi';
115
+        }
116
+        if (!isset($this->config['asmanager']['secret'])) {
117
+            $this->config['asmanager']['secret'] = 'phpagi';
118
+        }
103 119
     }
104 120
 
105 121
     /**
@@ -109,9 +125,12 @@  discard block
 block discarded – undo
109 125
      * @param array  $parameters
110 126
      * @return array of parameters
111 127
      */
112
-    function send_request($action, $parameters = array()){
128
+    function send_request($action, $parameters = array())
129
+    {
113 130
         $req = "Action: $action\r\n";
114
-        foreach ($parameters as $var => $val) $req .= "$var: $val\r\n";
131
+        foreach ($parameters as $var => $val) {
132
+            $req .= "$var: $val\r\n";
133
+        }
115 134
         $req .= "\r\n";
116 135
         if(!is_resource($this->socket)){
117 136
             return array();
@@ -127,9 +146,12 @@  discard block
 block discarded – undo
127 146
      * @param array  $parameters
128 147
      * @return array of parameters
129 148
      */
130
-    function send_request_timeout($action, $parameters = array()){
149
+    function send_request_timeout($action, $parameters = array())
150
+    {
131 151
         $req = "Action: $action\r\n";
132
-        foreach ($parameters as $var => $val) $req .= "$var: $val\r\n";
152
+        foreach ($parameters as $var => $val) {
153
+            $req .= "$var: $val\r\n";
154
+        }
133 155
         $req .= "\r\n";
134 156
         if(!is_resource($this->socket)){
135 157
             return array();
@@ -143,7 +165,8 @@  discard block
 block discarded – undo
143 165
      * @param string $pingname
144 166
      * @return array|bool
145 167
      */
146
-    function ping_ami_listner($pingname = 'CdrConnector'){
168
+    function ping_ami_listner($pingname = 'CdrConnector')
169
+    {
147 170
         // Установим фильтр на события.
148 171
         $params   = ['Operation'=>'Add', 'Filter' => 'Event: UserEvent'];
149 172
         $this->send_request_timeout('Filter', $params);
@@ -153,7 +176,9 @@  discard block
 block discarded – undo
153 176
             'Action'    => 'UserEvent',
154 177
             'UserEvent' => "{$pingname}Ping"
155 178
         );
156
-        foreach ($parameters as $var => $val) $req .= "$var: $val\r\n";
179
+        foreach ($parameters as $var => $val) {
180
+            $req .= "$var: $val\r\n";
181
+        }
157 182
         $req .= "\r\n";
158 183
         if(!is_resource($this->socket)){
159 184
             return array();
@@ -186,8 +211,7 @@  discard block
 block discarded – undo
186 211
 
187 212
             if($type == '' && count($this->Ping())==0){
188 213
                 $timeout = true;
189
-            }
190
-            else if('event' == $type && $parameters['Event'] == 'UserEvent' && "{$pingname}Pong" == $parameters['UserEvent']){
214
+            } else if('event' == $type && $parameters['Event'] == 'UserEvent' && "{$pingname}Pong" == $parameters['UserEvent']){
191 215
                 // Ответ получен.
192 216
                 $result = true;
193 217
                 break;
@@ -221,7 +245,7 @@  discard block
 block discarded – undo
221 245
                 if (count($m)>0) {
222 246
                     if($event_as_array){
223 247
                         $parameters['data'][$m['Event']][] = $m;
224
-                    }else{
248
+                    } else{
225 249
                         $parameters['data'][$m['Event']] = $m;
226 250
                     }
227 251
                 }
@@ -339,14 +363,15 @@  discard block
 block discarded – undo
339 363
      * @param $allow_timeout bool
340 364
      * @return array of parameters, empty on timeout
341 365
      */
342
-    function wait_user_event($allow_timeout = false){
366
+    function wait_user_event($allow_timeout = false)
367
+    {
343 368
         $timeout = false;
344 369
         do {
345 370
             $type       = '';
346 371
             $parameters = [];
347 372
             try{
348 373
                 $buffer = trim(@fgets($this->socket, 4096));
349
-            }catch (Exception $e){
374
+            } catch (Exception $e){
350 375
                 return false;
351 376
             }
352 377
             while ($buffer != '') {
@@ -361,8 +386,7 @@  discard block
 block discarded – undo
361 386
             }
362 387
             if($type == '' && count($this->Ping())==0){
363 388
                 $timeout = $allow_timeout;
364
-            }
365
-            else if('event' == $type){
389
+            } else if('event' == $type){
366 390
                 $this->process_event($parameters);
367 391
             }
368 392
         } while (!$timeout);
@@ -380,11 +404,18 @@  discard block
 block discarded – undo
380 404
      * @param string $events
381 405
      * @return boolean true on success
382 406
      */
383
-    function connect($server = NULL, $username = NULL, $secret = NULL, $events = 'on'){
407
+    function connect($server = NULL, $username = NULL, $secret = NULL, $events = 'on')
408
+    {
384 409
         // use config if not specified
385
-        if (is_null($server)) $server = $this->config['asmanager']['server'];
386
-        if (is_null($username)) $username = $this->config['asmanager']['username'];
387
-        if (is_null($secret)) $secret = $this->config['asmanager']['secret'];
410
+        if (is_null($server)) {
411
+            $server = $this->config['asmanager']['server'];
412
+        }
413
+        if (is_null($username)) {
414
+            $username = $this->config['asmanager']['username'];
415
+        }
416
+        if (is_null($secret)) {
417
+            $secret = $this->config['asmanager']['secret'];
418
+        }
388 419
 
389 420
         // get port from server if specified
390 421
         if (strpos($server, ':') !== false) {
@@ -428,7 +459,8 @@  discard block
 block discarded – undo
428 459
         return true;
429 460
     }
430 461
 
431
-    public function logged_in(){
462
+    public function logged_in()
463
+    {
432 464
         return $this->_logged_in;
433 465
     }
434 466
 
@@ -437,8 +469,11 @@  discard block
 block discarded – undo
437 469
      *
438 470
      * @example examples/sip_show_peer.php Get information about a sip peer
439 471
      */
440
-    function disconnect(){
441
-        if ($this->_logged_in == TRUE) $this->logoff();
472
+    function disconnect()
473
+    {
474
+        if ($this->_logged_in == TRUE) {
475
+            $this->logoff();
476
+        }
442 477
         if(is_resource($this->socket)){
443 478
             fclose($this->socket);
444 479
         }
@@ -458,7 +493,8 @@  discard block
 block discarded – undo
458 493
      * @param integer $timeout Maximum duration of the call (sec)
459 494
      * @return array
460 495
      */
461
-    function AbsoluteTimeout($channel, $timeout){
496
+    function AbsoluteTimeout($channel, $timeout)
497
+    {
462 498
         return $this->send_request('AbsoluteTimeout', array('Channel' => $channel, 'Timeout' => $timeout));
463 499
     }
464 500
 
@@ -470,7 +506,8 @@  discard block
 block discarded – undo
470 506
      * @param string $file the new name of the file created in the monitor spool directory.
471 507
      * @return array
472 508
      */
473
-    function ChangeMonitor($channel, $file){
509
+    function ChangeMonitor($channel, $file)
510
+    {
474 511
         return $this->send_request('ChangeMontior', array('Channel' => $channel, 'File' => $file));
475 512
     }
476 513
 
@@ -484,9 +521,12 @@  discard block
 block discarded – undo
484 521
      * @param string $actionid message matching variable
485 522
      * @return array
486 523
      */
487
-    function Command($command, $actionid = NULL){
524
+    function Command($command, $actionid = NULL)
525
+    {
488 526
         $parameters = array('Command' => $command);
489
-        if ($actionid) $parameters['ActionID'] = $actionid;
527
+        if ($actionid) {
528
+            $parameters['ActionID'] = $actionid;
529
+        }
490 530
         return $this->send_request('Command', $parameters);
491 531
     }
492 532
 
@@ -497,7 +537,8 @@  discard block
 block discarded – undo
497 537
      * @param string $eventmask is either 'on', 'off', or 'system,call,log'
498 538
      * @return array
499 539
      */
500
-    function Events($eventmask){
540
+    function Events($eventmask)
541
+    {
501 542
         return $this->send_request('Events', array('EventMask' => $eventmask));
502 543
     }
503 544
 
@@ -510,9 +551,12 @@  discard block
 block discarded – undo
510 551
      * @param string $actionid message matching variable
511 552
      * @return array
512 553
      */
513
-    function ExtensionState($exten, $context, $actionid = NULL){
554
+    function ExtensionState($exten, $context, $actionid = NULL)
555
+    {
514 556
         $parameters = array('Exten' => $exten, 'Context' => $context);
515
-        if ($actionid) $parameters['ActionID'] = $actionid;
557
+        if ($actionid) {
558
+            $parameters['ActionID'] = $actionid;
559
+        }
516 560
         return $this->send_request('ExtensionState', $parameters);
517 561
     }
518 562
 
@@ -527,7 +571,8 @@  discard block
 block discarded – undo
527 571
      * @param boolean $ret_array
528 572
      * @return string | array
529 573
      */
530
-    function GetVar($channel, $variable, $actionid = NULL, $ret_array = true){
574
+    function GetVar($channel, $variable, $actionid = NULL, $ret_array = true)
575
+    {
531 576
         $parameters = array('Channel' => $channel, 'Variable' => $variable);
532 577
         if ($actionid){
533 578
             $parameters['ActionID'] = $actionid;
@@ -545,7 +590,8 @@  discard block
 block discarded – undo
545 590
      * @param boolean $group
546 591
      * @return array
547 592
      */
548
-    public function GetChannels($group = true){
593
+    public function GetChannels($group = true)
594
+    {
549 595
         $res 	  = $this->send_request_timeout('CoreShowChannels');
550 596
         $channels = null;
551 597
         if(isset($res['data']['CoreShowChannel'])){
@@ -559,7 +605,7 @@  discard block
 block discarded – undo
559 605
                         continue;
560 606
                     }
561 607
                     $channels_id[$chan['Linkedid']][] = $chan['Channel'];
562
-                }else{
608
+                } else{
563 609
                     $channels_id[] = $chan['Channel'];
564 610
                 }
565 611
             }
@@ -575,7 +621,8 @@  discard block
 block discarded – undo
575 621
      * @param string $channel The channel name to be hungup
576 622
      * @return array
577 623
      */
578
-    function Hangup($channel){
624
+    function Hangup($channel)
625
+    {
579 626
         return $this->send_request('Hangup', array('Channel' => $channel));
580 627
     }
581 628
 
@@ -585,7 +632,8 @@  discard block
 block discarded – undo
585 632
      * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+IAXpeers
586 633
      * @return array
587 634
      */
588
-    function IAXpeerlist(){
635
+    function IAXpeerlist()
636
+    {
589 637
         $result = $this->send_request('IAXpeerlist');
590 638
         $data = (isset($result['data']) && is_array($result['data']))?$result['data']:[];
591 639
         $arr_peer = (isset($data['PeerEntry']) && is_array($data['PeerEntry']))?$data['PeerEntry']:[];
@@ -596,7 +644,8 @@  discard block
 block discarded – undo
596 644
      * Возвращает регистрации пиров.
597 645
      * @return array
598 646
      */
599
-    function IAXregistry(){
647
+    function IAXregistry()
648
+    {
600 649
         $result = $this->send_request('IAXregistry');
601 650
         $data = (isset($result['data']) && is_array($result['data']))?$result['data']:[];
602 651
         $arr_peer = (isset($data['RegistryEntry']) && is_array($data['RegistryEntry']))?$data['RegistryEntry']:[];
@@ -610,9 +659,13 @@  discard block
 block discarded – undo
610 659
      * @param string $actionid message matching variable
611 660
      * @return array
612 661
      */
613
-    function ListCommands($actionid = NULL){
614
-        if ($actionid) return $this->send_request('ListCommands', array('ActionID' => $actionid)); else
615
-            return $this->send_request('ListCommands');
662
+    function ListCommands($actionid = NULL)
663
+    {
664
+        if ($actionid) {
665
+            return $this->send_request('ListCommands', array('ActionID' => $actionid));
666
+        } else {
667
+                    return $this->send_request('ListCommands');
668
+        }
616 669
     }
617 670
 
618 671
     /**
@@ -621,7 +674,8 @@  discard block
 block discarded – undo
621 674
      * @param  array  $headers
622 675
      * @return array
623 676
      */
624
-    function UserEvent($name, $headers){
677
+    function UserEvent($name, $headers)
678
+    {
625 679
         $headers['UserEvent'] = $name;
626 680
         return $this->send_request_timeout('UserEvent', $headers);
627 681
     }
@@ -631,7 +685,8 @@  discard block
 block discarded – undo
631 685
      *
632 686
      * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Logoff
633 687
      */
634
-    function Logoff(){
688
+    function Logoff()
689
+    {
635 690
         return $this->send_request_timeout('Logoff');
636 691
     }
637 692
 
@@ -649,9 +704,12 @@  discard block
 block discarded – undo
649 704
      * @param string $actionid message matching variable
650 705
      * @return array
651 706
      */
652
-    function MailboxCount($mailbox, $actionid = NULL){
707
+    function MailboxCount($mailbox, $actionid = NULL)
708
+    {
653 709
         $parameters = array('Mailbox' => $mailbox);
654
-        if ($actionid) $parameters['ActionID'] = $actionid;
710
+        if ($actionid) {
711
+            $parameters['ActionID'] = $actionid;
712
+        }
655 713
         return $this->send_request('MailboxCount', $parameters);
656 714
     }
657 715
 
@@ -668,9 +726,12 @@  discard block
 block discarded – undo
668 726
      * @param string $actionid message matching variable
669 727
      * @return array
670 728
      */
671
-    function MailboxStatus($mailbox, $actionid = NULL){
729
+    function MailboxStatus($mailbox, $actionid = NULL)
730
+    {
672 731
         $parameters = array('Mailbox' => $mailbox);
673
-        if ($actionid) $parameters['ActionID'] = $actionid;
732
+        if ($actionid) {
733
+            $parameters['ActionID'] = $actionid;
734
+        }
674 735
         return $this->send_request('MailboxStatus', $parameters);
675 736
     }
676 737
 
@@ -684,11 +745,18 @@  discard block
 block discarded – undo
684 745
      * @param boolean $mix
685 746
      * @return array
686 747
      */
687
-    function Monitor($channel, $file = NULL, $format = NULL, $mix = NULL){
748
+    function Monitor($channel, $file = NULL, $format = NULL, $mix = NULL)
749
+    {
688 750
         $parameters = array('Channel' => $channel);
689
-        if ($file) $parameters['File'] = $file;
690
-        if ($format) $parameters['Format'] = $format;
691
-        if (!is_null($file)) $parameters['Mix'] = ($mix) ? 'true' : 'false';
751
+        if ($file) {
752
+            $parameters['File'] = $file;
753
+        }
754
+        if ($format) {
755
+            $parameters['Format'] = $format;
756
+        }
757
+        if (!is_null($file)) {
758
+            $parameters['Mix'] = ($mix) ? 'true' : 'false';
759
+        }
692 760
         return $this->send_request('Monitor', $parameters);
693 761
     }
694 762
 
@@ -702,7 +770,8 @@  discard block
 block discarded – undo
702 770
      * @param string $command
703 771
      * @return array
704 772
      */
705
-    function MixMonitor($channel, $file, $options, $command){
773
+    function MixMonitor($channel, $file, $options, $command)
774
+    {
706 775
         $parameters = array('Channel' => $channel);
707 776
         $parameters['File'] = $file;
708 777
         $parameters['options'] = $options;
@@ -717,7 +786,8 @@  discard block
 block discarded – undo
717 786
      * @param string $channel
718 787
      * @return array
719 788
      */
720
-    function StopMixMonitor($channel){
789
+    function StopMixMonitor($channel)
790
+    {
721 791
         $parameters = array('Channel' => $channel);
722 792
         return $this->send_request_timeout('StopMixMonitor', $parameters);
723 793
     }
@@ -730,7 +800,8 @@  discard block
 block discarded – undo
730 800
      * @param string $Val
731 801
      * @return array
732 802
      */
733
-    function DBPut($Family, $Key, $Val = ''){
803
+    function DBPut($Family, $Key, $Val = '')
804
+    {
734 805
         $parameters = array('Family' => $Family, 'Key' => $Key, 'Val' => $Val);
735 806
         $res_data = $this->send_request_timeout('DBPut', $parameters);
736 807
         return $res_data;
@@ -775,7 +846,8 @@  discard block
 block discarded – undo
775 846
      * @param string $Key
776 847
      * @return array
777 848
      */
778
-    function DBGet($Family, $Key){
849
+    function DBGet($Family, $Key)
850
+    {
779 851
         $parameters = array('Family' => $Family, 'Key' => $Key);
780 852
         return $this->send_request_timeout('DBGet', $parameters);
781 853
     }
@@ -798,22 +870,45 @@  discard block
 block discarded – undo
798 870
      * @param string  $actionid message matching variable
799 871
      * @return array
800 872
      */
801
-    function Originate($channel, $exten = NULL, $context = NULL, $priority = NULL, $application = NULL, $data = NULL, $timeout = NULL, $callerid = NULL, $variable = NULL, $account = NULL, $async = NULL, $actionid = NULL){
873
+    function Originate($channel, $exten = NULL, $context = NULL, $priority = NULL, $application = NULL, $data = NULL, $timeout = NULL, $callerid = NULL, $variable = NULL, $account = NULL, $async = NULL, $actionid = NULL)
874
+    {
802 875
         $parameters = array('Channel' => $channel);
803 876
 
804
-        if ($exten) $parameters['Exten'] = $exten;
805
-        if ($context) $parameters['Context'] = $context;
806
-        if ($priority) $parameters['Priority'] = $priority;
877
+        if ($exten) {
878
+            $parameters['Exten'] = $exten;
879
+        }
880
+        if ($context) {
881
+            $parameters['Context'] = $context;
882
+        }
883
+        if ($priority) {
884
+            $parameters['Priority'] = $priority;
885
+        }
807 886
 
808
-        if ($application) $parameters['Application'] = $application;
809
-        if ($data) $parameters['Data'] = $data;
887
+        if ($application) {
888
+            $parameters['Application'] = $application;
889
+        }
890
+        if ($data) {
891
+            $parameters['Data'] = $data;
892
+        }
810 893
 
811
-        if ($timeout) $parameters['Timeout'] = $timeout;
812
-        if ($callerid) $parameters['CallerID'] = $callerid;
813
-        if ($variable) $parameters['Variable'] = $variable;
814
-        if ($account) $parameters['Account'] = $account;
815
-        if (!is_null($async)) $parameters['Async'] = ($async) ? 'true' : 'false';
816
-        if ($actionid) $parameters['ActionID'] = $actionid;
894
+        if ($timeout) {
895
+            $parameters['Timeout'] = $timeout;
896
+        }
897
+        if ($callerid) {
898
+            $parameters['CallerID'] = $callerid;
899
+        }
900
+        if ($variable) {
901
+            $parameters['Variable'] = $variable;
902
+        }
903
+        if ($account) {
904
+            $parameters['Account'] = $account;
905
+        }
906
+        if (!is_null($async)) {
907
+            $parameters['Async'] = ($async) ? 'true' : 'false';
908
+        }
909
+        if ($actionid) {
910
+            $parameters['ActionID'] = $actionid;
911
+        }
817 912
 
818 913
         return $this->send_request('Originate', $parameters);
819 914
     }
@@ -826,7 +921,8 @@  discard block
 block discarded – undo
826 921
      * @param string $parkinglot message matching variable
827 922
      * @return array
828 923
      */
829
-    function ParkedCalls($parkinglot = NULL, $actionid = NULL){
924
+    function ParkedCalls($parkinglot = NULL, $actionid = NULL)
925
+    {
830 926
         $parameters = [];
831 927
         if ($actionid){
832 928
             $parameters['ActionID'] = $actionid;
@@ -844,7 +940,8 @@  discard block
 block discarded – undo
844 940
      *
845 941
      * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Ping
846 942
      */
847
-    function Ping(){
943
+    function Ping()
944
+    {
848 945
         return $this->send_request_timeout('Ping');
849 946
     }
850 947
 
@@ -857,9 +954,12 @@  discard block
 block discarded – undo
857 954
      * @param integer $penalty
858 955
      * @return array
859 956
      */
860
-    function QueueAdd($queue, $interface, $penalty = 0){
957
+    function QueueAdd($queue, $interface, $penalty = 0)
958
+    {
861 959
         $parameters = array('Queue' => $queue, 'Interface' => $interface);
862
-        if ($penalty) $parameters['Penalty'] = $penalty;
960
+        if ($penalty) {
961
+            $parameters['Penalty'] = $penalty;
962
+        }
863 963
         return $this->send_request('QueueAdd', $parameters);
864 964
     }
865 965
 
@@ -871,7 +971,8 @@  discard block
 block discarded – undo
871 971
      * @param string $interface
872 972
      * @return array
873 973
      */
874
-    function QueueRemove($queue, $interface){
974
+    function QueueRemove($queue, $interface)
975
+    {
875 976
         return $this->send_request('QueueRemove', array('Queue' => $queue, 'Interface' => $interface));
876 977
     }
877 978
 
@@ -880,7 +981,8 @@  discard block
 block discarded – undo
880 981
      *
881 982
      * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Queues
882 983
      */
883
-    function Queues(){
984
+    function Queues()
985
+    {
884 986
         return $this->send_request('Queues');
885 987
     }
886 988
 
@@ -891,9 +993,13 @@  discard block
 block discarded – undo
891 993
      * @param string $actionid message matching variable
892 994
      * @return array
893 995
      */
894
-    function QueueStatus($actionid = NULL){
895
-        if ($actionid) return $this->send_request('QueueStatus', array('ActionID' => $actionid)); else
896
-            return $this->send_request('QueueStatus');
996
+    function QueueStatus($actionid = NULL)
997
+    {
998
+        if ($actionid) {
999
+            return $this->send_request('QueueStatus', array('ActionID' => $actionid));
1000
+        } else {
1001
+                    return $this->send_request('QueueStatus');
1002
+        }
897 1003
     }
898 1004
 
899 1005
     /**
@@ -907,7 +1013,8 @@  discard block
 block discarded – undo
907 1013
      * @param string $priority
908 1014
      * @return array
909 1015
      */
910
-    function Redirect($channel, $extrachannel, $exten, $context, $priority){
1016
+    function Redirect($channel, $extrachannel, $exten, $context, $priority)
1017
+    {
911 1018
         return $this->send_request('Redirect', array('Channel' => $channel, 'ExtraChannel' => $extrachannel, 'Exten' => $exten, 'Context' => $context, 'Priority' => $priority));
912 1019
     }
913 1020
 
@@ -920,9 +1027,12 @@  discard block
 block discarded – undo
920 1027
      * @param string $append
921 1028
      * @return array
922 1029
      */
923
-    function SetCDRUserField($userfield, $channel, $append = NULL){
1030
+    function SetCDRUserField($userfield, $channel, $append = NULL)
1031
+    {
924 1032
         $parameters = array('UserField' => $userfield, 'Channel' => $channel);
925
-        if ($append) $parameters['Append'] = $append;
1033
+        if ($append) {
1034
+            $parameters['Append'] = $append;
1035
+        }
926 1036
         return $this->send_request('SetCDRUserField', $parameters);
927 1037
     }
928 1038
 
@@ -935,7 +1045,8 @@  discard block
 block discarded – undo
935 1045
      * @param string $value
936 1046
      * @return array
937 1047
      */
938
-    function SetVar($channel, $variable, $value){
1048
+    function SetVar($channel, $variable, $value)
1049
+    {
939 1050
         return $this->send_request('SetVar', array('Channel' => $channel, 'Variable' => $variable, 'Value' => $value));
940 1051
     }
941 1052
 
@@ -947,9 +1058,12 @@  discard block
 block discarded – undo
947 1058
      * @param string $actionid message matching variable
948 1059
      * @return array
949 1060
      */
950
-    function Status($channel, $actionid = NULL){
1061
+    function Status($channel, $actionid = NULL)
1062
+    {
951 1063
         $parameters = array('Channel' => $channel);
952
-        if ($actionid) $parameters['ActionID'] = $actionid;
1064
+        if ($actionid) {
1065
+            $parameters['ActionID'] = $actionid;
1066
+        }
953 1067
         return $this->send_request('Status', $parameters);
954 1068
     }
955 1069
 
@@ -960,7 +1074,8 @@  discard block
 block discarded – undo
960 1074
      * @param string $channel
961 1075
      * @return array
962 1076
      */
963
-    function StopMonitor($channel){
1077
+    function StopMonitor($channel)
1078
+    {
964 1079
         return $this->send_request('StopMonitor', array('Channel' => $channel));
965 1080
     }
966 1081
 
@@ -972,7 +1087,8 @@  discard block
 block discarded – undo
972 1087
      * Полученире текущих регистраций.
973 1088
      * @return array
974 1089
      */
975
-    public function get_sip_registry(){
1090
+    public function get_sip_registry()
1091
+    {
976 1092
         $peers = array();
977 1093
         $result = $this->send_request_timeout('SIPshowregistry');
978 1094
         if ($result['data'] !== null && $result['data']['RegistryEntry'] !== null) {
@@ -1042,12 +1158,15 @@  discard block
 block discarded – undo
1042 1158
      * Получение статусов пиров.
1043 1159
      * @return array
1044 1160
      */
1045
-    function get_sip_peers(){
1161
+    function get_sip_peers()
1162
+    {
1046 1163
         $peers = array();
1047 1164
         $res = $this->send_request_timeout('SIPpeers');
1048 1165
         if (isset($res['data']) && $res['data'] != null && $res['data']['PeerEntry'] != null) {
1049 1166
             foreach ($res['data']['PeerEntry'] as $peer) {
1050
-                if (!is_numeric($peer['ObjectName'])) continue;
1167
+                if (!is_numeric($peer['ObjectName'])) {
1168
+                    continue;
1169
+                }
1051 1170
                 // if ('Unmonitored' == $peer['Status']) continue;
1052 1171
                 $arr_status = explode(' ', $peer['Status']);
1053 1172
                 $peers[] = array('id' => $peer['ObjectName'], 'state' => strtoupper($arr_status[0]),);
@@ -1061,7 +1180,8 @@  discard block
 block discarded – undo
1061 1180
      * @param $peer
1062 1181
      * @return array
1063 1182
      */
1064
-    function get_sip_peer($peer){
1183
+    function get_sip_peer($peer)
1184
+    {
1065 1185
         $parameters = ['Peer' => trim($peer)];
1066 1186
         $res = $this->send_request_timeout('SIPshowpeer', $parameters);
1067 1187
         $arr_status          = explode(' ', $res['Status']);
@@ -1075,7 +1195,8 @@  discard block
 block discarded – undo
1075 1195
      * @param $peer
1076 1196
      * @return array
1077 1197
      */
1078
-    function get_pj_sip_peer($peer){
1198
+    function get_pj_sip_peer($peer)
1199
+    {
1079 1200
         $result = [];
1080 1201
         $parameters = ['Endpoint' => trim($peer)];
1081 1202
         $res = $this->send_request_timeout('PJSIPShowEndpoint', $parameters);
@@ -1127,12 +1248,16 @@  discard block
 block discarded – undo
1127 1248
      * @param string $message
1128 1249
      * @param integer $level from 1 to 4
1129 1250
      */
1130
-    function log($message, $level = 1){
1131
-        if ($this->pagi != false) $this->pagi->conlog($message, $level);
1251
+    function log($message, $level = 1)
1252
+    {
1253
+        if ($this->pagi != false) {
1254
+            $this->pagi->conlog($message, $level);
1255
+        }
1132 1256
 
1133 1257
     }
1134 1258
 
1135
-    function microtime_float(){
1259
+    function microtime_float()
1260
+    {
1136 1261
         list($usec, $sec) = explode(" ", microtime());
1137 1262
         return ((float)$usec + (float)$sec);
1138 1263
     }
@@ -1177,7 +1302,8 @@  discard block
 block discarded – undo
1177 1302
      * @param string | array $callback function
1178 1303
      * @return boolean sucess
1179 1304
      */
1180
-    function add_event_handler($event, $callback){
1305
+    function add_event_handler($event, $callback)
1306
+    {
1181 1307
         $event = strtolower($event);
1182 1308
         if (isset($this->event_handlers[$event])) {
1183 1309
             $this->log("$event handler is already defined, not over-writing.");
@@ -1194,7 +1320,8 @@  discard block
 block discarded – undo
1194 1320
      * @param array $parameters
1195 1321
      * @return mixed result of event handler or false if no handler was found
1196 1322
      */
1197
-    function process_event($parameters){
1323
+    function process_event($parameters)
1324
+    {
1198 1325
         $ret = false;
1199 1326
         $e = strtolower($parameters['Event']);
1200 1327
         $this->log("Got event.. $e");
@@ -1202,17 +1329,17 @@  discard block
 block discarded – undo
1202 1329
         $handler = '';
1203 1330
         if (isset($this->event_handlers[$e])){
1204 1331
             $handler = $this->event_handlers[$e];
1205
-        }
1206
-        elseif (isset($this->event_handlers['*'])){
1332
+        } elseif (isset($this->event_handlers['*'])){
1207 1333
             $handler = $this->event_handlers['*'];
1208 1334
         }
1209 1335
         if(is_array($handler)){
1210 1336
             call_user_func($handler, $parameters);
1211
-        }else if (function_exists($handler)) {
1337
+        } else if (function_exists($handler)) {
1212 1338
             $this->log("Execute handler $handler");
1213 1339
             $ret = $handler($e, $parameters, $this->server, $this->port);
1214
-        } else
1215
-            $this->log("No event handler for event '$e'");
1340
+        } else {
1341
+                    $this->log("No event handler for event '$e'");
1342
+        }
1216 1343
         return $ret;
1217 1344
     }
1218 1345
 }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      *
41 41
      * @access public
42 42
      */
43
-    public $socket = NULL;
43
+    public $socket = null;
44 44
 
45 45
     /**
46 46
      * Server we are connected to
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      * @access private
81 81
      * @var boolean
82 82
      */
83
-    private $_logged_in = FALSE;
83
+    private $_logged_in = false;
84 84
 
85 85
     /**
86 86
      * Constructor
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
      * @param string $config is the name of the config file to parse or a parent agi from which to read the config
89 89
      * @param array  $optconfig is an array of configuration vars and vals, stuffed into $this->config['asmanager']
90 90
      */
91
-    function __construct($config = NULL, $optconfig = array()){
91
+    function __construct($config = null, $optconfig = array()){
92 92
         // load config
93 93
         if (!is_null($config) && file_exists($config)) $this->config = parse_ini_file($config, true); elseif (file_exists(DEFAULT_PHPAGI_CONFIG)) $this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIG, true);
94 94
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
         $req = '';
152 152
         $parameters = array(
153 153
             'Action'    => 'UserEvent',
154
-            'UserEvent' => "{$pingname}Ping"
154
+            'UserEvent' => "{$pingname}ping"
155 155
         );
156 156
         foreach ($parameters as $var => $val) $req .= "$var: $val\r\n";
157 157
         $req .= "\r\n";
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
             if($type == '' && count($this->Ping())==0){
188 188
                 $timeout = true;
189 189
             }
190
-            else if('event' == $type && $parameters['Event'] == 'UserEvent' && "{$pingname}Pong" == $parameters['UserEvent']){
190
+            else if('event' == $type && $parameters['Event'] == 'UserEvent' && "{$pingname}pong" == $parameters['UserEvent']){
191 191
                 // Ответ получен.
192 192
                 $result = true;
193 193
                 break;
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
     public function wait_response($allow_timeout = false):array {
250 250
         $timeout = false;
251 251
         do {
252
-            $type = NULL;
252
+            $type = null;
253 253
             $parameters = array();
254 254
             if(!is_resource($this->socket)){
255 255
                 return $parameters;
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
      * @param string $events
381 381
      * @return boolean true on success
382 382
      */
383
-    function connect($server = NULL, $username = NULL, $secret = NULL, $events = 'on'){
383
+    function connect($server = null, $username = null, $secret = null, $events = 'on'){
384 384
         // use config if not specified
385 385
         if (is_null($server)) $server = $this->config['asmanager']['server'];
386 386
         if (is_null($username)) $username = $this->config['asmanager']['username'];
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
         }
398 398
 
399 399
         // connect the socket
400
-        $errno = $errstr = NULL;
400
+        $errno = $errstr = null;
401 401
         $timeout = 2;
402 402
 
403 403
         $this->socket = @fsockopen($this->server, $this->port, $errno, $errstr, $timeout);
@@ -419,12 +419,12 @@  discard block
 block discarded – undo
419 419
         // login
420 420
         $res = $this->send_request('login', array('Username' => $username, 'Secret' => $secret, 'Events' => $events));
421 421
         if ($res['Response'] != 'Success') {
422
-            $this->_logged_in = FALSE;
422
+            $this->_logged_in = false;
423 423
             $this->log("Failed to login.");
424 424
             $this->disconnect();
425 425
             return false;
426 426
         }
427
-        $this->_logged_in = TRUE;
427
+        $this->_logged_in = true;
428 428
         return true;
429 429
     }
430 430
 
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
      * @example examples/sip_show_peer.php Get information about a sip peer
439 439
      */
440 440
     function disconnect(){
441
-        if ($this->_logged_in == TRUE) $this->logoff();
441
+        if ($this->_logged_in == true) $this->logoff();
442 442
         if(is_resource($this->socket)){
443 443
             fclose($this->socket);
444 444
         }
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
      * @param string $actionid message matching variable
485 485
      * @return array
486 486
      */
487
-    function Command($command, $actionid = NULL){
487
+    function Command($command, $actionid = null){
488 488
         $parameters = array('Command' => $command);
489 489
         if ($actionid) $parameters['ActionID'] = $actionid;
490 490
         return $this->send_request('Command', $parameters);
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
      * @param string $actionid message matching variable
511 511
      * @return array
512 512
      */
513
-    function ExtensionState($exten, $context, $actionid = NULL){
513
+    function ExtensionState($exten, $context, $actionid = null){
514 514
         $parameters = array('Exten' => $exten, 'Context' => $context);
515 515
         if ($actionid) $parameters['ActionID'] = $actionid;
516 516
         return $this->send_request('ExtensionState', $parameters);
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
      * @param boolean $ret_array
528 528
      * @return string | array
529 529
      */
530
-    function GetVar($channel, $variable, $actionid = NULL, $ret_array = true){
530
+    function GetVar($channel, $variable, $actionid = null, $ret_array = true){
531 531
         $parameters = array('Channel' => $channel, 'Variable' => $variable);
532 532
         if ($actionid){
533 533
             $parameters['ActionID'] = $actionid;
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
      * @param string $actionid message matching variable
611 611
      * @return array
612 612
      */
613
-    function ListCommands($actionid = NULL){
613
+    function ListCommands($actionid = null){
614 614
         if ($actionid) return $this->send_request('ListCommands', array('ActionID' => $actionid)); else
615 615
             return $this->send_request('ListCommands');
616 616
     }
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
      * @param string $actionid message matching variable
650 650
      * @return array
651 651
      */
652
-    function MailboxCount($mailbox, $actionid = NULL){
652
+    function MailboxCount($mailbox, $actionid = null){
653 653
         $parameters = array('Mailbox' => $mailbox);
654 654
         if ($actionid) $parameters['ActionID'] = $actionid;
655 655
         return $this->send_request('MailboxCount', $parameters);
@@ -668,7 +668,7 @@  discard block
 block discarded – undo
668 668
      * @param string $actionid message matching variable
669 669
      * @return array
670 670
      */
671
-    function MailboxStatus($mailbox, $actionid = NULL){
671
+    function MailboxStatus($mailbox, $actionid = null){
672 672
         $parameters = array('Mailbox' => $mailbox);
673 673
         if ($actionid) $parameters['ActionID'] = $actionid;
674 674
         return $this->send_request('MailboxStatus', $parameters);
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
      * @param boolean $mix
685 685
      * @return array
686 686
      */
687
-    function Monitor($channel, $file = NULL, $format = NULL, $mix = NULL){
687
+    function Monitor($channel, $file = null, $format = null, $mix = null){
688 688
         $parameters = array('Channel' => $channel);
689 689
         if ($file) $parameters['File'] = $file;
690 690
         if ($format) $parameters['Format'] = $format;
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
      * @param string  $actionid message matching variable
799 799
      * @return array
800 800
      */
801
-    function Originate($channel, $exten = NULL, $context = NULL, $priority = NULL, $application = NULL, $data = NULL, $timeout = NULL, $callerid = NULL, $variable = NULL, $account = NULL, $async = NULL, $actionid = NULL){
801
+    function Originate($channel, $exten = null, $context = null, $priority = null, $application = null, $data = null, $timeout = null, $callerid = null, $variable = null, $account = null, $async = null, $actionid = null){
802 802
         $parameters = array('Channel' => $channel);
803 803
 
804 804
         if ($exten) $parameters['Exten'] = $exten;
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
      * @param string $parkinglot message matching variable
827 827
      * @return array
828 828
      */
829
-    function ParkedCalls($parkinglot = NULL, $actionid = NULL){
829
+    function ParkedCalls($parkinglot = null, $actionid = null){
830 830
         $parameters = [];
831 831
         if ($actionid){
832 832
             $parameters['ActionID'] = $actionid;
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
      * @param string $actionid message matching variable
892 892
      * @return array
893 893
      */
894
-    function QueueStatus($actionid = NULL){
894
+    function QueueStatus($actionid = null){
895 895
         if ($actionid) return $this->send_request('QueueStatus', array('ActionID' => $actionid)); else
896 896
             return $this->send_request('QueueStatus');
897 897
     }
@@ -920,7 +920,7 @@  discard block
 block discarded – undo
920 920
      * @param string $append
921 921
      * @return array
922 922
      */
923
-    function SetCDRUserField($userfield, $channel, $append = NULL){
923
+    function SetCDRUserField($userfield, $channel, $append = null){
924 924
         $parameters = array('UserField' => $userfield, 'Channel' => $channel);
925 925
         if ($append) $parameters['Append'] = $append;
926 926
         return $this->send_request('SetCDRUserField', $parameters);
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
      * @param string $actionid message matching variable
948 948
      * @return array
949 949
      */
950
-    function Status($channel, $actionid = NULL){
950
+    function Status($channel, $actionid = null){
951 951
         $parameters = array('Channel' => $channel);
952 952
         if ($actionid) $parameters['ActionID'] = $actionid;
953 953
         return $this->send_request('Status', $parameters);
Please login to merge, or discard this patch.
etc/asterisk/agi-bin/check_redirect.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 $DIALSTATUS = $agi->get_variable('DIALSTATUS', true);
15 15
 $linkedid   = $agi->get_variable('CDR(linkedid)', true);
16 16
 if($chan === '' && 'ANSWER' === $DIALSTATUS) {
17
-	exit;
17
+    exit;
18 18
 }
19 19
 // Обнуляем значение переменной.
20 20
 $agi->set_variable('BLINDTRANSFER', '');
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -13,13 +13,13 @@  discard block
 block discarded – undo
13 13
 $agi 		= new AGI();
14 14
 $DIALSTATUS = $agi->get_variable('DIALSTATUS', true);
15 15
 $linkedid   = $agi->get_variable('CDR(linkedid)', true);
16
-if($chan === '' && 'ANSWER' === $DIALSTATUS) {
16
+if ($chan === '' && 'ANSWER' === $DIALSTATUS) {
17 17
 	exit;
18 18
 }
19 19
 // Обнуляем значение переменной.
20 20
 $agi->set_variable('BLINDTRANSFER', '');
21 21
 
22
-try{
22
+try {
23 23
     $filter = [
24 24
         '(dst_chan=:chan: OR src_chan=:chan:) AND linkedid=:linkedid:',
25 25
         'bind'  => ['chan' => $chan, 'linkedid' => $linkedid],
@@ -28,18 +28,18 @@  discard block
 block discarded – undo
28 28
     ];
29 29
     $client  = new BeanstalkClient('select_cdr');
30 30
     $message = $client->request(json_encode($filter), 2);
31
-    if($message !== false){
31
+    if ($message !== false) {
32 32
         $res = json_decode($client->getBody(), true);
33
-        if(count($res) === 1){
34
-            $exten = ($res[0]['src_chan'] === $chan)?$res[0]['src_num']:$res[0]['dst_num'];
33
+        if (count($res) === 1) {
34
+            $exten = ($res[0]['src_chan'] === $chan) ? $res[0]['src_num'] : $res[0]['dst_num'];
35 35
             sleep(2);
36 36
             $agi->set_variable('pt1c_UNIQUEID', '');
37 37
             $agi->exec_goto('internal', $exten, '1');
38 38
         }
39
-    }else{
39
+    } else {
40 40
         Util::sys_log_msg('CheckRedirect', "Error get data from queue 'select_cdr'. ");
41 41
     }
42 42
 
43
-}catch (Exception $e){
43
+} catch (Exception $e) {
44 44
     Util::sys_log_msg('CheckRedirect', $e->getMessage());
45 45
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,10 +36,10 @@
 block discarded – undo
36 36
             $agi->set_variable('pt1c_UNIQUEID', '');
37 37
             $agi->exec_goto('internal', $exten, '1');
38 38
         }
39
-    }else{
39
+    } else{
40 40
         Util::sys_log_msg('CheckRedirect', "Error get data from queue 'select_cdr'. ");
41 41
     }
42 42
 
43
-}catch (Exception $e){
43
+} catch (Exception $e){
44 44
     Util::sys_log_msg('CheckRedirect', $e->getMessage());
45 45
 }
Please login to merge, or discard this patch.
etc/asterisk/agi-bin/phpagi-fastagi.php 3 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -1,79 +1,79 @@
 block discarded – undo
1 1
 #!/usr/local/bin/php -q
2 2
 <?php
3
- /**
4
-  * phpagi-fastagi.php : PHP FastAGI bootstrap
5
-  * Website: http://phpagi.sourceforge.net
6
-  *
7
-  * $Id: phpagi-fastagi.php,v 1.2 2005/05/25 18:43:48 pinhole Exp $
8
-  *
9
-  * Copyright (c) 2004, 2005 Matthew Asham <[email protected]>, David Eder <[email protected]>
10
-  * All Rights Reserved.
11
-  *
12
-  * This software is released under the terms of the GNU Lesser General Public License v2.1
13
-  * A copy of which is available from http://www.gnu.org/copyleft/lesser.html
14
-  *
15
-  * We would be happy to list your phpagi based application on the phpagi
16
-  * website.  Drop me an Email if you'd like us to list your program.
17
-  *
18
-  * @package phpAGI
19
-  * @version 2.0
20
-  * @example docs/fastagi.xinetd Example xinetd config file
21
-  */
3
+    /**
4
+     * phpagi-fastagi.php : PHP FastAGI bootstrap
5
+     * Website: http://phpagi.sourceforge.net
6
+     *
7
+     * $Id: phpagi-fastagi.php,v 1.2 2005/05/25 18:43:48 pinhole Exp $
8
+     *
9
+     * Copyright (c) 2004, 2005 Matthew Asham <[email protected]>, David Eder <[email protected]>
10
+     * All Rights Reserved.
11
+     *
12
+     * This software is released under the terms of the GNU Lesser General Public License v2.1
13
+     * A copy of which is available from http://www.gnu.org/copyleft/lesser.html
14
+     *
15
+     * We would be happy to list your phpagi based application on the phpagi
16
+     * website.  Drop me an Email if you'd like us to list your program.
17
+     *
18
+     * @package phpAGI
19
+     * @version 2.0
20
+     * @example docs/fastagi.xinetd Example xinetd config file
21
+     */
22 22
 
23
- /**
24
-  * Written for PHP 4.3.4, should work with older PHP 4.x versions.
25
-  * Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/
26
-  * Gracias. :)
27
-  *
28
-  */
23
+    /**
24
+     * Written for PHP 4.3.4, should work with older PHP 4.x versions.
25
+     * Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/
26
+     * Gracias. :)
27
+     *
28
+     */
29 29
 
30
-  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpagi.php');
30
+    require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpagi.php');
31 31
 
32
-  $fastagi = new AGI();
32
+    $fastagi = new AGI();
33 33
 
34
-  $fastagi->verbose(print_r($fastagi, true));
34
+    $fastagi->verbose(print_r($fastagi, true));
35 35
 
36
-  if(!isset($fastagi->config['fastagi']['basedir']))
36
+    if(!isset($fastagi->config['fastagi']['basedir']))
37 37
     $fastagi->config['fastagi']['basedir'] = dirname(__FILE__);
38 38
 
39
-  // perform some security checks
39
+    // perform some security checks
40 40
 
41
-  $script = $fastagi->config['fastagi']['basedir'] . DIRECTORY_SEPARATOR . $fastagi->request['agi_network_script'];
41
+    $script = $fastagi->config['fastagi']['basedir'] . DIRECTORY_SEPARATOR . $fastagi->request['agi_network_script'];
42 42
 
43
-  // in the same directory (or subdirectory)
44
-  $mydir = dirname($fastagi->config['fastagi']['basedir']) . DIRECTORY_SEPARATOR;
45
-  $dir = dirname($script) . DIRECTORY_SEPARATOR;
46
-  if(substr($dir, 0, strlen($mydir)) != $mydir)
47
-  {
43
+    // in the same directory (or subdirectory)
44
+    $mydir = dirname($fastagi->config['fastagi']['basedir']) . DIRECTORY_SEPARATOR;
45
+    $dir = dirname($script) . DIRECTORY_SEPARATOR;
46
+    if(substr($dir, 0, strlen($mydir)) != $mydir)
47
+    {
48 48
     $fastagi->conlog("$script is not allowed to execute.");
49 49
     exit;
50
-  }
50
+    }
51 51
 
52
-  // make sure it exists
53
-  if(!file_exists($script))
54
-  {
52
+    // make sure it exists
53
+    if(!file_exists($script))
54
+    {
55 55
     $fastagi->conlog("$script does not exist.");
56 56
     exit;
57
-  }
57
+    }
58 58
 
59
-  // drop privileges
60
-  if(isset($fastagi->config['fastagi']['setuid']) && $fastagi->config['fastagi']['setuid'])
61
-  {
59
+    // drop privileges
60
+    if(isset($fastagi->config['fastagi']['setuid']) && $fastagi->config['fastagi']['setuid'])
61
+    {
62 62
     $owner = fileowner($script);
63 63
     $group = filegroup($script);
64 64
     if(!posix_setgid($group) || !posix_setegid($group) || !posix_setuid($owner) || !posix_seteuid($owner))
65 65
     {
66
-      $fastagi->conlog("failed to lower privileges.");
67
-      exit;      
66
+        $fastagi->conlog("failed to lower privileges.");
67
+        exit;      
68
+    }
68 69
     }
69
-  }
70 70
 
71
-  // make sure script is still readable
72
-  if(!is_readable($script))
73
-  {
71
+    // make sure script is still readable
72
+    if(!is_readable($script))
73
+    {
74 74
     $fastagi->conlog("$script is not readable.");
75 75
     exit;
76
-  }
76
+    }
77 77
 
78
-  require_once($script);
78
+    require_once($script);
79 79
 ?>
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -27,41 +27,41 @@  discard block
 block discarded – undo
27 27
   *
28 28
   */
29 29
 
30
-  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpagi.php');
30
+  require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'phpagi.php');
31 31
 
32 32
   $fastagi = new AGI();
33 33
 
34 34
   $fastagi->verbose(print_r($fastagi, true));
35 35
 
36
-  if(!isset($fastagi->config['fastagi']['basedir']))
36
+  if (!isset($fastagi->config['fastagi']['basedir']))
37 37
     $fastagi->config['fastagi']['basedir'] = dirname(__FILE__);
38 38
 
39 39
   // perform some security checks
40 40
 
41
-  $script = $fastagi->config['fastagi']['basedir'] . DIRECTORY_SEPARATOR . $fastagi->request['agi_network_script'];
41
+  $script = $fastagi->config['fastagi']['basedir'].DIRECTORY_SEPARATOR.$fastagi->request['agi_network_script'];
42 42
 
43 43
   // in the same directory (or subdirectory)
44
-  $mydir = dirname($fastagi->config['fastagi']['basedir']) . DIRECTORY_SEPARATOR;
45
-  $dir = dirname($script) . DIRECTORY_SEPARATOR;
46
-  if(substr($dir, 0, strlen($mydir)) != $mydir)
44
+  $mydir = dirname($fastagi->config['fastagi']['basedir']).DIRECTORY_SEPARATOR;
45
+  $dir = dirname($script).DIRECTORY_SEPARATOR;
46
+  if (substr($dir, 0, strlen($mydir)) != $mydir)
47 47
   {
48 48
     $fastagi->conlog("$script is not allowed to execute.");
49 49
     exit;
50 50
   }
51 51
 
52 52
   // make sure it exists
53
-  if(!file_exists($script))
53
+  if (!file_exists($script))
54 54
   {
55 55
     $fastagi->conlog("$script does not exist.");
56 56
     exit;
57 57
   }
58 58
 
59 59
   // drop privileges
60
-  if(isset($fastagi->config['fastagi']['setuid']) && $fastagi->config['fastagi']['setuid'])
60
+  if (isset($fastagi->config['fastagi']['setuid']) && $fastagi->config['fastagi']['setuid'])
61 61
   {
62 62
     $owner = fileowner($script);
63 63
     $group = filegroup($script);
64
-    if(!posix_setgid($group) || !posix_setegid($group) || !posix_setuid($owner) || !posix_seteuid($owner))
64
+    if (!posix_setgid($group) || !posix_setegid($group) || !posix_setuid($owner) || !posix_seteuid($owner))
65 65
     {
66 66
       $fastagi->conlog("failed to lower privileges.");
67 67
       exit;      
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
   }
70 70
 
71 71
   // make sure script is still readable
72
-  if(!is_readable($script))
72
+  if (!is_readable($script))
73 73
   {
74 74
     $fastagi->conlog("$script is not readable.");
75 75
     exit;
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,8 +33,9 @@
 block discarded – undo
33 33
 
34 34
   $fastagi->verbose(print_r($fastagi, true));
35 35
 
36
-  if(!isset($fastagi->config['fastagi']['basedir']))
37
-    $fastagi->config['fastagi']['basedir'] = dirname(__FILE__);
36
+  if(!isset($fastagi->config['fastagi']['basedir'])) {
37
+      $fastagi->config['fastagi']['basedir'] = dirname(__FILE__);
38
+  }
38 39
 
39 40
   // perform some security checks
40 41
 
Please login to merge, or discard this patch.
etc/asterisk/agi-bin/clean_timeout.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,12 +10,12 @@
 block discarded – undo
10 10
 require_once 'phpagi.php';
11 11
 
12 12
 $agi = new AGI();
13
-$channel	= $agi->get_variable('MASTER_CHANNEL(M_TIMEOUT_CHANNEL)', 	true);
14
-$FROM_CHAN	= $agi->get_variable('FROM_CHAN', 	true);
13
+$channel = $agi->get_variable('MASTER_CHANNEL(M_TIMEOUT_CHANNEL)', true);
14
+$FROM_CHAN = $agi->get_variable('FROM_CHAN', true);
15 15
 
16 16
 /** @var AGI_AsteriskManager $am */
17 17
 $am = Util::get_am('off');
18
-$am->SetVar($channel,   'TIMEOUT(absolute)', '0');
18
+$am->SetVar($channel, 'TIMEOUT(absolute)', '0');
19 19
 $am->SetVar($FROM_CHAN, "MASTER_CHANNEL(M_DIALSTATUS)", 'ANSWER');
20 20
 
21 21
 // Перестрахова на случай с перехватом звонка через *8.
Please login to merge, or discard this patch.
etc/asterisk/agi-bin/phpagi-debug.php 3 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -10,83 +10,83 @@
 block discarded – undo
10 10
 *  Заглушка для отладки скрипта. 
11 11
 */
12 12
 class _AGI {
13
-	public function exec($v1, $v2){
14
-		echo "exec($v1, $v2)\n";	
15
-	}
16
-	public function answer(){
17
-		echo "answer()\n";	
18
-	}
19
-	public function get_variable($_varName){
13
+    public function exec($v1, $v2){
14
+        echo "exec($v1, $v2)\n";	
15
+    }
16
+    public function answer(){
17
+        echo "answer()\n";	
18
+    }
19
+    public function get_variable($_varName){
20 20
 		
21
-		$value = array();
22
-		$value['result']=1;
21
+        $value = array();
22
+        $value['result']=1;
23 23
 		
24
-		if('10000666' == PT1C_SKRIPTNAME){
25
-			switch ($_varName) {
26
-			    case 'v1':
27
-					$value['data']='SIP/204';
28
-			        break;
29
-			    case 'v2':
30
-					$value['data']='mikopbx-1558444069.34';
31
-			        break;
32
-			    case 'v3':
33
-					$value['data']='';
34
-			        break;
35
-			    case 'v6':
36
-					$value['data']='Records';
37
-			        break;
38
-			    case 'ASTSPOOLDIR':
39
-					$value['data']='/var/spool/asterisk';
40
-			        break;
41
-			    default:
42
-					$value['data']='';
43
-			}	
44
-		}else if('10000555' == PT1C_SKRIPTNAME){
45
-			switch ($_varName) {
46
-			    case 'v1':
47
-					$value['data']='SIP/201';
48
-			        break;
49
-			    case 'v2':
50
-					$value['data']='2017-01-01';
51
-			        break;
52
-			    case 'v3':
53
-					$value['data']='2019-01-01';
54
-			        break;
55
-			    case 'v4':
56
-					$value['data']='201-89257184254';
57
-			        break;
58
-			    default:
59
-					$value['data']='';
60
-			}	
61
-		}else if('1C_HistoryFax.php' == PT1C_SKRIPTNAME){
62
-			switch ($_varName) {
63
-			    case 'v1':
64
-					$value['data']='SIP/1000';
65
-			        break;
66
-			    case 'v2':
67
-					$value['data']='2017-01-01';
68
-			        break;
69
-			    case 'v3':
70
-					$value['data']='2019-01-01';
71
-			        break;
72
-			    default:
73
-					$value['data']='';
74
-			}	
75
-		}else if('10000777' == PT1C_SKRIPTNAME){
76
-			switch ($_varName) {
77
-			    case 'chan':
78
-					$value['data']='SIP/204';
79
-			        break;
80
-			    case 'uniqueid1c':
81
-					$value['data']='mikopbx-1519992881.0';
82
-			        break;
83
-			    case 'ASTSPOOLDIR':
84
-					$value['data']='/var/spool/asterisk';
85
-			        break;
86
-			    default:
87
-					$value['data']='';
88
-			}	
89
-		}
90
-		return $value['data'];
91
-	}
24
+        if('10000666' == PT1C_SKRIPTNAME){
25
+            switch ($_varName) {
26
+                case 'v1':
27
+                    $value['data']='SIP/204';
28
+                    break;
29
+                case 'v2':
30
+                    $value['data']='mikopbx-1558444069.34';
31
+                    break;
32
+                case 'v3':
33
+                    $value['data']='';
34
+                    break;
35
+                case 'v6':
36
+                    $value['data']='Records';
37
+                    break;
38
+                case 'ASTSPOOLDIR':
39
+                    $value['data']='/var/spool/asterisk';
40
+                    break;
41
+                default:
42
+                    $value['data']='';
43
+            }	
44
+        }else if('10000555' == PT1C_SKRIPTNAME){
45
+            switch ($_varName) {
46
+                case 'v1':
47
+                    $value['data']='SIP/201';
48
+                    break;
49
+                case 'v2':
50
+                    $value['data']='2017-01-01';
51
+                    break;
52
+                case 'v3':
53
+                    $value['data']='2019-01-01';
54
+                    break;
55
+                case 'v4':
56
+                    $value['data']='201-89257184254';
57
+                    break;
58
+                default:
59
+                    $value['data']='';
60
+            }	
61
+        }else if('1C_HistoryFax.php' == PT1C_SKRIPTNAME){
62
+            switch ($_varName) {
63
+                case 'v1':
64
+                    $value['data']='SIP/1000';
65
+                    break;
66
+                case 'v2':
67
+                    $value['data']='2017-01-01';
68
+                    break;
69
+                case 'v3':
70
+                    $value['data']='2019-01-01';
71
+                    break;
72
+                default:
73
+                    $value['data']='';
74
+            }	
75
+        }else if('10000777' == PT1C_SKRIPTNAME){
76
+            switch ($_varName) {
77
+                case 'chan':
78
+                    $value['data']='SIP/204';
79
+                    break;
80
+                case 'uniqueid1c':
81
+                    $value['data']='mikopbx-1519992881.0';
82
+                    break;
83
+                case 'ASTSPOOLDIR':
84
+                    $value['data']='/var/spool/asterisk';
85
+                    break;
86
+                default:
87
+                    $value['data']='';
88
+            }	
89
+        }
90
+        return $value['data'];
91
+    }
92 92
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -10,81 +10,81 @@
 block discarded – undo
10 10
 *  Заглушка для отладки скрипта. 
11 11
 */
12 12
 class _AGI {
13
-	public function exec($v1, $v2){
13
+	public function exec($v1, $v2) {
14 14
 		echo "exec($v1, $v2)\n";	
15 15
 	}
16
-	public function answer(){
16
+	public function answer() {
17 17
 		echo "answer()\n";	
18 18
 	}
19
-	public function get_variable($_varName){
19
+	public function get_variable($_varName) {
20 20
 		
21 21
 		$value = array();
22
-		$value['result']=1;
22
+		$value['result'] = 1;
23 23
 		
24
-		if('10000666' == PT1C_SKRIPTNAME){
24
+		if ('10000666' == PT1C_SKRIPTNAME) {
25 25
 			switch ($_varName) {
26 26
 			    case 'v1':
27
-					$value['data']='SIP/204';
27
+					$value['data'] = 'SIP/204';
28 28
 			        break;
29 29
 			    case 'v2':
30
-					$value['data']='mikopbx-1558444069.34';
30
+					$value['data'] = 'mikopbx-1558444069.34';
31 31
 			        break;
32 32
 			    case 'v3':
33
-					$value['data']='';
33
+					$value['data'] = '';
34 34
 			        break;
35 35
 			    case 'v6':
36
-					$value['data']='Records';
36
+					$value['data'] = 'Records';
37 37
 			        break;
38 38
 			    case 'ASTSPOOLDIR':
39
-					$value['data']='/var/spool/asterisk';
39
+					$value['data'] = '/var/spool/asterisk';
40 40
 			        break;
41 41
 			    default:
42
-					$value['data']='';
42
+					$value['data'] = '';
43 43
 			}	
44
-		}else if('10000555' == PT1C_SKRIPTNAME){
44
+		} else if ('10000555' == PT1C_SKRIPTNAME) {
45 45
 			switch ($_varName) {
46 46
 			    case 'v1':
47
-					$value['data']='SIP/201';
47
+					$value['data'] = 'SIP/201';
48 48
 			        break;
49 49
 			    case 'v2':
50
-					$value['data']='2017-01-01';
50
+					$value['data'] = '2017-01-01';
51 51
 			        break;
52 52
 			    case 'v3':
53
-					$value['data']='2019-01-01';
53
+					$value['data'] = '2019-01-01';
54 54
 			        break;
55 55
 			    case 'v4':
56
-					$value['data']='201-89257184254';
56
+					$value['data'] = '201-89257184254';
57 57
 			        break;
58 58
 			    default:
59
-					$value['data']='';
59
+					$value['data'] = '';
60 60
 			}	
61
-		}else if('1C_HistoryFax.php' == PT1C_SKRIPTNAME){
61
+		} else if ('1C_HistoryFax.php' == PT1C_SKRIPTNAME) {
62 62
 			switch ($_varName) {
63 63
 			    case 'v1':
64
-					$value['data']='SIP/1000';
64
+					$value['data'] = 'SIP/1000';
65 65
 			        break;
66 66
 			    case 'v2':
67
-					$value['data']='2017-01-01';
67
+					$value['data'] = '2017-01-01';
68 68
 			        break;
69 69
 			    case 'v3':
70
-					$value['data']='2019-01-01';
70
+					$value['data'] = '2019-01-01';
71 71
 			        break;
72 72
 			    default:
73
-					$value['data']='';
73
+					$value['data'] = '';
74 74
 			}	
75
-		}else if('10000777' == PT1C_SKRIPTNAME){
75
+		} else if ('10000777' == PT1C_SKRIPTNAME) {
76 76
 			switch ($_varName) {
77 77
 			    case 'chan':
78
-					$value['data']='SIP/204';
78
+					$value['data'] = 'SIP/204';
79 79
 			        break;
80 80
 			    case 'uniqueid1c':
81
-					$value['data']='mikopbx-1519992881.0';
81
+					$value['data'] = 'mikopbx-1519992881.0';
82 82
 			        break;
83 83
 			    case 'ASTSPOOLDIR':
84
-					$value['data']='/var/spool/asterisk';
84
+					$value['data'] = '/var/spool/asterisk';
85 85
 			        break;
86 86
 			    default:
87
-					$value['data']='';
87
+					$value['data'] = '';
88 88
 			}	
89 89
 		}
90 90
 		return $value['data'];
Please login to merge, or discard this patch.
Braces   +11 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,14 +9,18 @@  discard block
 block discarded – undo
9 9
 /**
10 10
 *  Заглушка для отладки скрипта. 
11 11
 */
12
-class _AGI {
13
-	public function exec($v1, $v2){
12
+class _AGI
13
+{
14
+	public function exec($v1, $v2)
15
+	{
14 16
 		echo "exec($v1, $v2)\n";	
15 17
 	}
16
-	public function answer(){
18
+	public function answer()
19
+	{
17 20
 		echo "answer()\n";	
18 21
 	}
19
-	public function get_variable($_varName){
22
+	public function get_variable($_varName)
23
+	{
20 24
 		
21 25
 		$value = array();
22 26
 		$value['result']=1;
@@ -41,7 +45,7 @@  discard block
 block discarded – undo
41 45
 			    default:
42 46
 					$value['data']='';
43 47
 			}	
44
-		}else if('10000555' == PT1C_SKRIPTNAME){
48
+		} else if('10000555' == PT1C_SKRIPTNAME){
45 49
 			switch ($_varName) {
46 50
 			    case 'v1':
47 51
 					$value['data']='SIP/201';
@@ -58,7 +62,7 @@  discard block
 block discarded – undo
58 62
 			    default:
59 63
 					$value['data']='';
60 64
 			}	
61
-		}else if('1C_HistoryFax.php' == PT1C_SKRIPTNAME){
65
+		} else if('1C_HistoryFax.php' == PT1C_SKRIPTNAME){
62 66
 			switch ($_varName) {
63 67
 			    case 'v1':
64 68
 					$value['data']='SIP/1000';
@@ -72,7 +76,7 @@  discard block
 block discarded – undo
72 76
 			    default:
73 77
 					$value['data']='';
74 78
 			}	
75
-		}else if('10000777' == PT1C_SKRIPTNAME){
79
+		} else if('10000777' == PT1C_SKRIPTNAME){
76 80
 			switch ($_varName) {
77 81
 			    case 'chan':
78 82
 					$value['data']='SIP/204';
Please login to merge, or discard this patch.
etc/rc/vendor/autoload.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,6 +8,6 @@
 block discarded – undo
8 8
 
9 9
 // autoload.php @generated by Composer
10 10
 
11
-require_once __DIR__ . '/composer/autoload_real.php';
11
+require_once __DIR__.'/composer/autoload_real.php';
12 12
 
13 13
 return ComposerAutoloaderInit6670dab4b71421eb4b91561314912df5::getLoader();
Please login to merge, or discard this patch.
etc/rc/vendor/php-school/terminal/src/InputCharacter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@
 block discarded – undo
74 74
      */
75 75
     public function isNotControl() : bool
76 76
     {
77
-        return ! $this->isControl();
77
+        return !$this->isControl();
78 78
     }
79 79
 
80 80
     /**
Please login to merge, or discard this patch.
etc/rc/vendor/php-school/terminal/src/UnixTerminal.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      */
162 162
     public function restoreOriginalConfiguration() : void
163 163
     {
164
-        exec('stty ' . $this->getOriginalConfiguration());
164
+        exec('stty '.$this->getOriginalConfiguration());
165 165
     }
166 166
 
167 167
     /**
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
     public function read(int $bytes): string
270 270
     {
271 271
         $buffer = '';
272
-        $this->input->read($bytes, function ($data) use (&$buffer) {
272
+        $this->input->read($bytes, function($data) use (&$buffer) {
273 273
             $buffer .= $data;
274 274
         });
275 275
         return $buffer;
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -269,7 +269,8 @@
 block discarded – undo
269 269
     public function read(int $bytes): string
270 270
     {
271 271
         $buffer = '';
272
-        $this->input->read($bytes, function ($data) use (&$buffer) {
272
+        $this->input->read($bytes, function ($data) use (&$buffer)
273
+        {
273 274
             $buffer .= $data;
274 275
         });
275 276
         return $buffer;
Please login to merge, or discard this patch.