<?php
class Stats
{
  public $stat_file = "";
  function __construct($stat_file)
  {
    $this->stat_file = $stat_file;
  }
  function writeData()
  {
    $file_str = "";
    if(file_exists($this->stat_file)){
      if(($file_str = file_get_contents($this->stat_file)) === false){
        //Błąd przy próbie odczytu zawartości pliku
        return false;
      }
    }
    if(!$fd = fopen($this->stat_file, "w")){
      //Błąd przy próbie otwarcia pliku
      return false;
    }
    $str = date("Y-m-d:G:i")." ";
    $str .= $_SERVER['REMOTE_ADDR']." ";
    if(isSet($_SERVER['HTTP_USER_AGENT'])){
      $str .= $_SERVER['HTTP_USER_AGENT'];
    }
    $str .= "\n";
    fwrite($fd, $str);
    fwrite($fd, $file_str);
    fclose($fd);
    return true;
  }

  function readData()
  {
    if(!$fd = fopen($this->stat_file, "r")){
      //Błąd przy próbie otwarcia pliku
      return false;
    }
    
    $result = "<ol>";
    while (!feof($fd)){
      if(($str = fgets($fd)) != ""){
        $result .= "<li>$str</li>\n";
      }
    }
    $result .= "</ol>";
    return $result;
  }
}
?>
