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) { $str .= ' von ' . str_pad($this->getNumberString($call, 'from'), 30); } else { $str .= ' nach ' . str_pad($this->getNumberString($call, 'to'), 30); } $str .= ' ' . date('H:i:s', $call->end - $call->start - 3600); return array($str . "\n", date("d.m.Y, l\n", $call->start)); } } ?>