<?php
    include('../loginsession.php');
    error_reporting(E_ALL);
    $filename = __FILE__;  //---Nama file saat ini
    $filenameshort = $filename;
    if (strlen($filename) > 48) {$filenameshort = substr($filename, 48);}
    $save = mysqli_query($conn, "INSERT INTO novia_abc_user_logs (userid,filename) VALUES ('$userini_id','$filenameshort')");
//-------------
    $cari ='';
    if(isset($_GET['cari'])){
    	$cari = $_GET['cari'];
    }
//-------------
?>

<!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>
		body {
		    color:#ccc;
		}
        .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: 96%;
            margin: 0 auto;
            padding: 5px 1px 5px 3px;
            /*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);*/
        }

    </style>	
</head>

<body>
<br>
<a href="../coding/coding_main.php" title="Lihat Keuangan Hari ini"><button style="padding : 10px; width:100%; background-color:#546E7A;">CODING</button></a>
<br>
<br>
	<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">
<?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="array_item.php?id=<?php echo $userId; ?>"><?php echo $Name." <br> ".$points; ?></a></button>
        <?php
    }
}

?>
</div>
<?php
echo "<pre>";
print_r($userPoints);
echo "</pre>";

//echo '<button>' . $Name . ': ' . $points . '</button> ';

?>

</body>
</html>
