<?php 
require_once "swift/swift_required.php";
/*
if($_GET['id']){
require('../config.php');
require('../init.php');
}*/
class eMail extends Swift {

	var $settings;
	
	function eMail() {
		global $db;	
		$this->db = $db;
		$this->tpl = $tpl;
		$this->path = $_SERVER['DOCUMENT_ROOT'] . "/";	
					
		$this->Set_Vars();
		$transport = Swift_SmtpTransport::newInstance($this->settings['server'], 25);
		$this->mailer = Swift_Mailer::newInstance($transport);
	}
	
	function Set_Vars(){
		$this->settings = array();
		$this->settings['server'] = "localhost";
		$this->settings['from_email'] = "info@dentalnistudio.si"; 
		$this->settings['from_name'] = "Dentalni studio";
		$this->settings['notice_email'] = "info@dentalnistudio.si";
	}
	
	function kontakt($email,$p){
		$this->email['to_email'] = $email;
		$this->email['subject'] = "Prijava na pregled na spletni strani ".$_SERVER['SERVER_NAME'];
		
		$tpl=new TemplatePower("templates/mail/mail.tpl");
		$tpl->prepare();
		
		foreach($p as $key=>$val)
			$tpl->assign($key,$val);
			
		if($p['na_prvi_pregled'])
			$tpl->assignGlobal("prvi_pregled","DA");
		else
			$tpl->assignGlobal("prvi_pregled","NE");
		$tpl->assignGlobal("server_name",$_SERVER['SERVER_NAME']);
		$tpl->prepare();
		
		$this->email['text']=$tpl->getOutputContent();
		
		$this->Send();
		$this->kontakt_confirm($p);
	}
	
	function kontakt_confirm($p){
		$this->email['to_email'] = $p['e-naslov'];
		$this->email['subject'] = "Prijava na pregled na spletni strani ".$_SERVER['SERVER_NAME'];
		
		$tpl=new TemplatePower("templates/mail/mail.tpl");
		$tpl->prepare();
		
		foreach($p as $key=>$val)
			$tpl->assign($key,$val);
			
		if($p['na_prvi_pregled'])
			$tpl->assignGlobal("prvi_pregled","DA");
		else
			$tpl->assignGlobal("prvi_pregled","NE");
		$tpl->assignGlobal("server_name",$_SERVER['SERVER_NAME']);
		$tpl->prepare();
		$tpl->newBlock("notice1");
		$tpl->prepare();
		$tpl->newBlock("notice2");
		$tpl->prepare();
		
		$this->email['text']=$tpl->getOutputContent();
		
		$this->Send();
	}

	
	function Send(){
		
		//Create the message
		$message = Swift_Message::newInstance()
  			->setSubject($this->email['subject'])
  			->setFrom(array($this->settings['from_email'] => $this->settings['from_name']))
  			->setTo(array($this->email['to_email']))
  			->setBody(strip_tags($this->email['text']))
  			->addPart($this->email['text'], 'text/html')
  		;
  		$result = $this->mailer->send($message);
	}
	
	function SendMultipleRecipients(){
		
		//Create the message
		$message = Swift_Message::newInstance()
  			->setSubject($this->email['subject'])
  			->setFrom(array($this->settings['from_email'] => $this->settings['from_name']))
  			->setTo($this->email['to_email'])
  			->setBody(strip_tags($this->email['text']))
  			->addPart($this->email['text'], 'text/html')
  		;
  		$result = $this->mailer->send($message);
	}
	
	
	function SendAttach(){
		//Create the message
		$message = Swift_Message::newInstance()
  			->setSubject($this->email['subject'])
  			->setFrom(array($this->settings['from_email'] => $this->settings['from_name']))
  			->setTo(array($this->email['to_email']))
  			->setBody(strip_tags($this->email['text']))
  			->addPart($this->email['text'], 'text/html')
  			 ->attach(Swift_Attachment::fromPath($this->email['attach']))
  		;
  		$result = $this->mailer->send($message);
	}
	
}
/*
if($_GET['id']){
$email = new eMail();
$data['email'] = "dc@zabec.net";
$data['order_id'] = "11";
$data['user'] = "Zabec.net d.o.o.";
$data['ip'] = "192.168.1.1";
$data['date'] = date("d.m.Y");
$data['pdf'] = "1238071553.pdf";

$email->Order_Bill('domenc@gmail.com',$data);
}*/