<?php
	include ("../inc/koneksi.php");
	include('../inc/password.php');
	
	$tanggal = date("d-m-Y");
	$id_lapor = rand();
	$username = mysql_real_escape_string($_POST['username']);
	$nama = mysql_real_escape_string($_POST['nama']);
	$lokasi = mysql_real_escape_string($_POST['lokasi']);
	$komentar = mysql_real_escape_string($_POST['komentar']);

	//cari id
	$cari = mysql_query("SELECT id_user FROM user WHERE username='$username'");
	$r = mysql_fetch_array($cari);
	$id_user = $r[0];
	$lat = 0;
	$lang = 0;
	$status = "Menunggu";

	//upload foto
	$temp_foto = explode(".", $_FILES["foto"]["name"]);
	$newfilefoto = generateRandomString() . '.' . end($temp_foto);
	move_uploaded_file($_FILES["foto"]["tmp_name"], "images/tabaos/" . $newfilefoto);

	$wrong = "";

	//simpan laporan
	$query = "INSERT INTO laporan (id_lapor,id_user,lat,lang,alamat,komentar,tanggal,status,foto) VALUES ('$id_lapor','$id_user','$lat','$lang','$lokasi','$komentar','$tanggal','$status','$newfilefoto')";		
	mysql_query($query) or die (mysql_error());

	if($wrong == "")
		$url = "tabaos.php?ket=berhasil";
	else
		$url = "tabaos.php?ket=$wrong";

	echo "<script language=\"javascript\">
		window.location='$url';
	</script>";

?>