<script type="text/javascript">
<!--
function confirmation(mid, page, action) {
	var answer = confirm("Process Transfer E-walet to this Member: " + mid + " ?")
	if (answer){
		//alert("Bye bye!")
		window.location = "?m=ewalet&page=" + page + "&mid=" + mid + "&action=" + action;
		
	}
	
}
//-->
</script>

<h2><img src="images/icon-48-article.png" width="48" height="48" align="absmiddle"> Order </h2>
<div id="menu_button2"><a href="?m=ewalet&amp;page=saldo"></a>
  <?
switch($page) {
	default :
	
		//---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("banner_bawah", $dtgl);	
	$db->select("a.id, a.username, a.status, b.nama", "banner_bawah as a inner join member as b on a.username=b.username", $dtgl, "username", "", "", "$start, $limit");

?>
</div>
<table width="70%" border="0" align="center" cellpadding="5" cellspacing="0">
  <tr class="tbl_header">
    <td width="6%" align="center">No.</td>
    <td width="39%" align="center">Username</td>
    <td width="26%" align="center">Nama </td>
    <td width="29%" align="center">Balance</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";
	} 	
	$username = $db->result($i, "username");
	//$nama = $db->result($i, "nama");
	$bl0 = $bulan - 1;
	$jam = date("H:i:s");
	
	
	
?>
  <tr class="<?= $class; ?>">
    <td width="6%" align="center"><?= $nom; ?>    </td>
    <td width="39%"><?= $db->result($i, "username"); ?></td>
    <td width="26%"><?= $db->result($i, "nama"); ?></td>
    <td align="right"><?= rupiah($db->myewalet($username)); ?></td>
  </tr>
  <?
	
	}
?>
</table>
<br />
<table width="80%" 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="?m=ewalet&show=1" style="font-size:10px; color:#0000CC"><< Awal </a> | <a href="?m=ewalet&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="?m=ewalet&show=<?= $i; ?>" style="font-size:10px; color:#0000CC">
<?= $i; ?>
</a> ]
<?php
		
		}
	
	}

}

if ($display < $paging) {

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

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

  <?
	break;
	
	case addfund :
	//---tgl mbr pertama aktif--
	$db->select("tglaktif", "member", "status=1", "tglaktif asc");
	$data = $db->fetch_row();
	$dtfrom = $data[0];
	$dtto = date("Y-m-d H:i:s");
	$sa = $db->saldoadmin("(tgl between '$dtfrom' and '$dtto')");
		if( isset($_POST['submit'])) {
			//---cek jml transfer----
			if($jumlah > $sa) {
				$err = "<span style='color:#FF0000'><b>Saldo Anda tidak mencukupi! Klik CANCEL untuk mengulang!</b></span>";
				$dis = "disabled";
			}	
	?>


  <form id="form2" name="form2" method="post" action="?m=ewalet&amp;page=kirim">
    <table width="80%" border="0" align="center" cellpadding="4" cellspacing="0" class="bordertable">
      <tr class="tbl_header">
        <td colspan="2" align="center">KONFIRMASI TRANSFER</td>
      </tr>
      <tr>
        <td width="50%" align="right" valign="top">E-walet Tujuan :</td>
        <td width="50%"><strong>
          <?= $tujuan; ?>
          <input name="tujuan" type="hidden" id="tujuan" value="<?= $tujuan; ?>" size="15" />
        </strong></td>
      </tr>
      <tr>
        <td width="50%" align="right" valign="top">Jumlah transfer :</td>
        <td width="50%"><strong>
          <?= rupiah($jumlah)." $err"; ?>
          <input name="jumlah" type="hidden" id="jumlah" value="<?= $jumlah; ?>" size="15" />
        </strong></td>
      </tr>
      <tr>
        <td width="50%" align="right" valign="top">Keterangan :</td>
        <td width="50%"><strong>
          <input name="ket" type="hidden" id="ket" value="<?= $ket; ?>" size="15" />
          </strong>
            <?= $ket; ?></td>
      </tr>

      <tr>
        <td colspan="2" align="center"><input type="submit" name="submit2" value="TRANSFER E-WALET" class="tombole" id="submit2" <?= $dis; ?>/>
            <input type="button" name="button" id="button" value="CANCEL" onclick="javascript:history.go(-1)" />        </td>
      </tr>
    </table>
  </form>
  <?
 	
 } else {
 ?>
<p>&nbsp;</p>
<form id="ewalet" name="form1" method="post" action="">
  <table width="80%" border="0" align="center" cellpadding="5" cellspacing="0" class="bordertable">
    <tr>
      <td colspan="2" align="center"><div class="ewalet">Saldo admin : <span>
        <?= rupiah($sa); ?>
      </span></div></td>
    </tr>
    <tr class="tbl_header">
      <td colspan="2" align="center">ADD FUND E-WALET</td>
    </tr>
    <tr>
      <td width="50%" align="right">Username E-walet tujuan :</td>
      <td width="50%"><label>
        <select name="tujuan" id="tujuan">
     <?
	 	$db->select("nama, username", "member", "status=1 and paket=1", "username");
		while($row=$db->fetch_row()) {
			echo "<option value='$row[1]'>$row[1] ($row[0])</option>";
		}
		?>	
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right">Jumlah dana :</td>
      <td><input name="jumlah" type="text" id="jumlah" size="10" /></td>
    </tr>
    <tr>
      <td align="right" valign="top">Catatan :</td>
      <td><textarea name="ket" cols="40" rows="5" id="ket"></textarea></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><label>
        <input type="submit" name="submit" id="submit" value="TRANSFER" />
      </label></td>
    </tr>
    <tr>
      <td align="right">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
  <script language="JavaScript" type="text/javascript">
 var frmvalidator = new Validator("ewalet");
 frmvalidator.addValidation("jumlah","req","Berapa jumlah yang akan ditransfer?");
 


</script>  
<p>&nbsp;</p>
<p>
  <?
  }
  	break;
	
	case kirim :
	
			$kode = kwitansi();
			//$mastere = $valid_admin
			$db->insert("banner_kiri", "", "'', '$kode', '$valid_admin-1', '$jumlah', '$ket', '$tujuan', '$clientdate', 1"); 		
			$db->insert("transaksi", "", "'', '$kode', '$mid', '$jumlah', '$clientdate', '$ket untuk $tujuan', 1");
			$db->insert("kwitansi", "", "'', '$kode', '$ket', '$clientdate'");
	?>
<table width="80%" border="0" align="center" cellpadding="5" cellspacing="0" class="bordertable">
      <tr class="tbl_header">
        <td colspan="2" align="center" style="color:#FF0000">ADD FUND  E-WALET SUCCESS!</td>
      </tr>
      <tr>
        <td align="right">Nomor kwitansi :</td>
        <td><strong>
        <?= $kode; ?>
        </strong></td>
      </tr>
      <tr>
        <td width="50%" align="right">Username E-walet tujuan: </td>
        <td width="50%"><strong>
          <?= $tujuan; ?>
        </strong></td>
      </tr>
      <tr>
        <td align="right">Jumlah ditransfer: </td>
        <td><strong><?= rupiah($jumlah); ?></strong></td>
      </tr>
      <tr>
        <td align="right">Keterangan :</td>
        <td><?= $ket; ?></td>
      </tr>
      <tr>
        <td colspan="2" align="center"><strong>Telah berhasil ditransfer!</strong></td>
      </tr>
      <tr>
        <td colspan="2" align="center">&nbsp;</td>
      </tr>
</table>
    <p>&nbsp;</p>
    
    <?
			
	break;
	case 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);
		
