<?
    global $vis_language;
    $ticket_details=$data[0]; $post_details=$data[1]; 
    $post_count=$data[2];     $note_details=$data[3]; 
    $domain_details=$data[4]; $comment_details=$data[5];
    $user_details=$data[6];   $customfields=$data[7];
    $due_flag =($ticket_details['pause_dtime']!='')? $ticket_details['pause_dtime']:'';
    $resolution_flag = ($ticket_details['pause_rtime']!='') ? $ticket_details['pause_rtime']:'';
?>
<div>
    <table cellpadding="0" cellspacing="0" width="100%">
        <tr><td width="83%"><h2 style="color:#b60e0d;font-weight:bold;"><?php echo($ticket_details['ticket_hash']); ?></h2></td>
            <td align="right" width="17%">
                <table width="80px" style="float:right;"><tr>
                <? for($cn=0;$cn<$ticket_details['rating'];$cn++){?>
                        <td><img src="<?php echo VIS_PATH_IMAGES; ?>starfil.gif" width="15px"/></td><? }
                for($cn=$ticket_details['rating'];$cn<5;$cn++){?>
                        <td><img src="<?php echo VIS_PATH_IMAGES; ?>staremt.gif" width="15px"/></td><?
                } ?>
                </tr></table>
            </td>
        </tr>
        <tr><td colspan="2"><div style="color:#666;"><strong><?= $vis_language['TXTCLIENT']; ?></strong>: <? echo $ticket_details['first_name'].' '.$ticket_details['last_name']; ?> &lt;<? echo $ticket_details['email']; ?>&gt; &nbsp;<? if($user_details['parent_email']!=''){ ?> <strong><?= $vis_language['TXTPARENT']; ?></strong>: <?= $user_details['parent_name'].' '.$user_details['parent_email']; ?><? } ?></div></td></tr>
      <tr><td><div class="vis_main_window_title">
        <div style="color:#666;font-size:35px;"><strong><? echo $vis_language['TXTSUBJECT']; ?>: <? echo $ticket_details['subject']; ?></strong></div>
    </div></td><td align="right"></td></tr>
    </table><br/>
    
    <table cellpadding="5" cellspacing="3" width="100%" cellspacing="0" style="border:1px solid #ddd;;color:#788288;">
        <tr><td style="background-color:#d9edf7;" colspan="2"><strong><?= $vis_language['TXTTICKETDETAILS']; ?></strong></td></tr>
        <tr><td><div style="color:#666;"><strong><? echo $vis_language['TXTSTATUS']; ?></strong>: <? echo $ticket_details['ticket_status']; ?></div></td><td><div style="color:#666;"><strong><? echo $vis_language['TXTPRIORITY']; ?></strong>: <? echo $ticket_details['ticket_priority']; ?></div></td></tr>
        <tr><td><div style="color:#666;"><strong><? echo $vis_language['TXTOWNER']; ?></strong>: <?  if($ticket_details['owner']=='') echo $vis_language['TXTUNASSIGNED']; else echo $ticket_details['owner'];?></div></td><td><div style="color:#666;"><strong><? echo $vis_language['TXTDEPARTMENT']; ?></strong>: <? echo $ticket_details['department_name']; ?></div></td></tr>
        <tr><td><div style="color:#666;"><strong><? echo $vis_language['TXTTYPE']; ?></strong>: <? echo $ticket_details['ticket_type']; ?></div></td><td><div style="color:#666;"><strong><? echo $vis_language['TXTFLAG']; ?></strong>: <? echo $ticket_details['ticket_flag_name']; ?></div></td></tr>
        <tr><td><div style="color:#666;"><strong><? echo $vis_language['TXTSLAPLAN']; ?></strong>: <? echo ($ticket_details['slaplan_id']==0) ? $vis_language['TXTCUSTDUETIME'] : $ticket_details['sla_name'];?></div></td>
            <td><div style="color:#666;"><strong><? echo $vis_language['TXTDUETIME']; ?></strong>: <? if($due_flag!='')echo (is_numeric($due_flag))?count_remain_time($due_flag) : $due_flag;elseif($ticket_details['due_time']<=0 && $ticket_details['user_replied']==1 && $ticket_details['status_id']!=3 && $ticket_details['sdue_time']!=0) echo $vis_language['TXTOVERDUE']; elseif($ticket_details['due_time']>0 && $ticket_details['user_replied']==1 && $ticket_details['status_id']!=3) echo count_remain_time($ticket_details['due_time']); else echo $vis_language['TXTUNDUE']; ?></div></td>
        </tr>
        <tr>
           <td><div style="color:#666;"><strong><? echo $vis_language['TXTRESOLUTIONTIME']; ?></strong>:  <? if($resolution_flag!='')echo (is_numeric($resolution_flag))? count_remain_time($resolution_flag) : $resolution_flag;elseif($ticket_details['resolution_time']<=0 && $ticket_details['status_id']!=3 && $ticket_details['rdue_time']!=0) echo $vis_language['TXTOVERDUE']; elseif($ticket_details['resolution_time']>0 && $ticket_details['status_id']!=3) echo count_remain_time($ticket_details['resolution_time']); else echo $vis_language['TXTUNDUE']; ?></div></td>
           <td><div style="color:#666;"><strong><? echo $vis_language['TXTCHANNEL']; ?></strong>: <? echo $ticket_details['channel_name']; ?></div></td>
             </tr>
    </table>
     <?php if($customfields!='') echo  '<br/>'.$customfields ; ?>
    <?    if($note_details!=-1) for($i=0;$i<count($note_details);$i++) {
        echo '<br/><table cellpadding="5" cellspacing="3" width="100%" cellspacing="0" style="border:1px solid #ddd;;color:#788288;"><tr><td style="background-color:#fcf8e3;"><strong>'.$vis_language['TXTNOTEPOSTEDBY'].'</strong>: '.$note_details[$i]['staff_name'].'</td><td style="background-color:#fcf8e3;"><strong>'.$vis_language['TXTPOSTON'].'</strong>: '.format_datetime($note_details[$i]['remark_date']).'</td></tr>';
        echo '<tr><td colspan="2">'.$note_details[$i]['content'].'</td></tr>';
        if($note_details[$i]['attachment'] != -1){ 
            echo '<tr><td colspan="2">';
                for($j=0; $j<count($note_details[$i]['attachment']); $j++){
                    echo '<div class="btn-group wrapper-xxs p-l-none"><a href="'.$domain_details['domain_url'].'?vis_module=export&vis_operation=get_attachment&vis_attachment='.$note_details[$i]['attachment'][$j]['attachment_id'].'&'.VIS_STAFF_COOKIE.'='.$_COOKIE[VIS_STAFF_COOKIE].'" class="btn btn-xs alert-success no-border">'.$note_details[$i]['attachment'][$j]['file_name'].'</a></div>';
                }
            echo '</td></tr>';
        }
        echo '</table>';
}

        for($i=0;$i<$post_count;$i++) { 
           if($comment_details[$i]!=-1) foreach($comment_details[$i] as $comment){ 
                echo '<br/><table cellpadding="5" cellspacing="3" width="100%" cellspacing="0" style="border:1px solid #ddd;;color:#788288;"><tr><td style="background-color:#f2dede;"><strong>'.$vis_language['TXTCOMMENTPOSTEDBY'].'</strong>: '.$comment['staff_name'].'</td><td style="background-color:#f2dede;"><strong>'.$vis_language['TXTPOSTON'].'</strong>: '.format_datetime($comment['remark_date']).'</td></tr>';
                echo '<tr><td colspan="2">'.nl2br(htmlentities($comment['content'], ENT_NOQUOTES, 'UTF-8')).'</td></tr>';
                echo '</table>';
            }?>
    <br/>
    
            <table cellpadding="5" cellspacing="3" width="100%" cellspacing="0" style="border:1px solid #ddd;;color:#788288;">
                <tr>
                    <td style="background-color:#d9edf7;" width="10%">
                        <? $profile_img=($post_details[$i]['image']==''?'default.jpg':$post_details[$i]['image']);
                            $profile_img=file_exists(VIS_PATH_PROFILE.$profile_img)?$profile_img:'default.jpg'; ?>
                        <img src="<? echo VIS_PATH_PROFILE; echo $profile_img; ?>" style="width:30px; height:30px; border-radius:50%;" />
                    </td>
                    <td style="background-color:#d9edf7;" width="41%"><strong><? echo ($post_details[$i]['submitter']==0)?$vis_language['TXTSTAFF']:$vis_language['TXTCLIENT']; ?></strong>: <? echo ($post_details[$i]['submitter']==1)? $ticket_details['first_name'].' '.$ticket_details['last_name']:$post_details[$i]['submitter_name']; ?><br /><strong><?= ($post_details[$i]['reply_forward']==0) ? $vis_language['TXTTO'] : (($post_details[$i]['reply_forward']==1) ? $vis_language['TXTREPLIEDTO'] : $vis_language['TXTFORWARDEDTO']);?></strong>: <? echo $post_details[$i]['receiver_to']; ?></td>
                    <td style="background-color:#d9edf7;" width="49%"><strong><? echo $vis_language['TXTPOSTON']; ?></strong>: <? echo format_datetime($post_details[$i]['receive_date']); ?></td>
                </tr>
                <tr>
                    <td colspan="3">
                        <div class="vis_main_window_content vis_round_corner" style="margin-left: 5px;">
                         <? echo $post_details[$i]['content']; ?>
                        </div>
                    </td>
                </tr>
                <? if($post_details[$i]['attachment']!=-1) { ?>
                <tr>
                    <td colspan="3">
                        <? $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 bg-primary" 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);
                               if(file_exists(VIS_PATH_FILES.$imagename)){
                                    $images.='<li style="float:left;display:inline;"><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="50px" src="'.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 '<ul class="vis_inline_images" style="float:left;">'.$images.'</ul>';
                        }
                        if($files!='') {  ?>
                    <?php echo $files; 
                        }?>
            
                    </td>
                </tr><? }?>
            </table>
    
    
            <? if($i<$post_count-1) echo '<br />';
        }?>
    </div>
</div>
