<?php
    include('loginsession.php');
    error_reporting(E_ALL);
    $filename = __FILE__;
    if (strlen(__FILE__) > 48) {$filename = substr(__FILE__, 48);}
    $save = mysqli_query($conn, "INSERT INTO novia_abc_user_logs (userid,filename) VALUES ('$userini_id','$filename')");
//-------------
    $id = 0;
    if(isset($_GET['id'])){
    	$id = $_GET['id'];
    }
    $NamE = $NAME[$id];
    
//-------------
    $pointacc = 0;
    $point = "SELECT * FROM novia_abc_user_logs WHERE userid = '$id' ORDER BY tanggal DESC";
    $result = $conn->query($point);
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
    		$pointacc ++;
    	}
    }
//-------------
$Total_Bulanan = 0;
$Total_Bulanan_Meditasi = 0;

$se = date("Y-m-d H:i:s");
$dt1 = new DateTime($se);
$timeU1 = $dt1->format('U');
$bulan = $timeU1 - 2592000;

$aero = "SELECT * FROM novia_abc_user_aero where userid=$id ORDER BY tanggal DESC";
$resultan = $conn->query($aero);
    while($baris = $resultan->fetch_assoc()) {
		
		
		$s = $baris["tanggal"];
        $dt = new DateTime($s);
        $currdate = $dt->format('Y-m-d');
        $detik = $dt->format('U');
		if ( $detik >= $bulan ){
			$Total_Bulanan += $baris["aero"];
			$Total_Bulanan_Meditasi += $baris["meditation"];
		}
	}
$PointAll = "Point ".$pointacc." Aerobik ".$Total_Bulanan." Meditasi ".$Total_Bulanan_Meditasi;

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//ID" "http://www.w3.org/TR/html4/frameset.dtd">
<html lang="id">
<head>
	<title>USER ACTIVITY</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="../css/style.css">
	<link href="../images/balance.ico" rel="icon" type="image/icon" />

	<style>
        .btn {
          background-color: #6497b1; /* Biru Lembut */
          border: none;
          color: #ddd;
          padding: 10px 10px;
          text-align: center;
          text-decoration: none;
          display: inline-block;
          font-size: 15px;
          font-family: "Times New Roman";
          margin: 4px 0px 0px 1px;
          cursor: pointer;
          border-radius: 5px;
          transition-duration: 0.4s;
          width:32%;
          height:55px;
        }
        
        .btn:hover {
          background-color: #b3cde0; /* Biru Lembut yang lebih gelap */
          color: white;
        }
        .container {
            width: 98%;
            margin: 0 auto;
            padding: 5px 1px 7px 3px;
            background-color: #f0f0f0;
            /*display: flex;
            justify-content: center;
            background-color: #f0f0f0;
            border: 1px solid #ccc;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);*/
        }
        .tiga {
        	background-color:#568aa0;
        	color: #ddd;
        }

	</style>
	
</head>
<body>
	<table width="100%" cellpadding="5">
		<tr class="dua">
		    <td><a href="administrasi.php" title="Pusat Navigasi Data"><button style="padding : 10px; width:100%;"> NAVIGASI </button></a></td>
		    <td><a href="index.php" title="Pusat Navigasi Data"><button style="padding : 10px; width:100%;"> HOME </button></a></td>
		</tr>
	</table> 
	
<div class="container">
	<table width="99%" cellpadding="5">
		<tr class="tiga">
		    <td Height=66px align="center";><a style = "font-size:18px; font-family: Times New Roman;">Aktifitas<a>
		        <a style = "font-size:21px; font-family: Times New Roman; text-transform:uppercase;"><br><?php echo $NamE; ?><a>
		        <a style = "font-size:15px; font-family: Times New Roman;"><br><?php echo $PointAll; ?><a></td>
		</tr>
	</table>


<?php

$userPoints = [];
$pointQuery = "SELECT userid FROM novia_abc_user_logs ORDER BY tanggal DESC";
$result = $conn->query($pointQuery);

if ($result && $result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $userId = $row['userid'];
    if ($userId != 0 && $userId != 1){
        if (!isset($userPoints[$userId])) {
            $userPoints[$userId] = 0;
        }
        $userPoints[$userId]++;
    }
    }
    foreach ($userPoints as $userId => $points) {
        $Name = $NAME[$userId];
        ?>
        <button class="btn"><a href="userlog_item.php?id=<?php echo $userId; ?>"><?php echo $Name." <br> ".$points; ?></a></button>
        <?php
    }
}

?>
</div>


<table width="100%" cellpadding="4">
	<tr class="head">
		<th width="30">ID</th>
		<th width="125">Tanggal</th>
		<th width="30">UserID</th>
		<th align="left">Halaman</th>
	</tr>

<?php 
$sty = 1;
$sql = "SELECT * FROM novia_abc_user_logs ORDER BY tanggal DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
	while($row = $result->fetch_assoc()) {
	$Userid = $row['userid'];
	if (isset($USERNAME[$Userid])) {
        $Username = $USERNAME[$Userid];
    }
	
	if ($Userid == $id){	
		$si = $row['id'] + 1;
		$y = 2;
		$result1 = fmod($si,$y);
		if ( $result1 == 0 ) $sty = "dua";
		if ( $result1 == 1 ) $sty = "satu";

    
?>
	<tr class=<?php echo $sty; ?>>
		<td width="30" align="center"><?php echo $row["id"]; ?></td>
		<td width="125" align="left"><?php echo $row["tanggal"]; ?></td>
		<td width="30" align="center"><?php echo $Username; ?></td>			
		<td><?php echo $row["filename"]; ?></td>
	</tr>
<?php
	}
	}
}
?>


</body>