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

/***************************************************************************
 *	PROJECT: ZokiSoft Smart Catalog
 *
 *	This program is a commercial software and any kind of using
 *	it must agree to ZokiSoft License Agreement.
 *
 *	This notice may not be removed from the code.
 *
 *	Copyright 2007-2008 ZokiSoft
 *	http://www.zokisoft.com/
 ***************************************************************************/

class Cron extends Catalog_Controller
{

	var $aHeaderVar = array();
	var $aFooterVar = array();
	var $aSystemVar = array();

/*
*
*	Constructor
*
*/
	function Cron()
	{

		parent::Catalog_Controller();

		$this->aHeaderVar['catalog_charset'] = $this->config->item('catalog_charset');

		$this->aSystemVar['template_viewer_root'] = $this->config->item('template_module_viewer');
		$this->aSystemVar['template_viewer_current'] = $this->config->item('template_viewer_cron');
		$this->aSystemVar['current_location'] = $this->uri->uri_string();

	}


	function index()
	{

		echo "\ncron jobs resides here\n\n";

	}


/*
*
*	send group of mails from table `email_queue`
*
*/
	function send_mail( $iAmount = '20' )
	{

		$this->load->database();

		$this->db->select('*');
		$this->db->limit( (int)$iAmount );
		$rRes = $this->db->get('`zok_email_queue`');

		if ( 0 == $rRes->num_rows() )
			return;

		$this->load->library('email');

		$sId = '';

		foreach ( $rRes->result_array() as $aMail )
		{

			$sId .= $aMail['Id'] . ',';

			$this->email->from( $aMail['Sender'] );
			$this->email->to( $aMail['Recipient'] );
			$this->email->subject( $aMail['Subject'] );
			$this->email->message( $aMail['Body'] );

			$this->email->send();
		}

		$sId .= '0';

		$this->db->where( ' Id IN (' . $sId . ')');
		$this->db->delete('zok_email_queue');

		return true;

	}


}

/* End of file cron.php */
/* Location: ./system/application/controllers/cron.php */