<?php 

	/**
	 * Bu dosya Moon Panel'in bir parçasıdır.
	 *
	 * Moon Panel
	 *
	 * Author: R10 <@bmathers>
	 *
	 */

	require admin_view('static/header');

?>

<div class="container-fluid">

	<div class="row">

		<div class="col-lg-12">

			<?php if($settings['ticket_system'] == 1): ?>

			<div id="main-container" class="container-fluid">

				<div id="chat-panel" class="panel panel-default">

					<div class="panel-heading">

						<h3 class="panel-title">Destek Sistemi <small><b>BETA</b></small></h3>

					</div>

					<section class="row">

						<div id="chat-list" class="col-md-3 col-lg-2"></div>

						<div id="chat-body" class="col-md-9 col-lg-10">

							<div style="height:662px;text-align: center">

								<h4>Destek Sistemi</h4>

								<p>Destek Taleplerini okumak için soldaki listeden görüntülemek istediğiniz mesajı seçiniz. Mesaj Listesi 15 saniyede bir yenilenmektedir, yeni mesajlar için sayfayı yenilemenize gerek yok ^^</p>

							</div>

						</div>

					</section> <!-- /body section -->   

				</div>

			</div>

			<?php else: ?>

			<?php if(route(2)): ?>



				<?php if(route(2) == "unread"): ?>

					<a href="javascript:;" data-toggle="modal" data-toggle="modal" data-target="#modalDefault" data-action="get_newsupport" class="btn btn-default">Yeni Talep Oluştur</a>
					<a href="<?=admin_url('support/unread')?>" class="btn btn-default">Okunmayan Talepler</a>

				<div class="pull-right">

				    <form class="form-inline" action="" method="get">

				        <div class="input-group">

				        	<input type="text" name="search" class="form-control" value="" placeholder="Destek Talebi ara...">

				        	<span class="input-group-btn">

				        		<select class="form-control" style="border-radius:0;" name="search_type">

				        			<option value="id">Ticket ID</option>

				        			<option value="link">Başlık</option>

				        			<option value="username">Kullanıcı Adı</option>

				        		</select>

				        		<button type="submit" class="btn btn-default"><span class="fa fa-search" aria-hidden="true"></span></button>

				            </span>

				        </div>

				    </form>

				</div>

				<div class="panel panel-default" style="margin-top:20px;">

					<table class="table order-table table-grey" style="margin-bottom:0;">

						<thead>

							<tr>

								<th>Ticket ID</th>

								<th>Kullanıcı adı</th>

								<th style="width:20%;">Başlık</th>

								<th>Durum</th>

								<th>Tarih</th>

								<th></th>

							</tr>

						</thead>

						<tbody>

							<?php foreach($tickets as $row): ?>

							<tr>

								<td><?=$row['ticket_id']?></td>

								<td><?=$row['user_username']?></td>

								<td><a <?php if($row['ticket_read'] == 0): ?>style="color:orange;"<?php endif; ?> href="<?=admin_url('support/'.$row['ticket_id'])?>"><?php if($row['ticket_read'] == 0): ?><b><?=$row['ticket_title']?></b><?php else: ?><?=$row['ticket_title']?><?php endif; ?></a></td>

								<td>

									<?php if($row['ticket_status'] == 0): ?>

										<span class="label label-danger"><i class="fas fa-lock-open"></i> Kapalı</span>

									<?php elseif($row['ticket_status'] == 1): ?>

										<span class="label label-success">Açık</span>

									<?php elseif($row['ticket_status'] == 2): ?>

										<span class="label label-default"><i class="fas fa-lock"></i> Kilitli</span>

									<?php endif; ?>

								</td>

								<td><?=str_date($row['ticket_date'])?></td>

								<td>

									<div class="dropdown pull-right">

										<button class="btn btn-xs btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">İşlemler<span class="caret"></span></button>

										<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">

											<?php if($row['ticket_status'] == 0): ?>

												<li><a href="#" onclick="update_ticket(<?=$row['ticket_id']?>, 2)">Talebi Kilitle</a></li>

												<li><a href="#" onclick="update_ticket(<?=$row['ticket_id']?>, 1)">Talebi Aç</a></li>

											<?php elseif($row['ticket_status'] == 1): ?>

												<li><a href="#" onclick="update_ticket(<?=$row['ticket_id']?>, 2)">Talebi Kilitle</a></li>

												<li><a href="#" onclick="update_ticket(<?=$row['ticket_id']?>, 1)">Talebi Kapat</a></li>

											<?php elseif($row['ticket_status'] == 2): ?>

											<?php endif; ?>

											

										</ul>

									</div>

								</td>

							</tr>

							<?php endforeach; ?>

						</tbody>

					</table>

				</div>

				<ul class="pagination">

					<?= $db->showPagination(admin_url(route(1) . '?' . $pageParam . '=[page]')); ?>

				</ul>

				<?php else: ?>

					<div class="col-md-6 col-md-offset-3">

        				<div class="ticket-header__title border-radius-top">

        					<div class="row">

            					<div class="col-md-12">

                					<div class="ticket-header-title">

                						<?=$ticket['ticket_title']?>

                						<?php if($ticket['ticket_status'] == 2): ?>

                							<small><span class='label label-default'>Bu destek talebi kilitlenmiş, artık cevaplanamaz.</span></small>

                						<?php elseif($ticket['ticket_status'] == 0): ?>

                							<small><span class='label label-default'>Bu destek talebi kapatılmış, tekrardan cevaplamak için talebi açınız.</span></small>

                						<?php endif; ?>

                                   		<div class="ticket-header-id">ID: <?=$ticket['ticket_id']?></div>

                					</div>

            					</div>

        					</div>

    					</div>

            			<div class="row">

               				<div class="col-md-12">

               					<?php if($ticket['ticket_status'] == 2): ?>

               					<?php elseif($ticket['ticket_status'] == 0): ?>

               					<div class="ticket-header__textarea">

                     				<div class="row">

                        				<div class="col-md-12">

               								<a href="#" class="btn btn-default" onclick="update_ticket(<?=$ticket['ticket_id']?>, 1)">Talebi Aktifleştir</a>

               							</div>

               						</div>

               					</div>

               					<?php else: ?>

                  				<div class="ticket-header__textarea">

                     				<div class="row">

                        				<div class="col-md-12">

                              				<form id="admin_send_message" onsubmit="return false;">

                              					<div class="col-md-12">

                                 					<div class="ticket-message-submit" style="margin-bottom:15px;">

                                    					<textarea name="message" id="editor" cols="30" rows="5" class="form-control ticket-edit__textarea"></textarea>

                                 					</div>

                              					</div>

                           						<input name="id" value="<?=$ticket['ticket_id']?>" hidden="">

                                 				<div class="col-sm-6">

                                                    <button class="btn btn-primary" type="submit">Cevabı gönder</button>

                                                    <div class="btn-group">

                                                        <a href="javascript:;" class="btn btn-default" onclick="update_ticket(<?=$ticket['ticket_id']?>, 1)">Talebi Kapat</a>

                                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="caret"></span><span class="sr-only">Toggle Dropdown</span></button>

                                    					<ul class="dropdown-menu">

                                                            <li><a href="javascript:;" onclick="update_ticket(<?=$ticket['ticket_id']?>, 2)">Talebi Kilitle Ve Kapat</a></li>

                                                        </ul>

                                                    </div>

                                            	</div>

                                			</form>

                            			</div>

                            		</div>

                            	</div>

                            	<?php endif; ?>

                            </div>

                        </div>

                        <div class="row">

            				<div class="col-md-12">

                          		<div class="ticket-body">

                           			<div class="ticket-message__container">

                           				<?php foreach($messages as $message): ?>

                                        <div class="<?php if($message['message_author'] == 1): ?>ticket-message__block ticket-message__client<?php else: ?>ticket-message__block ticket-message__support <?php endif; ?>">

                                 			<div class="ticket-message">

                                   	 			<div class="ticket-message__title">

                                       				<div class="row">

                                          				<div class="col-sm-6">

                                          					<?php if($message['message_author']): ?>

                                             				<strong><?=$ticket['user_username']?></strong>

                                             				<?php endif; ?>

                                          				</div>

                                          				<div class="col-sm-6">

                                             				<div class="ticket-message__title-date">

                                                				<?=str_date(date('Y-m-d h:m:s', $message['message_time']))?>

                                                			</div>

                                          				</div>

                                       				</div>

                                    			</div>

                                    			<div class="ticket-message__text"><?=htmlspecialchars_decode($message['message_text'])?></div>

                                 			</div>

                              			</div>

                              			<?php endforeach; ?>

                                    </div>

                        		</div>

                     		</div>

                  		</div>

            		</div>

				<?php endif; ?>

			

			<?php else: ?>
				<a href="javascript:;" data-toggle="modal" data-toggle="modal" data-target="#modalDefault" data-action="get_newsupport" class="btn btn-default">Yeni Talep Oluştur</a>
			<a href="<?=admin_url('support/unread')?>" class="btn btn-default">Okunmayan Talepler</a>

			<div class="pull-right">

			    <form class="form-inline" action="" method="get">

			        <div class="input-group">

			        	<input type="text" name="search" class="form-control" value="" placeholder="Destek Talebi ara...">

			        	<span class="input-group-btn">

			        		<select class="form-control" style="border-radius:0;" name="search_type">

			        			<option value="id">Ticket ID</option>

			        			<option value="link">Başlık</option>

			        			<option value="username">Kullanıcı Adı</option>

			        		</select>

			        		<button type="submit" class="btn btn-default"><span class="fa fa-search" aria-hidden="true"></span></button>

			            </span>

			        </div>

			    </form>

			</div>

			<div class="panel panel-default" style="margin-top:20px;">

				<table class="table order-table table-grey" style="margin-bottom:0;">

					<thead>

						<tr>

							<th>Ticket ID</th>

							<th>Kullanıcı adı</th>

							<th style="width:20%;">Başlık</th>

							<th class="dropdown-th">
									<div class="dropdown">
										<button class="btn btn-sm btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
											Durum
											<span class="caret"></span>
										</button>
										<ul class="dropdown-menu" aria-labelledby="dropdownMenu1" id="serviceListContent" style="max-height: 275px; overflow:hidden; overflow-y: scroll">
											<li>
												<a href="?status=1">Açık</a>
												<a href="?status=2">Kilitli</a>
											</li>
										</ul>
									</div>
								</th>

							<th>Tarih</th>

							<th></th>

						</tr>

					</thead>

					<tbody>

						<?php foreach($tickets as $row): ?>

						<tr>

							<td><?=$row['ticket_id']?></td>

							<td><?=$row['user_username']?></td>

							<td><a <?php if($row['ticket_read'] == 0): ?>style="color:orange;"<?php endif; ?> href="<?=admin_url('support/'.$row['ticket_id'])?>"><?php if($row['ticket_read'] == 0): ?><b><?=$row['ticket_title']?></b><?php else: ?><?=$row['ticket_title']?><?php endif; ?></a></td>

							<td>

								<?php if($row['ticket_status'] == 0): ?>

									<span class="label label-danger"><i class="fas fa-lock-open"></i> Kapalı</span>

								<?php elseif($row['ticket_status'] == 1): ?>

									<span class="label label-success">Açık</span>

								<?php elseif($row['ticket_status'] == 2): ?>

									<span class="label label-default"><i class="fas fa-lock"></i> Kilitli</span>

								<?php endif; ?>

							</td>

							<td><?=str_date($row['ticket_date'])?></td>

							<td>

								<div class="dropdown pull-right">

									<button class="btn btn-xs btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">İşlemler<span class="caret"></span></button>

									<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">

										<?php if($row['ticket_status'] == 0): ?>

											<li><a href="#" onclick="update_ticket(<?=$row['ticket_id']?>, 2)">Talebi Kilitle</a></li>

											<li><a href="#" onclick="update_ticket(<?=$row['ticket_id']?>, 1)">Talebi Aç</a></li>

										<?php elseif($row['ticket_status'] == 1): ?>

											<li><a href="#" onclick="update_ticket(<?=$row['ticket_id']?>, 2)">Talebi Kilitle</a></li>

											<li><a href="#" onclick="update_ticket(<?=$row['ticket_id']?>, 1)">Talebi Kapat</a></li>

										<?php elseif($row['ticket_status'] == 2): ?>

										<?php endif; ?>

										

									</ul>

								</div>

							</td>

						</tr>

						<?php endforeach; ?>

					</tbody>

				</table>

			</div>

			<ul class="pagination">

				<?= $db->showPagination(admin_url(route(1) . '?' . $pageParam . '=[page]')); ?>

			</ul>

			<?php endif; ?>

			<?php endif; ?>

		</div>

	</div>		

</div>

<?php require admin_view('static/footer') ?>