<?php
class Emaily extends Model {

public $conn = null;

	function __construct() {
		parent::Model();
		$this->load->library('email');
	}
	
	function email_test($id = 0, $key = 0, $mail = '')
	{
		if(!empty($id) and !empty($key) and !empty($mail))
		{
			$filename = getcwd().'/emailtexty/verify_prispevek.txt';
			$fd = @fopen($filename, "r");
			$contents = @fread($fd, filesize ($filename));
			@fclose ($fd);
			$contents = str_replace('%odkaz%', base_url().'aktivace/prispevku/'.$id.'/'.$key.'/', $contents);
			$contents = str_replace('%tm%', $this->data['tm'], $contents);
			$this->mail($mail, 'Aktivace', $contents);			
		}
	}	
	
	function verify_prispevok($id = 0, $key = 0, $mail = '')
	{
		if(!empty($id) and !empty($key) and !empty($mail))
		{
			$filename = getcwd().'/emailtexty/verify_prispevek.txt';
			$fd = @fopen($filename, "r");
			$contents = @fread($fd, filesize ($filename));
			@fclose ($fd);
			$contents = str_replace('%odkaz%', base_url().'aktivace/prispevku/'.$id.'/'.$key.'/', $contents);
			$contents = str_replace('%tm%', $this->data['tm'], $contents);
			$this->mail($mail, 'Aktivace', $contents);			
		}
	}
	
	function verify_hodnoceni($id = 0, $key = 0, $mail = '')
	{
		if(!empty($id) and !empty($key) and !empty($mail))
		{
			$filename = getcwd().'/emailtexty/verify_hodnoceni.txt';
			$fd = @fopen($filename, "r");
			$contents = @fread($fd, filesize ($filename));
			@fclose ($fd);
			$contents = str_replace('%odkaz%', base_url().'aktivace/hodnoceni/'.$id.'/'.$key.'/', $contents);
			$contents = str_replace('%tm%', $this->data['tm'], $contents);
			$this->mail($mail, 'Aktivace', $contents);			
		}
	}
	
	function verify_registrace($id = 0, $key = 0, $mail = '')
	{
		if(!empty($id) and !empty($key) and !empty($mail))
		{
			$filename = getcwd().'/emailtexty/verify_hodnoceni.txt';
			$fd = @fopen($filename, "r");
			$contents = @fread($fd, filesize ($filename));
			@fclose ($fd);
			$contents = str_replace('%odkaz%', base_url().'aktivace/registrace/'.$id.'/'.$key.'/', $contents);
			$contents = str_replace('%tm%', $this->data['tm'], $contents);
			$this->mail($mail, 'Aktivace', $contents);			
		}
	}
	
	function mail($to = '', $subject = '', $message = '')
	{
		$this->email->from('podpora@'.$this->data['domena'], 'Podpora');
		$this->email->to($to);
		$this->email->subject($subject);
		$this->email->message($message);
		$this->email->send();
	}
	
	function sendmail($from = '', $to = '', $subject = '', $message = '')
	{
		$this->email->from($from);
		$this->email->to($to);
		$this->email->subject($subject);
		$this->email->message($message);
		$this->email->send();
	}
}
?>
