<!DOCTYPE html>
<?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")]);
?>
<html lang="en">



<head>

	<meta charset="utf-8">

<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}" />
	    <!-- bootstrap -->
  
    <link rel="stylesheet" href="<?=theme("assets/kits/bootstrap/css/bootstrap.min.css");?>?v=<?=time()?>">
    <link rel="stylesheet" href="<?=theme("assets/css/bootstrap-datepicker.min.css");?>?v=<?=time()?>">	    
	<link rel="stylesheet" href="<?=theme("assets/css/main.css");?>?v=<?=time()?>">
	<link rel="stylesheet" href="<?=theme("assets/css/select2.css");?>?v=<?=time()?>">
	<link rel="stylesheet" href="<?=public_url("system/css/alertify.css");?>">
    <!-- fa-icons -->
    <link rel="stylesheet" type="text/css" href="https://cdn.mypanel.link/css/font-awesome/css/all.min.css">

</head>
<body class="dashboard-body">
    <?php if(!session('user_id')): ?>
     <div class="header">
        <div class="container">
            <div class="row" style="height: 99px;">
                <div class="col-auto align-self-center">
                    <div class="row">
                        <div class="col align-self-center">
						<a href="/">
                            <div class="site-name">
                                <img src="{SITE_LOGO}" alt="">
                            </div>
						</a>
                        </div>
                    </div>
                </div>
                <div class="col">
                    <div class="head-menu">
                        <div class="row">
                            <div class="col text-lg-right mmff">
                                <div class="header-menu">
                                    <ul>
                        <?php foreach($mainmenus as $row): if($row['menu_type'] == 2): ?>
                        <?php
                        
                                ?>
                                        <li>
                                            <a href="<?=isset($siteLinks[$row['menu_link']]['url']) ? $siteLinks[$row['menu_link']]['url'] : $row['menu_link'] ?>"><?=$row['menu_title']?></a>
                                        </li>

					<?php endif; endforeach; ?>

                                    </ul>
                                </div>
                            </div>
                            <div class="col-auto align-self-center mmff">
								<a href="/register" class="menu-btn">
									<div class="mb-icon">
										<i class="fas fa-user-circle"></i>
									</div>
									<div class="mb-text">Kayıt Ol</div>
								</a>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-auto for-mobile align-self-center">
                    <div class="home-menu-btn px-3 py-4" onclick="homeMenuToggle()" style="color: #fff;">
                        <i class="fal fa-bars"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <br>  
     <?php endif; ?>
      <script>
         var app = document.getElementsByTagName("BODY")[0];
         if (localStorage.lightMode == "dark") {
         	app.setAttribute("class", "dark");
         }
      </script>
    <div class="app-container">
        <?php if(session('user_id')): ?>
        <div class="app-sidebar">
            <div class="close-sidebar-btn" onclick="dashMenuToggle()">
                <i class="fas fa-bars"></i>
            </div>
		<div class="sidebar-header">
            <div class="sh-bg"></div>
            <div class="app-logo">
                <a href="/">
                <img src="{SITE_LOGO}" class="logo-lg" alt="">
                <img src="{SITE_LOGO}" class="logo-sm" alt="">
                </a>
            </div>
             <?php if ($user['user_authority'] == 1 || $user['user_authority'] == 2 || $user['user_authority'] == 0) { ?> 
            <div class="app-user">
				<div class="app-user-box">
					<div class="app-user-img">
							<a href="#">
								<img src="<?=theme("assets/img/avatar.png");?>">
							</a>
					</div>
					<div class="app-user-info">
						<h4 class="app-user-name">{USER_USERNAME} <img src="<?=theme("assets/img/verified.png")?>" width="16" /></h4>
						<div class="app-user-blnce">{USER_BALANCE} <?=CURRENCY_SYMBOL?></div>
					</div>
				</div>
				<ul class="list-inline">
					<li class="list-inline-item"><a href="{LINK_ACCOUNT}"><i class="fal fa-user-alt"></i></a></li>
					<li class="list-inline-item"><a href="{LINK_TICKETS}"><i class="fal fa-envelope-open"></i></a></li>
					<li class="list-inline-item"><a href="{LINK_LOGOUT}"><i class="fal fa-power-off"></i></i></a></li>
				</ul>
            </div>
            <?php } ?>
        </div>
            <div class="sidebar-content">
                <ul class="sidebar-menu">
                   
                    <?php foreach($mainmenus as $row): if($row['menu_type'] == 1):?>

                        <?php
                        if($row['menu_link'] == "tickets"){
                            if ($unread > 0) {
							echo '<li class="active">
									<a class="sidebar-link" href="{LINK_TICKETS}">
										<i class="fas fa-ticket-alt m-icon"></i> <span class="menu-text">{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>
									<a class="sidebar-link" href="{LINK_TICKETS}">
										<i class="fas fa-ticket-alt m-icon"></i> <span class="menu-text">{NAVBAR_TICKETS} </span>
									</a>
								  </li>';
						    }
                        }else{
                                               if($row['menu_title'] == "Panel Kirala"){
                                    $status = $db->from("settings")->where("id",1)->first();
        $status = json_decode($status['childpanel'],1);
        if($status['status'] == 1){
		$child = $db->from('child_panels')->where('user_id', session('user_id'))->first();

                        
                        ?>

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

								<i class="<?=$row['menu_icon']?> m-icon"></i> <span class="menu-text"><?=$row['menu_title']?></span>

							</a>

						</li>
						<?php }}else{ ?>
						
												<li>
							<a class="sidebar-link" href="<?=isset($siteLinks[$row['menu_link']]['url']) ? $siteLinks[$row['menu_link']]['url'] : $row['menu_link'] ?>">

								<i class="<?=$row['menu_icon']?> m-icon"></i> <span class="menu-text"><?=$row['menu_title']?></span>

							</a>

						</li>
						<?php
						}
						} ?>
					<?php endif; endforeach; ?>
				
					<?php 

					if ($user['user_authority'] == 2) {
						echo '<hr>
						<li>

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

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

							</a>

						</li>';
					}

					?>
					
                </ul>

            </div>
        </div>
        <div class="app-header">
            <div class="container-fluid">
                <div class="row row-80">
                    <div class="col-auto align-self-center">
                        <div class="dash-menu-btn" onclick="dashMenuToggle()">
                            <i class="fal fa-bars"></i>
                        </div>
                    </div>
                    <div class="col d-inline-block d-md-none align-self-center text-center">
                        <div class="app-logo">
							<img src="{SITE_LOGO}" />
                        </div>
                    </div>
                    <div class="col col-100 d-none d-md-inline-block align-self-center"> </div>
                    <div class="col-auto align-self-center">
                     <button class="darkmode" onclick="change_mode()">
						 <i class="fal fa-sun"></i>
						 <i class="fal fa-moon"></i>
                     </button>
                    </div>
                </div><!-- row -->
            </div>
        </div><!-- header -->
        <?php endif; ?>
        