<?php
class Admin_mail_model extends CI_Model {
	
	function ____construct() {
		parent::__construct();
   	}
   		
	function adminForgotMail($userName,$userEmail,$userActiveKey,$userType){
		//echo $userEmail;
  		$mailTemplates = $this->getMailTemplates(3);
		$verifyUrl = mail_url().'admin/verify/'.$userActiveKey; 
		$subject  = $mailTemplates['template_subject'];
		$phrase  = $mailTemplates['template_content'];
		$phrase = str_replace( base_url(), mail_url(), $phrase); 
		$search = array("{SITE_NAME}", "{SITE_PATH}","{USER_NAME}","{EMAIL}","{ADMIN_URL}","{USER_TYPE}","{VERIFY_URL}");
		$replace   = array(site_name(),mail_url(),$userName,$userEmail,$verifyUrl,$userType,$verifyUrl );
		$newphrase = str_replace($search, $replace, $phrase);

  		$config['mailtype'] = 'html';
		$config['charset'] = 'utf-8';
		$config['wordwrap'] = TRUE;
		$this->email->initialize($config);
		$this->email->clear(TRUE);
		$this->email->from(site_from_email(),site_name());
		$this->email->to($userEmail);
		$this->email->subject($subject);
		$this->email->message($newphrase);
		$this->email->send();
		return true;	
	} 
	
	function getMailTemplates($tempId = false){
		$this->db->where('template_id',$tempId);
		$mailQuery = $this->db->get('email_templates');
 		if($mailQuery->num_rows()){return $mailQuery->row_array();}
		else return false;
		
	}
}