<?
//*********************************************************************************
// Original Website By : Niadesain.com Di Jual melalui http://niadesain.com
// Please Call / SMS : 081384745483 (support@niadesain.com)
// Niadesain.com - Jasa Pembuatan Website Paling Murah dan Paling Lengkap
//*********************************************************************************
?>
<?
function genbiru($noid,$nama,$nourut,$join) {
	echo "<table width=75 height=85 border=0 cellpadding=0 cellspacing=0><tr>";
	echo "<td width=4 height=4><img src=../images/genbiru_03.gif width=4 height=4 /></td>";
	echo "<td height=4 background=../images/genbiru_04.gif></td>";
	echo "<td width=4 height=4><img src=../images/genbiru_05.gif width=4 height=4 /></td></tr>";
	echo "<tr><td background=../images/genbiru_07.gif></td>";
	echo "<td width=67 height=78 align=center valign=center background=../images/genbiru_08.gif style='font-family:Verdana, Arial, 
			Helvetica, sans-serif; font-size:9px; font-weight:bold'>";
	

		echo "<a href='jaringan.php?page=genealogi&awal=$noid'>$noid</a><br>$nama<br><br>$nourut<br>";
}
//---------kotak biru---------
function genbiru2($noid,$nama,$nourut,$join) {
	echo "<table width=75 height=85 border=0 cellpadding=0 cellspacing=0><tr>";
	echo "<td width=4 height=4><img src=../images/genbiru_03.gif width=4 height=4 /></td>";
	echo "<td height=4 background=../images/genbiru_04.gif></td>";
	echo "<td width=4 height=4><img src=../images/genbiru_05.gif width=4 height=4 /></td></tr>";
	echo "<tr><td background=../images/genbiru_07.gif></td>";
	echo "<td width=67 height=78 align=center valign=center background=../images/genbiru_08.gif style='font-family:Verdana, Arial, 
			Helvetica, sans-serif; font-size:9px; font-weight:bold'>";
	

		echo "$nama<br><br>$nourut<br>";
}
//-bawah---------
function genbirubawah() {
	
	echo "</td><td background=../images/genbiru_09.gif></td></tr><tr>";
	echo "<td width=4 height=4><img src=../images/genbiru_10.gif width=4 height=4 /></td>";
	echo "<td height=4 background=../images/genbiru_11.gif></td><td width=4 height=4>
		<img src=../images/genbiru_12.gif width=4 height=4 /></td></tr></table>";

}

//------kotak hijau------------------
function genhijau($noid,$nama,$nourut,$totki) {
	echo "<table width=75 height=85 border=0 cellpadding=0 cellspacing=0><tr>";
	echo "<td width=4 height=4><img src=../images/genhijau_03.gif width=4 height=4 /></td>";
	echo "<td height=4 background=../images/genhijau_04.gif></td>";
	echo "<td width=4 height=4><img src=../images/genhijau_05.gif width=4 height=4 /></td></tr>";
	echo "<tr><td background=../images/genhijau_07.gif></td>";
	echo "<td width=67 height=78 align=center valign=top background=../images/genhijau_08.gif style='font-family:Verdana, Arial, 
			Helvetica, sans-serif; font-size:9px; font-weight:bold'>";
	echo "$noid<br>$nama<br><br>$nourut<br>";
	//memberkiri($nama);
}
//-bawah---------
function genhijaubawah() {
	
	echo "</td><td background=../images/genbiru_09.gif></td></tr><tr>";
	echo "<td width=4 height=4><img src=../images/genhijau_10.gif width=4 height=4 /></td>";
	echo "<td height=4 background=../images/genhijau_11.gif></td><td width=4 height=4>
		<img src=../images/genhijau_12.gif width=4 height=4 /></td></tr></table>";

}


