<?php
require_once("includes/initialize.php");
$access = $_SESSION['access_level'];

$msg = ONLINEPAY::allmsg($access);
$path = "../../transcript/msguploads/";
if (isset($msg)){
    $mode='Transcript';
    
    $table1="transcript_content";
    $table2="transcript_messages";
}

$output=''; $count=1;




if (isset($_POST['submit'])){
    
    
    if (isset($_POST['res']) && !empty($_POST['res'])){
        
       $response = trim($_POST['res']);
        
       $ticket = trim($_POST['ticket']);
       
       if (isset($response) && ($response !='')){
           
           ONLINEPAY::MsgUpdate($table2, $ticket,'Answered');
           
            ONLINEPAY::ContentUpdate($table1, $ticket,$response);
           
           
       }
        
        
    }
    
}else if (isset($_POST['cancel'])){
    
    
}
//echo $path;

$msg = ONLINEPAY::allmsg($access);
$path = "../../transcript/msguploads/";
if (isset($msg)){
    $mode='Transcript';
    
    $table1="transcript_content";
    $table2="transcript_messages";
}




if (sizeof($msg)>0){
$output = '<form method="post" action="" style="margin-left:40px">';
foreach ($msg as $ms){
    
    if (isset($ms->ticket_title)){
        
        $output .=  '<div class="row">';
        $output .=  '<div class="col-md-12">';
        $output .=  '<h2><strong>Enquiry '.$count++.' : </strong>'.$ms->ticket_title.'</h2></div></div>';
        if (!empty($ms->attachment)){
        $output .= '<div class="row">
        <div class="col-md-12"><img src='.
         $path.$ms->attachment.'>
        
        </div></div>';
        
        }
        $output .=  '<div class="row"><div class="col-md-9">';
        
        $output .=  '<h4>'.$ms->message.'</h4></div>';
        
        $output .= '<div class="col-md-3">';
        
        $output .=  '<h4 style="float:right; color:blue; margin-right:20px">'.$mode.'</h4></div></div>';
        
        
        $output .=  '<input type="hidden" name="ticket" value="'.$ms->ticket.'">';
         
    //       <textarea cols="50%" rows="5" placeholder="Reply" name="message" class="form-control custom-control">
        
    //   </textarea>
      
        $output .=  '<div class="row"><div class="col-md-12">';
        
        
        $output .= '<textarea cols="80%" rows="10" name="res" class="form-control custom-control" placeholder="Enter response to this ticket number" value="">
       
                    </textarea>
        
                    </div></div><br>';
        
        $output .=  '<div class="row" style="width: 80%;"><div class="col-md-4">';
        $output .= '<input type="submit" name="submit" class="btn btn-success" value="Response"></div>
        
        <div class="col-md-4">';
        $output .= '<input type="submit" name="cancel" class="btn btn-danger" style="margin-left:0px" value="Close"></div>
        
        </div>';
        
    }
}

$output.='</form>';

}else{
    $output='<h3>No pending request.</h3>';
}


echo $output;
?>