Nama: Zico Ritonda Bahen
NRP: 05111740000064Kelas: C
1. Rancangan database:
Terdapat 2 database yang saya buat yitu,
2. Rancangan Interface aplikasi:
Saya menggunakan Codeigniter dan Bootstrap dalam pembuatannya. Saya menggunakan template SB Admin.
Login:
Halaman Admin:
Halaman User
3. Implementasi
Pada project ini saya menggunakan Framework Codeigniter.
Berikut sebagian source code yang telah saya buat:
Controllers:
Auth.php:
<?php
class Auth extends CI_Controller{
public function logout()
{
unset($_SESSION);
session_destroy();
redirect("auth/login","refresh");
}
public function login(){
$this->load->view('login');
//echo 'login';
$this->form_validation->set_rules('username','Username','required');
$this->form_validation->set_rules('password','Password','required|min_length[8]');
if($this->form_validation->run() == TRUE){
$username = $_POST['username'];
$password = md5($_POST['password']);
//check user in database
$this->db->select('*');
$this->db->from('users');
$this->db->where(array('username' => $username, 'password' => $password));
$query = $this->db->get();
$user = $query->row();
//if user exist
if($user->NIK){
//temporary massage
$this->session->set_flashdata("success", "Logged in");
//set session variable
$_SESSION['user_logged'] = TRUE;
$_SESSION['username'] = $user->username;
$_SESSION['nik'] = $user->NIK;
$_SESSION['nisn'] = $user->NISN;
$_SESSION['nama'] = $user->nama;
$_SESSION['alamat'] = $user->alamat;
$_SESSION['provinsi'] = $user->provinsi;
$_SESSION['kota'] = $user->kota;
$_SESSION['kecamatan'] = $user->kecamatan;
$_SESSION['kelurahan'] = $user->kelurahan;
$_SESSION['agama'] = $user->agama;
$_SESSION['ttl'] = $user->ttl;
$_SESSION['jk'] = $user->jk;
$_SESSION['tlp'] = $user->tlp;
$_SESSION['sekolah_asal'] = $user->sekolah_asal;
$_SESSION['sekolah_tujuan'] = $user->sekolah_tujuan;
$_SESSION['nama_ayah'] = $user->nama_ayah;
$_SESSION['nama_ibu'] = $user->nama_ibu;
$_SESSION['wali'] = $user->wali;
//redirect to profile page
redirect("user/profile","refresh");
}
else{
$this->session->set_flashdata("error","Akun belum terdaftar");
redirect("auth/login","refresh");
}
}
}
public function register(){
if(isset($_POST['daftar'])){
$this->form_validation->set_rules('username','Username','required');
$this->form_validation->set_rules('password','Password','required|min_length[8]');
$this->form_validation->set_rules('password','Confirm Password','required|min_length[8]|matches[password]');
$this->form_validation->set_rules('nik','NIK','required');
$this->form_validation->set_rules('nisn','NISN','required');
$this->form_validation->set_rules('nama','Nama','required');
$this->form_validation->set_rules('alamat','Alamat','required');
$this->form_validation->set_rules('provinsi','Provinsi','required');
$this->form_validation->set_rules('kota','Kota','required');
$this->form_validation->set_rules('kecamatan','Kecamatan','required');
$this->form_validation->set_rules('kelurahan','Kelurahan','required');
//jika form validation true
if($this->form_validation->run() == TRUE){
echo 'form-validated';
//add to database
$data = array(
'id_user'=> uniqid(),
'username'=>$_POST['username'],
'password'=>md5($_POST['password']),
'nik'=>$_POST['nik'],
'nisn'=>$_POST['nisn'],
'nama'=>$_POST['nama'],
'jk'=>$_POST['jk'],
'alamat'=>$_POST['alamat'],
'provinsi'=>$_POST['provinsi'],
'kota'=>$_POST['kota'],
'kecamatan'=>$_POST['kecamatan'],
'kelurahan'=>$_POST['kelurahan'],
);
$this->db->insert('users',$data);
$this->session->set_flashdata("success","Akun anda telah diregister. Silahkan login sekarang.");
redirect("auth/register","refresh");
}
}
//load view
$this->load->view('register');
}
}
User.php:
<?php
class User extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->model("user_model");
$this->load->library('form_validation');
if($_SESSION['user_logged'] == FALSE){
$this->session->set_flashdata("error", "Silahkan Login terlebih dahulu");
redirect("auth/login");
}
}
public function profile(){
$this->load->view('profile');
}
public function getById($id)
{
return $this->db->get_where($this->_table, ["username" => $id])->row();
}
public function edit($id = null)
{
if (!isset($id)) redirect('user');
$user = $this->user_model;
$validation = $this->form_validation;
$validation->set_rules($product->rules());
if ($validation->run()) {
$product->update();
$this->session->set_flashdata('success', 'Berhasil disimpan');
}
$data["user"] = $user->getById($id);
if (!$data["user"]) show_404();
$this->load->view("edit_profile", $data);
}
}
Models:
User_model.php:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class User_model extends CI_Model
{
private $_table = "users";
public $id_user;
public $nisn;
public $nik;
public $nama;
public $alamat;
public $provinsi;
public $kota;
public $kecamatan;
public $kelurahan;
public $agama;
public $ttl;
public $jk;
public $tlp;
public $sekolah_asal;
public $sekolah_tujuan;
public $nama_ayah;
public $nama_ibu;
public $wali;
public $username;
public $password;
public function rules()
{
return [
['field' => 'username',
'label' => 'username',
'rules' => 'required'],
['field' => 'nisn',
'label' => 'NISN',
'rules' => 'numeric'],
['field' => 'nik',
'label' => 'NIK',
'rules' => 'required'],
['field' => 'nama',
'label' => 'Nama',
'rules' => 'required'],
['field' => 'alamat',
'label' => 'Alamat',
'rules' => 'required'],
['field' => 'provinsi',
'label' => 'Provinsi',
'rules' => 'required'],
['field' => 'kota',
'label' => 'Kota',
'rules' => 'required'],
['field' => 'kecamatan',
'label' => 'Kecamatan',
'rules' => 'required'],
['field' => 'kelurahan',
'label' => 'Kelurahan',
'rules' => 'required'],
['field' => 'agama',
'label' => 'Agama',
'rules' => 'required'],
['field' => 'ttl',
'label' => 'Tempat, Tanggal Lahir',
'rules' => 'required'],
['field' => 'tlp',
'label' => 'No. Telepon',
'rules' => 'required'],
['field' => 'sekolah_asal',
'label' => 'Sekolah Asal',
'rules' => 'required'],
['field' => 'nama_ayah',
'label' => 'Nama Ayah',
'rules' => 'required'],
['field' => 'nama_ayah',
'label' => 'Nama Ayah',
'rules' => 'required'],
['field' => 'nama_ibu',
'label' => 'Nama Ibu',
'rules' => 'required'],
['field' => 'wali',
'label' => 'Wali',
'rules' => 'required'],
];
}
public function getAll()
{
return $this->db->get($this->_table)->result();
}
public function getById($id)
{
return $this->db->get_where($this->_table, ["id_user" => $id])->row();
}
public function save()
{
$post = $this->input->post();
$this->id_user = uniqid();
$this->kelurahan = $post["username"];
$this->nisn = $post["nisn"];
$this->nik = $post["nik"];
$this->nama = $post["nama"];
$this->alamat = $post["alamat"];
$this->provinsi = $post["provinsi"];
$this->kota = $post["kota"];
$this->kecamatan = $post["kecamatan"];
$this->kelurahan = $post["kelurahan"];
$this->kelurahan = $post["agama"];
$this->kelurahan = $post["ttl"];
$this->kelurahan = $post["jk"];
$this->kelurahan = $post["tlp"];
$this->kelurahan = $post["sekolah_asal"];
$this->kelurahan = $post["sekolah_tujuan"];
$this->kelurahan = $post["nama_ayah"];
$this->kelurahan = $post["nama_ibu"];
$this->kelurahan = $post["wali"];
$this->db->insert($this->_table, $this);
}
public function update()
{
$post = $this->input->post();
$this->username = $post["user"];
$this->nisn = $post["nisn"];
$this->nik = $post["nik"];
$this->nama = $post["nama"];
$this->alamat = $post["alamat"];
$this->provinsi = $post["provinsi"];
$this->kota = $post["kota"];
$this->kecamatan = $post["kecamatan"];
$this->kelurahan = $post["kelurahan"];
$this->kelurahan = $post["agama"];
$this->kelurahan = $post["ttl"];
$this->kelurahan = $post["jk"];
$this->kelurahan = $post["tlp"];
$this->kelurahan = $post["sekolah_asal"];
$this->kelurahan = $post["sekolah_tujuan"];
$this->kelurahan = $post["nama_ayah"];
$this->kelurahan = $post["nama_ibu"];
$this->kelurahan = $post["wali"];
$this->db->update($this->_table, $this, array('id_user' => $post['id']));
}
/*public function delete($id)
{
return $this->db->delete($this->_table, array("id_user" => $id));
}*/
}
View:
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, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title><?php echo SITE_NAME; ?> - Login</title>
<!-- Bootstrap core CSS-->
<link href="<?php echo base_url('assets/bootstrap/css/bootstrap.min.css') ?>" rel="stylesheet">
<!--<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">-->
<!-- Custom fonts for this template-->
<link href="<?php echo base_url('assets/fontawesome-free/css/all.min.css') ?>" rel="stylesheet" type="text/css">
<!--<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">-->
<!-- Custom styles for this template-->
<link href="<?php echo base_url('css/sb-admin.css') ?>" rel="stylesheet">
<!--<link href="css/sb-admin.css" rel="stylesheet">-->
</head>
<body class="bg-white">
<div class="container">
<div class="card card-login mx-auto mt-5">
<div class="card-header text-center">Login</div>
<div class="card-body">
<?php if(isset($_SESSION['success'])) { ?>
<div class="alert alert-success"> <?php echo $_SESSION['success'];?></div>
<?php } ?>
<?php echo validation_errors('<div class="alert alert-danger">','</div>'); ?>
<form action="" method="POST">
<div class="form-group">
<div class="form-label-group">
<input name="username" type="text" id="username" class="form-control" placeholder="Username" required="required" autofocus="autofocus">
<label for="username">Username</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input name="password" type="password" id="password" class="form-control" placeholder="Password" required="required">
<label for="password">Password</label>
</div>
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me">
Remember Password
</label>
</div>
</div>
<button class="btn btn-primary btn-block" name="login"> Login</button>
</form>
<div class="text-center">
<a class="d-block small mt-3" href="<?php echo base_url(); ?>index.php/auth/register">Daftar</a>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript-->
<script src="<?php echo base_url('assets/jquery/jquery.min.js') ?>"></script>
<script src="<?php echo base_url('assets/bootstrap/js/bootstrap.bundle.min.js') ?>"></script>
<!--<script src="vendor/jquery/jquery.min.js"></script>-->
<!--<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>-->
<!-- Core plugin JavaScript-->
<script src="<?php echo base_url('assets/jquery-easing/jquery.easing.min.js') ?>"></script>
<!--<script src="vendor/jquery-easing/jquery.easing.min.js"></script>-->
</body>
</html>
register.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, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>SB Admin - Register</title>
<!-- Bootstrap core CSS-->
<link href="<?php echo base_url('assets/bootstrap/css/bootstrap.min.css') ?>" rel="stylesheet">
<!--<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">-->
<!-- Custom fonts for this template-->
<link href="<?php echo base_url('assets/fontawesome-free/css/all.min.css') ?>" rel="stylesheet" type="text/css">
<!--<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">-->
<!-- Custom styles for this template-->
<link href="<?php echo base_url('css/sb-admin.css') ?>" rel="stylesheet">
<!--<link href="css/sb-admin.css" rel="stylesheet">-->
</head>
<body class="bg-white">
<div class="container">
<div class="card card-register mx-auto mt-5">
<div class="card-header">Daftar Akun</div>
<div class="card-body">
<?php if(isset($_SESSION['success'])) { ?>
<div class="alert alert-success"> <?php echo $_SESSION['success'];?></div>
<?php } ?>
<?php echo validation_errors('<div class="alert alert-danger">','</div>'); ?>
<form action="" method="POST">
<div class="form-group">
<div class="form-label-group">
<input name="username" id="username" class="form-control" placeholder="Username" required="required" type="text">
<label for="username">Username</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input name="password" id="password" class="form-control" placeholder="Password" required="required" type="password">
<label for="password">Password</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input name="password2" id="password" class="form-control" placeholder="Password" required="required" type="password">
<label for="password">Confirm Password</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input name="nik" type="text" id="nik" class="form-control" placeholder="NIK" required="required">
<label for="nik">NIK</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input name="nisn" type="text" id="nisn" class="form-control" placeholder="NISN" required="required">
<label for="nisn">NISN</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input name="nama" type="text" id="nama" class="form-control" placeholder="Nama" required="required">
<label for="nama">Nama</label>
</div>
</div>
<div class="form-group">
<label for="jk">Jenis Kelamin</label>
<select class="form-control" id="jk" name="jk">
<option value="Laki-Laki">Laki-Laki</option>
<option value="Perempuan">Perempuan</option>
</select>
</div>
<div class="form-group">
<div class="form-label-group">
<input name="alamat" type="text" id="alamat" class="form-control" placeholder="Alamat" required="required">
<label for="alamat">Alamat</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input name="provinsi" type="text" id="provinsi" class="form-control" placeholder="Provinsi" required="required">
<label for="provisi">Provinsi</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input name="kota" type="text" id="kota" class="form-control" placeholder="Kota" required="required">
<label for="kota">Kota</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input name="kecamatan" type="text" id="kecamatan" class="form-control" placeholder="Kecamatan" required="required">
<label for="kecamatan">Kecamatan</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input name="kelurahan" type="text" id="kelurahan" class="form-control" placeholder="Kelurahan" required="required">
<label for="kelurahan">Kelurahan</label>
</div>
</div>
<!--<a class="btn btn-primary btn-block" href="login.html">Daftar</a>-->
<div class="text-center">
<button class="btn btn-primary" name="daftar">Daftar</button>
</div>
</form>
<div class="text-center">
<a class="d-block small mt-3" href="<?php echo base_url(); ?>index.php/auth/login">Halaman Login</a>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript-->
<script src="<?php echo base_url('assets/jquery/jquery.min.js') ?>"></script>
<script src="<?php echo base_url('assets/bootstrap/js/bootstrap.bundle.min.js') ?>"></script>
<!--<script src="vendor/jquery/jquery.min.js"></script>-->
<!--<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>-->
<!-- Core plugin JavaScript-->
<script src="<?php echo base_url('assets/jquery-easing/jquery.easing.min.js') ?>"></script>
<!--<script src="vendor/jquery-easing/jquery.easing.min.js"></script>-->
</body>
</html>
/user/overview.php:
<!DOCTYPE html>
<html lang="en">
<head>
<?php $this->load->view("user/index/_partials/head.php") ?>
</head>
<body id="page-top">
<?php $this->load->view("user/index/_partials/navbar.php") ?>
<div id="wrapper">
<?php $this->load->view("user/index/_partials/sidebar.php") ?>
<div id="content-wrapper">
<div class="container-fluid">
<!--
karena ini halaman overview (home), kita matikan partial breadcrumb.
Jika anda ingin mengampilkan breadcrumb di halaman overview,
silahkan hilangkan komentar (//) di tag PHP di bawah.
-->
<?php //$this->load->view("admin/_partials/breadcrumb.php") ?>
<!-- Icon Cards-->
<!--<div class="row">
<div class="col-xl-3 col-sm-6 mb-3">
<div class="card text-white bg-primary o-hidden h-100">
<div class="card-body">
<div class="card-body-icon">
<i class="fas fa-fw fa-comments"></i>
</div>
<div class="mr-5">26 New Messages!</div>
</div>
<a class="card-footer text-white clearfix small z-1" href="#">
<span class="float-left">View Details</span>
<span class="float-right">
<i class="fas fa-angle-right"></i>
</span>
</a>
</div>
</div>
<div class="col-xl-3 col-sm-6 mb-3">
<div class="card text-white bg-warning o-hidden h-100">
<div class="card-body">
<div class="card-body-icon">
<i class="fas fa-fw fa-list"></i>
</div>
<div class="mr-5">11 New Tasks!</div>
</div>
<a class="card-footer text-white clearfix small z-1" href="#">
<span class="float-left">View Details</span>
<span class="float-right">
<i class="fas fa-angle-right"></i>
</span>
</a>
</div>
</div>
<div class="col-xl-3 col-sm-6 mb-3">
<div class="card text-white bg-success o-hidden h-100">
<div class="card-body">
<div class="card-body-icon">
<i class="fas fa-fw fa-shopping-cart"></i>
</div>
<div class="mr-5">123 New Orders!</div>
</div>
<a class="card-footer text-white clearfix small z-1" href="#">
<span class="float-left">View Details</span>
<span class="float-right">
<i class="fas fa-angle-right"></i>
</span>
</a>
</div>
</div>
<div class="col-xl-3 col-sm-6 mb-3">
<div class="card text-white bg-danger o-hidden h-100">
<div class="card-body">
<div class="card-body-icon">
<i class="fas fa-fw fa-life-ring"></i>
</div>
<div class="mr-5">13 New Tickets!</div>
</div>
<a class="card-footer text-white clearfix small z-1" href="#">
<span class="float-left">View Details</span>
<span class="float-right">
<i class="fas fa-angle-right"></i>
</span>
</a>
</div>
</div>
</div>-->
<!-- Data Area-->
<div class="card mb-3">
<div class="card-header">
<i class="fas fa-user-circle"></i>
Profil Calon Siswa</div>
<div class="card-body">
<span>NISN : <?php echo $_SESSION['nisn']; ?></span><br>
<span>NIK : <?php echo $_SESSION['nik']; ?></span><br>
<span>Nama : <?php echo $_SESSION['nama']; ?></span><br>
<span>Jenis Kelamin : <?php echo $_SESSION['jk']; ?></span><br>
<span>Tempat, Tanggal Lahir : <?php echo $_SESSION['ttl']; ?></span><br>
<span>Agama : <?php echo $_SESSION['agama']; ?></span><br>
<span>Nama Ayah: <?php echo $_SESSION['nama_ayah']; ?></span><br>
<span>Nama Ibu : <?php echo $_SESSION['nama_ibu']; ?></span><br>
<span>Nama Wali : <?php echo $_SESSION['wali']; ?></span><br>
<span>No Telepon: <?php echo $_SESSION['tlp']; ?></span><br>
<span>Sekolah Asal: <?php echo $_SESSION['sekolah_asal']; ?></span><br>
<span>Sekolah Tujuan: <?php echo $_SESSION['sekolah_tujuan']; ?></span><br>
<span>Alamat : <?php echo $_SESSION['alamat']; ?></span><br>
<span>Provinsi : <?php echo $_SESSION['provinsi']; ?></span><br>
<span>Kota : <?php echo $_SESSION['kota']; ?></span><br>
<span>Kecamatan : <?php echo $_SESSION['kecamatan']; ?></span><br>
<span>Kelurahan : <?php echo $_SESSION['kelurahan']; ?></span><br>
</div>
<a class="btn btn-danger" href="<?php echo base_url(); ?>index.php/auth/edit">Edit</a>
</div>
</div>
<!-- /.container-fluid -->
<!-- Sticky Footer -->
<?php $this->load->view("user/index/_partials/footer.php") ?>
</div>
<!-- /.content-wrapper -->
</div>
<!-- /#wrapper -->
<?php $this->load->view("user/index/_partials/scrolltop.php") ?>
<?php $this->load->view("user/index/_partials/modal.php") ?>
<?php $this->load->view("user/index/_partials/js.php") ?>
</body>
</html>
Berikut tampilan dari web yang saya buat:
Fitur yang belum sempat saya buat adalah melakukan edit pada data calon siswa.
Link Web: imagi3d.com/index.php/auth/login
Berikut merupakan video demo web saya :
Komentar
Posting Komentar