<?php
if (basename($_SERVER['SCRIPT_FILENAME']) == basename(__FILE__)){
echo "<p align=center><br><br><br><br><br><br><font size=\"6\" color=\"#FF0000\">ILLEGAL ACCESS !!";
echo "<meta http-equiv=\"refresh\" content=\"2; url=../index.php\">";
exit();} 
?>
<?php
if (empty($_SESSION["valid_admin"])){
echo "<p align=center><br><br><br><br><br><br><font size=\"6\" color=\"#FF0000\">ILLEGAL ACCESS !!";
echo "<meta http-equiv=\"refresh\" content=\"2; url=../../index.php\">";
exit();}
?>
<?php
	/* 
	############################[  <about> ] #######################
		S Name   ::       Inv-X Primadesain
		Update   ::       2013 © Primadesain.Com
		Author   ::       Agus Susanto S.kom
		Website  ::		  http://primadesain.com
		Contact  ::		  <primapc57@gmail.com> // +62 85228657360
	
	Primadesain melayani pembuatan website MLM dan Investasi
	( dengan sistem binary, trinary atau matrix dan matahari )
	juga menerima pembuatan website Iklan Baris, Website Profile,
	Reseller, Hyip, dll.
	############################[ </about> ] #######################
	*/
?>
<script type="text/javascript">
<!--
function confirmation(noid) {
	var answer = confirm("Are You sure to delete this record ?")
	if (answer){
		//alert("Bye bye!")
		window.location = "?go=dtreward&page=konfirm&id=$id";
		
	}
	
}
//-->
</script>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>

<h2><img src="images/icon-48-user.png" width="48" height="48" align="absmiddle" /> Reward </h2>
<div id="menu_button2"></div>


