<?php
/**
 * YAWIK
 *
 * @filesource
 * @copyright https://yawik.org/COPYRIGHT.php
 * @license   MIT
 */
/**
 * renders the detail view of an application.
 */

use Applications\Entity\StatusInterface as Status;

$this->headTitle($this->translate('Details'));
$this->headScript()->appendFile($this->basepath('modules/Applications/js/applications.manage.detail.js'));
$this->headScript()->appendScript('$(function() { $(".rating").barrating(); });');

/* @var Applications\Entity\Application $application */
$application = $this->application;
$job = $application->getJob();

/* @var \Auth\Entity\User $user */
$user = $this->auth()->getUser();

$employee=false;
if ($user->hasOrganization()) {
    $employee = $user->getOrganization()->getOrganization()->getEmployee($user);
}

$prevId = $nextId = $prevHref = $nextHref = false;

if (!$application->isDraft() && $this->list->getCount()):
    /* variables needed for the pagination*/
    $prevId = $this->list->getPrevious();
    $nextId = $this->list->getNext();
    $prevHref = $prevId ? $this->url('lang/applications/detail', array('id' => $prevId), true) : '#';
    $nextHref = $nextId ? $this->url('lang/applications/detail', array('id' => $nextId), true) : '#';
endif;

?>
<h1>
    <?php echo $this->translate('application for')?>:
    <?php $href = $job->getLink() ? $job->getLink() : $this->jobUrl($job, ['linkOnly' => true ]); ?>
    <?php echo $this->link($href, $job->getTitle())?>
    <?php if (!$application->isDraft() && $this->list->getCount() && 'guest' != $this->auth('role')):?>
        <small class="pull-right">
            <?php echo sprintf($this->translate('Application %d of %d'),
                               $this->list->getPosition(), $this->list->getCount()
            )?>
        </small>
    <?php endif ?>
</h1>

<div id="forward-email-result" class="alert" style="display:none"></div>
<nav class="navbar yk-toolbar">
<?php if ($job->getOrganization()->getWorkflowSettings()->getAcceptApplicationByRecruiters()):
    if (!$application->isDraft() && $application->getPermissions()->isGranted($this->auth('id'), 'change')): ?>
        <div id="state-actions" class="btn-group cam-action-states nav navbar-nav">
            <?php $status = $application->getStatus()->getName();

            if ($employee && \Organizations\Entity\EmployeeInterface::ROLE_RECRUITER == $employee->getRole() ) {
                $actionButtons = array(
                    Status::ACCEPTED => array(
                        'href' => $this->url(
                            'lang/applications/detail/status',
                            array('status' => Status::ACCEPTED),
                            true
                        ),
                        'label' => $this->translate('Accept'),
                        'title' => $this->translate('Inform the departement manager'),
                    ),
                );
            } else {
                $actionButtons = array(
                    Status::CONFIRMED => array(
                        'href' => $this->url(
                            'lang/applications/detail/status',
                            array('status' => Status::CONFIRMED),
                            true
                        ),
                        'label' => $this->translate('Confirm'),
                        'title' => $this->translate('Confirm the receipt'),
                    ),
                    Status::INVITED => array(
                        'href' => $this->url(
                            'lang/applications/detail/status',
                            array('status' => Status::INVITED),
                            true
                        ),
                        'label' => $this->translate('Invite'),
                        'title' => $this->translate('Invite the applicant'),
                    ),
                );
            }
            $actionButtons[ Status::INQUIRY ] = [
                'href' => $this->url(
                    'lang/applications/detail/status',
                    [ 'status' => Status::INQUIRY ],
                    true
                ),
                'label' => $this->translate('Inquiry'),
                'title' => $this->translate('Send an inquiry to the applicant'),
            ];
            $actionButtons[ Status::REJECTED ] = [
                'href' => $this->url(
                    'lang/applications/detail/status',
                    [ 'status' => Status::REJECTED ],
                    true
                ),
                'label' => $this->translate('Reject'),
                'title' => $this->translate('Reject the applicant'),
            ];

            foreach ($actionButtons as $targetStatus => $spec):
                if ($status == $targetStatus): continue; endif?>

                <button class="btn btn-sm btn-default"
                        data-href="<?php echo $spec['href']?>"
                    <?php if (isset($spec['title'])):?>
                        data-title="<?php echo $spec['title']?>"
                        data-toggle="modal"
                        data-target="#mail-box"
                    <?php endif ?>
                    ><?php echo $spec['label'] ?></button>
            <?php endforeach ?>
        </div>
    <?php endif ?>
