Aplikasi PKL dengan PHP
PHP
koneksi.php
<?php
$host = "localhost";
$username = "root";
$password = "";
$database = "pkl";
$koneksi = mysqli_connect($host,$username,$password,$database);
function register($username,$password,$nama)
{
global $koneksi;
$insert = mysqli_query($koneksi,"insert into user values ('$username','$password','$nama')");
return $insert;
}
function login($username,$password,$remember)
{
global $koneksi;
$query = mysqli_query($koneksi,"select * from user where username='$username'");
$data_user = $query->fetch_array();
if(password_verify($password,$data_user['password']))
{
if($remember)
{
setcookie('username', $username, time() + (60 * 60 * 24 * 5), '/');
setcookie('nama', $data_user['nama'], time() + (60 * 60 * 24 * 5), '/');
}
$_SESSION['username'] = $username;
$_SESSION['nama'] = $data_user['nama'];
$_SESSION['is_login'] = TRUE;
return TRUE;
}
}
function relogin($username)
{
global $koneksi;
$query = mysqli_query($koneksi,"select * from user where username='$username'");
$data_user = $query->fetch_array();
$_SESSION['username'] = $username;
$_SESSION['nama'] = $data_user['nama'];
$_SESSION['is_login'] = TRUE;
}
function tambah($data){
global $koneksi;
$namaperusahaan = $_POST['namaperusahaan'];
$alamat = $_POST['alamat'];
$email = $_POST['email'];
$website = $_POST['website'];
$sql = mysqli_query($koneksi, "insert into perusahaan values('$namaperusahaan','$alamat','$email','$website')");
return mysqli_affected_rows($koneksi);
}
function add($data){
global $koneksi;
$nama = $_POST['nama'];
$nis = $_POST['nis'];
$kelas = $_POST['kelas'];
$jurusan = $_POST['jurusan'];
$telp = $_POST['telp'];
$namaperusahaan = $_POST['namaperusahaan'];
$alamat = $_POST['alamat'];
$awal = $_POST['awal'];
$akhir = $_POST['akhir'];
$namapengawas = $_POST['namapengawas'];
$jabatan = $_POST['jabatan'];
$handphone = $_POST['handphone'];
$sql = mysqli_query($koneksi, "insert into f01 values('$nama','$nis','$kelas','$jurusan','$telp','$namaperusahaan','$alamat','$awal','$akhir','$namapengawas','$jabatan','$handphone','')");
return mysqli_affected_rows($koneksi);
}
function acc($data){
global $koneksi;
$nis = $_GET['nis'];
$sql = "update f01 set status = '1' where nis = '$nis'";
$query = mysqli_query($koneksi, $sql);
return mysqli_affected_rows($koneksi);
}
function tolak($data){
global $koneksi;
$nis = $_GET['nis'];
$sql = "update f01 set status = '2' where nis = '$nis'";
$query = mysqli_query($koneksi, $sql);
return mysqli_affected_rows($koneksi);
}
?>
login.php
<?php
session_start();
include 'koneksi.php';
if (isset($_SESSION['is_login'])) {
header('location:home.php');
}
if (isset($_COOKIE['username'])) {
relogin($_COOKIE['username']);
header('location:home.php');
}
if (isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if (isset($_POST['remember'])) {
$remember = TRUE;
}else{
$remember = FALSE;
}
if (login($username, $password, $remember)) {
header('location:home.php');
}
}
if (isset($_POST['admin'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = mysqli_query($koneksi,"select * from admin where username='$username' and password ='$password'");
header('location:admin.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style6.css">
<title>Sign In | Aplikasi PKL</title>
</head>
<body>
<center>
<h1>Sign In</h1>
<form action="" method="post">
<table>
<tr>
<td>
<input type="text" name="username" id="username" placeholder="Username" required autofocus style="width: 100%;">
</td>
</tr>
<tr>
<td>
<input type="password" name="password" id="password" placeholder="Password" required style="width: 100%;">
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="remember" id="" value="remember-me"> Remember me
</td>
</tr>
<tr>
<td>
<button type="submit" name="login" style="width: 100%;">Sign In</button>
</td>
</tr>
<tr>
<td>
<button type="submit" name="admin" style="width: 100%;">Login Admin</button>
</td>
</tr>
<tr>
<td><a href="register.php">Belum punya akun? Daftar sekarang</a></td>
</tr>
</table>
</form>
</center>
</body>
</html>
home.php
<?php
include 'koneksi.php';
session_start();
if (!isset($_SESSION['is_login'])) {
header('location:login.php');
}
$halaman = 3;
$page = isset($_GET['halaman']) ? (int)$_GET['halaman'] : 1;
$mulai = ($page > 1) ? ($page * $halaman) - $halaman : 0;
$result = mysqli_query($koneksi, "select namaperusahaan, alamat from perusahaan");
$total = mysqli_num_rows($result);
$pages = ceil($total/$halaman);
$no = $mulai+1;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
<link rel="stylesheet" href="style2.css">
<title>Halaman Utama | Aplikasi PKL</title>
</head>
<body>
<div class="navbar">
<h1>Aplikasi PKL</h1>
<nav>
<ul>
<li>Home</li>
<li><a href="f01.php">Request F01</a></li>
<li><a href="akun.php">Account</a></li>
<li><a href="logout.php">Log Out</a></li>
</ul>
</nav>
</div>
<center>
<h1 style="margin: 50px;">Daftar Perusahaan</h1>
</center>
<div class="meaning">
<table border="3" style="margin: 10px;">
<tr>
<th>No</th>
<th>Nama Perusahaan</th>
<th>Alamat Perusahaan</th>
</tr>
<?php
$sql = mysqli_query($koneksi, "select namaperusahaan, alamat from perusahaan limit $mulai, $halaman");
foreach ($sql as $row) {
?>
<tr>
<td><?php echo $no++; ?></td>
<td>
<?php echo $row['namaperusahaan']; ?>
</td>
<td>
<?php echo $row['alamat']; ?>
</td>
</tr>
<?php }?>
</table>
<a href="tambah.php">
<span class="material-symbols-outlined">add</span>
</a>
</div>
<center>
<div class="pagination">
<?php for($i=1; $i<=$pages; $i++) : ?>
<a href="?halaman=<?=$i; ?>" style="text-decoration: none; margin:12px; color:black; font-size: 22px;"><?= $i; ?></a>
<?php endfor; ?>
</div>
</center>
</body>
</html>
akun.php
<?php
session_start();
if (!isset($_SESSION['is_login'])) {
header('location:login.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
<link rel="stylesheet" href="style4.css">
<title>Document</title>
</head>
<body>
<div class="navbar">
<h1>Aplikasi PKL</h1>
<nav>
<ul>
<li><a href="home.php">Home</a></li>
<li><a href="f01.php">Request F01</a></li>
<li>Account</li>
<li><a href="logout.php">Log Out</a></li>
</ul>
</nav>
</div>
<center>
<h1 style="margin: 50px;">Halo, <?php echo $_SESSION['nama']; ?></h1>
<h3>Ini status permintaan F01 anda</h3>
<br>
<table border="3" >
<tr>
<th style="font-size: 18px; padding: 10px;">Nama Lengkap</th>
<th style="font-size: 18px;">NIS</th>
<th style="font-size: 18px;">Tempat PKL</th>
<th style="font-size: 18px; padding: 10px;">Status F01</th>
</tr>
<tr>
<?php
include 'koneksi.php';
$nis = $_SESSION['username'];
$sql = mysqli_query($koneksi, "select nama, nis, namaperusahaan, status from f01 where nis=$nis");
foreach($sql as $row){
?>
<td style="font-size: 18px; padding: 10px;">
<?php echo $row['nama'];?>
</td>
<td style="font-size: 18px; padding:10px;">
<?php echo $row['nis'];?>
</td>
<td style="font-size: 18px; padding: 10px;">
<?php echo $row['namaperusahaan'];?>
</td>
<td align=center style="font-size: 18px; padding: 10px;">
<?php
if ($row['status']=="") {
echo 'Belum ada respon';
}elseif ($row['status']=="1") {
echo '<span class="material-symbols-outlined" style="color: green;">done</span>';
}else{
echo '<span class="material-symbols-outlined" style="color: red;">close</span>';
}
?>
</td>
<?php }?>
</tr>
</table>
</center>
</body>
</html>
f01.php
<?php
include 'koneksi.php';
if (isset($_POST['submit'])) {
if (add($_POST)>0) {
echo "<script>alert('F01 berhasil dibuat');
document.location.href = 'home.php';
</script>";
}else {
echo "<script>alert('Data gagal diinput');</script>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
<link rel="stylesheet" href="style3.css">
<title>F01 | Aplikasi PKL</title>
</head>
<body>
<div class="navbar">
<h1>Aplikasi PKL</h1>
<nav>
<ul>
<li><a href="home.php">Home</a></li>
<li>Request F01</li>
<li><a href="">Account</a></li>
</ul>
</nav>
</div>
<center>
<h1 style="margin: 50px;">Isi Data F01</h1>
<div class="satu">
<form action="" method="post">
<table>
<tr>
<td>Nama</td>
<td>:</td>
<td>
<input type="text" name="nama" id="nama" style="padding: 5px;">
</td>
</tr>
<tr>
<td>NIS</td>
<td>:</td>
<td>
<input type="text" name="nis" id="nis" style="padding: 5px;">
</td>
</tr>
<tr>
<td>Kelas</td>
<td>:</td>
<td>
<select name="kelas" id="kelas" style="padding: 5px;">
<option value="">...</option>
<option value="X">X</option>
<option value="XI">XI</option>
<option value="XII">XII</option>
</select>
</td>
</tr>
<tr>
<td>Jurusan</td>
<td>:</td>
<td>
<input type="text" name="jurusan" id="jurusan" style="padding: 5px;">
</td>
</tr>
<tr>
<td>Nomor Telepon</td>
<td>:</td>
<td>
<input type="text" name="telp" id="telp" style="padding: 5px;">
</td>
</tr>
<tr>
<td>Nama Perusahaan</td>
<td>:</td>
<td>
<select name="namaperusahaan" id="namaperusahaan" style="padding: 5px;">
<option value="">...</option>
<?php
$data = mysqli_query($koneksi, "select namaperusahaan from perusahaan");
foreach ($data as $row) {
?>
<option value="<?php echo $row['namaperusahaan']; ?>"><?php echo $row['namaperusahaan']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td>Alamat Perusahaan</td>
<td>:</td>
<td><input type="text" name="alamat" id="alamat" style="padding: 5px;"></td>
</tr>
<tr>
<td>Awal PKL</td>
<td>:</td>
<td><input type="date" name="awal" id="awal" style="padding: 5px;"></td>
</tr>
<tr>
<td>Akhir PKL</td>
<td>:</td>
<td><input type="date" name="akhir" id="akhir" style="padding: 5px;"></td>
</tr>
<tr>
<td>Nama Kontak Person</td>
<td>:</td>
<td><input type="text" name="namapengawas" id="namapengawas" style="padding: 5px;"></td>
</tr>
<tr>
<td>Jabatan</td>
<td>:</td>
<td><input type="text" name="jabatan" id="jabatan" style="padding: 5px;"></td>
</tr>
<tr>
<td>No. Handphone</td>
<td>:</td>
<td><input type="text" name="handphone" id="handphone" style="padding: 5px;"></td>
</tr>
<tr>
<td colspan="2"><button type="submit" name="submit" style="padding: 5px;">Input</button></td>
<td><button type="reset" style="padding: 5px;">Reset Ulang</button></td>
</tr>
</table>
</form>
</div>
</center>
</body>
</html>
admin.php
<?php
include 'koneksi.php';
if (isset($_GET['cari'])) {
$cari = $_GET['cari'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
<link rel="stylesheet" href="style5.css">
<title>Admin | Aplikasi PKL</title>
</head>
<body>
<div class="navbar">
<h1>Admin Aplikasi PKL</h1>
<nav>
<ul>
<li><form action="" method="get">
<input type="text" name="cari" placeholder="Nama NIS atau tempat PKL"><input type="submit" value="cari">
</form></li>
<li><a href="admin.php">Home</a></li>
<li><a href="logout.php">Log Out</a></li>
</ul>
</nav>
</div>
<center>
<h1 style="margin: 50px;">Daftar Permintaan F01</h1>
<table border="3">
<tr>
<th>Nama</th>
<th>NIS</th>
<th>Kelas</th>
<th>Jurusan</th>
<th>No. Telpon Siswa</th>
<th>Tempat PKL</th>
<th>Alamat Perusahaan</th>
<th>Mulai PKL</th>
<th>Selesai PKL</th>
<th>Status</th>
<th>Aksi</th>
</tr>
<?php
if(isset($_GET['cari'])){
$cari = $_GET['cari'];
$sql = mysqli_query($koneksi, "select nama, nis, kelas, jurusan, telp, namaperusahaan, alamat, awal, akhir, status from f01 where nis like '%$cari%' or nama like '%$cari%' or namaperusahaan like '%$cari%'");
echo "<b>Hasil Pencarian: ".$cari."";
}else{
$sql = mysqli_query($koneksi, "select nama, nis, kelas, jurusan, telp, namaperusahaan, alamat, awal, akhir, status from f01");
}
foreach ($sql as $row) {
?>
<tr>
<td>
<?php echo $row['nama'];?>
</td>
<td>
<?php echo $row['nis'];?>
</td>
<td>
<?php echo $row['kelas'];?>
</td>
<td>
<?php echo $row['jurusan'];?>
</td>
<td>
<?php echo $row['telp'];?>
</td>
<td>
<?php echo $row['namaperusahaan'];?>
</td>
<td>
<?php echo $row['alamat'];?>
</td>
<td>
<?php echo $row['awal'];?>
</td>
<td>
<?php echo $row['akhir'];?>
</td>
<td>
<?php
if ($row['status']=="") {
echo "Belum divalidasi";
}elseif ($row['status']=="1") {
echo "Sudah divalidasi";
}else{
echo "Di tolak";
}
?>
</td>
<td>
<a href="acc.php?nis=<?=$row['nis']?>"><span class="material-symbols-outlined">done</span></a>
<a href="hapus.php?nis=<?=$row['nis']?>"><span class="material-symbols-outlined">close</span></a>
</td>
</tr>
<?php }?>
</table>
</center>
</body>
</html>
acc.php
<?php
include 'koneksi.php';
$nis = $_GET['nis'];
if (acc($data)>0) {
echo "
<script>alert('data berhasil diubah');
document.location.href = 'admin.php';
</script>";
}else{
echo "
<script>alert('data gagal diubah');
document.location.href = 'admin.php';
</script>";
}
?>
hapus.php
<?php
include 'koneksi.php';
$nis = $_GET['nis'];
if (tolak($data)>0) {
echo "
<script>alert('Penolakan f01 telah dilakukan');
document.location.href = 'admin.php';
</script>";
}else{
echo "
<script>alert('gagal ditolak');
document.location.href = 'admin.php';
</script>";
}
?>
logout.php
<?php
session_start();
session_unset();
session_destroy();
setcookie('username', '', 0, '/');
setcookie('nama', '', 0, '/');
header('location:login.php');
?>
register.php
<?php
include 'koneksi.php';
if (isset($_POST['register'])) {
$username = $_POST['username'];
$password = password_hash($_POST['password'],PASSWORD_DEFAULT);
$nama = $_POST['nama'];
if (register($username, $password, $nama)) {
header('location:login.php');
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Register | Aplikasi PKL</title>
</head>
<body>
<h1>Sign Up</h1>
<h3>Silahkan isi data di bawah ini</h3>
<hr>
<form action="" method="post">
<table>
<tr>
<td>Username</td>
<td>
<input type="text" name="username" id="username" placeholder="NIS anda">
</td>
</tr>
<tr>
<td>Nama</td>
<td><input type="text" name="nama" id="nama" placeholder="Nama"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" id="password" placeholder="NIS anda"></td>
</tr>
<tr>
<td>
<button type="submit" name="register">Sign Up</button>
</td>
</tr>
<tr>
<td colspan="3">
<a href="login.php">Sudah punya akun? Klik untuk login</a>
</td>
</tr>
</table>
</form>
</body>
</html>
tambah.php
<?php
include 'koneksi.php';
if (isset($_POST['submit'])) {
if (tambah($_POST)>0) {
echo "<script>alert('Data berhasil ditambah');
document.location.href = 'home.php';
</script>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
<link rel="stylesheet" href="style2.css">
<title>Halaman Utama | Aplikasi PKL</title>
</head>
<body>
<div class="navbar">
<h1>Aplikasi PKL</h1>
<nav>
<ul>
<li><a href="home.php">Home</a></li>
<li><a href="">Request F01</a></li>
</ul>
</nav>
</div>
<center>
<h1>Tambah Data Perusahaan</h1>
</center>
<center>
<form action="" method="post">
<table>
<tr>
<td>Nama Perusahaan</td>
<td>:</td>
<td>
<input type="text" name="namaperusahaan" id="namaperusahaan">
</td>
</tr>
<tr>
<td>Alamat</td>
<td>:</td>
<td>
<input type="text" name="alamat" id="alamat">
</td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td>
<input type="email" name="email" id="email">
</td>
</tr>
<tr>
<td>Website</td>
<td>:</td>
<td>
<input type="text" name="website" id="website">
</td>
</tr>
<tr>
<td colspan="2">
<button type="submit" name="submit">Tambah</button>
</td>
<td>
<button type="reset">Reset Ulang</button>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
CSS
style.css
@font-face {
font-family: 'biasa';
src: url(../Font/Mont-HeavyDEMO.otf);
}
@font-face {
font-family: 'normal';
src: url(../Font/Mont-ExtraLightDEMO.otf);
}
*{
font-family: 'biasa';
}
h3{
font-family: 'normal';
}
style2.css
@font-face {
font-family: 'biasa';
src: url(../Font/Mont-HeavyDEMO.otf);
}
@font-face {
font-family: 'normal';
src: url(../Font/Mont-ExtraLightDEMO.otf);
}
*{
font-family: 'biasa';
margin: 0;
padding: 0;
}
.navbar{
display: flex;
justify-content: space-between;
background-color: #E97777;
padding: 30px;
}
.navbar h1{
font-size: 40px;
}
.navbar nav ul {
display: flex;
justify-content: center;
}
.navbar nav ul li{
margin-right: 30px;
margin: 20px;
list-style: none;
}
.navbar nav ul li a{
text-decoration: none;
color: black;
}
.navbar nav ul li:hover, .navbar nav ul li a:hover{
color: white;
}
.meaning{
display: flex;
justify-content: center;
margin: 30px;
}
.meaning a{
background-color: #E97777;
color: black;
margin: 10px;
padding: 10px;
border-radius: 40px;
height: min-content;
}
.meaning a:hover{
color: white;
}
table tr td{
padding: 20px;
}
style3.css
@font-face {
font-family: 'biasa';
src: url(../Font/Mont-HeavyDEMO.otf);
}
@font-face {
font-family: 'normal';
src: url(../Font/Mont-ExtraLightDEMO.otf);
}
*{
font-family: 'biasa';
margin: 0;
padding: 0;
}
.navbar{
display: flex;
justify-content: space-between;
background-color: #E97777;
padding: 30px;
}
.navbar h1{
font-size: 40px;
}
.navbar nav ul {
display: flex;
justify-content: center;
}
.navbar nav ul li{
margin-right: 30px;
margin: 20px;
list-style: none;
}
.navbar nav ul li a{
text-decoration: none;
color: black;
}
.navbar nav ul li:hover, .navbar nav ul li a:hover{
color: white;
}
style4.css
@font-face {
font-family: 'biasa';
src: url(../Font/Mont-HeavyDEMO.otf);
}
@font-face {
font-family: 'normal';
src: url(../Font/Mont-ExtraLightDEMO.otf);
}
*{
font-family: 'biasa';
margin: 0;
padding: 0;
}
.navbar{
display: flex;
justify-content: space-between;
background-color: #E97777;
padding: 30px;
}
.navbar h1{
font-size: 40px;
}
.navbar nav ul {
display: flex;
justify-content: center;
}
.navbar nav ul li{
margin-right: 30px;
margin: 20px;
list-style: none;
}
.navbar nav ul li a{
text-decoration: none;
color: black;
}
.navbar nav ul li:hover, .navbar nav ul li a:hover{
color: white;
}
style5.css
@font-face {
font-family: 'biasa';
src: url(../Font/Mont-HeavyDEMO.otf);
}
@font-face {
font-family: 'normal';
src: url(../Font/Mont-ExtraLightDEMO.otf);
}
*{
font-family: 'biasa';
margin: 0;
padding: 0;
}
.navbar{
display: flex;
justify-content: space-between;
background-color: #E97777;
padding: 30px;
}
.navbar h1{
font-size: 40px;
}
.navbar nav ul {
display: flex;
justify-content: center;
}
.navbar nav ul li{
margin-right: 30px;
margin: 20px;
list-style: none;
}
.navbar nav ul li a{
text-decoration: none;
color: black;
}
.navbar nav ul li:hover, .navbar nav ul li a:hover{
color: white;
cursor: pointer;
}
table{
margin: 12px;
}
table tr th{
padding: 10px;
}
table tr td{
padding: 10px;
}
style6.css
@font-face {
font-family: 'biasa';
src: url(../Font/Mont-HeavyDEMO.otf);
}
@font-face {
font-family: 'normal';
src: url(../Font/Mont-ExtraLightDEMO.otf);
}
*{
font-family: 'biasa';
}
table{
border: 3px solid black;
border-radius: 12px;
margin: 50px;
padding: 50px;
}
button{
padding: 5px;
}
Comments
Post a Comment