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

class Anggota extends CI_Controller {

	function __construct(){
		parent::__construct();
		if(!$this->session->userdata('login')){
			redirect('login');
		}
		$this->load->model('Anggota_model');
		$this->load->model('Peminjaman_model');

	}

	public function index(){
	$q=$this->input->get('q');
	$kelas=$this->input->get('kelas');

	$data['anggota']=$this->Anggota_model->get($q,$kelas);
	$data['notif_count'] = $this->Peminjaman_model->count_notifikasi();

	$data['kelas']=$this->Anggota_model->kelas();

	$this->load->view('anggota/index',$data);
}



	public function tambah(){
		$data=[
			'nis'=>$this->input->post('nis'),
			'nama'=>$this->input->post('nama'),
			'kelas'=>$this->input->post('kelas'),
			'alamat'=>$this->input->post('alamat'),
			'no_hp'=>$this->input->post('no_hp')

		];

		$this->Anggota_model->insert($data);
		redirect('anggota');
	}

	public function edit($id){
		$data['row']=$this->Anggota_model->edit($id);
		$this->load->view('anggota/edit',$data);
	}

	public function update(){
		$id=$this->input->post('id');

		$data=[
			'nis'=>$this->input->post('nis'),
			'nama'=>$this->input->post('nama'),
			'kelas'=>$this->input->post('kelas'),
			'alamat'=>$this->input->post('alamat'),
			'no_hp'=>$this->input->post('no_hp')

		];

		$this->Anggota_model->update($id,$data);
		redirect('anggota');
	}

	public function hapus($id){
		$this->Anggota_model->delete($id);
		redirect('anggota');
	}
	public function get_by_nis(){
	$nis = $this->input->post('nis');
	$data = $this->Anggota_model->by_nis($nis);
	echo json_encode($data);
}

}
