default logging types are io, not only i
[auerswald-callnotifier.git] / src / callnotifier / Logger / CallDreambox.php
1 <?php
2 namespace callnotifier;
3
4 class Logger_CallDreambox extends Logger_CallBase
5 {
6     protected $host;
7
8     public function __construct($host, $callTypes = 'io', $msns = array())
9     {
10         parent::__construct($callTypes, $msns);
11         $this->host = $host;
12     }
13
14     public function log($type, $arData)
15     {
16         if ($type != 'startingCall') {
17             return;
18         }
19
20         $call = $arData['call'];
21         if (!$this->hasValidType($call)) {
22             return;
23         }
24         if (!$this->hasValidMsn($call)) {
25             return;
26         }
27         $this->displayStart($call);
28     }
29
30
31     protected function displayStart(CallMonitor_Call $call)
32     {
33         if ($call->type != CallMonitor_Call::INCOMING) {
34             return;
35         }
36
37         $this->addUnsetVars($call);
38
39         $msg = 'Anruf von ';
40         if ($call->fromName !== null) {
41             $msg .= $call->fromName
42                 . "\nNummer: " . $call->from;
43         } else {
44             $msg .= $call->from;
45         }
46         if ($call->fromLocation !== null) {
47             $msg .= "\nOrt: " . $call->fromLocation;
48         }
49
50         $this->notify($msg);
51     }
52
53     protected function notify($msg)
54     {
55         $url = 'http://' . $this->host
56             . '/web/message?type=2&timeout=10&text=' . urlencode($msg);
57         exec(
58             'curl'
59             . ' ' . escapeshellarg($url)
60             . ' > /dev/null 2>&1 &'
61         );
62     }
63 }
64 ?>