<?php
/**
 * Mail module
 * 
 * Process emails queue stored in database. This file is call by cronjobs
 * 
 * @package linea21\modules\mail
 * @author $Author$ - linea21 <info@linea21.com>
 * @version $Id$ 
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

@set_time_limit(0); // removing timeout

include_once('../config/define.php');

include_once('../languages/' . U_L . '/lang_common.' . CHARSET . '.php');
include_once('../mail/send.php');
include_once('../admin/' . SQL . '.inc.php');
include_once('../class/class.emailq.php');


$emailqo = new emailq;

// By default return a number of records equals to MAIL_BULK if is integer 
// else by default limit set in the class itself
$data = $emailqo->getQueue($sql_object);


if(isset($data[0]['eq_recipient'])) {
	
	foreach ($data as &$el) {
		
		// we populate the message
		$emailCont['recipient'] =  $el['eq_recipient'];
		$emailCont['subject'] 	=  $el['eq_subject'];
		$emailCont['html_body'] 	=  $el['eq_htmlbody'];
		$emailCont['txt_body']	=  $el['eq_textbody'];

		// and send it
		if(send_email($emailCont)) $emailqo->setSent($el['eq_id'], $sql_object);
		
	}
	
}

?>