<?php else: ?>
    <?php if (!$application->isDraft()
              && $application->getPermissions()->isGranted($this->auth('id'), 'change')): ?>
        <div id="state-actions" class="btn-group cam-action-states nav navbar-nav">
            <?php $status = $application->getStatus()->getName();

            if ($employee && \Organizations\Entity\EmployeeInterface::ROLE_DEPARTMENT_MANAGER == $employee->getRole() ) {
                $actionButtons = array(
                    Status::ACCEPTED => array(
                        'href' => $this->url(
                            'lang/applications/detail/status',
                            array('status' => Status::ACCEPTED),
                            true
                        ),
                        'label' => $this->translate('Accept'),
                        'title' => $this->translate('Inform the Recruiter'),
                    ),
                );
            } else {
                $actionButtons = array(
                    Status::CONFIRMED => array(
                        'href' => $this->url(
                            'lang/applications/detail/status',
                            array('status' => Status::CONFIRMED),
                            true
                        ),
                        'label' => $this->translate('Confirm'),
                        'title' => $this->translate('Confirm the receipt'),
                    ),
                    Status::INVITED => array(
                        'href' => $this->url(
                            'lang/applications/detail/status',
                            array('status' => Status::INVITED),
                            true
                        ),
                        'label' => $this->translate('Invite'),
                        'title' => $this->translate('Invite the applicant'),
                    ),
                );
            }
            $actionButtons[ Status::INQUIRY ] = [
                'href' => $this->url(
                    'lang/applications/detail/status',
                    [ 'status' => Status::INQUIRY ],
                    true
                ),
                'label' => $this->translate('Inquiry'),
                'title' => $this->translate('Send an inquiry to the applicant'),
            ];
            $actionButtons[ Status::REJECTED ] = [
                'href' => $this->url(
                    'lang/applications/detail/status',
                    [ 'status' => Status::REJECTED ],
                    true
                ),
                'label' => $this->translate('Reject'),
                'title' => $this->translate('Reject the applicant'),
            ];

            foreach ($actionButtons as $targetStatus => $spec):
                if ($status == $targetStatus): continue; endif?>

                <button class="btn btn-sm btn-default"
                        data-href="<?php echo $spec['href']?>"
                    <?php if (isset($spec['title'])):?>
                        data-title="<?php echo $spec['title']?>"
                        data-toggle="modal"
                        data-target="#mail-box"
                    <?php endif ?>
                    ><?php echo $spec['label'] ?></button>
            <?php endforeach ?>
        </div>

    <?php endif ?>
    <?php if (!$application->isDraft() && $this->acl()->isRole(Auth\Entity\User::ROLE_RECRUITER, true)):?>
        <form id="forward-email-form" action="<?php echo $this->url('lang/applications/detail',array(), true)?>" class="form-inline" method="get">

     <span id="forward-email" class="input-group navbar-nav">
            <span class="input-group-addon input-sm"
                  data-toggle="popover"
                  data-trigger="hover focus click"
                  data-placement="bottom"
                  title="<?php echo $this->translate('Enter an email address')?>"
                  data-content="<?php echo $this->translate('This application will be send as an email to the given address in a layout similar to that on this page with all attachments included.')?>">
            <i class="yk-icon yk-icon-envelope"></i>
            </span>
            <input type="hidden" name="action" value="forward">
            <input class="form-control input-sm" id="forward-email-input" name="email" type="email">
            <span class="input-group-btn">
            <button class="btn btn-sm btn-default" type="submit">
                <span class="yk-icon yk-icon-forward"></span> <?php echo $this->translate('Forward')?>
            </button>
            </span>
      </span>
        </form>
    <?php endif ?>
