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

class Home extends MY_Controller {

	function __construct() {
        parent::__construct();
		$this->load->library('email');
		error_reporting(0);
    }

	public function upi(){	
		$this->load->view('upi');
	}


public function ajax_enq(){
	 		//parse_str($_POST['formdata'],$_POST);
			//print_r($_POST);exit;	
			$this->load->library('email');
		    $message =$this->load->view("en_mail",$_POST,true); 
			//$this->load->view("appt_mail",$data,true);//exit;
			$this->email->set_newline("\r\n");
			$this->email->set_mailtype("html");
			$this->email->to("orders@investoromatic.com,satshl3112@gmail.com");
			$this->email->from("info@investoromatic.com");
			$this->email->subject('Order Enquiry');
			$this->email->message($message);
			if(!empty($_FILES["photo"]["name"])){

			$config['upload_path'] = './assets/img/';

			$config['allowed_types'] = 'gif|jpg|png|jpeg|svg|pdf|doc|docx|xls|csv';

			$config['max_size']	= '1000000';

			$this->upload->initialize($config);

			if (!$this->upload->do_upload('photo'))

			{

			echo $this->upload->display_errors();

			}

			else

			{

			$pic = $this->upload->data();

			$img=$pic['file_name'];

			$this->email->attach('./assets/img/'.$img);

			}

		}
		//	$this->email->send();
			if($this->email->send()==true){
		    echo '<div class="alert alert-succcess"><h2>Your Enquiry Received Successfully. We will get back to you soon.</h2></div>';
			}else{echo '<div class="alert alert-danger"><h2>Your Enquiry Couldnot be sent. Please try later.</h2></div>';}

}
	public function index(){	
		$this->load->view('header');
		$this->load->view('newhome');
		$this->load->view('footer');
	}
	
	public function index1()
	{
		
		//$this->load->view('adminlogin');
		$data =array();
		$this->template['middle'] = $this->load->view ($this->middle = 'home',$data,true);
		$this->layout();	
	}
	public function privacy()
	{
		$data =array();
		$this->template['middle'] = $this->load->view ($this->middle = 'privacy',$data,true);
		$this->layout();	
	}public function refund()
	{
		$data =array();
		$this->template['middle'] = $this->load->view ($this->middle = 'refund',$data,true);
		$this->layout();	
	}
	public function terms()
	{
		$data =array();
		$this->template['middle'] = $this->load->view ($this->middle = 'terms',$data,true);
		$this->layout();	
	}
	
	public function ajax_freeform(){
		    parse_str($_POST['formdata'],$_POST);
			//print_r($_POST);exit;
		    $this->db->insert("contact",$_POST);		
		    $message = $this->load->view("en_mail",$_POST,true); 
			//$this->load->view("appt_mail",$data,true);//exit;
			$this->email->set_newline("\r\n");
			$this->email->set_mailtype("html");
			$this->email->to("info@theglobecapitalpvtltd.in");
			$this->email->from("info@theglobecapitalpvtltd.in");
			$this->email->subject('Contact FreeTrial Enquiry');
			$this->email->message($message);
			$this->email->send();
			if($this->email->send()==true){
		    echo '<div class="alert alert-succcess"><h3>Your Enquiry Received Successfully. We will get back to you soon.</h3></div>';
			}else{echo '<div class="alert alert-danger"><h3>Your Enquiry Couldnot be sent. Please try later.</h3></div>';}
	}
	
	

	   	  public function newhome(){	
		$this->load->view('header');
		$this->load->view('newhome');
		$this->load->view('footer');
	   }

	     public function about(){	
		$this->load->view('header');
		$this->load->view('about');
		$this->load->view('footer');
	   }

	   
	     public function services(){	
		$this->load->view('header');
		$this->load->view('services');
		$this->load->view('footer');
	   }
	   
	     public function contact(){	
		$this->load->view('header');
		$this->load->view('contact');
		$this->load->view('footer');
	   }

	    public function shop(){	
		$this->load->view('header');
		$this->load->view('shop');
		$this->load->view('footer');
	   }

