<? global $vis_language; 
$ticketpgcount=0;
//THIS ONE
		 /*  echo "Ticket Array : "; 
						echo "<pre>";
						print_r($ticket_details);
						echo "</pre>";
						echo "<br>"; */
		//THIS ONE

  if(isset($operation['vis_operation']) && $operation['vis_operation']=='get_details'){
    $paging_list='';
	
	
       for($i=0;$i<$view_info['page_count'];$i++) 
	   {
/*if(isset($operation['vis_page1']) && $operation['vis_page1']!='')
{
$paging_list.='<option value="'.$i.'" '.(($operation['vis_page1']==$i)?'selected="selected"':'').'>'.($i+1).'</option>'; 
}
else
{
$paging_list.='<option value="'.$i.'" '.(($ticket_info['page']==$i)?'selected="selected"':'').'>'.($i+1).'</option>'; 
}
*/	  $paging_list.='<option value="'.$i.'">'.($i+1).'</option>'; 
	   }
	   $ticketpgcount=$ticket_info['page'];
	 
	  
	   }
         if($ticket_details==-1){ ?>
			<? include(VIS_PATH_TEMPLATE.'no_record_yet.php'); 
			if(isset($operation['vis_operation']) && $operation['vis_operation']!='get_details') echo '<script> $("#view_action").hide(); $("#vis_ticket_form .panel-footer").hide(); $("#vis_ticket_list").hide(); $(".fullFrame").removeClass("b-t").addClass("m-t-lg m-b-lg"); </script>';
		 }
       else {
	  ?><script>
	
	  localStorage.setItem("ticket_page_count",'<?php echo $ticket_info['page'];?>');
	  </script>
	   <?
?>
 <script type="application/javascript"> $("#view_action").show(); $("#vis_ticket_form .panel-footer").show(); $("#vis_ticket_list").show(); </script>

<? if(isset($operation['vis_operation']) && $operation['vis_operation']=='get_details'){ ?>
<div class="row wrapper clr">
    <div class="col-sm-9 tkt_left_menu"></div>
    <div  class="col-sm-3 text-right text-center-xs tkt_right_menu" id="paging">
	
        <select name="pageing" class="form-control input-sm selectpicker pull-right paging v-middle" onchange="$(this).parents('#vis_details_list<?= ($ticket_id!=0)?'_'.$ticket_id:''; ?>').visExecution('load_area',{'vis_module':'ticket', 'vis_operation':'get_details', 'vis_action':'history', 'vis_client_id':'<? echo $operation['vis_client_id']; ?>','vis_ticket':1 <? if($ticket_id!=0){ ?>,'vis_ticket_id':<? echo $ticket_id; }?>});">
        <? echo $paging_list;?>
        </select>
		
        <div class="text-muted pull-right label_page"><? echo $vis_language['TXTPAGE']; ?>:</div>
    </div>
</div>
<? } 
    if((isset($operation['vis_ticket']) && $operation['vis_ticket']==1) ||(isset($operation['vis_chk_hide']) || $operation['vis_chk_hide']==true))
    	echo '<div class="table-responsive scroll-x">';
    ?>	
<table class="table table-hover m-b-none" data-ride="datatables">
    <thead class="table_head">
        <? //if(isset($operation['vis_operation']) && ($operation['vis_operation']=='filter_ticket' || $operation['vis_operation']=='filter_queue_ticket')){ ?>
			<? if(!isset($operation['vis_ticket']) && $operation['vis_ticket']!=1 && $operation['vis_action']!='history'){ ?>
        <th width="42px" class="p-r-none">
            <div class="btn-group list_chkbox_action">
                <label class="checkbox m-n m-r-sm i-checks"  style="float: left;"><input type="checkbox"><i></i></label>
                <div class="btn-group m-t-xs" id="toogle_list_check">
				<?php if($operation['vis_filter_id']!= 21){ ?>
                    <button class="btn bg-empty btn-xs dropdown-toggle action_btn" data-toggle="dropdown">
                    <span class="caret"></span></button>
                    <ul class="dropdown-menu">
                        <li><a href="javascript:void(0);" onclick="$(this).visInterface('toogle_list_check', {'vis_form':'#vis_ticket_form', 'vis_list_status_class':'.vis_list_read', 'vis_list_status':'checked'})"><? echo $vis_language['TXTSELECTALLREAD']; ?></a></li>
                        <li><a href="javascript:void(0);" onclick="$(this).visInterface('toogle_list_check', {'vis_form':'#vis_ticket_form', 'vis_list_status_class':'.vis_list_unread', 'vis_list_status':'checked'})"><? echo $vis_language['TXTSELECTALLUNREAD']; ?></a></li>
                    </ul>
					<?php } ?>
                </div>
            </div>
        </th>
        <? } ?>
        <th></th>
        <? for($i=0;$i<$view_info['view_count'];$i++) { 
			//if($view_details[$i]['tab_title']!='TXTFLAG' && $view_details[$i]['tab_title']!='TXTATTACHMENT' && $view_details[$i]['tab_title']!='TXTLINK') 
			if($view_details[$i]['tab_title']!='TXTATTACHMENT' && $view_details[$i]['tab_title']!='TXTLINK')
			echo '<th>'.$vis_language[$view_details[$i]['tab_title']].'</th>';
			else echo '<th></th>'; }?>
    </thead>
    <tbody>			  
        <?  $channel_class="";
            for($i=0;$i<$ticket_info['ticket_count'];$i++) { if(($i+1)==$ticket_info['ticket_count']){ $last_count	=	1; }else {  $last_count	=	0; } 
            	if($ticket_details[$i]['user_replied']==0 || $ticket_details[$i]['status_id']==3 || $ticket_details[$i]['sdue_time']==0) $due_color='';
            	elseif($ticket_details[$i]['due_time']<0) $due_color=' vis_overdue';
            	else $due_color=' vis_new';
            	echo '<tr class="'.(($ticket_details[$i]['is_read']==1)?'vis_read_message':'vis_unread_message').$due_color.'">';  
				     	
            	if(!isset($operation['vis_ticket']) && $operation['vis_ticket']!=1 && $operation['vis_action']!='history'){
					echo '<td class="p-r-none list_chkbox_action" id="checkbox_data"><label class="checkbox m-n i-checks"><input data-dept-id="'.$ticket_details[$i]['department_id'].'" data-status="'.$ticket_details[$i]['status_id'].'" type="checkbox" class="vis_list_checkbox '.(($ticket_details[$i]['is_read']==1)?'vis_list_read':'vis_list_unread').'" name="vis_ticket_mass_chk_'.$i.'" id="vis_ticket_mass_chk_'.$i.'" value="'.$ticket_details[$i]['ticket_id'].'"><i></i></label></td>';
					$channel_class="p-l-none";
				}
					echo '<td class="'.$channel_class.'" align="center">';
				if($operation['vis_filter_id']==21){ 
					echo '<a onmouseout="hide_user_details(this);"  data-html="true" href="javascript:void(0);" id="post_'.$ticket_details[$i]['ticket_id'].'" rel="popover"   onmouseover="show_schedule_details('.$ticket_details[$i]['ticket_id'].','.$last_count.');">';
				}else{
					echo '<a data-html="true" href="javascript:void(0);" id="post_'.$ticket_details[$i]['ticket_id'].'" rel="popover"   onclick="show_last_post('.$ticket_details[$i]['ticket_id'].');">';
				}
				if($operation['vis_filter_id']==21){ echo '<i class="vh vh-clock vh-green vh-lg"></i>'; 
				}else if($ticket_details[$i]['channel_id']<=23 && strstr($ticket_details[$i]['icon_path'], "vh vh-")) {
                    echo ($ticket_details[$i]['ticket_lock'] != -1 && !empty($ticket_details[$i]['ticket_lock'])) ? '<i class="vh vh-lock vh-lg vis_fl"></i>' : '<i class="'.$ticket_details[$i]['icon_path'].' vh-lg"></i>';
				}
				else
				{
					if(file_exists(VIS_PATH_PROFILE.$ticket_details[$i]['icon_path']))
						echo '<img src="'.VIS_PATH_PROFILE.$ticket_details[$i]['icon_path'].'" class="thumb-xxs">';
					else
						echo '<i class="vh vh-channel vh-lg"></i>';
				}
            	echo '</a></td>';
            	for($j=0; $j < $view_info['view_count']; $j++) {
					$class = ( $view_details[$j]['tab_name']=='ticket_hash' 
                            || $view_details[$j]['tab_name']=='owner') ? 'class="txt_nowrap"' : '';
							
					if($view_details[$j]['tab_name']=='link') {
						if(isset($ticket_details[$i]['link_present']) && $ticket_details[$i]['link_present']) {
							echo '<td '.$class.'align="left"><a data-html="true" href="javascript:void(0);" id="linkdata_'.$ticket_details[$i]['ticket_id'].'" rel="popover" onclick="show_link_data('.$ticket_details[$i]['ticket_id'].', '.$j.');">';
							echo '<i class="vh vh-link-2"></i>';
							echo '</a></td>';
						} else { 
							echo '<td></td>';
						}
            		}
            		else if(isset($operation['filter_id']) && ($operation['filter_id']==7 || $operation['filter_id']==21) &&($ticket_details[$i]['draft_id']>0)){
            			echo '<td '.$class.' ><a href="#/ticket/new_ticket/'.$operation['view_title'].'/'.$ticket_details[$i]['ticket_id'].'"'; 
						echo ($view_details[$j]['tab_name']=='ticket_status')? ' style="color:'.$ticket_details[$i]['status_color'].'" ':'';
						echo ($view_details[$j]['tab_name']=='ticket_priority')? ' style="color:'.$ticket_details[$i]['priority_color'].'" ':'';
					echo '>';
				}else{
            			echo '<td '.$class; echo ($view_details[$j]['tab_name']=='CI_attached')? 'align="center" ':''; echo'><a href="#/ticket/ticket_details/'.$ticket_details[$i]['ticket_hash'].'/'.$ticket_details[$i]['ticket_id'].'"'; 
						echo ($view_details[$j]['tab_name']=='ticket_status')? ' style="color:'.$ticket_details[$i]['status_color'].'" ':'';
						echo ($view_details[$j]['tab_name']=='ticket_priority')? ' style="color:'.$ticket_details[$i]['priority_color'].'" ':'';
					echo '>';
					}
					
															
            		if($view_details[$j]['tab_name']=='receive_date' || $view_details[$j]['tab_name']=='modify_date' || $view_details[$j]['tab_name']=='last_replier_time') {
            			echo format_datetime($ticket_details[$i][$view_details[$j]['tab_name']]);
            		}
            		
            		elseif($view_details[$j]['tab_name']=='due_time') {
            			/* if($ticket_details[$i]['user_replied']==0 || $ticket_details[$i]['status_id']==3 || $ticket_details[$i]['sdue_time']==0) echo $vis_language['TXTUNDUE'];
            			elseif($ticket_details[$i]['due_time']<0) echo $vis_language['TXTOVERDUE'];
            			else echo count_remain_time($ticket_details[$i][$view_details[$j]['tab_name']]); *///Previous
						
						if($ticket_details[$i]['user_replied']==0 || $ticket_details[$i]['status_id']==3 || $ticket_details[$i]['sdue_time']==0) echo $vis_language['TXTUNDUE'];
            			elseif($ticket_details[$i]['due_time']<0) echo $vis_language['TXTOVERDUE'];
						elseif(($ticket_details[$i]['pause_dtime']!="" && $ticket_details[$i]['pause_dtime']>0) && $ticket_details[$i]['status_id']!=3)
						{
							echo count_remain_time($ticket_details[$i]['pause_dtime']);
						}
						else
						{
							echo count_remain_time($ticket_details[$i][$view_details[$j]['tab_name']]);
						}
							
						
						
						
            		}
            		elseif($view_details[$j]['tab_name']=='resolution_time') {
            			/* if($ticket_details[$i]['status_id']==3 || $ticket_details[$i]['rdue_time']==0) echo $vis_language['TXTUNDUE'];
            			elseif($ticket_details[$i]['resolution_time']<0) echo $vis_language['TXTOVERDUE'];
            			else echo count_remain_time($ticket_details[$i][$view_details[$j]['tab_name']]); *///Previous
						
						if($ticket_details[$i]['status_id']==3 || $ticket_details[$i]['rdue_time']==0) echo $vis_language['TXTUNDUE'];
            			elseif($ticket_details[$i]['resolution_time']<0) echo $vis_language['TXTOVERDUE'];
						elseif(($ticket_details[$i]['pause_rtime']!="" && $ticket_details[$i]['pause_rtime']>0) && $ticket_details[$i]['status_id']!=3)
						{
							echo count_remain_time($ticket_details[$i]['pause_rtime']);
						}
						else
						{
							echo count_remain_time($ticket_details[$i][$view_details[$j]['tab_name']]);
						}
						
						
						
            			 
						
						
            		}
            		elseif($view_details[$j]['tab_name']=='flag_color') { 
						echo '<span class="vh-stack"><i class="vh vh-flag-inner vh-stack-lg" style="color:'.$ticket_details[$i][$view_details[$j]["tab_name"]].'"></i><i class="vh vh-flag-empty vh-stack-lg"></i></span>';            			
            		}
            		elseif($view_details[$j]['tab_name']=='owner') {
            			if($ticket_details[$i]['owner']=="" || $ticket_details[$i]['owner']==null ) echo $vis_language['TXTUNASSIGNED']; else echo str_replace(",", "<br />", $ticket_details[$i]['owner']);
            		}
            		elseif($view_details[$j]['tab_name']=='subject') { 
						$schedule_tick = ($ticket_details[$i]['schedule_id']!=0)? '<div class="btn-group wrapper-xxs p-l-none"><label class="no-border" title="'.$vis_language['TXTSCHEDULETICKET'].'"><i class="vh vh-clock vh-green"></i></label></div>' : '';
            			$internal_tkt1 = (!$ticket_details[$i]['client_id']) ? '<div class="btn-group wrapper-xxs p-l-none"><label class="no-border" title="'.$vis_language['TXTINTERNALTICKET'].'"><i class="vh vh-information-round vh-blue"></i></label></div>': '';	
						$internal_tkt = 	$schedule_tick.$internal_tkt1;					
            			echo (strlen($ticket_details[$i][$view_details[$j]['tab_name']])>60) ? $internal_tkt.substr($ticket_details[$i][$view_details[$j]['tab_name']], 0, 60).'...' : $internal_tkt.$ticket_details[$i][$view_details[$j]['tab_name']];
            		
					}
            		elseif($view_details[$j]['tab_name']=='label') {
						if($label_details[$i]!=-1) for($k=0;$k<count($label_details[$i]);$k++) {
            			echo '<span class="label m-l-xs font-normal" style="background-color:'.$label_details[$i][$k]['label_color'].';color: #fff;">'.$label_details[$i][$k]['label_name'].'</span>';
						echo ($k <= count($label_details[$i])) ? '<br>' : ''; }
            		}
            		elseif($view_details[$j]['tab_name']=='star') {
						echo '<span class="vh-yellow m-l-xs">';
					    for($cn=0;$cn<5;$cn++){ 
						   echo '<i class="vh '.($cn<$ticket_details[$i]['rating']?'vh-star':'vh-star-empty').'"></i>';
					    }
						echo '</span>';
            		}
            		elseif($view_details[$j]['tab_name']=='attachment') {
						if($ticket_details[$i]['attachment_count']>0) echo '<i class="vh vh-paperclip"></i>';
            		}
                    elseif($view_details[$j]['tab_name']=='email') {
						if($ticket_details[$i]['client_id']==0) echo $ticket_details[$i]['recipients'];
                        else echo $ticket_details[$i][$view_details[$j]['tab_name']];
            		}
					elseif($view_details[$j]['tab_name']=='organization') {
						 echo $ticket_details[$i][$view_details[$j]['tab_name']];
            		}
					elseif($view_details[$j]['tab_name']=='company_name') {
						 echo $ticket_details[$i][$view_details[$j]['tab_name']];
            		}
					
					elseif($view_details[$j]['tab_name']=='ticket_category') {
						 echo $ticket_details[$i][$view_details[$j]['tab_name']];
            		}
					elseif($view_details[$j]['tab_name']=='ticket_sub_cateogy') {
						 echo $ticket_details[$i][$view_details[$j]['tab_name']];
            		}
					elseif($view_details[$j]['tab_name']=='ticket_item') {
						 echo $ticket_details[$i][$view_details[$j]['tab_name']];
            		}
					elseif($view_details[$j]['tab_name']=='ticket_level') {
						 echo $ticket_details[$i][$view_details[$j]['tab_name']];
            		}
					elseif($view_details[$j]['tab_name']=='location') {
						 echo $ticket_details[$i][$view_details[$j]['tab_name']];
            		}
					elseif($view_details[$j]['tab_name']=='CI_attached') {
						 echo $ticket_details[$i]['ci_present'];
            		}
					
            		else echo $ticket_details[$i][$view_details[$j]['tab_name']];
            		echo '</a></td>';
            	}
            	echo '</tr>';
            }?>
			
    </tbody>
</table>

<? if((isset($operation['vis_ticket']) && $operation['vis_ticket']==1) ||(isset($operation['vis_chk_hide']) || $operation['vis_chk_hide']==true))
    echo '</div>';
?>
<? if(isset($operation['vis_operation']) && $operation['vis_operation']=='get_details'){  ?>
<footer class="wrapper panel-footer bg-white">
    <div class="row">
        <div class="col-sm-9 tkt_left_menu"></div>
        <div class="col-sm-3 text-right text-center-xs tkt_right_menu" id="paging">
            <select name="pageing" class="form-control input-sm selectpicker pull-right paging v-middle" onchange="$(this).parents('#vis_details_list<?= ($ticket_id!=0)?'_'.$ticket_id:''; ?>').visExecution('load_area',{'vis_module':'ticket', 'vis_operation':'get_details', 'vis_action':'history','vis_client_id':'<? echo $operation['vis_client_id']; ?>','vis_ticket':1});" >
            <? echo $paging_list;?>
            </select>
		
            <div class="text-muted pull-right label_page"><? echo $vis_language['TXTPAGE']; ?>:</div>
        </div>
    </div>
</footer>
<? }
    }?>

