<?php include("config/connection.php"); ?>

<?php 
error_reporting(0);

$actget = $_GET['actget'];
$act = $_POST['act'];
$id = $_POST["id"];
$nama = $_POST['nama'];
$password = $_POST['password'];
$akses = $_POST['akses'];

//TAMBAH DATA
if ($act == 1){

	$sql="insert into tb_operator (nama, password, akses, status) values ('$nama','$password','$akses','1')";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-operator"</script>
<?php	

//UBAH DATA
}elseif ($act == 2){

	$sql="update tb_operator set nama = '".$nama."', password = '".$password."', akses = '".$akses."' where id_operator = '".$id."'";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-operator"</script>
<?php

//NONAKTIF DATA
}elseif($act == 3){
	$sql="update tb_operator set status = '0' where id_operator = '".$id."'";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-operator"</script>
<?php

//CARI DATA UNTUK EDIT
}elseif ($actget == 1){

	$id = $_GET['id'];
    $sql = "SELECT * from tb_operator WHERE id_operator = '".$id."'"; 
	$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
	mysql_close($test);

    $query = mysql_fetch_array($hasil);
    echo json_encode($query);
	
}
?>
