<?php
    $this->layout = false;
    $this->PageTitle = false;

    $to = isset($CLI_EMAIL) ? $CLI_EMAIL : '';
    $link = Util::linkEmailAtendimento($data, $to);

    $cs = Yii::app()->getClientScript();
    $cs->registerCssFile(FaHtml::getCssUrl('print.css'), 'print');

    $cs->registerCssFile(FaHtml::getJsUrl('bootstrap/css/bootstrap.min.css'));
    $cs->registerCssFile(FaHtml::getJsUrl('bootstrap/css/bootstrap-theme.min.css'));
    $cs->registerCssFile(FaHtml::getJsUrl('uibootstrap/css/bootstrap.min.css'));

    $cs->registerCssFile(FaHtml::getJsUrl('uibootstrap/css/font-awesome.min.css'));
    $cs->registerCssFile(FaHtml::getJsUrl('uibootstrap/css/font-awesome-ie7.min.css'));
    $cs->registerCssFile(FaHtml::getJsUrl('uibootstrap/css/font-awesome.min4.3.0.css'));

    $cs->registerCssFile(FaHtml::getJsUrl('jquery-ui-1.11.4/jquery-ui.min.css'));
    $cs->registerCssFile(FaHtml::getJsUrl('jquery-ui-1.11.4/jquery-ui.structure.min.css'));
    $cs->registerCssFile(FaHtml::getJsUrl('jquery-ui-1.11.4/themes/smoothness/jquery-ui.min.css'));
    $cs->registerCssFile(FaHtml::getJsUrl('jquery-ui-1.11.4/themes/smoothness/theme.css'));
    $cs->registerCssFile(FaHtml::getJsUrl('gallery/css/blueimp-gallery.min.css'));
    $cs->registerCssFile(FaHtml::getJsUrl('gallery/css/bootstrap-image-gallery.min.css'));

    $cs->registerCssFile(FaHtml::getCssUrl('main.css'));

    $cs->registerScriptFile(FaHtml::getJsUrl('jquery-2.2.3.min.js'));
    $cs->registerScriptFile(FaHtml::getJsUrl('jquery-ui-1.11.4/jquery-ui.min.js'));
    $cs->registerScriptFile(FaHtml::getJsUrl('jquery-ui-1.11.4/jquery-ui-i18n.min.js'));

    $cs->registerScriptFile(FaHtml::getJsUrl('browser.js'));
    $cs->registerScriptFile(FaHtml::getJsUrl('valida/valida.2.1.7.js'));
    $cs->registerScriptFile(FaHtml::getJsUrl('jquery.stickytableheaders.min.js'));
    $cs->registerScriptFile(FaHtml::getJsUrl('jquery.mask.min.js'));
    $cs->registerScriptFile(FaHtml::getJsUrl('bootstrap/js/bootstrap.min.js'));
    $cs->registerScriptFile(FaHtml::getJsUrl('gallery/js/jquery.blueimp-gallery.min.js'));
    $cs->registerScriptFile(FaHtml::getJsUrl('gallery/js/bootstrap-image-gallery.min.js'));
    $cs->registerScriptFile(FaHtml::getJsUrl('funcoes.js'));
    $cs->registerScriptFile(FaHtml::getJsUrl('ckeditor/ckeditor.js'));
