<?php

$this->PageTitle = 'Registro Campanhas Marketing';

$botoes = '{view}';

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

$imagem = FaHtml::iconBlank();

$this->menu = array(
    array('label' => FaHtml::iconCampanhaMarketing(), 'url' => array('campanhasMarketing/create'), '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(isset($_GET['Atendimentos'])) {
    $model->setAttributes($_GET['Atendimentos']);
}

$dataProvider = $model->search();

$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;
    }
    /* titulo */
    <?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;
    }
    /* responsavel */
    <?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: 100px!important;
            width: 100px!important;
    }
    /* total clientes */
    <?php $coluna++; ?>
    #admin-grid table th:nth-child(<?php echo $coluna; ?>),
    #admin-grid table td:nth-child(<?php echo $coluna; ?>) {
        min-width: 50px!important;
        max-width: 50px!important;
            width: 50px!important;
            text-align: center;
    }
    /* 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', array('model' => $model)); ?>
</div><!-- search-form -->
<?php
$this->widget('ext.Utils.widgets.CrmGridView', array(
    'id' => 'admin-grid',
    'dataProvider' => $dataProvider,
    'afterAjaxUpdate'=>'updated',
    'pager' => Util::getPagerDefaultConfig(),
    'selectableRows' => 1,
    'columns' => array(
        array(
            'name' => 'MKT_DATA_LANCAMENTO',
            'value' => '$data->MKT_DATA_LANCAMENTO',
            'visible' => in_array(User::getPrivilegio(), array(1, 6, 7, 8, 9, 13, 14, 20)),
        ),
        'MKT_DATA_ENVIO',
        'MKT_TITULO',
        'Responsavel',
        'MKT_COUNT_CLIENTES',
        array(
            'name' => 'MKT_TEXTO',
            'value' => 'nl2br($data->MKT_TEXTO)',
            '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("campanhasMarketing/view", array("id"=>$data->MKT_ID))',
                ),
                'delete' => array(
                    'label' => 'Excluir',
                    'url' => 'Yii::app()->createUrl("campanhasMarketing/delete", array("id"=>$data->MKT_ID))',
                ),
            ),
        ),
    ),
)
);