<?php 

class Kontak extends CI_Controller{
	 
	function __construct(){
		parent::__construct();
		$this->load->model('m_kontak');/* sesuaikan dengan nama file pada model */
		$this->load->model('m_login'); 
		$this->load->model('m_admin'); 
		$this->load->library('session');
 		$this->load->helper(array('form', 'url','tanggal'));
		if($this->session->userdata('status') != "loginbro"  and empty($this->session->userdata('email')) ){
			$this->session->set_flashdata('msg','<div class="alert alert-danger alert-dismissible">
						<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
						<strong> Admin Bukan Admin </strong>Ulangi Kembali
						</div> ');

			redirect(base_url("")); 
			
		}
	 
	}


	 
	function index(){	
		$data['title1'] = 'Kontak'; 	
		$data['title2'] = 'Ubah Data'; 	
		$data['kontak'] = $this->m_kontak->kontak();
		$data['admin'] = $this->m_admin->data_admin(); 
		$data['admin_login'] = $this->m_admin->data_admin_login(); 

 
		$this->load->view('master/header',$data); 
		$this->load->view('master/kontak/v_kontak');
		$this->load->view('master/footer',$data); 
	}
	 
	 
	public function code_ubah() {
    	
		$this->db->where('id',$this->input->post('id'));
		if ($_FILES['logo']['error'] <> 4) 
		{
				    	$query = $this->db->get('tb_kontak');
					    $row = $query->row();
					 
					    unlink("./images/kontak/$row->logo");

					  

				    	$config['upload_path']          = './images/kontak/';
						$config['allowed_types']        = 'gif|jpg|png';
					 	$config['file_name']  = url_title($this->input->post('logo',TRUE));
					    $config['remove_space'] = TRUE;

						$this->load->library('upload', $config);

						if ( ! $this->upload->do_upload('logo')){
									$this->session->set_flashdata('msg','Error');
					    			redirect('kontak');
						}else{
							$data=array(

								'nama_toko'=>  $this->input->post('nama_toko'),
								'email'=>  $this->input->post('email'),
								'nomor'=>  $this->input->post('nomor'),
								'alamat'=>  $this->input->post('alamat'),	
								'propinsi'=>  $this->input->post('propinsi'),
								'kab_kota'=>  $this->input->post('kab_kota'),
								'website'=>  $this->input->post('website'),
								'maps'=>  $this->input->post('maps'),
								'pajak'=>  $this->input->post('pajak'),
								'auto_print'=>  $this->input->post('auto_print'),
								'edit_harga'=>  $this->input->post('edit_harga'),
								'diskon'=>  $this->input->post('diskon'),
								'min_diskon'=>  $this->input->post('min_diskon'),
								'password_kasir'=>  $this->input->post('password_kasir'),
								'tampil_logo_struk'=>  $this->input->post('tampil_logo_struk'),


								'logo'=>  $this->upload->file_name

				            );
					      	$this->db->where('id',$this->input->post('id'));
		            		$this->db->update('tb_kontak',$data);
		            	 
							$data = array('upload_data' => $this->upload->data());
							 $this->session->set_flashdata('msg','success');
					    	redirect('kontak');
						}

		}else{

			$data=array(
					'nama_toko'=>  $this->input->post('nama_toko'),
		      		'email'=>  $this->input->post('email'),
		      		'alamat'=>  $this->input->post('alamat'),
		      		'nomor'=>  $this->input->post('nomor'),
		      		'propinsi'=>  $this->input->post('propinsi'),
		      		'kab_kota'=>  $this->input->post('kab_kota'),
		      		'website'=>  $this->input->post('website'),
		      		'maps'=>  $this->input->post('maps'),
		      		'pajak'=>  $this->input->post('pajak'),
		      		'edit_harga'=>  $this->input->post('edit_harga'),
		      		'auto_print'=>  $this->input->post('auto_print'),
		      		'diskon'=>  $this->input->post('diskon'),
		      		'min_diskon'=>  $this->input->post('min_diskon'),
		      		'password_kasir'=>  $this->input->post('password_kasir'),
		      		'tampil_logo_struk'=>  $this->input->post('tampil_logo_struk'),
	            );
		      	$this->db->where('id',$this->input->post('id'));
        		$this->db->update('tb_kontak',$data);
        			 $this->session->set_flashdata('msg','<div class="alert alert-success alert-dismissible">
						  <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
						  <strong> Data  berhasil disimpan  !</strong>
						</div> ');
	 
			 	$this->session->set_flashdata('msg','success');

    			redirect('kontak');
		}	
	} 
	 
}