//--------------merah--------------
function genmerah($noid,$nama,$nourut,$match) {
	echo "<table width=75 height=85 border=0 cellpadding=0 cellspacing=0><tr>";
	echo "<td width=4 height=4><img src=../images/genmerah_03.gif width=4 height=4 /></td>";
	echo "<td height=4 background=../images/genmerah_04.gif></td>";
	echo "<td width=4 height=4><img src=../images/genmerah_05.gif width=4 height=4 /></td></tr>";
	echo "<tr><td background=../images/genmerah_07.gif></td>";
	echo "<td width=67 height=78 align=center valign=center background=../images/genmerah_08.gif style='font-family:Verdana, Arial, 
			Helvetica, sans-serif; font-size:9px; font-weight:bold'>";
	echo "$noid<br>$nama<br><br>$nourut<br>";
}
//-bawah---------
function genmerahbawah() {
	
	echo "</td><td background=../images/genmerah_09.gif></td></tr><tr>";
	echo "<td width=4 height=4><img src=../images/genmerah_14.gif width=4 height=4 /></td>";
	echo "<td height=4 background=../images/genmerah_15.gif></td><td width=4 height=4>
		<img src=../images/genmerah_16.gif width=4 height=4 /></td></tr></table>";

}

function memberkiri($username, $dtgl) {
	$ki="";
	//-----------cari level tertinggi-------------
	$slv="select * from upline order by level desc";
	$rlv=mysql_query($slv);
	$slev=mysql_fetch_array($rlv);
	if($slev["level"] <= 25) {
		$jmlev=$slev["level"];
	} else {
		$jmlev = 25;
	}
	//------------------- kiri -----------------
	if($dtgl == "") {
		$sqlki="select a.username, b.status from upline as a inner join banner_kanan as b on a.username=b.username where a.upline0='$username' and a.posisi='kiri'";
	} else {
		$sqlki="select a.username, b.status from upline as a inner join banner_kanan as b on a.username=b.username where a.upline0='$username' and a.posisi='kiri' $dtgl";
	}
	$rki=mysql_query($sqlki);

	$kir=mysql_fetch_row($rki);
	$adaki=mysql_num_rows($rki);
	$user=$kir[0];
	$upliki=$kir["upline0"];
	
	if ($adaki > 0)
	{

		for($i=0;$i<$jmlev;$i++)
		{
			if($dtgl == "") {
			$sql2="select a.username, b.tglaktif from upline as a inner join banner_kanan as b on a.username=b.username where a.upline$i='$user'";
			} else {
			$sql2="select a.username, b.tglaktif from upline as a inner join banner_kanan as b on a.username=b.username where a.upline$i='$user' $dtgl";
			}
			$res=mysql_query($sql2);
	
			$jml=array();
	
			$jml[$i]=mysql_num_rows($res);
			$tot=$tot+$jml[$i];
			$lv=2 + $i;
			$tal=0;
	
			$tal=$tal+$tot;

	
		}
			$totki=$tot+1;
	} else {
		$totki=0;
	}
	$ki=$totki;
	return $ki;
}
//---------------------poin
function memberkirix($username, $dtgl) {
	$ki="";
	//-----------cari level tertinggi-------------
	$slv="select * from upline order by level desc";
	$rlv=mysql_query($slv);
	$slev=mysql_fetch_array($rlv);
	if($slev["level"] <= 25) {
		$jmlev=$slev["level"];
	} else {
		$jmlev = 25;
	}
	//------------------- kiri -----------------
	if($dtgl == "") {
		$sqlki="select a.username, b.status, b.poin from upline as a inner join banner_kanan as b on a.username=b.username where a.upline0='$username' and a.posisi='kiri'";
	} else {
		$sqlki="select a.username, b.status, b.poin from upline as a inner join banner_kanan as b on a.username=b.username where a.upline0='$username' and a.posisi='kiri' $dtgl";
	}
	
	if ($adaki > 0)
	{

		for($i=0;$i<$jmlev;$i++)
		{
			if($dtgl == "") {
			$sql2="select a.username, b.tglaktif from upline as a inner join banner_kanan as b on a.username=b.username where a.upline$i='$user'";
			} else {
			$sql2="select a.username, b.tglaktif from upline as a inner join banner_kanan as b on a.username=b.username where a.upline$i='$user' $dtgl";
			}
			$res=mysql_query($sql2);
	
			$jml=array();
	
			$jml[$i]=mysql_num_rows($res);
			$tot=$tot+$jml[$i];
			$lv=2 + $i;
			$tal=0;
	
			$tal=$tal+$tot;

	
		}
			$totki=$tot+1;
	} else {
		$totki=0;
	}
	$ki=$totki;
	return $ki;
}
//-------------endpoin

