<?php
$renewals = array();
$renewal_colors = array();
$renewal_rowHeaders = array();
$renewal_paramUrl = array();


$dashboard_summary_records = SummaryDashboardPerSegment::getDataPerDate($is_current, $tids, $vehicles, $radioactives, $assets, $segments, $date);
if ($dashboard_summary_records != null)
    $renewals = SummaryDashboardPerSegment::getRenewalInfos($is_current,$dashboard_summary_records['segment_name'], $dashboard_summary_records['id'], $renewal_colors, $renewal_rowHeaders, $renewal_paramUrl);
?>

<?php
if ($dashboard_summary_records != null)
    $this->widget('ext.DashboardTable', array(
	'rowHeaders' => array_merge(SummaryDashboardPerSegment::dashboardRowHeader(), $renewal_rowHeaders),
	'columnHeaders' => $segments,
	'params_used_in_all_urls' => array(
	    'date' => $date
	),
	'params_used_in_all_urls_rows' => array(
	    'status' => array_merge(SummaryDashboardPerSegment::dashboardRowsUrl(), $renewal_paramUrl)
	),
	'params_used_in_all_urls_columns' => array(
	    'segment' => SummaryDashboardPerSegment::getSegmentList($is_current, $date)
	),
	'visibleColumns' => (!empty($selected_segments)) ? $selected_segments : SummaryDashboardPerSegment::getSegmentList($is_current, $date, false),
	'data' => array(
	    'TIDs' => array(
		'data' => $tids,
		'url' => array('/dashboardReport/viewTIDDetail', 'is_current' => $is_current),
		'skips_values' => array(
		    '0',
		    '$0'
		),
		'visible' => strpos($section_visibility_array, 'tids') !== false
	    ),
	    'Vehicles' => array(
		'data' => $vehicles,
		'url' => array('/dashboardReport/viewAssetDetail', "type_of_asset_id" => Setting::getVehicleTypeOfAsset(), 'is_current' => $is_current),
		'skips_values' => array(
		    '0',
		),
		'visible' => strpos($section_visibility_array, 'vehicles') !== false
	    ),
	    'Radioactives' => array(
		'data' => $radioactives,
		'url' => array('/dashboardReport/viewAssetDetail', "type_of_asset_id" => Setting::getRadioActiveTypeOfAsset(), 'is_current' => $is_current),
		'skips_values' => array(
		    '0',
		),
		'visible' => strpos($section_visibility_array, 'radioactives') !== false
	    ),
	    'Assets' => array(
		'data' => $assets,
		'show_group_title' => false,
		'url' => array('/dashboardReport/viewAssetDetail', 'is_current' => $is_current),
		'skips_values' => array(
		    '0',
		),
		'visible' => strpos($section_visibility_array, 'vehicles') !== false || strpos($section_visibility_array, 'radioactives') !== false
	    ),
	    'TIDs Under Processing' => array(
		'data' => $renewals,
		'url' => array('/dashboardReport/viewTIDDetail', 'is_current' => $is_current, 'renewal' => 'true'),
		'skips_values' => array(
		    '0',
		),
		'visible' => strpos($section_visibility_array, 'renewalprogress') !== false
	    ),
	),
	'colors' => array_merge(SummaryDashboardPerSegment::dashboardRowsColors(), $renewal_colors),
    ));
?>

<script type="text/javascript">   
    
    var dashboard_update ="<?php echo (Setting::getdashboardUpdatePeriod() == '' || Setting::getdashboardUpdatePeriod() == null) ? 5000 : Setting::getdashboardUpdatePeriod() * 1000; ?>";
    jQuery(function($) {
	function updateDashboard()
	{
	  
	    //	    var selected_segments_array = [];
	    //	    $('#segment_name > option').each(function()
	    //	    {
	    //		if($(this).attr('selected') == 'selected')
	    //		    selected_segments_array.push($(this).text());
	    //	    });
	    //	    var selected_segments =  JSON.stringify(selected_segments_array);
	    var is_current = '<?php echo $is_current ?>';
	    var date = '<?php echo $date ?>';
	    var section_visibility_array = '<?php echo $section_visibility_array ?>';
	    var selected_segments = '<?php echo json_encode($selected_segments) ?>';
	    $.ajax({
		type:'post',
		data: {'ajax':true,
		    'is_current' : is_current,
		    'date' : date,
		    'section_visibility_array' : section_visibility_array,
		    'selected_segments':selected_segments
		},
		url: '<?php echo Yii::app()->createAbsoluteUrl('dashboardReport/view'); ?>',
		success: function(data) {		    
		    //$('#dashboard_container_div').html("");
		    $('#dashboard_container').html(data);
		},
		error: function(data,status,event, request, options) {	    
		    
		}
	    });
	}	
	setTimeout(updateDashboard, dashboard_update);
    });

</script>