                <!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>İstatistikler Paneli</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
	<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
    <style>
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        .stat-card {
            margin: 15px 0;
        }
        .stat-card h4 {
            margin-bottom: 10px;
        }
        .list-group-item {
            display: flex;
            justify-content: space-between;
        }
        .card-header {
            background-color: #f8f9fa;
            font-size: 1.2rem;
        }
        /* Flex container for charts */
        .chart-container {
            display: flex;
            justify-content: space-between;
        }
        .chart-container canvas {
            width: 33%;
        }
    </style>
</head>
<body style="overflow-x: hidden;">
<?php
header('Content-Type: text/html; charset=utf-8');
error_reporting(0);
$path="../../";
include("../../map.php");
include("../../secure.php");
if($_GET["s19"]<>""){ $s19 = "and s19=".$_GET["s19"].""; }
$sitems = json_decode(GetArr("sayfa"), true);
$hitems = json_decode(GetArr("haber"), true);
$uitems = json_decode(GetArr("kayit"), true);
$users = json_decode(GetArr("","users"), true);
$sqlm=mysqli_query($conn, "select id,ne,t3 from medya"); while($rsm=mysqli_fetch_assoc($sqlm)){$medias[] = $rsm;}
$sqlr=mysqli_query($conn, "select id from t2 where ne='request'"); while($rsr=mysqli_fetch_assoc($sqlr)){$requests[] = $rsm;}
$sqlr = mysqli_query($conn, "SELECT SUM(ne='request') AS request_count, SUM(ne='fmesaj') AS fmesaj_count FROM t2");
$rsr = mysqli_fetch_assoc($sqlr); $request_count = $rsr['request_count']; $fmesaj_count = $rsr['fmesaj_count'];
$sqlt=mysqli_query($conn, "select id from t4 where ne='teklif'"); $teklif_count=mysqli_num_rows($sqlt);
$sqlr=mysqli_query($conn, "select id from genel where ne='request'"); while($rsr=mysqli_fetch_assoc($sqlr)){$requests[] = $rsm;}
$ios=0;$and=0;
$sqlc = mysqli_query($conn, "select n8 from t5"); while($rsc=mysqli_fetch_assoc($sqlc)){ $jsa = json_decode($rsc["n8"],true);
	if($jsa["Device"]=="ios"){
		$ios++;
	}elseif($jsa["Device"]=="android"){
		$and++;
	}
}
if ($m16==1){
	$astoplam = $ystoplam = $gtoplam = $s40 = $s41 = $s42 = $s43 = $s44 = $sip0 = $sip1 = $sip2 = $sip3 = $sip4 = 0; $dpath="../../";
	$sql = mysqli_query($conn, "SELECT * FROM eticaret WHERE ne='siparis'"); while ($siparis = mysqli_fetch_assoc($sql)) {
		include("../ecommerce/ecommerce_order_calc.php");
		
		${"sip" . $siparis["s4"]}++;
		${"s4" . $siparis["s4"]} += $gtoplam;
		
		if (dtarih($siparis["ts1"], "yyyy-aa-gg") >= $haftabasi && $siparis["s4"] != 0) {
			$hstoplam += $gtoplam;
			$hcost += $gcost;
			$tbuhaftasip++;
		}
		
		if (dtarih($siparis["ts1"], "yyyy-aa-gg") >= $aybasi && $siparis["s4"] != 0) {
			$astoplam += $gtoplam;
			$acost += $gcost;
			$tbuaysip++;
		}
		
		if (dtarih($siparis["ts1"], "yyyy-aa-gg") >= $yilbasi && $siparis["s4"] != 0) {
			$ystoplam += $gtoplam;
			$ycost += $gcost;
			$tbuyilsip++;
		}
	}
}
	//findDirectoryPath("deppo")
