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

class Welcome extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		$this->load->view('welcome_message');
	}
	
	function kaos()
	{
		$this->db->select('f_name,f_email,f_hp,f_survey, f_alamat',false);
		$this->db->where('f_event_id',165);
		$sql = $this->db->get('trn_survey');
		if($sql->num_rows()>0)
		{
			$html = "<table>
				<tr>
					<td>Nama</td>
					<td>Email</td>
					<td>HP</td>
					<td>Alamat</td>
					<td>Ukuran</td>
				</tr>";
			foreach($sql->result_array() as $row)
			{
				$data = unserialize($row['f_survey']);
				$html .= "<tr>
				<td>".$row['f_name']."</td>
				<td>".$row['f_email']."</td>
				<td>".$row['f_hp']."</td>
				<td>".$row['f_alamat']."</td>
				<td>".$data['ukuran_kaos']."</td>
				</tr>";
			}
			
			$html .= "</table>";
			
	        $namaFile = "ReportKaos";
	
	        $namaFile .=".xls";

	        header("Pragma: public");
	        header("Expires: 0");
	        header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
	        header("Content-Type: application/force-download");
	        header("Content-Type: application/octet-stream");
	        header("Content-Type: application/download");
	        header("Content-Disposition: attachment;filename=" . $namaFile . "");
			echo $html;
		}
		else
		{
			echo json_encode(array('status' => 500 , 'message'=> 'tidak ada data'));
		}
	}
}
