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

class Halaman extends CI_Controller {
	
	public function __construct()
    {
        parent::__construct();
		$this->load->model('login');
		$this->load->model('halaman_m', 'halaman');
    }

	
	public function index()
	{
		
		
		$a=$this->session->userdata('username');
		$this->login->cek_login_siswa($a);
		$d['i_judul'] = "Halaman ".$this->config->item('nama_aplikasi_full');
        
        
        $config['total_rows'] = $this->halaman->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/halaman/index/";
		$this->pagination->initialize($config);
		
		
		
		$hal = $this->uri->segment(3);
		 if($hal==""){
			 $hal=0;
		}
           
        
		$d['page'] = $this->pagination->create_links();
		$d['no'] = $hal;
        
        $d['blog'] = $this->halaman->halaman_semua("", $this->session->userdata('hak'), "limit $hal, $config[per_page]");
        
        
		$this->load->view("theme/header", $d);
		$this->load->view('halaman/at_tampil',$d);
		$this->load->view("theme/footer");
	}
	
	
	 public function tambah($aksi=null, $id=null)
	{
		
	   $a=$this->session->userdata('username');
		$this->login->cek_login_siswa($a);
		
		
        
        
       
        
        $d['id'] = $id;
        
        if($aksi=="edit" and $id!=""){
			$d['i_judul'] = "Edit halaman";
            $d['judul_ind']=balik2("at_hal", "judul_ind", "id", $id, "tenan_id", $this->session->userdata('hak'));
            $d['judul_ing']=balik2("at_hal", "judul_ing", "id", $id, "tenan_id", $this->session->userdata('hak'));
            $d['isi_ind']=balik2("at_hal", "isi_ind", "id", $id, "tenan_id", $this->session->userdata('hak'));
            $d['isi_ing']=balik2("at_hal", "isi_ing", "id", $id, "tenan_id", $this->session->userdata('hak'));
        }
        elseif($aksi=="" and $id==""){
			$d['i_judul'] = "Tambah Artikel";
            $d['judul_ind']="";
            $d['judul_ing']="";
            $d['isi_ind']="";
            $d['isi_ing']="";
            
        }
        
		$this->load->view("theme/header", $d);
		$this->load->view('halaman/at_tambah',$d);
		$this->load->view("theme/footer");
	}
    
    public function simpan()
	{

	   $a=$this->session->userdata('username');
	   
		$this->login->cek_login_siswa($a);
		
		
		
	   $id = $this->input->post('id');
       $judul_ing = $this->input->post('judul_ing');
       $judul_ind = $this->input->post('judul_ind');
       $isi_ind = $this->input->post('isi_ind');
       $isi_ing = $this->input->post('isi_ing');
       
       
      
       if($id!=""){
       
	   	
        $this->halaman->editsimpan($id, $judul_ind, $judul_ing, $isi_ind, $isi_ing);
        echo"<html><head><meta http-equiv='refresh' content='0;url=".base_url()."index.php/halaman'></head><body></body></html>";
       }
       
       
       
    }
    
	
	
	
	
	
	
	
}