<?php endif ?>
    <div class="pull-right">
        <?php if (!$application->isDraft() && $this->list->getCount() && 'guest' != $this->auth('role')):?>
            <div class="btn-group">
                <a href="<?php echo $prevHref ?>" class="btn btn-sm btn-default<?php if (!$prevId): echo " disabled"; endif; ?>" title="<?php echo $this->translate('previous')?>"><span class="yk-icon fa-chevron-left"></span></a>
                <a href="<?php echo $this->url('lang/applications', array(), true) ?>" class="btn btn-sm btn-default" title="<?php echo $this->translate('Back to list') ?>"><span class=""></span> <?php echo $this->translate('List') ?></a>
                <a href="<?php echo $nextHref ?>" class="btn btn-sm btn-default<?php if (!$nextId): echo " disabled"; endif; ?>" title="<?php echo $this->translate('next')?>"><span class="yk-icon fa-chevron-right"></span></a>
            </div>
        <?php endif ?>
        <div class="pull-left" style="padding-left: 10px; padding-top:7px;">
            <p>
            </p>
        </div>
        <?php
        /**
         * this variable is currently set by the PDF module.
         */
        if (isset($externActionButtons)) {
            echo $externActionButtons;
        }
        ?>
        <?php if ($this->acl($application, 'delete')):?>
            <button class="btn btn-sm btn-default" data-title="delete Application"
                    data-toggle="modal"
                    data-target="#cam-delete-application"
                    title="<?php echo $this->translate('Delete application')?>">
                <i class="yk-icon yk-icon-delete"></i> <?php echo $this->translate("Delete");?>
            </button>
        <?php endif ?>
        <?php if ($this->acl($application, 'move')):?>
            <button class="btn btn-sm btn-default" data-title="<?=$this->translate('Move application to Talent Pool')?>"
                    data-toggle="modal"
                    data-target="#cam-move-application"
                    title="<?=$this->translate('Move application to Talent Pool')?>">
                <i class="yk-icon yk-icon-forward"></i> <?php echo $this->translate("Move");?>
            </button>
        <?php endif ?>
    </div>
</nav>

<div id="mail-box" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mail-box-label" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="mail-box-label">
                    <?php echo $this->translate('Invite the applicant') ?>
                </h3>
            </div>
            <div id="mail-box-content" class="modal-body">

            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><?php echo $this->translate('Cancel') ?></button>
                <button class="btn btn-primary" onclick="$('#applicant-mail').submit()"><?php echo $this->translate('Send mail') ?></button>
            </div>
        </div>
    </div>
</div>
<div id="cam-delete-application" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="delete-application-label" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="delete-application-label">
                    <?php echo $this->translate('Delete Application') ?>:
                </h3>
            </div>
            <div class="modal-body">
                <?php echo $this->translate('Are you sure you want to delete this application?')?>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><?php echo $this->translate('Cancel') ?></button>
                <a class="btn btn-primary" href="<?php echo $this->url('lang/applications/detail', array('id' => $application->getId()), array('query' => 'action=delete'), true)?>" title="<?php echo $this->translate('delete this application')?>">
                    <?php echo $this->translate('Delete application') ?></a>
            </div>
        </div>
    </div>
</div>
<div id="cam-move-application" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="move-application-label" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="move-application-label">
                    <?=$this->translate('Move application to Talent Pool')?>:
                </h3>
            </div>
            <div class="modal-body">
                <?=$this->translate('Are you sure you want to move this application to Talent Pool?')?>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><?=$this->translate('Cancel') ?></button>
                <a class="btn btn-primary" href="<?=$this->url('lang/applications/detail', array('id' => $application->getId()), array('query' => 'action=move'), true)?>">
                    <?=$this->translate('Move application to Talent Pool')?></a>
            </div>
        </div>
    </div>
