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

class PagesController 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/userguide3/general/urls.html
	 */

	public $shop;
    public $shopData; 

    public function __construct()
    {
        parent::__construct();// you have missed this line.
        $this->load->helper('cookie');
        $this->shop = $this->input->get('shop')??$this->input->cookie('shop');
        if(!$this->shop){
            redirect(base_url("auth"));
        }
        $this->shopData =$this->adminModel->get_row("app_record",array("shop_address"=>$this->shop));
    }  
	public function contactUs()
	{
		$this->load->view('pages/contactUs');
	}

	public function contactUsSend(){
		if($this->input->post("email")){
			$to = "info@enormapps.com";
			$reply = $this->input->post("email");
			$name = $this->input->post("name");
			$from = "reconvert@enormapps.com";
			$subject = "Reg: Reconvert By EA ".$this->shop;
			$message = $name.",\r\n".$this->input->post("message");

			$headers = "From:Reconvert-EA <$from>" . "\r\n" .
		    'Reply-To:'.$name.' <'.$reply . ">\r\n" .
		    'X-Mailer: PHP/' . phpversion();
			$ok = @mail($to, $subject, $message, $headers, "-f " . $from);   
			if($ok){
				echo json_encode(["error"=>false,"msg"=>"Your request successfuly send"]);
			}else{
				echo json_encode(["error"=>true,"msg"=>"Please try again"]);
			}
			die();
		}
		echo json_encode(["error"=>true,"msg"=>"404 not found"]);

		// echo json_encode($this->input->post());
	}
	public function faq()
	{
		$this->load->view('pages/faq');
	}

	public function pricing(){
		$this->load->view('pages/pricing');	
	}

	public function install(){
		$this->load->view('pages/install');	
	}
}
