<?php

Class Admin extends MY_BackendController{
    public function __construct(){
        parent::__construct();
    }

    public function index(){
        $data['_inactive_loading'] = true;
        $this->view('backend/admin/index',$data);
    }
	
	public function insert(){

        $request = $this->input->post();
        $data = [
           'first_name'=>$request['first_name'],
           'last_name'=>$request['last_name'],
           'username'=>$request['username'],
           'password'=>sha1($request['password']),
           'mobile'=>$request['phone'],
           "display_name"=>$request['first_name']
        ];
        $this->load->model('System_admin_model');
        $this->System_admin_model->create($data);
       redirect('backend/admin/index');
	}

    public function edit(){
        $get = $this->input->get();
        $this->load->model('System_admin_model');
        $data =  json_decode(json_encode($this->System_admin_model->get_id($get['id'])),true);
        $data['id'] = $get['id'];
        $data['_inactive_loading'] = true;
        $this->view('backend/admin/edit',$data);
        
    }

    public function update(){
        $request = $this->input->post();
        $data = [
            'first_name'=>$request['first_name'],
            'last_name'=>$request['last_name'],
            'username'=>$request['username'],
            'password'=>sha1($request['password']),
            'mobile'=>$request['phone'],
            "display_name"=>$request['first_name']
        ];
        $this->load->model("System_admin_model");
        $this->System_admin_model->update($data,$request['id']);
        redirect('backend/admin/index');
    }

    public function delete(){
        $request = $this->input->post();
        $get = $this->input->get();
        var_dump($request);
        var_dump($get);
        $ids = explode(",",$request['ids']);
        
        $this->load->model('System_admin_model');
        foreach($ids as $id){
            $this->System_admin_model->delete($id);
        }
        redirect('backend/admin/index');

        
    }

   
}