<? global $lang;?>
<?
  $td = \S::get_session( 'td' );
  $positions = \front\factory\Globelus::get_positions_list();
?>
<div id="user-panel">
  <div class="mini-box fluid" style="padding: 0; border: 0;">
    <div class="content profil">
      <form method="POST" action="/globelusCandidates/new_candidate/" enctype="multipart/form-data">
        <div class="step-title">
          <?= ucfirst( $lang['krok'] );?> 1 - <span><?= $lang['kandydat-profil-krok-1-opis'];?></span>
        </div>
        <div class="row">
          <div class="col-12 col-md-6">
            <div class="form-group row">
              <label form="name" class="col-12 col-sm-4"><?= ucfirst( $lang['imie'] );?>:</label>
              <div class="col-12 col-sm-8">
                <input type="text" id="name" name="name" class="form-control" value="<?= $td['p']['name'];?>" required >
              </div>
            </div>
          </div>
          <div class="col-12 col-md-6">
            <div class="form-group row">
              <label form="surname" class="col-12 col-sm-4"><?= ucfirst( $lang['nazwisko'] );?>:</label>
              <div class="col-12 col-sm-8">
                <input type="text" id="surname" name="surname" class="form-control" value="<?= $td['p']['surname'];?>" required >
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-12 col-md-6">
            <div class="form-group row">
              <label form="email" class="col-12 col-sm-4"><?= ucfirst( $lang['adres-email'] );?>:</label>
              <div class="col-12 col-sm-8 input-icon">
                <input type="text" id="email" name="email" class="form-control" value="" value="<?= $td['p']['email'];?>" required >
              </div>
            </div>
          </div>
          <div class="col-12 col-md-6">
            <div class="form-group row">
              <label form="phone" class="col-12 col-sm-4"><?= ucfirst( $lang['telefon'] );?>:</label>
              <div class="col-12 col-sm-8">
                <input type="text" id="phone" name="phone" class="form-control" value="<?= $td['p']['phone'];?>" required >
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-12 col-md-6">
            <div class="form-group row">
              <label form="date_of_birth" class="col-12 col-sm-4"><?= ucfirst( $lang['data-urodzenia'] );?>:</label>
              <div class="col-12 col-sm-8 input-icon date_of_birth">
                <input type="text" id="date_of_birth" name="date_of_birth" class="form-control date-birth" value="<?= $td['p']['date_of_birth'];?>" required >
                <i class="fa fa-calendar"></i>
              </div>
            </div>
          </div>
          <div class="col-12 col-md-6">
            <div class="form-group row">
              <label form="sex" class="col-12 col-sm-4"><?= ucfirst( $lang['plec'] );?>:</label>
              <div class="col-12 col-sm-8">
                <select id="sex" name="sex" class="form-control">
                  <option value="">--- wybierz ---</option>
                  <option value="0" <?= $td['p']['sex'] === '0' ? 'selected' : '';?>><?= $lang['kobieta'];?></option>
                  <option value="1" <?= $td['p']['sex'] === '1' ? 'selected' : '';?>><?= $lang['mezczyzna'];?></option>
                </select>
              </div>
            </div>
          </div>
        </div>
        <hr/>
        <div class="step-title">
          <?= ucfirst( $lang['krok'] );?> 2 - <span><?= $lang['kandydat-profil-krok-2-opis'];?></span>
        </div>
        <div class="row important">
          <div class="col-12">
            <div class="info">Wypełnij aby zwiększyć swoją szansę na znalezienie poszukiwanej pracy.</div>
            <div class="form-group row">
              <label form="positions" class="col-12 text-left text-bold"><?= ucfirst( $lang['w-jakim-zawodzie-szukasz-pracy'] );?></label>
              <div class="col-12">
                <div class="row positions positions_1" counter="1">
                  <div class="col-12 col-md-6 mb5">
                    <select counter="1" name="positions[]" class="form-control positions" placeholder="wybierz stanowisko" required>
                      <option value="">--- <?= $lang['wybierz']; ?> ---</option>
                      <? if ( is_array( $positions ) ): foreach ( $positions as $position_single ):?>
                        <option value="<?= $position_single['id']; ?>"><?= htmlspecialchars( $position_single['name'] );?></option>
                      <? endforeach; endif;?>
                    </select>
                  </div>
                  <div class="col-12 col-md-6 mb5">
                    <select name="positions_experience[]" counter="1" class="form-control" required >
                      <option value="">--- wybierz doświadczenie ---</option>
                      <?
                        $positions_experience = \front\factory\Globelus::positions_experience();
                        if ( is_array( $positions_experience ) ): foreach ( $positions_experience as $key => $val ):?>
                          <option value="<?= $key;?>"><?= $val;?></option>
                        <? endforeach; endif;
                      ?>
                    </select>
                  </div>
                </div>
              </div>
            </div>
            <div class="form-group row">
              <div class="col-12">
                <input type="checkbox" name="inexperience" id="inexperience"> <?= $lang['nie-posiadam-doswiadczenia'];?>
              </div>
            </div>
          </div>
        </div>
        <div class="row options important">
          <div class="col-12">
            <div class="info">Wypełnij aby zwiększyć swoją szansę na znalezienie poszukiwanej pracy.</div>
            <div class="form-group row">
              <label form="categories" class="col-12 text-left text-bold"><?= ucfirst( $lang['w-jakiej-branzy-szukasz-pracy'] );?></label>
            </div>
            <? $i_urf = 1;?>
            <? if ( is_array( $categories = \front\factory\GlobelusAdverts::categories() ) ): foreach ( $categories as $category ):?>
              <? $i_urf++;?>
              <? if ( $i_urf%2 == 0):?>
                <div class="row">
              <? endif;?>
                <div class="col-12 col-sm-6">
                  <input type="checkbox" name="categories[]" value="<?= $category['id'];?>" required > <?= $category['name'];?>
                </div>
              <? if ( $i_urf%2 == 1 ):?>
                </div>
              <? endif;?>
            <? endforeach; endif;?>
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <div class="form-group row">
              <label form="languages" class="col-12 text-left text-bold"><?= ucfirst( $lang['jakie-znasz-jezyki'] );?></label>
              <div class="col-12">
                <div class="row languages languages_1" counter="1">
                  <div class="col-12 col-md-6 mb5">
                    <input type="text" counter="1" name="languages[]" class="form-control" placeholder="<?= $lang['jezyk'];?>" value="" required >
                  </div>
                  <div class="col-12 col-md-6 mb5">
                    <select name="languages_experience[]" counter="1" class="form-control" required >
                      <option value="">--- <?= $lang['wybierz'];?> ---</option>
                      <?
                        $languages_experience = \front\factory\Globelus::languages_experience();
                        if ( is_array( $languages_experience ) ): foreach ( $languages_experience as $key => $val ):?>
                          <option value="<?= $key;?>"><?= $val;?></option>
                        <? endforeach; endif;
                      ?>
                    </select>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <div class="form-group row">
              <label form="countries" class="col-12 text-left text-bold"><?= ucfirst( $lang['w-jakim-kraju-szukasz-pracy'] );?> (max. 6)</label>
              <div class="col-12">
                <select name="countries[]" class="form-control countries" multiple placeholder="<?= $lang['podaj-kraj'];?>" required >
                  <?
                    $countries = \front\factory\Globelus::countries();
                    if ( is_array( $countries ) ): foreach ( $countries as $country ):?>
                      <option value="<?= $country['id'];?>"><?= $country['name'];?></option>
                    <? endforeach; endif;
                  ?>
                </select>
              </div>
            </div>
          </div>
        </div>
        <div class="row voivodeships" style="display: none;">
          <div class="col-12">
            <div class="form-group row">
              <label form="voivodeships" class="col-12 text-left text-bold">W jakim województwie szukasz pracy?</label>
              <div class="col-12">
                <select name="voivodeships[]" class="form-control voivodeships" multiple  placeholder="--- wybierz województwo ---">
                  <? $voivodeships = \front\factory\Globelus::get_voivodeships_list(); if ( is_array( $voivodeships ) ): foreach ( $voivodeships as $voivodeship ):?>
                    <option value="<?= $voivodeship[ 'id' ];?>"><?= $voivodeship[ 'name' ];?></option>
                  <? endforeach; endif;?>
                </select>
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <div class="form-group row">
              <label form="status_of_availability" class="col-12 text-left text-bold"><?= ucfirst( $lang['dostepnosc'] );?>:</label>
              <div class="col-12 col-md-6">
                <select name="status_of_availability" id="status_of_availability" class="form-control" placeholder="<?= $lang['wybierz'];?>">
                  <?
                    $status = \front\factory\Globelus::availability_status();
                    if ( is_array( $status ) ): foreach ( $status as $key => $val ):?>
                      <option value="<?= $key;?>"><?= $val;?></option>
                    <? endforeach; endif;
                  ?>
                </select>
              </div>
              <div class="col-12 col-md-6">
              <div id="date-of-availability-content" style="display: none;">
                <div class="form-group row">
                  <div class="col-12 col-md-6 input-icon date_of_availability">
                    <input type="text" id="date_of_availability" name="date_of_availability" class="form-control date" value="">
                    <i class="fa fa-calendar"></i>
                  </div>
                </div>
              </div>
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <div class="form-group row">
              <label form="experience_abroad" class="col-12 text-left text-bold"><?= ucfirst( $lang['czy-masz-doswiadczenie-w-pracy-za-granica'] );?></label>
              <div class="col-12">
                <select name="experience_abroad" class="form-control" required >
                  <option value="">--- wybierz ---</option>
                  <option value="0">nie</option>
                  <option value="1">tak</option>
                </select>
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <div class="form-group row">
              <label form="accommodation" class="col-12 text-left text-bold"><?= ucfirst( $lang['czy-potrzebujesz-zakwaterowania'] );?></label>
              <div class="col-12">
                <select name="accommodation" class="form-control" required >
                  <option value="">--- wybierz ---</option>
                  <option value="0">nie</option>
                  <option value="1">tak</option>
                </select>
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <div class="form-group row">
              <label form="driving_license" class="col-12 text-left text-bold"><?= ucfirst( $lang['czy-posiadasz-prawo-jazdy'] );?></label>
              <div class="col-12">
                <select name="driving_license" class="form-control" required >
                  <option value="">--- wybierz ---</option>
                  <option value="0">nie</option>
                  <option value="1">tak</option>
                </select>
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <div class="form-group row">
              <label form="own_car" class="col-12 text-left text-bold"><?= ucfirst( $lang['czy-dysponujesz-wlasnym-samochodem'] );?></label>
              <div class="col-12">
                <select name="own_car" class="form-control" required >
                  <option value="">--- wybierz ---</option>
                  <option value="0">nie</option>
                  <option value="1">tak</option>
                </select>
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <div class="form-group row">
              <label form="other_information" class="col-12 text-left text-bold"><?= ucfirst( $lang['kandydat-edycja-inne'] );?></label>
              <div class="col-12">
                <textarea name="other_information" id="other_information"></textarea>
              </div>
            </div>
          </div>
        </div>
        <hr/>
        <div class="step-title">
          <?= ucfirst( $lang['krok'] );?> 3 - <span><?= $lang['kandydat-profil-krok-3-opis'];?></span>
        </div>
        <div class="row">
          <div class="col-12 col-md-6">
            <div class="form-group row">
              <label form="cv" class="col-12 col-sm-4"><?= strtoupper( $lang['cv'] );?> (max. 5mb):</label>
              <div class="col-12 col-sm-8 pt10">
                <input type="file" id="cv" name="cv" required >
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-12 col-md-6">
            <div class="form-group row">
              <label form="avatar" class="col-12 col-sm-4"><?= ucfirst( $lang['zdjecie'] );?> (max. 1mb):</label>
              <div class="col-12 col-sm-8 pt10">
                <input type="file" id="avatar" name="avatar">
              </div>
            </div>
          </div>
        </div>
        <div class="form-group row agremment-profile">
          <div class="col-12">
            <input type="checkbox" id="agremment-profile" name="agremment_profile"> <?= $lang['rejestracja-zgoda-na-wyswietlenie-profilu'];?>
          </div>
        </div>
        <div class="form-group row agremment-marketing">
          <div class="col-12">
            <input type="checkbox" id="agremment-marketing" name="agremment_marketing"> Wyrażam zgodę na kontakt mailowy i/lub telefoniczny  ze strony globelus.pl
          </div>
        </div>
        <div class="row">
          <div class="col-12 col-md-6">
            <div class="form-group row">
              <div class="col-12 mt20">
                <input type="submit" value="<?= ucfirst( $lang['zatwierdz'] );?>" class="btn btn-success">
              </div>
            </div>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
