<?php
namespace front\controls;
class GlobelusAdverts
{
  public static function last_adverts( $limit = 3 )
  {
    return \front\view\GlobelusAdverts::last_adverts(
              \front\factory\GlobelusAdverts::last_adverts( $limit )
            );
  }

  public static function main_page_adverts( $limit = 5 )
  {
    return \front\view\GlobelusAdverts::main_page_adverts(
              \front\factory\GlobelusAdverts::main_page_adverts( $limit )
            );
  }

  public static function top_firms( $limit = 5 )
  {
    return \front\view\GlobelusAdverts::top_firms(
              \front\factory\GlobelusAdverts::top_firms( $limit )
            );
  }

  public static function top_categories( $limit = 5 )
  {
    return \front\view\GlobelusAdverts::top_categories(
              \front\factory\GlobelusAdverts::top_categories( $limit )
            );
  }

  public static function top_countries( $limit = 5 )
  {
    return \front\view\GlobelusAdverts::top_countries(
              \front\factory\GlobelusAdverts::top_countries( $limit )
            );
  }

  public static function remove_from_favorite()
  {
    global $lang;

    if ( !\front\factory\Globelus::permissions_check( $g_user = \S::get_session( 'g_user' ), __CLASS__ . "\\" . __FUNCTION__ ) )
      return false;

    if ( \front\factory\GlobelusAdverts::remove_from_favorite( \S::get( 'advert_id' ), $g_user['id'] ) )
    {
      \S::set_alert_prompt( 'Informacja', $lang['ogloszenie-zostalo-usuniete-obserwowanych'] );
      \S::set_session( 'g_user', \front\factory\GlobelusUser::user_details( $g_user['id'] ) );
    }
    header( 'Location: ' . \S::get( 'redirect_url' ) );
    exit;
  }

  public static function add_to_favorite()
  {
    global $lang;

    if ( !\front\factory\Globelus::permissions_check( $g_user = \S::get_session( 'g_user' ), __CLASS__ . "\\" . __FUNCTION__ ) )
      return false;

    if ( \front\factory\GlobelusAdverts::add_to_favorite( \S::get( 'advert_id' ), $g_user['id'] ) )
    {
      \S::set_alert_prompt( 'Informacja', $lang['ogloszenie-zostalo-dodane-do-obserwowanych'] );
      \S::set_session( 'g_user', \front\factory\GlobelusUser::user_details( $g_user['id'] ) );
    }
    header( 'Location: ' . \S::get( 'redirect_url' ) );
    exit;
  }

  public static function send_message()
  {
    $g_user = \S::get_session( 'g_user' );

    if ( \front\factory\GlobelusAdverts::send_message( \S::get( 'advert_id' ), $g_user['id'], \S::get( 'name' ), \S::get( 'surname' ), \S::get( 'email' ), \S::get( 'phone' ), \S::get( 'text' ), $_FILES['cv'], \S::get( 'register' ) ) )
    {
      if ( \S::get( 'register' ) )
        \S::set_session( 'send_register', true );
      \S::set_session( 'send_message', true );
    }

    header( 'Location: ' . \S::get( 'redirect_url' ) );
    exit;
  }

  public static function advert_details()
  {
    global $page, $settings;

    $advert_details = \front\factory\GlobelusAdverts::advert_details( \S::get( 'advert_id' ) );
    $page['language']['meta_title'] = $advert_details['title'] . ' - ' . $advert_details['country_name'] . ' - oferta pracy | Globelus';

    $g_user = \S::get_session( 'g_user' );

    $settings['ssl'] ? $base = 'https' : $base = 'http';

    $page['language']['canonical'] = $base . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

    if ( ( !$advert_details['visible'] or $advert_details['old'] ) and $advert_details['user_id'] != $g_user['id'] ) {
      header( 'Location: /' );
      exit;
    }

    return \Tpl::view( 'globelus/adverts/advert-details', [
      'advert' => $advert_details,
      'g_user' => $g_user,
      'similar_adverts' => \front\factory\GlobelusAdverts::get_similar_adverts( $advert_details )
    ] );
  }

