<?php	
	
	global $conn;
	
	$conn = mysqli_connect("127.0.0.1", "p1d3ti08", "Gibeon08", "p1d3ti08_proyek");
	if(!$conn){
		die("database connect problem");
	}
	$db_use = mysqli_select_db($conn, "p1d3ti08_proyek") or die ("select db problem!!");
	
	function execQ($strQ){
		global $conn;
		$res = mysqli_query($conn, $strQ);
		
		return $res;
	}
	
function getUser(){
		$strQ = "SELECT * FROM user  ";
		
		$resItem = execQ($strQ);
		
	if(mysqli_num_rows($resItem)!=0){
		$ret = array();
		while($data = mysqli_fetch_assoc($resItem)){
			array_push($ret, array(
				'id' => $data['id'],
				'nama' => $data['namalengkap'],
				'alamat' => $data['alamat'],
				'email' => $data['email'],
				'peserta' => $data['jumlahpeserta']
			)); 
		}
		
		return $ret;
		
	} else{
		return false;
	}
	}
	
	   
	  function getAllKeluhan(){
		$strQ = "SELECT * FROM keluhan";
		
		$resItem = execQ($strQ);
		
	if(mysqli_num_rows($resItem)!=0){
		$ret = array();
		while($data = mysqli_fetch_assoc($resItem)){
			array_push($ret, array(
				'id' => $data['ID'],
				'nama_pengunjung' => $data['namapengunjung'],
				'email_pengunjung' => $data['emailpengunjung'],
				'isi_keluhan' => $data['isikeluhan']
			)); 
		}
		
		return $ret;
		
	} else{
		return false;
	}
	}
	
	function getProfil(){
		$strQ = "SELECT * FROM profil";
		
		$resItem = execQ($strQ);
		
	if(mysqli_num_rows($resItem)!=0){
		$ret = array();
		while($data = mysqli_fetch_assoc($resItem)){
			array_push($ret, array(
				'id' => $data['id'],
				'gambar' => $data['gambar'],
				'konten' => $data['konten']		
			)); 
		}
		
		return $ret;
		
	} else{
		return false;
	}
	}
	function getDaftar(){
		$strQ = "SELECT * FROM kamar";
		
		$resItem = execQ($strQ);
		
	if(mysqli_num_rows($resItem)!=0){
		$ret = array();
		while($data = mysqli_fetch_assoc($resItem)){
			array_push($ret, array(
				'id' => $data['id'],
				'nama' => $data['nama kamar'],
				'kapasitas' => $data['kapasitas kamar'],
				'harga' => $data['harga'],
				'gambar' => $data['gambar']
				
			)); 
		}
		
		return $ret;
		
	} else{
		return false;
	}
	}
	function redirect($_location){
		header('Location: ' .$_location);
	}
	function getPemesanan(){
		$strQ = "SELECT * FROM pemesanan";
		
		$resItem = execQ($strQ);
		
	if(mysqli_num_rows($resItem)!=0){
		$ret = array();
		while($data = mysqli_fetch_assoc($resItem)){
			array_push($ret, array(
				'id' => $data['id'],
				'namalengkap' => $data['namalengkap'],
				'alamat' => $data['alamat'],
				'email' => $data['email'],
				'jumlahpeserta' => $data['jumlahpeserta'],
				'waktumulai' => $data['waktumulai'],
				'waktuselesai' => $data['waktuselesai'],
				'namaruangan' =>  $data['namaruangan'],
				'gambar' =>  $data['gambar']
			)); 
		}
		
		return $ret;
		
	} else{
		return false;
	}
	}
	function getPengunjung(){
		$strQ = "SELECT * FROM user where role LIKE 'user' ";
		
		$resItem = execQ($strQ);
		
	if(mysqli_num_rows($resItem)!=0){
		$ret = array();
		while($data = mysqli_fetch_assoc($resItem)){
			array_push($ret, array(
				'id' => $data['id'],
				'namalengkap' => $data['namalengkap'],
				'alamat' => $data['alamat'],
				'email' => $data['email'],
				'username' => $data['username'],
				'password' => $data['password'],
				'role' => $data['role']
				
			)); 
		}
		
		return $ret;
		
	} else{
		return false;
	}
	}
	