</div>

<div id="cam-application-comments" class="modal fade modal-scrollable" tabindex="-1" role="dialog" aria-hidden="true"
     data-list-errormessage="<?php echo $this->translate('Error while loading comments.')?>"
     data-list-url="<?php echo $this->url(
         'lang/applications/comments', array('action' => 'list'),
         array('query' => array(
             'applicationId' => $application->getId()
         )), true
     )?>"
     data-form-errormessage="<?php echo $this->translate('Error while loading comment form.')?>"
     data-form-url="<?php echo $this->url(
         'lang/applications/comments', array('action' => 'form'),
         true)?>"
     data-application-id="<?php echo $application->getId() ?>"
     data-mode="list">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3><?php echo $this->translate('Comments') ?> <i class="yk-icon yk-icon-spinner fa-spin"></i> </h3>
            </div>
            <div id="cam-application-comments-body" class="modal-body">
                <div class="cam-error hide"><p></p></div>
            </div>
            <div class="modal-footer">
                <button id="cam-application-comments-cancelbtn" class="btn btn-default hide"><?php echo $this->translate('Cancel') ?></button>
                <button id="cam-application-comments-savebtn" class="btn btn-primary hide"><?php echo $this->translate('Save') ?></button>
                <button id="cam-application-comments-addbtn" class="btn btn-primary" ><?php echo $this->translate('Add new comment') ?></button>
                <button id="cam-application-comments-closebtn" class="btn btn-default" data-dismiss="modal" aria-hidden="true"><?php echo $this->translate('Close') ?></button>
            </div>
        </div>
    </div>
</div>

<?php if ($this->acl()->isRole(Auth\Entity\User::ROLE_RECRUITER, true)):?>
    <div id="cam-application-history" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="history-box-label" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="history-box-label">
                        <?php echo $this->translate('Status history') ?>:
                    </h3>
                </div>
                <div class="modal-body">
                    <table class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th><?php echo $this->translate('Date') ?></th>
                            <th><?php echo $this->translate('State') ?></th>
                            <th><?php echo $this->translate('Comment') ?></th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($application->getHistory() as $history): /* @var Applications\Entity\History $history */ ?>
                            <tr>
                                <td><?php echo $this->dateFormat($history->getDate())?></td>
                                <td><?php echo $this->translate($history->getStatus()->getName()) ?></td>
                                <td><?php echo $history->getMessage() ?></td>
                            </tr>
                        <?php endforeach ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
