<?php
Class Enquiry extends CI_Controller{

    function __construct()
    {
        parent::__construct();
        $this->load->model('View_data');
		$this->load->model('Common_model');
        $this->load->helper(array('html','language','form','text'));
		$this->load->library('session');
    }

	
    public function contact_us()
    {
		$name = $this->input->post('name');
		$email = $this->input->post('email');
		$mobile = $this->input->post('mobile');
		$department = $this->input->post('department');
		$message = $this->input->post('message');
		
		$data['name'] = $name;
		$data['email'] = $email;
		$data['mobile'] = $mobile;
		$data['department'] = $department;
		$data['message'] = $message;
		$ci = get_instance();
		$ci->load->library('email');
		
		$config['protocol'] = $ci->config->item('protocol');
		$config['smtp_host'] = $ci->config->item('host');
		$config['smtp_port'] = $ci->config->item('port');
		$config['smtp_user'] = $ci->config->item('user');
		$config['smtp_pass'] = $ci->config->item('pass');
		$config['charset'] = "utf-8";
		$config['mailtype'] = "html";
		//$config['newline'] = "\r\n";

		$ci->email->set_newline("\r\n");	 
	    $ci->email->set_header('HTTP/1.1 200 OK');
	    $ci->email->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
	    $ci->email->set_header('Cache-Control: no-store, no-cache, must-revalidate');
	    $ci->email->set_header('Cache-Control: post-check=0, pre-check=0');
	    $ci->email->set_header('Pragma: no-cache');
		
		$ci->email->initialize($config);   
		$ci->email->from($email, $name);
		$list = array($ci->config->item('to'));
		$ci->email->to($list);    
		$subject = 'Online Enquiry';
		$ci->email->subject($subject);
		$body = $ci->load->view('Frontend/emails/contactenquiry.php',$data,TRUE);
		$ci->email->message($body);
		$ci->load->library('encrypt');
			
	  if($ci->email->send()){
			$this->session->set_flashdata('success', TRUE);
			$mailsubject = 'Thanks For Enquiry';
			$feedback = 'Thank You for enquiry, we will revert to you soon. For Any Query Please call us on :'.$this->config->item('mobile');
			$this->mailtocustomer($name, $email,$mailsubject, $feedback);
			redirect('feedback', 'location');
			} else {
			 $this->session->set_flashdata('success', FALSE);
		   redirect('feedback', 'location');
		}
    }
	public function register_now()
	{
	 $name = $this->input->post('name');
	 $email = $this->input->post('email');
	 $mobile = $this->input->post('mobile');
	 $phone = $this->input->post('phone');
	 $code = $this->input->post('code');
	 $category = $this->input->post('category');
	 $person = $this->input->post('owner');
	 $fax = $this->input->post('fax');
	 $address = $this->input->post('address');
	 $city = $this->input->post('city');
	 $state = $this->input->post('state');
	 $pincode = $this->input->post('pincode');

	$data['name'] = $name;
	$data['email'] = $email;
	$data['mobile'] = $mobile;
	$data['phone'] = $phone;
	$data['fax'] = $fax;
	$data['code'] = $code;
	$data['category'] = $category;
	$data['address'] = $address." ".$city." ".$state." ".$pincode;
	$data['owner'] = $person;
		
	 $ci = get_instance();
	 $ci->load->library('email');
	 $config['protocol'] = $ci->config->item('protocol');
	 $config['smtp_host'] = $ci->config->item('host');
	 $config['smtp_port'] = $ci->config->item('port');
	 $config['smtp_user'] = $ci->config->item('user');
	 $config['smtp_pass'] = $ci->config->item('pass');
	 $config['charset'] = "utf-8";
	 $config['mailtype'] = "html";
	 //$config['newline'] = "\r\n";
	 $ci->email->set_newline("\r\n");	 
	    $ci->email->set_header('HTTP/1.1 200 OK');
	    $ci->email->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
	    $ci->email->set_header('Cache-Control: no-store, no-cache, must-revalidate');
	    $ci->email->set_header('Cache-Control: post-check=0, pre-check=0');
	    $ci->email->set_header('Pragma: no-cache');

		$ci->email->initialize($config);   
		$ci->email->from($email, $name);
		$list = array($ci->config->item('to'));
		$ci->email->to($list);    
		$subject = 'Vendor Registration Form';
		$ci->email->subject($subject);
		$body = $ci->load->view('Frontend/emails/supplierenquiry.php',$data,TRUE);
		$ci->email->message($body);
		$ci->load->library('encrypt');
	 
	 if($ci->email->send()) {
			$this->session->set_flashdata('success', TRUE);
			$mailsubject ='Registration Confirmation';
			$feedback = 'Thank You!! Your registration has been successfully done. We will revert to you soon. For Any Query Please call us on :'.$this->config->item('mobile');
			$this->mailtocustomer($name, $email,$mailsubject,$feedback);
			redirect('feedback', 'location');
			} else {
			 $this->session->set_flashdata('success', FALSE);
		   redirect('feedback', 'location');
		}
	}
	
	public function sendresume()
    {
	 $mobile = $this->input->post('mobile');	
	 move_uploaded_file($_FILES['up_resume']['tmp_name'],'assets/resume'.$mobile.'.pdf');
	 
	 $fname = $this->input->post('fname');
	 $lname = $this->input->post('lname');
	 $email = $this->input->post('email');
	 $birthdate = $this->input->post('birthdate');
	 $years = $this->input->post('years');
	 $months = $this->input->post('months');
	 $qualification = $this->input->post('qualification');
	 $key_role = $this->input->post('key_role');
	 $experience = $years."yr ".$months." months";
	 $name= $fname." ".$lname;
	 $mailsubject="Confirmation";
	 $message = ' Thank you for Applying, We will revert you in 5 Working days to your email & Phone.';
	 $this->mailtocustomer($name,$email,$mailsubject,$message);
	 $this->mailtoadmin($fname,$lname,$email,$mobile,$qualification,$birthdate,$experience,$key_role);	 
	 
	$this->session->set_flashdata('success',TRUE);
	redirect('feedback', 'location');
	}

	public function mailtoadmin($fname,$lname,$email,$mobile,$qualification,$birthdate,$experience,$key_role)
	{
	 $filepath = 'assets/resume'.$mobile.'.pdf';
	 $data['name'] = $fname." ".$lname;
	 $data['email'] = $email;
	 $data['mobile'] = $mobile;
	 $data['qualification'] = $qualification;
	 $data['birthdate'] = $birthdate;
	 $data['experience'] = $experience;
	 $data['keyrole'] = $key_role;
	 
	 $ci = get_instance();
	 $ci->load->library('email');
	 $config['protocol'] = $ci->config->item('protocol');
	 $config['smtp_host'] = $ci->config->item('host');
	 $config['smtp_port'] = $ci->config->item('port');
	 $config['smtp_user'] = $ci->config->item('user');
	 $config['smtp_pass'] = $ci->config->item('pass');
	 $config['charset'] = "utf-8";
	 $config['mailtype'] = "html";
	 //$config['newline'] = "\r\n";

	 $ci->email->set_newline("\r\n");	 
	    $ci->email->set_header('HTTP/1.1 200 OK');
	    $ci->email->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
	    $ci->email->set_header('Cache-Control: no-store, no-cache, must-revalidate');
	    $ci->email->set_header('Cache-Control: post-check=0, pre-check=0');
	    $ci->email->set_header('Pragma: no-cache');
		
		$ci->email->initialize($config);   
		$ci->email->from($email, $name);
		$list = array($ci->config->item('to'));
		$ci->email->to($list);    
		$subject = "Applicant's Details";
		$ci->email->subject($subject);
		$body = $ci->load->view('Frontend/emails/resume-enquiry.php',$data,TRUE);
		$ci->email->attach(FCPATH.$filepath);
		$ci->email->message($body);
		$ci->load->library('encrypt');
	
		$ci->email->send();
	}

	public function mailtocustomer($name, $email,$mailsubject,$feedback)
	{
	 $ci = get_instance();
	 $ci->load->library('email');
	  	$data['feedback'] = $feedback;
		$data['name'] = $name;

	    $ci->load->library('email');
	    $config['protocol'] = $ci->config->item('protocol');
	    $config['smtp_host'] = $ci->config->item('host');
	    $config['smtp_port'] = $ci->config->item('port');
	    $config['smtp_user'] = $ci->config->item('user');
	    $config['smtp_pass'] = $ci->config->item('pass');
	    $config['charset'] = "utf-8";
	    $config['mailtype'] = "html";
	    //$config['newline'] = "\r\n";
	    $ci->email->set_newline("\r\n");	 
	    $ci->email->set_header('HTTP/1.1 200 OK');
	    $ci->email->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
	    $ci->email->set_header('Cache-Control: no-store, no-cache, must-revalidate');
	    $ci->email->set_header('Cache-Control: post-check=0, pre-check=0');
	    $ci->email->set_header('Pragma: no-cache');

	    $ci->email->initialize($config);   
	    $ci->email->from($ci->config->item('to'), $ci->config->item('company'));
	    $list = array($email);
	    $ci->email->to($list);    
	    $subject = $mailsubject;
	    $ci->email->subject($subject);
	    $body = $ci->load->view('Frontend/emails/mailtocustomer.php',$data,TRUE);
	    $ci->email->message($body);
	    $ci->load->library('encrypt');
        
		if($ci->email->send())
		{
		  return true;
		}
		else {
  
		  return false;
		}
	}

}
