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

class HapusUmkm extends CI_Controller {

	public function __construct()
    {
        parent::__construct();
        $this->load->model("UserModel");
        $this->load->model("UmkmModel");
        $this->load->model("AbsensiModel");
		
		
		if($this->UserModel->isNotLogin()) {
			redirect(site_url('login'));
		} elseif(!($this->UserModel->isAdmin())) {
			redirect(site_url('dashboard'));
		} 
		
		$get = $this->input->get();
		if($get['id_umkm']==NULL){
			redirect(site_url('admin/umkm'));
		}
    }

	public function index()
	{

		
		$get = $this->input->get();
		$umkm = $this->UmkmModel->getUmkmsById($get['id_umkm']);
		
		$count = $this->AbsensiModel->getAbsensiCountByUmkmId($get['id_umkm']);
		
		if($count>0){
			redirect(site_url('admin/umkm?del_msg=error&umkm='.$umkm->nama));
		} else {
			if($umkm->foto_umkm!=='umkm.png'){
				unlink('./assets/images/umkm/'.$umkm->foto_umkm);
			}
			$this->UmkmModel->delete($get['id_umkm']);
			redirect(site_url('admin/umkm?del_msg=success'));
		}


		
			$data['umkm'] = $umkm;
			$data['user_logged'] = $this->session->userdata('user_logged');
		
	}

	
}
