<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Kmpart extends CI_Controller
{

	function __construct()
	{
		parent::__construct();
		check_not_login(); // kode akses login diambil dari helper
		check_admin();
		$this->load->model(['Lokcab_m', 'Kmpart_m']);
		$this->load->library('form_validation');
	}

	public function index()
	{
		$data['katbrg'] = $this->Kmpart_m->get();
		$data['Part'] = $this->Kmpart_m->getpart();
		$this->template->load('template', 'kmpart', $data);
	}

	public function editharga()
	{
		$this->form_validation->set_rules('hargam_brg', 'hargam_brg', 'trim|required');
		$this->form_validation->set_message('required', '" masih kossong "');

		if ($this->form_validation->run() == false) {
			$data['katbrg'] = $this->Kmpart_m->get();
			$data['Part'] = $this->Kmpart_m->getpart();
			$this->template->load('template', 'kmpart', $data);
		} else {
			$post = $this->input->post(null, TRUE);
			$this->Kmpart_m->editharga($post);
			if ($this->db->affected_rows() > 0) {
				$this->session->set_flashdata('success', 'Data harga berhasil di Perbaharui');
			}
			redirect($_SERVER['HTTP_REFERER']);
		}
	}
}
