<?php 
	defined('BASEPATH') OR exit('No direct script access allowed');
error_reporting(0);
class Home extends CI_Controller {
      function __construct(){
            parent::__construct();
			$this->load->library('session');
			$this->load->model('m_home');
			$this->load->model('m_pesan');
			$this->load->model('m_kategori');
			$this->load->model('m_fasilitas');
			$this->load->model('m_slide');
			$this->load->model('m_client');
			$this->load->model('m_icon');
			$this->load->model('m_infosewa');
      }
	public function index()
	{
	//template
	$headeractive = $this->uri->segment(1);
	$cek = $this->m_home->getmenu($headeractive);
	$title = $cek->title;
	$description = $cek->description;
	$data['title'] = $title;
	$data['description'] =$description;
	$data['headeractive'] = $headeractive;
	$data['kategori'] = $this->m_kategori->filterkategori();	
	$data['slide'] = $this->m_slide->tampilhome();	
	$data['client'] = $this->m_client->tampilhome();	
	$data['icon'] = $this->m_icon->tampilhome();		
	$data['infosewa'] = $this->m_infosewa->tampilhome();	
	/*
	//cek jatuh tempo 
	$cekdata = $this->m_pesan->pesan_lama();	
	foreach($cekdata->result() as $row){
	$jttempo = date('Y-m-d', strtotime('+3 days', strtotime( $row->tglpesan )));
	
	$jtsekarang = date('Y-m-d');
	//$tempo = $jttempo - $jthari;
	if($jtsekarang >= $jttempo){
		$idpesan = $row->idpesan;

		$data_save = array(
					'status' => '2'
						);			
		$where = array(
						'idpesan' => $idpesan,
						'disetujui' => 0
				);
		$this->m_pesan->update($where,$data_save,'pesan');						
	}
	}
	*/
	//template
	$this->load->view('top', $data);	
	$this->load->view('header',$data);		
	$this->load->view('slide', $data);	
	$this->load->view('content',$data);	
	$this->load->view('foot', $data);
	$this->load->view('footjs');	
	}
	function detail()
	{
	//template
	
	$headeractive = $this->uri->segment(1);
	$idkategori = intval($this->uri->segment(3));
	$idfasilitas = intval( $this->uri->segment(4));
	if($idkategori AND $idfasilitas){
	$id = $idfasilitas;
	$cek = $this->m_home->getmenu($headeractive);
	$title = $cek->title;
	$description = $cek->description;
	$data['title'] = $title;
	$data['description'] =$description;
	$data['headeractive'] = $headeractive;
	$data['detailfilekategori'] = $this->m_kategori->detailfilekategori($idfasilitas);	
	$data['icon'] = $this->m_icon->tampilhome();		
	$data['fasilitas'] = $this->m_fasilitas->edit($id);	
	$id = $idkategori;
	$data['namakategori'] = $this->m_kategori->edit($id);	
	$this->load->view('top', $data);	
	$this->load->view('header',$data);		
	$this->load->view('detail',$data);	
	$this->load->view('foot', $data);
	$this->load->view('footjs');	
	}else{
	//template
	$headeractive = $this->uri->segment(1);
	$cek = $this->m_home->getmenu($headeractive);
	$title = $cek->title;
	$description = $cek->description;
	$data['title'] = $title;
	$data['description'] =$description;
	$data['headeractive'] = $headeractive;
	$data['kategori'] = $this->m_kategori->filterkategori();	
	$data['slide'] = $this->m_slide->tampilhome();	
	$data['client'] = $this->m_client->tampilhome();		
	$data['icon'] = $this->m_icon->tampilhome();
	$data['infosewa'] = $this->m_infosewa->tampilhome();			
	$this->load->view('top', $data);	
	$this->load->view('header',$data);		
	$this->load->view('slide', $data);	
	$this->load->view('content',$data);	
	$this->load->view('foot', $data);	
	$this->load->view('footjs');			
	}
	}	
	public function tes()
	{
		$this->load->view('tes');
	}


	public function pesanwa()
	{
// Ambil data nama dan alamat dari formulir
        //$nama = $this->input->post('nama');
        //$alamat = $this->input->post('alamat');
        
        // Muat konfigurasi Twilio
        $this->config->load('twilio');
        
        // Kirim notifikasi WhatsApp menggunakan Twilio
        $this->load->library('twilio');
        $this->twilio->sms($this->config->item('twilio_whatsapp_number'), '+6282330623370', 
            "Pengguna dengan nama $nama dan alamat $alamat telah mengisi formulir.");
        
        // Redirect ke halaman sukses atau tampilkan pesan sukses
       // redirect('success_page');		
	   echo 'Suksess';
	}		
}