?>
<div class="">
    <!-- İstatistikler Card'ları -->
    <div class="row">
	<?php
	$i=0;$f=0;$v=0;
	foreach($medias as $key=>$value){
		if($value["t3"]=="sayfa" and $value["ne"]=="resim"){$i++;}
		if($value["t3"]=="sayfa" and $value["ne"]=="dosya"){$f++;}
		if($value["t3"]=="sayfa" and $value["ne"]=="video"){$v++;}
	}
	?>
			 <div class="card stat-card" style="width: 19%; margin-left:15px; margin-right:10px;">
				<div class="card-header">Toplam Sayfa Sayısı</div>
				<div class="card-body d-flex justify-content-between align-items-center">
					<!-- Soldaki sayfa sayısı -->
					<button class="btn btn-primary" style="padding: 10px 20px; font-size: 1.2rem;">
						<span id="total-pages"><?php echo count($sitems);?></span>
					</button>
					<!-- Sağdaki 3 farklı sayı alanı: Resim, Dosya, Video -->
					<div class="d-flex">
						<div class="stat-box" style="margin-left: 15px;">
							<i class="fas fa-image" style="font-size: 1.5rem; color: #e74c3c;"></i>
							<span id="image-count" class="ml-2"><?php echo $i;?></span>
						</div>
						<div class="stat-box" style="margin-left: 15px;">
							<i class="fas fa-file-alt" style="font-size: 1.5rem; color: #f39c12;"></i>
							<span id="file-count" class="ml-2"><?php echo $f;?></span>
						</div>
						<div class="stat-box" style="margin-left: 15px;">
							<i class="fas fa-video" style="font-size: 1.5rem; color: #3498db;"></i>
							<span id="video-count" class="ml-2"><?php echo $v;?></span>
						</div>
					</div>
				</div>
			</div>
	<?php
	$i=0;$f=0;$v=0;
	foreach($medias as $key=>$value){
		if($value["t3"]=="haber" and $value["ne"]=="resim"){$i++;}
		if($value["t3"]=="haber" and $value["ne"]=="dosya"){$f++;}
		if($value["t3"]=="haber" and $value["ne"]=="video"){$v++;}
	}
	?>
             <div class="card stat-card" style="width: 19%; margin-right:10px;">
                <div class="card-header">Toplam Haber Sayısı</div>
                <div class="card-body d-flex justify-content-between align-items-center">
					<!-- Soldaki sayfa sayısı -->
					<button class="btn btn-primary" style="padding: 10px 20px; font-size: 1.2rem;">
						<span id="total-pages"><?php echo count($hitems);?></span>
					</button>
					<!-- Sağdaki 3 farklı sayı alanı: Resim, Dosya, Video -->
					<div class="d-flex">
						<div class="stat-box" style="margin-left: 15px;">
							<i class="fas fa-image" style="font-size: 1.5rem; color: #e74c3c;"></i>
							<span id="image-count" class="ml-2"><?php echo $i;?></span>
						</div>
						<div class="stat-box" style="margin-left: 15px;">
							<i class="fas fa-file-alt" style="font-size: 1.5rem; color: #f39c12;"></i>
							<span id="file-count" class="ml-2"><?php echo $f;?></span>
						</div>
						<div class="stat-box" style="margin-left: 15px;">
							<i class="fas fa-video" style="font-size: 1.5rem; color: #3498db;"></i>
							<span id="video-count" class="ml-2"><?php echo $v;?></span>
						</div>
					</div>
				</div>
            </div>
