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

class User extends CI_Controller {

    // CONSTRUCT
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->model('M_user');
        $this->load->helper('url');

        if (!$this->session->userdata('username')) {
            redirect('login');
        }
    }

	public function klinik()
	{
		$data['judul'] = "Klinik";
        $data['user'] = $this->db->get_where('userV2', ['username' => $this->session->userdata('username')])->row_array();
        $data['klinik'] = $this->M_user->klinik()->result_array(); 
        $data['countklinik'] = $this->M_user->klinikAkhir()->row_array(); 
        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('user/klinik', $data);
        $this->load->view('properti/footer', $data);
	}

    public function prosesUser()
    {
        $id = $this->input->post('id');
        $nama = $this->input->post('nama');
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $dept = $this->input->post('dept');
        $userstatus = $this->input->post('userstatus');
        $this->db->query("INSERT INTO userV2 (id, username, [password], nama, dept, userstatus) VALUES ('$id', '$username', '$password', '$nama', '$dept', '$userstatus')");
        redirect('user/klinik');
    }

    public function updateUser($id)
    {
        $id = $this->input->post('id');
        $nama = $this->input->post('nama');
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $dept = $this->input->post('dept');
        $userstatus = $this->input->post('userstatus');
        $this->db->query("UPDATE userV2 SET nama = '$nama', username = '$username', [password] = '$password', dept = '$dept', userstatus = $userstatus WHERE id = '$id'");
        redirect('user/klinik');
    }

    public function hapus($id)
    {
        $this->db->query("DELETE FROM userV2 WHERE id = '$id'");
        redirect('user/klinik');
    }
}
