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

class Album extends CI_Controller {
	
	public function __construct()
    {
        parent::__construct();
		$this->load->model('login');
        $this->load->model('album_m', 'data');
    }

	public function data_list()
	{
	   $a=$this->session->userdata('username');
		$this->login->cek_login_siswa($a);
		$d['i_judul'] = "Gallery ".$this->config->item('nama_aplikasi_full');
       
		 
        $config['total_rows'] = $this->data->jum_hal($this->session->userdata('hak'));
		$config['per_page'] = 10;
		$config['uri_segment'] = 3;
		$config['full_tag_open'] = '<table id="simple-table" class="table-striped table-bordered table-hover"><thead><tr>';
		$config['full_tag_close'] = '</tr></thead></table>';
		$config['prev_link'] = '<th width="20" align="center">&lt;</th>';
		$config['prev_tag_open'] = '<th width="20" align="center">';
		$config['prev_tag_close'] = '</th>';
		$config['next_link'] = '<th width="20" align="center">&gt;</th>';
		$config['next_tag_open'] = '<th width="20" align="center">';
		$config['next_tag_close'] = '</th>';
		$config['cur_tag_open'] = '<th width=20" align="center"><a href="#" class="pi-active">';
		$config['cur_tag_close'] = '</a></th>';
		$config['num_tag_open'] = '<th width="20" align="center">';
		$config['num_tag_close'] = '</th>';
		 
		$config['first_tag_open'] = '<td width="20" align="center">';
		$config['first_tag_close'] = '</td>';
		$config['last_tag_open'] = '<td width="20" align="center">';
		$config['last_tag_close'] = '</td>';
		 
		$config['first_link'] = '<td width="20" align="center">&lt;&lt;</td>';
		$config['last_link'] = '<td width="20" align="center">&gt;&gt;</td>';
		
		$config['base_url'] = base_url()."index.php/album/data_list/";
		$this->pagination->initialize($config);
		
		
		
		$hal = $this->uri->segment(3);
		 if($hal==""){
			 $hal=0;
		}
           
        
		$d['page'] = $this->pagination->create_links();
		$d['no'] = $hal;
        
        $d['data'] = $this->data->semua($this->session->userdata('hak'), "limit $hal, $config[per_page]");
        
        
		$this->load->view('theme/header.php',$d);
        $this->load->view('album/at_tampil.php',$d);
        $this->load->view('theme/footer.php',$d);
	}
    
    public function tambah($aksi=null, $id=null)
	{
	   $a=$this->session->userdata('username');
		$this->login->cek_login_siswa($a);
        
        $d['i_judul'] = "Tambah Data Album";
        $d['id'] = $id;
        
        if($aksi=="edit" and $id!=""){
            $d['galery']=balik("at_galeri_id", "galery", "id", $id);
        }
        elseif($aksi=="" and $id==""){
            $d['galery']="";
        }
        
		$this->load->view('theme/header.php',$d);
        $this->load->view('album/tambah.php',$d);
        $this->load->view('theme/footer.php',$d);
	}
    
    public function simpan()
	{
	   $a=$this->session->userdata('username');
		$this->login->cek_login_siswa($a);
		
	   $id = $this->input->post('id');
	   $galery = $this->input->post('galery');
       if($id==""){
        $this->data->simpan($galery, $this->session->userdata('hak'));
        echo"<html><head><meta http-equiv='refresh' content='0;url=".base_url()."index.php/album/data_list'></head><body></body></html>";
       }
       if($id!=""){
        $this->data->editsimpan($id, $galery, $this->session->userdata('hak'));
        echo"<html><head><meta http-equiv='refresh' content='0;url=".base_url()."index.php/album/data_list'></head><body></body></html>";
       }
       
       
       
    }
    
    public function hapus($id=null)
	{
		$a=$this->session->userdata('username');
		$this->login->cek_login_siswa($a);
		$this->data->hapus($id);
		echo "<script>alert('Data berhasil dihapus')</script>";
		echo"<html><head><meta http-equiv='refresh' content='0;url=".base_url()."index.php/album/data_list'></head><body></body></html>";
	}
	

	
}
