216 lines
7.2 KiB
PHP
216 lines
7.2 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Artikel extends CI_Controller
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model("ModelArtikel");
|
|
}
|
|
|
|
function index()
|
|
{
|
|
$artikel = $this->ModelArtikel->get_data();
|
|
$data = array(
|
|
'body' => 'Artikel/list',
|
|
'artikel' => $artikel
|
|
);
|
|
$this->load->view('index', $data);
|
|
}
|
|
|
|
function view()
|
|
{
|
|
$id = $this->uri->segment(3);
|
|
$artikel = $this->ModelArtikel->get_data_edit($id);
|
|
$data = array(
|
|
'artikel' => $artikel,
|
|
);
|
|
$this->load->view('Artikel/view', $data);
|
|
}
|
|
|
|
public function input()
|
|
{
|
|
$artikel = $this->ModelArtikel->get_data();
|
|
$data = array(
|
|
'body' => 'Artikel/input',
|
|
'form' => 'Artikel/form',
|
|
'artikel' => $artikel,
|
|
);
|
|
$this->load->view('index', $data);
|
|
}
|
|
public function insert()
|
|
{
|
|
$patch = "desain/artikel/";
|
|
$config['upload_path'] = "" . $patch;
|
|
$config['allowed_types'] = 'jpeg|jpg|png';
|
|
$config['max_size'] = 11240;
|
|
$this->upload->initialize($config);
|
|
$this->load->library('upload', $config);
|
|
if ($this->upload->do_upload('gambar_artikel')) {
|
|
$data = array(
|
|
'judul' => $this->input->post('judul'),
|
|
'tanggal' => date("Y-m-d"),
|
|
'penulis' => $this->input->post('penulis'),
|
|
'konten' => $this->input->post('konten'),
|
|
'gambar' => $patch . $this->upload->data()["file_name"],
|
|
'gambar_artikel' => "https://isipiringku.esolusindo.com/" . $patch . $this->upload->data()["file_name"],
|
|
);
|
|
if($this->db->insert("artikel", $data)){
|
|
$id = $this->db->insert_id();
|
|
$data = array(
|
|
'view' => "https://isipiringku.esolusindo.com/Artikel/view/" . $id
|
|
);
|
|
$this->db->where("id_artikel", $id);
|
|
$this->db->update("artikel", $data);
|
|
|
|
redirect(base_url() . "Artikel");
|
|
}
|
|
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
|
|
|
|
} else {
|
|
$data = array(
|
|
'judul' => $this->input->post('judul'),
|
|
'tanggal' => date("Y-m-d"),
|
|
'penulis' => $this->input->post('penulis'),
|
|
'konten' => $this->input->post('konten'),
|
|
'gambar' => $patch . $this->upload->data()["file_name"],
|
|
'gambar_artikel' => "https://isipiringku.esolusindo.com/" . $patch . $this->upload->data()["file_name"],
|
|
'view' => "https://isipiringku.esolusindo.com/Artikel/view/" . $this->db->insert_id()
|
|
);
|
|
if ($this->db->insert("artikel", $data)) {
|
|
if($this->db->insert("artikel", $data)){
|
|
$id = $this->db->insert_id();
|
|
$data = array(
|
|
'view' => "https://isipiringku.esolusindo.com/Artikel/view/" . $id
|
|
);
|
|
$this->db->where("id_artikel", $id);
|
|
$this->db->update("artikel", $data);
|
|
}
|
|
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
|
|
redirect(base_url() . "Artikel");
|
|
} else {
|
|
$this->session->set_flashdata("notif", $this->Notif->gagal("gagal Input Data"));
|
|
redirect(base_url() . "Artikel");
|
|
}
|
|
}
|
|
}
|
|
|
|
function edit()
|
|
{
|
|
$id = $this->uri->segment(3);
|
|
$artikel = $this->ModelArtikel->get_data_edit($id);
|
|
$data = array(
|
|
'body' => 'Artikel/edit',
|
|
'form' => 'Artikel/form_edit',
|
|
'artikel' => $artikel,
|
|
);
|
|
$this->load->view('index', $data);
|
|
}
|
|
public function update()
|
|
{
|
|
$id = $this->uri->segment(3);
|
|
|
|
$patch = "desain/artikel/";
|
|
$config['upload_path'] = "./" . $patch;
|
|
$config['allowed_types'] = 'jpeg|jpg|png';
|
|
$config['max_size'] = 11240;
|
|
|
|
$this->upload->initialize($config);
|
|
$this->load->library('upload', $config);
|
|
if ($_FILES["gambar_artikel"]["name"] == null) {
|
|
$data = array(
|
|
'judul' => $this->input->post('judul'),
|
|
'tanggal' => date("Y-m-d"),
|
|
'penulis' => $this->input->post('penulis'),
|
|
'konten' => $this->input->post('konten'),
|
|
//'gambar_artikel' => $patch . $this->upload->data()["file_name"],
|
|
);
|
|
$this->db->where("id_artikel", $id);
|
|
if ($this->db->update("artikel", $data)) {
|
|
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
|
|
redirect(base_url() . "Artikel");
|
|
} else {
|
|
$this->session->set_flashdata("notif", $this->Notif->gagal("gagal Input Data"));
|
|
redirect(base_url() . "Artikel");
|
|
}
|
|
} else {
|
|
if ($this->upload->do_upload('gambar_artikel')) {
|
|
$data = array(
|
|
'judul' => $this->input->post('judul'),
|
|
'tanggal' => date("Y-m-d"),
|
|
'penulis' => $this->input->post('penulis'),
|
|
'konten' => $this->input->post('konten'),
|
|
'gambar' => $patch . $this->upload->data()["file_name"],
|
|
'gambar_artikel' => "https://isipiringku.esolusindo.com/" . $patch . $this->upload->data()["file_name"],
|
|
);
|
|
$this->db->where("id_artikel", $id);
|
|
$this->db->update("artikel", $data);
|
|
$artikel = $this->ModelArtikel->get_data_edit($id);
|
|
unlink('./'.$artikel['gambar']);
|
|
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
|
|
redirect(base_url() . "Artikel");
|
|
} else {
|
|
$data = array(
|
|
'judul' => $this->input->post('judul'),
|
|
'tanggal' => date("Y-m-d"),
|
|
'penulis' => $this->input->post('penulis'),
|
|
'konten' => $this->input->post('konten'),
|
|
'gambar_artikel' => "https://isipiringku.esolusindo.com/" . $patch . $this->upload->data()["file_name"],
|
|
);
|
|
$this->db->where("id_artikel", $id);
|
|
if ($this->db->update("artikel", $data)) {
|
|
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
|
|
redirect(base_url() . "Artikel");
|
|
} else {
|
|
$this->session->set_flashdata("notif", $this->Notif->gagal("gagal Input Data"));
|
|
redirect(base_url() . "Artikel");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function delete()
|
|
{
|
|
$id = $this->input->post("id_artikel");
|
|
$this->db->where_in("id_artikel", $id);
|
|
if ($this->db->delete("artikel")) {
|
|
//$this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
|
|
redirect(base_url() . "Artikel");
|
|
// code...
|
|
} else {
|
|
$this->session->set_flashdata("notif", $this->Notif->gagal("gagal Input Data"));
|
|
redirect(base_url() . "Artikel");
|
|
}
|
|
}
|
|
|
|
// function upload_file($file)
|
|
// {
|
|
// $msg = "";
|
|
// $nama = "";
|
|
// $config['upload_path'] = './desain/artikel';
|
|
// $config['allowed_types'] = '*';
|
|
// $config['max_size'] = 11240;
|
|
// echo $_FILES[$file]["name"];
|
|
|
|
// if ($_FILES[$file]["name"]) {
|
|
// $this->load->library('upload', $config);
|
|
// if (!$this->upload->do_upload($file)) {
|
|
// $msg = $this->upload->display_errors();
|
|
// echo $msg;
|
|
// die();
|
|
// } else {
|
|
// $upload = $this->upload->data();
|
|
// $nama = $upload['file_name'];
|
|
// $msg = "Berhasil Upload " . $nama;
|
|
// }
|
|
// } else {
|
|
// $msg = "File Kosong";
|
|
// }
|
|
// return array(
|
|
// 'pesan' => $msg,
|
|
// 'nama' => $nama,
|
|
// 'link' => "desain/artikel/" . $nama
|
|
// );
|
|
// }
|
|
} |