Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kuis KL Web Lanjut A2_Nur Istiqomah_04741 #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions ambil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<html>
<head>
<title>Halaman Ambil Barang Titipan</title>
</head>
<body>
<?php
session_start();
if(isset($_SESSION['login']) && ($_SESSION['login'] == 1)){
?>
<form action=" " method="POST" enctype="multipart/form-data">
<table align="center"; margin="100">
<tr>
<td><H2>Pengambilan Barang</H2></td>
</tr>
<tr>
<td align="right">Masukkan Nomor Penitipan Barang: </td>
<td align="left"><input type="text" name="no_trx"></td>
</tr>
<tr>
<td align="right"><input type="submit" value="ambil"></td>
</tr>
<tr>
<td><a href="index.php">Back</a></td>
</tr>
</table>
</form>
<?php
/*require('koneksi.php');

if($_SERVER['REQUEST_METHOD'] == 'POST'){
$id_transaksi=$_POST['id_transaksi'];


$sql="Update transaksi set tanggal_kembali = now() ,
durasi =(select datediff(now(),tanggal_pinjam)) where id_transaksi=".$_POST['id_transaksi'];

mysqli_query($con, $sql) or die(' Error'.mysqli_error($con));


}*/

require('koneksi.php');

if($_SERVER['REQUEST_METHOD'] == 'POST'){
$no_trx=$_POST['no_trx'];


$sql="Update transaksi set jam_ambil=now() , durasi=timestampdiff(SECOND,jam_masuk,jam_ambil) where no_trx=".$_POST['no_trx'];

mysqli_query($con, $sql) or die(' Error'.mysql_error($con));

$s = "Update transaksi set biaya = $tarif where no_trx =".$_POST['no_trx'];
$q = mysqli_query($con, $s);


}
?>
<?php
require('koneksi.php');
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$i=1;
$query= mysqli_query($con, "SELECT * From transaksi where no_trx= ".$_POST['no_trx']);
function tarif($con, $id, $durasi){
if ($durasi > 0) {
$tarif = ($durasi* 1000)/3600;

return $tarif;
}else{
$tarif = 0;
return $tarif;
}
}
while ($data =mysqli_fetch_assoc($query)){
$tarif = tarif($con, $_POST['no_trx'], $data['durasi']);

/*require('koneksi.php');
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$i=1;
$query= mysqli_query($con, "SELECT * From transaksi where no_trx= ".$_POST['no_trx']);
while ($data =mysqli_fetch_assoc($query)){*/

echo "<table border='2'><tr>";
echo "<th>No</th>";
echo "<th>No Transaksi</th>";
echo "<th>Nama Pelanggan</th>";
echo "<th>No HaPe</th>";
echo "<th>Deskripsi Barang</th>";
echo "<th>Jam Masuk</th>";
echo "<th>Jam Ambil</th>";
echo "<th>Durasi</th>";
echo "<th>Biaya</th>";
echo "</tr>";
echo "<tr>";
echo "<td>".$i."</td>";
echo "<td>".$data['no_trx']."</td>";
echo "<td>".$data['nama_pelanggan']."</td>";
echo "<td>".$data['no_hp']."</td>";
echo "<td>".$data['desc_barang']."</td>";
echo "<td>".$data['jam_masuk']."</td>";
echo "<td>".$data['jam_ambil']."</td>";
echo "<td>".($data['durasi']/3600)."</td>";
echo "<td>".$data['biaya']."</td>";
$i++;
echo "</table>";
}

}
?>

<?php
}else{
header('location:login.php');
}
?>
</body>
</html>
67 changes: 67 additions & 0 deletions cari.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<html>
<head>
<title>Daftar Barang</title>
</head>
<body>
<?php session_start();
if(isset($_SESSION['login']) && ($_SESSION['login'] == 1)){ ?>
<H2>Pencarian</H2>
<form action=" " method="POST" enctype="multipart/form-data">
<table>
<tr>
<td>Masukkan Nomor Transaksi : </td>
<td><input type="text" name="no_trx"></td>
</tr>
<tr>
<td><input type="submit" value="Cari"></td>
</tr>
<tr><td><a href="index.php">Back</a></td></tr>
</table>
</form>


<?php

require('koneksi.php');
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$i=1;
$query= mysqli_query($con, "SELECT * From transaksi where no_trx= ".$_POST['no_trx']);
while ($data =mysqli_fetch_assoc($query)){

echo "<table border='2'><tr>";
echo "<th>No</th>";
echo "<th>No Transaksi</th>";
echo "<th>Nama Pelanggan</th>";
echo "<th>No HaPe</th>";
echo "<th>Deskripsi Barang</th>";
echo "<th>Jam Masuk</th>";
echo "<th>Jam Ambil</th>";
echo "<th>Durasi</th>";
echo "<th>Biaya</th>";
echo "</tr>";
echo "<tr>";
echo "<td>".$i."</td>";
echo "<td>".$data['no_trx']."</td>";
echo "<td>".$data['nama_pelanggan']."</td>";
echo "<td>".$data['no_hp']."</td>";
echo "<td>".$data['desc_barang']."</td>";
echo "<td>".$data['jam_masuk']."</td>";
echo "<td>".$data['jam_ambil']."</td>";
echo "<td>".$data['durasi']."</td>";
echo "<td>".$data['biaya']."</td>";
//echo "<td>".$data['username']."</td>";
/* echo "<td><a href=\"edit_barang.php?id=".$data['id_barang']."\">Edit</a></td>";
echo "<td><a href=\"hapus_barang.php?id=".$data['id_barang']."\" onclick=\"alert('Anda Akan Menghapus Barang??')\">Hapus</a></td>";
echo "</tr>"; */
$i++;
echo "</table>";
}}
?>