<?
if (isset($_GET['page']) && $_GET['page'] == "history") {
?>
<?
  	//---pagination----------------
$limit = '50'; // How many results should be shown at a time
$scroll = '0'; // Do you want the scroll function to be on (1 = YES, 2 = NO)
$scrollnumber = '50'; // How many elements to the record bar are shown at a time when the scroll function is on
//-------------pagination--------------
if (!isset ($_GET['show'])) {

	$display = 1;
	
} else {

	$display = $_GET['show'];
	
}
$start = (($display * $limit) - $limit);


//if($uidm == 001) {

//$db->select("*", "member", $kat);
	$numrows = $db->count_records("rewardx", "");	
	$db->select("id, kode, username, reward, peringkat, tglbayar, status", "rewardx", "", "", "", "", "$start, $limit");
 ?> 
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
  <tr class="tbl_header">
    <td width="6%" align="center"><strong>No.</strong></td>
    <td width="12%" align="center"><strong>Tanggal</strong></td>
    <td width="11%" align="center"><strong>Username</strong></td>
    <td width="15%" align="center"><strong>Nama</strong></td>
	<td width="14%" align="center"><strong>Peringkat</strong></td>
	<td width="15%" align="center"><strong>Reward</strong></td>
	 <td width="9%" align="center"><strong>Status</strong></td>
	 <td width="9%" align="center"><strong>Hapus</strong></td>
  </tr>	
<?php
$j=$db->num_rows();
for($i=0;$i<$j;$i++) {
	$nom = $i + 1 + $start;
	$lid = $i - 1;
	if(is_odd($i) == 0) {
		$class = "tblrow_ganjil";
	} else {
		$class = "tblrow_genap";
	} 	
	if($db->result($i, "status") > 0) {
		$img = "<img src='../images/valid.png'/>";
	} else {
		$img = "<img src='../images/error.png'/>";
	}
	$id = $db->result($i, "id");
	$mid = $db->result($i, "username");
	$kode = $db->result($i, "kode");
	$reward = $db->result($i, "reward");
	$peringkat = $db->result($i, "peringkat");
	$tt = date('d-m-Y', strtotime($db->result($i, "tglbayar")));
?> 	

  <tr class="<?= $class; ?>">
     <td width="6%" align="center"> <?php echo $nom; ?></td>
	 <td width="15%" align="center"><?= $tt; ?></td>
   
    <td  align="center"><?= $mid; ?></td>
	 <td  align="center"><?= $db->dataku("nama", $mid); ?></td>
	 <td  align="center"><?= $peringkat; ?></td>
	 <td  align="center"><?= $reward; ?></td>
	 <td  align="center"><?= $img; ?></td>
	 <td  align="center"> <a href="?go=dtreward&page=delete&id=<?= $id; ?>&kode=<?= $kode; ?>&mid=<?= $mid; ?>" onclick="return confirm('PERHATIAN: Menghapus data ini akan menghapus reward yang telah diberikan !! Yakin akan menghapus data ini ?? ');"><img src="images/icon-32-delete_resize.png" width="17" height="22" border="0" title="HAPUS DATA" /></a></td>

 
  </tr>
<?
 $nom++;
 }

 
 ?>  
</table>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0">
  <tr>
    <td align="center">
     <?php

//}
//

$paging = ceil ($numrows / $limit);

// Display the navigation
if ($display > 1) {
	
	$previous = $display - 1;
	
?>
  <a href="?go=dtreward&page=history&kat=<?php echo $kat; ?>&show=1" style="font-size:10px; color:#0000CC"><< Awal </a> | <a href="?go=dtreward&page=history&kat=<?php echo $kat; ?>&show=<?php echo $previous; ?>" style="font-size:10px; color:#0000CC">< Sebelumnya </a> |
  <?php

}

if ($numrows != $limit) {
	
	if ($scroll == 1) {
	
		if ($paging > $scrollnumber) {
			
			$first = $display;
			
			$last = ($scrollnumber - 1) + $display;
			
		}
	
	} else {
	
		$first = 1;
			
		$last = $paging;
			
	}
	
	if ($last > $paging ) {
			
		$first = $paging - ($scrollnumber - 1);
			
		$last = $paging;
			
	}
	
	for ($i = $first;$i <= $last;$i++){
		
		if ($display == $i) {
			
?>
[ <b>
<?php echo $i ?>
</b> ]
<?php
			
		} else {
			
?>
[ <a href="?go=dtreward&page=history&kat=<?php echo $kat; ?>&show=<?php echo $i; ?>" style="font-size:10px; color:#0000CC">
<?php echo $i; ?>
</a> ]
<?php
		
		}
	
	}

}

if ($display < $paging) {

	$next = $display + 1;
	
?>
| <a href="?go=dtreward&page=history&kat=<?php echo $kat; ?>&show=<?php echo $next; ?>" style="font-size:10px; color:#0000CC">Selanjutnya ></a> | <a href="?go=dtreward&page=history&kat=<?php echo $kat; ?>&show=<?php echo $paging; ?>" style="font-size:10px; color:#0000CC">Terakhir >></a>
<?php

}
//
?>
    </td>
  </tr>
</table>

<?
} else if (isset($_GET['page']) && $_GET['page'] == "delete") {

if(isset($_GET["id"])){ $no = $_GET["id"]; }
if(isset($_GET["kode"])){ $kode = $_GET["kode"]; }
if(isset($_GET["mid"])){ $mid = $_GET["mid"]; }

$statsmmx = $db->dataku("statrwd", $mid);
$sql2="SELECT poin FROM wd_reward WHERE kode='$kode'"; 
$dt2=mysql_query($sql2);
$config2=mysql_fetch_array($dt2);
$batas = $config2['poin'];
$nwstts = $statsmmx - $batas;
		
	$db->delete("wd_reward", "kode=$kode");
	$db->delete("rewardx", "kode=$kode");
	$db->update("member", "statrwd='$nwstts'", "username='$mid'");
	
	echo "<meta http-equiv='refresh' content='0;URL=?go=dtreward&page=history'>";


} else {
?>
<?
//---pagination----------------
$limit = '50'; // How many results should be shown at a time
$scroll = '0'; // Do you want the scroll function to be on (1 = YES, 2 = NO)
$scrollnumber = '50'; // How many elements to the record bar are shown at a time when the scroll function is on
//-------------pagination--------------
if (!isset ($_GET['show'])) {

	$display = 1;
	
} else {

	$display = $_GET['show'];
	
}
$start = (($display * $limit) - $limit);


//if($uidm == 001) {

//$db->select("*", "member", $kat);
if($Submit == "CARI") {
	$filter = "nama like '%$keywrd%' or username like '%$keywrd%'";
	$where = "nama like '%$keywrd%' or username like '%$keywrd%'";
} else {
	
	$filter = "status=$kat";
	$where = "status=$kat";
}
//---
if($kat > 0 or !$kat) {
	$order = "tgl asc";
} else {
	$order = "tglaktif asc";
}		
if($kat == "") {
	$numrows = $db->count_records("member", "status=1");
	$db->select("id, username, nama, sponsor, email, kota, tgl, status", "member", "status=1", $order, "", "", "$start, $limit");

	
} else {
	$numrows = $db->count_records("member", "status=$kat");	
	$db->select("id, username, nama, sponsor, email, kota, tgl, status", "member", $where, $order, "", "", "$start, $limit");
}
$sel = "selected";





?>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td colspan="12" align="center" style="padding:0"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="padding:0; margin:0">
      <tr>
        <td></td>
      </tr>
    </table></td>
  </tr>
  <tr class="tbl_header">
    <td width="5%" align="center">#</td>
    <td width="9%" align="center">Username</td>
    <td width="17%" align="center">Nama Lengkap</td>
    <td width="11%" align="center">Member Kiri </td>
    <td width="12%" align="center">Member Kanan  </td>
    <td width="19%" align="center">Point Diambil</td>
	
  </tr>
  <?


$j=$db->num_rows();
for($i=0;$i<$j;$i++) {
	$nom = $i + 1 + $start;
	$lid = $i - 1;
	if(is_odd($i) == 0) {
		$class = "tblrow_ganjil";
	} else {
		$class = "tblrow_genap";
	} 
		
	if($db->result($i, "status") > 0) {
		$aktif = "<a href='#' onclick=\"confirmation('".$db->result($i, "username")."', 'activation', 'Disable')\" style='cursor:hand'><img src='images/icon-16-checkin.png' title='Change to Disable' border=0 /></a>";
	} else {
		$aktif = "<a href='#' onclick=\"confirmation('".$db->result($i, "username")."', 'activation', 'Activated')\" style='cursor:hand'><img src='images/publish_x.png' title='Change to Active Member' border=0 /></a>";
	}
	if($db->result($i, "blokir") > 0) {
		$blokir = "<a href='#' onclick=\"confirmation('".$db->result($i, "username")."', 'blokir', 'UnBlocked')\" style='cursor:hand'><img src='images/icon-16-checkin.png' title='Change to Enable/UnBlocked' border=0 /></a>";
	} else {
		$blokir = "<a href='#' onclick=\"confirmation('".$db->result($i, "username")."', 'blokir', 'Blocked')\" style='cursor:hand'><img src='images/publish_x.png' title='Click here to Blocked this Member' border=0 /></a>";
	}
?>
<? 
$mide=$db->result($i, "username");
$rwww="SELECT peringkat2 FROM configuration"; 
$dtrwww=mysql_query($rwww);
$configrwww=mysql_fetch_array($dtrwww);
$batasrwd = explode("|", $configrwww['peringkat2']);
$rankrwd = explode("|", $configrwww['peringkat2']);
$rewardrwd = explode("|", $configrwww['peringkat2']);

$batasrwx1 = $batasrwd[0]; 
$batasrwx2 = $batasrwd[4]; 
$batasrwx3 = $batasrwd[8]; 
$batasrwx4 = $batasrwd[12]; 
$batasrwx5 = $batasrwd[16];
$batasrwx6 = $batasrwd[20];

$rankrwx1 = $rankrwd[1]; 
$rankrwx2 = $rankrwd[5]; 
$rankrwx3 = $rankrwd[9]; 
$rankrwx4 = $rankrwd[13]; 
$rankrwx5 = $rankrwd[17]; 
$rankrwx6 = $rankrwd[21]; 

$rewardx1 = $rewardrwd[2]; 
$rewardx2 = $rewardrwd[6]; 
$rewardx3 = $rewardrwd[10]; 
$rewardx4 = $rewardrwd[14]; 
$rewardx5 = $rewardrwd[18]; 
$rewardx6 = $rewardrwd[22]; 


$sql_rwd1 = mysql_query("select * from wd_reward where username='".$mide."' and jenis='1'");
$ada_rwd1 = mysql_num_rows($sql_rwd1);
$rowcrwd1 = mysql_fetch_array($sql_rwd1);
if($ada_rwd1 > 0){
$point1 = $rowcrwd1['pointreward'];
$status1="<img src='../images/tick.png' width='16' height='16' />";
} else {
$point1 = "";
$status1="<img src='../images/publish_x.png' width='16' height='16' />";
}

$sql_rwd2 = mysql_query("select * from wd_reward where username='".$mide."' and jenis='2'");
$ada_rwd2 = mysql_num_rows($sql_rwd2);
$rowcrwd2 = mysql_fetch_array($sql_rwd2);
if($ada_rwd2 > 0){
$point2 = $rowcrwd2['pointreward'];
$status2="<img src='../images/tick.png' width='16' height='16' />";
} else {
$point2 = "";
$status2="<img src='../images/publish_x.png' width='16' height='16' />";
}

$sql_rwd3 = mysql_query("select * from wd_reward where username='".$mide."' and jenis='3'");
$ada_rwd3 = mysql_num_rows($sql_rwd3);
$rowcrwd3 = mysql_fetch_array($sql_rwd3);
if($ada_rwd3 > 0){
$point3 = $rowcrwd3['pointreward'];
$status3="<img src='../images/tick.png' width='16' height='16' />";
} else {
$point3 = "";
$status3="<img src='../images/publish_x.png' width='16' height='16' />";
}

$sql_rwd4 = mysql_query("select * from wd_reward where username='".$mide."' and jenis='4'");
$ada_rwd4 = mysql_num_rows($sql_rwd4);
$rowcrwd4 = mysql_fetch_array($sql_rwd4);
if($ada_rwd4 > 0){
$point4 = $rowcrwd4['ppointrewardoint'];
$status4="<img src='../images/tick.png' width='16' height='16' />";
} else {
$point4 = "";
$status4="<img src='../images/publish_x.png' width='16' height='16' />";
}

$sql_rwd5 = mysql_query("select * from wd_reward where username='".$mide."' and jenis='5'");
$ada_rwd5 = mysql_num_rows($sql_rwd5);
$rowcrwd5 = mysql_fetch_array($sql_rwd5);
if($ada_rwd5 > 0){
$point5 = $rowcrwd5['pointreward'];
$status5="<img src='../images/tick.png' width='16' height='16' />";
} else {
$point5 = "";
$status5="<img src='../images/publish_x.png' width='16' height='16' />";
}
$sql_rwd6 = mysql_query("select * from wd_reward where username='".$mide."' and jenis='6'");
$ada_rwd6 = mysql_num_rows($sql_rwd6);
$rowcrwd6 = mysql_fetch_array($sql_rwd6);
if($ada_rwd6 > 0){
$point6 = $rowcrwd6['pointreward'];
$status6="<img src='../images/tick.png' width='16' height='16' />";
} else {
$point6 = "";
$status6="<img src='../images/publish_x.png' width='16' height='16' />";
}
$sql_rwd7 = mysql_query("select * from wd_reward where username='".$mide."' and jenis='7'");
$ada_rwd7 = mysql_num_rows($sql_rwd7);
$rowcrwd7 = mysql_fetch_array($sql_rwd7);
if($ada_rwd7 > 0){
$point7 = $rowcrwd7['pointreward'];
$status7="<img src='../images/tick.png' width='16' height='16' />";
} else {
$point7 = "";
$status7="<img src='../images/publish_x.png' width='16' height='16' />";
}

$pointnya = $point1+$point2+$point3+$point4+$point5+$point6+$point7;

$memberix = memberL1($mide);
$membernanx = memberL2($mide);
$memberi = $memberix - $pointnya;
$membernan = $membernanx - $pointnya;
if($memberi > 0){
	$sldmemberi = $memberi;
}else{
	$sldmemberi = "---";
}
if($membernan > 0){
	$sldmembera = $membernan;
}else{
	$sldmembera = "---";
}
if($pointnya > 0){
	$pointnyac = $pointnya;
}else{
	$pointnyac = "---";
}

if($memberi >= $batasrwx1 && $membernan >= $batasrwx1 && $memberi < $batasrwx2 && $membernan < $batasrwx2){
$qualy1="Qualified";
$reward1=$rewardx1;
$ambil1= "<a class='btn btn-sm green' href='index.php?go=withdrawlreward'><i class='fa fa-check'></i>&nbsp;Get Reward</a>";
} else {
$qualy1="Belum Qualified";
$reward1="---";
$ambil1= "---";
}
if($memberi >= $batasrwx2 && $membernan >= $batasrwx2 && $memberi < $batasrwx3 && $membernan < $batasrwx3){
$qualy2="Qualified";
$reward2=$rewardx2;
$ambil2= "<a class='btn btn-sm green' href='index.php?go=withdrawlreward'><i class='fa fa-check'></i>&nbsp;Get Reward</a>";
} else {
$qualy2="Belum Qualified";
$reward2="---";
$ambil2= "---";
}
if($memberi >= $batasrwx3 && $membernan >= $batasrwx3 && $memberi < $batasrwx4 && $membernan < $batasrwx4){
$qualy3="Qualified";
$reward3=$rewardx3;
$ambil3= "<a class='btn btn-sm green' href='index.php?go=withdrawlreward'><i class='fa fa-check'></i>&nbsp;Get Reward</a>";
} else {
$qualy3="Belum Qualified";
$reward3="---";
$ambil3= "---";
}
if($memberi >= $batasrwx4 && $membernan >= $batasrwx4 && $memberi < $batasrwx5 && $membernan < $batasrwx5){
$qualy4="Qualified";
$reward4=$rewardx4;
$ambil4= "<a class='btn btn-sm green' href='index.php?go=withdrawlreward'><i class='fa fa-check'></i>&nbsp;Get Reward</a>";
} else {
$qualy4="Belum Qualified";
$reward4="---";
$ambil4= "---";
}
if($memberi >= $batasrwx5 && $membernan >= $batasrwx5 && $memberi < $batasrwx6 && $membernan < $batasrwx6){
$qualy5="Qualified";
$reward5=$rewardx5;
$ambil5= "<a class='btn btn-sm green' href='index.php?go=withdrawlreward'><i class='fa fa-check'></i>&nbsp;Get Reward</a>";
} else {
$qualy5="Belum Qualified";
$reward5="---";
$ambil5= "---";
}
if($memberi >= $batasrwx6 && $membernan >= $batasrwx6 && $memberi < $batasrwx7 && $membernan < $batasrwx7){
$qualy6="Qualified";
$reward6=$rewardx6;
$ambil6= "<a class='btn btn-sm green' href='index.php?go=withdrawlreward'><i class='fa fa-check'></i>&nbsp;Get Reward</a>";
} else {
$qualy6="Belum Qualified";
$reward6="---";
$ambil6= "---";
}
if($memberi >= $batasrwx7 && $membernan >= $batasrwx7){
$qualy7="Qualified";
$reward7=$rewardx7;
$ambil7= "<a class='btn btn-sm green' href='index.php?go=withdrawlreward'><i class='fa fa-check'></i>&nbsp;Get Reward</a>";
} else {
$qualy7="Belum Qualified";
$reward7="---";
$ambil7= "---";
}


			 
	
?>

  <tr class="<?= $class; ?>">
    <td width="5%" align="center"><?= $nom; ?>    </td>
    <td width="9%" align="center">
      <?= $db->result($i, "username"); ?>    </td>
    <td align="center">
       <?= $db->result($i, "nama"); ?>
    </td>
   
    <td align="center">
	<?= $sldmemberi; ?>
	</td>
    <td align="center">
	<?= $sldmembera; ?>
	</td>
    <td align="center">
	<?= $pointnyac; ?>
</td>
 
  </tr>
  <?
	}
?>
</table>
<br />
<div id="keterangan">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td align="center">
     <?php

//}
//

$paging = ceil ($numrows / $limit);

// Display the navigation
if ($display > 1) {
	
	$previous = $display - 1;
	
?>
  <a href="?go=dtreward&kat=<?= $kat; ?>&show=1" style="font-size:10px; color:#0000CC"><< Awal </a> | <a href="?go=dtreward&kat=<?= $kat; ?>&show=<?= $previous; ?>" style="font-size:10px; color:#0000CC">< Sebelumnya </a> |
  <?php

}

if ($numrows != $limit) {
	
	if ($scroll == 1) {
	
		if ($paging > $scrollnumber) {
			
			$first = $display;
			
			$last = ($scrollnumber - 1) + $display;
			
		}
	
	} else {
	
		$first = 1;
			
		$last = $paging;
			
	}
	
	if ($last > $paging ) {
			
		$first = $paging - ($scrollnumber - 1);
			
		$last = $paging;
			
	}
	
	for ($i = $first;$i <= $last;$i++){
		
		if ($display == $i) {
			
?>
[ <b>
<?= $i ?>
</b> ]
<?php
			
		} else {
			
?>
[ <a href="?go=dtreward&kat=<?= $kat; ?>&show=<?= $i; ?>" style="font-size:10px; color:#0000CC">
<?= $i; ?>
</a> ]
<?php
		
		}
	
	}

}

if ($display < $paging) {

	$next = $display + 1;
	
?>
| <a href="?go=dtreward&kat=<?= $kat; ?>&show=<?= $next; ?>" style="font-size:10px; color:#0000CC">Selanjutnya ></a> | <a href="?go=dtreward&kat=<?= $kat; ?>&show=<?= $paging; ?>" style="font-size:10px; color:#0000CC">Terakhir >></a>
<?php

}
//
?>
    </td>
  </tr>
</table>
<p>&nbsp;</p>
<?php } ?>