<?php endif; ?>
<div class="row">
    <div class="col-md-4">
        <div class="panel panel-default">
            <div class="panel-heading"><?php echo $this->translate('personal information')?></div>
            <div class="panel-body">
                <div class="pull-left">
                    <div class="yk-portrait">
                        <?php if ($application->getContact()->getImage()):?>
                            <img src="<?php echo $this->basePath($application->getContact()->getImage()->getUri()) ?>" class="img-thumbnail"/>
                        <?php else:?>
                            <span class="yk-icon yk-icon-portrait fa-fg img-thumbnail"></span>
                        <?php endif?>
                    </div>
                </div>
                <div>
                    <!--suppress HtmlUnknownTag -->
                    <adress>
                        <?php $contact = $application->getContact(); ?>
                        <strong><?php echo $contact->getDisplayName() ?></strong><br>
                        <?php echo $contact->getStreet() ?> <?php echo $contact->getHouseNumber() ?><br>
                        <?php echo $contact->getPostalCode() ?> <?php echo $contact->getCity() ?><br>
                        <br>
                        <?php if ($contact->getPhone()):?>
                            <abbr title="<?php echo $this->translate("Phone")?>"><i class="yk-icon yk-icon-phone"></i></abbr>
                            <?php echo $contact->getPhone(); ?><br>
                        <?php endif?>
                        <?php if ($contact->getEmail()):?>
                            <abbr title="E-Mail"><i class="yk-icon yk-icon-envelope"></i></abbr>
                            <?php echo $this->link($contact->getEmail()); ?><br>
                        <?php endif?>
                    </adress>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <?php if ($this->attachmentsForm):?>
            <?php
            $this->attachmentsForm->prepare();
            $this->attachmentsForm->setAttribute('data-errorkey', 'attachments'); // required by max count validator
            $attachmentsElement = $this->attachmentsForm->get('attachments');
            $attachmentsElement->setAttribute('class', 'btn btn-default btn-block');
            $formFileUpload = $this->formFileUpload(); /* @var $formFileUpload \Core\Form\View\Helper\FormFileUpload */
            $formFileUpload->setAllowClickableDropZone(false)
                ->setAllowRemove(false)
                ->setNonEmptyNotice('')
                ->setEmptyNotice($this->translate("no attachments available"));
            ?>
            <?=$this->form()->openTag($this->attachmentsForm)?>
        <?php endif;?>
        <div class="panel panel-default<?php if ($this->attachmentsForm):?> <?=$formFileUpload->getDropZoneClass($attachmentsElement)?><?php endif;?>">
            <div class="panel-heading"><?php echo $this->translate('Attachments')?></div>
            <div class="panel-body">
                <?php if ($this->attachmentsForm):?>
            		<?=$formFileUpload->renderFileList($attachmentsElement)?>
                <?php else:?>
                    <?php if(count($application->getAttachments())>0):?>
                        <?php foreach( $application->getAttachments() as $attachment): /* @var Applications\Entity\Attachment $attachment */ ?>
                            <div class="row show-grid">
                                <div class="col-md-12">
                                    <span class="yk-icon yk-icon-paperclip"></span> <a href="<?php echo $this->basePath($attachment->getUri()) ?>" target="_new"><?php echo $attachment->getMetadata()->getName() ?></a>
                                </div>
                            </div>
                        <?php endforeach; // attachments?>
                    <?php else:?>
                        <?php echo $this->translate("no attachments available");?>
                    <?php endif;?>
                <?php endif;?>
                <?php if (count($application->getProfiles())): ?>
                    <hr>
                    <?php foreach ($application->getProfiles() as $profile): /* @var Auth\Entity\SocialProfiles\AbstractProfile $profile*/ ?>

                        <a data-toggle="modal" data-target="#sp-modal" class="btn-sp btn btn-default" href="?action=social-profile&spId=<?php echo $profile->getId() ?>">
                            <span class="fa fa-<?php echo strtolower($profile->getName()) ?>"></span>
                            <?php echo $profile->getName() ?>
                        </a>

                    <?php endforeach;
                    $this->headScript()->appendFile($this->basepath('modules/Core/js/core.reloadable-modal.js'))?>
                    <div class="modal fade modal-scrollable" id="sp-modal" data-reloadable="body" tabindex="-1" role="dialog" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <h4 class="modal-title">
                                        <span class="fa-spin yk-icon yk-icon-spinner"></span>
                                        <?php echo $this->translate('Loading')?> ...</h4>
                                </div>
                                <div class="modal-body">

                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-primary" data-dismiss="modal"><?php echo $this->translate('Close') ?></button>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php  endif; ?>
                <?php if ($this->attachmentsForm):?>
                	<br><br><?=$formFileUpload->renderFileElement($attachmentsElement)?>
            	<?php endif;?>
            </div>
        </div>
        <?php if ($this->attachmentsForm):?>
            <?=$this->formElement($this->attachmentsForm->get('return'))?>
            <?=$this->form()->closeTag()?>
        <?php endif;?>
    </div>
    <div class="col-md-4">
        <div class="panel panel-default">
            <div class="panel-heading"><?php echo $this->translate('State')?></div>
            <table class="table">
                <tr>
                    <td><?php echo $this->translate('date of receipt')?>:</td>
                    <td>
                        <?php if(!is_null($application->getDateCreated())): ?>
                            <?=$this->dateFormat($application->getDateCreated()->getTimestamp(), 'short'); ?>
                        <?php endif; ?>
                        <?=$application->getSubscriber()? '<br/>' . $this->translate("via"). ': '. $application->getSubscriber()->getName():'';?>
                    </td>
                </tr>
                <?php if(!$application->isDraft()):?>
                <tr>
                    <td style="width:50%"><?php echo $this->translate('application state')?>:</td>
                    <td class="cam-color-<?php echo $application->getStatus() ?>">
                        <?php echo $this->translate($application->getStatus()->getName()) ?>
                    </td>
                </tr>
                <?php endif; ?>
                <?php if ($this->acl()->isRole(Auth\Entity\User::ROLE_RECRUITER,true)):?>
                    <tr>
                        <td><?php echo $this->translate('rating')?>:</td>
                        <td class="col-md-6">
          <span id="application-rating">
          <?php $rating = $this->rating($application->getRating());
          if ($application->isDraft() || !$this->acl()->isRole(Auth\Entity\User::ROLE_RECRUITER,true)):
              echo $rating;
          else:?>
              <button id="<?php echo $rating?"cam-applications-comments-toggle":"cam-applications-comments-quickadd"?>"
                      data-title="title"
                      data-target="#cam-application-comments"
                      data-toggle="modal"
                      title="<?php echo $rating?$this->translate('View comments'):$this->translate('Add comment') ?>">
                  <?php echo $this->partial('applications/manage/_rating', array('application' => $application)) ?>
              </button>
          <?php endif ?>
          </span>
                        </td>
                    </tr>
                    <?php if(!is_null($application->getDateCreated())): ?>
                        <?php if ($application->getDateCreated()->getTimestamp() != $application->getDateModified()->getTimestamp()):?>
                        <tr>
                            <td><?php echo $this->translate('last modification date')?>:</td>
                            <td>
                                <a data-title="title"
                                   data-toggle="modal"
                                   class="btn btn-default btn-xs"
                                   data-target="#cam-application-history"
                                   title="<?php echo $this->translate('Status history')?>">
                                    <i class="yk-icon yk-icon-history"></i>
                                </a>
                                <a data-title="title"
                                   data-toggle="modal"
                                   data-target="#cam-application-history"
                                   title="<?php echo $this->translate('Status history')?>">
                                    <?php echo $this->dateFormat($application->getDateModified()->getTimestamp(), 'short'); ?>
                                </a>
                            </td>
                        </tr>
                    <?php endif;?>
                    <?php endif; ?>
                    <tr>
                        <td><?php echo $this->translate('agent')?>:</td>
                        <td><?php echo $this->contactLink($job->getUser()->getInfo())?></td>
                    </tr>
                    <?php
                    if ($job->hasMetaData('organizations:managers')): ?>
                    <tr>
                        <td><?php echo $this->translate('Manager')?>:</td>
                        <td>
                            <ul>
                            <?php

                            $managers = $job->getMetaData('organizations:managers');

                            foreach ($managers as $manager) {
                                echo '<li>'.$manager['name'].'</li>';
                            }

                            ?>
                            </ul>
                        </td>
                    </tr>
                    <?php endif;?>
                <?php endif; # allowed only for recruiters ?>
                <?php if($application->getFacts()->getWillingnessToTravel()):?>
                    <tr>
                        <td><?php echo $this->translate('Willingness to travel')?>:</td>
                        <td><?php echo $application->getFacts()->getWillingnessToTravel() ?></td>
                    </tr>
                <?php endif?>
                <?php if($application->getFacts()->getEarliestStartingDate()):?>
                    <tr>
                        <td><?php echo $this->translate('Earliest starting date')?>:</td>
                        <td><?php echo $this->dateFormat($application->getFacts()->getEarliestStartingDate(),'short') ?></td>
                    </tr>
                <?php endif?>
                <?php if($application->getFacts()->getExpectedSalary()):?>
                    <tr>
                        <td><?php echo $this->translate('Expected salary')?>:</td>
                        <td><?php echo $application->getFacts()->getExpectedSalary() ?></td>
                    </tr>
                <?php endif?>
                <?php if($application->getFacts()->getDrivingLicense()):?>
                    <tr>
                        <td><?php echo $this->translate('Driving license')?>:</td>
                        <td><?php echo $application->getFacts()->getDrivingLicense()?$this->translate("Yes"):$this->translate("No") ?></td>
                    </tr>
                <?php endif?>
            </table>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                <i class="yk-icon yk-icon-summary"></i>
                <?php echo $this->translate('Cover Letter')?>
            </div>
            <div class="panel-body">
                <?php echo nl2br($application->getSummary()) ?>
            </div>
        </div>
    </div>
