<?php
  function IsDateType($date)
  {
    //funkica zisti, ci sa $date syntaxovo podoba na datum definovany premennou $pattern
    $nums=array("0","1","2","3","4","5","6","7","8","9");
    $pattern="xxxx-xx-xx";
    $ret=true;
    if (strlen($date)==strlen($pattern)) 
    {
      for ($i=0;$i<strlen($date);$i++)
      {
        if (substr($pattern,$i,1)==="x")
        {
          if (!in_array(substr($date,$i,1),$nums))
          {
            return false;
          }
        }
        else {
          if (substr($pattern,$i,1)!==substr($date,$i,1))
          {
            return false;
          }
        }
      }
    }
    else
    {
      return false;
    }
    return true;
  }
  
  function ShortenText($text)
  {
    //funkcia skrati text
    if (strlen($text)>40)
    {
      return substr($text,0,38)."...";
    }
    else
    {
      return $text;
    }
  }
  
  function CmpAvgAscending ($a,$b)
  {
    if ($a["avg"] == $b["avg"]) return 0;
    return ($a["avg"] > $b["avg"]) ? 1 : -1;
  }
  
  function CmpAvgDescending ($a,$b)
  {
    if ($a["avg"] == $b["avg"]) return 0;
    return ($a["avg"] > $b["avg"]) ? -1 : 1;
  }
  
  function CmpDateAscending ($a,$b)
  {
    if ($a["date"] == $b["date"]) return 0;
    return ($a["date"] > $b["date"]) ? 1 : -1;
  }
  
?>
