
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE bank_tb SET nominal=%s WHERE no_rek=%s",
                       GetSQLValueString($_POST['nom'], "text"),
                       GetSQLValueString($_POST['no_rek'], "text"));

  mysql_select_db($database_sistem, $sistem);
  $Result1 = mysql_query($updateSQL, $sistem) or die(mysql_error());
}

mysql_select_db($database_sistem, $sistem);
$query_bank = "SELECT * FROM bank_tb WHERE bank_tb.no_rek='$_GET[no_rek]'";
$bank = mysql_query($query_bank, $sistem) or die(mysql_error());
$row_bank = mysql_fetch_assoc($bank);
$totalRows_bank = mysql_num_rows($bank);

?>
<script type="text/javascript" charset="utf-8">
          $(document).ready(function(){
            $('#bbkas').dataTable({
					     "oLanguage": {
						      "sLengthMenu": "Tampilkan _MENU_ data per halaman",
						      "sSearch": "Pencarian: ", 
						      "sZeroRecords": "Maaf, tidak ada data yang ditemukan",
						      "sInfo": "Menampilkan _START_ s/d _END_ dari _TOTAL_ data",
						      "sInfoEmpty": "Menampilkan 0 s/d 0 dari 0 data",
						      "sInfoFiltered": "(di filter dari _MAX_ total data)",
						      "oPaginate": {
						          "sFirst": "<<",
						          "sLast": ">>", 
						          "sPrevious": "<", 
						          "sNext": ">"
					       }
				      },
              "sPaginationType":"full_numbers",
              "bJQueryUI":true
            });
          })    
        </script>

<table width="100%" border="0" align="center" cellpadding="5" cellspacing="5">
  <tr>
    <td><h3 style="color:#036">Form Update Data</h3></td>
  </tr>
  <tr>
    <td><form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
      <table width="400" border="0" cellpadding="4" cellspacing="4" class="isi_tabel">
        <tr>
          <td width="100">Kode Bank</td>
          <td width="10">:</td>
          <td><?php echo $row_bank['kode_bank'];?></td>
        </tr>
        <tr>
          <td>No. Rekening</td>
          <td>:</td>
          <td><?php echo $row_bank['no_rek'];?>
            <input type="hidden" name="no_rek" id="no_rek" value="<?php echo $row_bank['no_rek'];?>" /></td>
        </tr>
        <tr>
          <td>Nama Bank</td>
          <td>:</td>
          <td><?php echo $row_bank['nama_bank'];?></td>
        </tr>
        <tr>
          <td>Saldo</td>
          <td>:</td>
          <td><input name="nom" id="rupiah" type="text" size="20" /></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><input name="show" type="text" id="rupiah2" style="opacity:10" size="20" readonly="readonly" /></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><input type="submit" name="update" id="update" value="Update Data" /></td>
        </tr>
      </table>
      <input type="hidden" name="MM_update" value="form1" />
    </form></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><table width="400" class="isi_tabel">
        <tr>
          <td width="100">Tabel</td>
          <td width="10">:</td>
          <td>Daftar Nama Bank</td>
        </tr>
        <tr>
          <td>Unit</td>
          <td>:</td>
          <td><?php echo $_SESSION['nama'];?></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%" align="center"  bgcolor="#FFFFFF" class="display" id="bbkas">
      <thead>
        <tr height="40" class="form_body">
          <th align="center" width="100">No</th>
          <th align="center">Kode Bank</th>
          <th align="center">No. Rekening</th>
          <th align="center">Nama Bank</th>
          <th align="center">Saldo</th>
          <th align="center">Proses</th>
        </tr>
        </thead>
      <tbody>
      
        <?php        mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * From bank_tb where kode_unit='$_SESSION[kode]' and jenis='Bank' order by kode_bank asc");
					          $no = 1;
							
                    while ($r = mysql_fetch_array($sql)) {
                      echo "<tr height='25'>
          <td align='center'>$no</td>
		  <td align='center'>$r[kode_bank]</td>
            <td align='center'>$r[no_rek]</td>
			<td align='left'>$r[nama_bank]</td>
			<td align='right'>";?><?php echo formatRupiah($r['nominal']);?><?php echo"</td>
			<td align='center'>";?><a href="?section=Setting&module=saldo_awal_bank&no_rek=<?php echo $r['no_rek'];?>">Proses</a><?php echo"</td>
          </tr>";
                      $no++;
                    }
                    ?>
      </tbody>
      <tfoot>
        <tr>
       <th colspan="3" align="center">Saldo</th>
          <th align="right"><?php echo '-';?></th>
          <th align="right"><?php echo '-';?></th>
          <th align="right"><?php echo '-';?></th>
        </tr>
      </tfoot>
    </table>
    <p>&nbsp;</p></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
<p>&nbsp;</p>
        <?php
mysql_free_result($bank);

?>
 <script type="text/javascript">
		
		var rupiah = document.getElementById('rupiah');
		rupiah.addEventListener('keyup', function(e){
			// tambahkan 'Rp.' pada saat form di ketik
			// gunakan fungsi formatRupiah() untuk mengubah angka yang di ketik menjadi format angka
			rupiah.value = formatRupiah(this.value, 'Rp. ');
		});
			var rupiah = document.getElementById('rupiah2');
		rupiah.addEventListener('keyup', function(e){
			// tambahkan 'Rp.' pada saat form di ketik
			// gunakan fungsi formatRupiah() untuk mengubah angka yang di ketik menjadi format angka
			rupiah.value = formatRupiah(this.value, 'Rp. ');
		});
 
		/* Fungsi formatRupiah */
		function formatRupiah(angka, prefix){
			var number_string = angka.replace(/[^,\d]/g, '').toString(),
			split   		= number_string.split(','),
			sisa     		= split[0].length % 3,
			rupiah     		= split[0].substr(0, sisa),
			ribuan     		= split[0].substr(sisa).match(/\d{3}/gi);
 
			// tambahkan titik jika yang di input sudah menjadi angka ribuan
			if(ribuan){
				separator = sisa ? '.' : '';
				rupiah += separator + ribuan.join('.');
			}
 
			rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
			return prefix == undefined ? rupiah : (rupiah ? 'Rp. ' + rupiah : '');
		}
	</script>       