<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Admin extends CI_Controller {
	
	function __construct() {
		parent::__construct();
		
	
	 
    $this->load->model('User_model'); 	


   } 
	
	public function index() {  
	if ($this->session->userdata('admin_coba') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		$a['page']	= "d_amain";
		
		$this->load->view('admin/aaa', $a);
	}
		
	
		

	
		//---------------------------Kumpulan baru-----------------------------//
		public function faq() {
		if ($this->session->userdata == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		$total_row		= $this->db->query("SELECT * FROM tb_faq")->num_rows();
		$per_page		= 10;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
	
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp					= addslashes($this->input->post('idp'));
		$pertanyaan				= addslashes($this->input->post('pertanyaan'));
		$jawaban				= addslashes($this->input->post('jawaban'));
		
		
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_faq WHERE id = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data has been deleted </div>");
			redirect('admin/faq');
		} else if ($mau_ke == "add") {
			$a['page']		= "/faq/f_faq";
		} else if ($mau_ke == "edt") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_faq WHERE id = '$idu'")->row();	
			$a['page']		= "faq/f_faq";
		} else if ($mau_ke == "act_add") {	
			$this->db->query("INSERT INTO tb_faq VALUES (NULL, '$pertanyaan', '$jawaban')");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Berhasil Ditambah</div>");
			redirect('admin/faq');
		} else if ($mau_ke == "act_edt") {
			if ($password = md5("-")) {
				$this->db->query("UPDATE tb_faq SET pertanyaan = '$pertanyaan', jawaban = '$jawaban' WHERE id = '$idp'");
			} else {
				$this->db->query("UPDATE tb_faq SET pertanyaan = '$pertanyaan', jawaban = '$jawaban' WHERE id = '$idp'");
			}
			
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data has been updated </div>");			
			redirect('admin/faq');
		} else {
			$a['data']		= $this->db->query("SELECT * FROM tb_faq")->result();
			$a['page']		= "faq/l_faq";
		}
		
		
	
		
		$this->load->view('admin/aaa', $a);
	}
	public function materi() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		
		$total_row		= $this->db->query("SELECT * FROM tb_materi")->num_rows();
	
		$per_page		= 1500000;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//if (empty($awal) || $awal == 1) { $awal = 0; } { $awal = $awal; }
		$akhir	= $per_page;
		
		$a['pagi']	= _page($total_row, $per_page, 4, base_url()."admin/surat_masuk/p");
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp					= addslashes($this->input->post('idp'));
		$judul					= addslashes($this->input->post('judul'));
		//upload config 
		$config['upload_path'] 		= './upload/materi';
		$config['allowed_types'] 	= 'gif|jpg|png|pdf|doc|docx|rar';
		$config['max_size']			= '3000000';
		$config['max_width']  		= '3000000';
		$config['max_height'] 		= '3000000';

		$this->load->library('upload', $config);
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_materi WHERE id = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Berhasil Dihapus</div>");
			redirect('admin/materi');
		} else if ($mau_ke == "add") {
			$a['page']		= "materi/f_materi";
		} else if ($mau_ke == "edt") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_materi WHERE id = '$idu'")->row();	
			$a['page']		= "materi/f_materi";
		} 
		
		else if ($mau_ke == "act_add") {	
				if ($this->upload->do_upload('file_materi')){
				$up_data	 	= $this->upload->data();					
				$this->db->query("INSERT INTO tb_materi VALUES (NULL, '$judul', '".$up_data['file_name']."')");
				}
				else 
				{
						$this->db->query("INSERT INTO tb_materi VALUES (NULL, '$judul', '')");
				} 	
		$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diinput. ".$this->upload->display_errors()."</div>");
			redirect('admin/materi');
		} else if  ($mau_ke == "act_edt") {
			
			if ($this->upload->do_upload('file_materi'))  
					
				{
				$up_data	 	= $this->upload->data();
				$this->db->query("UPDATE tb_materi SET judul = '$judul', file = '".$up_data['file_name']."'  WHERE id = '$idp'");
			}
			else   
			{
				$this->db->query("UPDATE tb_materi SET judul = '$judul' WHERE id = '$idp'");
					
			} 
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diperbaiki. ".$this->upload->display_errors()."</div>");			
			redirect('admin/materi');
		} else   
		{
			$a['data']		= $this->db->query("SELECT 	* FROM tb_materi; ")->result();
			$a['page']		= "materi/l_materi";
		}
		$this->load->view('admin/aaa', $a);
	}
	public function dokumen() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		
		$total_row		= $this->db->query("SELECT * FROM tb_dokumen")->num_rows();
	
		$per_page		= 1500000;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp					= addslashes($this->input->post('idp'));
		$judul					= addslashes($this->input->post('judul'));
		//upload config 
		$config['upload_path'] 		= './upload/dokumen';
		$config['allowed_types'] 	= 'gif|jpg|png|pdf|doc|docx|rar';
		$config['max_size']			= '3000000';
		$config['max_width']  		= '3000000';
		$config['max_height'] 		= '3000000';

		$this->load->library('upload', $config);
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_dokumen WHERE id = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Berhasil Dihapus</div>");
			redirect('admin/dokumen');
		} else if ($mau_ke == "add") {
			$a['page']		= "dokumen/f_dokumen";
		} else if ($mau_ke == "edt") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_dokumen WHERE id = '$idu'")->row();	
			$a['page']		= "dokumen/f_dokumen";
		} 
		
		else if ($mau_ke == "act_add") {	
				if ($this->upload->do_upload('file_dokumen')){
				$up_data	 	= $this->upload->data();					
				$this->db->query("INSERT INTO tb_dokumen VALUES (NULL, '$judul', '".$up_data['file_name']."')");
				}
				else 
				{
						$this->db->query("INSERT INTO tb_dokumen VALUES (NULL, '$judul', '')");
				} 	
		$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diinput. ".$this->upload->display_errors()."</div>");
			redirect('admin/dokumen');
		} else if  ($mau_ke == "act_edt") {
			
			if ($this->upload->do_upload('file_dokumen'))  
					
				{
				$up_data	 	= $this->upload->data();
				$this->db->query("UPDATE tb_dokumen SET judul = '$judul', file = '".$up_data['file_name']."'  WHERE id = '$idp'");
			}
			else   
			{
				$this->db->query("UPDATE tb_dokumen SET judul = '$judul' WHERE id = '$idp'");
					
			} 
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diperbaiki. ".$this->upload->display_errors()."</div>");			
			redirect('admin/dokumen');
		} else   
		{
			$a['data']		= $this->db->query("SELECT 	* FROM tb_dokumen; ")->result();
			$a['page']		= "dokumen/l_dokumen";
		}
		$this->load->view('admin/aaa', $a);
	}
	public function dokumen_manual() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		
		$total_row		= $this->db->query("SELECT * FROM tb_dokumen_manual")->num_rows();
	
		$per_page		= 1500000;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp					= addslashes($this->input->post('idp'));
		$judul					= addslashes($this->input->post('judul'));
		//upload config 
		$config['upload_path'] 		= './upload/dokumen_manual';
		$config['allowed_types'] 	= 'gif|jpg|png|pdf|doc|docx|rar';
		$config['max_size']			= '3000000';
		$config['max_width']  		= '3000000';
		$config['max_height'] 		= '3000000';

		$this->load->library('upload', $config);
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_dokumen_manual WHERE id = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Berhasil Dihapus</div>");
			redirect('admin/dokumen_manual');
		} else if ($mau_ke == "add") {
			$a['page']		= "dokumen_manual/f_dokumen_manual";
		} else if ($mau_ke == "edt") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_dokumen_manual WHERE id = '$idu'")->row();	
			$a['page']		= "dokumen_manual/f_dokumen_manual";
		} 
		
		else if ($mau_ke == "act_add") {	
				if ($this->upload->do_upload('file_dokumen_manual')){
				$up_data	 	= $this->upload->data();					
				$this->db->query("INSERT INTO tb_dokumen_manual VALUES (NULL, '$judul', '".$up_data['file_name']."')");
				}
				else 
				{
						$this->db->query("INSERT INTO tb_dokumen_manual VALUES (NULL, '$judul', '')");
				} 	
		$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diinput. ".$this->upload->display_errors()."</div>");
			redirect('admin/dokumen_manual');
		} else if  ($mau_ke == "act_edt") {
			
			if ($this->upload->do_upload('file_dokumen_manual'))  
					
				{
				$up_data	 	= $this->upload->data();
				$this->db->query("UPDATE tb_dokumen SET judul = '$judul', file = '".$up_data['file_name']."'  WHERE id = '$idp'");
			}
			else   
			{
				$this->db->query("UPDATE tb_dokumen_manual SET judul = '$judul' WHERE id = '$idp'");
					
			} 
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diperbaiki. ".$this->upload->display_errors()."</div>");			
			redirect('admin/dokumen_manual');
		} else   
		{
			$a['data']		= $this->db->query("SELECT 	* FROM tb_dokumen_manual; ")->result();
			$a['page']		= "dokumen_manual/l_dokumen_manual";
		}
		$this->load->view('admin/aaa', $a);
	}
	public function sop() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		
		$total_row		= $this->db->query("SELECT * FROM tb_sop")->num_rows();
	
		$per_page		= 1500000;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp					= addslashes($this->input->post('idp'));
		$judul					= addslashes($this->input->post('judul'));
		//upload config 
		$config['upload_path'] 		= './upload/sop';
		$config['allowed_types'] 	= 'gif|jpg|png|pdf|doc|docx|rar';
		$config['max_size']			= '3000000';
		$config['max_width']  		= '3000000';
		$config['max_height'] 		= '3000000';

		$this->load->library('upload', $config);
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_sop WHERE id = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Berhasil Dihapus</div>");
			redirect('admin/sop');
		} else if ($mau_ke == "add") {
			$a['page']		= "sop/f_sop";
		} else if ($mau_ke == "edt") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_sop WHERE id = '$idu'")->row();	
			$a['page']		= "sop/f_sop";
		} 
		
		else if ($mau_ke == "act_add") {	
				if ($this->upload->do_upload('file_sop')){
				$up_data	 	= $this->upload->data();					
				$this->db->query("INSERT INTO tb_sop VALUES (NULL, '$judul', '".$up_data['file_name']."')");
				}
				else 
				{
						$this->db->query("INSERT INTO tb_sop VALUES (NULL, '$judul', '')");
				} 	
		$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diinput. ".$this->upload->display_errors()."</div>");
			redirect('admin/sop');
		} else if  ($mau_ke == "act_edt") {
			
			if ($this->upload->do_upload('file_sop'))  
					
				{
				$up_data	 	= $this->upload->data();
				$this->db->query("UPDATE tb_sop SET judul = '$judul', file = '".$up_data['file_name']."'  WHERE id = '$idp'");
			}
			else   
			{
				$this->db->query("UPDATE tb_sop SET judul = '$judul' WHERE id = '$idp'");
					
			} 
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diperbaiki. ".$this->upload->display_errors()."</div>");			
			redirect('admin/sop');
		} else   
		{
			$a['data']		= $this->db->query("SELECT 	* FROM tb_sop; ")->result();
			$a['page']		= "sop/l_sop";
		}
		$this->load->view('admin/aaa', $a);
	}
	public function undang() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		
		$total_row		= $this->db->query("SELECT * FROM tb_undang")->num_rows();
	
		$per_page		= 1500000;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp					= addslashes($this->input->post('idp'));
		$judul					= addslashes($this->input->post('judul'));
		//upload config 
		$config['upload_path'] 		= './upload/undang';
		$config['allowed_types'] 	= 'gif|jpg|png|pdf|doc|docx|rar';
		$config['max_size']			= '3000000';
		$config['max_width']  		= '3000000';
		$config['max_height'] 		= '3000000';

		$this->load->library('upload', $config);
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_undang WHERE id = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Berhasil Dihapus</div>");
			redirect('admin/undang');
		} else if ($mau_ke == "add") {
			$a['page']		= "undang/f_undang";
		} else if ($mau_ke == "edt") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_undang WHERE id = '$idu'")->row();	
			$a['page']		= "undang/f_undang";
		} 
		
		else if ($mau_ke == "act_add") {	
				if ($this->upload->do_upload('file_undang')){
				$up_data	 	= $this->upload->data();					
				$this->db->query("INSERT INTO tb_undang VALUES (NULL, '$judul', '".$up_data['file_name']."')");
				}
				else 
				{
						$this->db->query("INSERT INTO tb_undang VALUES (NULL, '$judul', '')");
				} 	
		$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diinput. ".$this->upload->display_errors()."</div>");
			redirect('admin/undang');
		} else if  ($mau_ke == "act_edt") {
			
			if ($this->upload->do_upload('file_undang'))  
					
				{
				$up_data	 	= $this->upload->data();
				$this->db->query("UPDATE tb_undang SET judul = '$judul', file = '".$up_data['file_name']."'  WHERE id = '$idp'");
			}
			else   
			{
				$this->db->query("UPDATE tb_undang SET judul = '$judul' WHERE id = '$idp'");
					
			} 
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diperbaiki. ".$this->upload->display_errors()."</div>");			
			redirect('admin/undang');
		} else   
		{
			$a['data']		= $this->db->query("SELECT 	* FROM tb_undang; ")->result();
			$a['page']		= "undang/l_undang";
		}
		$this->load->view('admin/aaa', $a);
	}
	public function peraturan() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		
		$total_row		= $this->db->query("SELECT * FROM tb_peraturan")->num_rows();
	
		$per_page		= 1500000;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp					= addslashes($this->input->post('idp'));
		$judul					= addslashes($this->input->post('judul'));
		//upload config 
		$config['upload_path'] 		= './upload/peraturan';
		$config['allowed_types'] 	= 'gif|jpg|png|pdf|doc|docx|rar';
		$config['max_size']			= '3000000';
		$config['max_width']  		= '3000000';
		$config['max_height'] 		= '3000000';

		$this->load->library('upload', $config);
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_peraturan WHERE id = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Berhasil Dihapus</div>");
			redirect('admin/peraturan');
		} else if ($mau_ke == "add") {
			$a['page']		= "peraturan/f_peraturan";
		} else if ($mau_ke == "edt") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_peraturan WHERE id = '$idu'")->row();	
			$a['page']		= "peraturan/f_peraturan";
		} 
		
		else if ($mau_ke == "act_add") {	
				if ($this->upload->do_upload('file_peraturan')){
				$up_data	 	= $this->upload->data();					
				$this->db->query("INSERT INTO tb_peraturan VALUES (NULL, '$judul', '".$up_data['file_name']."')");
				}
				else 
				{
						$this->db->query("INSERT INTO tb_peraturan VALUES (NULL, '$judul', '')");
				} 	
		$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diinput. ".$this->upload->display_errors()."</div>");
			redirect('admin/peraturan');
		} else if  ($mau_ke == "act_edt") {
			
			if ($this->upload->do_upload('file_peraturan'))  
					
				{
				$up_data	 	= $this->upload->data();
				$this->db->query("UPDATE tb_peraturan SET judul = '$judul', file = '".$up_data['file_name']."'  WHERE id = '$idp'");
			}
			else   
			{
				$this->db->query("UPDATE tb_peraturan SET judul = '$judul' WHERE id = '$idp'");
					
			} 
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diperbaiki. ".$this->upload->display_errors()."</div>");			
			redirect('admin/peraturan');
		} else   
		{
			$a['data']		= $this->db->query("SELECT 	* FROM tb_peraturan; ")->result();
			$a['page']		= "peraturan/l_peraturan";
		}
		$this->load->view('admin/aaa', $a);
	}
	public function form() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		
		$total_row		= $this->db->query("SELECT * FROM tb_form")->num_rows();
	
		$per_page		= 1500000;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp					= addslashes($this->input->post('idp'));
		$judul					= addslashes($this->input->post('judul'));
		//upload config 
		$config['upload_path'] 		= './upload/form';
		$config['allowed_types'] 	= 'gif|jpg|png|pdf|doc|docx|rar';
		$config['max_size']			= '3000000';
		$config['max_width']  		= '3000000';
		$config['max_height'] 		= '3000000';

		$this->load->library('upload', $config);
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_form WHERE id = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Berhasil Dihapus</div>");
			redirect('admin/form');
		} else if ($mau_ke == "add") {
			$a['page']		= "form/f_form";
		} else if ($mau_ke == "edt") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_form WHERE id = '$idu'")->row();	
			$a['page']		= "form/f_form";
		} 
		
		else if ($mau_ke == "act_add") {	
				if ($this->upload->do_upload('file_form')){
				$up_data	 	= $this->upload->data();					
				$this->db->query("INSERT INTO tb_form VALUES (NULL, '$judul', '".$up_data['file_name']."')");
				}
				else 
				{
						$this->db->query("INSERT INTO tb_form VALUES (NULL, '$judul', '')");
				} 	
		$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diinput. ".$this->upload->display_errors()."</div>");
			redirect('admin/form');
		} else if  ($mau_ke == "act_edt") {
			
			if ($this->upload->do_upload('file_form'))  
					
				{
				$up_data	 	= $this->upload->data();
				$this->db->query("UPDATE tb_form SET judul = '$judul', file = '".$up_data['file_name']."'  WHERE id = '$idp'");
			}
			else   
			{
				$this->db->query("UPDATE tb_form SET judul = '$judul' WHERE id = '$idp'");
					
			} 
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diperbaiki. ".$this->upload->display_errors()."</div>");			
			redirect('admin/form');
		} else   
		{
			$a['data']		= $this->db->query("SELECT 	* FROM tb_form; ")->result();
			$a['page']		= "form/l_form";
		}
		$this->load->view('admin/aaa', $a);
	}
	public function pretest() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		
		$total_row		= $this->db->query("SELECT * FROM tb_pretest")->num_rows();
	
		$per_page		= 1500000;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp					= addslashes($this->input->post('idp'));
		$pemilik					= addslashes($this->input->post('pemilik'));
		$alamat					= addslashes($this->input->post('alamat'));
		$satu					= addslashes($this->input->post('satu'));
		$dua					= addslashes($this->input->post('dua'));
		$tiga					= addslashes($this->input->post('tiga'));
		$empat					= addslashes($this->input->post('empat'));
		$lima					= addslashes($this->input->post('lima'));
		$enam					= addslashes($this->input->post('enam'));
		$tujuh					= addslashes($this->input->post('tujuh'));
		$delapan				= addslashes($this->input->post('delapan'));
		$sembilan					= addslashes($this->input->post('sembilan'));
		$sepuluh					= addslashes($this->input->post('sepuluh'));
		$sebelas					= addslashes($this->input->post('sebelas'));
		$duabelas					= addslashes($this->input->post('duabelas'));
		$tigabelas					= addslashes($this->input->post('tigabelas'));
		$empatbelas					= addslashes($this->input->post('empatbelas'));
		$limabelas					= addslashes($this->input->post('limabelas'));
		$enambelas					= addslashes($this->input->post('enambelas'));
		$tujuhbelas					= addslashes($this->input->post('tujuhbelas'));
		$delapanbelas					= addslashes($this->input->post('delapanbelas'));
		$sembilanbelas					= addslashes($this->input->post('sembilanbelas'));
		$duapuluh					= addslashes($this->input->post('duapuluh'));
		$duasatu					= addslashes($this->input->post('duasatu'));
		$duadua					= addslashes($this->input->post('duadua'));
		$duatiga					= addslashes($this->input->post('duatiga'));
		$duaempat					= addslashes($this->input->post('duaempat'));
		$dualima					= addslashes($this->input->post('dualima'));
		
		$total					= $satu + $dua + $tiga + $empat + $lima + $enam + $tujuh + $delapan + $sembilan + $sepuluh + $sebelas + $duabelas + $tigabelas + $empatbelas + $limabelas + $enambelas + $tujuhbelas + $delapanbelas + $sembilanbelas + $duapuluh + $duasatu + $duadua + $duatiga + $duaempat + $dualima ;
		
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_pretest WHERE id = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Berhasil Dihapus</div>");
			redirect('admin/pretest');
		} else if ($mau_ke == "add") {
			$a['page']		= "pretest/f_pretest";
	
		} else if ($mau_ke == "act_add") {	
				{
									
				$this->db->query("INSERT INTO tb_pretest VALUES (NULL,'$pemilik', '$alamat', '$satu','$dua','$tiga', '$empat','$lima','$enam', '$tujuh','$delapan','$sembilan', '$sepuluh','$sebelas','$duabelas', '$tigabelas','$empatbelas','$limabelas', '$enambelas','$tujuhbelas','$delapanbelas', '$sembilanbelas','$duapuluh','$duasatu', '$duadua','$duatiga','$duaempat','$dualima','$total')");
				}
					
		$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diinput Nilai anda = $total.</div>");
			redirect('admin/pretest');
		} 
		else if ($this->session->userdata('admin_level') == "User") 
		{
			
			$a['data']		= $this->db->query("SELECT 	* FROM tb_pretest where pemilik = '".$this->session->userdata('admin_pemilik')."'; ")->result();
			$a['page']		= "pretest/l_pretest";
		}
		else   
		{
			$a['data']		= $this->db->query("SELECT 	* FROM tb_pretest; ")->result();
			$a['page']		= "pretest/l_pretest";
		}
		$this->load->view('admin/aaa', $a);
	}
	
	public function postest() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		
		$total_row		= $this->db->query("SELECT * FROM tb_postest")->num_rows();
	
		$per_page		= 1500000;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp					= addslashes($this->input->post('idp'));
		$pemilik					= addslashes($this->input->post('pemilik'));
		$alamat					= addslashes($this->input->post('alamat'));
		$satu					= addslashes($this->input->post('satu'));
		$dua					= addslashes($this->input->post('dua'));
		$tiga					= addslashes($this->input->post('tiga'));
		$empat					= addslashes($this->input->post('empat'));
		$lima					= addslashes($this->input->post('lima'));
		$enam					= addslashes($this->input->post('enam'));
		$tujuh					= addslashes($this->input->post('tujuh'));
		$delapan				= addslashes($this->input->post('delapan'));
		$sembilan					= addslashes($this->input->post('sembilan'));
		$sepuluh					= addslashes($this->input->post('sepuluh'));
		$sebelas					= addslashes($this->input->post('sebelas'));
		$duabelas					= addslashes($this->input->post('duabelas'));
		$tigabelas					= addslashes($this->input->post('tigabelas'));
		$empatbelas					= addslashes($this->input->post('empatbelas'));
		$limabelas					= addslashes($this->input->post('limabelas'));
		$enambelas					= addslashes($this->input->post('enambelas'));
		$tujuhbelas					= addslashes($this->input->post('tujuhbelas'));
		$delapanbelas					= addslashes($this->input->post('delapanbelas'));
		$sembilanbelas					= addslashes($this->input->post('sembilanbelas'));
		$duapuluh					= addslashes($this->input->post('duapuluh'));
		$duasatu					= addslashes($this->input->post('duasatu'));
		$duadua					= addslashes($this->input->post('duadua'));
		$duatiga					= addslashes($this->input->post('duatiga'));
		$duaempat					= addslashes($this->input->post('duaempat'));
		$dualima					= addslashes($this->input->post('dualima'));
		
		$total					= $satu + $dua + $tiga + $empat + $lima + $enam + $tujuh + $delapan + $sembilan + $sepuluh + $sebelas + $duabelas + $tigabelas + $empatbelas + $limabelas + $enambelas + $tujuhbelas + $delapanbelas + $sembilanbelas + $duapuluh + $duasatu + $duadua + $duatiga + $duaempat + $dualima ;
		
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_postest WHERE id = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Berhasil Dihapus</div>");
			redirect('admin/postest');
		} else if ($mau_ke == "add") {
			$a['page']		= "postest/f_postest";
	
		} else if ($mau_ke == "act_add") {	
				{
									
				$this->db->query("INSERT INTO tb_postest VALUES (NULL,'$pemilik', '$alamat', '$satu','$dua','$tiga', '$empat','$lima','$enam', '$tujuh','$delapan','$sembilan', '$sepuluh','$sebelas','$duabelas', '$tigabelas','$empatbelas','$limabelas', '$enambelas','$tujuhbelas','$delapanbelas', '$sembilanbelas','$duapuluh','$duasatu', '$duadua','$duatiga','$duaempat','$dualima','$total')");
				}
					
		$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diinput Nilai anda = $total.</div>");
			redirect('admin/postest');
		} 
		else if ($this->session->userdata('admin_level') == "User") 
		{
			
			$a['data']		= $this->db->query("SELECT 	* FROM tb_postest where pemilik = '".$this->session->userdata('admin_pemilik')."'; ")->result();
			$a['page']		= "postest/l_postest";
		}
		else   
		{
			$a['data']		= $this->db->query("SELECT 	* FROM tb_postest; ")->result();
			$a['page']		= "postest/l_postest";
		}
		$this->load->view('admin/aaa', $a);
	}
	
	public function mohon() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		
		$total_row		= $this->db->query("SELECT * FROM tb_mohon")->num_rows();
	
		$per_page		= 1500000;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp						= addslashes($this->input->post('idp'));
		$pemilik					= addslashes($this->input->post('pemilik'));
		$produk						= addslashes($this->input->post('produk'));
		$jenis						= addslashes($this->input->post('jenis'));
		$alamat						= addslashes($this->input->post('alamat'));
		$status						= addslashes($this->input->post('status'));
		$ket						= addslashes($this->input->post('ket'));
		//upload config 
		$config['upload_path'] 		= './upload/mohon';
		$config['allowed_types'] 	= 'gif|jpg|png|pdf|doc|docx|rar';
		$config['max_size']			= '3000000';
		$config['max_width']  		= '3000000';
		$config['max_height'] 		= '3000000';

		$this->load->library('upload', $config);
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_mohon WHERE id = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Berhasil Dihapus</div>");
			redirect('admin/mohon');
		} else if ($mau_ke == "add") {
			$a['page']		= "mohon/f_mohon";
		} else if ($mau_ke == "edt") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_mohon WHERE id = '$idu'")->row();	
			$a['page']		= "mohon/f_mohon";
		} else if ($mau_ke == "edt_ver") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_mohon WHERE id = '$idu'")->row();	
			$a['page']		= "mohon/f_mohon_ver";
		} 
		
		else if ($mau_ke == "act_add") {	
				if ($this->upload->do_upload('file_mohon1')){
				$up_data1	 	= $this->upload->data();					
				if ($this->upload->do_upload('file_mohon2')) 					
				$up_data2	 	= $this->upload->data();
				if ($this->upload->do_upload('file_mohon3')) 					
				$up_data3	 	= $this->upload->data();
				if ($this->upload->do_upload('file_mohon4')) 					
				$up_data4	 	= $this->upload->data();		
				if ($this->upload->do_upload('file_mohon5')) 					
				$up_data5	 	= $this->upload->data();
				if ($this->upload->do_upload('file_mohon6')) 					
				$up_data6	 	= $this->upload->data();
				if ($this->upload->do_upload('file_mohon7')) 					
				$up_data7	 	= $this->upload->data();
				if ($this->upload->do_upload('file_mohon8')) 					
				$up_data8	 	= $this->upload->data();
				if ($this->upload->do_upload('file_mohon9')) 					
				$up_data9	 	= $this->upload->data();	
				$this->db->query("INSERT INTO tb_mohon VALUES (NULL, '$pemilik','$produk', '$jenis','$alamat',NOW(),'$status','$ket', '".$up_data1['file_name']."','".$up_data2['file_name']."','".$up_data3['file_name']."','".$up_data4['file_name']."','".$up_data5['file_name']."','".$up_data6['file_name']."','".$up_data7['file_name']."','".$up_data8['file_name']."','".$up_data9['file_name']."')");
				}
				else 
				{
				$this->db->query("INSERT INTO tb_mohon VALUES (NULL, '$pemilik','$produk', '$jenis','$alamat', NOW(),'$status','$ket','".$up_data1['file_name']."','".$up_data2['file_name']."','".$up_data3['file_name']."','".$up_data4['file_name']."','".$up_data5['file_name']."','".$up_data6['file_name']."','".$up_data7['file_name']."','".$up_data8['file_name']."','".$up_data9['file_name']."')");
				
				} 	
		$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diinput. ".$this->upload->display_errors()."</div>");
			redirect('admin/mohon');
		} else if  ($mau_ke == "act_edt") {
				if ($this->upload->do_upload('file_mohon1')){
				$up_data1	 	= $this->upload->data();					
				if ($this->upload->do_upload('file_mohon2')) 					
				$up_data2	 	= $this->upload->data();
				if ($this->upload->do_upload('file_mohon3')) 					
				$up_data3	 	= $this->upload->data();
				if ($this->upload->do_upload('file_mohon4')) 					
				$up_data4	 	= $this->upload->data();		
				if ($this->upload->do_upload('file_mohon5')) 					
				$up_data5	 	= $this->upload->data();
				if ($this->upload->do_upload('file_mohon6')) 					
				$up_data6	 	= $this->upload->data();
				if ($this->upload->do_upload('file_mohon7')) 					
				$up_data7	 	= $this->upload->data();
				if ($this->upload->do_upload('file_mohon8')) 					
				$up_data8	 	= $this->upload->data();
				if ($this->upload->do_upload('file_mohon9')) 					
				$up_data9	 	= $this->upload->data();						
				$this->db->query("UPDATE tb_mohon SET  pemilik = '$pemilik', file1 = '".$up_data1['file_name']."', file2 = '".$up_data2['file_name']."', file3 = '".$up_data3['file_name']."', file4 = '".$up_data4['file_name']."', file5 = '".$up_data5['file_name']."', file6 = '".$up_data6['file_name']."', file7 = '".$up_data7['file_name']."', file8 = '".$up_data8['file_name']."', file9 = '".$up_data9['file_name']."' WHERE id = '$idp'");
				
				}
			
				
			else   
			{
				
				$this->db->query("UPDATE tb_mohon SET  pemilik = '$pemilik' WHERE id = '$idp'");
					
			} 
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diperbaiki. ".$this->upload->display_errors()."</div>");			
			redirect('admin/mohon');
		} else if ($mau_ke == "act_edt_ver") {
			if ($password = md5("-")) {
				$this->db->query("UPDATE tb_mohon SET status = '$status', ket = '$ket'  WHERE id = '$idp'");
			} else {
				$this->db->query("UPDATE tb_mohon SET status = '$status', ket = '$ket'  WHERE id = '$idp'");
			}
			
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data has been updated </div>");			
			redirect('admin/mohon');
	} else if ($this->session->userdata('admin_level') == "User") 
		{
			
			$a['data']		= $this->db->query("SELECT 	* FROM tb_mohon where pemilik = '".$this->session->userdata('admin_pemilik')."'; ")->result();
			
			$a['page']		= "mohon/l_mohon";
		}
	
	
	
	else   
		{
			$a['data']		= $this->db->query("SELECT 	* FROM tb_mohon; ")->result();
			$a['page']		= "mohon/l_mohon";
		}
		$this->load->view('admin/aaa', $a);
	}
	
	
	public function alur() {  
	if ($this->session->userdata('admin_coba') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		$a['page']	= "alur/l_alur";

		$this->load->view('admin/aaa', $a);
	}
	public function syarat() {  
	if ($this->session->userdata('admin_coba') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		$a['page']	= "syarat/l_syarat";

		$this->load->view('admin/aaa', $a);
	}
	public function temuan() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		
		$total_row		= $this->db->query("SELECT * FROM tb_temuan")->num_rows();
	
		$per_page		= 1500000;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp						= addslashes($this->input->post('idp'));
		$pemilik					= addslashes($this->input->post('pemilik'));
		$alamat						= addslashes($this->input->post('alamat'));
		$isi						= addslashes($this->input->post('isi'));
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_temuan WHERE id_temuan = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Berhasil Dihapus</div>");
			redirect('admin/temuan');
		} else if ($mau_ke == "add") {
			$a['page']		= "temuan/f_temuan";
		} else if ($mau_ke == "edt") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_temuan WHERE id_temuan = '$idu'")->row();	
			$a['page']		= "temuan/f_temuan";
		} 
		
		else if ($mau_ke == "act_add") {	
			
						{
									
				$this->db->query("INSERT INTO tb_temuan VALUES (NULL, '$pemilik','$alamat','$isi')");
				}
		$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diinput.</div>");
			redirect('admin/temuan');
		} else if  ($mau_ke == "act_edt") {
			
			if ($this->upload->do_upload('file_dokumen'))  
					
				{
				$up_data	 	= $this->upload->data();
				$this->db->query("UPDATE tb_temuan SET isi = '$isi' WHERE id = '$idp'");
			}
			else   
			{
				$this->db->query("UPDATE tb_temuan SET isi = '$isi' WHERE id = '$idp'");
					
			} 
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diperbaiki. ".$this->upload->display_errors()."</div>");			
			redirect('admin/temuan');
		} 
		else if ($this->session->userdata('admin_level') == "User") 
		{
			
			$a['data']		= $this->db->query("SELECT 	* FROM tb_temuan where pemilik = '".$this->session->userdata('admin_pemilik')."'; ")->result();
			$a['page']		= "temuan/l_temuan";
		}
		
		
		else   
		{
			$a['data']		= $this->db->query("SELECT 	* FROM tb_temuan ")->result();
			$a['page']		= "temuan/l_temuan";
		}
		$this->load->view('admin/aaa', $a);
	}
	
	public function perbaikan() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(4);
		$idu1					= $this->uri->segment(3);
		$idu2					= $this->uri->segment(5);
		
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp					= addslashes($this->input->post('idp'));
		$id_temuan				= addslashes($this->input->post('id_temuan'));
		$pemilik				= addslashes($this->input->post('pemilik'));
		$ket					= addslashes($this->input->post('ket'));
		$status					= addslashes($this->input->post('status'));
		
		
		$cari					= addslashes($this->input->post('q'));
		
		/* pagination */	
		$total_row		= $this->db->query("SELECT * FROM tb_perbaikan WHERE id_temuan = '$idu1'")->num_rows();
		$per_page		= 10000;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//if (empty($awal) || $awal == 1) { $awal = 0; } { $awal = $awal; }
		$akhir	= $per_page;
		
	
		$a['judul_surat']	= gval("tb_temuan", "id_temuan", "isi", $idu1);
		//upload config 
		$config['upload_path'] 		= './upload/perbaikan';
		$config['allowed_types'] 	= 'gif|jpg|png|pdf|doc|docx|rar';
		$config['max_size']			= '3000000';
		$config['max_width']  		= '3000000';
		$config['max_height'] 		= '3000000';

		$this->load->library('upload', $config);
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_perbaikan WHERE id = '$idu2'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data has been deleted </div>");
			redirect('admin/perbaikan/'.$idu1);
		} else if ($mau_ke == "add") {
			$a['page']		= "perbaikan/f_perbaikan";
		} else if ($mau_ke == "edt") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_perbaikan WHERE id = '$idu2'")->row();	
			$a['page']		= "perbaikan/f_perbaikan";
		} else if ($mau_ke == "edt_ver") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_perbaikan WHERE id = '$idu2'")->row();	
			$a['page']		= "perbaikan/f_perbaikan_ver";
		} else if ($mau_ke == "act_add") {	
				if ($this->upload->do_upload('file_perbaikan')){
				$up_data	 	= $this->upload->data();					
				$this->db->query("INSERT INTO tb_perbaikan VALUES (NULL, '$id_temuan','$pemilik','$ket', '".$up_data['file_name']."','$status')");
				}
				else 
				{
						$this->db->query("INSERT INTO tb_perbaikan VALUES (NULL, '$id_temuan','$pemilik','$ket', '','$status')");
				} 	
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diinput. ".$this->upload->display_errors()."</div>");
			redirect('admin/perbaikan/'.$idu1);
		
		} else if  ($mau_ke == "act_edt") {
			
			if ($this->upload->do_upload('file_Perbaikan'))  
					
				{
				$up_data	 	= $this->upload->data();
				$this->db->query("UPDATE tb_perbaikan SET ket = '$ket', file = '".$up_data['file_name']."'  WHERE id = '$idp'");
			}
			else   
			{
				$this->db->query("UPDATE tb_perbaikan SET ket = '$ket' WHERE id = '$idp'");
					
			} 
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diperbaiki. ".$this->upload->display_errors()."</div>");			
			redirect('admin/perbaikan/'.$idu1);
		} else if ($mau_ke == "act_edt_ver") {
			if ($password = md5("-")) {
				$this->db->query("UPDATE tb_perbaikan SET status = '$status' WHERE id = '$idp'");
			} else {
				$this->db->query("UPDATE tb_perbaikan SET status = '$status'  WHERE id = '$idp'");
			}
			
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data has been updated </div>");			
			redirect('admin/perbaikan/'.$idu1);
		
		} else if ($this->session->userdata('admin_level') == "User") {
			$a['data']		= $this->db->query("SELECT * FROM tb_perbaikan where pemilik = '".$this->session->userdata('admin_pemilik')."' AND id_temuan = '$idu1' ;")->result();
			$a['page']		= "perbaikan/l_perbaikan";
		}
		else  {
			$a['data']		= $this->db->query("SELECT * FROM tb_perbaikan  WHERE id_temuan = '$idu1'")->result();
			$a['page']		= "perbaikan/l_perbaikan";
		}
		
		$this->load->view('admin/aaa', $a);	
	}
	public function rekomendasi() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		
		$total_row		= $this->db->query("SELECT * FROM tb_rekomendasi")->num_rows();
	
		$per_page		= 1500000;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp						= addslashes($this->input->post('idp'));
		$pemilik					= addslashes($this->input->post('pemilik'));
		$alamat						= addslashes($this->input->post('alamat'));
		$isi						= addslashes($this->input->post('isi'));
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM tb_rekomendasi WHERE id_rekomendasi = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Berhasil Dihapus</div>");
			redirect('admin/rekomendasi');
		} else if ($mau_ke == "add") {
			$a['page']		= "rekomendasi/f_rekomendasi";
		} else if ($mau_ke == "edt") {
			$a['datpil']	= $this->db->query("SELECT * FROM tb_rekomendasi WHERE id_rekomendasi = '$idu'")->row();	
			$a['page']		= "rekomendasi/f_rekomendasi";
		} 
		
		else if ($mau_ke == "act_add") {	
			
						{
									
				$this->db->query("INSERT INTO tb_rekomendasi VALUES (NULL, '$pemilik','$alamat','$isi')");
				}
		$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diinput.</div>");
			redirect('admin/rekomendasi');
		} else if  ($mau_ke == "act_edt") {
			
			if ($this->upload->do_upload('file_dokumen'))  
					
				{
				$up_data	 	= $this->upload->data();
				$this->db->query("UPDATE tb_rekomendasi SET isi = '$isi' WHERE id = '$idp'");
			}
			else   
			{
				$this->db->query("UPDATE tb_rekomendasi SET isi = '$isi' WHERE id = '$idp'");
					
			} 
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data Sudah Diperbaiki. ".$this->upload->display_errors()."</div>");			
			redirect('admin/rekomendasi');
		} 
		else if ($this->session->userdata('admin_level') == "User") 
		{
			
			$a['data']		= $this->db->query("SELECT 	* FROM tb_rekomendasi where pemilik = '".$this->session->userdata('admin_pemilik')."'; ")->result();
			$a['page']		= "rekomendasi/l_rekomendasi";
		}
		
		
		else   
		{
			$a['data']		= $this->db->query("SELECT 	* FROM tb_rekomendasi ")->result();
			$a['page']		= "rekomendasi/l_rekomendasi";
		}
		$this->load->view('admin/aaa', $a);
	}
