Commit 4766dd33 by KyrieCettyara

admin

parent 4f158c2f
......@@ -49,6 +49,9 @@ $routes->get('logout', ' UserController::logout');
$routes->get('list-kuliner', "ArtikelController::listKuliner");
$routes->get("kuliner/(:num)", "ArtikelController::kulinerById/$1");
$routes->match(["get", "post"], "add-artikel", "ArtikelController::addArtikel");
$routes->match(["get", "post"], "edit-artikel/(:num)", "ArtikelController::editArtikel/$1");
$routes->get("delete-artikel/(:num)", "ArtikelController::deleteArtikel/$1");
/*
* --------------------------------------------------------------------
* Additional Routing
......
......@@ -3,7 +3,7 @@
namespace App\Controllers;
use App\Controllers\BaseController;
use App\Models\ArtikelModel;
use App\Models\UserModel;
class AdminController extends BaseController
{
......@@ -21,9 +21,44 @@ class AdminController extends BaseController
return view("admin/dashboard");
}
public function addArtikel()
public function addAdminAcc()
{
if ($this->request->getMethod() == "post") {
$data['title'] = 'Tambah Artikel';
if ($this->request->getMethod() == 'post') {
//let's do the validation here
$rules = [
'name' => 'required|min_length[3]|max_length[20]',
'email' => 'required|min_length[6]|max_length[50]|valid_email|is_unique[user.email]',
'password' => 'required|min_length[8]|max_length[255]',
'password_confirm' => 'matches[password]',
];
if (!$this->validate($rules)) {
return view('auth/register', [
"validation" => $this->validator,
]);
} else {
$model = new UserModel();
$newData = [
'name' => $this->request->getVar('name'),
'email' => $this->request->getVar('email'),
'password' => $this->request->getVar('password'),
'role_id' => 1,
'is_active' => 1,
'date_created' => time()
];
$model->save($newData);
$session = session();
$session->setFlashdata('success', 'Successful Registration');
return redirect()->to(base_url('admin'));
}
}
return view('add_artikel', $data);
}
}
......@@ -4,6 +4,7 @@ namespace App\Controllers;
use App\Models\ArtikelModel;
use App\Models\BookmarkModel;
use App\Models\JenisArtikelModel;
class ArtikelController extends BaseController
{
......@@ -30,10 +31,17 @@ class ArtikelController extends BaseController
$value = $kulinerModel->where('id_artikel', $key)->first();
$this->setArtikelSession($value);
if (session()->get('role_id') == 1) {
return view('byId', [
"value" => $value,
]);
return view('admin/detail', [
"value" => $value,
]);
} else {
return view('byId', [
"value" => $value,
]);
}
}
private function setArtikelSession($value)
......@@ -60,6 +68,85 @@ class ArtikelController extends BaseController
];
$bookmarkModel->save($data);
session()->destroy();
return view('landing_page', $data);
}
public function addArtikel()
{
$data['title'] = 'Tambah Artikel';
$model = new JenisArtikelModel();
$data = $model->findAll();
if ($this->request->getMethod() == 'post') {
$model = new ArtikelModel();
$newData = [
'id_jenis_artikel' => $this->request->getVar('id_jenis_artikel'),
'gambar' => $this->request->getVar('gambar'),
'judul_artikel' => $this->request->getVar('judul_artikel'),
'isi_artikel' => $this->request->getVar('isi_artikel'),
];
$model->save($newData);
$session = session();
$session->setFlashdata('success', 'Successful Registration');
return redirect()->to(base_url('admin'));
}
return view('admin/add_artikel', [
"data" => $data,
]);
}
public function editArtikel($id = null)
{
$data['title'] = 'Tambah Artikel';
$model = new JenisArtikelModel();
$modelArtikel = new ArtikelModel();
$data = $model->findAll();
$modelId = $modelArtikel->where("id_artikel", $id)->first();
if ($this->request->getMethod() == "post") {
$newData = [
'id_jenis_artikel' => $this->request->getVar('id_jenis_artikel'),
'gambar' => $this->request->getVar('gambar'),
'judul_artikel' => $this->request->getVar('judul_artikel'),
'isi_artikel' => $this->request->getVar('isi_artikel'),
];
$modelArtikel->update($id, $newData);
$session = session();
$session->setFlashdata("success", "Data updated successfully");
return redirect()->to(base_url('kuliner/7'));
}
return view('admin/edit_artikel', [
"modelId" => $modelId,
"data" => $data,
]);
}
public function deleteArtikel($id)
{
$model = new ArtikelModel();
$artikel = $model->delete($id);
$session = session();
$session->setFlashdata("success", "Artikel Berhasil Dihapus");
return redirect()->to(base_url('admin'));
}
}
......@@ -44,7 +44,7 @@ class AuthController extends BaseController
if ($user['role_id'] == 1) {
return redirect()->to(base_url('admin'));
} elseif ($user['role_id'] == 2) {
return redirect()->to(base_url('landing_page'));
return redirect()->to(base_url('/'));
}
}
}
......
<?php
namespace App\Models;
use CodeIgniter\Model;
class JenisArtikelModel extends Model
{
protected $DBGroup = 'default';
protected $table = 'jenis_artikel';
protected $primaryKey = 'id_jenis_artikel';
protected $useAutoIncrement = true;
protected $insertID = 0;
protected $returnType = 'array';
protected $useSoftDelete = false;
protected $protectFields = true;
protected $allowedFields = [
'nama_jenis_artikel',
];
// Dates
protected $useTimestamps = false;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = [];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
}
<div class="panel-body">
<hr>
<form class="" action="<?= base_url('ArtikelController/addArtikel'); ?>" method="post">
<div class="form-group">
<label for="name">Jenis Artikel</label>
<select name="id_jenis_artikel" id="id_jenis_artikel">
<?php foreach ($data as $value) : ?>
<option value="<?= $value['id_jenis_artikel']; ?>">
<?= $value['nama_jenis_artikel']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="gambar">Gambar</label>
<input type="file" class="form-control" name="gambar" id="gambar">
</div>
<div class="form-group">
<label for="judul_artikel">Judul Artikel</label>
<input type="text" class="form-control" name="judul_artikel" id="judul_artikel">
</div>
<div class="form-group">
<label for="isi_artikel">Isi</label>
<input type="text" class="form-control" name="isi_artikel" id="isi_artikel">
</div>
<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>
\ No newline at end of file
......@@ -10,4 +10,6 @@
</div>
</div>
</div>
</div>
\ No newline at end of file
</div>
<a href="<?= base_url('ArtikelController/addArtikel') ?>" class="get-started-btn">Logout</a>
\ No newline at end of file
<h2 id="judul_artikel" name="judul_artikel"><?= $value['judul_artikel']; ?></h1>
<button> <a href=" <?= base_url('edit-artikel/' . $value['id_artikel']); ?>">Edit</a></button>
<button> <a href="<?= base_url('delete-artikel/' . $value['id_artikel']); ?>">Delete</a></button>
\ No newline at end of file
<div class="panel-body">
<hr>
<form class="" action="<?= base_url('ArtikelController/editArtikel/' . $modelId['id_artikel']); ?>" method="post">
<div class="form-group">
<label for="name">Jenis Artikel</label>
<select name="id_jenis_artikel" id="id_jenis_artikel" value="<?= $modelId['id_jenis_artikel'] ?>">
<?php foreach ($data as $value) : ?>
<option value="<?= $value['id_jenis_artikel']; ?>">
<?= $value['nama_jenis_artikel']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="gambar">Gambar</label>
<input type="file" class="form-control" name="gambar" id="gambar" value="<?= $modelId['gambar'] ?>">
</div>
<div class="form-group">
<label for="judul_artikel">Id Artikel</label>
<input type="text" class="form-control" name="judul_artikel" id="id_artikel" value="<?= $modelId['id_artikel'] ?>" readonly>
</div>
<div class="form-group">
<div class="form-group">
<label for="judul_artikel">Judul Artikel</label>
<input type="text" class="form-control" name="judul_artikel" id="judul_artikel " value="<?= $modelId['judul_artikel'] ?>">
</div>
<div class="form-group">
<label for="isi_artikel">Isi</label>
<input type="text" class="form-control" name="isi_artikel" id="isi_artikel" value="<?= $modelId['isi_artikel'] ?>">
</div>
<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>
\ No newline at end of file
......@@ -78,12 +78,22 @@
</div>
<div class="Hotbg">
<input type="text" name="input" class="Hotbg-txt" placeholder="Search >>>">
<a href="<?php echo base_url('Home/search'); ?>?cari=sabun" class="Hotbg-btn">
<input onchange="ganti()" id="search" type="text" name="input" class="Hotbg-txt" placeholder="Search >>>">
<a id="searchb" href="" class="Hotbg-btn">
<i class="fa fa-search"></i>
</a>
</div>
<script>
function ganti() {
let searchin = document.getElementById("search");
let searchButton = document.getElementById("searchb");
let baseURL = "<?php echo base_url('Home/search'); ?>";
let link = baseURL + "?cari=" + searchin.value;
searchButton.href = link;
}
</script>
</div>
</header><!-- End Header -->
......
......@@ -13,13 +13,7 @@
<th>NIM</th>
<th>Alamat</th>
</tr>
<?php foreach ($mahasiswa as $mhs) : ?>
<tr>
<td><?php echo $mhs['nama']; ?></td>
<td><?php echo $mhs['nim']; ?></td>
<td><?php echo $mhs['alamat']; ?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment