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

class Admin2 extends CI_Controller {
// 	public function index()
// 	{
// 		$this->load->model('M_login');
// 		$this->load->model('M_alumni');
// 	}

	public function admin_login()
	{
		$this->load->view('admin/login');
	}
	
	public function index()
	{
		if(isset($_SESSION['username'])){
			$username = $_SESSION['username'];

			//Load Detail Profil
		    $this->load->model('M_login');
			$detail = $this->M_login->detailAdmin($username);
			$data['detail'] = $detail;

			//Load Para Alumni
			$this->load->model('M_alumni');
			$data['data_alumni'] = $this->M_alumni->tampil_data();

			//Load View
			$this->load->view('admin/header',$data);
			$this->load->view('admin/dashboard',$data);
			//$this->load->view('admin/revisi',$data);
			$this->load->view('admin/footer');
		}else{
			redirect('admin/admin_login');
		}
	}

	public function authLogin()
	{
		$this->load->model('M_login');
		$username = $this->input->post('username');
		$password = $this->input->post('password');

		$this->form_validation->set_rules('username','Username','required');
		$this->form_validation->set_rules('password','Password','required');

		if($this->form_validation->run() != FALSE){
			$data = [
				'username' => $username,
				'password' => md5($password),
			];
			$cekLogin = $this->M_login->cekLoginAdmin($data);
		}else{
		    redirect('admin/admin_login');
		}
	}

	public function admin_logout()
	{
		$this->session->sess_destroy();
		redirect('admin/admin_login');
	}

	public function terima_alumni($email)
	{
		$this->load->model('M_alumni');
		$data = array(
			'status' => 1, 
		);

		$this->M_alumni->update_statusAlumni(urldecode($email), $data);
		redirect('admin');
	}

	public function tolak_alumni($email)
	{
		$this->load->model('M_alumni');
		$data = array(
			'status' => 2, 
		);

		$this->M_alumni->update_statusAlumni(urldecode($email), $data);
		redirect('admin');
	}

	public function revisi_alumni($data)
	{
		$this->load->model('M_alumni');
		$con = urldecode($data);
		$con1 = explode(",",$con);
		//echo "<script>console.log('$con1[0]');</script>";
		$email = $con1[0]; $telp = $con1[1];

		$datarev = array(
			'email' => $email, 
		);

		$where = array(
			'telp' => $telp, 
		);

		$this->M_alumni->update_revisiAlumni($where, $datarev);
		
	}
}