<?php
 include '../../koneksi.php';
// $id = $_GET['id'];
 //$user = $_GET['user'];
 
if (isset ($_POST ['update_pengguna']))
	{
	$id = $_POST['id'];
	$nama = $_POST['nama'];
	$username = $_POST['Username'];
	$email = $_POST['Email'];
	$jkel = $_POST['Sex'];
	$level = $_POST['level'];
	$status = $_POST['status'];
$update = mysql_query("update user set nama_lengkap='$nama', username='$username', Email='$email', Jkel='$jkel', level='$level', status_admin='$status' where id='$id'");
mysql_close();
if ($update) {
    header("location:tabel_user.php");
} else {
    echo "gagal mengupdate data";
	}
}



elseif (isset ($_POST['update_kriteria']))
	{
	$id = $_POST['id'];
	$nama = $_POST['nama_kriteria'];
	$bobot = $_POST['bobot'];
	$type = $_POST['type'];
$update = mysql_query("update kriteria set nama_kriteria='$nama', bobot='$bobot',type='$type' where id_kriteria='$id'");
mysql_close();
if ($update) {
    header("location:kriteria/tabel_kriteria.php");
} else {
    echo "gagal mengupdate data";

	
}
}
elseif (isset ($_POST['update_pemohon']))
	{
	$id = $_POST['id'];
	$nama_pemohon = $_POST['nama_pemohon'];
	$alamat_pemohon = $_POST['alamat_pemohon'];
	$nomor_tlp = $_POST['nomor_tlp'];
	$tanggal = $_POST['tanggal'];
$update = mysql_query("update pemohon set nama_pemohon='$nama_pemohon', alamat_pemohon='$alamat_pemohon',nomor_tlp='$nomor_tlp',tanggal='$tanggal' where id_pemohon='$id'");
mysql_close();
if ($update) {
    header("location:pemohon/tabel_pemohon.php");
} else {
    echo "gagal mengupdate data";

	
}
}

elseif (isset ($_POST['update_asuransi']))
	{
	$id = $_POST['id'];
	$nama = $_POST['nama'];
	$website = $_POST['website'];
	$phone = $_POST['phone'];
	
$update = mysql_query("update tbcalon set nama='$nama', website='$website', phone='$phone 'where idCalon='$id'");
mysql_close();
if ($update) {
    header("location:tabel_Asuransi.php");
} else {
    echo "gagal mengupdate data";
	echo $id;
	echo $nama;
	echo $email;
	echo $alamat;
	echo $nama_pengiklan;
	
}
}


elseif (isset ($_POST['update_sub']))
	{
	$id = $_POST['id'];
	$nama_kriteria = $_POST['nama_kriteria'];
	$tampil=mysql_query("SELECT * FROM kriteria  where nama_kriteria='$nama_kriteria'");
	while($w=mysql_fetch_array($tampil))
					{
			    $id_kriteria= "$w[id_kriteria]"; 
				}
	$nama_sub = $_POST['nama_sub'];
	$bobot = $_POST['bobot'];
$update = mysql_query("update sub_kriteria set nama_kriteria='$nama_kriteria',id_kriteria='$id_kriteria', nama_sub='$nama_sub', bobot='$bobot' where id_sub='$id'");
mysql_close();
if ($update) {
   header("location:sub_kriteria/tabel_sub.php");
} else {
    echo "gagal mengupdate data";	
}
}



elseif (isset ($_POST['update_rumah']))
	{
	
	$dir_gambar = 'C:\xampp\htdocs\website\SPK-Perumahan\images\rumah\\';
$url_folder_gambar = 'http://localhost/website/SPK-Perumahan/images/rumah/';
if(empty($_FILES['userfile']['name'])){
//echo "Gambar kosong, harap pilih file terlebih dahulu.";
$filename2 = 'default.jpg';
}
else
{
$filename2 = basename($_FILES['userfile']['name']);
$uploadfile = $dir_gambar . $filename2;
echo $_FILES['userfile']['tmp_name'];
echo '<br />' . $uploadfile;
$uploadedfile = $_FILES['userfile']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);

// Create an Image from it so we can do the resize
//$src = imagecreatefromjpeg($uploadedfile);

// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);

// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being “stretched”
// or “squashed”. If you prefer some max width other than
// 600, simply change the $newwidth variable
$newwidth=960;
$newheight=($height/$width)*600;
$tmp=imagecreatetruecolor($newwidth,$newheight);

// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = $dir_gambar. $_FILES['userfile']['name'];
//$filename = basename($_FILES['userfile']['name']);
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
// has completed.

	//move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);
}
	$id = $_POST['id'];
	$tipe = $_POST['tipe'];
	$jumlah_kamar = $_POST['jumlah_kamar'];
	$harga = $_POST['harga'];
	$cicilan = $_POST['cicilan'];
	
$update = mysql_query("update data_rumah set tipe_rumah='$tipe', jumlah_kamar='$jumlah_kamar', harga='$harga', cicilan='$cicilan',gambar='$filename2' where id='$id'");
mysql_close();
if ($update) {
    header("location:tabel_rumah.php");
} else {
    echo "gagal mengupdate data";
	
}
}

?>