<?php

class Base extends Controller {

  var $jazyk;
  var $tplData;

  function Base() {
  
    parent::Controller();
    
    $this->load->model("nastavenie");
    $this->load->model("language");
    
    $jazyk = $this->uri->segment(3);
    $jazyk = (!empty($jazyk) ? $jazyk : $this->nastavenie->vyber("hlavny_jazyk"));
    $this->jazyk = ($jazyk == "sk" ? "sk" : ($jazyk == "hu" ? "hu" : ($jazyk == "en" ? "en" : $this->nastavenie->vyber("hlavny_jazyk"))));
    $this->_assign("jazyk", $this->jazyk);
    
    $this->language->LoadLang($this->jazyk, $this->nastavenie->vyber("hlavny_jazyk"));
  }
  
  function _assignTplData()
  {
    $this->tplData["baseurl"] = base_url(); 
    $this->tplData["siteurl"] = site_url();
    $this->tplData["urisegments"] = $this->uri->uri_string();
      
    foreach($this->tplData as $k => $v)
    {
      $this->_assign($k, $v);
    }
  }
  
  function _debug($var)
  {
    echo "<pre>";
    print_r($var);
    echo "</pre>";
  }
  
  function _debugAndDie($var)
  {
    $this->_debug($var);
    die();
  }
  
  function _assign($varname, $varvalue)
  {
    $this->ci_smarty->assign($varname, $varvalue);
  }
  
  function _langPanelLink($lang, $class, $func = "index")
  {
    $i=1;
    $array = array();
    
    while (!($this->uri->segment($i) === FALSE))
    {
      $array[] = $this->uri->segment($i);
      $i++;
    }
    
    if (!isset($array[0]) || empty($array[0]))
      $array[0] = $class;
    if (!isset($array[1]))
      $array[1] = $func;
      $array[2] = $lang;
    
    return implode("/", $array);
  }
  
  function _prepareLangPanel($class, $func = "index")
  {
    $this->_assign("lang_panel_sk", base_url() . $this->_langPanelLink("sk", $class, $func));
    $this->_assign("lang_panel_hu", base_url() . $this->_langPanelLink("hu", $class, $func));
    $this->_assign("lang_panel_en", base_url() . $this->_langPanelLink("en", $class, $func));
  }
  
  function _setBody($filename)
  {
    $this->tplData["body_file"] = "$filename.tpl";
  }
  
  function _setTitle($title)
  {
    $this->tplData["page_title"] = $title;
  }
  
  function _setHeader($title)
  {
    $this->tplData["page_header_title"] = $title;
  }
  
  // Funkcie na vykreslovanie stranky nezavisle nad ostatnym prostredim
  
  function _buildLangPanel()
  {
    $this->_assign("langpanel_lang", $this->language->GetLang("lang_panel"));
  }
}

?>