<?php

$query = $db->prepare("SELECT * FROM `tickets` WHERE user_id = ? ORDER BY ticket_id DESC");

$query->execute([session("user_id")]);

$tickets = $query->fetchAll(PDO::FETCH_ASSOC);

foreach ($tickets as $ticket) {
	if ($ticket['client_read'] == 0 && $ticket['client_read'] != null) {
		$unread++;							
	}
}
$date = time();
$query = $db->prepare("UPDATE `users` SET last_date = $date WHERE user_id = ?");
$query->execute([session("user_id")]);
?>

<!DOCTYPE html>

<html lang="en">



<head>

	<meta charset="utf-8">

	<meta http-equiv="X-UA-Compatible" content="IE=edge">

	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

	
	<?php if(@$meta): ?>
	<title><?php if($meta['title']): ?><?=$meta['title']?><?php else: ?>{PAGE_TITLE} | {SITE_TITLE}<?php endif; ?></title>
	<meta name="description" content="<?php if($meta['desc']): ?><?=$meta['desc']?><?php else: ?>{SITE_DESC}<?php endif; ?>"/>
	<meta name="keywords" content="<?php if($meta['keyw']): ?><?=$meta['keyw']?><?php else: ?>{SITE_KEYW}<?php endif; ?>"/>	
	<?php else: ?>
	<title>{PAGE_TITLE} | {SITE_TITLE}</title>
	<meta name="description" content="{SITE_DESC}"/>
	<meta name="keywords" content="{SITE_KEYW}"/>
	<?php endif; ?>

	<link rel="shortcut icon" href="{SITE_FAVO}" />

	<link rel="apple-touch-icon-precomposed" href="{SITE_FAVO}" />

	<link rel="stylesheet" href="<?=theme("assets/css/app.css");?>?v=<?=time()?>">

	<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css">

	<link rel="stylesheet" href="<?=public_url("system/css/alertify.css");?>">

	<script src="https://www.google.com/recaptcha/api.js" async defer></script>



	<?= htmlspecialchars_decode($settings['header_code']); ?>



	<script type="text/javascript">

		var _url = "{LINK_POST}";

	</script>



	<style>

		.hide{

			display:none;

		}
		
		body.dark-mode table.dataTable tbody tr {background-color: #474150;}
		body.dark-mode .dataTables_info, body.dark-mode .dataTables_wrapper .dataTables_filter{color: #fff;}

	</style>



</head>



<body>

	<div class="wrapper">

		<nav id="sidebar" class="sidebar">

			<div class="sidebar-content js-simplebar">

				<a class="sidebar-brand" href="{LINK_HOMEPAGE}">

					<img src="{SITE_LOGO}" height="50">

				</a>



				<ul class="sidebar-nav">



					<?php foreach($mainmenus as $row): if($row['menu_type'] == 1):?>

                        <?php
                        if($row['menu_link'] == "tickets"){
                            if ($unread > 0) {
							echo '<li class="sidebar-item">
									<a class="sidebar-link" href="{LINK_TICKETS}">
										<i style="color:#dc123c;" class="align-middle fas fa-ticket-alt"></i> <span style="color:#dc123c;" class="align-middle">{NAVBAR_TICKETS} <span style="background:white;color:#000;padding:2px 5px;border-radius:2px 5px;font-weight:bold;">'.$unread.'</span></span>
									</a>
								  </li>';
						    }else{
							echo '<li class="sidebar-item">
									<a class="sidebar-link" href="{LINK_TICKETS}">
										<i class="align-middle fas fa-ticket-alt"></i> <span class="align-middle">{NAVBAR_TICKETS} </span>
									</a>
								  </li>';
						    }
                        }else{ ?>

						<li class="sidebar-item">

							<a class="sidebar-link" href="<?=isset($siteLinks[$row['menu_link']]['url']) ? $siteLinks[$row['menu_link']]['url'] : $row['menu_link'] ?>">

								<i class="align-middle <?=$row['menu_icon']?>"></i> <span class="align-middle"><?=$row['menu_title']?></span>

							</a>

						</li>
						<?php } ?>

					<?php endif; endforeach; ?>
					
					
					
					<?php 

					if ($user['user_authority'] == 2) {
						echo '<hr>
						<li class="sidebar-item">

							<a class="sidebar-link" href="/admin">

								<i class="align-middle fas fa-arrow-alt-circle-right"></i> <span class="align-middle"> Admin Paneli</span>

							</a>

						</li>';
					}

					?>
					

					



				</ul>

			</div>

		</nav>



		<div class="main">

			<nav class="navbar navbar-expand navbar-light navbar-bg">

				<a class="sidebar-toggle d-flex">

					<i class="hamburger align-self-center"></i>

				</a>



				<div class="navbar-collapse collapse">

					<ul class="navbar-nav navbar-align">

						<li class="nav-item">

							<a class="nav-link d-none d-sm-inline-block" href="{LINK_ADD}">

								<span class="text-dark">{USER_BALANCE} <?=CURRENCY_SYMBOL?></span>

							</a>

						</li>

						<li class="nav-item dropdown">

							<a class="nav-icon dropdown-toggle d-inline-block d-sm-none" href="#" data-toggle="dropdown">

								<i class="align-middle" data-feather="settings"></i>

							</a>



							<a class="nav-link dropdown-toggle d-none d-sm-inline-block" href="#" data-toggle="dropdown">

								<span class="text-dark">{USER_USERNAME}</span>

							</a>

							<div class="dropdown-menu dropdown-menu-right">

								<a class="dropdown-item" href="{LINK_ACCOUNT}"><i class="align-middle mr-1" data-feather="user"></i> {MY_ACCOUNT}</a>

								<div class="dropdown-divider"></div>

								<a class="dropdown-item" href="{LINK_LOGOUT}">{LOGOUT_TITLE}</a>

							</div>

						</li>

						<li class="nav-item">

							<a class="nav-icon d-inline-block" href="#" id="nightIcon" onclick="darkLight()">

							</a>

						</li>

					</ul>

				</div>

			</nav>

			

			<main class="content">

				<div class="container-fluid p-0">



					<h1 class="h3 mb-3"><?=$title?></h1>