<?php
mysql_select_db($database_sistem, $sistem);
$query_unit = "SELECT * FROM user_tb WHERE user_tb.`level`='Unit'";
$unit = mysql_query($query_unit, $sistem) or die(mysql_error());
$row_unit = mysql_fetch_assoc($unit);
$totalRows_unit = mysql_num_rows($unit);

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_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO bank_tb (kode_unit, no_rek, nama_bank, kode_bank, jenis, nominal) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['kode_unit'], "text"),
                       GetSQLValueString($_POST['no_rek'], "text"),
                       GetSQLValueString($_POST['nama_bank'], "text"),
                       GetSQLValueString($_POST['kode_bank'], "text"),
                       GetSQLValueString($_POST['jenis'], "text"),
                       GetSQLValueString($_POST['nominal'], "text"));

  mysql_select_db($database_sistem, $sistem);
  $Result1 = mysql_query($insertSQL, $sistem) or die(mysql_error());
}
?>
<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>

<p>&nbsp;</p>
<table width="75%" border="0" align="center" cellpadding="5" cellspacing="5" background="images/tr2.png">
  <tr>
    <td><hr /></td>
  </tr>
  <tr>
    <td><h3>Form Input Data Deposito</h3></td>
  </tr>
  <tr>
    <td><form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
        <table align="left" class="isi_tabel">
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">Nama Unit</td>
            <td><select name="kode_unit">
              <?php
do {  
?>
              <option value="<?php echo $row_unit['kode_unit']?>"<?php if (!(strcmp($row_unit['kode_unit'], $row_unit['kode_unit']))) {echo "selected=\"selected\"";} ?>><?php echo $row_unit['nama_unit']?></option>
              <?php
} while ($row_unit = mysql_fetch_assoc($unit));
  $rows = mysql_num_rows($unit);
  if($rows > 0) {
      mysql_data_seek($unit, 0);
	  $row_unit = mysql_fetch_assoc($unit);
  }
?>
            </select></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">No. Rekening</td>
            <td><input type="text" name="no_rek" value="" size="32" /></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">Nama Bank</td>
            <td><input type="text" name="nama_bank" value="" size="32" /></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">Kode Bank</td>
            <td valign="baseline"><table>
              <tr>
                <td><input type="radio" name="kode_bank" value="Deposito 1" />
                  Deposito 1</td>
              </tr>
              <tr>
                <td><input type="radio" name="kode_bank" value="Deposito 2" />
                  Deposito 2</td>
              </tr>
              <tr>
                <td><input type="radio" name="kode_bank" value="Deposito 3" />
                  Deposito 3</td>
              </tr>
              <tr>
                <td><input type="radio" name="kode_bank" value="Deposito 4" />
                  Deposito 4</td>
              </tr>
              <tr>
                <td><input type="radio" name="kode_bank" value="Deposito 5" />
                  Deposito 5</td>
              </tr>
            </table></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">Jenis Account</td>
            <td valign="baseline"><table>
              <tr>
                <td><input type="radio" name="jenis" value="Bank" disabled="disabled" />
                  Bank</td>
              </tr>
              <tr>
                <td><input name="jenis" type="radio" value="Deposito" checked="checked" />
                  Deposito</td>
              </tr>
            </table></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">Nominal</td>
            <td><input name="nominal" type="text" value="0" size="32" readonly="readonly" /></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">&nbsp;</td>
            <td><input type="submit" value="Input Data Deposito" /></td>
          </tr>
        </table>
        <input type="hidden" name="MM_insert" value="form2" />
      </form>
    <p>&nbsp;</p></td>
  </tr>
  <tr>
    <td><hr /></td>
  </tr>
  <tr>
    <td><h3>Tabel  Daftar Nama Bank</h3></td>
  </tr>
  <tr>
    <td><table width="90%" 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">Kode Unit</th>
        </tr>
        </thead>
      <tbody>
      
        <?php        mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * From bank_tb where jenis='Deposito' order by kode_unit, 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'>$r[kode_unit]</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><hr /></td>
  </tr>
</table>
        