<script type="text/javascript" src="<?= VIS_PATH_SCRIPT; ?>datatables/data-tables/DT_bootstrap.js"></script>
<?
    global $vis_language;
    if($report!=-1) {?>
<table cellpadding="0" cellspacing="0" border="0" class="table table-hover b-t b-light m-b-none" id="datatable">
   <thead class="table_head">  
   	<tr>
   		<th colspan="3" align="center"><? echo $vis_language['TXTTOTALTICKETREPLIED'].": ".count($replied).'/'.count($report); ?></th>
		<th colspan="3" align="center"><? echo $vis_language['TXTTOTALAVGRESPONSESLAMAINTAIN'].": ".(($report_cnt==0)?0:round((($responseCount/count($report))*100), 2)).'%'; ?></th>
		<th colspan="3" align="center"><? echo $vis_language['TXTTOTALAVGRESOLUTIONSLAMAINTAIN'].": ".(($report_cnt==0)?0:round((($resolutionCount/count($report))*100), 2)).'%'; ?></th>
	</tr>       
	<tr>
		<th><? echo $vis_language['TXTTICKETHASH']; ?></th>
		<th><? echo $vis_language['TXTSUBJECT']; ?></th>
		<th><? echo $vis_language['TXTCLIENT']; ?></th>
		<th><? echo $vis_language['TXTORGN']; ?></th>
        <th><? echo $vis_language['TXTCREATIONDATE']; ?></th>		
		<th><? echo $vis_language['TXTSTATUS']; ?></th>		
		<th><? echo $vis_language['TXTSLAPLAN'];?></th>	
		<th><? echo $vis_language['TXTAVGRESPONSE'];?></th>
		<th><? echo $vis_language['TXTAVGRESOLUTIONTIME']; ?></th>	
		<th><? echo $vis_language['TXTRESPONSESLA']; ?></th>	
		<th><? echo $vis_language['TXTRESOLUTIONTSLA']; ?></th>	
	</tr>
    </thead>
	  <?   
	  	foreach($report as $ticket_id => $details) 
		{
			$resolution_flag = ($details['pause_rtime']!='') ? $details['pause_rtime']:'';
			if($details['total_sla_seconds'] > $details['used_sla_seconds']){
				$timestamp = $details['timestamp']/$details['count'];
			}else{
				$timestamp = $details['timestamp'];
			}
		    $setUndue = 0;
		    $sla_name = ($details['sla_name']!= '')?$details['sla_name']:$vis_language['TXTCUSTDUETIME'];
            echo '<tr><td class="txt_nowrap"><a href="#/ticket/ticket_details/'.$details['ticket_hash'].'/'.$details['ticket_id'].'">'.$details['ticket_hash'].'</a> </td><td class="txt_nowrap">'.$details['subject'].'</td><td class="txt_nowrap">'.$details['email'].'</td><td class="txt_nowrap">'.$details['group_name'].'</td><td class="txt_nowrap">'.format_datetime($details['ticket_entry']).'</td>
            <td>'.$details['status_name'].'</td><td>'.$sla_name.'</td><td class="txt_nowrap">';
            //echo ($details['is_posted'] && $details['count']!=0)?count_remain_time(round(($details['timestamp']/$details['count']),2)):'Not responded';
			echo ($details['is_posted'] && $details['count']!=0) ? count_remain_time(round(($timestamp),2)) : 'Not responded';
			$resolution_time = ($resolution_flag!='')?count_remain_time($resolution_flag):$report[$ticket_id]['avg_resolution_time'];
            echo '</td><td class="txt_nowrap">'.$resolution_time.'</td><td>';
            echo $details['response_sla'];
            echo "</td><td>";
            echo $details['resolution_sla'];
            echo "</td></tr>";
            
            
        } ?>         
</table>
         <script>
		 	$("#vis_export_rpt_<?= $operation['vis_operation'] ?>").show(); 
		 	$("#vis_export_rpt_<?= $operation['vis_operation'] ?>").html('<a href="javascript:void(0);" class="vis_button_export btn btn-primary btn-sm" data-toggle="ajaxModal" data-modal-arguments="vis_module=report&vis_operation=add_report_inqueue&vis_static_area=vis_open_new_dialog&duration=<? echo $data['duration']; ?>&from_date=<? echo strtotime($data['from_date']); ?>&to_date=<? echo strtotime($data['to_date']);?>&department_id=<? echo $data['department_id'];?>&vis_client_id=<? echo $data['vis_client_id'];?>&vis_criteria=<? $data['vis_criteria'];?>&report_type=2" onclick="" type="button"><? echo $vis_language['TXTEXPORT']; ?></a>'); 
		 	
		 	$("#vis_schedule_rpt_<?= $operation['vis_operation'] ?>").show(); 
		 	$("#vis_schedule_rpt_<?= $operation['vis_operation'] ?>").html('<a href="javascript:void(0);" class="vis_button_export btn btn-primary btn-sm" data-toggle="ajaxModal" data-modal-arguments="vis_module=report&vis_operation=add_schedule_report_inqueue&vis_static_area=vis_open_new_dialog&duration=<? echo $data['duration']; ?>&from_date=<? echo strtotime($data['from_date']); ?>&to_date=<? echo strtotime($data['to_date']);?>&department_id=<? echo $data['department_id'];?>&vis_client_id=<? echo $data['vis_client_id'];?>&vis_criteria=<? $data['vis_criteria'];?>&report_type=2" onclick="" type="button"><? echo $vis_language['TXTSCHEDULE']; ?></a>'); 
		</script><?
    }
    else  {
		$operation['no_record']=1;
        include(VIS_PATH_TEMPLATE.'no_record_yet.php');
        ?>
             <script> $("#vis_export_rpt_<?= $operation['vis_operation'] ?>").hide();
             $("#vis_schedule_rpt_<?= $operation['vis_operation'] ?>").hide();
             </script>          
        <?php
    } ?>
	
	<script>
$(document).ready(function() {	
$('#datatable').dataTable({		
       "bPaginate" : true,
       "aaSorting":  [],
       "iDisplayLength": <?php echo SECURITY_DATA_PER_PAGE;?>,
	   "sDom": '<"top"iflp<"clear">>rt<"bottom"iflp<"clear">>', 		
	   "bFilter" : false,
	   "bLengthChange": false,
	   "bInfo": false,
	   "aoColumns": [
			{ "bSortable": true },
			{ "bSortable": true },
			{ "bSortable": true },
			{ "bSortable": true },
		  	{ "bSortable": true },	
			{ "bSortable": true },	
			{ "bSortable": true },	
			{ "bSortable": true },	   
		  	{ "bSortable": true },
			{ "bSortable": true },	   
		  	{ "bSortable": true }
		]
	});
});	
</script>
