<?php
include "koneksi.php";
$response = array();
if(isset($_POST['id_dimensi'], $_POST['id_pernyataan'])){
	$id_dimensi = $_POST['id_dimensi'];
	$id_pernyataan = $_POST['id_pernyataan'];

	$sql = "DELETE FROM aturan WHERE id_dimensi='".$id_dimensi."'";
	$result = mysqli_query($koneksi, $sql);

	if($result){
		for($i=0; $i<count($id_pernyataan); $i++){
			if($id_pernyataan[$i]!=0){
				$sql2 = "INSERT INTO aturan(id_dimensi, id_pernyataan) VALUES('".$id_dimensi."', '".$id_pernyataan[$i]."')";
				$result2 = mysqli_query($koneksi, $sql2);
			}
		}
		$response["success"] = 1;
		$response["message"] = "Aturan Berhasil Diubah";
		echo json_encode($response);
	} else {
		$response["success"] = 0;
		$response["message"] = "Aturan Gagal Diubah";
		echo json_encode($response);
	}
} else {
	$response["success"] = 0;
	$response["message"] = "Aturan gagal ditambah";
	echo json_encode($response);
}
?>
