<?php
/*
+--------------------------------------------------------------------------
|   TanyaCMS - Question and Answer Sofware
|   -----------------------------------------------------------------------
|   by fbschool dev team
|   (c) 2011 - 2012 FBSCHOOL
|   http://www.fbschool.com/tanyacms
|   -----------------------------------------------------------------------
|   This is NOT a freeware, use is subject to license terms
|   Support: 13455n@gmail.com
+--------------------------------------------------------------------------
*/


if (!defined('IN_TANYACMS'))
{
	die;
}

class main extends ASK_CONTROLLER
{
	public function get_access_rule()
	{
		$rule_action['rule_type'] = 'black';
		
		return $rule_action;
	}
	
	public function setup()
	{
		HTTP::no_cache_header();
	}
	
	public function index_action()
	{
		$this->run_action();
	}
	
	public function run_action()
	{
		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');             // Date in the past
		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
		header('Cache-Control: no-cache, must-revalidate');           // HTTP/1.1
		header('Pragma: no-cache');                                   // HTTP/1.0
		
		@set_time_limit(0);
		
		if ($call_actions = $this->model('cronlog')->start())
		{
			foreach ($call_actions AS $call_action)
			{			
				if ($plugins = ASK_APP::plugins()->parse('cronlog', 'main', $call_action))
				{
					foreach ($plugins AS $plugin_file)
					{
						include($plugin_file);
					}
				}
			
				$call_function = $call_action . '_action';
			
				$this->$call_function($this->user_id);
			}
		}
		
		if (ASK_APP::config()->get('system')->debug)
		{
			TPL::output('global/debuger.tpl.htm');
		}
	}
	
	// Performed per second
	public function second_action($user_id = null)
	{
		$this->model('cronlog')->second($user_id);
	}
	
	// Every half a minute execution
	public function half_minute_action($user_id = null)
	{
		$this->model('cronlog')->half_minute($this->user_id);
	}
	
	// Every minute
	public function minute_action($user_id = null)
	{
		$this->model('cronlog')->minute($user_id);
	}
	
	// Performed every half hour
	public function half_hour_action($user_id = null)
	{
		$this->model('cronlog')->half_hour($user_id);
	}
	
	// Hourly
	public function hour_action($user_id = null)
	{
		$this->model('cronlog')->hour($user_id);
	}
	
	// Daily executed
	public function day_action($user_id = null)
	{
		$this->model('cronlog')->day($user_id);
	}
	
	// Weekly
	public function week_action($user_id = null)
	{
		$this->model('cronlog')->week($user_id);
	}
}