<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Icon extends CI_Controller {
	function __construct(){
		parent::__construct();	
			$this->load->library('session');
			$this->load->library('form_validation');
			//$this->load->model('m_icon');
			$this->load->model('m_icon');
			if($this->session->userdata('username') =='' OR $this->session->userdata('token') !=md5('100%Madiun'.date('Ymd')) ){
				redirect(base_url("login"));
			}			
	}
	public function index()
	{
	$data['icon'] = $this->m_icon->tampil();
	$this->load->view('admin/icon', $data);			
	}	
	public function save()
	{
		if(isset($_POST['simpan'])){
		$this->form_validation->set_rules('namalist','namalist','required|max_length[100]');				
		$namalist=$this->security->xss_clean($this->input->post('namalist'));		
		$deskripsi=$this->security->xss_clean($this->input->post('deskripsi'));		
		$idlist=$this->security->xss_clean($this->input->post('idlist'));		
		$status=$this->security->xss_clean($this->input->post('status'));		
		if($this->form_validation->run() == false){ 
				$data['alert'] = 'danger';
				$data['pesan'] = 'Ada kesalahan, mohon periksa kembali !';
				$this->load->view('admin/icon', $data);
		}else{
		$data_save = array(
								'deskripsi' => $deskripsi,
								'status' => $status
						);			
		$where = array(
						'idlist' => $idlist
				);
		$this->m_icon->update($where,$data_save,'list');		
		$data['icon'] = $this->m_icon->tampil();		
		$data['alert'] = 'success';
		$data['pesan'] = 'Berhasil diperbarui';		
		$this->load->view('admin/icon', $data);		
		}
		}
		if(isset($_POST['kembali'])){
		$data['alert'] = '';
		$data['pesan'] = '';				
		$data['icon'] = $this->m_icon->tampil();
		$this->load->view('admin/icon', $data);			
		}		
	}	
}