//---------------------poin kanan
function memberkananx($username, $dtgl) {
	$ka="";
	//-----------cari level tertinggi-------------
	$slv="select * from upline order by level desc";
	$rlv=mysql_query($slv);
	$slev=mysql_fetch_array($rlv);
	if($slev["level"] <= 25) {
		$jmlev=$slev["level"];
	} else {
		$jmlev = 25;
	}
	
	//---------------kanan-----------
	if($dtgl == "") {
		$sqlka="select a.username, b.tglaktif, b.status from upline as a inner join banner_kanan as b on a.username=b.username where a.upline0='$username' and a.posisi='kanan'";
	} else {
		$sqlka="select a.username, b.tglaktif, b.status from upline as a inner join banner_kanan as b on a.username=b.username where a.upline0='$username' and a.posisi='kanan' $dtgl";
	}
	
	
	$rka=mysql_query($sqlka);
	$kan=mysql_fetch_array($rka);
	$adaka=mysql_num_rows($rka);
	$user2=$kan[0];
	$tot2=0;
	if ($adaka > 0)
	{
		for($j=0;$j<$jmlev;$j++)
		{
			$sql2="select a.username, b.tglaktif from upline as a inner join banner_kanan as b on a.username=b.username where a.upline$j='$user2' $dtgl";
			$res=mysql_query($sql2);
			$jml=array();
			$jml[$j]=mysql_num_rows($res);
			$tot2=$tot2+$jml[$j];
			$lv2=2 + $j;
			$tal=0;
			$tal=$tal+$tot;
		}
	
			$totka = $tot2 + 1;
	} else {
		$totka=0;
	}
	$ka=$totka;
	return $ka;
}
//-------------poin kanan


function membertengah($username, $dtgl) {
	$tg="";
	//-----------cari level tertinggi-------------
	$slv="select * from upline order by level desc";
	$rlv=mysql_query($slv);
	$slev=mysql_fetch_array($rlv);
	if($slev["level"] <= 25) {
		$jmlev=$slev["level"];
	} else {
		$jmlev = 25;
	}
	//------------------- kiri -----------------
	if($dtgl == "") {
		$sqltg="select a.username, b.status from upline as a inner join banner_kanan as b on a.username=b.username where a.upline0='$username' and a.posisi='tengah'";
	} else {
		$sqltg="select a.username, b.status from upline as a inner join banner_kanan as b on a.username=b.username where a.upline0='$username' and a.posisi='tengah' $dtgl";
	}
	$rtg=mysql_query($sqltg);

	$ktg=mysql_fetch_row($rtg);
	$adatg=mysql_num_rows($rtg);
	$user=$ktg[0];
	$uplitg=$ktg["upline0"];
	
	if ($adatg > 0)
	{

		for($i=0;$i<$jmlev;$i++)
		{
			if($dtgl == "") {
			$sql2="select a.username, b.tglaktif from upline as a inner join banner_kanan as b on a.username=b.username where a.upline$i='$user'";
			} else {
			$sql2="select a.username, b.tglaktif from upline as a inner join banner_kanan as b on a.username=b.username where a.upline$i='$user' $dtgl";
			}
			$res=mysql_query($sql2);
	
			$jml=array();
	
			$jml[$i]=mysql_num_rows($res);
			$tot=$tot+$jml[$i];
			$lv=2 + $i;
			$tal=0;
	
			$tal=$tal+$tot;

	
		}
			$tottg=$tot+1;
	} else {
		$tottg=0;
	}
	$tg=$tottg;
	return $tg;
}