	     public function cart(){	
		$this->load->view('header');
		$this->load->view('cart');
		$this->load->view('footer');
	   }

	      public function portfolio(){	
		$this->load->view('header');
		$this->load->view('portfolio');
		$this->load->view('footer');
	   }
	     public function checkout(){	
		$this->load->view('header');
		$this->load->view('checkout');
		$this->load->view('footer');
	   }

	    public function shopdetail(){	
		$this->load->view('header');
		$this->load->view('shopdetail');
		$this->load->view('footer');
	   }

	     public function blogs(){	
		$this->load->view('header');
		$this->load->view('blogs');
		$this->load->view('footer');
	   }

	      public function pricing(){	
		$this->load->view('header');
		$this->load->view('pricing');
		$this->load->view('footer');
	   }

	    public function newfaqs(){	
		$this->load->view('header');
		$this->load->view('newfaqs');
		$this->load->view('footer');
	   }




	    	
	   

	   


	public function admin()
	{
		$this->load->view('adminlogin');
	}
	
	
	public function testpdf(){
		$this->load->library('Pdf');
		$pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
		$pdf->SetTitle('Pdf Example');
		$pdf->SetHeaderMargin(30);
		$pdf->SetTopMargin(20);
		$pdf->setFooterMargin(20);
		$pdf->SetAutoPageBreak(true);
		$pdf->SetAuthor('Author');
		$pdf->SetDisplayMode('real', 'default');
		$pdf->Write(5, 'CodeIgniter TCPDF Integration');
		$pdf->Output('pdfexample.pdf', 'I');	
	}
	
	public function employee()
	{
		$this->load->view('emplogin');
	}
	
	public function adminlogin(){
		//echo "<pre>";print_r($_POST);exit;
		$chk=$this->db->get_where("admin",array("username"=>$this->input->post("username"),"password"=>md5($this->input->post("password"))));
		if($chk->num_rows()>0)
		{
			$d=$chk->row();
			$data=array("admin"=>"true","type"=>'admin',"loggeduser"=>"admin");
						$this->session->set_userdata($data);
						redirect("admin");
		}
		else
		{
			$this->session->set_flashdata('msg', 'Invalid Username or Password');	
			redirect("home");
		}
	}
	
	public function emplogin(){
		$chk=$this->db->get_where("employees",array("emp_email"=>$this->input->post("username"),"emp_password"=>md5($this->input->post("password")),"emp_status"=>""));
		$chk2=$this->db->get_where("employees",array("mob1"=>$this->input->post("username"),"emp_password"=>md5($this->input->post("password")),"emp_status"=>""));

		if($chk->num_rows()>0)
		{
			$d=$chk->row();
			$roles=$this->db->get_where("emp_des",array("emp_id"=>$d->emp_id))->result();
			$role=array();
			foreach($roles as $r){array_push($role,$r->des_id);}
			$roles=implode(",",$role);
			$data=array("user"=>$d->emp_id,"employee"=>"true","type"=>'employee',"roles"=>$roles,"branch"=>$d->branch_id,"img"=>$d->profile_photo,"loggeduser"=>$d->firstname.' '.$d->lastname);
						$this->session->set_userdata($data);
						redirect("employee");
		}
		else if($chk2->num_rows()>0)
		{
			$d=$chk2->row();
			$roles=$this->db->get_where("emp_des",array("emp_id"=>$d->emp_id))->result();
			$role=array();
			foreach($roles as $r){array_push($role,$r->des_id);}
			$roles=implode(",",$role);
			$data=array("user"=>$d->emp_id,"employee"=>"true","type"=>'employee',"roles"=>$roles,"branch"=>$d->branch_id,"img"=>$d->profile_photo,"loggeduser"=>$d->firstname.' '.$d->lastname);
						$this->session->set_userdata($data);
						redirect("employee");
		}else
		{
			$this->session->set_flashdata('msg', 'Invalid Email or Password');	
			redirect("home/employee");
		}
	}
}
