file = $file; $this->callTypes = $callTypes; $this->msns = (array)$msns; $fileHdl = fopen($this->file, 'a'); if (!$fileHdl) { throw new \Exception( 'Cannot open call log file for writing: ' . $this->file ); } fclose($fileHdl); } public function log($type, $arData) { if ($type != 'finishedCall') { return; } $call = $arData['call']; if (!$this->hasValidType($call)) { return; } if (!$this->hasValidMsn($call)) { return; } list($logline, $date) = $this->createLogEntry($call); $arLines = file($this->file); if (isset($arLines[0]) && $arLines[0] == $date) { //same date as previous log entry $arLines = array_pad($arLines, -count($arLines) - 1, ''); } else { $arLines = array_pad($arLines, -count($arLines) - 2, ''); } $arLines[0] = $date; $arLines[1] = $logline; //keep 50 lines only array_splice($arLines, 50); file_put_contents($this->file, implode('', $arLines)); } protected function createLogEntry(CallMonitor_Call $call) { $this->addUnsetVars($call); $str = ' ' . date('H:i', $call->start); if ($call->type == CallMonitor_Call::INCOMING) { $prefix = ' von '; $numstr = $this->getNumberString($call, 'from'); } else { $prefix = ' nach '; $numstr = $this->getNumberString($call, 'to'); } if ($this->callTypes == 'io') { $str .= $prefix; $str .= str_pad($numstr, 20); } else { $str .= ' ' . str_pad($numstr, 25); } $str .= ' ' . date('H:i:s', $call->end - $call->start - 3600); setlocale(LC_TIME, 'de_DE.utf-8'); return array($str . "\n", strftime("%x, %A\n", $call->start)); } } ?>