<?php

$this->PageTitle = 'Registro de envio de E-mail Marketing';

$botoes = '{view} {prospecto}';

if (User::isAdmin()) {
    $botoes .= ' {delete}';
}

$imagem = FaHtml::iconBlank();

$this->menu = array(
    array('label' => FaHtml::iconAtividadeMultipla(), 'url' => array('atendimentos/EmailMarketing'), 'linkOptions' => array('target' => '_blank', 'class' => 'novo')),
    array('label' => FaHtml::iconSetaClose(), 'url' => '#', 'linkOptions' => array('class' => 'search-button')),
    array('label' => FaHtml::iconRefresh(), 'url' => 'javascript:void(0);', 'linkOptions' => array('onclick' => 'reloadFrame();', 'class' => 'refresh-button'))
);

if(User::getPrivilegio() == 6 && User::getSetor() == 5) {
    $model->ATD_IDFUNCIONARIO = User::getId();
}

if(isset($_GET['Atendimentos'])) {
    $model->setAttributes($_GET['Atendimentos']);
}

$dataProvider = $model->searchEmailMarketing();

$coluna = -1;
if(in_array(User::getPrivilegio(), array(1, 6, 7, 8, 9, 13, 14, 20))) {
    $coluna = 0;
}
?>
<style type="text/css">
    /* data de lançamento */
    <?php $coluna++; ?>
    #admin-grid table th:nth-child(<?php echo $coluna; ?>):not(.empty),
    #admin-grid table td:nth-child(<?php echo $coluna; ?>):not(.empty) {
        min-width: 100px!important;
        max-width: 100px!important;
            width: 100px!important;
            text-align: center;
    }
    /* data */
    <?php $coluna++; ?>
    #admin-grid table th:nth-child(<?php echo $coluna; ?>):not(.empty),
    #admin-grid table td:nth-child(<?php echo $coluna; ?>):not(.empty) {
        min-width: 60px!important;
        max-width: 60px!important;
            width: 60px!important;
            text-align: center;
    }
    /* cliente */
    <?php $coluna++; ?>
    #admin-grid table th:nth-child(<?php echo $coluna; ?>),
    #admin-grid table td:nth-child(<?php echo $coluna; ?>) {
        min-width: 150px!important;
        max-width: 250px!important;
            width: 250px!important;
    }
    /* cidade */
    <?php $coluna++; ?>
    #admin-grid table th:nth-child(<?php echo $coluna; ?>),
    #admin-grid table td:nth-child(<?php echo $coluna; ?>) {
        min-width: auto!important;
        max-width: 150px!important;
            width: 150px!important;
    }
    /* atendente */
    <?php $coluna++; ?>
    #admin-grid table th:nth-child(<?php echo $coluna; ?>),
    #admin-grid table td:nth-child(<?php echo $coluna; ?>) {
        min-width: auto!important;
        max-width: 150px!important;
            width: 150px!important;
    }
    /* observações */
    <?php $coluna++; ?>
    #admin-grid table th:nth-child(<?php echo $coluna; ?>),
    #admin-grid table td:nth-child(<?php echo $coluna; ?>) {
        min-width: 450px!important;
        max-width: 450px!important;
            width: 450px!important;
    }
    /* ações */
    <?php $coluna++; $width=(User::isAdmin() ? 60 : 40); ?>
    #admin-grid table th:nth-child(<?php echo $coluna; ?>),
    #admin-grid table td:nth-child(<?php echo $coluna; ?>) {
        min-width: <?php echo $width; ?>px!important;
        max-width: <?php echo $width; ?>px!important;
            width: <?php echo $width; ?>px!important;
            text-align: center;
    }
</style>
<div class="search-form" <?php if($dataProvider->totalItemCount > 0) echo 'style="display: none;"'; ?> >
    <?php $this->renderPartial('_search_email_marketing', array('model' => $model)); ?>
</div><!-- search-form -->
<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'admin-grid',
    'dataProvider' => $dataProvider,
    'afterAjaxUpdate'=>'updated',
    'pager' => Util::getPagerDefaultConfig(),
    'selectableRows' => 1,
    'columns' => array(
        array(
            'name' => 'ATD_DTLANCAMENTO',
            'value' => '$data->ATD_DTLANCAMENTO',
            'visible' => in_array(User::getPrivilegio(), array(1, 6, 7, 8, 9, 13, 14, 20)),
        ),
        'ATD_DTCADASTRO',
        array(
            'name' => 'ATD_IDCLIENTE',
            'value' => 'GxHtml::valueEx($data->Cliente)',
        ),
        array(
            'name' => 'Cliente.Cidade',
            'value' => 'isset($data->Cliente->Cidade) ? $data->Cliente->Cidade : ""',
        ),
        array(
            'name' => 'Atendente',
            'header' => 'Autor',
            'value' => 'GxHtml::valueEx($data->Atendente)',
        ),
        array(
            'name' => 'ATD_OBS',
            'value' => 'nl2br($data->ATD_OBS)',
            'type' => 'raw'
        ),
        array(
            'class' => 'CButtonColumn',
            'template' => $botoes,
            'viewButtonOptions' => array('target' => '_blank'),
            'updateButtonOptions' => array('target' => '_blank'),
            'buttons' => array(
                'view' => array(
                    'label' => 'Exibir',
                    'url' => 'Yii::app()->createUrl("atendimentos/view", array("id"=>$data->ATD_IDATENDIMENTO, "retorno"=>"agenda"))',
                ),
                'prospecto' => array(
                    'label' => 'Cliente',
                    'imageUrl' => FaHtml::getImgUrl('ico-prospects.png'),
                    'url' => 'Yii::app()->createUrl("clientes/view", array("id"=>$data->ATD_IDCLIENTE))',
                    'options' => array('target' => '_blank'),
                ),
                'delete' => array(
                    'label' => 'Excluir',
                    'url' => 'Yii::app()->createUrl("atendimentos/vdelete", array("id"=>$data->ATD_IDATENDIMENTO))',
                ),
            ),
        ),
    ),
)
);