?>
<h1>Atendimento com horas reduzidas de treinamento</h1>
<div class="items">
<div class="info-cliente atendimentos">
    <div class="col-xs-12 header">
        <a data-toggle="tooltip" data-placement="right" title="" data-original-title="Atendimento do Suporte"  class="col-xs-2">
            <i class="fa fa-life-ring"></i> Código: <?= $data->ATD_IDATENDIMENTO; ?>
        </a>
        <ul class="col-xs-10 text-right">
            <li><a href="<?= $link; ?>"><?= FaHtml::iconMail(); ?></a></li>
            <?php
            $ExplodeTipo = explode(',', $data->ATD_TIPO);
            if (($data->ATD_TIPO == "V" || @in_array('V', $ExplodeTipo)) && $data->Motivo->MOT_TIPO == 1) {
            ?>
                <li>
                    <a href="<?= Yii::app()->createUrl('atendimentos/pdf', array('id'=>$data->ATD_IDATENDIMENTO)); ?>"
                       target="_blank">
                       <?= FaHtml::iconPdf(); ?>
                    </a>
                </li>
            <?php } ?>
            <?php if ($data->getLinkEditar()) { ?>
                <li>
                    <a href="<?= Yii::app()->createUrl('atendimentos/'.$data->getLinkEditar(),
                                                       array('id'=>$data->ATD_IDATENDIMENTO)); ?>"
                        target="_blank"><?= FaHtml::iconUpdate(); ?>
                    </a>
                </li>
            <?php } ?>
            <?php if (User::isAdmin()) { ?>
                <li>
                    <a href="<?= Yii::app()->createUrl('atendimentos/savdelete', array('id'=>$data->ATD_IDATENDIMENTO)); ?>"
                       onclick="return confirm('Deseja realmente excluir este item?');">
                       <?= FaHtml::iconDelete(); ?>
                    </a>
                </li>
            <?php } ?>
        </ul>
    </div>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="solicitacoes-view">
        <tr class="odd">
            <td width="5%"><strong>Data</strong></td>
            <td width="15%"><?= $data->ATD_DTCADASTRO; ?></td>
            <td width="5%"><strong>Horário</strong></td>
            <td width="15%">
                <?php
                    echo substr($data->ATD_HORAINICIO, 0, 5);
                    if(isset($data->ATD_HORAFINAL)){
                        echo " às ".substr($data->ATD_HORAFINAL, 0, 5);
                    }
                ?>
            </td>
            <td width="10%"><strong>Total de Horas</strong></td>
            <td width="50%" colspan="3"><?= substr($data->ATD_TOTALHORAS, 0, 5); ?></td>
        </tr>
        <tr class="even">
            <td><strong>Tipo</strong></td>
            <td>
                <?= $data->ATD_TIPO == 'PR' ? 'Pendente de Retorno' : Util::getTipoAtendimento(explode(',', $data->ATD_TIPO)); ?>
            </td>
            <td><strong>Situação</strong></td>
            <td><?= Util::getSituacaoAtendimento($data->ATD_SITUACAO); ?></td>
            <td><strong>Motivo</strong></td>
            <td><?= $data->Motivo; ?></td>
            <td><strong>Versão</strong></td>
            <td><?= $data->Versao; ?></td>
        </tr>
        <tr class="odd">
            <td><strong>Contato</strong></td>
            <td><?= $data->ATD_CONTATO; ?></td>
            <td><strong>Veículo</strong></td>
            <td><?= $data->Veiculo; ?></td>
            <?php if(isset($data->Motivo->MOT_TIPO)) { ?>
                <td><strong><?= ($data->Motivo->MOT_TIPO == 1) ? 'Técnico' : 'Vendedor'; ?></strong></td>
            <?php } else { ?>
                <td><strong>Técnico/Vendedor</strong></td>
            <?php } ?>
            <td><?= $data->Atendente; ?></td>
            <td><strong>Autor</strong></td>
            <td><?= (empty($data->ATD_IDUSUARIO)) ? $data->Atendente : $data->Funcionario; ?></td>
        </tr>
        <tr class="even">
            <td><strong>Descrição</strong></td>
            <td colspan="7" class="overflow-break-word">
            <?php
                echo Util::niceTextAtendimentos($data->ATD_OBS);

                if($data->hasHorasReduzidas()) {
                    echo '<br /><br />';
                    echo '<b>Horas reduzidas da implantação: ' . $data->horasImplantacao().'</b><br />';
                    if($data->hasHorasDisponiveis()) {
                        echo '<b>Saldo disponível: ' . $data->horasDisponiveis().'</b>';
                    }
                }
            ?>
                <?php if (!empty($data->ATD_UPDATE)) { ?>
                    <a class="toggle_atendimentos_update" href="#" data-toggle="toggle_<?= $data->ATD_IDATENDIMENTO; ?>">
                        Atualizações<i class="fa fa-sort-desc"></i>
                    </a>
                <?php } ?>
            </td>
        </tr>
        <?php $last = 'even'; ?>
        <?php if (!empty($data->ATD_UPDATE)) { ?>
            <tr class="<?= $last = ($last=='even'?'odd':'even'); ?> toggle_atd toggle_<?= $data->ATD_IDATENDIMENTO; ?>">
                <td><strong>Atualizações</strong></td>
                <td colspan="7" class="overflow-break-word"><?= Util::niceTextAtendimentos($data->ATD_UPDATE); ?></td>
            </tr>
        <?php } ?>
        <?php if(!empty($data->Arquivos)) { ?>
            <tr class="<?= empty($data->ATD_UPDATE) ? 'even' : 'odd'; ?>">
                <td><strong>Arquivos</strong></td>
                <td colspan="7">
                    <ul id="links" class="imagens tab-pane fade in active">
                        <?php foreach($data->Arquivos as $arquivo) { ?>
                            <li><?= $arquivo->getLink(); ?></li>
                        <?php }?>
                    </ul>
                </td>
            </tr>
        <?php }?>
    </table>
</div>
</div>