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

class HapusPemilik extends CI_Controller {

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

	public function index()
	{

		$get = $this->input->get();
		$pemilik = $this->UserModel->getUsersById($get['id_user']);
		
		$count = $this->UmkmModel->getUmkmCountByUserId($get['id_user']);

		if($count>0){
			redirect(site_url('admin/dashboard?del_msg=error&pemilik='.$pemilik->nama));
		} else {
			if($pemilik->foto_user!=='user.png'){
				unlink('./assets/images/'.$pemilik->foto_user);
			}
			$this->UserModel->delete($get['id_user']);
			redirect(site_url('admin/dashboard?del_msg=success'));
		}


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

	
}