?>
  </p>
  <h4 align="center">HISTORY TRANSAKSI</h4>
  <form action="" method="post" name="form1" id="form3">
    <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0">
      <tr>
        <td width="17%">Transaksi Bulan </td>
        <td width="83%"><? 
		//tglbl(); 
		$thn=substr($clientdate, 0, 4);
	$bln=substr($clientdate, 5, 2);
	$tgl=substr($clientdate, 8, 2);
	if(!$bulan && !$tahun) {
		$bulan = $bln;
		$tahun = $thn;
	}	
		echo "<select name=bulan size=1 class=form>";
	$bulan0=array("Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember");
	$jbln=count($bulan0);
	if($bulan =="") {
		$bulan2 = $bln;
	} else {
		$bulan2 = $bulan;
	}
	for($b=0;$b<$jbln;$b++) {
		if($bulan2-1 == $b) {
			$pil="selected";
			} else {
			$pil="";
			}
			if($b+1 < 10) {
			$k2=$b+1;
			$k="0$k2";
			} else {
				$k=$b+1;
			}
		echo "<option value=$k $pil>$bulan0[$b]</option>";
	}
	echo "</select>";
	echo "<select name=tahun size=1 class=form>";
//$bulan=array("Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember");
	$jthn=15;
	for($t=8;$t<$jthn;$t++) {
		$thn2 = 2012 + $t;	
		if($tahun == $thn2) {
			$pil="selected";
			} else {
			$pil="";
			}
		
		echo "<option value='200$t' $pil>$thn2</option>";
	}
	echo "</select>";
	$tgaktif = $db->dataku("tglaktif", $user_session); 
	//$dtfrom0 = $tgaktif; 
	//$dtto0 = "$tahun-$bl0-31 23:59:59";
	$dtfrom = "$tahun-$bulan-01 00:00:00";
	$dtto = "$tahun-$bulan-31 00:00:00";
		
		?>
            <input type="submit" name="Submit2" value="LIHAT HISTORY" class="tombol" />
        </td>
      </tr>
    </table>
  </form>
  <table width="90%" border="0" align="center" cellpadding="5" cellspacing="0" class="bordertable">
<tr class="tbl_header">
            <td align="center">NO.</td>
            
            <td align="center">NO. TRANSAKSI</td>
            <td align="center">TANGGAL</td>
            <td align="center">USERNAME</td>
            <td align="center">JUMLAH</td>
            <td align="center">URAIAN</td>
