<?php
function fotoprofile($username)
{
	include("../koneksi.php");
	$query = "SELECT admin_pic	FROM admins where username='$username'";
	$data = mysqli_query($koneksi, $query);
	$row = mysqli_fetch_assoc($data);
	// echo $row['member_pic'];
	// die;
	return $row['admin_pic'];
}

function rupiah($angka)
{
	$hasil_rupiah = "Rp " . number_format($angka, 2, ',', '.');
	return $hasil_rupiah;
}

function jmlfree()
{
	include("../koneksi.php");
	$query = "SELECT *	FROM user WHERE level='free'";
	$data = mysqli_query($koneksi, $query);
	$jml = mysqli_num_rows($data);
	// echo $jml;
	// die;
	return $jml;
}

function jmlmember()
{
	include("../koneksi.php");
	$query = "SELECT *	FROM user WHERE level='member'";
	$data = mysqli_query($koneksi, $query);
	$jml = mysqli_num_rows($data);
	// echo $jml;
	// die;
	return $jml;
}

function counter()
{
	if (!isset($_SESSION['counter'])) { // It's the first visit in this session
		$handle = fopen("counter.txt", "r");
		if (!$handle) {
			echo "Could not open the file";
		} else {
			$counter = (int) fread($handle, 20);
			fclose($handle);
			$counter++;
			// echo " <p> Visitor Count: " . $counter . " </p> ";
			$handle = fopen("counter.txt", "w");
			fwrite($handle, $counter);
			fclose($handle);
			$_SESSION['counter'] = $counter;
		}
	} else { // It's not the first time, do not update the counter but show the total hits stored in session
		$counter = $_SESSION['counter'];
		// return $counter;
		// echo " <p> Visitor Count: " . $counter . " </p> ";
	}
	return $counter;
}

function visitor()
{
	// if (!isset($_SESSION['counter'])) { // It's the first visit in this session
	$handle = fopen("../counter.txt", "r");
	if (!$handle) {
		echo "Could not open the file";
	} else {
		$counter = (int) fread($handle, 20);
		fclose($handle);
		// $counter++;
		// echo " <p> Visitor Count: " . $counter . " </p> ";
		// $handle = fopen("counter.txt", "w");
		// fwrite($handle, $counter);
		// fclose($handle);
		// $_SESSION['counter'] = $counter;
	}
	// } else { // It's not the first time, do not update the counter but show the total hits stored in session
	// 	$counter = $_SESSION['counter'];
	// return $counter;
	// echo " <p> Visitor Count: " . $counter . " </p> ";
	// }
	return $counter;
}

function newconfirm()
{
	include("../koneksi.php");
	$query = "SELECT *	FROM konfirm_transfer WHERE validasi='false'";
	$data = mysqli_query($koneksi, $query);
	$jml = mysqli_num_rows($data);
	// echo $jml;
	// die;
	if ($jml == 0)
		return "";
	else
		return $jml;
}

function statistik($ref)
{
	include "koneksi.php";
	$query = "SELECT * FROM user WHERE username= '$ref'";
	$data = mysqli_query($koneksi, $query);
	$cek = mysqli_num_rows($data);

	if ($cek > 0) {
		$row = mysqli_fetch_assoc($data);
		$id_member = $row['id'];
	} else {
		$id_member = '1';
	}
	if (!isset($_SESSION['stat3'])) { // It's the first visit in this session
		$query = "INSERT INTO tbl_statistik (id_landing, id_member, count) 
		VALUES ('17','$id_member','1')";
		mysqli_query($koneksi, $query);
		$_SESSION['stat3'] = "1";
	}
}
