<?
global $db, $settings;

ob_start();
?>
<? if ( is_array( $this -> answers ) and count( $this -> answers ) ):?>
  <? foreach ( $this -> answers as $answer ):?>
    <div class="answer mb10">
      <div class="row">
        <div class="col-xs-12 col-md-2 col-lg-1">
          <div class="img">
            <? if ( $answer['user_id'] and file_exists( '../' . \front\factory\GlobelusCandidates::avatar_url( $answer['user_id'] ) ) ):?>
              <img src="/avatar/<?= $answer['user_id'];?>/<?= \S::get_token();?>">
            <? else:?>
              <img src="/images/no-avatar.png">
            <? endif;?>
          </div>
        </div>
        <div class="col-xs-12 col-md-10 col-lg-11">
          <p style="color:<? if ( !$answer['displayed'] ):?>#e72f34;<? else:?>#8c8c8c;<? endif;?>">
            <b><?= $answer['surname'] . ' ' . $answer['name'];?></b> | <?= date( 'Y-m-d H:i', strtotime( $answer['date_add'] ) );?>
          </p>
          <p>
            <?= $lang['tel.'];?> <?= $answer['phone'];?> | 
            <?= $lang['email'];?> <a href="mailto:<?= $answer['email'];?>"><?= $answer['email'];?></a> |
            <? if ( ( $answer['cv'] and file_exists( '../' . $answer['cv'] ) ) || ( !$answer['cv'] and $answer['user_id'] and file_exists( '../' . \front\factory\GlobelusCandidates::cv_url( $answer['user_id'] ) ) ) ):?>
              <?
                if ( !$answer['cv'] and $answer['user_id'] and file_exists( '../' . \front\factory\GlobelusCandidates::cv_url( $answer['user_id'] ) ) )
                  $cv_url = '/cv/' . $answer['user_id'] . '/' . \S::get_token() . '/';
                else if ( $answer['cv'] and file_exists( '../' . $answer['cv'] ) )
                  $cv_url = '/cv-tmp/' . $answer['id'] . '/' . \S::get_token() . '/';
              ?>
              <a href="<?= $cv_url;?>" class="cv">
                <i class="fa fa-file-text-o"></i> pobierz CV
              </a>
            <? endif;?>
          </p>
          <div class="mt10">
            <?= nl2br( $answer['text'] );?>
          </div>
        </div>
      </div>
    </div>
  <? endforeach;?>
<? else:?>
  <div class="alert alert-danger mt20">Brak odpowiedzi do tego ogłoszenia.</div>
<? endif;?>
<?
$out = ob_get_clean();

$grid                    = new \gridEdit;
$grid -> id              = 'answers-list';
$grid -> gdb_opt         = $gdb;
$grid -> include_plugins = true;
$grid -> title           = 'Odpowiedzi do ogłoszenia: ' . $this -> advert['title'];
$grid -> actions         = [
        'cancel' => [ 'url' => '/admin/globelus_adverts/main_view/' ]
];
$grid -> external_code   = $out;
$grid -> persist_edit    = true;
$grid -> id_param        = 'id';

echo $grid -> draw();
?>
<style type="text/css">
  hr {
    margin: 10px 0;
  }
  #g-edit-save {
    display: none;
  }
  .form-group {
    margin-bottom: 0;
  }
  .g-container .panel-body {
    position: relative;
  }
  .img {
    width: 100%;
    max-width: 150px;
    margin: auto;
  }
  .img img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
</style>