<script type="application/javascript">

 function show_schedule_details(ticket_id,last_count){
    	var popover_id = $("#post_"+ticket_id); 
    	if($(".popover").length){
    		popover_id.popover('destroy').removeAttr("data-content").removeAttr("data-original-title");
    	}
    	else{ 
    		$.ajax({
    			url: 'index.php?vis_tmpst=new Date().getTime()',
    			data: {'vis_module':'ticket', 'vis_operation':'show_schedule_details', 'vis_ticket_id':ticket_id},
    			type: "POST",
    			dataType: "html",
    			success: function(data) {
    				var close_btn = ""; 
    				popover_id.attr("data-html","true");
					popover_id.attr("data-content",data);
					if(last_count==1){	}   
    				popover_id.attr("data-original-title",close_btn);
    				popover_id.popover('show');				
    			},
    			error: function(xhr, ajaxOptions, thrownError) {$("#vis_global_msg_div").visInterface("load_global_message", "Error: "+xhr.status+" - "+thrownError);}
    		});
    	}
    }
	$(".selectpicker").selectpicker();
    $( "body" ).on( "click", function() {
      if($(".popover").length){ $("[id^='post_']").popover('destroy').removeAttr("data-content").removeAttr("data-original-title"); }
      if($(".popover").length){ $("[id^='linkdata_']").popover('destroy').removeAttr("data-content").removeAttr("data-original-title"); }
      if($("#toogle_list_check").hasClass("open") || $(".popover").length) $("#vis_ticket_list").addClass("scroll-x");
     
    });
    function show_last_post(ticket_id){
    	var popover_id = $("#post_"+ticket_id); 
    	if($(".popover").length){
    		popover_id.popover('destroy').removeAttr("data-content").removeAttr("data-original-title");
    	}
    	else{ 
    		$.ajax({
    			url: 'index.php?vis_tmpst=new Date().getTime()',
    			data: {'vis_module':'ticket', 'vis_operation':'last_post', 'vis_ticket_id':ticket_id},
    			type: "POST",
    			dataType: "html",
    			success: function(data) {
    				var close_btn = "<button type='button' class='close pull-right' data-dismiss='popover'> &times;</button><?= $vis_language['TXTLATESTPOST'];?>&nbsp;";
    				popover_id.attr("data-content",data);
    				popover_id.attr("data-original-title",close_btn);
    				popover_id.popover('show');				
    			},
    			error: function(xhr, ajaxOptions, thrownError) {$("#vis_global_msg_div").visInterface("load_global_message", "Error: "+xhr.status+" - "+thrownError);}
    		});
    	}
    }
	function show_link_data(ticket_id, link_col_pos){ 
    	var popover_id = $("#linkdata_"+ticket_id); 
		popover_id.attr('data-toggle','ajaxModal');
		popover_id.attr('data-modal-arguments','vis_module=ticket&vis_operation=load_link_data&vis_ticket_id='+ticket_id);
    }
