<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Page extends Controller_Website {
	public function action_index($slug ="",$lang ="")
	{
		if(!$lang)
		{
			$lang = substr(i18n::$lang,0,2);
		}
		
		
		
		
		////// Ana Sayfada  gösterme yapmaya çalışma
		$pages = ORM::factory("page")->where('lang','=',$lang)->find_all();
		
		$view = View::factory("header", array("pages"=>$pages));
		$this->template->header = $view;
		
		
		
		
		
		
		
		$orms = ORM::factory("page")->where('slug','=',$slug)->find_all();
		foreach($orms as $orm)
		{
			if($orm->lang == $lang)
			{
				if($orm->loaded())
					$this->template->content = $orm->content;
				else
					$this->template->content = "Böyle bir sayfa bulunamadı!";
		
			}
			
		}
		
		
	}
	public function action_lang($lang = "tr-tr")
	{
		Session::instance()->set("lang", $lang);
		i18n::$lang = $lang;
        
        if(isset($_GET["to_go"]))
        {
            $this->request->redirect($_GET["to_go"]);
        }
        else
        {
		    gen::re_back();
        }
	}

}