<commit_before><?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Email_manager
{
	private $_CI;
	private $_cc = array();
	private $_bcc = array();

	public function __construct($options = array())
	{
		$this->_CI = & get_instance();
		$this->_CI->error_message = '';

		foreach ($options as $key => $value) 
		{
			$key = "_{$key}";
			if (isset($this->$key))
				$this->$key = $value;	
		}
		
	}
	
	public function initialize($params = array())
	{
		if(!count($params))
			return FALSE;
	
		foreach ($params as $key => $val)
		{
			$key = "_{$key}";
			if (isset($this->$key))
				$this->$key = $val;
		}
	
	}
	
	public function send_email($to, $toname, $from, $from_name, $subject, $message, $cc = array(),$attachments = array())
	{
		$this->_CI->config->load('email_config');
	
		$this->_CI->load->library('email', $this->_CI->config->item('email'));

		$this->_CI->email->clear(TRUE);
		
		$this->_CI->email->set_newline("\r\n");
	
		$this->_CI->email->from($from,$from_name);
		$this->_CI->email->to($to);
		$this->_CI->email->cc( array_merge($cc, $this->_cc) );
		$this->_CI->email->bcc($this->_bcc);

		$this->_CI->email->subject($subject);
		$this->_CI->email->message($message);
		foreach ($attachments as $file)
			$this->_CI->email->attach($file);
		
		if ( ! $this->_CI->email->Send())
			return FALSE;
		
		return TRUE;
	}
	
	function send_order_mail($so_id = 0, $status = null)
	{
		
		if(!$so_id)
			return FALSE;
	
		//get sales_order details
		$this->_CI->load->model('checkout_model');

		$result = $this->db->get_where("sales_order",array('id' => $so_id) );
        
        if(!$result->num_rows())
            return FALSE;
        
        $so_details = $result->row_array();
		
		$records = $this->checkout_model->get_product_details_by_sales_order($so_id);
        if(!count($records))
           return FALSE;
        
        $product_details = array();
        foreach ($records as $record)
        {
            $product_details[$record['product_id']]['sku']          = $record['sku'];
            $product_details[$record['product_id']]['name']         = $record['product_name'];
            $product_details[$record['product_id']]['sell_price']   = $record['unit_price'];
            if(isset($product_details[$record['product_id']]['quantity']))
                $product_details[$record['product_id']]['quantity'] += $record['quantity'];
            else
                $product_details[$record['product_id']]['quantity'] = $record['quantity'];
        }
        
        $data['so_details']         = $so_details;
        $data['status']				= $status;
        $data['product_details']    = $product_details;
        $data['billing'] = $this->checkout_model->get_address(array("id" => $so_details['billing_address_id'],"type"=>"ba"));
        $data['shipping'] = $this->checkout_model->get_address(array("id" => $so_details['shipping_address_id'],"type"=>"sa"));

        
        //$data['mail_type']			= 'customer';
		$data['so_id']				= $so_id;
		$data['message'] 			= $this->_CI->load->view('checkout/order-confirmation', $data, TRUE);
		
		$message = $this->_CI->load->view('checkout/system_email_template', $data, TRUE);
		
		if( strcmp($status,'FAILED') !== 0 ) 
		{	
			$mail_title = "Order Info - #{$so_id}";
		}
		else
		{
			$mail_title = "Order Info - #{$so_id} - Failed";
		}

		$this->send_email($data['billing']['email'], '', '<EMAIL>', 'gavaskar', "Order Confirmation Mail", $message);
		 
		$this->checkout_model->addaction_loginfo('sales_order', 'Order confirmation mail has been sent to customer', $so_id);

	}


	function send_fraudulent_order_mail($so_id = 0, $status = null)
	{
		
		if(!$so_id)
			return FALSE;
	
		//get sales_order details
		$this->_CI->load->model('sales_order_model');
		$result = $this->_CI->sales_order_model->get_where(array('id' => $so_id));
		
		if(!$result->num_rows())
			return FALSE;
		
		$result_set = $this->_CI->sales_order_model->check_fradulent($so_id);
        if( !count($result_set) )
        	return FALSE;

		$so_details = $result->row_array();
		
		//now get address
		$address_info = getAdddressBySoId($so_id, 'B', 'both');
		if(!$address_info)
			return FALSE;
		
		$address = $address_info['data']; <commit_msg>Email Manager Templates<commit_after><?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Email_manager
{
	private $_CI;
	private $_cc = array();
	private $_bcc = array();

	public function __construct($options = array())
	{
		$this->_CI = & get_instance();
		$this->_CI->error_message = '';

		foreach ($options as $key => $value) 
		{
			$key = "_{$key}";
			if (isset($this->$key))
				$this->$key = $value;	
		}
		
	}
	
	public function initialize($params = array())
	{
		if(!count($params))
			return FALSE;
	
		foreach ($params as $key => $val)
		{
			$key = "_{$key}";
			if (isset($this->$key))
				$this->$key = $val;
		}
	
	}
	
	


	public function send_email($to, $toname, $from, $from_name, $subject, $message, $cc = array(),$attachments = array())
	{
		/*$this->_CI->config->load('email_config');*/
	
		$this->_CI->load->library('email');

		$this->_CI->email->clear(TRUE);
		
		$this->_CI->email->set_newline("\r\n");
	
		$this->_CI->email->from($from,$from_name);
		$this->_CI->email->to($to);
		//$this->_CI->email->cc( array_merge($cc, $this->_cc) );
		//$this->_CI->email->bcc($this->_bcc);

		$this->_CI->email->subject($subject);
		$this->_CI->email->message($message);
		
		/*foreach ($attachments as $file)
			$this->_CI->email->attach($file);*/
		
		if ( ! $this->_CI->email->Send())
			return FALSE;
		
		return TRUE;
	}
	
	function send_order_mail($so_id = 0, $status = null)
	{
		
		if(!$so_id)
			return FALSE;

		//get sales_order details
		$this->_CI->load->model('checkout_model');

		$result = $this->_CI->db->get_where("sales_order",array('id' => $so_id) );

		if(!$result->num_rows())
           return FALSE;
        
        $so_details = $result->row_array();
		
		$records = $this->_CI->checkout_model->get_product_details_by_sales_order($so_id);
        
        if(!count($records))
           return FALSE;

        $product_details = array();
        foreach ($records as $record)
        {
            $product_details[$record['product_id']]['sku']          = $record['sku'];
            $product_details[$record['product_id']]['name']         = $record['product_name'];
            $product_details[$record['product_id']]['sell_price']   = $record['unit_price'];
            if(isset($product_details[$record['product_id']]['quantity']))
                $product_details[$record['product_id']]['quantity'] += $record['quantity'];
            else
                $product_details[$record['product_id']]['quantity'] = $record['quantity'];
        }
        

        $data['so_details']         = $so_details;
        $data['status']				= $status;
        $data['product_details']    = $product_details;
        $data['billing'] = $this->_CI->checkout_model->get_address(array("id" => $so_details['billing_address_id'],"type"=>"ba"));
        $data['shipping'] = $this->_CI->checkout_model->get_address(array("id" => $so_details['shipping_address_id'],"type"=>"sa"));

        
        $data['mail_type']			= 'customer';
		$data['so_id']				= $so_id;
		$data['message'] 			= $this->_CI->load->view('checkout/order-confirmation', $data, TRUE);
		
		$message = $this->_CI->load->view('checkout/system_email_template', $data, TRUE);
		
		if( strcmp($status,'FAILED') !== 0 ) 
		{	
			$mail_title = "Order Info - #{$so_id}";
		}
		else
		{
			$mail_title = "Order Info - #{$so_id} - Failed";
		}


		$this->send_email("<EMAIL>", 'gavas', '<EMAIL>', 'gavaskar', "Order Confirmation Mail", $message);
		 
		$this->_CI->checkout_model->addaction_loginfo('sales_order', 'Order confirmation mail has been sent to customer', $so_id);

	}


	function send_fraudulent_order_mail($so_id = 0, $status = null)
	{
		
		if(!$so_id)
			return FALSE;
	
		//get sales_order details
		$this->_CI->load->model('sales_order_model');
		$result = $this->_CI->sales_order_model->get_where(array('id' => $so_id));
		
		if(!$result->num_rows())
			return FALSE;
		
		$result_set = $this->_CI->sales_order_model->check_fradulent($so_id);
        if( !count($result_set) )
        	return FALSE;

		$so_details = $result->row_array();
		
		//now get address
		$address_info = getAdddressBySoId($so_id, 'B', 'both');
		if(!$address_info)
			return FALSE;
		
		$address = $address_info['data']; 
{'fraction_non_alphanumeric': 0.2056151940545004, 'fraction_numerical': 0.00070779756989501, 'mean_word_length': 3.3836608066184075, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 186, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3288251', 'n_tokens_mistral': 3234, 'n_tokens_neox': 2885, 'n_words': 450}