<?
   if(!empty($post_details))
   {
       global $vis_language, $request_data;
       $post_count=count($post_details);
       if($post_paging_count>1){ ?>
<div class="text-right">
   <ul class="pagination m-t-xs pagination_ticket_post" id=""></ul>
</div>
<? } 
   for($i=0;$i<$post_count;$i++) { ?>	
<section id="vis_ticket_post_<? echo $post_details[$i]['post_id']; ?>">
   <? if($comment_details[$i]!=-1)
      foreach($comment_details[$i] as $comment){?>
   <section class="panel panel-default pos-rlt clearfix m-b-md" id="vis_ticket_post_comment_area_<? echo $comment['remark_id']; ?>">
      <div class="panel-heading b-b b-light">
         <div class="">
            <div class="row">
               <div class="m-l pull-left">
                  <label class="pull-left"><? echo $vis_language['TXTCOMMENTPOSTEDBY']; ?></label>
                  <a class="link m-l-xs" href="#/home/profile_view/Profile/<? echo $comment['staff_id'];?>"><i class="vh vh-user m-r-xs"></i><? echo $comment['staff_name'];?></a>
               </div>
               <div class="pull-right m-r">
                  <label class="pull-left"><? echo $vis_language['TXTPOSTON']; ?></label>
                  <div class="text-muted m-r pull-left"><i class="m-r-xs"></i><? echo format_datetime($comment['remark_date']); ?></div>
                  <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                  <span class="caret"></span>
                  </button>
                  <ul class="dropdown-menu dropdown-menu-right text-left" role="menu">
                     <li><a data-toggle="ajaxModal" data-modal-arguments="vis_module=ticket&vis_operation=confirm_delete_comment&vis_remark_id=<? echo $comment['remark_id']; ?>&vis_static_area=vis_comment_delete_form&vis_ticket_id=<? echo $ticket_details['ticket_id']; ?>"><? echo $vis_language['TXTDELETE']; ?></a></li>
                     <li>
                        <a  title="<?= $vis_language['TXTREPLYWITHQUOTE']?>" href="javascript:void(0);"
                           onclick="$('#vis_ticket_comment_content_edit_<? echo $comment['remark_id'];?>').visExecution('load_area',{'vis_module':'ticket', 'vis_operation':'ticket_comment_edit', 'vis_remark_id':'<? echo $comment['remark_id']; ?>', 'vis_ticket_id':<? echo $ticket_details['ticket_id']; ?>});"><? echo $vis_language['TXTEDIT']; ?></a>
                     </li>
                  </ul>
               </div>
            </div>
         </div>
      </div>
      <div class="panel-collapse wrapper" id ="vis_ticket_comment_content_text_<? echo $comment['remark_id']; ?>">
         <div><?= $comment['content']; ?></div>
      </div>
      <div class="panel-collapse wrapper" id="vis_ticket_comment_content_edit_<? echo $comment['remark_id']; ?>"></div>
   </section>
   <?  } ?>
   <section class="panel panel-default pos-rlt clearfix m-b-md" id="vis_ticket_post_area_<? echo $post_details[$i]['post_id']; ?>">
      <div class="panel-heading b-b b-light padder-v">
         <div class="btn-group pull-right">
            <div class="pull-left m-r-sm m-t-xs">
               <label><? echo $vis_language['TXTPOSTON']; ?></label>
               <span class="text-muted m-l-xs"><? echo format_datetime($post_details[$i]['receive_date']); ?></span>
            </div>
            <? if(isset($post_details[$i]['modify_date']) && $post_details[$i]['modify_date']!=""){ ?>
            <div class="pull-left m-r-sm m-t-xs">
               <label><? echo $vis_language['TXTMODIFIEDON']?></label>
               <span class="text-muted m-l-xs"><? echo format_datetime($post_details[$i]['modify_date']); ?></span>
            </div>
            <? } ?>
            <a class="btn btn-default btn-sm" title="<?= $vis_language['TXTREPLYWITHQUOTE']?>" href="javascript:void(0);" onclick="$('#vis_ticket_reply_<? echo $ticket_details['ticket_id']; ?>').visExecution('reply_forward', {'vis_ticket_id':<? echo $ticket_details['ticket_id']; ?>, 'vis_department_id':<? echo $ticket_details['department_id']; ?>, 'vis_domain_id':<? echo $ticket_details['domain_id']; ?>, 'vis_action':'reply', 'vis_post_id':<? echo $post_details[$i]['post_id']; ?>}); <? if($autoticketlockflag==1){?>$('#vis_ticket_reply_<?= $ticket_details['ticket_id']; ?>').visExecution('load_operations',{'vis_module':'ticket', 'vis_operation':'lock_onreplyticket', 'vis_action':'lock', 'vis_ticket_id':<? echo $ticket_details['ticket_id']; ?>}); <? }?>"><i class="vh vh-mail-reply text-muted"></i></a>
            <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
            <span class="caret"></span>
            </button>
            <ul class="dropdown-menu dropdown-menu-right text-left" role="menu">
               <li><a href="javascript:void(0);" onclick="$('#vis_ticket_reply_<? echo $ticket_details['ticket_id']; ?>').visExecution('reply_forward', {'vis_ticket_id':<? echo $ticket_details['ticket_id']; ?>, 'vis_department_id':<? echo $ticket_details['department_id']; ?>, 'vis_domain_id':<? echo $ticket_details['domain_id']; ?>, 'vis_action':'forward', 'vis_post_id':<? echo $post_details[$i]['post_id']; ?>});"><? echo $vis_language['TXTFORWARD']; ?></a></li>
               <li><a href="javascript:void(0);" onclick="$('#vis_ticket_post_content_edit_<? echo $post_details[$i]['post_id']; ?>').visExecution('load_area',{'vis_module':'ticket', 'vis_operation':'post_edit', 'vis_post_id':<? echo $post_details[$i]['post_id']; ?>, 'vis_ticket_id':<? echo $ticket_details['ticket_id']; ?>});"><? echo $vis_language['TXTEDIT']; ?></a></li>
               <li><a href="javascript:void(0);" data-toggle="ajaxModal" data-modal-arguments="vis_module=ticket&vis_operation=confirm_delete_post&vis_static_area=vis_post_delete_form&vis_ticket_id=<? echo $ticket_details['ticket_id']; ?>&vis_post_id=<? echo $post_details[$i]['post_id']; ?>"><? echo $vis_language['TXTDELETE']; ?></a></li>
               <li><a href="javascript:void(0);" data-toggle="ajaxModal" data-modal-arguments="vis_module=ticket&vis_operation=show_split_ticket_post_form&vis_ticket_id=<? echo $ticket_details['ticket_id']; ?>&vis_post_id=<? echo $post_details[$i]['post_id']; ?>"><? echo $vis_language['TXTSPLIT']; ?></a></li>
            </ul>
            <div class="clear"></div>
         </div>
         <div class="pull-left clear">
            <?
               $post_client_details = $ticket_object->client_details('email="'.$post_details[$i]['submitter_email'].'" and domain_id = "'.$ticket_details['domain_id'].'"'); 
               if($post_details[$i]['submitter']==1 && $post_client_details != -1 ) $link = 'href="#/client/client_details/'.$post_details[$i]['full_name'].'/'.$ticket_details['client_id'].'"';
               else if($post_client_details == -1 && $post_details[$i]['submitter']==1) $link = "";
               else $link = 'href="#/home/profile_view/'.$vis_language['TXTPROFILE'].'/'.$post_details[$i]['submitter_id'].'"'; ?>
               
                <a <?= $link; ?> class="">
            <? if($post_details[$i]['image']=='' || $post_details[$i]['image']=='default.jpg'){?>
          <div class="l-avatar m-r-sm">
          <? if($post_details[$i]['first_name']!=''){
											$firstname=preg_split('//u', $post_details[$i]['first_name'], -1, PREG_SPLIT_NO_EMPTY); 
											$lastname=preg_split('//u', $post_details[$i]['last_name'], -1, PREG_SPLIT_NO_EMPTY);
											$fullname=ucfirst($firstname[0]).ucfirst($lastname[0]);
											
											?>
   <div class="b"><? echo $fullname;?></div>
    <? }else{ ?>
    <img class="b" src="<?= VIS_PATH_PROFILE.'default.jpg';?>">
    <? }?>
          
          </div>
          <? }else{ ?>
          <div class="l-avatar m-r-sm">
          <img src="<? echo VIS_PATH_PROFILE; echo $post_details[$i]['image']; ?>" class="b" >
          </div>
          <? }?>
          </a>
           <!-- <a <? //= $link; ?> class="thumb m-r-sm avatar">
            <img src="<? //echo VIS_PATH_PROFILE; echo ($post_details[$i]['image']==''?'default.jpg':$post_details[$i]['image']); ?>"  class="img-thumbnail" />
            </a>-->
         </div>
         <div>
           <? //echo '<pre>'; print_r($post_details); echo '</pre>';
               $post_client_details = $ticket_object->client_details('email="'.$post_details[$i]['submitter_email'].'" and domain_id = "'.$ticket_details['domain_id'].'"'); 
                $link = ($post_client_details != -1 && $post_client_details['client_id']== $ticket_details['client_id'])?' href="#/client/client_details/'. $ticket_details['first_name'].' '.$ticket_details['last_name'] .'/'. $ticket_details['client_id'].'" onmouseover="javascript:show_user_details(1,'. $ticket_details['client_id'].','.$post_details[$i]['post_id'].');" onmouseout="hide_user_details(this);"':'';
																
																$checkclass=($post_details[$i]['submitter']==1)?(($post_client_details!=-1  && $post_client_details['client_id'] == $ticket_details['client_id'])?'class="label bg-light dker"':''):'class="label bg-primary"';
																echo '<label '.$checkclass.'>';
                echo ($post_details[$i]['submitter']==1)?(($post_client_details!=-1  && $post_client_details['client_id'] == $ticket_details['client_id'])?$vis_language['TXTCLIENT']:$vis_language['TXTFROM']):$vis_language['TXTSTAFF'];
																echo '</label>';
																 ?>
            <? 	if($post_details[$i]['submitter']==1 && $post_client_details!=-1){  // client ?>
            <a  id="user_<?= $post_details[$i]['post_id'].'_1_'.$ticket_details['client_id'];?>" class="link m-l-xs"   <?php echo $link;  ?> ><? $from = ($post_details[$i]['submitter_name']!=''  && $post_client_details['client_id']== $ticket_details['client_id'])?$post_details[$i]['full_name'] : $post_details[$i]['submitter_email'] ; 
			echo ($from=='')?$ticket_details['first_name'] .'<'.$ticket_details['user_name'].'>':$from;
			?></a> 
            <? }else if($post_client_details==-1 && $post_details[$i]['submitter']==1){
               echo '<span class="link m-l-xs">'.$post_details[$i]['submitter_email'].'</span>';
               }
               else{ // staff ?>
            <a class="link m-l-xs" href="#/home/profile_view/<? echo $vis_language['TXTPROFILE'];?><?= ($post_details[$i]['submitter_id'] != VIS_STAFF_ID) ? '/'.$post_details[$i]['submitter_id'] : '';?>"  onmouseover="javascript:show_user_details(0,<?= $post_details[$i]['submitter_id'].','.$post_details[$i]['post_id']?>);" id="user_<?= $post_details[$i]['post_id'].'_0_'.$post_details[$i]['submitter_id'];?>" onmouseout="hide_user_details(this);"><?= $post_details[$i]['full_name']; ?></a>
            <? } ?>
         </div>
         <div class="m-r-sm m-b-xs">
            <? if($post_details[$i]['as_client']==1){
               echo '<span class="">'.$vis_language['TXTTICKETCREATEDBY'].' <a class="link m-l-xs" href="#/home/profile_view/<? echo $vis_language[\'TXTPROFILE\'];?>/'.$post_details[$i]['submitter_id'].'" onmouseover="javascript:show_user_details(0,'.$post_details[$i]['submitter_id'].','.$post_details[$i]['post_id'].');" id="user_'.$post_details[$i]['post_id'].'_0_'.$post_details[$i]['submitter_id'].'" onmouseout="hide_user_details(this);">'.$post_details[$i]['staff_name'].'</a></span>';
            }
            else if(isset($post_details[$i]['receiver_to']) && $post_details[$i]['receiver_to']!=""){?>				
            <label><?= ($post_details[$i]['reply_forward']==0) ? $vis_language['TXTTO'] : (($post_details[$i]['reply_forward']==1) ? $vis_language['TXTREPLIEDTO'] : $vis_language['TXTFORWARDEDTO']);?></label>
            <span class="text-muted m-l-xs"><?= str_replace(',', ', ', $post_details[$i]['receiver_to']).'';?></span>
            <? 	if($post_details[$i]['submitter'] && $post_details[$i]['submitter_id']==$ticket_details['client_id'] && $post_details[$i]['received_via']==1)
               echo '<span class="text-muted m-l-xs">'.$vis_language['TXTVIACLIENTPORTAL'].'</span>';
               } else echo "&nbsp;"; ?>
         </div>
         <div class="clear">
            <?	if(isset($post_details[$i]['receiver_cc']) && $post_details[$i]['receiver_cc']!=""){ ?>
            <div class="m-r-sm">
               <label><?= $vis_language['TXTCC']?></label>
               <span class="link m-l-sm"><?= str_replace(',', ', ', $post_details[$i]['receiver_cc']);?></span>
            </div>
            <? } ?>
         </div>
         <div class="clear">
            <?	if(isset($post_details[$i]['receiver_bcc']) && $post_details[$i]['receiver_bcc']!=""){ ?>
            <div class="m-r-sm">
               <label><?= $vis_language['TXTBCC']?></label>
               <span class="link m-l-sm"><?= str_replace(',', ', ', $post_details[$i]['receiver_bcc']);?></span>
            </div>
            <? } ?>
         </div>
      </div>
      <div class="panel-body wrapper">
         <? 
            preg_match('/(<img[^>]+>)/i', $post_details[$i]['content'], $matches);
                if(!empty($matches))
			    {
					   $isInlineImage  = 1;
				}
            	if(!$show_inline_img && !empty($matches)){ ?>
         <div class="text-right p-r-none"><a href="javascript:void(0);" class="link m-l-sm" id="load_inline_image_<? echo $post_details[$i]['post_id']; ?>" onclick="load_inline_images('<? echo $post_details[$i]['post_id']; ?>');"><span class="vis_load_inline_img"><? echo $vis_language['TXTSHOWINLINEIMG']; ?></span></a> </div>
         <? } ?>
         <div id="vis_ticket_post_content_div_<? echo $post_details[$i]['post_id']; ?>" class="vis_inlineimagepopup vh-ticket-post">
            <div class="vis_max_img_size" id="vis_ticket_post_content_text_<? echo $post_details[$i]['post_id']; ?>"><? if(!$show_inline_img) { echo preg_replace("/<img[^>]+\>/i", "", $post_details[$i]['content']);} else echo ($post_details[$i]['content']); ?></div>
            <div id="vis_ticket_post_content_edit_<? echo $post_details[$i]['post_id']; ?>"></div>
         </div>
         <? if($post_details[$i]['attachment']!=-1) { 
            $images=''; $files='';
            for($j=0;$j<count($post_details[$i]['attachment']);$j++) { 
            	if (!preg_match('/image/',$post_details[$i]['attachment'][$j]['file_type'])) { 
            	  $files.='<div class="btn-group wrapper-xxs p-l-none"><a class="btn btn-xs alert-success no-border" href="'.$post_details[$i]['attachment'][$j]['domain_url'];
            	   if(VIS_DOMAIN==$post_details[$i]['attachment'][$j]['file_location']) $files.= 'manage/';
            		$files.='?vis_module=export&vis_operation=get_attachment&vis_attachment='.$post_details[$i]['attachment'][$j]['attachment_id'].'&'.VIS_STAFF_COOKIE.'='.$_COOKIE[VIS_STAFF_COOKIE].'"><span class="vis-icon-med vis-icon-article"></span>&nbsp;'.$post_details[$i]['attachment'][$j]['file_name'].'</a></div>';
               }
               else {
				
				  
            	   $imagedetails=explode("/",$post_details[$i]['attachment'][$j]['content']);
            	   $imagename=file_exists(VIS_PATH_FILES.'thumb_'.end($imagedetails))?'thumb_'.end($imagedetails):end($imagedetails);
            	   $images.='<li><a href="'.$post_details[$i]['attachment'][$j]['domain_url'];
            	   if(VIS_DOMAIN==$post_details[$i]['attachment'][$j]['file_location']) $images.= 'manage/';
            		$images.='?vis_module=export&vis_operation=get_attachment&vis_attachment='.$post_details[$i]['attachment'][$j]['attachment_id'].'&'.VIS_STAFF_COOKIE.'='.$_COOKIE[VIS_STAFF_COOKIE].'"><img width="100" height="100" src="'./*$post_details[$i]['attachment'][$j]['domain_url'].*/VIS_PATH_FILES.$imagename.'" alt="'.$post_details[$i]['attachment'][$j]['file_name'].'" title="'.$post_details[$i]['attachment'][$j]['file_name'].'"/></a></li>';
               }
              }
              if($images!='') { ?>
         <?php echo '<div class="b b-t m-sm b-dashed m-l-none m-r-none"></div><div class="clear"><ul class="vis_inline_images nav navbar-nav hidden-xs">'.$images.'</ul></div>';
            }
            if($files!='') {  ?>
         <div class="b b-t m-sm b-dashed m-l-none m-r-none"></div>
         <?php echo $files; 
            }
            }?>
         <?  if($validation_error[$i]!=-1 && $validation_error[$i]!='') foreach($validation_error[$i] as $key=>$error){
            echo '<div class="b b-t m-sm b-dashed m-l-none m-r-none"></div><div class="clear"><ul class="vis_inline_images nav navbar-nav hidden-xs vh-danger">'. $error['content'] .'</ul></div>';
            }
              ?>
      </div>
   </section>
</section>
<? } 	
   if($post_paging_count>1){ ?>
<div class="text-right">
   <ul class="pagination m-t-xs pagination_ticket_post" id=""></ul>
</div>
<? } if($isInlineImage == 1){?>
<script type="text/javascript" src="<?php echo VIS_PATH_SCRIPT;?>fancyBox/source/jquery.fancybox.js?v=2.1.5"></script>
<link rel="stylesheet" type="text/css" href="<?php echo VIS_PATH_SCRIPT;?>fancyBox/source/jquery.fancybox.css?v=2.1.5" media="screen" />
<script type="text/javascript">
$(document).ready(function() {
	$('.vis_inlineimagepopup').on('mouseover','img',function(){
		$('.vis_inlineimagepopup img').addClass('vis-pointer');
	})

    $('.vis_inlineimagepopup').on('click','img',function(){
        currentImgWidth = this.naturalWidth;
		$.fancybox.open({ 
						href : $(this).attr('src'),
						type : 'iframe',
						padding : 5,
						width:currentImgWidth ,
					});
			
		});
});
</script>
<? }?>

	
<script type="text/javascript">
	
	
   function load_inline_images(postid){
   	var display='';	
   	if($('#load_inline_image_'+postid+' .vis_load_inline_img').text()==='<? echo $vis_language['TXTSHOWINLINEIMG']; ?>') {
   		display=1;
   		$('#load_inline_image_'+postid+' .vis_load_inline_img').text('<? echo $vis_language['TXTHIDEINLINEIMG']; ?>');
   	}
   	else {
   		display=0;
   		$('#load_inline_image_'+postid+' .vis_load_inline_img').text('<? echo $vis_language['TXTSHOWINLINEIMG']; ?>');
   	}
   	$.post( 'index.php', { 'vis_module': 'ticket', 'vis_operation': 'load_inline_images', 'vis_post_id': postid , 'vis_display':display}, function( data ) {
   		$("#vis_ticket_post_content_text_"+postid).html(data.vis_post_content_html);
   	}, "json");
   }
   $('.pagination_ticket_post').twbsPagination({
   	totalPages:<?php echo $post_paging_count; ?>,
   	visiblePages:5,startPage: <?= $page;?>,
   	onPageClick: function (event, page) { 
   		$('#ticket_details_view #vis_ticket_post_forms').visExecution('load_operations', {'vis_module':'ticket', 'vis_operation':'get_ticket_post', 'vis_ticket_id':<?= $ticket_details['ticket_id'];?>, 'vis_action':'load_more_post', 'vis_page':page});
   	}
   });
</script>
<?php } else include(VIS_PATH_TEMPLATE.'no_record_yet.php'); ?>

