<?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'] = "white";
		
		if ($this->user_info['permission']['search_avail'] AND $this->user_info['permission']['visit_site'])
		{
			$rule_action['rule_type'] = "black"; //'black'Blacklist, blacklist check  'white' white list, outside the whitelist check
		}
		
		$rule_action['actions']=array();
		
		return $rule_action;
	}
	
	public function setup()
	{
		HTTP::no_cache_header();
		
		$this->crumb('Search', '/search/');
	}
	
	public function index_action()
	{
		if ($_POST['q'])
		{
			HTTP::redirect('/search/q-' . base64_encode($_POST['q']));
		}
		
		$keyword = htmlspecialchars(base64_decode($_GET['q']));
		
		$this->crumb($keyword, '/search/q-' . urlencode($keyword));
		
		if (!$keyword)
		{
			HTTP::redirect('/');	
		}
		
		TPL::assign('keyword', $keyword);
		TPL::assign('split_keyword', implode(' ', $this->model('system')->analysis_keyword($keyword)));
		
		TPL::import_css(array(
			'css/main.css',
		));
		
		TPL::output('search/index');
	}
}