public function manage_user() {
		if ($this->session->userdata == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		/* pagination */	
		$total_row		= $this->db->query("SELECT * FROM t_user")->num_rows();
		$per_page		= 10;
		
		$awal	= $this->uri->segment(4); 
		$awal	= (empty($awal) || $awal == 1) ? 0 : $awal;
		
		//if (empty($awal) || $awal == 1) { $awal = 0; } { $awal = $awal; }
		$akhir	= $per_page;
		
		$a['pagi']	= _page($total_row, $per_page, 4, base_url()."admin/manage_user/p");
		
		//ambil variabel URL
		$mau_ke					= $this->uri->segment(3);
		$idu					= $this->uri->segment(4);
		
		$cari					= addslashes($this->input->post('q'));

		//ambil variabel Postingan
		$idp					= addslashes($this->input->post('idp'));
		$pemilik					= addslashes($this->input->post('pemilik'));
		$produk						= addslashes($this->input->post('produk'));
		$jenis						= addslashes($this->input->post('jenis'));
		$alamat						= addslashes($this->input->post('alamat'));
		$status						= addslashes($this->input->post('status'));
		
		if ($mau_ke == "del") {
			$this->db->query("DELETE FROM t_user WHERE id = '$idu'");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data has been deleted </div>");
			redirect('admin/manage_user');
		} else if ($mau_ke == "add") {
			$a['page']		= "/manage_user/f_manage_user";
		} else if ($mau_ke == "edt") {
			$a['datpil']	= $this->db->query("SELECT * FROM t_user WHERE id = '$idu'")->row();	
			$a['page']		= "manage_user/f_manage_user";
		} else if ($mau_ke == "act_add") {	
			$this->db->query("INSERT INTO t_user VALUES (NULL, '$pemilik', '$produk', '$jenis', '$alamat', '$status')");
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data has been added</div>");
			redirect('admin/manage_user');
		} else if ($mau_ke == "act_edt") {
			if ($password = md5("-")) {
				$this->db->query("UPDATE t_user SET pemilik = '$pemilik', produk = '$produk', jenis = '$jenis', alamat = '$alamat', status = '$status' WHERE id = '$idp'");
			} else {
				$this->db->query("UPDATE t_user SET pemilik = '$pemilik', produk = '$produk', jenis = '$jenis', alamat = '$alamat', status = '$status' WHERE id = '$idp'");
			}
			
			$this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Data has been updated </div>");			
			redirect('admin/manage_user');
		} else {
			$a['data']		= $this->db->query("SELECT * FROM t_user where level = 'User'")->result();
			$a['page']		= "manage_user/l_manage_user";
		}
		
		
	
		
		$this->load->view('admin/aaa', $a);
	}
	
	//---------------------------Kumpulan Cetak-----------------------------//
	public function cetak_nota() 	{
		$idu = $this->uri->segment(3);
		$a['datpil1']	= $this->db->query("SELECT * FROM data_cetak_nota WHERE id_pembayaran = '$idu'")->row();	
		$this->load->view('admin/cetak/f_cetak_nota', $a);
											}
											
	public function cetak_pelanggan() 	{
		$a['data']	= $this->db->query("SELECT * FROM t_user WHERE level ='User'")->result();
		$this->load->view('admin/cetak/f_cetak_pelanggan', $a);
	}
	public function cetak_kinerja() 	{
		$a['data']		= $this->db->query("SELECT * FROM t_user where level = 'Teknisi' order by id DESC")->result();
		$b['data']	= $this->db->query("SELECT * FROM tb_pemasangan")->result();
		$c['data']	= $this->db->query("SELECT * FROM tb_pemutusan")->result();
		$d['data']	= $this->db->query("SELECT * FROM tb_perbaikan")->result();
		$this->load->view('admin/cetak/f_cetak_kinerja', $a, $b, $c, $d);
	}
	public function config_laporan_pemasangan() {
		$a['page']	= "cetak/f_config_laporan_pemasangan";
		$this->load->view('admin/aaa', $a);
	} 	
	public function config_laporan_pembayaran() {
		$a['page']	= "cetak/f_config_laporan_pembayaran";
		$this->load->view('admin/aaa', $a);
	} 		
	public function config_laporan_pemutusan() {
		$a['page']	= "cetak/f_config_laporan_pemutusan";
		$this->load->view('admin/aaa', $a);
	}
	public function config_laporan_perbaikan() {
		$a['page']	= "cetak/f_config_laporan_perbaikan";
		$this->load->view('admin/aaa', $a);
	}
	public function cetak_laporan() {
		$jenis_surat	= $this->input->post('tipe');
		$tgl_start		= $this->input->post('tgl_start');
		$tgl_end		= $this->input->post('tgl_end');
		
		$a['tgl_start']	= $tgl_start;
		$a['tgl_end']	= $tgl_end;		

		if ($jenis_surat == "config_laporan_pemasangan") {	
			$a['data']	= $this->db->query("SELECT * FROM tb_pemasangan WHERE tgl_pasang >= '$tgl_start' AND tgl_pasang <= '$tgl_end' AND jenis = 'Pemasangan' ORDER BY id_pemasangan")->result(); 
			$this->load->view('admin/cetak/config_laporan_pemasangan', $a);
		} else if ($jenis_surat == "config_laporan_pembayaran")  {
			$a['data']	= $this->db->query("SELECT * FROM data_cetak_nota WHERE tanggal >= '$tgl_start' AND tanggal <= '$tgl_end' ORDER BY id_pembayaran")->result(); 
			$this->load->view('admin/cetak/config_laporan_pembayaran', $a);
		} else if ($jenis_surat == "config_laporan_pemutusan")  {
			$a['data']	= $this->db->query("SELECT * FROM data_pemutusan WHERE tanggal >= '$tgl_start' AND tanggal <= '$tgl_end' AND jenis = 'Pemutusan' ORDER BY id_pemutusan")->result(); 
			$this->load->view('admin/cetak/config_laporan_pemutusan', $a);	
			
			
		} else  {
			$a['data']	= $this->db->query("SELECT * FROM tb_perbaikan WHERE tanggal >= '$tgl_start' AND tanggal <= '$tgl_end' ORDER BY id_perbaikan")->result(); 
			$this->load->view('admin/cetak/config_laporan_perbaikan', $a);
		} 
		
	}
	
	
	public function passwod() {
		if ($this->session->userdata('admin_valid') == FALSE && $this->session->userdata('admin_id') == "") {
			redirect("admin/login");
		}
		
		$ke				= $this->uri->segment(3);
		$id_user		= $this->session->userdata('admin_id');
		
		//var post
		$p1				= md5($this->input->post('p1'));
		$p2				= md5($this->input->post('p2'));
		$p3				= md5($this->input->post('p3'));
		
		if ($ke == "simpan") {
			$cek_password_lama	= $this->db->query("SELECT password FROM t_user WHERE id = $id_user")->row();
			//echo 
			
			if ($cek_password_lama->password != $p1) {
				$this->session->set_flashdata('k_passwod', '<div id="alert" class="alert alert-error">Password Lama tidak sama'.$this->db->last_query().'-'.$cek_password_lama->p.'-'.$p1.'</div>');
				redirect('admin/passwod');
			} else if ($p2 != $p3) {
				$this->session->set_flashdata('k_passwod', '<div id="alert" class="alert alert-error">Password Baru 1 dan 2 tidak cocok</div>');
				redirect('admin/passwod');
			} else {
				$this->db->query("UPDATE t_admin SET password = '$p3' WHERE id = $id_user");
				$this->session->set_flashdata('k_passwod', '<div id="alert" class="alert alert-success">Password berhasil diperbaharui</div>');
				redirect('admin/passwod');
			}
		} else {
			$a['page']	= "f_passwod";
		}
		
		$this->load->view('admin/aaa', $a);
	}
	
	//login
	public function login() {
		$this->load->view('admin/login');
	}
	
	public function do_login() {
		$user = $_POST['user'];
    $pass = hash('md5', $_POST['password']);

   
    $this->form_validation->set_rules('password', 'Password', 'required|min_length[6]|max_length[15]');

    if($this->form_validation->run() == FALSE)
    {
        $this->load->view('login');
    }
    else
    {
        $res = $this->User_model->check_user($user , $pass);
        if(!empty($res))
        {
            if($res[0]['status'] == '1')
            {
               
				$data = array(
				
				
				
                    'admin_id' => $res[0]['id'],
                    'admin_user' => $res[0]['user'],
					
					'admin_status' => $res[0]['status'],
					'admin_pemilik' => $res[0]['pemilik'],
					'admin_produk' => $res[0]['produk'],
					'admin_jenis' => $res[0]['jenis'],
					'admin_alamat' => $res[0]['alamat'],
					'admin_level' => $res[0]['level'],
					
					'admin_coba' => true
					);
				
				
				
				
                $this->session->set_userdata($data);
				$a['page']	= "d_amain";
                $this->load->view('admin/aaa', $a);
            }
            else
            {
                $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Verify your email address first to login...</div>');
        redirect(base_url().'admin/login');
            }
        }
        else
        {
            $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">email/password not found</div>');
        redirect(base_url().'admin/login');
        }
    }
}

function setSession($userId,$userName) {
    
    $userSession = array('userId'=>$userId,
                         'userName'=>$userName,
                         'loggedIn'=>TRUE );
    $this->session->set_userdata($userSession);
}

		

	
	
public function get_daya(){
    if (isset($_GET['term'])) {
        $result = $this->User_model->user($_GET['term']);
        if (count($result) > 0) {
            foreach ($result as $row)
                $arr_result[] = array(
                    'label'         => $row->id,
					'fname'         => $row->fname,
					'no_hp'         => $row->no_hp,
                    'alamat'   		=> $row->alamat,
             );
                echo json_encode($arr_result);
        }
    }
}
public function get_teknisi(){
    if (isset($_GET['term'])) {
        $result = $this->User_model->teknisi($_GET['term']);
        if (count($result) > 0) {
            foreach ($result as $row)
                $arr_result[] = array(
                     'label'         => $row->id,
					'nama_teknisi'         => $row->nama_teknisi,
					'hp_teknisi'         => $row->hp_teknisi	,
					
                    
             );
                echo json_encode($arr_result);
        }
    }
}	
	
	
public function get_paket($id=0){
         #Saving...
         $this->db->simple_query('SET sql_mode ="" ');
         $items=$this->db->from('tb_paket')->where('tipe_paket', $id)->get()->row();
		$data['nilai_harga']=$items->harga;
			
			
        
		
         die(json_encode($data));
    }	
	
	
	

	

	public function logout(){
        $this->session->sess_destroy();
		redirect('admin/login');
    }
	
	
	
	public function registration()  
   {  
		$this->form_validation->set_rules('user', 'Username','required');
		 $this->form_validation->set_rules('password','Password','required');
         $this->form_validation->set_rules('confirmpswd','Password','required|matches[password]');
         $this->form_validation->set_rules('pemilik', 'Pemilik','required');
         $this->form_validation->set_rules('produk','Produk','required');
			  $this->form_validation->set_rules('jenis','Jenis Produk','required');
			    $this->form_validation->set_rules('alamat','Alamat','required');
         if($this->form_validation->run() == FALSE) {
             $this->load->view('admin/login');
         }else{
 
             $id =    $this->input->post('id');
             $user =    $this->input->post('user');
             $password =  md5($this->input->post('password'));
			 $level =    $this->input->post('level');
			 $status =    $this->input->post('status');
			$pemilik =    $this->input->post('pemilik');
			$produk =    $this->input->post('produk');
			$jenis =    $this->input->post('jenis');
			$alamat =    $this->input->post('alamat');
			
			$sql = $this->db->query("SELECT * FROM t_user where user =  '$user' 	");
			$cek_nama = $sql->num_rows();
			if ($cek_nama > 0) {
			$this->session->set_flashdata("kk", "<div class=\"alert alert-success\" id=\"alert\">Username $user Sudah Digunakan, Silakan Ganti Yang Lain</div>");
			redirect(site_url('admin/login'));
			} else 
            $this->db->query("INSERT INTO t_user VALUES (NULL, '$user', '$password', '$level', '$status', '$pemilik','$produk','$jenis','$alamat')");
             $this->session->set_flashdata("k", "<div class=\"alert alert-success\" id=\"alert\">Pendaftaran Berhasil, Data Anda Akan Diproses Petugas Kamu Maksimal 1x24 Jam, Agar Bisa Melakukan Login</div>");
			redirect(site_url('admin/login'));
         }
     }

	
	public function get_lengkap(){
    if (isset($_GET['term'])) {
        $result = $this->User_model->lengkap($_GET['term']);
        if (count($result) > 0) {
            foreach ($result as $row)
                $arr_result[] = array(
                    'label'         => $row->pemilik,
                    'alamat'   => $row->alamat,
             );
                echo json_encode($arr_result);
        }
    }
	}
	public function get_lengkap_rekomendasi(){
    if (isset($_GET['term'])) {
        $result = $this->User_model->lengkap_rekomendasi($_GET['term']);
        if (count($result) > 0) {
            foreach ($result as $row)
                $arr_result[] = array(
                    'label'         => $row->pemilik,
                    'alamat'   => $row->alamat,
             );
                echo json_encode($arr_result);
        }
    }
	}
	
		
}