<?php
}else{
header('location:login.php');
}
?>
</body>
</html>
9 changes: 9 additions & 0 deletions ceklogin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
session_start();

//jika session username belum dibuat, atau session username kosong
if (!isset($_SESSION['name']) || empty($_SESSION['name'])) {
//redirect ke halaman login
header('location:login.php');
}
?>
27 changes: 27 additions & 0 deletions hapus2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

$host='localhost';
$dbname='quiz';
$user='root';
$pass='';

//membuat koneksi
$con = mysqli_connect($host, $user, $pass, $dbname);
if(mysqli_connect_errno()){
echo "koneksi error: ". mysqli_connect_error();
}

if(isset($_GET['id'])){
$sql="delete from transaksi where no_trx= ". $_GET['id'];
$query=mysqli_query($con,$sql);

if(!$query){
echo mysqli_error($con);
}else{
echo "data berhasil dihapus.";
echo "<a href=\"index.php\">kembali</a>";

}
}

?>
61 changes: 61 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<html>
<head>
<title>Daftar Barang</title>
</head>
<body>
<table><tr>
<th><a href="tambah.php" align="right">Tambah Data Barang</a></th>
<th><a href="ambil.php" align="right">Ambil Barang</a></th>
<th><a href="cari.php" align="right">Pencarian Barang</a></th>
<th><th><a href="logout.php" align="right">Logout</a></th></th>
</tr></table>
<?php
require('koneksi.php');
session_start();
if(isset($_SESSION['login']) && ($_SESSION['login'] == 1)){
echo "<h2>Daftar Barang Titipan</h2>";
?>
<table border="5px"><tr>
<th>No</th>
<th>Nomor Transaksi</th>
<th>Nama Pelanggan</th>
<th>Nomor HP</th>
<th>Deskripsi Barang</th>
<th>Nomor Loker</th>
<th>Jam Masuk</th>
<th>Jam Ambil</th>
<th>Durasi</th>
<th>Biaya</th>
<th>Aksi</th>
</tr>
<?php
$i=1;
$query= mysqli_query($con, "SELECT * From transaksi");
while ($data =mysqli_fetch_assoc($query)){
echo "<tr>";
echo "<td>".$i."</td>";
echo "<td>".$data['no_trx']."</td>";
echo "<td>".$data['nama_pelanggan']."</td>";
echo "<td>".$data['no_hp']."</td>";
echo "<td>".$data['desc_barang']."</td>";
echo "<td>".$data['no_loker']."</td>";
echo "<td>".$data['jam_masuk']."</td>";
echo "<td>".$data['jam_ambil']."</td>";
echo "<td>".$data['durasi']."</td>";
echo "<td>".$data['biaya']."</td>";
//echo "<td>".$data['username']."</td>";
//echo "<td><a href=\"edit_barang.php?id=".$data['no_trx']."\">Edit</a></td>";
echo "<td><a href=\"hapus2.php?id=".$data['no_trx']."\" onclick=\"alert('Anda Akan Menghapus Barang??')\">Hapus</a></td>";
echo "</tr>";
$i++;
}
?>
</table>
</body>
</html>

<?php
}else{
header('location:login.php');
}
?>
12 changes: 12 additions & 0 deletions konek.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
$host='localhost';
$dbname='penitipan';
$user='root';
$pass='';

//membuat koneksi
$con = mysqli_connect($host, $user, $pass, $dbname);
if(mysqli_connect_errno()){
echo "koneksi error: ". mysqli_connect_error();
}
?>
10 changes: 10 additions & 0 deletions koneksi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

$host='localhost';
$dbname='quiz';
$user='root';
$pass='';

$con=mysqli_connect($host, $user, $pass, $dbname);

?>
17 changes: 17 additions & 0 deletions log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
session_start();
$sql="SELECT *FROM user where username='".$_POST['username']."' AND password='".$_POST['password']."'";

$query=mysqli_query($con, $sql) or die (mysqli_error($con));

$data=mysql_fetch_assoc($query);


$_SESSION['namauser'] = $data['username'];

if(!isset($_SESSION['namauser'])){
//jika session belum di set/register
die("Anda belum login");
}

?>
47 changes: 47 additions & 0 deletions login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<H2>Selamat Datang</H2>
<form action=" " method="POST" enctype="multipart/form-data">
<table>
<tr>
<td>Username : </td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password : </td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="submit" value="Login"></td>
</tr>
</table>
</form>

<?php
session_start();
require('koneksi.php');
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$sql="SELECT *FROM user where username='".$_POST['username']."' AND password='".$_POST['password']."'";
echo $_POST['username'];
echo $_POST['password'];
$query=mysqli_query($con, $sql) or die (mysqli_error($con));

if(mysqli_num_rows($query)){
while($data=mysqli_fetch_assoc($query)){
$_SESSION['login']=1;
$_SESSION['name']=$data['nama_pengguna'];

header('location:index.php');
}

}else{
echo "username atau password salah";
}
}
?>
</body>
</html>
5 changes: 5 additions & 0 deletions logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
session_start();
session_destroy();
header('location:login.php');
?>
Loading