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

Menambahkan fitur edit dan hapus pada menu namagement dan sub menu management #3

Open
wants to merge 5 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
68 changes: 68 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

# Created by https://www.gitignore.io/api/windows,codeigniter,visualstudiocode
# Edit at https://www.gitignore.io/?templates=windows,codeigniter,visualstudiocode

### CodeIgniter ###
*/config/development
*/logs/log-*.php
!*/logs/index.html
*/cache/*
!*/cache/index.html
!*/cache/.htaccess

user_guide_src/build/*
user_guide_src/cilexer/build/*
user_guide_src/cilexer/dist/*
user_guide_src/cilexer/pycilexer.egg-info/*

#codeigniter 3
application/logs/*
!application/logs/index.html
!application/logs/.htaccess
/vendor/

# My costum
application/config/config.php
application/config/database.php


### CodeIgniter Patch ###

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

### VisualStudioCode Patch ###
# Ignore all local history of files
.history

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/windows,codeigniter,visualstudiocode
2 changes: 1 addition & 1 deletion application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
| a PHP script and you can easily do that on your own.
|
*/
$config['base_url'] = 'http://localhost/wpu-login/';
$config['base_url'] = 'http://localhost/wpu-login-sandikag/';

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion application/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'root',
'password' => '',
'database' => 'wpu_login',
'dbdriver' => 'mysqli',
'dbprefix' => '',
Expand Down
31 changes: 31 additions & 0 deletions application/controllers/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public function __construct()
{
parent::__construct();
is_logged_in();
$this->load->model('Menu_model', 'menu');
}

public function index()
Expand Down Expand Up @@ -65,4 +66,34 @@ public function submenu()
redirect('menu/submenu');
}
}

public function editMenu($id)
{
$this->db->update('user_menu', ['menu' => $this->input->post('menu') ] ,[ 'id' => $id ]);
$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">The menu has ben edited!</div>');
redirect('menu');
}

public function deleteMenu($id)
{
$this->db->delete('user_menu',['id' => $id]);
$this->db->delete('user_sub_menu',['menu_id' => $id]);
$this->session->set_flashdata('message', '<div class="alert alert-danger" role="alert">The menu has ben deleted!</div>');
redirect('menu');
}

public function editSubMenu($id)
{
$this->menu->saveSubMenu($id);

$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">The menu has ben edited!</div>');
redirect('menu/submenu');
}

public function deleteSubMenu($id)
{
$this->menu->deleteSubMenu($id);
$this->session->set_flashdata('message', '<div class="alert alert-danger" role="alert">The menu has ben deleted!</div>');
redirect('menu/submenu');
}
}
20 changes: 20 additions & 0 deletions application/models/Menu_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,27 @@ public function getSubMenu()
$query = "SELECT `user_sub_menu`.*, `user_menu`.`menu`
FROM `user_sub_menu` JOIN `user_menu`
ON `user_sub_menu`.`menu_id` = `user_menu`.`id`
ORDER BY `menu` desc
";
return $this->db->query($query)->result_array();
}

public function saveSubMenu($id)
{
$data = array(
'menu_id' => $this->input->post('menu_id') ,
'title' => $this->input->post('title'),
'url' => $this->input->post('url'),
'icon' => $this->input->post('icon'),
'is_active' => $this->input->post('is_active')
);
$this->db->where('id', $id);
$this->db->update('user_sub_menu', $data);

}

public function deleteSubMenu($id)
{
$this->db->delete('user_sub_menu',['id' => $id]);
}
}
55 changes: 43 additions & 12 deletions application/views/menu/index.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<!-- Begin Page Content -->
<div class="container-fluid">

<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800"><?= $title; ?></h1>

<div class="row">
<div class="col-lg-8">
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800"><?= $title; ?></h1>
<a href="" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm" data-toggle="modal" data-target="#newMenuModal"><i class="fas fa-fw fa-plus"></i> Add New Menu</a>
</div>
<!-- end Page Heading -->


<div class="row">
<div class="col-lg-6">
<!-- <a href="" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm" data-toggle="modal" data-target="#newMenuModal"><i class="fas fa-fw fa-plus"></i> Add New Menu</a> -->
<?= form_error('menu', '<div class="alert alert-danger" role="alert">', '</div>'); ?>

<?= $this->session->flashdata('message'); ?>

<a href="" class="btn btn-primary mb-3" data-toggle="modal" data-target="#newMenuModal">Add New Menu</a>

<table class="table table-hover">
<thead>
Expand All @@ -29,9 +33,9 @@
<th scope="row"><?= $i; ?></th>
<td><?= $m['menu']; ?></td>
<td>
<a href="" class="badge badge-success">edit</a>
<a href="" class="badge badge-danger">delete</a>
</td>
<a href="" data-toggle="modal" data-target="#editMenuModal<?= $m['id'] ?>" class="badge badge-success"><i class="far fa-fw fa-edit"></i></a>
<a href="<?= base_url('menu/deleteMenu/'.$m['id']) ?>" class="badge badge-danger" onclick="return confirm('Apakah anda yakin untuk menghapus <?= $m['menu']; ?> ?')"><i class="far fa-fw fa-trash-alt"></i></a>
</td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
Expand All @@ -50,9 +54,7 @@
</div>
<!-- End of Main Content -->

