<?php

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

class Reseller extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('model_app');
    }

    private $view = "frontend";

    public function index() {
        $key['key_page'] = 'reseller';
        $data = array(
            'title' => "Daftar Reseller Amazink | amazinkprint.com",
            'meta_desc' => "Daftar Menjadi Reseller Resmi AMAZiNK di Kota Anda. Click Here.",
            'met_key' => "Daftar Reseller Amazink | amazinkprint.com",
            'home' => "",
            'reseler' => $this->model_app->getSelectedData('page',$key),
            'slide' => $this->model_app->getAllData_order_by("slider_toko", "no_urut", "asc")
        );
        renderFront("$this->view/v_reseller", $data);
    }
    
    function statisPage(){
        $data = array(
            'title' => "Daftar Reseller Amazink | amazinkprint.com",
            'meta_desc' => "Daftar Menjadi Reseller Resmi AMAZiNK di Kota Anda. Click Here.",
            'met_key' => "Daftar Reseller Amazink | amazinkprint.com",
            'home' => "",
            'reseler' => $this->model_app->getAllData('reseller'),
        );
        renderFront("$this->view/v_reseller_statis", $data);
    }

    function simpan() {
        $this->load->library('form_validation');
        
        $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
        $this->form_validation->set_message('required', 'Field %s harus diisi');

        $this->form_validation->set_rules('txtnama', 'Nama', 'required');
        $this->form_validation->set_rules('txtemail', 'Email', 'required|valid_email');
        $this->form_validation->set_rules('txtalamat', 'Alamat', 'required');
        $this->form_validation->set_rules('txtnotelp', 'No Telepon', 'required');
        $this->form_validation->set_rules('txtpesan', 'Pesan', 'required');
        if ($this->form_validation->run()) {
            $sql = "INSERT INTO reseller_guest(nama,email,alamat,notelp,pesan,dateadded,datemodified) 
                        VALUES(?,?,?,?,?,NOW(),NOW())";
            $nama = $this->input->post("txtnama", TRUE);
            $email = $this->input->post("txtemail", TRUE);
            $alamat = $this->input->post("txtalamat", TRUE);
            $notelp = $this->input->post("txtnotelp", TRUE);
            $pesan = $this->input->post("txtpesan", TRUE);
            $simpan = $this->db->query($sql, array($nama, $email, $alamat, $notelp, $pesan));

            //$to = "info.amazink@gmail.com";
            $to = "blognyaprast@gmail.com";
            $subject = "Resseler";

            $message = "
<html>
<head>
<title>Data Resseler</title>
</head>
<body>
<p>Permohonan Resseler</p>
<table>
<tr>
<th>nama</th>
<th>email</th>
<th>alamat</th>
<th>notelp</th>
</tr>
<tr>
<td>$nama</td>
<td>$email</td>
<td>$alamat</td>
<td>$notelp</td>
</tr>
</table>
<p>Pesan : </p>
<p>$pesan</p>
</body>
</html>
";

// Always set content-type when sending HTML email
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
            $headers .= 'From: <amazinkprint@amazink.com>' . "\r\n";

            mail($to, $subject, $message, $headers);


            $this->session->set_flashdata("green", "Terima kasih {$nama}, telah mengisi form reseller kami");
            redirect('reseller');
            //$simpan = $this->m_reseller->simpan();
            //$data["message_contact"] = "Terima kasih {$nama} telah mengisi form kontak kami";
        } else {

            $this->session->set_flashdata("red", "Maaf System sedang mengalami gangguan mohon periksa kembali seluruh inputan anda");
            redirect('reseller');
        }
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */