<div id="page-wrapper">
    <div class="container-fluid">
        <div class="row">
	        <div class="col-lg-12">
		        <h1 class="page-header">Administration du support</h1>
	        </div>
            <div class="col-lg-8">
	        	<div class="padding-20 margin-bottom-30 clearfix">
					<h3 class="h3 text-center">
						<strong>Support</strong> - #<?= $ticket->id; ?> <?= $ticket->title; ?> [<?php if(!$ticket->closed) { 
				            	switch($ticket->state){
						            case 0: echo "En attente"; break;
						            case 1: echo "<span class='text-success'>Résolu</span>"; break;
						            case 2: echo "<span class='text-warning'>Prise en charge</span>"; break;
					            } 
				            } else {
					            echo "<span class='text-danger'>Fermé</span>";
				            }
				        ?>]
						<?php if(!($ticket->state==1) && !$ticket->closed): ?>
						<form method="POST" autocomplete="off" style="display:inline-block">
							<input type="submit" name="resolved" class="btn btn-success btn-sm" value="Résolu">
						</form>
						<?php endif; ?>
						<?php if(!($ticket->state == 2) && !($ticket->state == 1)): ?>
						<form style="display:inline-block" method="POST" autocomplete="off">
							<input type="submit" class="btn btn-warning btn-sm" name="mark" value="Marquer">
						</form>
						<?php endif; ?>
						<?php if(!$ticket->closed && !($ticket->state==1)): ?>
						<form style="display:inline-block" method="POST" autocomplete="off">
							<input type="submit" class="btn btn-danger btn-sm" name="close" value="Fermer">
						</form>
						<?php endif; ?>
					</h3>
					<?php foreach($answers as $answer): ?>
					<?php $answer->author = $this->users->getUserById($answer->author); ?>
					<div class="media">
						<a class="media-left" href="#">
							<img src="<?= $this->users->getAvatarLink($answer->author['id']); ?>" width="64" height="64">
						</a>		
						<div class="media-body">
							<div class="media-content">
								<a href="#" class="media-heading"><?= $answer->author['username']; ?></a>
								<span class="date"><?= getPhraseFromTime($answer->created); ?></span>
								<?php if($answer->is_staff): ?><span class="label label-warning">Staff</span><?php endif; ?>
								<p><?= $answer->content; ?></p>
							</div>
						</div>
					</div>
					<hr width="70%">
					<?php endforeach; ?>
				</div>
            </div>
            <div class="col-lg-4">
	            <div class="col-md-6 col-lg-12 col-sm-12 col-xs-12 margin-bottom-10">
		            <div class="panel panel-default">
	                    <div class="panel-heading">
	                        Liste des réponses préenregistrées
	                    </div>
	                    <!-- /.panel-heading -->
	                    <div class="panel-body">
							<div class="dataTable_wrapper" id="support_saved_answers">
								<?php foreach($saved_answers as $answer): ?>
								<button class="btn btn-info" onclick="fastAnswer($(this).data('answer'))" data-answer="<?= addslashes($answer->content); ?>"><?= $answer->title; ?></button>
								<?php endforeach; ?>
	                        </div>
	                        <!-- /.table-responsive -->
	                    </div>
	    			</div>
	            </div>
				<div class="col-md-6 col-lg-12 col-sm-12 col-xs-12 margin-bottom-10">
					<h4 class="h4 text-center"><strong>Répondre</strong></h4>
					<?= (isset($errors)?$errors:''); ?>
					<?= (isset($success)?$success:''); ?>
					<form method="POST" class="no-padding-xs margin-bottom-10" autocomplete="off">
						<label for="answer_content">Votre réponse</label>
						<textarea class="form-control margin-bottom-10" name="answer_content" id="answer_content" placeholder="Votre réponse"></textarea>
						<input class="btn btn-info pull-right" name="answer_submit" id="answer_submit" value="Répondre" type="submit" style="margin-top: 10px;">
					</form>
				</div>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
    </div>
    <!-- /.container-fluid -->
</div>
<script type="text/javascript">web_page = "support_view";</script>