$string = substr($stringCut, 0, strrpos($stringCut, ' ')) . ' ...';
}
$TicketData = App\Model\helpdesk\Ticket\Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
$TicketDatarow = App\Model\helpdesk\Ticket\Ticket_Thread::where('id', '=', $TicketData)->first();
$LastResponse = App\User::where('id', '=', $TicketDatarow->user_id)->first();
if ($LastResponse->role == "user") {
    $rep = "#F39C12";
    $username = $LastResponse->user_name;
} else {
    $rep = "#000";
    $username = $LastResponse->first_name . " " . $LastResponse->last_name;
    if ($LastResponse->first_name == null || $LastResponse->last_name == null) {
        $username = $LastResponse->user_name;
    }
}
$titles = App\Model\helpdesk\Ticket\Ticket_Thread::where('ticket_id', '=', $ticket->id)->get();
$count = count($titles);
foreach ($titles as $title) {
    $title = $title;
}
$assigned_to = App\User::where('id', '=', $ticket->assigned_to)->first();
if ($assigned_to == null) {
    $assigned = "Unassigned";
} else {
    $assigned = $assigned_to->first_name . " " . $assigned_to->last_name;
}
?>
                        <td class="mailbox-name"><a href="{!! route('ticket.thread',[$ticket->id]) !!}" title="{!! $title->title !!}">{{$string}}   </a> ({!! $count!!}) <i class="fa fa-comment"></i>
                        @if($collab > 0)&nbsp;<i class="fa fa-users"></i>@endif 
                        @if($attach > 0)&nbsp;<i class="fa fa-paperclip"></i>@endif</td>
                        <td class="mailbox-Id"><a href="{!! route('ticket.thread',[$ticket->id]) !!}" title="{!! $title->title !!}">#{!! $ticket->ticket_number !!}</a></td>
$help_topic = App\Model\helpdesk\Manage\Help_topic::where('id', '=', $tickets->help_topic_id)->first();
$dept = App\Model\helpdesk\Agent\Department::where('id', '=', $help_topic->department)->first();
?>
        <table class="table">    
            <tr><th></th><th></th></tr>
            <tr><td><b>Status:</b></td>       	<td>{{$status->state}}</td></tr>
            <tr><td><b>Priority:</b></td>     	<td>{{$priority->priority}}</td></tr>
            <tr><td><b>Department:</b></td>   	<td>{{$dept->name}}</td></tr> 
            <tr><td><b>Email:</b></td>        	<td>{{$user->email}}</td></tr>
            <tr><td><b>Phone:</b></td>        	<td>{{$user->mobile}}</td></tr>
            <tr><td><b>Source:</b></td>         <td>{{$ticket_source}}</td></tr>
            <tr><td><b>Help Topic:</b></td>     <td>{{$help_topic->topic}}</td></tr>
        </table>

        <?php 
$conversations = App\Model\helpdesk\Ticket\Ticket_Thread::where('ticket_id', '=', $tickets->id)->get();
?>
        @foreach($conversations as $conversation)
        <br/><hr>
        <span class="time-label">
                                <?php 
$role = App\User::where('id', '=', $conversation->user_id)->first();
?>
                                <?php 
if ($conversation->is_internal) {
    ?>
                                <i class="fa fa-tag bg-purple" title="Posted by System"></i>
                                    <?php 
} else {
    if ($role->role == 'agent' || $role->role == 'admin') {
        ?>
                                <div class="col-md-2">
                                    <label>Reply Content</label>
                                </div>
                                <div class="col-md-10">
                                    <textarea id="txtEditor2"> </textarea>
                                </div>
                            </div>
                        </div>
                    </form>
                </div> -->
            </div>
        </div>
        <!-- ticket  conversations -->
<?php 
$conversations = App\Model\helpdesk\Ticket\Ticket_Thread::where('ticket_id', '=', $tickets->id)->orderBy('id', 'DESC')->paginate(10);
$ij = App\Model\helpdesk\Ticket\Ticket_Thread::where('ticket_id', '=', $tickets->id)->first();
?>

        <!-- row -->
        <div class="row" >

            <div id="refresh1">
            <style type="text/css">
            .pagination{
                margin-bottom: -20px;
                margin-top: 0px;
            }
            </style>
                <ul class="pull-right" style="padding-right:40px" >
                    <?php 
echo $conversations->setPath(url('/thread/' . $tickets->id))->render();
                                        <table class="table table-hover">
                                            <!-- <tr><th></th><th></th></tr> -->
                                            <tr><td><b>{!! Lang::get('lang.help_topic') !!}:</b></td>     <?php 
$help_topic = App\Model\helpdesk\Manage\Help_topic::where('id', '=', $tickets->help_topic_id)->first();
?>
<td title="{{$help_topic->topic}}">{{$help_topic->topic}}</td></tr>
                                            <tr><td><b>{!! Lang::get('lang.last_message') !!}:</b></td>   <td>{{ucwords($last->poster)}}</td></tr>
                                        </table>
                                    </div>
                                    <!-- </div> -->
                                </section> 
                            </div>
                        </div>
                    </div>
<?php 
$conversations = App\Model\helpdesk\Ticket\Ticket_Thread::where('ticket_id', '=', $tickets->id)->where('is_internal', '=', 0)->paginate(10);
foreach ($conversations as $conversation) {
    $ConvDate1 = $conversation->created_at;
    $ConvDate = explode(' ', $ConvDate1);
    $date = $ConvDate[0];
    $time = $ConvDate[1];
    $time = substr($time, 0, -3);
    if (isset($data) && $date == $data) {
    } else {
        $data = $ConvDate[0];
    }
    $role = App\User::where('id', '=', $conversation->user_id)->first();
    $attachment = App\Model\helpdesk\Ticket\Ticket_attachments::where('thread_id', '=', $conversation->id)->first();
    if ($attachment == null) {
        $body = $conversation->body;
    } else {