</div>

<?php if(count($application->getCv()->getEmployments())>0):?>
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="yk-icon yk-icon-work-experience"></i>
                    <?=$this->translate('work experience')?>
                </div>
                <table class="table table-condensed table-bordered">
                    <thead>
                    <tr>
                        <th class="col-md-1"><?=$this->translate('Start')?></th>
                        <th class="col-md-1"><?=$this->translate('End')?></th>
                        <th class="col-md-3"><?=$this->translate('Company')?></th>
                        <th><?=$this->translate('Description')?></th>
                    </tr>
                    </thead>
                    <?php foreach( $application->getCv()->getEmployments() as $employment): /* @var $employment \Cv\Entity\Employment */ ?>
                        <tr>
                            <td><?=$this->dateFormat($employment->getStartDate(),'medium', 'null')?></td>
                            <td><?=$this->dateFormat($employment->getEndDate(),'medium', 'null')?></td>
                            <td><?=$employment->getOrganizationName() ?></td>
                            <td><?=$employment->getDescription() ?></td>
                        </tr>
                    <?php endforeach; // employments?>
                </table>
            </div>
        </div>
    </div>
<?php endif;?>

<?php if(count($application->getCv()->getEducations())>0):?>
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="yk-icon yk-icon-university"></i>
                    <?=$this->translate('education and training')?>
                </div>
                <table class="table table-condensed table-bordered">
                    <tr>
                        <th class="col-md-1"><?=$this->translate('Start')?></th>
                        <th class="col-md-1"><?=$this->translate('End')?></th>
                        <th class="col-md-3"><?=$this->translate('University')?></th>
                        <th><?=$this->translate('Description')?></th>
                    </tr>
                    <?php foreach( $application->getCv()->getEducations() as $education): /* @var $education \Cv\Entity\Education */ ?>
                        <tr>
                            <td><?=$this->dateFormat($education->getStartDate(),'medium', 'null') ?></td>
                            <td><?=$this->dateFormat($education->getEndDate(),'medium', 'null') ?></td>
                            <td><?=$education->getOrganizationName() ?></td>
                            <td><?=$education->getDescription() ?></td>
                        </tr>
                    <?php endforeach; // educations?>
                </table>
            </div>
        </div>
    </div>
<?php endif;?>

<?php if(count($application->getCv()->getSkills())>0):?>
    <h2><?=$this->translate('personal skills')?></h2>
    <?php foreach( $application->getCv()->getSkills() as $kill): ?>
        <div class="col-md-3"><?php echo $this->translate('native language')?></div>
        <div class="col-md-3">TODO</div>
    <?php endforeach; // skills?>
<?php endif;?>

<?php
if ($application->isDraft()):
    echo $this->partial('applications/apply/_buttons', array('application' => $application, 'isPreview' => true));
endif
?>