<!-- Modal -->

<!-- Modal -->
<!-- Start Modal -->
<div class="modal fade" id="newMenuModal" tabindex="-1" role="dialog" aria-labelledby="newMenuModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
Expand All @@ -75,4 +77,33 @@
</form>
</div>
</div>
</div>
</div>
<!-- End Modal -->

<!-- edit Modal -->
<?php foreach ($menu as $em):?>
<div class="modal fade" id="editMenuModal<?= $em['id']?>" tabindex="-1" role="dialog" aria-labelledby="editMenuModal<?= $em['id']?>" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editMenuModal<?= $em['id']?>">Edit Menu</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form action="<?= base_url('menu/editMenu/'.$em['id']); ?>" method="post">
<div class="modal-body">
<div class="form-group">
<input type="text" class="form-control" value="<?= $em['menu'] ?>" id="menu" name="menu" placeholder="Menu name">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
<button type="submit" class="btn btn-primary">Simpan</button>
</div>
</form>
</div>
</div>
</div>
<?php endforeach;?>
<!-- End edit Modal -->
78 changes: 69 additions & 9 deletions application/views/menu/submenu.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<!-- Begin Page Content -->
<div class="container-fluid">


<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800"><?= $title; ?></h1>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800"><?= $title; ?></h1>
<a href="" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm" data-toggle="modal" data-target="#newSubMenuModal"><i class="fas fa-fw fa-plus"></i> Add New Submenu</a>
</div>



Expand All @@ -16,7 +20,6 @@

<?= $this->session->flashdata('message'); ?>

<a href="" class="btn btn-primary mb-3" data-toggle="modal" data-target="#newSubMenuModal">Add New Submenu</a>

<table class="table table-hover">
<thead>
Expand All @@ -39,10 +42,10 @@
<td><?= $sm['menu']; ?></td>
<td><?= $sm['url']; ?></td>
<td><?= $sm['icon']; ?></td>
<td><?= $sm['is_active']; ?></td>
<td><?php if($sm['is_active'] == 0) {echo "NO"; }else{ echo "YES" ;} ?></td>
<td>
<a href="" class="badge badge-success">edit</a>
<a href="" class="badge badge-danger">delete</a>
<a href="" data-toggle="modal" data-target="#eeditSubMenuModal<?= $sm['id'] ?>" class="badge badge-success"><i class="far fa-fw fa-edit"></i></a>
<a href="<?= base_url('menu/deleteSubMenu/'.$sm['id']) ?>" class="badge badge-danger" onclick="return confirm('Apakah anda yakin untuk menghapus <?= $sm['menu']; ?> ?')"><i class="far fa-fw fa-trash-alt"></i></a>
</td>
</tr>
<?php $i++; ?>
Expand All @@ -62,9 +65,7 @@
</div>
<!-- End of Main Content -->

<!-- Modal -->

<!-- Modal -->
<!-- New Modal -->
<div class="modal fade" id="newSubMenuModal" tabindex="-1" role="dialog" aria-labelledby="newSubMenuModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
Expand Down Expand Up @@ -109,4 +110,63 @@
</form>
</div>
</div>
</div>
</div>
<!-- End New Modal -->

<!-- Edit Modal -->
<?php foreach($subMenu as $esm): ?>
<div class="modal fade" id="eeditSubMenuModal<?= $esm['id'] ?>" tabindex="-1" role="dialog" aria-labelledby="eeditSubMenuModal<?= $esm['id'] ?>Label" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="eeditSubMenuModal<?= $esm['id'] ?>Label">Add New Sub Menu</h5>
<buttond type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</buttond>
</div>
<form action="<?= base_url('menu/editSubmenu/'.$esm['id']); ?>" method="post">
<div class="modal-body">
<div class="form-group">
<input type="text" class="form-control" value="<?= $esm['title'] ?>" id="title" name="title" placeholder="Submenu title">
</div>
<div class="form-group">
<select name="menu_id" id="menu_id" class="form-control">
<option >Select Menu</option>
<?php foreach ($menu as $mm) : ?>
<?php if($esm['menu_id'] == $mm['id'] ): ?>
<option value="<?= $mm['id']; ?>" selected> <?= $mm['menu']; ?> </option>
<?php else:?>
<option value="<?= $mm['id']; ?>" > <?= $mm['menu']; ?> </option>
<?php endif;?>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<input type="text" class="form-control" value="<?= $esm['url'] ?>" id="url" name="url" placeholder="Submenu url">
</div>
<div class="form-group">
<input type="text" class="form-control" value="<?= $esm['icon'] ?>" id="icon" name="icon" placeholder="Submenu icon">
</div>
<div class="form-group">
<div class="form-check">
<?php if ($esm['is_active'] == 1):?>
<input class="form-check-input" type="checkbox" value="1" name="is_active" id="is_active<?= $esm['id'] ?>" checked>
<?php else:?>
<input class="form-check-input" type="checkbox" value="1" name="is_active" id="is_active<?= $esm['id'] ?>" >
<?php endif;?>
<label class="form-check-label" for="is_active<?= $esm['id'] ?>">
Active?
</label>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
<button type="submit" class="btn btn-primary">Simpan</button>
</div>
</form>
</div>
</div>
</div>
<?php endforeach; ?>
<!-- End Edit Modal -->