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

class Add_slider extends CI_Controller {

	
	public function __construct()
        {
                parent::__construct();
                $this->load->library('session');
                $this->load->model('admin/Add_slider_model');
                if(!isset($_SESSION['admin'])){redirect('admin/Login');}
        }

	

	public function index()
	{
		$this->load->view('admin/header');
		$this->load->view('admin/add-slider');
		$this->load->view('admin/footer');
	}

	public function insert()
	{
		// $slug = preg_replace('/[^a-z0-9]+/i', '-', trim(strtolower($patr)));
		$data = $this->Add_slider_model->db_insert();
		if($data == 1){
			$this->session->set_flashdata("success"," Data sucessfully Saved.");
				redirect('admin/Add_slider');
		}else{
			$this->session->set_flashdata("error"," Data Not Insert.");
				redirect('admin/Add_slider');
		}
	}

	public function view()
	{
		$data['view_all'] = $this->Add_slider_model->get_all();
		$this->load->view('admin/header');
		$this->load->view('admin/slide-table', $data);
		$this->load->view('admin/footer');
	}

	public function edit($id)
	{
		$data['data'] = $this->Add_slider_model->select($id);
		$data['id'] = $id;
 		$this->load->view('admin/header');
		$this->load->view('admin/add-slider', $data);
		$this->load->view('admin/footer');
	}

	public function update()
	{
		$data = $this->Add_slider_model->update($_POST);
		if($data == 1){
			$this->session->set_flashdata("success"," Data sucessfully Update.");
				redirect('admin/Add_slider/view');

		}
	}

	public function delete($id)
	{
		$data = $this->Add_slider_model->delete($id);
			if($data == 1){
			$this->session->set_flashdata("success"," Data sucessfully Deleted.");
				redirect('admin/Add_slider/view');

		}
	}
}
