<?php
include('../../Common/Global.php');

$Config['Web']['ShowPHPError'] = true;
while (1)
{
  $ModifyTime = filemtime('webcam.jpg');
  if ((time() - $Config['Web']['WebcamRefresh']) >= $ModifyTime)
  {
//    $Output = shell_exec('wget "http://kamera-stred/Webcam.jpg?MobilePass='.$Config['Web']['WebcamPassword'].'&V=2&Q=2&B=2&U=0" -O webcam_cache.jpg -T '.($Config['Web']['WebcamRefresh']).' --limit-rate=200k');
    $Output = shell_exec('wget "http://kamera-knihovna/cgi-bin/viewer/video.jpg" -O webcam_cache.jpg -T '.($Config['Web']['WebcamRefresh']).' --limit-rate=200k');

    if ((strpos($Output, 'failed') === false) and (strpos($Output, 'error') === false))
      shell_exec('mv -f webcam_cache.jpg webcam.jpg');
  }
  //echo('.');
  Sleep($Config['Web']['WebcamRefresh']);
}