<link class="footer" rel="stylesheet" type="text/css" href="/plugins/datepicker/css/bootstrap-datepicker.standalone.css">
<link class="footer" rel="stylesheet" type="text/css" href="/plugins/selectize/css/selectize.bootstrap3.css">
<link class="footer" rel="stylesheet" type="text/css" href="/plugins/summernote/summernote-lite.css">
<script class="footer" type="text/javascript" src="/plugins/summernote/summernote-lite.js"></script>
<script class="footer" type="text/javascript" src="/plugins/summernote/lang/summernote-pl-PL.js"></script>
<script class="footer" type="text/javascript" src="/libraries/framework/vendor/plugins/moment/moment.js"></script>
<script class="footer" type="text/javascript" src="/libraries/framework/vendor/plugins/moment/pl.js"></script>
<script class="footer" type="text/javascript" src="/plugins/datepicker/js/bootstrap-datepicker.js"></script>
<script class="footer" type="text/javascript" src="/plugins/datepicker/locales/bootstrap-datepicker.pl.min.js"></script>
<script class="footer" type="text/javascript" src="/plugins/selectize/js/selectize.js"></script>
<script class="footer" type="text/javascript">
  $( function()
  {
    $( '.positions_1 select.positions' ).selectize({
      maxItems: 1
    });

    $( 'body' ).on( 'submit', '#user-panel form', function( e )
    {
      if(
          $( "#user-panel form #cv" )[0].files.length
        &&
          $( '#user-panel form #cv' )[0].files[0].type != 'application/msword'
        &&
          $( '#user-panel form #cv' )[0].files[0].type != 'application/rtf'
        &&
          $( '#user-panel form #cv' )[0].files[0].type != 'text/pdf'
        &&
          $( '#user-panel form #cv' )[0].files[0].type != 'application/pdf'
        &&
          $( '#user-panel form #cv' )[0].files[0].type != 'application/vnd.oasis.opendocument.text'
        &&
          $( '#user-panel form #cv' )[0].files[0].type != 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
        &&
          $( '#user-panel form #cv' )[0].files[0].type != 'image/jpeg' )
      {
        e.preventDefault();
        $.alert(
        {
          title: '<?= ucfirst( $lang['blad'] );?>',
          icon: 'fa fa-exclamation',
          content: '<?= $lang['cv-niedozwolony-format-pliku'];?>',
          type: 'blue',
          closeIcon: true,
          closeIconClass: 'fa fa-close',
          typeAnimated: true,
          animation: 'opacity',
          columnClass: 'large',
          theme: 'modern',
          buttons:
          {
            confirm:
            {
              text: '<?= $lang['zamknij'];?>',
              btnClass: 'btn-blue',
              keys: ['enter'],
              action: function() {}
            }
          }
        });
      }

      if(
          $( "#user-panel form #avatar" )[0].files.length
        &&
          $( '#user-panel form #avatar' )[0].files[0].type != 'image/jpeg'
        &&
          $( '#user-panel form #avatar' )[0].files[0].type != 'image/png' )
      {
        e.preventDefault();
        $.alert(
        {
          title: '<?= ucfirst( $lang['blad'] );?>',
          icon: 'fa fa-exclamation',
          content: '<?= $lang['zdjecie-niedozwolony-format-pliku'];?>',
          type: 'blue',
          closeIcon: true,
          closeIconClass: 'fa fa-close',
          typeAnimated: true,
          animation: 'opacity',
          columnClass: 'large',
          theme: 'modern',
          buttons:
          {
            confirm:
            {
              text: '<?= $lang['zamknij'];?>',
              btnClass: 'btn-blue',
              keys: ['enter'],
              action: function() {}
            }
          }
        });
      }
    });

    $( '#other_information' ).summernote({
      height: 200,
      lang: 'pl-PL',
      toolbar: [
            ['font', ['bold', 'underline', 'clear']],
            ['para', ['ul', 'ol', 'paragraph']],
            ['table', ['table']]
        ]
    });

    $( 'body' ).on( 'change', '#status_of_availability', function()
    {
      var status = $( this ).val();
      if ( status != 2 )
        $( '#date-of-availability-content' ).hide();
      else
        $( '#date-of-availability-content' ).show();
    });

    $( 'body' ).on( click_event, '.input-icon .fa', function()
    {
      $( this ).parent().children( 'input' ).focus();
    });

    $( 'body' ).on( click_event, 'input[name="categories[]"]', function()
    {
      if ( $( this ).is( ':checked' ) )
        $( 'input[name="categories[]"]' ).removeAttr( 'required' );
      else
        $( 'input[name="categories[]"]' ).attr( 'required', 'required' );
    });

    $( 'body' ).on( click_event, '#inexperience', function()
    {
      if ( $( this ).is( ':checked' ) )
        $( '.positions select' ).attr( 'readonly', 'readonly' );
      else
        $( '.positions select' ).removeAttr( 'readonly' );
    });

    /* dodaj kolejne stanowiska */
    $( 'body' ).on( 'change', '.positions select', function( )
    {
      var counter = parseInt( $( this ).attr( 'counter' ) );
      if ( counter < 3 && $( '.positions_' + counter + ' select.positions' ).val( ) !== '' && $( '.positions_' + counter + ' select.positions_experience' ).val( ) !== '' && !$( '.positions_' + ( counter + 1 ) ).length )
      {
        $( '.positions_' + counter ).after( '<div class="row positions_' + ( counter + 1 ) + ' positions" counter="' + ( counter + 1 ) + '">'
            + '<div class="col-12 col-md-6 mb5">'
            + '<select counter="' + ( counter + 1 ) + '" name="positions[]" class="form-control positions" placeholder="wybierz stanowisko">'
              + '<option value="">--- <?= $lang['wybierz']; ?> ---</option>'
              <? if ( is_array( $positions ) ): foreach ( $positions as $position_single ):?>
                + '<option value="<?= $position_single['id']; ?>"><?= htmlspecialchars( $position_single['name'] );?><\/option>'
              <? endforeach; endif;?>
            + '<\/select>'
            + '<\/div>'
            + '<div class="col-12 col-md-6 mb5">'
              + '<select name="positions_experience[]" counter="' + ( counter + 1 ) + '" class="form-control">'
                + '<option value="">--- <?= $lang[ 'wybierz' ];?> ---<\/option>'
                <? $positions_experience = \front\factory\Globelus::positions_experience(); if ( is_array( $positions_experience ) ): foreach ( $positions_experience as $key => $val ):?>
                  + '<option value="<?= $key;?>"><?= $val;?><\/option>'
                <? endforeach; endif;?>
              + '<\/select>'
            + '<\/div>'
          + '<\/div>' );

        $( '.positions_' + ( counter + 1 ) + ' select.positions' ).selectize({
          maxItems: 1
        });
      };
    });

    $( 'body' ).on( 'change', '.languages input, .languages select', function()
    {
      var counter = parseInt( $( this ).attr( 'counter' ) );

      if (
              counter < 3
            &&
              $( '.languages_' + counter + ' input' ).val() !== ''
            &&
              $( '.languages_' + counter + ' select' ).val() !== ''
            &&
              !$( '.languages_' + ( counter + 1 ) ).length )
      {
        $( '.languages_' + counter ).after( '<div class="row languages_' + ( counter + 1 ) + ' languages" counter="' + ( counter + 1 ) + '">'
                          + '<div class="col-12 col-md-6 mb5">'
                            + '<input type="text" counter="' + ( counter + 1 ) + '" name="languages[]" class="form-control" placeholder="<?= $lang['jezyk'];?>" value="">'
                          + '<\/div>'
                          + '<div class="col-12 col-md-6 mb5">'
                            + '<select name="languages_experience[]" counter="' + ( counter + 1 ) + '" class="form-control">'
                              + '<option value="">--- <?= $lang['wybierz'];?> ---</option>'
                              <?
                                $languages_experience = \front\factory\Globelus::languages_experience();
                                if ( is_array( $languages_experience ) ): foreach ( $languages_experience as $key => $val ):?>
                                  + '<option value="<?= $key;?>"><?= $val;?></option>'
                                <? endforeach; endif;
                              ?>
                            + '<\/select>'
                          + '<\/div>'
                        + '<\/div>' );
      };
    });

    $( 'input[type="text"].date-birth' ).datepicker({
        format: "dd.mm.yyyy",
        language: 'pl'
    });

    $( 'input[type="text"].date' ).datepicker({
        format: "yyyy-mm-dd",
        language: 'pl'
    });

    $( '.countries' ).selectize({
      maxItems: 6
    });

    $( 'select.voivodeships' ).selectize();

    $( 'body' ).on( 'change', '.countries', function()
    {
      if ( $.inArray( "1", $( this ).val() ) > -1 )
      {
        $( '.row.voivodeships' ).show();
      }
      else
      {
        $( '.row.voivodeships' ).hide();
      }
    });
  });
</script>