</tr>
<?
	$numrows = $db->count_records("banner_kiri", "(tgl between '$dtfrom' and '$dtto')");	
	$db->select("kode, uraian, username, jumlah, tujuan, tgl", "banner_kiri", "(tgl between '$dtfrom' and '$dtto')", "id desc", "", "", "$start, $limit");
	$ada = $db->num_rows();
	if($ada > 0) {
		$nom=1 + $start;
		while($row=$db->fetch_row()) {
			if($row[4] == $row[2]) {
				$ket = "$row[1]";
			} else {
				$ket = 	"$row[1]";
			}
			if(is_odd($nom) == 0) {
				$class = "tblrow_ganjil";
			} else {
				$class = "tblrow_genap";
			} 	
			if($row[2] == "admin-1") {
				$user = "admin";
			} else {
				$user = $row[2];
			}		
?>
          <tr class="<?= $class; ?>">
            <td width="4%" align="right"><?= $nom; ?>.</td>
            <td width="12%" align="center"><?= $row[0]; ?></td>
            <td width="10%" align="center"><?= date("d-m-Y", strtotime($row[5])); ?></td>
            
            <td width="14%"><?= $user; ?></td>
            <td width="14%" align="right"><?= rupiah($row[3]); ?></td>
            <td width="46%"><?= $ket; ?></td>
</tr>
	<?
		$nom++;
		}
	} else {
	?>
    	<tr class="<?= $class; ?>">
            <td colspan="6" align="center"><strong>Belum ada data transaksi bulan ini.</strong></td>
    </tr>
	<?
	}
	?>
</table>
  <br />
<table width="80%" 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="?m=ewalet&page=history&show=1" style="font-size:10px; color:#0000CC"><< Awal </a> | <a href="?m=ewalet&page=history&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="?m=ewalet&page=history&show=<?= $i; ?>" style="font-size:10px; color:#0000CC">
<?= $i; ?>
</a> ]
<?php
		
		}
	
	}

}

if ($display < $paging) {

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

}
//
?>
    </td>
  </tr>
</table>
	
	
<p>
  <?
		
	break;	
	
	case saldo :
?>	  
</p>
<h4 align="center">TRANSAKSI</h4>
<table width="1000" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#000000" class="bordertable">
  <tr bgcolor="#FFFF33" class="tbl_header">
    <td align="center"><strong>NO.</strong></td>
    <td align="center"><strong>TANGGAL</strong></td>
    <td align="center"><strong>USERNAME</strong></td>
    <td align="center"><strong>JUMLAH</strong></td>
    <td align="center"><strong>URAIAN</strong></td>
    <td align="center"><strong>STATUS</strong></td>
  </tr>
  <?
	$numrows = $db->count_records("banner_kiri");	
	$db->select("kode, uraian, username, jumlah, tujuan, tgl,status", "banner_kiri", "tujuan='admin'", "id desc");
	$ada = $db->num_rows();
	if($ada > 0) {
		$nom=1 + $start;
		while($row=$db->fetch_row()) {
			if($row[4] == $row[2]) {
				$ket = "$row[1]";
			} else {
				$ket = 	"$row[1]";
			}
			if(is_odd($nom) == 0) {
				$class = "tblrow_ganjil";
			} else {
				$class = "tblrow_genap";
			} 	
			if($row[2] == "admin-1") {
				$user = "admin";
			} else {
				$user = $row[2];
			}	
			if($row[6] > 0) {
				$st = "DONE";
			} else {
				$st = "<a href=#  onclick=\"confirmation('$row[2]', 'proses', '$row[0]')\">PENDING</a>";
			}		
?>
  <tr class="<?= $class; ?>">
    <td width="4%" align="right"><?= $nom; ?>
      .</td>
    <td width="10%" align="center"><?= date("d-m-Y", strtotime($row[5])); ?></td>
    <td width="11%"><div align="center">
      <?= $user; ?>
    </div></td>
    <td width="15%" align="right"><div align="center">
      <?= rupiah($row[3]); ?>
    </div></td>
    <td width="39%"><div align="center">
      <?= $ket; ?>
    </div></td>
    <td width="10%"><div align="center">
      <?= $st; ?>
    </div></td>
  </tr>
  <?
		$nom++;
		}
	} else {
	?>
  <tr class="<?= $class; ?>">
    <td colspan="6" align="center"><strong>Belum ada data transaksi bulan ini.</strong></td>
  </tr>
  <?
	}
	?>
</table>
<?
	break;
	
	case proses :
	    $sql = mysql_query("select kodepos, nama from banner_kanan where username='$mid'");
 
		$db->select("kode, uraian, username, jumlah, tujuan, tgl,status", "banner_kiri", "kode='$action'");
		$row=$db->fetch_row();
 
		    $db->update("banner_kiri", "status=1", "kode='$action'"); 	
			$db->insert("transaksi", "", "NULL, '$action', '$mid', '$row[3]', '$clientdate', '$row[1] (transfer e-walet ke $row[2])', 0");
			$db->insertkomjual($mid, $row[3]);
			$db->insertkomro($mid, $row[3]);
			echo "<meta http-equiv='refresh' content='0;URL=?m=ewalet&page=saldo'>";
	break;		
}
?>	
