<? global $lang;?>
<div class="row">
  <div class="col-12 col-sm-4 col-md-3">
    <div class="advert-filtr">
      <form method="GET" action="/oferty-pracy">
        <input type="hidden" name="filtr" value="t">
        <div class="title"><?= $lang['filtry-wyszukiwania'];?><i class="fa fa-chevron-down"</i></div>
        <div class="content">
          <div class="subtitle"><?= ucfirst( $lang['slowo-kluczowe'] );?></div>
          <div class="subcontent" style="display: block;">
            <input type="text" name="k" class="form-control" value="<?= htmlspecialchars( $this -> values['f_keyword'] );?>" placeholder="<?= $lang['wpisz-szukane-slowo-kluczowe'];?>">
          </div>
          <div class="subtitle toggle" content="categories"><?= ucfirst( $lang['kategorie'] );?></div>
          <div class="subcontent" id="subcontent-categories">
            <ul>
              <? if ( is_array( $this -> values['categories'] ) ): foreach ( $this -> values['categories'] as $category ):?>
                <li <? if ( ++$i > 5 ):?> style="display: none;"<? endif;?>>
                  <input class="checkbox" type="checkbox" name="c1[]" value="<?= $category['id'];?>" <? if ( in_array( $category['id'], $this -> values['f_categories'] ) ):?>checked="checked"<? endif;?>><?= $category['name'];?>
                </li>
              <? endforeach; endif;?>
            </ul>
            <a href="#" class="btn btn-primary show-more" content="subcontent-categories">więcej</a>
          </div>
          <div class="subtitle toggle" content="countries"><?= ucfirst( $lang['kraj'] );?></div>
          <div class="subcontent" id="subcontent-countries">
            <ul>
              <? if ( is_array( $this -> values['countries'] ) ): foreach ( $this -> values['countries'] as $country ):?>
                <li <? if ( ++$j > 5 ):?> style="display: none;"<? endif;?>>
                  <input class="checkbox country_select" type="checkbox" name="c2[]" value="<?= $country['id'];?>" <? if ( in_array( $country['id'], $this -> values['f_countries'] ) ):?>checked="checked"<? endif;?>><?= $country['name'];?>
                </li>
              <? endforeach; endif;?>
            </ul>
            <a href="#" class="btn btn-primary show-more" content="subcontent-countries">więcej</a>
          </div>
          <div class="subtitle toggle" content="voivodeships">Województwo (tylko Polska)</div>
          <div class="subcontent" id="subcontent-voivodeships">
            <ul>
              <? if ( is_array( $this -> voivodeships ) ): foreach ( $this -> voivodeships as $voivodeship ):?>
                <li <? if ( ++$k > 5 ):?> style="display: none;"<? endif;?>>
                  <input class="checkbox voivodeships_select" type="checkbox" name="v[]" value="<?= $voivodeship['id'];?>" <? if ( in_array( $voivodeship['id'], $this -> f_voivodeships ) ):?>checked="checked"<? endif;?>><?= $voivodeship['name'];?>
                </li>
              <? endforeach; endif;?>
            </ul>
            <a href="#" class="btn btn-primary show-more" content="subcontent-voivodeships">więcej</a>
          </div>
          <div class="subtitle toggle" content="time"><?= ucfirst( $lang['oferty-z-okresu'] );?></div>
          <div class="subcontent" id="subcontent-time">
            <ul>
              <li>
                <input class="checkbox" type="radio" name="t" value="0" <? if ( !$this -> values['f_time'] ):?>checked="checked"<? endif;?>> <?= $lang['wszystkie'];?>
              </li>
              <li>
                <input class="checkbox" type="radio" name="t" value="1" value="1" <? if ( $this -> values['f_time'] == 1 ):?>checked="checked"<? endif;?>> <?= $lang['filtr-okres-1'];?>
              </li>
              <li>
                <input class="checkbox" type="radio" name="t" value="2" value="2" <? if ( $this -> values['f_time'] == 2 ):?>checked="checked"<? endif;?>> <?= $lang['filtr-okres-2'];?>
              </li>
              <li>
                <input class="checkbox" type="radio" name="t" value="3" value="3" <? if ( $this -> values['f_time'] == 3 ):?>checked="checked"<? endif;?>> <?= $lang['filtr-okres-3'];?>
              </li>
              <li>
                <input class="checkbox" type="radio" name="t" value="4" value="4" <? if ( $this -> values['f_time'] == 4 ):?>checked="checked"<? endif;?>> <?= $lang['filtr-okres-4'];?>
              </li>
              <li style="display: none;">
                <input class="checkbox" type="radio" name="t" value="5" value="5" <? if ( $this -> values['f_time'] == 5 ):?>checked="checked"<? endif;?>> <?= $lang['filtr-okres-5'];?>
              </li>
              <li style="display: none;">
                <input class="checkbox" type="radio" name="t" value="6" value="6" <? if ( $this -> values['f_time'] == 6 ):?>checked="checked"<? endif;?>> <?= $lang['filtr-okres-6'];?>
              </li>
            </ul>
            <a href="#" class="btn btn-primary show-more" content="subcontent-time">więcej</a>
          </div>
          <div class="subtitle toggle" content="work-type"><?= ucfirst( \S::lang( 'rodzaj-pracy' ) );?></div>
          <div class="subcontent" id="subcontent-work-type">
            <ul>
              <? foreach ( $this -> values['work_types'] as $key => $val ):?>
                <li <? if ( ++$l > 4 ):?> style="display: none;"<? endif;?>>
                  <input class="checkbox work_type_select" type="checkbox" name="wt[]" value="<?= $key;?>" <? if ( in_array( $key, $this -> values['f_work_type'] ) ):?>checked="checked"<? endif;?>> <?= $val;?>
                </li>
              <? endforeach;?>
            </ul>
            <a href="#" class="btn btn-primary show-more" content="subcontent-work-type">więcej</a>
          </div>
          <div class="subtitle toggle" content="other">Inne kryteria</div>
          <div class="subcontent" id="subcontent-other">
            <ul>
              <li>
                <input class="checkbox" type="checkbox" name="wl" <? if ( $this -> values['f_without_language'] ):?>checked="checked"<? endif;?>> bez znajomości języka obcego
              </li>
              <li>
                <input class="checkbox" type="checkbox" name="we" <? if ( $this -> values['f_without_experience'] ):?>checked="checked"<? endif;?>> bez doświadczenia
              </li>
              <li>
                <input class="checkbox" type="checkbox" name="fc" <? if ( $this -> values['f_for_couples'] ):?>checked="checked"<? endif;?>> dla par
              </li>
              <li>
                <input class="checkbox" type="checkbox" name="ap" <? if ( $this -> f_accommodation_provided ):?>checked="checked"<? endif;?>> zapewnione zakwaterowanie
              </li>
            </ul>
            <a href="#" class="btn btn-primary show-more" content="subcontent-other">więcej</a>
          </div>
        </div>
        <input type="submit" class="btn btn-success pull-right mt10" value="<?= $lang['zatwierdz'];?>">
      </form>
    </div>
  </div>
  <div class="col-12 col-sm-8 col-md-9">
    <div class="adverts-filtr-text">
      <? if ( $this -> values['f_categories'] or $this -> values['f_countries'] or $this -> f_voivodeships or $this -> values['f_time'] or $this -> values['f_work_type'] or $this -> values['f_without_language'] or $this -> values['f_without_experience'] or $this -> values['f_for_couples'] or $this -> f_accommodation_provided ):?>
        Oferty pracy:
        <? foreach ( $this -> values['f_categories'] as $category ):?><strong><?= \front\factory\Globelus::get_category_name( $category );?></strong>, <? endforeach;?>
        <? if ( $this -> values['f_countries'] ):?>
          kraje:
          <? foreach ( $this -> values['f_countries'] as $country ):?><strong><?= str_replace( '-', '', \front\factory\Globelus::get_country_name( $country ) );?></strong>, <? endforeach;?>
        <? endif;?>
        <? foreach ( $this -> f_voivodeships as $voivodeship ):?><strong><?= \front\factory\Globelus::get_voivodeship_name( $voivodeship );?></strong>, <? endforeach;?>
        <? if ( $this -> values['f_time'] == 1 ):?>z okresu: <strong><?= $lang['filtr-okres-1'];?></strong>, <? endif;?>
        <? if ( $this -> values['f_time'] == 2 ):?>z okresu: <strong><?= $lang['filtr-okres-2'];?></strong>, <? endif;?>
        <? if ( $this -> values['f_time'] == 3 ):?>z okresu: <strong><?= $lang['filtr-okres-3'];?></strong>, <? endif;?>
        <? if ( $this -> values['f_time'] == 4 ):?>z okresu: <strong><?= $lang['filtr-okres-4'];?></strong>, <? endif;?>
        <? if ( $this -> values['f_time'] == 5 ):?>z okresu: <strong><?= $lang['filtr-okres-5'];?></strong>, <? endif;?>
        <? if ( $this -> values['f_time'] == 6 ):?>z okresu: <strong><?= $lang['filtr-okres-6'];?></strong>, <? endif;?>
        <? if ( $this -> values['f_work_type'] and ( count( $this -> values['f_work_type'] ) > 1 or count( $this -> values['f_work_type'] ) == 1 and $this -> values['f_work_type'][0] != 0 ) ):?>
          <?
            $work_types = \front\factory\Globelus::work_types();
          ?>
          rodzaj pracy:
          <? foreach ( $this -> values['f_work_type'] as $work_type ):?><strong><?= $work_types[ $work_type ];?></strong>, <? endforeach;?>
        <? endif;?>
        <? if ( $this -> values['f_without_language'] or $this -> values['f_without_experience'] or $this -> values['f_for_couples'] or $this -> f_accommodation_provided ):?>
          inne:
        <? endif;?>
        <? if ( $this -> values['f_without_language'] ):?><strong><?= $lang['bez-znajomosci-jezyka'];?></strong>, <? endif;?>
        <? if ( $this -> values['f_without_experience'] ):?><strong><?= $lang['bez-doswiadczenia'];?></strong>, <? endif;?>
        <? if ( $this -> values['f_for_couples'] ):?><strong><?= $lang['dla-par'];?></strong>, <? endif;?>
        <? if ( $this -> f_accommodation_provided ):?><strong>zapewnione zakwaterowanie</strong>, <? endif;?>
      <? endif;?>
    </div>
    <? if ( is_array( $this -> values['adverts'] ) and count( $this -> values['adverts']) ):?>
      <? foreach ( $this -> values['adverts'] as $advert ):?>
        <div class="advert-entry <? if ( $advert['highlight'] ):?>highlight<? endif;?>">
          <? if ( $advert['highlight'] ):?><div id="highlight-text">Oferta wyróżniona</div><? endif;?>
          <div class="row">
            <div class="col-12 col-lg-2">
              <div class="logo">
                <? if ( file_exists( \front\factory\GlobelusFirms::logo_url( $advert['user_id'] ) ) ):?>
                  <img src="/logo/<?= $advert['user_id'];?>/<?= \S::get_token();?>">
                <? else:?>
                  <img src="/images/no-logo.jpg">
                <? endif;?>
              </div>
            </div>
            <div class="col-12 col-lg-10">
              <div class="row">
                <div class="col-12 col-lg-9">
                  <a class="title" href="/oferta/<?= $advert['id'];?>/<?= \S::seo( $advert['title'], true );?>" title="Ogłoszenie: <?= addslashes( $advert['title'] );?>"><?= $advert['title'];?></a>
                </div>
                <div class="col-12 col-lg-3 date-add">
                  <?= date( 'Y-m-d', strtotime( $advert['date_active'] ) );?>
                  <div class="flag">
                    <? if ( file_exists( 'upload/filemanager/flags/' . \S::seo( $advert['country'] ) . '.jpg' ) ):?>
                      <img src="/upload/filemanager/flags/<?= \S::seo( $advert['country'] );?>.jpg">
                    <? endif;?>
                  </div>
                </div>
              </div>
              <div class="info">
                <span class="place">
                  <a href="/oferty-pracy/<?= \S::seo( $advert['country'], true );?>" title="praca <?= $adver['country'];?>"><?= $advert['country'];?></a> - <?= $advert['city'];?>
                </span> | <a href="/pracodawca/<?= $advert['user_id'];?>/<?= \S::seo( $advert['firm_name_profile'] );?>" class="firm"><?= $advert['firm_name_profile'];?></a> |
                <span class="category">
                  <a href="/oferty-pracy/<?= \S::seo( $advert['category'], true );?>" title="praca <?= $advert['category'];?>"><?= $advert['category'];?></a>
                </span>
              </div>
              <div class="icons">
                <? if ( trim( $advert['salary'] ) ):?>
                  <div class="_content">
                    <div class="_icon">
                      <img src="/images/icon-money.svg">
                    </div>
                    <div class="_text">
                      <?= $advert['salary'];?>
                    </div>
                  </div>
                <? endif; ?>
                <? if ($advert['overtime']) : ?>
                  <div class="_content">
                    <div class="_icon">
                      <img src="/images/icon-time.svg">
                    </div>
                    <div class="_text">
                      <?= $advert['overtime_quantity']; ?>
                    </div>
                  </div>
                <? endif; ?>
                <? if ($advert['accommodation']) : ?>
                  <div class="_content">
                    <div class="_icon">
                      <img src="/images/icon-bed.svg">
                    </div>
                    <div class="_text">
                      <?= $advert['accommodation_cost']; ?>
                    </div>
                  </div>
                <? endif; ?>
                <? if ($advert['travel_refund']) : ?>
                  <div class="_content">
                    <div class="_icon">
                      <img src="/images/icon-plane.svg">
                    </div>
                    <div class="_text">
                      refundacja przejazdu
                    </div>
                  </div>
                <? endif; ?>
                <? if ($advert['work_type']) : ?>
                  <div class="_content">
                    <div class="_icon">
                      <img src="/images/icon-plane.svg">
                    </div>
                    <div class="_text">
                      <? $work_type = \front\factory\Globelus::work_types();
                      echo $work_type[$advert['work_type']]; ?>
                    </div>
                  </div>
                <? endif; ?>
                <? if ($advert['without_experience']) : ?>
                  <div class="_content">
                    <div class="_icon">
                      <img src="/images/icon-case.svg">
                    </div>
                    <div class="_text">
                      <?= \S::lang('bez-doswiadczenia'); ?>
                    </div>
                  </div>
                <? endif; ?>
                <? if ($advert['without_language']) : ?>
                  <div class="_content">
                    <div class="_icon">
                      <img src="/images/icon-lang.svg">
                    </div>
                    <div class="_text">
                      <?= \S::lang('bez-znajomosci-jezyka'); ?>
                    </div>
                  </div>
                <? endif; ?>
                <? if ($advert['for_couples']) : ?>
                  <div class="_content">
                    <div class="_icon">
                      <img src="/images/icon-couple.svg">
                    </div>
                    <div class="_text">
                      <?= \S::lang('dla-par'); ?>
                    </div>
                  </div>
                <? endif; ?>
                <? if ($advert['outside_ue']) : ?>
                  <div class="_content">
                    <div class="_icon">
                      <img src="/images/icon-ue.svg">
                    </div>
                    <div class="_text">
                      dla obywateli spoza UE
                    </div>
                  </div>
                <? endif; ?>
                <? if ($advert['without_driving_license']) : ?>
                  <div class="_content">
                    <div class="_icon">
                      <img src="/images/icon-car.svg">
                    </div>
                    <div class="_text">
                      bez prawa jazdy
                    </div>
                  </div>
                <? endif; ?>
              </div>
              <div class="text-right">
                <a href="/oferta/<?= $advert['id'];?>/<?= \S::seo( $advert['title'], true );?>" class="btn btn-success"><?= $lang['szczegoly-oferty'];?></a>
              </div>
            </div>
          </div>
        </div>
      <? endforeach;?>
    <? else:?>
      <div class="alert"><?= $lang['brak-ogloszen-o-prace'];?></div>
    <? endif;?>
    <?
      if ( \S::get( 'cp' ) == 1 )
      {
        $query_string = preg_replace( '/\/oferty-pracy/', '', $_SERVER['REQUEST_URI'] );
        $query_string = preg_replace( '/\//', '', $query_string );
        $query_string = preg_replace( '/\?/', '', $query_string );
      }
      else
      {
        $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, $this -> values['category_name'] ) !== false )
        $query_string = str_replace( $this -> values['category_name'], '', $query_string );

      if ( strpos( $query_string, $this -> values['country_name'] ) !== false )
        $query_string = str_replace( $this -> values['country_name'], '', $query_string );

      if ( $this -> values['f_for_couples'] )
        $query_string = str_replace( 'dla-par', '', $query_string );

      if ( $this -> values['f_without_experience'] )
        $query_string = str_replace( 'bez-doswiadczenia', '', $query_string );

      if ( $this -> values['f_without_language'] )
        $query_string = str_replace( 'bez-jezyka', '', $query_string );

      if ( $this -> values['f_salary'] )
        $query_string = str_replace( 'z-podanym-wynagrodzeniem', '', $query_string );

      $document_uri = explode( '?', $_SERVER['REQUEST_URI'], 2 );
      $document_uri = $document_uri[0];

      $url = substr( $document_uri, 1, strlen( $document_uri ) );
      $url_tmp = explode( '/', $url );

      if ( (int)$url_tmp[ count( $url_tmp ) - 1 ] ) {
        $url = '';
        for ( $i = 0; $i < count( $url_tmp ) - 1; $i++ ) {
          $url .= $url_tmp[$i];
          if ( $i != count( $url_tmp ) - 2 )
            $url .= '/';
        }
      }

      if ( ( $this -> values['adverts_count'] / \front\factory\GlobelusAdverts::advert_list_limit ) > 1 ):
        echo \front\view\Globelus::pager(
                $url,
                ceil( $this -> values['adverts_count'] / \front\factory\GlobelusAdverts::advert_list_limit ),
                \S::get( 'cp' ),
                $query_string
              );
      endif;
    ?>
    [DODATKOWA_TRESC]
  </div>