//----jml member kanan-----------
function memberkanan($username, $dtgl) {
	$ka="";
	//-----------cari level tertinggi-------------
	$slv="select * from upline order by level desc";
	$rlv=mysql_query($slv);
	$slev=mysql_fetch_array($rlv);
	if($slev["level"] <= 25) {
		$jmlev=$slev["level"];
	} else {
		$jmlev = 25;
	}
	
	//---------------kanan-----------
	if($dtgl == "") {
		$sqlka="select a.username, b.tglaktif, b.status from upline as a inner join banner_kanan as b on a.username=b.username where a.upline0='$username' and a.posisi='kanan'";
	} else {
		$sqlka="select a.username, b.tglaktif, b.status from upline as a inner join banner_kanan as b on a.username=b.username where a.upline0='$username' and a.posisi='kanan' $dtgl";
	}
	
	
	$rka=mysql_query($sqlka);
	$kan=mysql_fetch_array($rka);
	$adaka=mysql_num_rows($rka);
	$user2=$kan[0];
	$tot2=0;
	if ($adaka > 0)
	{
		for($j=0;$j<$jmlev;$j++)
		{
			$sql2="select a.username, b.tglaktif from upline as a inner join banner_kanan as b on a.username=b.username where a.upline$j='$user2' $dtgl";
			$res=mysql_query($sql2);
			$jml=array();
			$jml[$j]=mysql_num_rows($res);
			$tot2=$tot2+$jml[$j];
			$lv2=2 + $j;
			$tal=0;
			$tal=$tal+$tot;
		}
	
			$totka = $tot2 + 1;
	} else {
		$totka=0;
	}
	$ka=$totka;
	return $ka;
}

//--kanan-------------
function is_odd ($n) {
	return ($n & 1);
}	

function category_name($id) {
	$sql = mysql_query("select title from categories where id='$id'") or die;
	$kat = mysql_fetch_row($sql);
	$cat = $kat[0];
	return $cat;
}	

function menu_show($pos, $catid, $m) {
	$sql = mysql_query("select id, name, link from menu where published=1 order by ordering") or die;
	
	echo "<div id=$pos><ul id=saturday>";
	while($row = mysql_fetch_row($sql)) {
		if($row[2] == "?m=home" or $row[2] == "") {
			$link = "./";
		} else {
			$link = $row[2];
		}
		//---url---
		$ul0 = array();
		$ul = explode("=", $row[2]);
		$ul0[2] = $ul[2]; //----m=content
		$ul0[1] = $ul[1];
		$ur = explode("&", $ul0[1]);
		$ur0 = $ur[0];
		if($catid == $ul0[2] && $m == $ur0 or $m == "" && $ur0 == "home") {
			$class = "class=current";
		} else {
			$class = "";
		}			
		echo "<li><a href='$link' $class>$row[1]</a></li>";
	}
	echo "</ul></div>";
}			

//-rupiah------------
function rupiah($rp)
{
	$rupiah = "";
	$p = strlen($rp);
	while($p > 3)
	{
		$rupiah = "." . substr($rp,-3) . $rupiah;
		$l = strlen($rp) - 3;
		$rp = substr($rp,0,$l);
		$p = strlen($rp);
	}
	$rupiah = "Rp. " . $rp . $rupiah . ",-";
	return $rupiah;
}

//-rupiah------------
function rupiah2($rp)
{
	$rupiah2 = "";
	$p = strlen($rp);
	while($p > 3)
	{
		$rupiah2 = "." . substr($rp,-3) . $rupiah2;
		$l = strlen($rp) - 3;
		$rp = substr($rp,0,$l);
		$p = strlen($rp);
	}
	$rupiah2 = $rp . $rupiah2;
	return $rupiah2;
}

