<?php
namespace site;

class VSite {
  
  public static function drawVisitCounter()
  {
    if ( !$visit = \System::getSessionVar( 'visit' ) )
    {
      $visit = file_get_contents( '.visit' );
      $visit ++;
      file_put_contents( '.visit', $visit );
      \System::setSessionVar( 'visit', $visit );
    }
    return '<div id="visit_counter">Odwiedziło nas: <span>' . $visit . '</span> osób</div>';
  }
  
  public function drawStaticContainer( $id )
  {
    $tpl = new \Savant3;
    $tpl -> _container = \admin\factory\SContainers::getContainer( $id );
    return $tpl -> fetch( 'other/static-container' );
  }
  
  public function drawAjaxContactForm()
  {
    $tpl = new \Savant3;
    return $tpl -> fetch( 'site/ajax-contact-form' );
  }
  
  public static function drawTitle( $title )
  {
    $tpl = new \Savant3;
    $tpl -> _title = $title;
    return $tpl -> fetch( 'site/title' );
  }
  
  public static function drawContactForm()
  {
    $tpl = new \Savant3;
    return $tpl -> fetch( 'site/contact-form' );
  }
  
  public function drawCookieInformation()
  {
    $tpl = new \Savant3;
    return $tpl -> fetch( 'other/cookie-information' );
  }
  
  public function getFacebookLikeBox()
  {
    $tpl = new \Savant3;
    return $tpl -> fetch( 'other/facebook-like-box' );
  }

  public static function drawAlert()
  {
    $tpl = new \Savant3;
    $tpl -> _alert = \System::getSessionVar( 'alert' );
    $out = $tpl -> fetch( 'other/alert' );
    
    \System::setSessionVar( 'alert', '' );
    
    return $out;
  }
  
  public static function drawAdverts()
  {
    $advert = \admin\factory\Adverts::getAcitveAdvert();
    
    if ( $advert && !\System::getSessionVar('advert_close') )
    {
      $tpl = new \Savant3;
      $tpl -> _advert = $advert;
      return $tpl -> fetch( 'other/advert' );
    }
  }
  
  public function drawSiteMapPages( $pages )
  {
    $tpl = new \Savant3;
    $tpl -> _pages = $pages;
    return $tpl -> fetch( 'site/sitemap-pages' );
  }

  public function drawSiteMap()
  {
    $sitemaps = \site\FSite::getSiteMap();
    
    $tpl = new \Savant3;
    $tpl -> _sitemaps = $sitemaps;
    return $tpl -> fetch( 'site/sitemap' );
  }

  public static function drawSearchFormFull()
  {
    global $config , $lang;

    $articles = '';
    $message  = '';

    if ( !isset( $config['search_limit'] ) )
      $limit = 10;
    else
      $limit = $config['search_limit'];

    if ( \System::formGet( 's_text' ) )
      \System::setSessionVar( 'search_text' , \System::saveString( \System::formGet( 's_text' ) , true ) );

    $text = \System::getSessionVar( 'search_text' );

    if ( $text && strlen( $text ) >= 3 )
    {
      $bs   = \System::formGet( 'bs' );
      $ls   = ceil( \article\FArticle::searchArtileByTextCount( $text ) / $limit );

      if ( $bs < 1 )
        $bs = 1;
      else if ( $bs > $ls )
        $bs = $ls;
      $from = $limit * ( $bs - 1 );
      if ( $from < 0 )
        $from = 0;

      $articles   = \article\FArticle::searchArtileByText( $text , $from , $limit );
    }
    else if ( $text )
      $message = $lang -> getTrans( 'T_MINIMALNA_ILOSC_ZNAKOW_WYSZUKIWARKA' );

    $tpl = new \Savant3;
    $tpl -> _text     = $text;
    $tpl -> _articles = $articles;
    $tpl -> _message  = $message;
    $out = $tpl -> fetch( 'site/search-results' );

    if ( isset( $ls ) && $ls > 1 )
    {
      $a    = \System::getPagingVar( "a" , $bs , $ls );
      $b    = \System::getPagingVar( "b" , $bs , $ls );
      $link = '[bs],wyszukiwarka';

      $tpl = new \Savant3;
      $tpl -> _a    = $bs-$b;
      $tpl -> _b    = $bs+$a;
      $tpl -> _ls   = $ls;
      $tpl -> _link	= $link;
      $tpl -> _bs   = $bs;
      $out .= $tpl -> fetch( 'site/paging' );
    }

    return $out;
  }

  public static function drawSearchForm()
  {
    $tpl = new \Savant3;
    return $tpl -> fetch( 'site/search-form' );
  }

  public static function drawNameDay()
  {
    $tpl = new \Savant3;
    $tpl -> _nameday = \System::getNameDay();
    return $tpl -> fetch( 'other/name-day');
  }

  public static function drawClock()
  {
    $tpl = new \Savant3;
    $tpl -> _data = \System::getFormatDate();
    return $tpl -> fetch( 'other/clock' );
  }

  public static function drawBanners()
  {
    $tpl = new \Savant3;
    $tpl -> _banners = \admin\factory\Banners::getBannersAll();
    return $tpl -> fetch( 'other/banners' );
  }

  public static function drawCopyright()
  {
    $tpl = new \Savant3;
    return $tpl -> fetch( 'other/copyright' );
  }

  public function drawGuestBook()
  {
    $tpl = new \Savant3;
    return $tpl -> fetch( 'site/guest-book' );
  }

  public function drawContactSite()
  {
    $tpl = new \Savant3;
    $tpl -> _firm_name    = \admin\factory\Settings::getSystemSettings( 'firm_name' );
    $tpl -> _street       = \admin\factory\Settings::getSystemSettings( 'street' );
    $tpl -> _city         = \admin\factory\Settings::getSystemSettings( 'city' );
    $tpl -> _postal_code  = \admin\factory\Settings::getSystemSettings( 'postal_code' );
    $tpl -> _phone        = \admin\factory\Settings::getSystemSettings( 'phone' );
    $tpl -> _fax          = \admin\factory\Settings::getSystemSettings( 'fax' );
    $tpl -> _email        = \admin\factory\Settings::getSystemSettings( 'email' );
    $tpl -> _nip          = \admin\factory\Settings::getSystemSettings( 'nip' );
    $tpl -> _contact_form = \admin\factory\Settings::getSystemSettings( 'contact_form' );
    $tpl -> _info         = \admin\factory\Settings::getSystemSettings( 'info' );
    return $tpl -> fetch( 'site/contact' );
  }

  public static function drawContactMini()
  {
    $tpl = new \Savant3;
    $tpl -> _firm_name    = \admin\factory\Settings::getSystemSettings( 'firm_name' );
    $tpl -> _street       = \admin\factory\Settings::getSystemSettings( 'street' );
    $tpl -> _city         = \admin\factory\Settings::getSystemSettings( 'city' );
    $tpl -> _postal_code  = \admin\factory\Settings::getSystemSettings( 'postal_code' );
    $tpl -> _phone        = \admin\factory\Settings::getSystemSettings( 'phone' );
    $tpl -> _fax          = \admin\factory\Settings::getSystemSettings( 'fax' );
    $tpl -> _email        = \admin\factory\Settings::getSystemSettings( 'email' );
    $tpl -> _nip          = \admin\factory\Settings::getSystemSettings( 'nip' );
    return $tpl -> fetch( 'other/contact-mini' );
  }
}
?>