<style>
    span.required {
	color: #eee!important;
    }

    .red-star {
	color: #eee!important;
	display: none;
    }
</style>
<?php
/* @var $this TidController */
/* @var $model Tid */
$this->breadcrumbs = array(
    yii::t('default', 'Dashboard') => array('view'),
    (($status == 'Fine' || $status == 'Days Count') ? 'Expired' . " " . yii::t('default', 'TIDs') . " \\ " . $status : $status . " " . yii::t('default', 'TIDs')) .
    (($segment == 'Total') ? ' - Total Segments' : ' - ' . $segment),
);


Yii::app()->clientScript->registerScript('search', "
	$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
	});
	$('.search-form form').submit(function(){
	$('#tid-grid').yiiGridView('update', {
	data: $(this).serialize()
	});
	return false;
	});



	
");
?>
<?php
echo CHtml::link('Export', array('TIDExportToExcel', 'renewal' => $renewal, 'segment' => $segment, 'status' => $status, 'date' => $date, 'is_current' => ($model instanceof VTid) ? true : false), array('class' => 'btn btn-success'));
?>
&nbsp;
<?php echo CHtml::link('Advanced Search', '#', array('class' => 'search-button btn')); ?>
<div class="search-form" style="display:none">
    <?php
    $this->renderPartial('/tid/_search', array(
	'model' => $model,
    ));
    ?>
</div><!-- search-form -->


<div id="flash-msg">
    <br>
    <?php $this->widget('bootstrap.widgets.TbAlert'); ?>
</div>


<?php
    $this->widget('yiiwheels.widgets.grid.WhGridView', array(
	'id' => 'tid-grid',
	'dataProvider' => $model->search($segment, $status, $date, $renewal),
	'filter' => $model,
	'afterAjaxUpdate' => 'function(id,options) {
                hide_column();
		$("td.empty").show();
	    }',
	'columns' => array(
	    'number',
	    array(
		'name' => 'tid_no',
		'type' => 'html',
		'value' => (($model instanceof VTid) ? 'CHtml::link($data->tid_no, array("/tid/view", "id" => $data->id))' : 'CHtml::link($data->tid_no, array("/tid/view", "id" => $data->tid_id))'),
	    ),
	    'value',
	    array(
		'name' => 'point_of_entry_name',
		'value' => '$data->point_of_entry_name',
		'filter' => PointOfEntry::getNamesForView(),
		'htmlOptions' => array('width' => '100'),
	    ),
	    array(
		'name' => 'last_status_ti_status',
		'value' => '$data->last_status_ti_status',
		'filter' => TidStatus::getStatusOptions()
	    ),
	    array(
		'name' => 'last_status_ti_type_id',
		'value' => '$data->ti_type_name',
		'filter' => TiType::getNamesForView()
	    ),
	    array(
		'name' => 'last_status_ti_expiry_date',
		'value' => '($data->last_status_ti_expiry_date != "0000-00-00") ?$data->last_status_ti_expiry_date: ""',
	    ),
	    array(
		'name' => 'last_status_contract_id',
		'value' => '$data->contract_reference',
		'filter' => Contract::getNamesForView()
	    ),
	    'expiry_days',
	    'fine',
	    'grace_period',
	    array(
		'name' => 'segment_name',
		'value' => '$data->segment_name',
		'filter' => Segment::getNamesForView()
	    ),
	    array(
		'name' => 'last_status_under_processing',
		'value' => '($data->last_status_under_processing == null) ? "" : $data->last_status_under_processing',
		'filter' => array('Yes' => Yii::t('default', 'Yes'), 'No' => Yii::t('default', 'No'))
	    ),
	    array(
		'name' => 'renewal_stage_name',
		'value' => '$data->renewal_stage_name',
		'filter' => RenewalStage::getNamesForView()
	    ),
	    array(
		'class' => 'CButtonColumn',
		'htmlOptions' => array('width' => '120'),
		'template' => '{update} {delete} {renew} {add_invoice} {add_asset}',
		'afterDelete' => 'function(link,success,data){ if(success) $("#flash-msg").html(data); }',
		'buttons' => array(
		    'delete' => array
			(
			'url' => (($model instanceof VTid) ? 'Yii::app()->createAbsoluteUrl("tid/delete", array("id" => $data->id))' : 'Yii::app()->createAbsoluteUrl("tid/delete", array("id" => $data->tid_id))'),
			'visible' => 'Yii::app()->user->checkAccess(User::SYSTEM_ADMIN_ROLE) && !Yii::app()->user->isGuest',
		    ),
		    'update' => array
			(
			'url' => (($model instanceof VTid) ? 'Yii::app()->createAbsoluteUrl("tid/update", array("id" => $data->id))' : 'Yii::app()->createAbsoluteUrl("tid/update", array("id" => $data->tid_id))'),
			'visible'=>'!Yii::app()->user->isGuest'
		    ),
		    'renew' => array
			(
			'label' => Yii::t('default', 'Renew'),
			'url' => (($model instanceof VTid) ? 'array("tid/renew","id"=>$data->id)' : 'array("tid/renew","id"=>$data->tid_id)'),
			'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/renew.png',
			'visible' => ($model instanceof VTid) 
				? '(($data->getLastStatus() != null) ? ($data->getLastStatus()->tiType->validity_mode == "Permanent" ?  false : true) : true) && !Yii::app()->user->isGuest'
				: '(($data->tid->getLastStatus() != null) ? ($data->tid->getLastStatus()->tiType->validity_mode == "Permanent" ?  false : true) : true) && !Yii::app()->user->isGuest',
		    ),
		    'add_invoice' => array(
			'label' => Yii::t('default', 'Add New Invoice'),
			'url' => (($model instanceof VTid) ? 'array("invoice/create","tid_id"=>$data->id)' : 'array("invoice/create","tid_id"=>$data->tid_id)'),
			'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/add_invoice.png',
			'visible'=>'!Yii::app()->user->isGuest'
		    ),
		    'add_asset' => array(
			'label' => Yii::t('default', 'Add New Asset'),
			'url' => (($model instanceof VTid) ? 'array("asset/create","tid_id"=>$data->id)' : 'array("asset/create","tid_id"=>$data->tid_id)'),
			'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/add_asset.png',
			'visible'=>'!Yii::app()->user->isGuest'
		    ),
		),
	    ),
	),
    ));
?>

    <script type="text/javascript">
        var status = '<?php echo $status ?>';
function hide_column() {
grid = $('#tid-grid');
$('tr', grid).each(function() {
    $('td:eq(2), th:eq(2),td:eq(8), th:eq(8),td:eq(9), th:eq(9),td:eq(10), th:eq(10)', this).hide();
});
if(status == 'Fine')
    $('tr', grid).each(function() {
	$('td:eq(9), th:eq(9)', this).show();
    });
else
    if(status == 'Days Count')
	$('tr', grid).each(function() {
	    $('td:eq(8), th:eq(8)', this).show();
	});
else
    if(status == 'Grace')
	$('tr', grid).each(function() {
	    $('td:eq(10), th:eq(10)', this).show();
	});

}
hide_column() ;
</script>