<?php
$i=0;$f=0;$v=0;
foreach($medias as $key=>$value){
	if($value["t3"]=="kayit" and $value["ne"]=="resim"){$i++;}
	if($value["t3"]=="kayit" and $value["ne"]=="dosya"){$f++;}
	if($value["t3"]=="kayit" and $value["ne"]=="video"){$v++;}
}
?>
             <div class="card stat-card" style="width: 19%; margin-right:10px;">
                <div class="card-header">Toplam Kayıt Sayısı</div>
                <div class="card-body d-flex justify-content-between align-items-center">
					<!-- Soldaki sayfa sayısı -->
					<button class="btn btn-primary" style="padding: 10px 20px; font-size: 1.2rem;">
						<span id="total-pages"><?php echo count($uitems);?></span>
					</button>
					<!-- Sağdaki 3 farklı sayı alanı: Resim, Dosya, Video -->
					<div class="d-flex">
						<div class="stat-box" style="margin-left: 15px;">
							<i class="fas fa-image" style="font-size: 1.5rem; color: #e74c3c;"></i>
							<span id="image-count" class="ml-2"><?php echo $i;?></span>
						</div>
						<div class="stat-box" style="margin-left: 15px;">
							<i class="fas fa-file-alt" style="font-size: 1.5rem; color: #f39c12;"></i>
							<span id="file-count" class="ml-2"><?php echo $f;?></span>
						</div>
						<div class="stat-box" style="margin-left: 15px;">
							<i class="fas fa-video" style="font-size: 1.5rem; color: #3498db;"></i>
							<span id="video-count" class="ml-2"><?php echo $v;?></span>
						</div>
					</div>
				</div>
            </div>
			<div class="card stat-card" style="width: 19%; margin-right:10px;">
                <div class="card-header"><?php echo $t25s[0]?></div>
					<div class="card-body d-flex justify-content-between align-items-center">
					<!-- Soldaki sayfa sayısı -->
					<button class="btn btn-primary" style="padding: 10px 20px; font-size: 1.2rem;">
						<span id="total-pages"><?php echo count($users);?></span>
					</button>
					<!-- Sağdaki 3 farklı sayı alanı: Resim, Dosya, Video -->
					<div class="d-flex">
						<div class="stat-box" style="margin-left: 15px;">
							<i class="fas fa-mobile-alt" style="font-size: 1.5rem; color: #e74c3c;"></i>
							<span id="image-count" class="ml-2"><?php echo ($ios+$and)?></span>
						</div>
						<div class="stat-box" style="margin-left: 15px;">
							<i class="fab fa-apple" style="font-size: 1.5rem; color: #f39c12;"></i>
							<span id="file-count" class="ml-2"><?php echo $ios?></span>
						</div>
						<div class="stat-box" style="margin-left: 15px;">
							<i class="fab fa-android" style="font-size: 1.5rem; color: #3498db;"></i>
							<span id="video-count" class="ml-2"><?php echo $and?></span>
						</div>
					</div>
				</div>
            </div>
            <div class="card stat-card" style="width: 19%; margin-right:10px;">
                <div class="card-header">Diğer</div>
					<div class="card-body d-flex justify-content-between align-items-center">
					<button class="btn btn-primary" style="padding: 10px 20px; font-size: 1.2rem;"><?php echo $request_count+$fmesaj_count+$teklif_count;?></button>
					<!-- Sağdaki 3 farklı sayı alanı: Resim, Dosya, Video -->
					<div class="d-flex">
						<div class="stat-box" style="margin-left: 30px;" title="Talepler">
							<i class="fa fa-receipt" style="font-size: 1.5rem; color: #e74c3c;"></i><br>
							<span id="image-count" class="ml-2"><?php echo $request_count;?></span>
						</div>
						<div class="stat-box" style="margin-left: 30px;" title="Mesajlar">
							<i class="fa fa-envelope-open-text" style="font-size: 1.5rem; color: #3498db;"></i><br>
							<span id="video-count" class="ml-2"><?php echo $fmesaj_count;?></span>
						</div>
						<div class="stat-box" style="margin-left: 30px;" title="Teklifler">
							<i class="fa fa-magic" style="font-size: 1.5rem; color: #f39c12;"></i><br>
							<span id="file-count" class="ml-2"><?php echo $teklif_count;?></span>
						</div>
					</div>
				</div>
            </div>
    </div>
    <!-- Charts Container -->
    <div class="chart-container">
        <!-- Order Status Pie Chart -->
        <div class="card stat-card " style="width: 33%;">
            <div class="card-header">Toplam Sipariş Durumu (Pie)</div>
            <div class="card-body">
                <canvas id="orderStatusChart"></canvas>
                <div id="orderStatusPieDetails"></div>
            </div>
        </div>
        
        <!-- Order Status Bar Chart -->
        <div class="card stat-card" style="width: 33%;">
            <div class="card-header">Toplam Sipariş Durumu (Bar)</div>
            <div class="card-body">
                <canvas id="orderStatusBarChart"></canvas>
                <div id="orderStatusBarDetails"></div>
            </div>
        </div>
        <!-- Order Status Bar Chart -->
        <div class="card stat-card" style="width: 33%;">
		<div class="card-header">En Çok İzlenen Ürünler</div>
			<ul class="list-group" id="top-products">
<?php $sql = mysqli_query($conn, "select * from ".$_SESSION['lang']." where ne='kayit' $s19 order by s20 desc limit 10"); while($rsu=mysqli_fetch_assoc($sql)){?>
					<li class="list-group-item"><?php echo kisalt($rsu["t1"],60)?><span class="badge badge-success"><?php echo nice_number($rsu["s20"])?></span></li>
<?php }?>
			</ul>
        </div>
    </div>
    <!-- En Çok İzlenen Ürünler -->
    <div class="row">
        <div class="col-md-3">
            <div class="card stat-card">
                <div class="card-header">En Çok İzlenen Sayfalar</div>
				<ul class="list-group" id="top-products">
<?php $sql = mysqli_query($conn, "select * from ".$_SESSION['lang']." where ne='sayfa' $s19 order by s20 desc limit 10"); while($rsu=mysqli_fetch_assoc($sql)){?>
					<li class="list-group-item"><?php echo kisalt($rsu["t1"],40)?><span class="badge badge-success"><?php echo nice_number($rsu["s20"])?></span></li>
<?php }?>				</ul>
            </div>
		</div>
