Membuat Aplikasi Klinik #22 - Module Profile
Sesi ini merupakan sesi terkahir dari rangkaian tutorial membuat aplikasi klinik berbasis web. Jadi disini kita akan membuat module profile untuk mempermudah pengguna mengganti profile dari mulai email, password dan foto yang digunakan.
Lihat sebelumnya : Membuat Aplikasi Klinik #21 - Module Dokter
Langkah pertama Anda bisa membuat file baru pada folder admin dengan nama Profile.php
<?php
class Profile
{
public function myprofile($path,$user)
{
?>
<?php
$this->err = array();
if($_SERVER['REQUEST_METHOD']=='POST')
{
if(empty($this->app->post('email')))
{
array_push($this->err, "email wajib diisi !");
}
elseif($this->app->vldEmail($this->app->post('email')))
{
array_push($this->err, "Format email tidak benar");
}
else
{
if($user['email']!=$this->app->post('email'))
{
if($this->obj->cekData('email','users', $this->app->post('email')))
{
array_push($this->err,"Email tersebut sudah ada");
}
else
{
$email = $this->app->post('email');
}
}
else
{
$email = $this->app->post('email');
}
}
if(!empty($_POST['password']))
{
if(strlen($_POST['password'])<6) {
array_push($this->err, "Password tidak boleh kurang dari 6 karakter");
}
else
{
$password = $_POST['password'];
}
}
if(empty($this->app->post('nama_lengkap')))
{
array_push($this->err, "Nama lengkap tidak boleh kosong");
}
else
{
$nama_lengkap = $this->app->post('nama_lengkap');
}
if(!empty($_FILES['photo']['name']))
{
$this->upload->createImage('photo','../content/');
if(!in_array($this->upload->file_extension, $this->upload->file_valid))
{
array_push($this->err, "Format gambar tidak sesuai, harap masukan format jpeg, jpg atau png");
}
else
{
if($this->upload->file_size>300000)
{
array_push($this->err, "File tidak boleh lebih dari 300 kb");
}
}
}
if(count($this->err)==0)
{
if(!empty($_FILES['photo']['name']))
{
if(move_uploaded_file($this->upload->file_tmp, $this->upload->file_dir.$this->upload->file_item))
{
if(empty($_POST['password']))
{
if($this->obj->updateTable('users',
'email=:email,
nama_lengkap=:nama_lengkap,
photo=:photo
','user_id=:user_id',
array(
":email"=>$email,
":nama_lengkap"=>$nama_lengkap,
":photo"=>$this->upload->file_item,
":user_id"=>$user['user_id']
)
))
{
$this->success= $this->app->alert('success','Data berhasil disimpane');
//
$this->app->reload(3,'?page=profile');
}
else
{
$this->success = $this->app->alert('danger','User gagal diperbaharui');
$this->app->reload(3,'?page=profile');
}
}
else
{
if($this->obj->updateTable('users',
'email=:email,
password=:password,
nama_lengkap=:nama_lengkap,
photo=:photo
','user_id=:user_id',
array(
":email"=>$email,
":password"=>password_hash($password,PASSWORD_DEFAULT),
":nama_lengkap"=>$nama_lengkap,
":photo"=>$this->upload->file_item,
":user_id"=>$user['user_id']
)
))
{
$this->success= $this->app->alert('success','Data berhasil disimpan');
$this->app->reload(3,'?page=profile');
}
else
{
$this->success = $this->app->alert('danger','Data gagal diperbaharui');
$this->app->reload(3,'?page=profile');
}
}
}
else
{
$this->success = $this->app->alert('danger', 'Foto gagal diperbaharui');
$this->app->reload(3);
}
}
else
{
if(empty($_POST['password']))
{
if($this->obj->updateTable('users',
'email=:email,
nama_lengkap=:nama_lengkap
','user_id=:user_id',
array(
":email"=>$email,
":nama_lengkap"=>$nama_lengkap,
":user_id"=>$user['user_id']
)
))
{
$this->success= $this->app->alert('success','Data berhasil disimpane');
//
$this->app->reload(3,'?page=profile');
}
else
{
$this->success = $this->app->alert('danger','User gagal diperbaharui');
$this->app->reload(3,'?page=profile');
}
}
else
{
if($this->obj->updateTable('users',
'email=:email,
password=:password,
nama_lengkap=:nama_lengkap
','user_id=:user_id',
array(
":email"=>$email,
":password"=>password_hash($password,PASSWORD_DEFAULT),
":nama_lengkap"=>$nama_lengkap,
":user_id"=>$user['user_id']
)
))
{
$this->success= $this->app->alert('success','Data berhasil disimpan');
$this->app->reload(3,'?page=profile');
}
else
{
$this->success = $this->app->alert('danger','Data gagal diperbaharui');
$this->app->reload(3,'?page=profile');
}
}
}
}
else
{
$this->app->noresubmit();
}
}
?>
<div class="content-wrapper">
<?=$this->app->bread('Edit Profile','Home','?page=home')?>
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<?php
if(count($this->err)>0)
{
$this->app->getError($this->err);
}
?>
<div class="card card-primary">
<div class="card-header">
<h3 class="card-title">Edit user</h3>
</div>
<form action="<?php htmlentities($_SERVER['REQUEST_URI'])?>" method="post" enctype="multipart/form-data">
<div class="card-body">
<?=$this->success?>
<div class="row">
<div class="form-group col-md-6">
<label>Email</label>
<input type="text" name="email" value="<?=$user['email']?>" class="form-control" placeholder="Masukan email" required="">
</div>
<div class="form-group col-md-6">
<label>Password</label>
<input type="password" name="password" class="form-control" placeholder="Masukan password">
</div>
</div>
<div class="form-group">
<label>Nama lengkap</label>
<input type="text" name="nama_lengkap" value="<?=$user['nama_lengkap']?>" class="form-control" placeholder="Masukan nama_lengkap" required="">
</div>
<div class="form-group">
<label for="exampleInputFile">Photo</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="photo" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
<img src="../content/<?=$user['photo']?>" height="80px" width="80px" />
</div>
<div class="form-group">
<button type="submit" class="btn btn-md btn-primary">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
</div>
<?php
}
}
Kedua Anda perlu memodifikasi navigasi sidebar baik untuk role admin, administrasi dan dokter :
Navadmin.php
public function admin_sidebar($path='', $user='')
{
?>
<!-- Main Sidebar Container -->
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<!-- Brand Logo -->
<a href="?page=home" class="brand-link">
<img src="<?=$path?>content/web/<?=$this->info['klinik_logo']?>" alt="AdminLTE Logo" class="brand-image img-circle elevation-3" style="opacity: .8">
<span class="brand-text font-weight-light"><?=$this->info['klinik_name']?></span>
</a>
<!-- Sidebar -->
<div class="sidebar">
<!-- Sidebar user panel (optional) -->
<div class="user-panel mt-3 pb-3 mb-3 d-flex">
<div class="image">
<img src="<?=$path?>content/<?=$user['photo']?>" class="img-circle elevation-2" alt="User Image">
</div>
<div class="info">
<a href="#" class="d-block"><?=$user['nama_lengkap']?></a>
<a href="?page=profile" class="d-block">Edit</a>
</div>
</div>
<!-- SidebarSearch Form -->
<div class="form-inline">
<div class="input-group" data-widget="sidebar-search">
<input class="form-control form-control-sidebar" type="search" placeholder="Search" aria-label="Search">
<div class="input-group-append">
<button class="btn btn-sidebar">
<i class="fas fa-search fa-fw"></i>
</button>
</div>
</div>
</div>
<!-- Sidebar Menu -->
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<!-- Add icons to the links using the .nav-icon class
with font-awesome or any other icon font library -->
<li class="nav-item">
<a href="?page=home" class="nav-link active">
<i class="nav-icon fas fa-tachometer-alt"></i>
<p>
Dashboard
</p>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="nav-icon fas fa-chart-pie"></i>
<p>
Pasien
<i class="right fas fa-angle-left"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="?page=semua_pasien" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Semua pasien</p>
</a>
</li>
<li class="nav-item">
<a href="?page=pasien_tambah" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Tambah pasien</p>
</a>
</li>
</ul>
</li>
<li class="nav-item">
<a href="?page=antrian" class="nav-link">
<i class="nav-icon fas fa-copy"></i>
<p>
Antrian
</p>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="nav-icon fas fa-unlock-alt"></i>
<p>
Role
<i class="right fas fa-angle-left"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="?page=semua_role" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Semua role</p>
</a>
</li>
<li class="nav-item">
<a href="?page=role_tambah" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Tambah role</p>
</a>
</li>
</ul>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="nav-icon fas fa-users"></i>
<p>
Users
<i class="right fas fa-angle-left"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="?page=semua_pengguna" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Semua pengguna</p>
</a>
</li>
<li class="nav-item">
<a href="?page=user_tambah" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Tambah pengguna</p>
</a>
</li>
</ul>
</li>
<li class="nav-header">PENGATURAN</li>
<li class="nav-item">
<a href="?page=profile_klinik" class="nav-link">
<i class="nav-icon fas fa-cogs"></i>
<p>
Profile Klinik
</p>
</a>
</li>
</ul>
</nav>
<!-- /.sidebar-menu -->
</div>
<!-- /.sidebar -->
</aside>
<?php
}
Navadministrasi.php
public function administrasi_sidebar($path='', $user='')
{
?>
<!-- Main Sidebar Container -->
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<!-- Brand Logo -->
<a href="?page=home" class="brand-link">
<img src="<?=$path?>content/web/<?=$this->info['klinik_logo']?>" alt="AdminLTE Logo" class="brand-image img-circle elevation-3" style="opacity: .8">
<span class="brand-text font-weight-light"><?=$this->info['klinik_name']?></span>
</a>
<!-- Sidebar -->
<div class="sidebar">
<!-- Sidebar user panel (optional) -->
<div class="user-panel mt-3 pb-3 mb-3 d-flex">
<div class="image">
<img src="<?=$path?>content/<?=$user['photo']?>" class="img-circle elevation-2" alt="User Image">
</div>
<div class="info">
<a href="#" class="d-block"><?=$user['nama_lengkap']?></a>
<a href="?page=profile" class="d-block">Edit</a>
</div>
</div>
<!-- SidebarSearch Form -->
<div class="form-inline">
<div class="input-group" data-widget="sidebar-search">
<input class="form-control form-control-sidebar" type="search" placeholder="Search" aria-label="Search">
<div class="input-group-append">
<button class="btn btn-sidebar">
<i class="fas fa-search fa-fw"></i>
</button>
</div>
</div>
</div>
<!-- Sidebar Menu -->
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<!-- Add icons to the links using the .nav-icon class
with font-awesome or any other icon font library -->
<li class="nav-item">
<a href="?page=home" class="nav-link active">
<i class="nav-icon fas fa-tachometer-alt"></i>
<p>
Dashboard
</p>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="nav-icon fas fa-chart-pie"></i>
<p>
Pasien
<i class="right fas fa-angle-left"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="?page=semua_pasien" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Semua pasien</p>
</a>
</li>
<li class="nav-item">
<a href="?page=pasien_tambah" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Tambah pasien</p>
</a>
</li>
</ul>
</li>
<li class="nav-item">
<a href="?page=antrian" class="nav-link">
<i class="nav-icon fas fa-copy"></i>
<p>
Antrian
</p>
</a>
</li>
</ul>
</nav>
<!-- /.sidebar-menu -->
</div>
<!-- /.sidebar -->
</aside>
<?php
}
Navdokter.php
public function dokter_sidebar($path='', $user='')
{
?>
<!-- Main Sidebar Container -->
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<!-- Brand Logo -->
<a href="?page=home" class="brand-link">
<img src="<?=$path?>content/web/<?=$this->info['klinik_logo']?>" alt="AdminLTE Logo" class="brand-image img-circle elevation-3" style="opacity: .8">
<span class="brand-text font-weight-light"><?=$this->info['klinik_name']?></span>
</a>
<!-- Sidebar -->
<div class="sidebar">
<!-- Sidebar user panel (optional) -->
<div class="user-panel mt-3 pb-3 mb-3 d-flex">
<div class="image">
<img src="<?=$path?>content/<?=$user['photo']?>" class="img-circle elevation-2" alt="User Image">
</div>
<div class="info">
<a href="#" class="d-block"><?=$user['nama_lengkap']?></a>
<a href="?page=profile" class="d-block">Edit</a>
</div>
</div>
<!-- SidebarSearch Form -->
<div class="form-inline">
<div class="input-group" data-widget="sidebar-search">
<input class="form-control form-control-sidebar" type="search" placeholder="Search" aria-label="Search">
<div class="input-group-append">
<button class="btn btn-sidebar">
<i class="fas fa-search fa-fw"></i>
</button>
</div>
</div>
</div>
<!-- Sidebar Menu -->
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<!-- Add icons to the links using the .nav-icon class
with font-awesome or any other icon font library -->
<li class="nav-item">
<a href="?page=home" class="nav-link active">
<i class="nav-icon fas fa-tachometer-alt"></i>
<p>
Dashboard
</p>
</a>
</li>
<li class="nav-item">
<a href="?page=antrian" class="nav-link">
<i class="nav-icon fas fa-copy"></i>
<p>
Antrian
</p>
</a>
</li>
</ul>
</nav>
<!-- /.sidebar-menu -->
</div>
<!-- /.sidebar -->
</aside>
<?php
}
Ketiga Anda perlu menambahkan url untuk mengakses profile pada Runadmin.php, Runadministrasi.php dan Rundokter
case 'profile':
$this->crud->myprofile($path, $user);
break;
Terkahir lakukan extends pada file Profileklinik.php
<?php
class Profileklinik extends Profile
{
0 Response to "Membuat Aplikasi Klinik #22 - Module Profile"
Post a Comment
Komentar yang Anda kirim akan terlebih dahulu di moderasi oleh Admin