<link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css">
<script src="media/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
          $(document).ready(function(){
            $('#data_user').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>
<?php
mysql_select_db($database_sistem, $sistem);
$query_userid = "SELECT * FROM user_tb where id='$_GET[reg]'";
$userid = mysql_query($query_userid, $sistem) or die(mysql_error());
$row_userid = mysql_fetch_assoc($userid);
$totalRows_userid = mysql_num_rows($userid);


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"] == "form1")) {
  $insertSQL = sprintf("REPLACE INTO user_tb (id, password, kode_unit, nama_unit, alamat, telp, email, `level`, direktur, bendahara, piko, nama_admin) VALUES (%s, md5(%s), %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['kode_unit'], "text"),
                       GetSQLValueString($_POST['nama_unit'], "text"),
                       GetSQLValueString($_POST['alamat'], "text"),
                       GetSQLValueString($_POST['telp'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['level'], "text"),
                       GetSQLValueString($_POST['direktur'], "text"),
                       GetSQLValueString($_POST['bendahara'], "text"),
					   GetSQLValueString($_POST['piko'], "text"),
                       GetSQLValueString($_POST['nama_admin'], "text"));

  mysql_select_db($database_sistem, $sistem);
 
  $query=mysql_query($insertSQL); 
if ($query==true){
		?>
			<script>
				alert ("Proses Update Data Sukses ..!!"); history.back();
			</script>
			<?php
		}
		else
		{
			?>
			<script>
				alert ("Proses Update Data Gagal,..!!"); history.back();
			</script>
			<?php
				}
}
?>	

<table width="100%" border="0" align="center" cellpadding="5">
  <tr>
    <td><table width="100%">
      <tr>
        <td align="left" valign="top"><h3 style="color:#036">Form Edit Data User</h3></td>
      </tr>
      <tr>
        <td align="left" valign="top"><form action="?section=Setting&module=proses_update_user" method="post" name="form1" id="form1">
          <table width="50%" align="left" cellpadding="2" cellspacing="2" class="form_body">
            <tr valign="baseline">
              <td nowrap="nowrap" align="left">Id User</td>
              <td><label for="id"></label>
                <input name="id" type="text" id="id" value="<?php echo $row_userid['kode_unit'];?>" size="20" readonly="readonly" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="left">Password</td>
              <td><input type="password" name="password" value="" size="20" required="required" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="left">Kode Unit</td>
              <td><input name="kode_unit" type="text" value="<?php echo $row_userid['kode_unit'];?>" size="10" readonly="readonly" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="left">Nama Unit</td>
              <td><input name="nama_unit" type="text" value="<?php echo $row_userid['nama_unit'];?>" size="32" readonly="readonly" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="left">Level</td>
              <td><input name="level" type="text" value="<?php echo $row_userid['level'];?>" size="32" readonly="readonly" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="left">Alamat</td>
              <td><input name="alamat" type="text" value="<?php echo $row_userid['alamat'];?>" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="left">Telp</td>
              <td><input name="telp" type="text" value="<?php echo $row_userid['telp'];?>" size="20" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="left">Direktur Eksekutif</td>
              <td><input name="direktur" type="text" value="<?php echo $row_userid['direktur'];?>" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="left">Pimpinan Komunitas</td>
              <td><input name="piko" type="text" id="piko" value="<?php echo $row_userid['piko'];?>" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="left">Bendahara</td>
              <td><input name="bendahara" type="text" value="<?php echo $row_userid['bendahara'];?>" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="left">Email</td>
              <td><input name="email" type="text" value="<?php echo $row_userid['email'];?>" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="left">Nama Admin</td>
              <td><input name="nama_admin" type="text" value="<?php echo $row_userid['nama_admin'];?>" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="left">&nbsp;</td>
              <td><input type="submit" value="Update Data User" class="button" /></td>
            </tr>
          </table>
          <input type="hidden" name="MM_insert" value="form1" />
        </form></td>
      </tr>
      <tr>
        <td align="left" valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td align="left" valign="top"><table width="100%" align="center"  bgcolor="#FFFFFF" class="display" id="data_user">
          <thead>
            <tr class="form_body" height="30">
              <th align="center">No</th>
              <th align="center">Id User</th>
              <th align="center">Kode Unit</th>
              <th align="center">Nama Unit</th>
              <th align="center">Alamat</th>
              <th align="center">Telp</th>
              <th align="center">Email</th>
              <th align="center">Nama Admin</th>
              <th align="center">Edit</th>
              <th align="center">Hapus</th>
            </tr>
          </thead>
          <tbody>
            <?php        
			if($_SESSION['level']=='Unit'){
			mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * FROM user_tb where kode_unit='$_SESSION[kode]' order by id asc");
			}elseif($_SESSION['level']=='Pusat'){
			mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * FROM user_tb order by level asc");
			}
					         $no = 1;
                    while ($r = mysql_fetch_array($sql)) {
		
                      echo "<tr>
          <td align='center'>$no</td>
		  <td align='center'>$r[id]</td>
            <td align='center'>$r[kode_unit]</td>
			<td align='center'>$r[nama_unit]</td>
           <td align='left'>$r[alamat]</td>
			<td align='right'>$r[telp]</td>
			<td align='right'>$r[email]</td>
			<td align='right'>$r[nama_admin]</td>
			<td align='center'>"?>
            <a href="media.php?section=Setting&module=edit_user_pusat&amp;reg=<?php echo $r['id'];?>"><img src="images/edit.png" width="15" height="15" /></a><?php echo"</td>
		  <td align='center'>"?>
          <a href="media.php?section=Setting&module=hapus_user&amp;reg=<?php echo $r['id'];?>"><img src="images/cross.png" width="15" height="15" /></a><?php echo"</td>

          </tr>";
                      $no++;
                    }
                    ?>
                    </tbody>
          <tr>
            <td></td>
          </tr>
          <tr>
            <td></td>
          </tr>
          <tfoot>
          </tfoot>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
<p>&nbsp;</p>
