<?php
$this->PageTitle = 'Novidades';

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

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

$imagem = (User::getUser()->FUN_TBL_NOVIDADES == 1 ) ? FaHtml::iconNovo() : FaHtml::iconBlank();

$this->menu = array(
    array('label' => $imagem, 'url' => array('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'))
);
?>

<?php
$dataProvider = $model->search();
?>
<div class="search-form" style="display:<?php echo ($dataProvider->totalItemCount > 0) ? 'none' : 'block'; ?>" >
    <?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(),
    'columns' => array(
        'NOV_DATA',
        'NOV_ASSUNTO',
        array(
            'name' => 'Projeto',
            'value' => 'GxHtml::valueEx($data->Projeto)',
        ),
        array(
            'name' => 'VersaoProjeto',
            'value' => 'GxHtml::valueEx($data->VersaoProjeto)',
        ),
        array(
            'name' => 'Autor',
            'value' => 'GxHtml::valueEx($data->Autor)',
        ),
        array(
            'class' => 'CButtonColumn',
            'template' => $botoes,
            'viewButtonOptions' => array('target' => '_blank'),
            'updateButtonOptions' => array('target' => '_blank'),
            'buttons' => array(
                'view' => array(
                    'label' => 'Exibir',
                    'url' => 'Yii::app()->createUrl("novidades/view", array("id"=>$data->NOV_IDNOVIDADE))',
                ),
                'update' => array(
                    'label' => 'Editar',
                    'url' => 'Yii::app()->createUrl("novidades/update", array("id"=>$data->NOV_IDNOVIDADE))',
                    'visible' => 'getUpdate($data->NOV_IDFUNCIONARIO)',
                ),
                'delete' => array(
                    'label' => 'Excluir',
                    'url' => 'Yii::app()->createUrl("novidades/delete", array("id"=>$data->NOV_IDNOVIDADE))',
                ),
            ),
        ),
    ),
));

function getUpdate($NOV_IDFUNCIONARIO) {
    if (User::isAdmin() or $NOV_IDFUNCIONARIO == User::getId()) {
        return true;
    } else {
        return false;
    }
}