<div class="col-md-3">
            <div class="card stat-card">
				<div class="card-header">En Çok İzlenen Haberler</div>
				<ul class="list-group" id="top-products">
<?php $sql = mysqli_query($conn, "select * from ".$_SESSION['lang']." where ne='haber' $s19 order by s20 desc limit 10"); while($rsu=mysqli_fetch_assoc($sql)){?>
					<li class="list-group-item"><?php echo kisalt($rsu["t1"],40)?><span class="badge badge-success"><?php echo nice_number($rsu["s20"])?></span></li>
<?php }?>
				</ul>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card stat-card">
				<div class="card-header">Ürün Grupları</div>
				<ul class="list-group" id="top-products">
<?php
$sqlx=mysqli_query($conn, "select Cat_ID,Cat_".$_SESSION['lang']." from kategoriler where ne='ukategori' order by Cat_".$_SESSION['lang']." asc"); while($rsx=mysqli_fetch_assoc($sqlx)){$x++;
$sql = mysqli_query($conn, "select id from ".$_SESSION['lang']." where ne='kayit' and s9='".$rsx["Cat_ID"]."' $s19"); $rsu=mysqli_num_rows($sql);
?>
					<li class="list-group-item"><?php echo $rsx["Cat_".$_SESSION['lang'].""];?><span class="badge badge-success"><?php echo $rsu?> Ürün</span></li>
<?php }?>
				</ul>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card stat-card">
                <div class="card-header">Alarm Listesi (<?php echo $module["s17"]?>)</div>
				<ul class="list-group" id="top-products">
<?php $sql = mysqli_query($conn, "select * from ".$_SESSION['lang']." where ne='kayit' and s5 <= ".$module["s17"]." $s19 limit 10"); while($rsu=mysqli_fetch_assoc($sql)){?>
					<li class="list-group-item"><?php echo kisalt($rsu["t1"],40)?><span class="badge badge-danger">Stokta Yok</span></li>
<?php }?>
				</ul>
            </div>
        </div>
    </div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.2/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.min.js"></script>
<script>
// Example JSON data (in a real scenario, this data would come from a server)
const statsData = {
    "totalOrders": {
        "waiting": <?php echo $sip0;?>,
        "confirmed": <?php echo $sip1;?>,
        "shipped": <?php echo $sip2;?>,
        "completed": <?php echo $sip4;?>,
        "waitingAmount": <?php echo number_format($s40,2);?>,
        "confirmedAmount": <?php echo number_format($s41,2);?>,
        "shippedAmount": <?php echo number_format($s42,2);?>,
        "completedAmount": <?php echo number_format($s44,2);?>
    }
};
$(document).ready(function () {
    var ctx = document.getElementById('orderStatusChart').getContext('2d');
    var orderStatusChart = new Chart(ctx, {
        type: 'pie',
        data: {
            labels: ['Beklemede', 'Onaylanmış', 'Kargoda', 'Tamamlanan'],
            datasets: [{
                data: [
                    statsData.totalOrders.waiting,
                    statsData.totalOrders.confirmed,
                    statsData.totalOrders.shipped,
                    statsData.totalOrders.completed
                ],
                backgroundColor: ['#f39c12', '#27ae60', '#2980b9', '#8e44ad'],
                label: 'Sipariş Durumu'
            }]
        },
        options: {
            plugins: {
                tooltip: {
                    callbacks: {
                        label: function (tooltipItem) {
                            const amount = [
                                statsData.totalOrders.waitingAmount,
                                statsData.totalOrders.confirmedAmount,
                                statsData.totalOrders.shippedAmount,
                                statsData.totalOrders.completedAmount
                            ][tooltipItem.dataIndex];
                            return `${tooltipItem.label}: ${tooltipItem.raw} adet (${amount} TL)`;
                        }
                    }
                }
            }
        }
    });
    // Order Status Bar Chart (Bar Chart)
    var barCtx = document.getElementById('orderStatusBarChart').getContext('2d');
    var orderStatusBarChart = new Chart(barCtx, {
        type: 'bar',
        data: {
            labels: ['Beklemede', 'Onaylanmış', 'Kargoda', 'Tamamlanan'],
            datasets: [{
                label: 'Sipariş Durumu',
                data: [
                    statsData.totalOrders.waiting,
                    statsData.totalOrders.confirmed,
                    statsData.totalOrders.shipped,
                    statsData.totalOrders.completed
                ],
                backgroundColor: '#3498db',
                borderColor: '#2980b9',
                borderWidth: 1
            }]
        },
        options: {
            responsive: true,
            scales: {
                y: {
                    beginAtZero: true
                }
            }
        }
    });
});
</script>
</body>
</html>