<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Email extends MY_Controller{
	public function index(){
	}
	
	public function send_report(){
		ini_set("memory_limit", "-1");
		
		$this->load->model("email_model");
		$this->load->model("pdf_model");
		$this->load->model("email_distribution_model");
		$post = $this->input->post();
		
//		sleep(2);
		if($this->input->post('CONTENT') != ""){
			$data_array = $this->email_distribution_model->get_data("REPORT = '".$this->input->post('REPORT')."'");
			
			if(count($data_array) > 0){
				$email_array = array();
				foreach($data_array as $v){
					if($v->EMAIL != "") array_push($email_array, $v->EMAIL);
				}
				
				$data['content'] = $post['CONTENT'];
				
				//PDF---
				$path = "assets/pdf_temp";
				$filename = $this->input->post('SUBJECT')." ".date("ymdHis").".pdf";
//				$this->pdf_model->generate("convert_pdf/index", $data, $filename, $path);
				//------
				
//				if($this->email_model->send($email_array, $this->input->post('SUBJECT'), $this->load->view("convert_pdf/index", $data, TRUE), "", "", array($path."/".$filename))){
				if($this->email_model->send($email_array, $this->input->post('SUBJECT'), $this->load->view("convert_pdf/index", $data, TRUE), "", "")){
//					unlink($path."/".$filename);
					
					echo "1";
				}
			}
			else{
				echo "1";
			}
		}
	}
}