  public static function adverts_list()
  {
    global $page, $settings;

    if ( \S::get( 'filtr_reset' ) == true )
    {
      \S::delete_session( 'adverts-filtr-categories' );
      \S::delete_session( 'adverts-filtr-keyword' );
      \S::delete_session( 'adverts-filtr-countries' );
      \S::delete_session( 'adverts-filtr-voivodeships' );
      \S::delete_session( 'adverts-filtr-time' );
      \S::delete_session( 'adverts-filtr-work-type' );
      \S::delete_session( 'adverts-filtr-salary' );
      \S::delete_session( 'adverts-filtr-without-language' );
      \S::delete_session( 'adverts-filtr-without-experience' );
      \S::delete_session( 'adverts_filtr_for_couples' );
      \S::delete_session( 'adverts_filtr_outside_ue' );
      \S::delete_session( 'adverts_filtr_without_driving_license' );
      \S::delete_session( 'adverts_filtr_travel_refund' );
      \S::delete_session( 'adverts_filtr_sort' );
      \S::delete_session( 'adverts-filtr-countries' );
      \S::delete_session( 'adverts-filtr-categories' );
      \S::delete_session( 'adverts_filtr_accommodation_provided' );
    }

    if ( \S::get( 'filtr' ) )
    {
      \S::set_session( 'adverts-filtr-categories', \S::get( 'c1' ) );
      \S::set_session( 'adverts-filtr-keyword', \S::get( 'k' ) );
      \S::set_session( 'adverts-filtr-countries', \S::get( 'c2' ) );
      \S::set_session( 'adverts-filtr-voivodeships', \S::get( 'v' ) );
      \S::set_session( 'adverts-filtr-time', \S::get( 't' ) );
      \S::set_session( 'adverts-filtr-work-type', \S::get( 'wt' ) );
      \S::set_session( 'adverts-filtr-salary', \S::get( 'sl' ) == 'on' ? 1 : 0 );
      \S::set_session( 'adverts-filtr-without-language', \S::get( 'wl' ) == 'on' ? 1 : 0 );
      \S::set_session( 'adverts-filtr-without-experience', \S::get( 'we' ) == 'on' ? 1 : 0 );
      \S::set_session( 'adverts_filtr_for_couples', \S::get( 'fc' ) == 'on' ? 1 : 0 );
      \S::set_session( 'adverts_filtr_outside_ue', \S::get( 'oue' ) == 'on' ? 1 : 0 );
      \S::set_session( 'adverts_filtr_without_driving_license', \S::get( 'wdl' ) == 'on' ? 1 : 0 );
      \S::set_session( 'adverts_filtr_travel_refund', \S::get( 'tr' ) == 'on' ? 1 : 0 );
      \S::set_session( 'adverts_filtr_sort', (int)\S::get( 's' ) );
      \S::set_session( 'adverts_filtr_accommodation_provided', \S::get( 'ap' ) == 'on' ? 1 : 0 );

      if ( \S::get( 'cc_name' ) and $tmp_country_id = \front\factory\Globelus::country_id_by_nameseo( \S::get( 'cc_name' ) ) )
        \S::set_session( 'adverts-filtr-countries', [ 0 => $tmp_country_id ] );

      if ( \S::get( 'cc_name2' ) and $tmp_category_id = \front\factory\Globelus::category_id_by_nameseo( \S::get( 'cc_name2' ) ) )
        \S::set_session( 'adverts-filtr-categories', [ 0 => $tmp_category_id ] );
    }

    $countries = \S::get_session( 'adverts-filtr-countries' );
    $voivodeships = \S::get_session( 'adverts-filtr-voivodeships' );
    $keywords     = \S::get_session( 'adverts-filtr-keyword' );
    $categories   = \S::get_session( 'adverts-filtr-categories' );
    $time         = \S::get_session( 'adverts-filtr-time' );
    $work_type    = \S::get_session( 'adverts-filtr-work-type' );
    $salary       = \S::get_session( 'adverts-filtr-salary' );
    $without_lang = \S::get_session( 'adverts-filtr-without-language' );
    $without_exp  = \S::get_session( 'adverts-filtr-without-experience' );
    $for_couples  = \S::get_session( 'adverts_filtr_for_couples' );
    $outside_ue = \S::get_session( 'adverts_filtr_outside_ue' );
    $without_driving_license = \S::get_session( 'adverts_filtr_without_driving_license' );
    $travel_refund = \S::get_session( 'adverts_filtr_travel_refund' );
    $sort         = \S::get_session( 'adverts_filtr_sort' );
    $accommodation_provided = \S::get_session( 'adverts_filtr_accommodation_provided' );

    if ( is_array( $countries ) and count( $countries ) === 1 and $countries[0] != 75 and $countries[0] != 77 )
    {
      if ( is_array( $categories ) and count( $categories ) === 1 and !$voivodeships and !$without_lang and !$without_exp and !$for_couples and !$outside_ue and !$accommodation_provided )
      {
        $country_name   = \S::seo( \front\factory\Globelus::country_name( $countries[0] ), true );
        $category_name  = \S::seo( \front\factory\Globelus::category_name( $categories[0] ), true );
        if ( strpos( $_SERVER['REQUEST_URI'], $category_name ) === false )
        {
          if ( !$keywords and !$time )
          {
            header( 'Location: /oferty-pracy/' . $country_name . '/' . $category_name );
            exit;
          }
          else
          {
            header( 'Location: /oferty-pracy/' . $country_name . '/' . $category_name . '/' . str_replace( [ '/oferty-pracy/', '/oferty-pracy' ], [ '', '' ], $_SERVER['REQUEST_URI'] ) );
            exit;
          }
        }
      }
      else if ( $salary and !$without_lang and !$without_exp and !$for_couples and !$outside_ue and !$keywords and !$categories and !$time and !$work_type and !$voivodeships and !$accommodation_provided )
      {
        $country_name = \S::seo( \front\factory\Globelus::country_name( $countries[0] ), true );
        if ( strpos( $_SERVER['REQUEST_URI'], $country_name ) === false )
        {
          header( 'Location: /oferty-pracy/' . $country_name . '/z-podanym-wynagrodzeniem' );
          exit;
        }
      }
      else if ( !$salary and $without_lang and !$without_exp and !$for_couples and !$outside_ue and !$keywords and !$categories and !$time and !$work_type and !$voivodeships and !$accommodation_provided )
      {
        $country_name = \S::seo( \front\factory\Globelus::country_name( $countries[0] ), true );
        if ( strpos( $_SERVER['REQUEST_URI'], $country_name ) === false )
        {
          header( 'Location: /oferty-pracy/' . $country_name . '/bez-jezyka' );
          exit;
        }
      }
      else if ( !$salary and !$without_lang and $without_exp and !$for_couples and !$outside_ue and !$keywords and !$categories and !$time and !$work_type and !$voivodeships and !$accommodation_provided )
      {
        $country_name = \S::seo( \front\factory\Globelus::country_name( $countries[0] ), true );
        if ( strpos( $_SERVER['REQUEST_URI'], $country_name ) === false )
        {
          header( 'Location: /oferty-pracy/' . $country_name . '/bez-doswiadczenia' );
          exit;
        }
      }
      else if ( !$salary and !$without_lang and !$without_exp and $for_couples and !$outside_ue and !$keywords and !$categories and !$time and !$work_type and !$voivodeships and !$accommodation_provided )
      {
        $country_name = \S::seo( \front\factory\Globelus::country_name( $countries[0] ), true );
        if ( strpos( $_SERVER['REQUEST_URI'], $country_name ) === false )
        {
          header( 'Location: /oferty-pracy/' . $country_name . '/dla-par' );
          exit;
        }
      }
      else if ( !$salary and !$without_lang and !$without_exp and !$for_couples and !$outside_ue and !$keywords and !$categories and !$time and !$work_type and !$voivodeships and !$accommodation_provided )
      {
        if ( $_SERVER['REMOTE_ADDR'] == '83.24.103.179' )
        {
          var_dump( $voivodeships );
          exit;
        }
        $country_name = \S::seo( \front\factory\Globelus::country_name( $countries[0] ), true );
        if ( strpos( $_SERVER['REQUEST_URI'], $country_name ) === false )
        {
          header( 'Location: /oferty-pracy/' . $country_name . '/od-zaraz' );
          exit;
        }
      }
      else if ( !$salary and !$without_lang and !$without_exp and !$for_couples and !$outside_ue and !$keywords and !$categories and !$time and !$work_type and ( $voivodeships and count( $voivodeships ) == 1 ) and !$accommodation_provided )
      {
        $country_name = \S::seo( \front\factory\Globelus::country_name( $countries[0] ), true );
        if ( strpos( $_SERVER['REQUEST_URI'], $country_name ) === false )
        {
          header( 'Location: /oferty-pracy/' . $country_name . '/' . \front\factory\Globelus::get_voivodeship_seo( $voivodeships[0] ) );
          exit;
        }
      }
      else
      {
        $country_name = \S::seo( \front\factory\Globelus::country_name( $countries[0] ), true );
        if ( strpos( $_SERVER['REQUEST_URI'], $country_name ) === false )
        {
          if ( !$keywords and !$categories and !$time and !$work_type and !$salary and !$without_lang and !$without_exp and !$for_couples and !$outside_ue and !$voivodeships and !$accommodation_provided )
          {
            header( 'Location: /oferty-pracy/' . $country_name );
            exit;
          }
          else
          {
            header( 'Location: /oferty-pracy/' . $country_name . '/' . str_replace( [ '/oferty-pracy/', '/oferty-pracy' ], [ '', '' ], $_SERVER['REQUEST_URI'] ) );
            exit;
          }
        }
      }
    }
    else
    {
      if ( is_array( $categories ) and count( $categories ) === 1 )
      {
        $category_name  = \S::seo( \front\factory\Globelus::category_name( $categories[0] ), true );
        if ( strpos( $_SERVER['REQUEST_URI'], $category_name ) === false )
        {
          if ( !$keywords and !$countries and !$time and !$work_type and !$salary and !$without_lang and !$without_exp and !$for_couples and !$outside_ue and !$accommodation_provided )
          {
            header( 'Location: /oferty-pracy/' . $category_name );
            exit;
          }
          else
          {
            header( 'Location: /oferty-pracy/' . $category_name . '/' . str_replace( [ '/oferty-pracy/', '/oferty-pracy' ], [ '', '' ], $_SERVER['REQUEST_URI'] ) );
            exit;
          }
        }
      }
    }

    $adverts_count = \front\factory\GlobelusAdverts::adverts_count( [
                        'categories' => \S::get_session( 'adverts-filtr-categories' ),
                        'keyword' => \S::get_session( 'adverts-filtr-keyword' ),
                        'countries' => \S::get_session( 'adverts-filtr-countries' ),
                        'time' => \S::get_session( 'adverts-filtr-time' ),
                        'work_type' => \S::get_session( 'adverts-filtr-work-type' ),
                        'salary' => \S::get_session( 'adverts-filtr-salary' ),
                        'without_language' => \S::get_session( 'adverts-filtr-without-language' ),
                        'without_experience' => \S::get_session( 'adverts-filtr-without-experience' ),
                        'for_couples' => \S::get_session( 'adverts_filtr_for_couples' ),
                        'outside_ue' => \S::get_session( 'adverts_filtr_outside_ue' ),
                        'without_driving_license' => \S::get_session( 'adverts_filtr_without_driving_license' ),
                        'travel_refund' => \S::get_session( 'adverts_filtr_travel_refund' ),
                      ],
                      \S::get_session( 'adverts-filtr-voivodeships' ),
                      \S::get_session( 'adverts_filtr_accommodation_provided' )
                     );

    if ( $adverts_count > 0 and (int)\S::get( 'cp' ) > ceil( $adverts_count / \front\factory\GlobelusAdverts::advert_list_limit ) )
    {
      $query_string = preg_replace( '/\/oferty-pracy\/([0-9]*)/', '', $_SERVER['REQUEST_URI'] );
      header( 'Location: /oferty-pracy/' . $query_string );
      exit;
    }

    $adverts_filtr_countries  = \S::get_session( 'adverts-filtr-countries' );
    $adverts_filtr_categories = \S::get_session( 'adverts-filtr-categories' );

    if ( is_array( $adverts_filtr_countries ) and is_array( $adverts_filtr_categories ) )
    {
      $page['language']['meta_title'] = 'Praca ';
      foreach ( $adverts_filtr_countries as $cou_tmp )
      {
        $page['language']['meta_title'] .= \front\factory\Globelus::country_name( $cou_tmp );
        if ( $cou_tmp != end( $adverts_filtr_countries ) )
          $page['language']['meta_title'] .= ', ';
      }

      $page['language']['meta_title'] .= ', oferty pracy ';
      foreach ( $adverts_filtr_categories as $cat_tmp )
      {
        $page['language']['meta_title'] .= \front\factory\Globelus::category_name( $cat_tmp );
        if ( $cat_tmp != end( $adverts_filtr_categories ) )
          $page['language']['meta_title'] .= ', ';
      }

      $page['language']['meta_title'] .= ' - Najnowsze oferty | globelus.pl';
    }

    if ( is_array( $adverts_filtr_categories ) and !is_array( $adverts_filtr_countries ) )
    {
      $page['language']['meta_title'] = 'Praca ';
      foreach ( $adverts_filtr_categories as $cat_tmp )
      {
        $page['language']['meta_title'] .= \front\factory\Globelus::category_name( $cat_tmp );
        if ( $cat_tmp != end( $adverts_filtr_categories ) )
          $page['language']['meta_title'] .= ', ';
      }
      $page['language']['meta_title'] .= ' - Najnowsze oferty pracy | globelus.pl';
    }

    if ( !is_array( $adverts_filtr_categories ) and is_array( $adverts_filtr_countries ) and $salary and !$without_lang and !$without_exp and !$for_couples and !$keywords and !$categories and !$time and !$work_type )
    {
      $page['language']['meta_title'] = 'Praca z podanym wynagrodzeniem ';
      foreach ( $adverts_filtr_countries as $cou_tmp )
      {
        $page['language']['meta_title'] .= \front\factory\Globelus::country_name( $cou_tmp );
        if ( $cou_tmp != end( $adverts_filtr_countries ) )
          $page['language']['meta_title'] .= ', ';
      }
      $page['language']['meta_title'] .= ' - Aktualne oferty pracy | Globelus';
    }

    if ( !is_array( $adverts_filtr_categories ) and is_array( $adverts_filtr_countries ) and !$salary and $without_lang and !$without_exp and !$for_couples and !$keywords and !$categories and !$time and !$work_type )
    {
      $page['language']['meta_title'] = 'Praca bez języka ';
      foreach ( $adverts_filtr_countries as $cou_tmp )
      {
        $page['language']['meta_title'] .= \front\factory\Globelus::country_name( $cou_tmp );
        if ( $cou_tmp != end( $adverts_filtr_countries ) )
          $page['language']['meta_title'] .= ', ';
      }
      $page['language']['meta_title'] .= ' - Aktualne oferty pracy | Globelus';
    }

    if ( !is_array( $adverts_filtr_categories ) and is_array( $adverts_filtr_countries ) and !$salary and !$without_lang and $without_exp and !$for_couples and !$keywords and !$categories and !$time and !$work_type )
    {
      $page['language']['meta_title'] = 'Praca bez doświadczenia ';
      foreach ( $adverts_filtr_countries as $cou_tmp )
      {
        $page['language']['meta_title'] .= \front\factory\Globelus::country_name( $cou_tmp );
        if ( $cou_tmp != end( $adverts_filtr_countries ) )
          $page['language']['meta_title'] .= ', ';
      }
      $page['language']['meta_title'] .= ' - Aktualne oferty pracy | Globelus';
    }

    if ( !is_array( $adverts_filtr_categories ) and is_array( $adverts_filtr_countries ) and !$salary and !$without_lang and !$without_exp and $for_couples and !$keywords and !$categories and !$time and !$work_type )
    {
      $page['language']['meta_title'] = 'Praca dla par ';
      foreach ( $adverts_filtr_countries as $cou_tmp )
      {
        $page['language']['meta_title'] .= \front\factory\Globelus::country_name( $cou_tmp );
        if ( $cou_tmp != end( $adverts_filtr_countries ) )
          $page['language']['meta_title'] .= ', ';
      }
      $page['language']['meta_title'] .= ' - Aktualne oferty pracy | Globelus';
    }

    if ( !is_array( $adverts_filtr_categories ) and is_array( $adverts_filtr_countries ) )
    {
      if ( count( $adverts_filtr_countries ) === 1 )
      {
        $page['language']['title'] = 'Praca ' . str_replace( '-', '', \front\factory\Globelus::country_name( $adverts_filtr_countries[0] ) );
        $page['show_title'] = true;
      }
    }

    if ( is_array( $adverts_filtr_categories ) and !is_array( $adverts_filtr_countries ) )
    {
      if ( count( $adverts_filtr_categories ) === 1 )
      {
        $page['language']['title'] = 'Praca ' . strtolower( \front\factory\Globelus::category_name( $adverts_filtr_categories[0] ) );
        $page['show_title'] = true;
      }
    }

    $adverts_list = \front\factory\GlobelusAdverts::adverts_list( [
                        'start' => \S::get( 'cp' ),
                        'limit' => \front\factory\GlobelusAdverts::advert_list_limit,
                        'categories' => $adverts_filtr_categories,
                        'keyword' => \S::get_session( 'adverts-filtr-keyword' ),
                        'countries' => \S::get_session( 'adverts-filtr-countries' ),
                        'time' => \S::get_session( 'adverts-filtr-time' ),
                        'work_type' => \S::get_session( 'adverts-filtr-work-type' ),
                        'salary' => \S::get_session( 'adverts-filtr-salary' ),
                        'without_language' => \S::get_session( 'adverts-filtr-without-language' ),
                        'without_experience' => \S::get_session( 'adverts-filtr-without-experience' ),
                        'for_couples' => \S::get_session( 'adverts_filtr_for_couples' ),
                        'outside_ue' => \S::get_session( 'adverts_filtr_outside_ue' ),
                        'without_driving_license' => \S::get_session( 'adverts_filtr_without_driving_license' ),
                        'travel_refund' => \S::get_session( 'adverts_filtr_travel_refund' ),
                        'sort' => \S::get_session( 'adverts_filtr_sort' )
                      ],
                      \S::get_session( 'adverts-filtr-voivodeships' ),
                      \S::get_session( 'adverts_filtr_accommodation_provided' )
                    );

    if ( \S::get( 'cp' ) > 0 )
    {
      $query_string = preg_replace( '/oferty-pracy/', '', $_SERVER['REQUEST_URI'] );
      $query_string = preg_replace( '/([0-9]*)/', '', $query_string );
      $query_string = preg_replace( '/\?/', '', $query_string );
      $query_string = preg_replace( '/\//', '', $query_string );

      if ( strpos( $query_string, $category_name ) !== false )
        $query_string = str_replace( $category_name, '', $query_string );

      if ( strpos( $query_string, $country_name ) !== false )
        $query_string = str_replace( $country_name, '', $query_string );

      $url = 'oferty-pracy';

      if ( $country_name )
        $url .= '/' . $country_name;

      if ( $category_name )
        $url .= '/' . $category_name;

      $settings['ssl'] ? $base = 'https' : $base = 'http';

      $url = $base . '://' . $_SERVER['SERVER_NAME'] . '/' . $url;

      if ( \S::get( 'cp' ) > 1 )
        $page['language']['noindex'] = '1';
    }

    return \Tpl::view( 'globelus/adverts/adverts-list', [
      'values' => [
              'adverts' => $adverts_list,
              'adverts_count' => $adverts_count,
              'country_name' => $country_name,
              'category_name' => $category_name,
              'categories' => \front\factory\GlobelusAdverts::categories(),
              'countries' => \front\factory\Globelus::countries(),
              'work_types' => \front\factory\Globelus::work_types(),
              'f_categories' => $adverts_filtr_categories,
              'f_keyword' => \S::get_session( 'adverts-filtr-keyword' ),
              'f_countries' => \S::get_session( 'adverts-filtr-countries' ),
              'f_time' => \S::get_session( 'adverts-filtr-time' ),
              'f_work_type' => \S::get_session( 'adverts-filtr-work-type' ),
              'f_salary' => \S::get_session( 'adverts-filtr-salary' ),
              'f_without_language' => \S::get_session( 'adverts-filtr-without-language' ),
              'f_without_experience' => \S::get_session( 'adverts-filtr-without-experience' ),
              'f_for_couples' => \S::get_session( 'adverts_filtr_for_couples' ),
              'f_outside_ue' => \S::get_session( 'adverts_filtr_outside_ue' ),
              'f_without_driving_license' => \S::get_session( 'adverts_filtr_without_driving_license' ),
              'f_travel_refund' => \S::get_session( 'adverts_filtr_travel_refund' ),
            ],
      'voivodeships' => \front\factory\Globelus::get_voivodeships_list(),
      'f_voivodeships' => \S::get_session( 'adverts-filtr-voivodeships' ),
      'f_accommodation_provided' => \S::get_session( 'adverts_filtr_accommodation_provided' )
    ] );
  }

  static public function advert_apply() {

    $g_user = \S::get_session( 'g_user' );

    return \Tpl::view( 'globelus/adverts/advert-apply', [
      'advert' => \front\factory\GlobelusAdverts::advert_details( \S::get( 'advert_id' ) ),
      'g_user' => $g_user,
      'send_message' => \S::get_session( 'send_message' ),
      'send_register' => \S::get_session( 'send_register' )
    ] );
  }
}