//--make random password-----------
function makeRandomPassword() { 
          $salt = "abchefghjkmnpqrstuvwxyz0123456789"; 
          srand((double)microtime()*1000000);  
          $i = 0; 
          while ($i <= 7) { 
                $num = rand() % 33; 
                $tmp = substr($salt, $num, 1); 
                $pass = $pass . $tmp; 
                $i++; 
          } 
          return $pass; 
}

//------------upline spillover-----------
function spillover($field, $username) {
	$sql="SELECT kiri, kanan FROM upline WHERE username='$username'";
	$mq=mysql_query($sql);
	$cek=mysql_num_rows($mq);
	$ada=mysql_fetch_row($mq);
	if($ada[0] == "" or $ada[1] == "") {
		if($ada[0] == "") {
			$posisi = "KIRI";
		//} else if($ada[1] == "") {
			//$posisi = "TENGAH";
		} else {
			$posisi = "KANAN";
		}
		//echo "upline = $username<br>Posisi : $posisi<br>";
		//echo "kiri : $ada[0]<br>kanan : $ada[1]<br>";
		if($field == "random") {
			$nm="";
			$nm=$username;
			return $nm;
		}
		if($field == "pos") {
			$ps="";
	 		$ps=$posisi;
			return $ps;
		}
	} else {
		$upli=array();
		$pos=array();
		for($i=0;$i<25;$i++) {
		$sql="SELECT username, kiri, kanan FROM upline WHERE upline$i='$username'";
		$mq=mysql_query($sql);
		$cek=mysql_num_rows($mq);
		while($ada=mysql_fetch_row($mq)) {
			if($ada[1] == "" or $ada[2] == "" ) {
			if($ada[1] == "") {
				$posisi = "KIRI";
			//} else if($ada[2] == "") {
				//$posisi = "TENGAH";
			} else {
				$posisi = "KANAN";
			}
	//echo "upline$i = $ada[0]<br>Posisi : $posisi<br>";
	//echo "kiri : $ada[1]<br>kanan : $ada[2]<br>";
			$upli[]=$ada[0];	
			$pos[]=$posisi;
		}
	}
	//echo "upline$i = $ada[0]<br>Posisi : $posisi<br>";

	}
	if($field == "random") {
		$nm="";
		$nm=$upli[0];
		return $nm;
	}
	if($field == "pos") {
		$ps="";
	 	$ps=$pos[0];
		return $ps;
	}
	}
		mysql_free_result($mq);
}
//---------tgl expire----------
function formatgl($tgaktif) {
	$tg = "";
	//$tgaktif = date("Y-m-d"); 
	$hari=array("Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu");
	$bulane = array("Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember");
	$expire = date("w, d m Y",strtotime($tgaktif)); 
//$showexp = date("w n d Y",time() + (7776000/3)); 
	$day = substr($expire, 0, 1);
	$tgle = substr($expire, 3,2);
	$blne = substr($expire, 6,2);
	$thne = substr($expire, 9,4);
	if($blne < 10 ) {
		$blne0 = substr($blne, 1,1) - 1;
	} else {
		$blne0 = $blne - 1;
	}
	$tg =  "$hari[$day], $tgle $bulane[$blne0] $thne";
	return $tg;
}

//---jml member per level--
function jmlmember($username, $dtgl) {
	$jm = 0;
	$jm = memberkiri($username, $dtgl) + memberkiri($username, $dtgl);
	return $jm;
}	

function warning($text) {
	echo "<div id='warning'><p align=center>$text</p></div>";
}	
function kwitansi() {
	$ko = 0;
	$sql = mysql_query("select kode from kwitansi order by kode desc");
	if(mysql_num_rows($sql) == 0) {
		$ko = 100123;
	} else {	
		$data = mysql_fetch_row($sql);
		$ko = $data[0] + 1;
	}	
	return $ko;
}	
?>