@@ -344,6 +344,36 @@ function Events($eventmask)
344
344
return $ this ->send_request ('Events ' , array ('EventMask ' =>$ eventmask ));
345
345
}
346
346
347
+ /**
348
+ * Generate random ActionID
349
+ **/
350
+ function ActionID ()
351
+ {
352
+ return "A " .sprintf (rand (),"%6d " );
353
+ }
354
+
355
+ /**
356
+ *
357
+ * DBGet
358
+ * http://www.voip-info.org/wiki/index.php?page=Asterisk+Manager+API+Action+DBGet
359
+ * @param string $family key family
360
+ * @param string $key key name
361
+ **/
362
+ function DBGet ($ family , $ key , $ actionid = NULL )
363
+ {
364
+ $ parameters = array ('Family ' =>$ family , 'Key ' =>$ key );
365
+ if ($ actionid == NULL )
366
+ $ actionid = $ this ->ActionID ();
367
+ $ parameters ['ActionID ' ] = $ actionid ;
368
+ $ response = $ this ->send_request ("DBGet " , $ parameters );
369
+ if ($ response ['Response ' ] == "Success " )
370
+ {
371
+ $ response = $ this ->wait_response (false , $ actionid );
372
+ return $ response ['Val ' ];
373
+ }
374
+ return "" ;
375
+ }
376
+
347
377
/**
348
378
* Check Extension Status
349
379
*
@@ -453,7 +483,7 @@ function MailboxCount($mailbox, $actionid=NULL)
453
483
* @param string $actionid message matching variable
454
484
*/
455
485
function MailboxStatus ($ mailbox , $ actionid =NULL )
456
- {
486
+ {
457
487
$ parameters = array ('Mailbox ' =>$ mailbox );
458
488
if ($ actionid ) $ parameters ['ActionID ' ] = $ actionid ;
459
489
return $ this ->send_request ('MailboxStatus ' , $ parameters );
@@ -516,7 +546,7 @@ function Originate($channel,
516
546
if ($ actionid ) $ parameters ['ActionID ' ] = $ actionid ;
517
547
518
548
return $ this ->send_request ('Originate ' , $ parameters );
519
- }
549
+ }
520
550
521
551
/**
522
552
* List parked calls
@@ -801,6 +831,24 @@ function add_event_handler($event, $callback)
801
831
$ this ->event_handlers [$ event ] = $ callback ;
802
832
return true ;
803
833
}
834
+ /**
835
+ *
836
+ * Remove event handler
837
+ *
838
+ * @param string $event type or * for default handler
839
+ * @return boolean sucess
840
+ **/
841
+ function remove_event_handler ($ event )
842
+ {
843
+ $ event = strtolower ($ event );
844
+ if (isset ($ this ->event_handlers [$ event ]))
845
+ {
846
+ unset($ this ->event_handlers [$ event ]);
847
+ return true ;
848
+ }
849
+ $ this ->log ("$ event handler is not defined. " );
850
+ return false ;
851
+ }
804
852
805
853
/**
806
854
* Process event
@@ -813,7 +861,7 @@ function process_event($parameters)
813
861
{
814
862
$ ret = false ;
815
863
$ e = strtolower ($ parameters ['Event ' ]);
816
- $ this ->log ("Got event.. $ e " );
864
+ $ this ->log ("Got event.. $ e " );
817
865
818
866
$ handler = '' ;
819
867
if (isset ($ this ->event_handlers [$ e ])) $ handler = $ this ->event_handlers [$ e ];
@@ -823,6 +871,8 @@ function process_event($parameters)
823
871
{
824
872
$ this ->log ("Execute handler $ handler " );
825
873
$ ret = $ handler ($ e , $ parameters , $ this ->server , $ this ->port );
874
+ } elseif (is_array ($ handler )) {
875
+ $ ret = call_user_func ($ handler , $ e , $ parameters , $ this ->server , $ this ->port );
826
876
}
827
877
else
828
878
$ this ->log ("No event handler for event ' $ e' " );
0 commit comments