</script>
<script type="text/javascript">

$(document).ready(function() {	
if(localStorage.getItem("clickreply")===null)
{

	<?php if($operation['filter_id']=='1') { ?>	
	localStorage.setItem("ticket_currnt_page",null);
	<? } ?>
}
var selectop='<?php echo $ticket_info['page'];?>';
<?php if($operation['vis_module']=="ticket") { ?>
if(localStorage.getItem("ticket_currnt_page")===null)
{
selectop='<?php echo $ticket_info['page'];?>';
}
else
{
selectop=localStorage.getItem("ticket_currnt_page");
localStorage.removeItem("ticket_currnt_page");
if ((typeof vis_apply_filter === "function" && selectop>0) || selectop==0) {
vis_apply_filter(parseInt(selectop),'<?= $operation['filter_id'];?>');
}

}
<?php } ?>

				
    	  var oTable =  $('[data-ride="datatables"]').dataTable({
    		"bAutoWidth": false,
            "bPaginate" : false,
			
			"bDeferRender": true,
			"bStateSave":true,
    		"sDom": 't',
    		"aoColumns": [
    		<? if(!(isset($operation['vis_action']) && $operation['vis_action']=='history')){?>
				{ "bSortable": false },
    		<? }//if ?>
				{ "bSortable": false },
    		  <?php for($i=0; $i<($view_info['view_count']); $i++){  
				//if( $view_details[$i]['tab_name'] == 'attachment' || $view_details[$i]['tab_name']=='flag_color' || $view_details[$i]['tab_name']=='link' || $view_details[$i]['tab_name']=='receive_date' || $view_details[$i]['tab_name']=='modify_date' || $view_details[$i]['tab_name']=='last_replier_time')
				if( $view_details[$i]['tab_name'] == 'attachment' || $view_details[$i]['tab_name']=='link' || $view_details[$i]['tab_name']=='receive_date' || $view_details[$i]['tab_name']=='modify_date' || $view_details[$i]['tab_name']=='last_replier_time' || $view_details[$i]['tab_name']=='due_time' || $view_details[$i]['tab_name']=='resolution_time') echo '{ "bSortable": false }'; else echo 'null'; if($i<count($view_details)-1) echo ','; }?>
    		],
		
			
     
    	});
		

<?php if($operation['vis_module']=="ticket") { ?>
if(selectop>0){
$('.pagination_ticket_list').twbsPagination({
totalPages:<?php echo $view_info['page_count']; ?>,visiblePages:3,startPage: ''+(parseInt(selectop)+1)+'',first:'<i class="vh vh-angle-double-left"></i>',prev:'<i class="vh vh-angle-left"></i>',next:'<i class="vh vh-angle-right"></i>',last:'<i class="vh vh-angle-double-right"></i>',onPageClick: function (event, page) {  page=parseInt(page)-1;  
vis_apply_filter(page,'<?= $operation['filter_id'];?>');
}
});
 
$(".pagination a").each(function() {
var oldv=$( this ).text();
if(oldv==(parseInt(selectop)+1)){$( this ).parent().addClass('active');
}else {$( this ).parent().removeClass('active');}});

}
<? } ?>
});
 localStorage.removeItem("clickreply");
</script>