</div>
<script class="footer" type="text/javascript">
  $( function()
  {
    if ( $(document).width() < 768 )
    {
      $( 'body' ).on( click_event, '.advert-filtr .title', function()
      {
        if ( $( '.advert-filtr .content' ).is( ':visible' ) )
        {
          $( this ).children( 'i' ).addClass( 'fa-chevron-down' ).removeClass( 'fa-chevron-up' );
          $( '.advert-filtr .content' ).hide();
        }
        else
        {
          $( this ).children( 'i' ).addClass( 'fa-chevron-up' ).removeClass( 'fa-chevron-down' );
          $( '.advert-filtr .content' ).show();
        }
      });
    }

    <? if ( $this -> values['f_categories'] ):?>
      if ( $(document).width() >= 768 )
        $( '#subcontent-categories' ).show();
    <? endif;?>

    <? if ( $this -> f_voivodeships ):?>
      if ( $(document).width() >= 768 )
        $( '#subcontent-voivodeships' ).show();
    <? endif;?>

    <? if ( $this -> values['f_countries'] ):?>
      if ( $(document).width() >= 768 )
        $( '#subcontent-countries' ).show();
    <? endif;?>

    <? if ( $this -> values['f_time'] ):?>
      if ( $(document).width() >= 768 )
        $( '#subcontent-time' ).show();
    <? endif;?>

    <? if ( $this -> values['f_work_type'] ):?>
      if ( $(document).width() >= 768 )
        $( '#subcontent-work-type' ).show();
    <? endif;?>

    <? if ( $this -> values['f_salary'] or $this -> values['f_without_language'] or $this -> values['f_without_experience'] or $this -> values['f_for_couples'] ):?>
      if ( $(document).width() >= 768 )
        $( '#subcontent-other' ).show();
    <? endif;?>

    $( 'body' ).on( click_event, '.advert-filtr div.toggle', function(e)
    {
      var content_id = $( this ).attr( 'content' );
      if ( $( '#subcontent-' + content_id ).is( ':visible' ) )
      {
        $( '#subcontent-' + content_id ).hide();
        $( this ).children( 'i' ).removeClass( 'fa-chevron-up' ).addClass( 'fa-chevron-down' );
      }
      else
      {
        $( '#subcontent-' + content_id ).show();
        $( this ).children( 'i' ).removeClass( 'fa-chevron-down' ).addClass( 'fa-chevron-up' );
      }
      return false;
    });

    $( 'body' ).on( 'click', '.seo-additional-text .btn', function(e)
    {
      e.preventDefault();
      if ( $( '.seo-additional-text .row:nth-child(2)' ).hasClass( 'hidden' ) )
      {
        $( '.seo-additional-text .row:nth-child(2)' ).removeClass( 'hidden' );
        $( this ).html( 'mniej' );
      }
      else
      {
        $( '.seo-additional-text .row:nth-child(2)' ).addClass( 'hidden' );
        $( this ).html( 'więcej' );
      }
    });

    $( '.voivodeships_select' ).on( 'ifClicked', '', function()
    {
      if ( $( this ).val() == 1 && $( this ).iCheck('check') )
      {
        $( '.voivodeships_select' ).each( function()
        {
          if ( $( this ).val() != 1 )
            $( this ).iCheck('uncheck');
        });
      }
      else
      {
        $( '.voivodeships_select[value="1"]' ).removeAttr('checked').iCheck('update');
      }
    });

    $( '.work_type_select' ).on( 'ifClicked', '', function()
    {
      if ( $( this ).val() == 0 && $( this ).iCheck('check') )
      {
        $( '.work_type_select' ).each( function()
        {
          if ( $( this ).val() != 0 )
            $( this ).iCheck('uncheck');
        });
      }
      else
      {
        $( '.work_type_select[value="0"]' ).removeAttr('checked').iCheck('update');
      }
    });

    $( '.country_select' ).on( 'ifClicked', '', function()
    {
      if ( $( this ).val() == 75 && $( this ).iCheck('check') )
      {
        $( '.country_select' ).each( function()
        {
          if ( $( this ).val() != 75 )
            $( this ).iCheck('uncheck');
        })
      }
      else if ( $( this ).val() == 77 && $( this ).iCheck('check') )
      {
        $( '.country_select' ).each( function()
        {
          if ( $( this ).val() != 77 )
          {
            $( this ).iCheck('uncheck');
          }
        })
      }
      else
      {
        $( '.country_select[value="75"]' ).removeAttr('checked').iCheck('update');
        $( '.country_select[value="77"]' ).removeAttr('checked').iCheck('update');
      }
    });

    $( 'body' ).on( 'click', '.show-more', function(e)
    {
      e.preventDefault();
      var content_id = $( this ).attr( 'content' );
      $( '#' + content_id + ' li' ).show();
      $( this ).removeClass( 'show-more' ).addClass( 'show-less' ).html( 'mniej' );
    });

    $( 'body' ).on( 'click', '.show-less', function(e)
    {
      e.preventDefault();
      var content_id = $( this ).attr( 'content' );
      $( '#' + content_id + ' li' ).each( function( i )
      {
        if ( i > 4 )
          $( this ).hide();
      });
      $( this ).removeClass( 'show-less' ).addClass( 'show-more' ).html( 'więcej' );
    });
  });
</script>